Panda3D Manual: Manipulating Sounds
<<prev | top | next>> |
As we said Sound Effects and Music are handled separately in Pand3D. Each can handle 16 different sounds. This value is actually set as the audio-cache-limit in the panda config.prc (found in your install directory) and can be changed. There are times where either sound effects, music, or both should be disabled and later enabled. These commands affect entire categories of sounds. Passing True or False in the last 2 functions will disable or enable the respective groups.
base.disableAllAudio() base.enableAllAudio() base.enableMusic(bEnableMusic) base.enableSoundEffects(bEnableSoundEffects)
Explained below is some advanced audio processing routines. Sound Effects and Music in code are implemented as AudioManager objects. You can access these audio managers with the following code.
soundEffectsMgr = base.sfxManagerList[0] musicMgr = base.sfxManagerList[1]
Notice that sound effects are the first item in the sfxManagerList and the music is next. A few things can be controlled with AudioManager objects. Setting the doppler factor, dropoff factor can be set through these objects. Positional audio is implemented through these objects. A wrapper Audio3DManager class has been implemented to help do positional audio. Audio3DManager takes as input an audioManager and a listener for the sound. A listener is the point of reference from where the sound should be heard. For a player in a Panda3D session, this could be the camera. Sounds further away from the camera will not be loud. Objects nearer to the camera will be loud.
from direct.showbase import Audio3DManager audio3d = Audio3DManager.Audio3DManager(base.sfxManagerList[0], camera)
To create a sound that is positional, you need to use the getsound() function in the AudioManager class and pass 1 as a paramter. e.g.
mySound = base.sfxManagerList[0].getSound('blue.wav', 1)
Sounds can be attached to objects such that when they move, the sound source will move alongwith them. However, this code has undergone changes recently. At the time of this writing, the code is still in flux. The following functions may help, or they may not. UPDATE ME.
audio3d.attachSoundToObject( mySound, teapot )
An update function needs to be called however, to move the object 'carrying' the sound. This update needs to be running in a Task.
audio3d.update()
<<prev | top | next>> |