Skip to content

Commit

Permalink
SOUND: Add EmptyAudioStream
Browse files Browse the repository at this point in the history
  • Loading branch information
DrMcCoy committed Aug 18, 2018
1 parent f784ac9 commit 2aa5655
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 1 deletion.
2 changes: 1 addition & 1 deletion src/sound/audiostream.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,7 @@ LoopingAudioStream::~LoopingAudioStream() {
}

size_t LoopingAudioStream::readBuffer(int16 *buffer, const size_t numSamples) {
if ((_loops && _completeIterations == _loops) || !numSamples)
if ((_loops && _completeIterations == _loops) || !numSamples || (_parent->getLength() == 0))
return 0;

const size_t samplesRead = _parent->readBuffer(buffer, numSamples);
Expand Down
17 changes: 17 additions & 0 deletions src/sound/audiostream.h
Original file line number Diff line number Diff line change
Expand Up @@ -151,6 +151,23 @@ class RewindableAudioStream : public AudioStream {
}
};

/** An empty audio stream that plays nothing. */
class EmptyAudioStream : public RewindableAudioStream {
public:
EmptyAudioStream() { }

size_t readBuffer(int16 *UNUSED(buffer), const size_t UNUSED(numSamples)) { return 0; }

int getChannels() const { return 1; }

int getRate() const { return 44100; }

bool endOfData() const { return true; }
bool rewind() { return true; }

uint64 getLength() const { return 0; }
};

/**
* A looping audio stream. This object does nothing besides using
* a RewindableAudioStream to play a stream in a loop.
Expand Down

0 comments on commit 2aa5655

Please sign in to comment.