Game Development Reference
In-Depth Information
Decoding Ogg Vorbis iles
Ogg Vorbis is a widely used, free, open, and patent-free audio compression format. It is
comparable to other formats used to store and play digital music, such as MP3, VQF, and AAC.
Getting ready
The reader should be familiar with the sound streaming technique from the previous recipe.
The details on the
.ogg
container ile format and the Vorbis audio compression algorithm
can be found at
http://xiph.org
.
How to do it...
1.
We add the
IsEOF()
method to the
iWaveDataProvider
interface. This is used
to inform
AudioSource
when the sound is inished:
virtual bool IsEOF() const { return true; }
2.
Another method we add is
Seek()
, which rewinds the audio stream:
virtual void Seek( float Time ) {}
3.
In the
DecodingProvider
class, we implement the
StreamWaveData()
member function, which reads the decoded sound data from a source memory
block using the
ReadFromFile()
method:
class DecodingProvider: public StreamingWaveDataProvider
{
clPtr<Blob> FRawData;
public:
bool FEof;
virtual bool IsEOF() const { return FEof; }
4.
The
FLoop
lag tells the decoder to rewind if an end of stream is encountered
and start playback again from the beginning:
bool FLoop;
public:
DecodingProvider( const clPtr<Blob>& blob )
{
FRawData = blob;
FEof = false;
}
5.
The main streaming routine attempts to read more data from the source
memory block:
virtual int StreamWaveData( int Size )
{