Game Development Reference
In-Depth Information
'
If you
re short on media space, you can store everything in MP3 or OGG and
decompress the data in memory at load time. This is a pretty good idea for short
sound effects that you hear often, like weapons fire and footsteps. Music and back-
ground ambiance can be many minutes long and are almost always played in their
compressed form.
Always Keep Your Original High-Fidelity Audio Recordings
Make sure that all of your original sound is recorded in high-resolution WAV
format, and plan to keep it around until the end of the project. If you convert
all your audio to a compressed format such as MP3, you
'
ll lose sound quality,
and you won
'
t be able to reconvert the audio stream to a higher bit-rate if the
quality isn
t good enough. This is exactly the same thing as storing all your
artwork in high-resolution TGAs or TIFFs. You
'
ll always have the original work
stored in the highest possible resolution in case you need to mess with it later.
'
A Quick Word About Threads and Synchronization
Sound systems run in a multithreaded architecture. I
m talking about real multi-
threading here and not the cooperative multitasking. What
'
'
s the difference? You
should already be familiar with the Process and ProcessManager classes from
Chapter 7,
These classes are cooperative, which
means it is up to them to decide when to return control to the calling routine. For
those of you who remember coding in the old DOS or Windows 3.x days, this is all
we had without some serious assembly level coding. In a way, it was a lot safer, for
reasons you
Controlling the Main Loop.
ll see in a minute, but it was a heck of a lot harder to get the computer to
accomplish many tasks at once.
A classic task in games is to play some neat music in the background while you are
playing the game. Like I said at the start of this chapter, sound creates emotion in
your game. But what is really going on in the background to make sound come out
of your speakers?
Sound data is pushed into the sound card, and the sound card ' sdriversoftwarecon-
verts this data into electric signals that are sent to your speakers. The task of reading
new data into the sound card and converting it into a usable format takes some CPU
time away from your computer. While modern sound cards have CPUs of their own,
getting the data from the digital media into the sound card still takes your main CPU.
Since sound data is played at a linear time scale, it
'
s critical to push data into the
sound card at the right time. If it is pushed too early, you
'
ll overwrite music that is
about to be played. If it is pushed too late, the sound card will play some music
you
'
'
ve already heard, only to skip ahead when the right data gets in place.
 
 
Search WWH ::




Custom Search