Panda3D Manual: Manipulating Sounds
<<prev | top | next>> |
## Looping a Sound To cause a sound to loop [IE 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, occassionally Panda users have had difficulty getting sounds to loop seamlessly. The problems have been traced to three(!) different causes: 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. 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. 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. & Calling play() will cause the sound to start over from the beginning. ## Changing Playback speed You can change the rate at which a sound plays back. To change a sounds playback speed use....
    mySound.setPlayRate(N)
Where N is any float. NOTE!!! Negative numbers will play a sound backwards. 0 is 'Pause' a sound. You can also get a sound's play rate with..
    mySound.getPlayRate()
<<prev | top | next>> |