xoreos  0.0.5
Classes | Public Member Functions | Private Attributes | List of all members
Sound::QueuingAudioStreamImpl Class Reference
Inheritance diagram for Sound::QueuingAudioStreamImpl:
Inheritance graph
[legend]
Collaboration diagram for Sound::QueuingAudioStreamImpl:
Collaboration graph
[legend]

Classes

struct  StreamHolder
 We queue a number of (pointers to) audio stream objects. More...
 

Public Member Functions

 QueuingAudioStreamImpl (int rate, int channels)
 
 ~QueuingAudioStreamImpl ()
 
virtual size_t readBuffer (int16 *buffer, const size_t numSamples)
 Fill the given buffer with up to numSamples samples. More...
 
virtual int getChannels () const
 Return the number channels in this stream. More...
 
virtual int getRate () const
 Sample rate of the stream. More...
 
virtual bool endOfData () const
 End of data reached? If this returns true, it means that at this time there is no data available in the stream. More...
 
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 additional data will appear in it in the future. More...
 
virtual void queueAudioStream (AudioStream *stream, bool disposeAfterUse)
 Queue an audio stream for playback. More...
 
virtual void finish ()
 Mark this stream as finished. More...
 
virtual bool isFinished () const
 Is the stream marked as finished? More...
 
size_t numQueuedStreams () const
 Return the number of streams still queued for playback (including the currently playing stream). More...
 
- Public Member Functions inherited from Sound::AudioStream
virtual ~AudioStream ()
 

Private Attributes

const int _rate
 The sampling rate of this audio stream. More...
 
const int _channels
 The number of channels in this audio stream. More...
 
bool _finished
 This flag is set by the finish() method only. More...
 
