60 : _parent(stream, disposeAfterUse), _loops(loops), _completeIterations(0) {
70 const size_t samplesRead =
_parent->readBuffer(buffer, numSamples);
79 const size_t remainingSamples = numSamples - samplesRead;
87 const size_t samplesReadNext =
readBuffer(buffer + samplesRead, remainingSamples);
91 return samplesRead + samplesReadNext;
237 throw Common::Exception(
"QueuingAudioStreamImpl::queueAudioStream(): Trying to queue another audio stream, but the QueuingAudioStream is finished.");
240 throw Common::Exception(
"QueuingAudioStreamImpl::queueAudioStream(): stream has mismatched parameters");
248 size_t samplesDecoded = 0;
250 while (samplesDecoded < numSamples && !
_queue.empty()) {
253 const size_t n = stream->
readBuffer(buffer + samplesDecoded, numSamples - samplesDecoded);
267 return samplesDecoded;
const int _channels
The number of channels in this audio stream.
~QueuingAudioStreamImpl()
Common::Mutex _mutex
A mutex to avoid access problems (causing e.g.
uint64 getDuration() const
QueuingAudioStream * makeQueuingAudioStream(int rate, int channels)
Factory function for an QueuingAudioStream.
size_t numQueuedStreams() const
Return the number of streams still queued for playback (including the currently playing stream)...
We queue a number of (pointers to) audio stream objects.
StreamHolder(AudioStream *stream, bool disposeAfterUse)
uint64 getDurationOnce() const
Return the duration of one loop.
virtual int getChannels() const =0
Return the number channels in this stream.
virtual size_t readBuffer(int16 *buffer, const size_t numSamples)
Fill the given buffer with up to numSamples samples.
virtual int getRate() const =0
Sample rate of the stream.
Common::DisposablePtr< RewindableAudioStream > _parent
virtual bool isFinished() const
Is the stream marked as finished?
bool endOfData() const
End of data reached? If this returns true, it means that at this time there is no data available in t...
virtual int getChannels() const
Return the number channels in this stream.
LoopingAudioStream(RewindableAudioStream *stream, size_t loops, bool disposeAfterUse=true)
Creates a looping audio stream object.
virtual void finish()
Mark this stream as finished.
Basic exceptions to throw.
A rewindable audio stream.
size_t readBuffer(int16 *buffer, const size_t numSamples)
Fill the given buffer with up to numSamples samples.
virtual size_t readBuffer(int16 *buffer, const size_t numSamples)=0
Fill the given buffer with up to numSamples samples.
static const size_t kSizeInvalid
static const uint64 kInvalidLength
std::queue< StreamHolder > _queue
The queue of audio streams.
size_t _completeIterations
Convenience class that locks a mutex on creation and unlocks it on destruction.
Generic audio input stream.
virtual int getRate() const
Sample rate of the stream.
virtual void queueAudioStream(AudioStream *stream, bool disposeAfterUse)
Queue an audio stream for playback.
QueuingAudioStreamImpl(int rate, int channels)
AudioStream * makeLoopingAudioStream(RewindableAudioStream *stream, size_t loops)
Wrapper functionality to efficiently create a stream, which might be looped.
virtual bool endOfStream() const
End of stream reached? If this returns true, it means that all data in this stream is used up and no ...
bool _finished
This flag is set by the finish() method only.
uint64 getLengthOnce() const
Return the length of one loop.
const int _rate
The sampling rate of this audio stream.
virtual bool endOfData() const =0
End of data reached? If this returns true, it means that at this time there is no data available in t...
virtual bool endOfData() const
End of data reached? If this returns true, it means that at this time there is no data available in t...