openAL source and listener position

I am trying to get the following code working:

local ch, src = audio.play(playbackSoundHandle, { onComplete=onCompleteSound })
al.Listener( al.POSITION, xl, yl, zl )
al.Source( src, al.POSITION, x, y, z )

I’m assuming it works on Apple devices, as I’ve seen ALexplorer (http://developer.anscamobile.com/code/alexplorer) and I haven’t heard anyone say that it doesn’t work for them. However, the position setting is not working for me at all on the simulator on Windows or on Android device builds. Pitch works fine in ALexplorer and in my own code.

I have made sure that my audio files are all mono, and I even explicitly set al.ROLLOFF_FACTOR to make sure it wasn’t set to 0 somehow, but that made no difference.

Here are my system details, if it might make a difference:

Windows: Vista SP1
Android: HTC Desire Android 2.2
Corona: build 591 and 731 [import]uid: 112085 topic_id: 23669 reply_id: 323669[/import]

I did a quick Android test on an HTC PC36100 EVO 4G using the ALexplorer example. I had to go back to build 591 because the sample code needs to be updated. (Volunteers welcome.)

I hacked up the example to play a continuous/looping sound. Moving the x-position slider, I did hear a slight shift using headphones. So I think it is working.

Maybe playing with the AL_REFERENCE_DISTANCE might make things more noticeable.
[import]uid: 7563 topic_id: 23669 reply_id: 95260[/import]

Still no luck :confused: I made my audio looping, set the reference distance to 100, and set my source position x value in the range of -400 to +400.

[code]
local function onCompleteSound(event)
print (“completed sound”)
if restartSound then
ch, src = audio.play(playbackSoundHandle, { onComplete=onCompleteSound })
else
src = nil
end
end

local function onTap(event)
local x = event.x - display.viewableContentWidth * 0.5
local y = event.y - display.viewableContentHeight * 0.5
local z = 0
print (“tap x:” … x … " y:" … y)
if not src then
ch, src = audio.play(playbackSoundHandle, { onComplete=onCompleteSound })
end
al.Source( src, al.ROLLOFF_FACTOR, 1.0 )
al.Source( src, al.REFERENCE_DISTANCE, 100.0 )
al.Source( src, al.POSITION, {x, y, z} )
end
[/code] [import]uid: 112085 topic_id: 23669 reply_id: 95321[/import]

Okay, I figured out the problem. My luaal binding doesn’t handle tables as a parameter to al.Source. You need to pass 3 number values instead of a table for al.Source. I’m a little surprised the program didn’t crash or throw an error.

(You seem to have a pretty good handle on the OpenAL APis, so I’m assuming you would understand the Lua binding code which is publicly posted. Feel free to contribute a patch if you think this should be better.)

Here is the code I got working:

[code]
local function onTap(event)
local x = event.x - display.viewableContentWidth * 0.5
local y = event.y - display.viewableContentHeight * 0.5
local z = 0
print (“tap x:” … x … " y:" … y)

al.Source( src, al.ROLLOFF_FACTOR, 1.0 )
al.Source( src, al.REFERENCE_DISTANCE, 100.0 )
al.Source( src, al.POSITION, x, y, z )
end

playbackSoundHandle = audio.loadSound(“UFO_engine.wav”)
ch, src = audio.play(playbackSoundHandle, { loops=-1})

Runtime:addEventListener( “tap”, onTap)
[/code] [import]uid: 7563 topic_id: 23669 reply_id: 95324[/import]

That works! Thank you so much for figuring that out! I think I was originally passing the position as 3 values, and then I saw them passed as a table in the openAL reference, so I tried that and completely forgot to change it back after making so many other changes. I can finally get back to work on my game idea. Thanks again! [import]uid: 112085 topic_id: 23669 reply_id: 95326[/import]

It works in simulator, in real devices position x has no effect. In simulator ‘y’ and ‘z’ neither. Bug reported. [import]uid: 113117 topic_id: 23669 reply_id: 104287[/import]

Is this on Mac/iOS? If so did you file a bug with us or Apple? To me, this sounds like a bug with iOS because the code for this stuff is identical for Mac and iOS. Please file a bug with Apple and let us know the bug number.
[import]uid: 7563 topic_id: 23669 reply_id: 104302[/import]

i have reported a bug to you…Z and Y position dont work in simulator neither. [import]uid: 113117 topic_id: 23669 reply_id: 104391[/import]