xoreos  0.0.5
Public Member Functions | Private Attributes | List of all members
Sound::LoopingAudioStream Class Reference

A looping audio stream. More...

#include <audiostream.h>

Inheritance diagram for Sound::LoopingAudioStream:
Inheritance graph
[legend]
Collaboration diagram for Sound::LoopingAudioStream:
Collaboration graph
[legend]

Public Member Functions

 LoopingAudioStream (RewindableAudioStream *stream, size_t loops, bool disposeAfterUse=true)
 Creates a looping audio stream object. More...
 
 ~LoopingAudioStream ()
 
size_t readBuffer (int16 *buffer, const size_t numSamples)
 Fill the given buffer with up to numSamples samples. More...
 
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...
 
int getChannels () const
 Return the number channels in this stream. More...
 
int getRate () const
 Sample rate of the stream. More...
 
size_t getCompleteIterations () const
 Returns number of loops the stream has played. More...
 
bool rewind ()
 
uint64 getLength () const
 
uint64 getDuration () const
 
uint64 getLengthOnce () const
 Return the length of one loop. More...
 
uint64 getDurationOnce () const
 Return the duration of one loop. More...
 
- Public Member Functions inherited from Sound::AudioStream
virtual ~AudioStream ()
 
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...
 

Private Attributes

Common::DisposablePtr< RewindableAudioStream_parent
 
size_t _loops
 
size_t _completeIterations
 

Additional Inherited Members

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

Detailed Description

A looping audio stream.

This object does nothing besides using a RewindableAudioStream to play a stream in a loop.

Definition at line 175 of file audiostream.h.

Constructor & Destructor Documentation

◆ LoopingAudioStream()

Sound::LoopingAudioStream::LoopingAudioStream ( RewindableAudioStream stream,
size_t  loops,
bool  disposeAfterUse = true 
)

Creates a looping audio stream object.

See also
makeLoopingAudioStream
Parameters
streamStream to loop
loopsHow often to loop (0 = infinite)
disposeAfterUseDestroy the stream after the LoopingAudioStream has finished playback.

Definition at line 59 of file audiostream.cpp.

◆ ~LoopingAudioStream()

Sound::LoopingAudioStream::~LoopingAudioStream ( )

Definition at line 63 of file audiostream.cpp.

Member Function Documentation

◆ endOfData()

bool Sound::LoopingAudioStream::endOfData ( ) const
virtual

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 97 of file audiostream.cpp.

References _completeIterations, and _loops.

◆ getChannels()

int Sound::LoopingAudioStream::getChannels ( ) const
inlinevirtual

Return the number channels in this stream.

Implements Sound::AudioStream.

Definition at line 192 of file audiostream.h.

References _parent.

◆ getCompleteIterations()

size_t Sound::LoopingAudioStream::getCompleteIterations ( ) const
inline

Returns number of loops the stream has played.

Definition at line 196 of file audiostream.h.

References _completeIterations.

◆ getDuration()

uint64 Sound::LoopingAudioStream::getDuration ( ) const

Definition at line 127 of file audiostream.cpp.

References _loops, _parent, and Sound::RewindableAudioStream::kInvalidLength.

◆ getDurationOnce()

uint64 Sound::LoopingAudioStream::getDurationOnce ( ) const

Return the duration of one loop.

Definition at line 142 of file audiostream.cpp.

References _parent.

◆ getLength()

uint64 Sound::LoopingAudioStream::getLength ( ) const

Definition at line 116 of file audiostream.cpp.

References _loops, _parent, and Sound::RewindableAudioStream::kInvalidLength.

◆ getLengthOnce()

uint64 Sound::LoopingAudioStream::getLengthOnce ( ) const

Return the length of one loop.

Definition at line 138 of file audiostream.cpp.

References _parent.

◆ getRate()

int Sound::LoopingAudioStream::getRate ( ) const
inlinevirtual

Sample rate of the stream.

Implements Sound::AudioStream.

Definition at line 193 of file audiostream.h.

References _parent.

◆ readBuffer()

size_t Sound::LoopingAudioStream::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 66 of file audiostream.cpp.

References _completeIterations, _loops, _parent, and Sound::AudioStream::kSizeInvalid.

◆ rewind()

bool Sound::LoopingAudioStream::rewind ( )

Definition at line 108 of file audiostream.cpp.

References _completeIterations, and _parent.

Member Data Documentation

◆ _completeIterations

size_t Sound::LoopingAudioStream::_completeIterations
private

Definition at line 212 of file audiostream.h.

Referenced by endOfData(), getCompleteIterations(), readBuffer(), and rewind().

◆ _loops

size_t Sound::LoopingAudioStream::_loops
private

Definition at line 211 of file audiostream.h.

Referenced by endOfData(), getDuration(), getLength(), and readBuffer().

◆ _parent

Common::DisposablePtr<RewindableAudioStream> Sound::LoopingAudioStream::_parent
private

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