Use the sound mixer library to apply volume, pitch, and filter effects to global (non-spatialized) sounds. The mixer supports playing single and multi channel WAV files.
To add a mixer object, use the viz.addSoundMixer() command.
The mixer has methods for setting effect parameters and playing sounds:
Multiple mixers can be added, each with its own effect settings. In addition, mixers can have parent/child relationships where the child inherits the settings of the parent. The final effect output from the child mixer is a product of both the child and parent settings. In the following example code, the sound plays at 25% of its original volume (0.5 x 0.5):
To play a sound, specify a WAV file in the mixer.play command. All effects on the mixer will be applied to the sound. To loop or preload a sound, specify the play mode after the file name:
Use the mixer.setPaused and mixer.stop commands to pause and stop all sounds on the mixer and sub-mixers:
Note: If the mixer is paused and a sound is played, the sound will start in a paused state until the mixer is resumed.
To synchronize sounds put the mixer in a paused state, play all the sounds, then un-pause the mixer:
The sound mixer supports volume, pitch, and filter effects. Use the mixer.setPitch command to make the audio play slower or faster:
To enable filtering use the mixer.setFilter command and specify a viz.AudioFilter object. The filter object defines the type, frequency, and Q factor of the filter.
Filter Type | Description |
viz.FILTER_NONE | No filter is applied. |
viz.FILTER_LOWPASS |
Passes frequencies below the frequency value and attenuates frequencies above (e.g. muffled sound, music played in another room). The Q factor affects the dampening of high frequencies. |
viz.FILTER_HIGHPASS | Passes frequencies above the frequency value and attenuates frequencies below (e.g. telephone speaker). The Q factor affects the dampening of low frequencies. |
viz.FILTER_BANDPASS | Passes a range of frequencies and attenuates frequencies outside that range. The frequency value determines the center of the range and the Q factor determines the bandwidth. |
viz.FILTER_NOTCH | Passes frequencies outside a range and attenuates values inside. The frequency value determines the center of the range and the Q factor determines the bandwidth. |
In the following code, a lowpass filter is applied to muffle the sound source: