openAL questions

I’m experimenting with the secretive undocumented openAL libraries .

At its simplest implementation I’d like to try and get sound effects corresponding to where a user taps on the screen.

Although I have some understanding of the various APIs, I’m a little baffled by the corresponding values; i.e these commands:

al.Source( mySource, al.ROLLOFF_FACTOR, 1.0 )
al.Source( mySource, al.REFERENCE_DISTANCE, 240.0 )
al.Source( mySource, al.POSITION, y, x, z)

What impact does 1.0, 240, x,y,z have ? Are the x,y,z values corresponding to screen co-ordinates? My guessing is that they relate to the listener (default 0,0,0?), but using somebody else’s code I’m generating x,y and z with the following code:

local x = event.x - display.viewableContentWidth \* 0.5  
local y = event.y - display.viewableContentHeight \* 0.5  
local z = 0  

Which creates values int eh range of -240 to 240 and -160 to 160?!?!

No matter what I tinker with I can’t quite create the effect I’m looking for, essentially a smashed plate on the far right of the screen should only really be heard on the right earphone and vice-versa - that’s just not happening for me.

I should note that I’ve ensured all tracks are mono and my game is played in a landscape orientation, which may be screwing around with the positioning.

Any clarification on these values, or general assistance would be extremely appreciated. [import]uid: 33275 topic_id: 24042 reply_id: 324042[/import]

These are in absolute OpenAL coordinates. Reference distance helps you set a scale. The result you hear from your speakers is the result of the absolute positions of the source compared to the absolute positions of the listener (computed for you by OpenAL automatically).

OpenAL uses the same coordinate system as OpenGL and your math textbook.
On a desktop, the default would be:
x moves left-right (negative on the left)
y moves up-down (positive on the top)
z moves towards/away from the screen (positive comes towards your head)

By default, everything is at <0,0,0>. [import]uid: 7563 topic_id: 24042 reply_id: 96916[/import]

Hi ewing, thanks so much for your help.

Can I just ask one more question; is it safe to assume the above code for calculating positions for the sound based on a user tap is the correct way to move forwards?

I presume these would have to hold some relation to the scale set by al.REFERENCE_DISTANCE?

Sorry that’s two questions really, and I know you have plenty on your hands instead of answering inane openAL questions. [import]uid: 33275 topic_id: 24042 reply_id: 96927[/import]

Just an update - managed to get it all working like a charm, so wanted to thank you again for your assistance.

Was a schoolboy error on my behalf, had the x,y,z co-ordinated calculated within a loop and their scope wasn’t available to al.Source( mySource, al.POSITION, y, x, z) outside of the loop.

Thanks again… [import]uid: 33275 topic_id: 24042 reply_id: 97056[/import]