RANDOM USER PROJECTS
Disney's Pirates of the Caribbean Online
Flight Simulator, created by Carnegie Mellon students
Super Duper Mario Bros: a cool variant of an old classic

Panda3D Manual: Manipulating Sounds

Contents

Looping a Sound

To cause a sound to loop (i.e., cause it to repeat once it is finished playing) do the following:

mySound.setLoop(True)
mySound.play()

To stop a sound from looping pass False in the
setLoop
function.

mySound.setLoop(False)

Sounds can also be looped for a certain number of times:

mySound.setLoopCount(n)

Where 'n' can be any positive integer. 0 will cause a sound to loop forever. 1 will cause a sound to play only once. >1 will cause a sound to loop that many times.

NOTE Setting a sound's loop count will automatically set a sound's loop flag to 0 or >1 will automatically setLoop to TRUE.

Notes on Looping Sounds Seamlessly

Looping a sound seamlessly should be as simple as loading the sound, then calling setLoop and play. However, occasionally Panda users have had difficulty getting sounds to loop seamlessly. The problems have been traced to three(!) different causes:

  1. Some MP3 encoders contain a bug where they add blank space at the end of the sound. This causes a skip during looping. Try using a wav instead.
  2. Some have tried using Sound Intervals to create a loop. Unfortunately, sound intervals depend on Panda's Thread to restart the sound, and if the CPU is busy, there's a skip. This is not a seamless method, in general. Use setLoop instead.
  3. There is a bug in Miles sound system, which requires a workaround in Panda3D. At one time, the workaround was causing problems with FMOD, until we devised a new workaround. This bug no longer exists, you can ignore it.

So the easiest way to get a reliable looping sound is to use wav files, and to use setLoop, not sound intervals. Of course, when it comes time to ship your game, you can convert your sounds to mp3, but before you do, test your mp3 encoder to see if it contains the blank-space bug.

Cueing Time

There are getTime, setTime and length functions for sounds. These will respectively, report the current time position, set the current time position and report the length. All these are in seconds.

mySound.length()

will return the length of a sound file in seconds.

mySound.getTime()

will get the current time the 'playback head' of a sound is at in seconds.

mySound.setTime(n)

will set the 'playhead head' of a sound to n (where is seconds).

NOTE Sounds will start playing IMMEDIATELY after the command is issued, and calling play will cause the sound to start over from the beginning.

Changing Playback Speed

To change a sound's playback speed, use:

mySound.setPlayRate(n)

Where n is any float.

Negative numbers will play a sound backwards. Passing the value 0 will pause the sound.

You can also get a sound's play rate with:

mySound.getPlayRate()