Panda3D Manual: Loading and Playing Sounds and Music
  <<prev top next>>     

Architecture

The implementation of the sound system in Panda3d allows for a division of audio into two categories - Sound Effects and Music. This division is only a convenience for programmers as Panda3d allows these two audio groups to be treated individually. These differences are explained on the next page.

Basics

Loading a Sound

Loading sound is done through the Loader class. (Loading sounds through the 'base' builtin is deprecated and is only present for backwards compatibility.)

In a normal Panda3D environment, loader is a builtin when you import DirectStart like this:

import direct.directbase.DirectStart

Load the sound, by supplying the path to the sound. Here's an example:

mySound1 = loader.loadSfx("SoundFile.wav")

These will return an object of the type AudioSound. It is necessary to put the extension in the sound filename.


Playing a Sound

To play sounds you can do the following:

mySound.play()


Stopping a Sound

To stop a sound:

mySound.stop()


Querying Sound Status

To check the status of a sound:

mySound.status()

status() returns 1 if it isn't currently playing and 2 if it is playing.


Setting Volume

The volume can be set between 0 and 1 and will linearly scale between these.

mySound.setVolume(0.5)


Panning a Sound

You can change the balance of a sound. The range is between -1.0 to 1.0. Hard left is -1.0 and hard right is 1.0.

mySound.setBalance(-0.5)

NOTE !!!

If running Panda from interactive prompt you must call the Update() command, after you play a sound.

base.sfxManagerList[n].update()

This is because the update() command is called every frame to reset a sound's channel.

In interactive mode Panda's frame update is suspended, and does not run automatically.

  <<prev top next>>