Possible audaspace bug?

hey, don’t normally like to post and pester but I find the audaspace documentation a bit far and few between.

Ive been using audaspace to setup 3d sound and it does work up until the listener position is then changed. normally set to the camera. My guess is that the logic brick 3d sound actuator automatically updates the location and orientation of the listener object every frame? this seems quite costly to me but i guess this is how 3d sound is done am i wrong?.

At the moment if you start a 3d sound with audaspace at some location in 3d space and then move the listener object around, audaspace will not update volume and panning unless the sound is re-played every frame (this is bad :rolleyes:). Ive tried to run just the created aud device every frame but have had no luck in it updating the listener location.

I can post a demonstration blend if ive not been clear. Hoping someone else has come across this problem to.

Thank you for any help.

def play():

    from bge import logic
    import aud
            
    o = logic.getCurrentController().owner
    scene = logic.getCurrentScene()

    if o.sensors["Keyboard"].positive:
        
        device = aud.device()

        invopen = aud.Factory.file("Sounds/sfx/inventoryopen.ogg")

        device.distance_model = aud.AUD_DISTANCE_MODEL_INVERSE_CLAMPED
        device.listener_location = scene.active_camera.worldPosition
        device.listener_orientation = scene.active_camera.worldOrientation.to_quaternion()

        aud.AUD_FORMAT_S16
        aud.AUD_DEVICE_OPENAL

        handle = aud.device().play(invopen)
        handle.volume = 1.00
        handle.loop_count = 0
        handle.relative = False
        handle.location = o.worldPosition

Speculation:
Try updating the listener location each frame.

Because blender’s python is just an interface between it and C, some funny things happen. One of these is that attributes sometimes don’t update. So when you use:
device.listener_location = scene.active_camera.worldPosition
It grabs the current value only.

So if you replay the sound, it grabs the updated location, but if you just move the camera, it uses the old (not moved) location.

At least that would make sense to me.

Thanks for the reply. Yes your thinking was the same as mine also. I have tried updating the listener location every frame but this makes no change. Weird thing is there’s no mention of this being a requirement for 3d sound or even how to correctly update listener location in the audaspace docs which leads me to believe this is a bug.

Im really surprised im the only one to bring this up on the forums after I used the search function I guess people just don’t use audio in the bge very much.

I will keep trying and if I have no luck ill hit the bug tracker.

If you hold down your Keyboard input, does the sound update? Your function works while the keyboard is positive, not when in another state. Might be the problem.

Sent from my Galaxy Nexus using Tapatalk

Ok ive made some more progress and what was previously stated is correct, you do need to update the position and orientation of the listener object every frame if your camera moves around in real time. For some reason it wasn’t happening before.

I guess this is quite good because if you only need to update the listener location you can do only so and possibly save some cpu time, I don’t know what cpu cost this sort of updating every-frame is like yet with many sound sources. ill leave some info here for others in the same boat as me. Wish i could update the audaspace docs now :eyebrowlift2:

So at the moment for testing I just set it up as two separate functions in one script, if you use the code below you can have an always true pulse sensor connected to the update function and start the sound once with the play function using a sensor of your choice.

Im still having trouble updating sound location position every-frame, im getting a (aud.device has no attribute location) even though the attribute/function is in the docs for audaspace. Im probably just not seeing the problem for looking :no:

Ill post a demonstration blend now I got the listener object updating ive come across lots of crackling when 3d sound is panned across the speakers wondering if its just me or not. Maybe someone else can take a look and listen for the crackle it seems its not just with audaspace but with the logic bricks 3d audio as well.

The blend will have to be in a zip as i cant pack audio and then use audaspace im pretty sure.

from bge import logic
import aud

o = logic.getCurrentController().owner
scene = logic.getCurrentScene()
listener = scene.objects['listenerObject']

device = aud.device()

def play():
        
    invopen = aud.Factory.file("mono.wav")

    device.distance_model = aud.AUD_DISTANCE_MODEL_INVERSE_CLAMPED
    
    handle = device.play(invopen)
    handle.volume = 1.00
    handle.loop_count = -1
    handle.relative = False
    handle.location = o.worldPosition

def update():

    device.listener_location = listener.worldPosition
    device.listener_orientation = listener.worldOrientation.to_quaternion()

Attachments

3Dtester.zip (1.27 MB)

i guess to have found the “bug”(if is a bug)
the file must be “mono” to update the volume correctly!

horrible script :


from bge import logic
import aud








class Sound:
    def __init__(self, ob, file):
        self.ob = ob
        self.aud = aud
        self.device = self.aud.device()
        self.device.distance_model = self.aud.AUD_DISTANCE_MODEL_INVERSE_CLAMPED
        
        factory = self.aud.Factory.file(file)
        self.ram = self.aud.Factory.buffer(factory)
        h = self.device.play(self.ram)
        h.volume = 1.00
        h.loop_count = -1
        h.relative = False
        h.location = ob.worldPosition
        self.handle = h
        
    def addFactory(self, key, path):
        factory = self.aud.Factory.file(path)
        self.factories[key] = self.aud.Factory.buffer(factory)  
        
        
    def update(self):
        
        cam = self.ob.scene.active_camera
        
        
        #self.handle.volume = 1 / max(1, cam.getDistanceTo(self.ob))
        
        self.handle.location = self.ob.worldPosition
        
        
        self.device.listener_location = cam.worldPosition
        self.device.listener_orientation = cam.worldOrientation.to_quaternion()
                


        
        
        
import bge
def main(cont):
    own = cont.owner
    if not "init" in own:
        own["init"] = 1
        #own["sound"] = Sound(own, bge.logic.expandPath("//") + "Kick.ogg") # mono ..work
        #own["sound"] = Sound(own, bge.logic.expandPath("//") + "Punch.ogg") # stereo not work
        #own["sound"] = Sound(own, bge.logic.expandPath("//") + "Punch3.ogg") # stereo not work
        #own["sound"] = Sound(own, bge.logic.expandPath("//") + "Punch.wav") # stereo not work
        own["sound"] = Sound(own, bge.logic.expandPath("//") + "Punch_mono.ogg") # mono .. work!!
        
    own["sound"].update()

Mono: For any 3D Audio or Panning effects the sound source has to be single channel, otherwise it’s assumed that the 3D audio and panning information is already present in the multichannel file.

Sent from my Nexus 5 using Tapatalk

Don’t think I was to clear in the start, the sound file is mono. The problem isn’t that the sound was not in 3d it was, but that it wasn’t updating its position in 3d space as the listener object moved around. I have since figured out how to update the listener object now.

Can I ask has anyone noticed crackling in the 3d audio sound when its panned across the listener object? I uploaded a blend to demonstrate. I did some more testing since I discovered this crackle and under linux the audio crackling is non existent (cant test on mac). Also tested two different sound cards under windows with the crackling being persistent across both.

sorry i not see blend before (the sound file is called exactly “mono.wav” xD )

i found a potential problem anyway. (if the file is not mono is played correctly (also the volume at start is “3D”) but changing handle.location do nothing)mono uber alles…

you blend has different problem ,

  1. check the consolle to see error more matter (window -> toggle consolle)
  2. the code even try to update the position of the obj source since the function “play” run only one time

just change the code of “3dtest.py” :
(i tried to change less lines possible)


import bge
import aud


o = bge.logic.getCurrentController().owner
scene = bge.logic.getCurrentScene()
listener = scene.objects['listenerObject']


device = aud.device()


def play():


    file = bge.logic.expandPath("//") + "mono.wav"
    
    factory = aud.Factory(file)


    device.distance_model = aud.AUD_DISTANCE_MODEL_INVERSE_CLAMPED
    
    handle = device.play(factory)
    handle.volume = 1.00
    handle.loop_count = -1
    handle.relative = False
    handle.location = o.worldPosition
    o["handle"] = handle


def update(cont):
    o = cont.owner
    o["handle"].location = o.worldPosition
    
    device.listener_location = listener.worldPosition
    device.listener_orientation = listener.worldOrientation.to_quaternion()



anyway thanks to your piece of code i got finally how use aud module!

Glad it helped MacroIt. Yeah sorry about that didn’t get around to putting in the every-frame update for the sound location position, but I can see you’ve done this in your script. huh thats weird I dont get any console errors with the example I put up, ill check it again.

Oh macroIt seeing as you tried the blend example I put up, did you notice any crackling while the sound was playing and if yes or no, what operating system do you use? trying to gather some info.

Maybe it would be good if this thread was renamed to something like (audaspace 3D sound not updating) so for the people that do use the forum search function can find this to help them, as there’s no documentation on how to do this with audaspace.