Game Development Reference
In-Depth Information
WavProvider( const clPtr<clBlob>& blob )
{
FRawData = blob;
sWAVHeader H = *(sWAVHeader*)FRawData->GetData();
const unsigned short FORMAT_PCM = 1;
FChannels = H.Channels;
FSamplesPerSec = H.SampleRate;
FBitsPerSample = H.nBitsperSample;
}
24. The destructor is empty, since our
Blob
object is wrapped into a smart pointer:
virtual ~WavProvider() {}
25. The
iWaveDataProvider
interface is simple, and here we just implement two
member functions.
GetWaveData()
returns a pointer to the audio data:
virtual ubyte* GetWaveData()
{
return (ubyte*)FRawData->GetDataConst() +
sizeof( sWAVHeader );
}
26. The
GetWaveDataSize()
method subtracts the ile header size from the total ile
size:
virtual size_t GetWaveDataSize() const
{
return FRawData->GetSize() - sizeof( sWAVHeader );
};
And we are done with the audio playback and decoding for now.
How it works…
Now we can demonstrate how to use all the audio classes together. As usual, we create an
empty application template, which can be found in the
1_AL_Abstraction
folder.
In order to be able to use OpenAL, we must declare a global
AudioThread
instance:
AudioThread g_Audio;
We start this thread in the
OnStart()
callback function:
g_Audio.Start( iThread::Priority_Normal );
In this example, we implement the
SoundThread
class whose
Run()
method does all the
playback. On this thread, we must wait for
g_Audio
to get initialized:
while ( !g_Audio.FInitialized ) {}