Game Development Reference
In-Depth Information
How to do it…
1.
The class SoundThread , where we implement the actual playback, is as follows:
class SoundThread: public iThread
{
2.
First we declare handles to the OpenAL audio device and device context:
ALCdevice* FDevice;
ALCcontext* FContext;
3.
Then, we declare handles to the OpenAL audio source and buffer:
ALuint FSourceID;
ALuint FBufferID;
4.
The Run() member function does all the work that includes initialization, de-
initialization, and submission of audio data into OpenAL:
virtual void Run()
{
5.
We initialize the pointers to OpenAL functions:
LoadAL();
6.
Then we create the device and device context:
FDevice = alcOpenDevice( NULL );
FContext = alcCreateContext( FDevice, NULL );
7.
Finally, we select our newly created device context as the current one:
alcMakeContextCurrent( FContext );
8.
Now, we begin the creation of the audio source:
alGenSources( 1, &FSourceID );
9.
We set a constant maximum playback volume of 1.0 , which is called gain in OpenAL:
alSourcef( FSourceID, AL_GAIN, 1.0f );
10. To hear something, we must load the ile containing the sound data:
clPtr<iIStream> Sound = g_FS->CreateReader("test.wav");
11. We use our memory-mapped iles and ask our iStream object about the ile size:
int DataSize = (int)Sound->GetSize();
const ubyte* Data = Sound->MapStream();
 
Search WWH ::




Custom Search