Common::Mutex _mutex
 A mutex to avoid access problems (causing e.g. More...
 
std::queue< StreamHolder_queue
 The queue of audio streams. More...
 

Additional Inherited Members

- Static Public Attributes inherited from Sound::AudioStream
static const size_t kSizeInvalid = SIZE_MAX
 

Detailed Description

Definition at line 146 of file audiostream.cpp.

Constructor & Destructor Documentation

◆ QueuingAudioStreamImpl()

Sound::QueuingAudioStreamImpl::QueuingAudioStreamImpl ( int  rate,
int  channels 
)
inline

Definition at line 190 of file audiostream.cpp.

◆ ~QueuingAudioStreamImpl()

Sound::QueuingAudioStreamImpl::~QueuingAudioStreamImpl ( )

Member Function Documentation

◆ endOfData()

virtual bool Sound::QueuingAudioStreamImpl::endOfData ( ) const
inlinevirtual

End of data reached? If this returns true, it means that at this time there is no data available in the stream.

However there may be more data in the future. This is used by e.g. a rate converter to decide whether to keep on converting data or stop.

Implements Sound::AudioStream.

Definition at line 198 of file audiostream.cpp.

References _mutex, and _queue.

◆ endOfStream()

virtual bool Sound::QueuingAudioStreamImpl::endOfStream ( ) const
inlinevirtual

End of stream reached? If this returns true, it means that all data in this stream is used up and no additional data will appear in it in the future.

This is used by the mixer to decide whether a given stream shall be removed from the list of active streams (and thus be destroyed). By default this maps to endOfData()

Reimplemented from Sound::AudioStream.

Definition at line 202 of file audiostream.cpp.

References _finished, _mutex, and _queue.

◆ finish()

virtual void Sound::QueuingAudioStreamImpl::finish ( )
inlinevirtual

Mark this stream as finished.

That is, signal that no further data will be queued to it. Only after this has been done can this stream ever 'end'.

Implements Sound::QueuingAudioStream.

Definition at line 210 of file audiostream.cpp.

References _finished, and _mutex.

◆ getChannels()

virtual int Sound::QueuingAudioStreamImpl::getChannels ( ) const
inlinevirtual

Return the number channels in this stream.

Implements Sound::AudioStream.

Definition at line 196 of file audiostream.cpp.

References _channels.

Referenced by queueAudioStream().

Here is the caller graph for this function:

◆ getRate()

virtual int Sound::QueuingAudioStreamImpl::getRate ( ) const
inlinevirtual

Sample rate of the stream.

Implements Sound::AudioStream.

Definition at line 197 of file audiostream.cpp.

References _rate.

Referenced by queueAudioStream().

Here is the caller graph for this function:

◆ isFinished()

virtual bool Sound::QueuingAudioStreamImpl::isFinished ( ) const
inlinevirtual

Is the stream marked as finished?

Implements Sound::QueuingAudioStream.

Definition at line 215 of file audiostream.cpp.

References _finished, and _mutex.

◆ numQueuedStreams()

size_t Sound::QueuingAudioStreamImpl::numQueuedStreams ( ) const
inlinevirtual

Return the number of streams still queued for playback (including the currently playing stream).

Implements Sound::QueuingAudioStream.

Definition at line 220 of file audiostream.cpp.

References _mutex, and _queue.

◆ queueAudioStream()

void Sound::QueuingAudioStreamImpl::queueAudioStream ( AudioStream audStream,
bool  disposeAfterUse 
)
virtual

Queue an audio stream for playback.

This stream plays all queued streams, in the order they were queued. If disposeAfterUse is set to DisposeAfterUse::YES, then the queued stream is deleted after all data contained in it has been played.

Implements Sound::QueuingAudioStream.

Definition at line 235 of file audiostream.cpp.

References _finished, _mutex, _queue, Sound::AudioStream::getChannels(), getChannels(), Sound::AudioStream::getRate(), and getRate().

Here is the call graph for this function:

◆ readBuffer()

size_t Sound::QueuingAudioStreamImpl::readBuffer ( int16 buffer,
const size_t  numSamples 
)
virtual

Fill the given buffer with up to numSamples samples.

Returns the actual number of samples read, or kSizeInvalid if a critical error occurred (note: you must check if this value is less than what you requested, this can happen when the stream is fully used up).

Data has to be in native endianness, 16 bit per sample, signed. For stereo stream, buffer will be filled with interleaved left and right channel samples, starting with a left sample. Furthermore, the samples in the left and right are summed up. So if you request 4 samples from a stereo stream, you will get a total of two left channel and two right channel samples.

The same holds true for more channels. Channel configurations recognized:

  • 5.1: front left, front right, front center, low frequency rear left, rear right

Implements Sound::AudioStream.

Definition at line 246 of file audiostream.cpp.

References Sound::QueuingAudioStreamImpl::StreamHolder::_disposeAfterUse, _mutex, _queue, Sound::AudioStream::endOfData(), Sound::AudioStream::kSizeInvalid, and Sound::AudioStream::readBuffer().

Here is the call graph for this function:

Member Data Documentation

◆ _channels

const int Sound::QueuingAudioStreamImpl::_channels
private

The number of channels in this audio stream.

Definition at line 171 of file audiostream.cpp.

Referenced by getChannels().

◆ _finished

bool Sound::QueuingAudioStreamImpl::_finished
private

This flag is set by the finish() method only.

See there for more details.

Definition at line 176 of file audiostream.cpp.

Referenced by endOfStream(), finish(), isFinished(), and queueAudioStream().

◆ _mutex

Common::Mutex Sound::QueuingAudioStreamImpl::_mutex
mutableprivate

A mutex to avoid access problems (causing e.g.

corruption of the linked list) in thread aware environments.

Definition at line 182 of file audiostream.cpp.

Referenced by endOfData(), endOfStream(), finish(), isFinished(), numQueuedStreams(), queueAudioStream(), and readBuffer().

◆ _queue

std::queue<StreamHolder> Sound::QueuingAudioStreamImpl::_queue
private

The queue of audio streams.

Definition at line 187 of file audiostream.cpp.

Referenced by endOfData(), endOfStream(), numQueuedStreams(), queueAudioStream(), readBuffer(), and ~QueuingAudioStreamImpl().

◆ _rate

const int Sound::QueuingAudioStreamImpl::_rate
private

The sampling rate of this audio stream.

Definition at line 166 of file audiostream.cpp.

Referenced by getRate().


The documentation for this class was generated from the following file: