Game Development Reference
In-Depth Information
if(!m_AudioBuffer)
return;
m_AudioBuffer->VPlay(volume, looping);
}
void SoundProcess::Stop()
{
if(m_AudioBuffer)
m_AudioBuffer->VStop();
}
float SoundProcess::GetProgress()
{
if (m_AudioBuffer)
return m_AudioBuffer->VGetProgress();
return 0.0f;
}
Launching Sound Effects
The only thing you need to see now is how to tie all this together to launch
and monitor a sound effect in your game. It may seem a little anticlimactic, but
here it is:
Resource resource(
);
shared_ptr<ResHandle> rh = g_pApp->m_ResCache->GetHandle(&resource);
shared_ptr<SoundProcess> sfx(new SoundProcess(srh, PROC_MUSIC, 100, true));
m_pProcessManager->Attach(sfx);
There
SpaceGod7-Level2.ogg
s clearly an awful lot of work going on in the background, all of which you
now know how to do. Launching a sound effect ties together much of the code
you
'
'
ve seen in this topic: a cooperative multitasker, the resource cache, and a bit of
DirectX, which launches an extra thread to manage the problem of getting data to the
sound card at exactly the right speed. Still, it
'
s nice to know that all that functionality
can be accessed with three lines of code.
If you want to launch three sound effects based on the same data, one playing as
soon as the other is complete, here
'
s how you do it. Each one plays at a lower volume
level than the one before it.
Resource resource(
);
shared_ptr<SoundProcess> sfx1(new SoundProcess(srh, PROC_SOUNDFX, 100, false));
shared_ptr<SoundProcess> sfx2(new SoundProcess(srh, PROC_SOUNDFX, 60, false));
shared_ptr<SoundProcess> sfx3(new SoundProcess(srh, PROC_SOUNDFX, 40, false));
blip.wav
 
 
Search WWH ::




Custom Search