170
Chapter 15: Adding Sounds To Virtual Worlds
To choose a starting location in a sound file, pass the starting frame to the
setCurrentFrame() field. A frame is equal to (1/SampleRate) of a second. The sample rate
might be, for example, 44KHz, or 44,000 Hz. If, for example, you pass 44000.0 into the
setCurrentFrame() field, the sound would begin playing one second (44000 × 1/44000 =
1) into the sound file.
Sound Priority
Your application can play only a limited number of sounds at the same time. The factors
that determine whether or not a sound is heard include
• The proximity of the listener to the source.
• The priority level of the sound.
Higher priority sounds are heard instead of lower priority sounds if too many sounds
could possibly be heard by the listener at the same time. Set the priority level of a sound
in the setPriority() method.
Playing the Sound File
The setControl() field provides an intuitive interface for playing the sound sample in
sound files. You pass into setControl() any of the ControlEnum values, including PLAY,
PAUSE, REWIND, FASTFORWARD, and STOP.
Locating and Directing the Sound
To enable all of the other effects implemented by the fields in the csSound node, covered
in the next section, pass a non NULL value to setSpatialize(). If you pass a NULL value
to the field, the volume is a constant value throughout the scene. This choice is
appropriate, for example, for background music.
To locate the sound source in a scene, pass its coordinates to the setLocation() field.
Cosmo 3D gives you a great deal of control over how sound propagates from the source.
When you supply a vector describing the direction of the sound, the sound propagates
in all directions, but attenuates least in specified direction. The attenuation of the sound
over distance is characterized by an ellipse, as shown in Figure 15-2.