Skip to content

Commit

Permalink
Merge pull request #54 from UniversityRadioYork/mw-general-cleanup
Browse files Browse the repository at this point in the history
General cleanup
  • Loading branch information
wlcx committed Nov 15, 2014
2 parents 0c6cd80 + f9c6f7f commit cf6ca6d
Show file tree
Hide file tree
Showing 47 changed files with 705 additions and 441 deletions.
26 changes: 0 additions & 26 deletions BSDmakefile

This file was deleted.

4 changes: 2 additions & 2 deletions Doxyfile
Original file line number Diff line number Diff line change
Expand Up @@ -721,7 +721,7 @@ WARN_FORMAT = "$file:$line: $text"
# messages should be written. If left blank the output is written to standard
# error (stderr).

WARN_LOGFILE =
WARN_LOGFILE = doc/doxygen_warnings.txt

#---------------------------------------------------------------------------
# Configuration options related to the input files
Expand Down Expand Up @@ -784,7 +784,7 @@ EXCLUDE_SYMLINKS = NO
# Note that the wildcards are matched against the file with absolute path, so to
# exclude all test directories for example use the pattern */test/*

EXCLUDE_PATTERNS =
EXCLUDE_PATTERNS = */tests/*

# The EXCLUDE_SYMBOLS tag can be used to specify one or more symbol names
# (namespaces, classes, functions, etc.) that should be excluded from the
Expand Down
3 changes: 3 additions & 0 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -109,6 +109,9 @@ OWN_HEADERS = $(foreach dir,$(OWN_SRC_SUBDIRS),$(wildcard $(dir)/*.hpp))
OWN_CHEADERS = $(foreach dir,$(OWN_SRC_SUBDIRS),$(wildcard $(dir)/*.h))
TO_FORMAT = $(OWN_SOURCES) $(OWN_CSOURCES) $(OWN_HEADERS) $(OWN_CHEADERS)

# Version stuff
CFLAGS += -D PD_VERSION=\"$(shell git describe --tags --always)\"

# Now set up the flags needed for playd.
CFLAGS += -c $(WARNS) $(PKG_CFLAGS) -g -std=$(C_STD)
CXXFLAGS += -c $(WARNS) $(PKG_CFLAGS) -g -std=$(CXX_STD)
Expand Down
15 changes: 13 additions & 2 deletions README.VisualStudio.md
Original file line number Diff line number Diff line change
Expand Up @@ -16,8 +16,7 @@ the `lib` and `include` subdirectories respectively.

The `lib` directory should include:

* `libsox.lib`, from building libuv _as a shared library_ (see below for a
somewhat hacky way to do this with MSVC);
* `libsox.lib`, from building libuv _as a shared library_ (see below);
* `libuv.lib`, from building libuv as below;
* `portaudio_x86.lib`, from building PortAudio from `cmake` as below;
* `portaudiocpp-vc7_1-d.lib`, from building the PortAudio C++ bindings as
Expand Down Expand Up @@ -53,6 +52,16 @@ this should work fine.

## SoX

One of the authors, at the time of writing, maintain a [fork] of SoX with a
VS2013 solution set up for building a dynamic DLL and import library. This
also contains any patches that we've applied to SoX to get it working for us.

Note that SoX itself requires several libraries to be placed in the directory
one level above its root directory to compile; see the Visual Studio project's
includes for details.

### Stable SoX

Some persuasion of the dated sources recommended by the SoX build instructions
is necessary to get them to build with modern Visual Studio. The following
'hacks' work on 32-bit VS2013:
Expand Down Expand Up @@ -88,3 +97,5 @@ is necessary to get them to build with modern Visual Studio. The following

This is needed to make LibSoX build a `.lib` file for dynamic linking. An
example is given in the source bundle as `libsox.def`.

[fork]: https://github.com/CaptainHayashi/sox
22 changes: 11 additions & 11 deletions src/audio/audio.cpp
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
// This file is part of playd.
// playd is licenced under the MIT license: see LICENSE.txt.
// playd is licensed under the MIT licence: see LICENSE.txt.

/**
* @file
Expand All @@ -22,7 +22,7 @@

Audio::Audio(AudioSource *source, AudioSink *sink) : source(source), sink(sink)
{
ClearFrame();
this->ClearFrame();
}

std::string Audio::Path() const
Expand Down Expand Up @@ -57,7 +57,7 @@ void Audio::SeekToPositionMicroseconds(
{
auto samples = this->source->Seek(microseconds);
this->sink->SetPosition(samples);
ClearFrame();
this->ClearFrame();
}

void Audio::ClearFrame()
Expand All @@ -69,10 +69,10 @@ void Audio::ClearFrame()

bool Audio::Update()
{
bool more_frames_available = DecodeIfFrameEmpty();
bool more_frames_available = this->DecodeIfFrameEmpty();

if (!FrameFinished()) {
TransferFrame();
if (!this->FrameFinished()) {
this->TransferFrame();
}

this->sink->SetInputReady(more_frames_available);
Expand All @@ -88,9 +88,9 @@ void Audio::TransferFrame()

// We empty the frame once we're done with it. This
// maintains FrameFinished(), as an empty frame is a finished one.
if (FrameFinished()) {
ClearFrame();
assert(FrameFinished());
if (this->FrameFinished()) {
this->ClearFrame();
assert(this->FrameFinished());
}

// The frame iterator should be somewhere between the beginning and
Expand All @@ -105,11 +105,11 @@ bool Audio::DecodeIfFrameEmpty()
// Either the current frame is in progress, or has been emptied.
// AdvanceFrameIterator() establishes this assertion by emptying a
// frame as soon as it finishes.
assert(this->frame.empty() || !FrameFinished());
assert(this->frame.empty() || !this->FrameFinished());

bool more_frames_available = true;

if (FrameFinished()) {
if (this->FrameFinished()) {
AudioSource::DecodeResult result = this->source->Decode();

this->frame = result.second;
Expand Down
2 changes: 1 addition & 1 deletion src/audio/audio.hpp
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
// This file is part of playd.
// playd is licenced under the MIT license: see LICENSE.txt.
// playd is licensed under the MIT licence: see LICENSE.txt.

/**
* @file
Expand Down
18 changes: 7 additions & 11 deletions src/audio/audio_sink.cpp
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
// This file is part of playd.
// playd is licenced under the MIT license: see LICENSE.txt.
// playd is licensed under the MIT licence: see LICENSE.txt.

/**
* @file
Expand Down Expand Up @@ -77,12 +77,11 @@ void AudioSink::SetPosition(AudioSink::SamplePosition samples)
void AudioSink::Transfer(AudioSink::TransferIterator &start,
const AudioSink::TransferIterator &end)
{
// No point transferring 0 bytes.
if (start == end) {
return;
}
assert(start < end);

// No point transferring 0 bytes.
if (start == end) return;

unsigned long bytes = std::distance(start, end);
// There should be a whole number of samples being transferred.
assert(bytes % bytes_per_sample == 0);
Expand All @@ -93,10 +92,8 @@ void AudioSink::Transfer(AudioSink::TransferIterator &start,
// Only transfer as many samples as the ring buffer can take.
// Don't bother trying to write 0 samples!
auto count = std::min(samples, this->ring_buf.WriteCapacity());
if (count == 0) {
return;
}
assert(0 < count);
if (count == 0) return;

auto start_ptr = reinterpret_cast<char *>(&*start);
unsigned long written_count = this->ring_buf.Write(start_ptr, count);
Expand Down Expand Up @@ -160,14 +157,13 @@ PlayCallbackStepResult AudioSink::PlayCallbackFailure(
{
decltype(in) result;

if (InputReady()) {
if (this->InputReady()) {
// There's been some sort of genuine issue.
// Make up some silence to plug the gap.
Debug() << "Buffer underflow" << std::endl;
memset(out, 0, this->bytes_per_sample * frames_per_buf);
result = std::make_pair(paContinue, frames_per_buf);
}
else {
} else {
// End of input is ok, it means the stream can finish.
result = std::make_pair(paComplete, in.second);
}
Expand Down
4 changes: 2 additions & 2 deletions src/audio/audio_sink.hpp
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
// This file is part of playd.
// playd is licenced under the MIT license: see LICENSE.txt.
// playd is licensed under the MIT licence: see LICENSE.txt.

/**
* @file
Expand Down Expand Up @@ -176,7 +176,7 @@ class AudioSink : portaudio::CallbackInterface {
int paCallbackFun(const void *inputBuffer, void *outputBuffer,
unsigned long numFrames,
const PaStreamCallbackTimeInfo *timeInfo,
PaStreamCallbackFlags statusFlags);
PaStreamCallbackFlags statusFlags) override;

/**
* Performs one step in the callback.
Expand Down
36 changes: 17 additions & 19 deletions src/audio/audio_source.cpp
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
// This file is part of playd.
// playd is licenced under the MIT license: see LICENSE.txt.
// playd is licensed under the MIT licence: see LICENSE.txt.

/**
* @file
Expand Down Expand Up @@ -33,12 +33,12 @@ const size_t AudioSource::BUFFER_SIZE = 16384;
AudioSource::AudioSource(const std::string &path)
: buffer(BUFFER_SIZE), context(nullptr)
{
Open(path);
this->Open(path);
}

AudioSource::~AudioSource()
{
Close();
this->Close();
}

std::string AudioSource::Path() const
Expand Down Expand Up @@ -72,15 +72,15 @@ std::uint64_t AudioSource::SamplePositionFromMicroseconds(
// need to convert the position to seconds then multiply by the rate.
// We do things in a slightly peculiar order to minimise rounding.

return (position * SampleRate()) / 1000000;
return (position * this->SampleRate()) / 1000000;
}

TimeParser::MicrosecondPosition AudioSource::MicrosecondPositionFromSamples(
std::uint64_t samples) const
{
// This is basically SamplePositionFromMicroseconds but backwards.

return (samples * 1000000) / SampleRate();
return (samples * 1000000) / this->SampleRate();
}

size_t AudioSource::BytesPerSample() const
Expand All @@ -94,24 +94,24 @@ size_t AudioSource::BytesPerSample() const
// regards each channel as having its own separate sample, so we need
// to multiply and divide sample counts by the channel count when
// talking to SoX.
return 4 * ChannelCount();
return 4 * this->ChannelCount();
}

std::uint64_t AudioSource::Seek(TimeParser::MicrosecondPosition position)
{
assert(this->context != nullptr);

auto samples = SamplePositionFromMicroseconds(position);
auto samples = this->SamplePositionFromMicroseconds(position);

// See BytesPerSample() for an explanation of this ChannelCount().
auto sox_samples = samples * ChannelCount();
auto sox_samples = samples * this->ChannelCount();

// libsox doesn't seem to like seeking into an ended file, so close
// and re-open it first.
if (this->decode_state == DecodeState::END_OF_FILE) {
std::string path = Path();
Close();
Open(path);
std::string path = this->Path();
this->Close();
this->Open(path);
}

// Have we tried to seek past the end of the file?
Expand All @@ -137,22 +137,22 @@ AudioSource::DecodeResult AudioSource::Decode()
auto buf = reinterpret_cast<sox_sample_t *>(&this->buffer.front());

// See BytesPerSample() for an explanation of this ChannelCount().
auto sox_capacity = BufferSampleCapacity() * ChannelCount();
auto sox_capacity = this->BufferSampleCapacity() * this->ChannelCount();
size_t read = sox_read(this->context, buf, sox_capacity);

DecodeVector decoded;

if (read == 0) {
this->decode_state = DecodeState::END_OF_FILE;
}
else {
} else {
this->decode_state = DecodeState::DECODING;

// Copy only the bit of the buffer occupied by decoded data
// See BytesPerSample() for an explanation of the
// ChannelCount() division.
auto front = this->buffer.begin();
auto read_bytes = (BytesPerSample() * read) / ChannelCount();
auto read_bytes = (this->BytesPerSample() * read) /
this->ChannelCount();
decoded = DecodeVector(front, front + read_bytes);
}

Expand All @@ -172,13 +172,11 @@ AudioSource::DecodeResult AudioSource::Decode()

void AudioSource::Open(const std::string &path)
{
Close();
this->Close();

this->context = sox_open_read(path.c_str(), nullptr, nullptr, nullptr);
if (this->context == nullptr) {
std::ostringstream os;
os << "couldn't open " << path;
throw FileError(os.str());
throw FileError("couldn't open" + path);
}
}

Expand Down
2 changes: 1 addition & 1 deletion src/audio/audio_source.hpp
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
// This file is part of playd.
// playd is licenced under the MIT license: see LICENSE.txt.
// playd is licensed under the MIT licence: see LICENSE.txt.

/**
* @file
Expand Down
2 changes: 1 addition & 1 deletion src/audio/audio_system.cpp
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
// This file is part of playd.
// playd is licenced under the MIT license: see LICENSE.txt.
// playd is licensed under the MIT licence: see LICENSE.txt.

/**
* @file
Expand Down
6 changes: 3 additions & 3 deletions src/audio/audio_system.hpp
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
// This file is part of playd.
// playd is licenced under the MIT license: see LICENSE.txt.
// playd is licensed under the MIT licence: see LICENSE.txt.

/**
* @file
Expand Down Expand Up @@ -51,7 +51,7 @@ class AudioSystem : public AudioSinkConfigurator {
/**
* Destructs an AudioSystem, uninitialising its libraries.
*/
~AudioSystem();
virtual ~AudioSystem();

/**
* Loads a file, creating an Audio for it.
Expand Down Expand Up @@ -82,7 +82,7 @@ class AudioSystem : public AudioSinkConfigurator {

virtual portaudio::Stream *Configure(
const AudioSource &source,
portaudio::CallbackInterface &cb) const;
portaudio::CallbackInterface &cb) const override;

private:
std::string device_id; ///< The current device ID.
Expand Down
2 changes: 1 addition & 1 deletion src/audio/ringbuffer.hpp
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
// This file is part of playd.
// playd is licenced under the MIT license: see LICENSE.txt.
// playd is licensed under the MIT licence: see LICENSE.txt.

/**
* @file
Expand Down
Loading

0 comments on commit cf6ca6d

Please sign in to comment.