xoreos  0.0.5
Public Member Functions | Protected Attributes | List of all members
Sound::PCMStream< is16Bit, isUnsigned, isLE > Class Template Reference

This is a stream, which allows for playing raw PCM data from a stream. More...

Inheritance diagram for Sound::PCMStream< is16Bit, isUnsigned, isLE >:
Inheritance graph
[legend]
Collaboration diagram for Sound::PCMStream< is16Bit, isUnsigned, isLE >:
Collaboration graph
[legend]

Public Member Functions

 PCMStream (int rate, int channels, bool disposeStream, Common::SeekableReadStream *stream)
 
virtual ~PCMStream ()
 
size_t readBuffer (int16 *buffer, const size_t numSamples)
 Fill the given buffer with up to numSamples samples. More...
 
int getChannels () const
 Return the number channels in this stream. 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 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 Attributes

const int _rate
 Sample rate of stream. More...
 
const int _channels
 Amount of channels. More...
 
uint64 _length
 
Common::DisposablePtr< Common::SeekableReadStream_stream
 Stream to read data from. More...
 

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

template<bool is16Bit, bool isUnsigned, bool isLE>
class Sound::PCMStream< is16Bit, isUnsigned, isLE >

This is a stream, which allows for playing raw PCM data from a stream.

It also features playback of multiple blocks from a given stream.

Definition at line 72 of file pcm.cpp.

Constructor & Destructor Documentation

◆ PCMStream()

template<bool is16Bit, bool isUnsigned, bool isLE>
Sound::PCMStream< is16Bit, isUnsigned, isLE >::PCMStream ( int  rate,
int  channels,
bool  disposeStream,
Common::SeekableReadStream stream 
)
inline

◆ ~PCMStream()

template<bool is16Bit, bool isUnsigned, bool isLE>
virtual Sound::PCMStream< is16Bit, isUnsigned, isLE >::~PCMStream ( )
inlinevirtual

Definition at line 89 of file pcm.cpp.

Member Function Documentation

◆ endOfData()

template<bool is16Bit, bool isUnsigned, bool isLE>
bool Sound::PCMStream< is16Bit, isUnsigned, isLE >::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 95 of file pcm.cpp.

References Sound::PCMStream< is16Bit, isUnsigned, isLE >::_stream.

◆ getChannels()

template<bool is16Bit, bool isUnsigned, bool isLE>
int Sound::PCMStream< is16Bit, isUnsigned, isLE >::getChannels ( ) const
inlinevirtual

Return the number channels in this stream.

Implements Sound::AudioStream.

Definition at line 94 of file pcm.cpp.

References Sound::PCMStream< is16Bit, isUnsigned, isLE >::_channels.

◆ getLength()

template<bool is16Bit, bool isUnsigned, bool isLE>
uint64 Sound::PCMStream< is16Bit, isUnsigned, isLE >::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 97 of file pcm.cpp.

References Sound::PCMStream< is16Bit, isUnsigned, isLE >::_length.

◆ getRate()

template<bool is16Bit, bool isUnsigned, bool isLE>
int Sound::PCMStream< is16Bit, isUnsigned, isLE >::getRate ( ) const
inlinevirtual

Sample rate of the stream.

Implements Sound::AudioStream.

Definition at line 96 of file pcm.cpp.

References Sound::PCMStream< is16Bit, isUnsigned, isLE >::_rate.

◆ readBuffer()

template<bool is16Bit, bool isUnsigned, bool isLE>
size_t Sound::PCMStream< is16Bit, isUnsigned, isLE >::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 103 of file pcm.cpp.

References READ_ENDIAN_SAMPLE.

◆ rewind()

template<bool is16Bit, bool isUnsigned, bool isLE>
bool Sound::PCMStream< is16Bit, isUnsigned, isLE >::rewind ( )
virtual

Rewinds the stream to its start.

Returns
true on success, false otherwise.

Implements Sound::RewindableAudioStream.

Definition at line 115 of file pcm.cpp.

Member Data Documentation

◆ _channels

template<bool is16Bit, bool isUnsigned, bool isLE>
const int Sound::PCMStream< is16Bit, isUnsigned, isLE >::_channels
protected

◆ _length

template<bool is16Bit, bool isUnsigned, bool isLE>
uint64 Sound::PCMStream< is16Bit, isUnsigned, isLE >::_length
protected

◆ _rate

template<bool is16Bit, bool isUnsigned, bool isLE>
const int Sound::PCMStream< is16Bit, isUnsigned, isLE >::_rate
protected

Sample rate of stream.

Definition at line 75 of file pcm.cpp.

Referenced by Sound::PCMStream< is16Bit, isUnsigned, isLE >::getRate().

◆ _stream

template<bool is16Bit, bool isUnsigned, bool isLE>
Common::DisposablePtr<Common::SeekableReadStream> Sound::PCMStream< is16Bit, isUnsigned, isLE >::_stream
protected

Stream to read data from.

Definition at line 80 of file pcm.cpp.

Referenced by Sound::PCMStream< is16Bit, isUnsigned, isLE >::endOfData().


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