Game Development Reference
In-Depth Information
}
m_AllPaused=false;
}
void Audio::VStopAllSounds()
{
IAudioBuffer *audioBuffer = NULL;
AudioBufferList::iterator i;
AudioBufferList::iterator end;
for(i=m_AllSamples.begin(), end=m_AllSamples.end(); i!=end; ++i)
{
audioBuffer = (*i);
audioBuffer->VStop();
}
m_AllPaused=false;
}
The code for each of these routines iterates the list of currently playing sounds and
calls the appropriate stop, resume, or pause method of the
IAudioBuffer
object.
The
Audio
and
AudioBuffer
classes are useless on their own; we must still create
the platform-specific code. Since DirectSound is completely free to use by anyone,
we
ll create our platform-specific code around that technology.
You
'
ll need to extend this code if you want to play MP3 or MIDI. Still, DirectSound
can make a good foundation for a game
'
s take a look at the
implementation for
DirectSoundAudio
first, which extends the
Audio
class we
just discussed:
'
s audio system. Let
'
class DirectSoundAudio : public Audio
{
public:
DirectSoundAudio() { m_pDS = NULL; }
virtual bool VActive() { return m_pDS != NULL; }
virtual IAudioBuffer *VInitAudioBuffer(
shared_ptr<ResHandle> soundResource);
virtual void VReleaseAudioBuffer(IAudioBuffer* audioBuffer);
virtual void VShutdown();
virtual bool VInitialize(HWND hWnd);
protected:
IDirectSound8* m_pDS;