As we said Sound Effects and Music are handled separately in Panda3D. 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 loadSfx() function on the Audio3DManager rather than the normal loader.loadSfx() which is for non-positional sounds. e.g.
mySound = audio3d.loadSfx('blue.wav')
|
Sounds can be attached to objects such that when they move, the sound source will move along with them.
audio3d.attachSoundToObject( mySound, teapot )
|
You can use the Audio3DManager's setSoundVelocity() and setListenerVelocity() to set the velocity of sounds or the listener to get the doppler pitch shifting of moving objects. If you would like the Audio3DManager to help you adjust the velocity of moving objects automatically like it does with their position, you can call setSoundVelocityAuto() or setListenerVelocityAuto() like this:
audio3d.setSoundVelocity(sound,velocityVector)
audio3d.setListenerVelocity(velocityVector)
base.cTrav = CollisionTraverser()
audio3d.setSoundVelocityAuto(sound)
audio3d.setListenerVelocityAuto()
|
Currently, for the latter to work, a CollisionTraverser must be attached to base.cTrav as you see in the example. If you already have one assigned to do collision detection that will be sufficient.
The attenuation of moving sounds by distance is based the way sound works in the real world. By default it assumes a scale of 1 panda unit equal to 1 foot. If you use another scale you'll need to use setDistanceFactor to adjust the scale. If you want to position the sounds but don't want the volume to be effected by their distance, you can set the distance factor to 0.
audio3d.setDistanceFactor(scale)
|
|