Game Development Reference
In-Depth Information
Figure 13.4
Sound system class hierarchy.
The sound system inherits from IAudio . This object is responsible for the list of sounds
currently active. As you might predict, you only need one of these for your game.
The Audio base class implements some implementation-generic routines, and the
DirectSoundAudio class completes the implementation with DirectSound-specific calls.
The sound system needs access to the bits that make up the raw sound. The
IAudioBuffer interface defines the methods for an implementation-generic sound
buffer. AudioBuffer is a base class that implements some of the IAudioBuffer
interface, and the DirectSoundAudioBuffer completes the implementation of
the interface class using DirectSound calls. Each instance of a sound effect will use
one of these buffer objects.
A Resource encapsulates sound data, presumably loaded from a file or your
resource cache. If you had five explosions going off simultaneously, you
'
d have one
Resource object and five DirectSoundAudioBuffer objects.
Sound Resources and Handles
If you want to play a sound in your game, the first thing you do is load it. Sound
resources are loaded exactly the same as other game resources; they will likely exist
in a resource file. Sound effects can be tiny or quite long. Your game may have thou-
sands of these things, or tens of thousands as many modern games have. Just as you
saw in Chapter 8,
Loading and Caching Game Data,
you shouldn
'
t store each effect
in its own file; rather, you should pull it from a resource cache.
A resource cache is convenient if you have many simultaneous sounds that use the
same sound data, such as weapons fire. You should load this resource once, taking up
only one block of memory, and have the sound driver create many
players
that will
use the same resource.
 
 
Search WWH ::




Custom Search