Game Development Reference
In-Depth Information
into sound categories such as sound effects, music, ambient background effects, or
speech. This creates an easy way for a game to turn off or change the volume level
of a particular type of sound, which most gamers will expect. If players want to turn
down the music level so they can hear speech better, it
'
s a good idea to let them.
SoundProcess::SoundProcess(
shared_ptr<ResHandle> soundResource,
int typeOfSound, int volume, bool looping)
: CProcess(typeOfSound, 0),
m_SoundResource(soundResource),
m_Volume(volume),
m_isLooping(looping)
{
InitializeVolume();
}
SoundProcess::~SoundProcess()
{
if (m_AudioBuffer)
{
g_Audio->VReleaseAudioBuffer(m_AudioBuffer.get());
}
}
The meat of the code in SoundProcess is in the next few methods. One important
concept to understand about sounds is that the code might create a sound process
long before the sound should be played or even loaded. Since sound effects tend to
require a lot of data, it ' s a good idea to be careful about when you instantiate sound
effects. After all, you don
t want your game to stutter or suffer wacky pauses. The
code shown next assumes the simplest case, where you want the sound to begin play-
ing immediately, but it
'
'
s good to know that you don
'
t have to do it this way.
void SoundProcess::VOnInitialize()
{
if ( m_handle == NULL || m_handle->GetExtra() == NULL)
return;
//This sound will manage its own handle in the other thread
IAudioBuffer *buffer = g_Audio->VInitAudioBuffer(m_handle);
if (!buffer)
{
VKill();
return;
}
Search WWH ::




Custom Search