Game Development Reference
In-Depth Information
How to do it…
1.
First, we enrich iWaveDataProvider with the additional methods
IsStreaming() , which indicates that the data from this provider should be read in
small chunks, and StreamWaveData() , which actually reads a single chunk:
class iWaveDataProvider: public iObject
virtual bool IsStreaming() const { return false; }
virtual int StreamWaveData( int Size ) { return 0; }
};
2.
Next we write a derived class, which contains an intermediate buffer for decoded or
generated sound data. It does not implement StreamWaveData() , but implements
the GetWaveData() and GetWaveDataSize() methods:
class StreamingWaveDataProvider: public iWaveDataProvider
{
public:
virtual bool IsStreaming() const { return true; }
virtual ubyte* GetWaveData() { return (ubyte*)&FBuffer[0]; }
virtual size_t GetWaveDataSize() const { return FBufferUsed; }
std::vector<char> FBuffer;
int FBufferUsed;
};
3.
The FBufferUsed ield holds the number of bytes used in the FBuffer vector. Now
we modify the AudioSource class to support our new streaming data providers. We
do not want cracks or interruptions in the playback process, so we use a queue of
buffers instead of the single buffer that we used in a single-block sound playback.
To do this, we irst declare a buffer counter and an array of buffer IDs:
class AudioSource: public iObject
{
private:
unsigned int FSourceID;
int FBuffersCount;
unsigned int FBufferID[2];
 
Search WWH ::




Custom Search