I’ve encountered a bit of an odd audio issue: It seems that, if I have a looping sound attached to the listener of that sound, or updated to have the same position as that listener, rapid changes in position can produce little “bursts” of sound on one side or the other.
Here below is a short program that demonstrates the issue (at least on my machine). Simply run the program, and then press the left- and right- arrow-keys to move the smiley. Quick changes produce more “bursts”, making them easier to detect, but it seems to happen intermittently with any change in direction.
from direct.showbase.ShowBase import ShowBase
from panda3d.core import PandaNode, NodePath
from direct.showbase import Audio3DManager
class Game(ShowBase):
def __init__(self):
ShowBase.__init__(self)
self.disableMouse()
# The 3D Audio Manager
self.audio3D = Audio3DManager.Audio3DManager(self.sfxManagerList[0], render)
# The sound to be played
self.sound = self.audio3D.loadSfx("noise.ogg")
self.sound.setLoop(True)
self.sound.set3dAttributes(0, 0, 0, 0, 0, 0)
self.sound.setVolume(2)
self.sound.play()
# The player-object
self.player = loader.loadModel("smiley")
self.player.reparentTo(render)
self.player.setPos(0, 0, 0)
# Setting up the listener
self.audio3D.attachListener(self.player)
# Attaching the sound
self.audio3D.attachSoundToObject(self.sound, self.player)
# Final setup
self.camera.setY(-40)
self.setupKeys()
self.taskMgr.add(self.update, "update")
def setupKeys(self):
self.keys = {
"up" : False,
"down" : False,
"left" : False,
"right" : False,
}
self.accept("w", self.setKey, extraArgs = ["up", True])
self.accept("w-up", self.setKey, extraArgs = ["up", False])
self.accept("s", self.setKey, extraArgs = ["down", True])
self.accept("s-up", self.setKey, extraArgs = ["down", False])
self.accept("a", self.setKey, extraArgs = ["left", True])
self.accept("a-up", self.setKey, extraArgs = ["left", False])
self.accept("d", self.setKey, extraArgs = ["right", True])
self.accept("d-up", self.setKey, extraArgs = ["right", False])
def setKey(self, key, state):
self.keys[key] = state
def update(self, task):
dt = self.clock.getDt()
# Move the player according to the keys
if self.keys["left"]:
self.player.setX(self.player, -10 * dt)
if self.keys["right"]:
self.player.setX(self.player, 10 * dt)
return task.cont
app = Game()
app.run()
And here is the sound-file used by the above:
noise.zip (16.6 KB)
(The effect isn’t all that prominent with this sound, so you may have to listen closely.)
[edit] Note that this effect seems to also happen if one uses “set3dAttributes” in an update-task instead of “attachSoundToObject”.