Game Development Reference
In-Depth Information
Guide (part of the OpenAL documentation) gives some pretty good tips on how to use
its special effects extensions for environmental modeling.
Doppler Effect
The Doppler effect results when there is a relative motion between a sound source and
the listener. It manifests itself as an increase in frequency when the source and listener
are approaching each other, and a decrease in frequency when the source and listener
are moving away from each other. For example, the horn of an approaching train seems
to increase in pitch as it gets closer but seems to decrease in pitch as the train passes
and moves away. The Doppler effect is a very obvious clue as to the relative motion of
a sound source that you can capture in your games. For example, you could model the
sound of a speeding car with a Doppler effect complimenting visual cues of a car ap‐
proaching and passing by a player.
What's happening physically is that the encounter frequency of the sound waves relative
to the listener is augmented, owing to the relative velocity. An approaching velocity
means there are more waves encountered by the listener per unit of time, which is heard
as a higher frequency than the source frequency. Conversely, a departing velocity means
there are fewer waves encountered per unit of time, which is heard as a lower frequency.
Assuming still air, the increased frequency heard when the sound source and listener
are approaching each other is given by the relation:
f h = f [(c + v l )/(c + v s )]
where f h is the frequency heard by the listener, c is the speed of sound, v l is the speed of
the listener, and v s is the speed of the source. This equation shows that the frequency
heard by the listener is increased in proportion to the ratio of the sum of the speed of
sound plus the relative speed of the source and listener to the speed of sound. If the
source and listener are moving away from each other, then v r is negative and the fre‐
quency heard is reduced.
For your game, you could use prerecorded sounds with Doppler effects for passing cars
or other moving sound sources; however, you won't be able to adjust the Doppler effect
to represent the actual relative speed between sound source and listener if you're sim‐
ulating the object to which the sound is attached using the techniques discussed in this
book. Your prerecorded sound is fixed. It may work just fine, by the way. That said, if
you're using an audio system such as OpenAL, you can use its built-in Doppler effect
capabilities. Basically, if you're simulating an object that's generating a sound, you update
its sound source to reflect the object's velocity while at the same time updating the
listener object to reflect the player's velocity. OpenAL will handle the rest for you. We'll
show a simple example of this in the next section.
Search Nedrilad ::




Custom Search