3D audio & hpr bug maybe?

Hi again, I have a nasty problem with 3D positioning and the camera. I took a few tutorials and mashed them together so the pacing panda is a sound emitter that walks past the camera and the camera/listener hears something totally different. There are a few weird cases but the simplest is left and right being reversed.

Funnily enough, while testing this I unknowingly recreated Astelix’s camera.lookAt example here but with my looping continuous sound. So since the camera is moving around in a circle but always pointed at the source, it should always sound centered (equal l+r) but instead it pans all over 360 degrees while the panda walks the line, and also while getting louder and softer which was the only thing I expected…

The camera positioning does not seem to break the panning, only the camera rotation. If you leave out disabling the mouse and moving the camera, you start in the floor while a noisy panda walks over your head sounding rather mono. Then if you move with the left mouse button to any direction, the sound seems to move away in the correct direction but as soon as you rotate, it goes wrong.

Here’s a real straightforward test, can someone tell me if I did something rather wrong or if it’s this way for them too?

from math import pi, sin, cos
from direct.showbase.ShowBase import ShowBase
from direct.task import Task
from direct.actor.Actor import Actor
from direct.interval.IntervalGlobal import Sequence
from panda3d.core import Point3
from direct.showbase.Audio3DManager import Audio3DManager


class MyApp(ShowBase):
	def __init__(self):
		ShowBase.__init__(self)
		base.disableMouse()

		self.camera.setPos(-5.0, 0.0, 1.0)
		self.camera.setHpr(-90.0, 0.0, 0.0)

		self.environ = self.loader.loadModel("models/environment")
		self.environ.reparentTo(self.render)
		self.environ.setScale(0.25, 0.25, 0.25)
		self.environ.setPos(-8, 42, 0)
		
		self.pandaActor = Actor("models/panda-model", {"walk": "models/panda-walk4"})
		self.pandaActor.setScale(0.005, 0.005, 0.005)
		self.pandaActor.reparentTo(self.render)
		
		self.pandaActor.loop("walk")
		
		pandaPosInterval1 = self.pandaActor.posInterval(13, Point3(0, -10, 0), startPos=Point3(0, 10, 0))
		pandaPosInterval2 = self.pandaActor.posInterval(13, Point3(0, 10, 0), startPos=Point3(0, -10, 0))
		pandaHprInterval1 = self.pandaActor.hprInterval(3, Point3(180, 0, 0), startHpr=Point3(0, 0, 0))
		pandaHprInterval2 = self.pandaActor.hprInterval(3, Point3(0, 0, 0), startHpr=Point3(180, 0, 0))

		self.pandaPace = Sequence(pandaPosInterval1, pandaHprInterval1, pandaPosInterval2, pandaHprInterval2, name="pandapace")
		self.pandaPace.loop()

#the questionable audio stuff
		self.audio3d = Audio3DManager(base.sfxManagerList[0], camera)
		self.audio3d.setDropOffFactor(0.2)

		self.mySound = self.audio3d.loadSfx("audio/engine.wav")
		self.mySound.setLoop(True)
		self.audio3d.attachSoundToObject(self.mySound, self.pandaActor)
		self.mySound.play()

app = MyApp()
app.run()

What’s supposed to happen is the camera moves to just off-center, facing sideways (OK I lied, it’s an imaginary straightforward test) so the noisy panda walks directly in front of the listener. What I get instead is the sound on the right which pans left as the panda walks from left to right.

This is using FMOD on Linux; I can’t test with OpenAL because it still hangs, something really sick with my Gentoo because other python audio apps freeze too and the newest Xubuntu barely installed, now freezes the machine rock solid a moment after I login. I’m about to throw this thing so hard… :slight_smile:

I rebuilt Panda3D against the newest FMOD (4.30.00 is out) using a newer GCC and all since I rebuilt everything else on this box trying to get BrainWorkshop to not freeze the way Panda did at first. It made no change in the 3D problem, and never mind the rest. In a bit I’m going to install Panda on a WinXP box to see what I can see. Thanks for any clues.

EDIT: Tried both FMOD and OpenAL on WinXP, same problem.

I found a wav file and stuck it into a directory called audio, and named it engine.wav

I get the message:

:audio(warning): stereo sound /c/Users/Joe/Documents/PandaCode/Misc/audio/engine.wav will not be spatialized

When starting it up, and the sound does not pan at all. I get centered audio the whole time.

I ran into both these bugs when implementing 3d audio features in my game.
Sound coming from wrong direction: https://discourse.panda3d.org/viewtopic.php?t=7423
Sound position not updating with camera (see last post): https://discourse.panda3d.org/viewtopic.php?t=8549

Whoa, I misunderstood the one and outright missed the other somehow, thanks et1337 for the fix and teedee for pointing it out. :slight_smile: