Game Development Reference
In-Depth Information
VActive() is something you can call to determine if the sound system is active. As
rare as it may be, a sound card might be disabled or not installed. It is also likely that
during initialization or game shutdown, you
'
ll want to know if the sound system has
a heartbeat.
The next two methods, VInitAudioBuffer() and VReleaseAudioBuffer() , are
called when you want to launch a new sound or tell the audio system you are done
with it and it can release audio resources back to the system. This is important, so
read it twice. You ' ll call these for each instance of a sound, even if it is exactly the
same effect. You might want to play the same sound effect at two different volumes,
such as when two players are firing the same type of weapon at each other, or you
have multiple explosions going off at the same time in different places.
You
ll notice that the only parameter to the initialize method is a shared pointer to a
ResHandle object. This object contains the single copy of the actual decompressed
PCM sound data. The result of the call, assuming it succeeds, is a pointer to an object
that implements the IAudioBuffer interface. What this means is that the audio
system is ready to play the sound.
The next three methods are system-wide sound controls, mostly for doing things like
pausing and resuming sounds when needed, such as when the player on a Windows
game Alt-Tabs away from your game. It ' s extremely annoying to have game sound
effects continue in the background if you are trying to check email or convince
your boss you aren
'
t playing a game.
The last two methods, VInitialize() and VShutdown() , are used to create and
tear down the sound system. Let
'
s take a look at a platform-agnostic partial imple-
mentation of the IAudio interface:
'
class Audio : public IAudio
{
public:
Audio();
virtual void VStopAllSounds();
virtual void VPauseAllSounds();
virtual void VResumeAllSounds();
virtual void VShutdown();
static bool HasSoundCard(void);
bool IsPaused() { return m_AllPaused; }
protected:
typedef std::list<IAudioBuffer *> AudioBufferList;
Search WWH ::




Custom Search