Greetings. I’m trying to code my first 3d positional audio program but i’m failing at setting the listener or updating its position. My listener is the camera but the sound’s pan and volume does not change relative to the camera’s position. Could you please provide some tips? My code is below:
from math import pi, sin, cos
#import direct.directbase.DirectStart
from direct.showbase.ShowBase import ShowBase
from direct.showbase import Audio3DManager
from direct.task import Task
from direct.actor.Actor import Actor
from direct.interval.IntervalGlobal import Sequence
from panda3d.core import Point3
from panda3d.core import FilterProperties
class MyApp(ShowBase):
def __init__(self):
ShowBase.__init__(self)
self.scene = self.loader.loadModel("models/environment")
self.scene.reparentTo(self.render)
self.scene.setScale(0.25, 0.25, 0.25)
self.scene.setPos(-8, 42, 0)
self.taskMgr.add(self.gameloop, "gameloop")
self.pandaActor = Actor("models/panda-model",
{"walk": "models/panda-walk4"})
self.pandaActor.setScale(0.005, 0.005, 0.005)
self.pandaActor.setPos(-2, 0, 0)
self.pandaActor.reparentTo(self.render)
# Loop its animation.
self.pandaActor.loop("walk")
self.camera.setPos(20, 10, 0)
self.audio3d = Audio3DManager.Audio3DManager(base.sfxManagerList[0], self.camera)
self.audio3d.attachListener(self.camera)
self.camera.setHpr(0, 0, 0)
mySound = self.audio3d.loadSfx("models/audio/sfx/GUI_rollover.wav")
self.audio3d.attachSoundToObject(mySound, self.pandaActor)
mySound.setLoop(True)
mySound.play()
#fp=FilterProperties()
#fp.addReverb(0.6, 0.5, 0.1, 0.1, 0.1)
#base.sfxManagerList[0].configureFilters(fp)
def gameloop(self, task):
#As long as the procedure spinCameraTask() returns the constant Task.cont, the task manager will continue to call it every frame.
base.sfxManagerList[0].update()
self.audio3d.update()
return Task.cont
app = MyApp()
app.run()