xoreos  0.0.5
Public Member Functions | Protected Types | Protected Member Functions | Protected Attributes | List of all members
Sound::MP3Stream Class Reference
Inheritance diagram for Sound::MP3Stream:
Inheritance graph
[legend]
Collaboration diagram for Sound::MP3Stream:
Collaboration graph
[legend]

Public Member Functions

 MP3Stream (Common::SeekableReadStream *inStream, bool dispose)
 
 ~MP3Stream ()
 
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...
 
uint64 getLength () const
 Estimate the total number of samples per channel in this stream. More...
 
bool rewind ()
 Rewinds the stream to its start. More...
 
- Public Member Functions inherited from Sound::RewindableAudioStream
virtual uint64 getDuration () const
 Estimate the total duration of the stream in milliseconds. 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...
 

Protected Types

enum  State { MP3_STATE_INIT, MP3_STATE_READY, MP3_STATE_EOS }
 
enum  { BUFFER_SIZE = 5 * 8192 }
 

Protected Member Functions

void decodeMP3Data ()
 
void readMP3Data ()
 
void initStream ()
 
void readHeader ()
 
void deinitStream ()
 

Protected Attributes

Common::DisposablePtr< Common::SeekableReadStream_inStream
 
size_t _posInFrame
 
State _state
 
mad_timer_t _totalTime
 
mad_stream _stream
 
mad_frame _frame
 
mad_synth _synth
 
uint64 _length
 
uint64 _samples
 
int _sampleRate
 
int _channels
 
byte _buf [BUFFER_SIZE+MAD_BUFFER_GUARD]
 

Additional Inherited Members

- Static Public Attributes inherited from Sound::RewindableAudioStream
static const uint64 kInvalidLength = UINT64_C(0xFFFFFFFFFFFFFFFF)
 
- Static Public Attributes inherited from Sound::AudioStream
static const size_t kSizeInvalid = SIZE_MAX
 

Detailed Description

Definition at line 68 of file mp3.cpp.

Member Enumeration Documentation

◆ anonymous enum

anonymous enum
protected
Enumerator
BUFFER_SIZE 

Definition at line 93 of file mp3.cpp.

◆ State

enum Sound::MP3Stream::State
protected
Enumerator
MP3_STATE_INIT 
MP3_STATE_READY 
MP3_STATE_EOS 

Definition at line 70 of file mp3.cpp.

Constructor & Destructor Documentation

◆ MP3Stream()

Sound::MP3Stream::MP3Stream ( Common::SeekableReadStream inStream,
bool  dispose 
)

Definition at line 123 of file mp3.cpp.

References _buf, _channels, _frame, _length, _sampleRate, _samples, _state, BUFFER_SIZE, decodeMP3Data(), deinitStream(), initStream(), MP3_STATE_EOS, MP3_STATE_INIT, and readHeader().

Here is the call graph for this function:

◆ ~MP3Stream()

Sound::MP3Stream::~MP3Stream ( )

Definition at line 157 of file mp3.cpp.

References deinitStream().

Here is the call graph for this function:

Member Function Documentation

◆ decodeMP3Data()

void Sound::MP3Stream::decodeMP3Data ( )
protected

Definition at line 161 of file mp3.cpp.

References _frame, _posInFrame, _state, _stream, _synth, initStream(), MP3_STATE_EOS, MP3_STATE_INIT, MP3_STATE_READY, readMP3Data(), and warning().

Referenced by MP3Stream(), and readBuffer().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ deinitStream()

void Sound::MP3Stream::deinitStream ( )
protected

Definition at line 305 of file mp3.cpp.

References _frame, _state, _stream, _synth, MP3_STATE_EOS, and MP3_STATE_INIT.

Referenced by initStream(), MP3Stream(), and ~MP3Stream().

Here is the caller graph for this function:

◆ endOfData()

bool Sound::MP3Stream::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 107 of file mp3.cpp.

References _state, and MP3_STATE_EOS.

◆ getChannels()

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

Return the number channels in this stream.

Implements Sound::AudioStream.

Definition at line 108 of file mp3.cpp.

References _channels.

◆ getLength()

uint64 Sound::MP3Stream::getLength ( ) const
inlinevirtual

Estimate the total number of samples per channel in this stream.

If this value is not calculatable, return kInvalidLength.

