Game Development Reference
In-Depth Information
{
return NULL;
}
// Add handle to the list
IAudioBuffer *audioBuffer =
(IAudioBuffer *)(new DirectSoundAudioBuffer(sampleHandle, resHandle));
m_AllSamples.push_front(audioBuffer);
return audioBuffer;
}
Notice the switch statement at the beginning of this code? It branches on the sound
type, which signifies what kind of sound resource is about to play: WAV, MP3, OGG,
or MIDI. In our simple example, we
re only looking at WAV data or OGG data that
has been decompressed, so if you want to extend this system to play other kinds of
sound formats, you
'
ll hook that new code in right there. For now, those other for-
mats are short circuited and will force a failure.
The call to IDirectSound8::CreateSoundBuffer() is preceded by setting vari-
ous values of a DSBUFFERDESC structure that informs DirectSound what kind of
sound is being created. Take special note of the flags, since that member controls
what can happen to the sound. An example is the DSBCAPS_CTRLVOLUME flag,
which tells DirectSound that we want to be able to control the volume of this sound
effect. Other examples include DSBCAPS_CTRL3D , which enables 3D sound, or
DSBCAPS_CTRLPAN , which enables panning control. Take a look at the DirectSound
docs to learn more about this important structure.
After we ' re sure we ' re talking about a sound data format we support, there are two
things to do. First, the sound data is passed onto DirectSound
'
s CreateSoundBuf-
fer() method, which creates an IDirectSoundBuffer8 object. Next, the Direct-
Sound sound buffer is handed to our C++ wrapper class, DirectSound
AudioBuffer , and inserted into the master list of sound effects managed by Audio .
Releasing an audio buffer is pretty trivial:
'
void DirectSoundAudio::VReleaseAudioBuffer(IAudioBuffer *sampleHandle)
{
sampleHandle->VStop();
m_AllSamples.remove(sampleHandle);
}
The call
to IAudioBuffer::VStop() stops the sound effect, and it
is then
removed from the list of active sounds.
Search WWH ::




Custom Search