Game Development Reference
In-Depth Information
class iWaveDataProvider: public iObject
{
public:
iWaveDataProvider(): FChannels( 0 ),
FSamplesPerSec( 0 ),
FBitsPerSample( 0 ) {}
9.
The main routines of this class enable access to the decoded audio data:
virtual ubyte* GetWaveData() = 0;
virtual size_t GetWaveDataSize() const = 0;
10. Here is how we can get the internal OpenAL audio format identiier for the data from
this provider:
ALuint GetALFormat() const
{
if ( FBitsPerSample == 8 )
{
return (FChannels == 2) ?
AL_FORMAT_STEREO8 : AL_FORMAT_MONO8;
}
else if ( FBitsPerSample == 16)
{
return (FChannels == 2) ?
AL_FORMAT_STEREO16 : AL_FORMAT_MONO16;
}
return AL_FORMAT_MONO8;
}
11. Also, we store the information about the audio format here:
int FChannels;
int FSamplesPerSec;
int FBitsPerSample;
};
12. As we already know, an audio source must be created to produce sounds. This
functionality is implemented in the
AudioSource
class, which wraps the OpenAL
function calls from the previous recipe. This class uses the
iWaveDataProvider
instance as the audio data source:
class AudioSource: public iObject
{
public: