2D sound in Corona

I’m looking to add 2D sound to my app.  A couple of years ago I saw a post from a Corona moderator who exposed a few undocumented methods for creating this effect.  I cannot locate this post.  Does anyone have information about these methods?

Alternatively, I can build my own 2D sound module (maybe even a plugin) if I can gain access to the Left and Right outputs of the audio channels - i.e. stereo control.   Currently, all I see in the Corona Audio Guide is channels and volume but no Left/Right control.

Thanks for any insight you can provide.

I did a small experiment or two with the ‘secret audio featuers’  

The word is, there is no guarantee these features will work on all devices.

However, it is still fun to play with:

https://github.com/roaminggamer/RG_FreeStuff/tree/master/AskEd/2015/07/secretAudio

If I find more links/samples I have made, I’ll link them here later.

Yes!  That’s the one, thanks Ed!  Thanks for the samples too.

OK, I went down the rabbit hole of OpenAL for a bit and have returned with a few tips.  I probably won’t be using OpenAL in my current projects but here are a few suggestions for your journey.

  1. Check out ThinMatrix a Java developer with inspiring blogs - one about OpenAL

[media]https://www.youtube.com/watch?v=BR8KjNkYURk&t=15s[/media]

  1. If you want to use 2D sound, referencing a listener and an object, your source sound MUST BE MONO.  Boy did I waste a lot of time trying to figure that one out.

  2. Offset the z value for the listener or the source for better sound quality.  If they have matching z values - the sound transfer left/right will be too abrupt.

  3. Here is some code that gets the basics of positional sound working

[lua]

local soundTable = {

    wood = audio.loadSound( “sound/wood10.mp3” )

}

al.DistanceModel(al.LINEAR_DISTANCE_CLAMPED)

local function sound2D( o, t )

    local mychannel, mysource = audio.play(soundTable[“wood”])

    al.Listener(al.POSITION, o.x/100, o.y/100, 1)

    al.Source(mysource, al.POSITION,  t.x/100, t.y/100, 0.0)

   ---- distance model info -----

    al.Source(mysource, al.ROLLOFF_FACTOR, 1)

    al.Source(mysource, al.REFERENCE_DISTANCE, 2)

    al.Source(mysource, al.MAX_DISTANCE, 15)

end

[/lua]

I look forward to playing around with OpenAL in the future, but for now, it’s time to move on.

That’s pretty cool stuff! 

2D sound really doesn’t work on a small hand held device with a single speaker!

This has inspired me though with my grid based game. I’m building my sound system right now, and I think it would be really neat to have tiles that emit sounds. And they could just get louder or softer based on how close they are to the XY of the player.   :huh:

Not really 2D, left or right. but maybe this idea would be relatively easier…

hmm…  :mellow:

2D sound is best with headphones for sure.  I’ve purchased a few games that start with a headphone prompt  Theoretically it could have some success on iPads and tablets that have multiple speakers (and, of course, desktops) but if the speakers are too close together that could be problematic.  I haven’t tested it on an iPad yet but it was pretty cool on my iPhone with headphones.

I did a small experiment or two with the ‘secret audio featuers’  

The word is, there is no guarantee these features will work on all devices.

However, it is still fun to play with:

https://github.com/roaminggamer/RG_FreeStuff/tree/master/AskEd/2015/07/secretAudio

If I find more links/samples I have made, I’ll link them here later.

Yes!  That’s the one, thanks Ed!  Thanks for the samples too.

OK, I went down the rabbit hole of OpenAL for a bit and have returned with a few tips.  I probably won’t be using OpenAL in my current projects but here are a few suggestions for your journey.

  1. Check out ThinMatrix a Java developer with inspiring blogs - one about OpenAL

[media]https://www.youtube.com/watch?v=BR8KjNkYURk&t=15s[/media]

  1. If you want to use 2D sound, referencing a listener and an object, your source sound MUST BE MONO.  Boy did I waste a lot of time trying to figure that one out.

  2. Offset the z value for the listener or the source for better sound quality.  If they have matching z values - the sound transfer left/right will be too abrupt.

  3. Here is some code that gets the basics of positional sound working

[lua]

local soundTable = {

    wood = audio.loadSound( “sound/wood10.mp3” )

}

al.DistanceModel(al.LINEAR_DISTANCE_CLAMPED)

local function sound2D( o, t )

    local mychannel, mysource = audio.play(soundTable[“wood”])

    al.Listener(al.POSITION, o.x/100, o.y/100, 1)

    al.Source(mysource, al.POSITION,  t.x/100, t.y/100, 0.0)

   ---- distance model info -----

    al.Source(mysource, al.ROLLOFF_FACTOR, 1)

    al.Source(mysource, al.REFERENCE_DISTANCE, 2)

    al.Source(mysource, al.MAX_DISTANCE, 15)

end

[/lua]

I look forward to playing around with OpenAL in the future, but for now, it’s time to move on.

That’s pretty cool stuff! 

2D sound really doesn’t work on a small hand held device with a single speaker!

This has inspired me though with my grid based game. I’m building my sound system right now, and I think it would be really neat to have tiles that emit sounds. And they could just get louder or softer based on how close they are to the XY of the player.   :huh:

Not really 2D, left or right. but maybe this idea would be relatively easier…

hmm…  :mellow:

2D sound is best with headphones for sure.  I’ve purchased a few games that start with a headphone prompt  Theoretically it could have some success on iPads and tablets that have multiple speakers (and, of course, desktops) but if the speakers are too close together that could be problematic.  I haven’t tested it on an iPad yet but it was pretty cool on my iPhone with headphones.