Reimplemented from Sound::RewindableAudioStream.

Definition at line 110 of file mp3.cpp.

References _length.

◆ getRate()

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

Sample rate of the stream.

Implements Sound::AudioStream.

Definition at line 109 of file mp3.cpp.

References _sampleRate.

◆ initStream()

void Sound::MP3Stream::initStream ( )
protected

Definition at line 246 of file mp3.cpp.

References _frame, _inStream, _posInFrame, _samples, _state, _stream, _synth, _totalTime, deinitStream(), MP3_STATE_INIT, MP3_STATE_READY, readMP3Data(), and Sound::timer_zero.

Referenced by decodeMP3Data(), MP3Stream(), and rewind().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ readBuffer()

size_t Sound::MP3Stream::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 331 of file mp3.cpp.

References _frame, _posInFrame, _state, _synth, decodeMP3Data(), MP3_STATE_EOS, and Sound::scale_sample().

Here is the call graph for this function:

◆ readHeader()

void Sound::MP3Stream::readHeader ( )
protected

Definition at line 268 of file mp3.cpp.

References _frame, _samples, _state, _stream, _totalTime, MP3_STATE_EOS, MP3_STATE_READY, readMP3Data(), and warning().

Referenced by MP3Stream(), and rewind().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ readMP3Data()

void Sound::MP3Stream::readMP3Data ( )
protected

Definition at line 203 of file mp3.cpp.

References _buf, _inStream, _state, _stream, BUFFER_SIZE, and MP3_STATE_EOS.

Referenced by decodeMP3Data(), initStream(), and readHeader().

Here is the caller graph for this function:

◆ rewind()

bool Sound::MP3Stream::rewind ( )
virtual

Rewinds the stream to its start.

Returns
true on success, false otherwise.

Implements Sound::RewindableAudioStream.

Definition at line 233 of file mp3.cpp.

References _state, _totalTime, initStream(), MP3_STATE_EOS, MP3_STATE_READY, and readHeader().

Here is the call graph for this function:

Member Data Documentation

◆ _buf

byte Sound::MP3Stream::_buf[BUFFER_SIZE+MAD_BUFFER_GUARD]
protected

Definition at line 98 of file mp3.cpp.

Referenced by MP3Stream(), and readMP3Data().

◆ _channels

int Sound::MP3Stream::_channels
protected

Definition at line 91 of file mp3.cpp.

Referenced by getChannels(), and MP3Stream().

◆ _frame

mad_frame Sound::MP3Stream::_frame
protected

Definition at line 84 of file mp3.cpp.

Referenced by decodeMP3Data(), deinitStream(), initStream(), MP3Stream(), readBuffer(), and readHeader().

◆ _inStream

Common::DisposablePtr<Common::SeekableReadStream> Sound::MP3Stream::_inStream
protected

Definition at line 76 of file mp3.cpp.

Referenced by initStream(), and readMP3Data().

◆ _length

uint64 Sound::MP3Stream::_length
protected

Definition at line 87 of file mp3.cpp.

Referenced by getLength(), and MP3Stream().

◆ _posInFrame

size_t Sound::MP3Stream::_posInFrame
protected

Definition at line 78 of file mp3.cpp.

Referenced by decodeMP3Data(), initStream(), and readBuffer().

◆ _sampleRate

int Sound::MP3Stream::_sampleRate
protected

Definition at line 90 of file mp3.cpp.

Referenced by getRate(), and MP3Stream().

◆ _samples

uint64 Sound::MP3Stream::_samples
protected

Definition at line 88 of file mp3.cpp.

Referenced by initStream(), MP3Stream(), and readHeader().

◆ _state

State Sound::MP3Stream::_state
protected

◆ _stream

mad_stream Sound::MP3Stream::_stream
protected

Definition at line 83 of file mp3.cpp.

Referenced by decodeMP3Data(), deinitStream(), initStream(), readHeader(), and readMP3Data().

◆ _synth

mad_synth Sound::MP3Stream::_synth
protected

Definition at line 85 of file mp3.cpp.

Referenced by decodeMP3Data(), deinitStream(), initStream(), and readBuffer().

◆ _totalTime

mad_timer_t Sound::MP3Stream::_totalTime
protected

Definition at line 81 of file mp3.cpp.

Referenced by initStream(), readHeader(), and rewind().


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