[Resolved] Help with splitting stereo sounds so that they only use the left or right speaker?

I am making an app which relies on the user being able to identify 2 separate sounds, and so it would be ideal if these 2 sounds could be played in each speaker / earphone independently.

I found a guide which said that the openal functions can be accessed in Corona, and as I have already used this to alter the pitch of sounds I’m fairly sure this is correct. I have tried to use the following to make the sound only use 1 speaker, but the sound still uses both speakers:

-- I have tried using values from 1 up to display.contentWidth as the offset value  
local soundPos = \_W \* 0.5  
  
--i is always 1 or 2 (i.e. left and right)  
if i == 1 then  
 soundPos = -soundPos  
end  
  
--set the x position of the sound source  
al.Source(sounds[i].Source, al.POSITION, soundPos, 0.0, 0.0)  
  
--position listener in the middle  
al.Listener(al.POSITION, 0.0, 0.0, 0.0)  
  
audio.play(sounds.....etc)  
  

Have I missed something obvious? The sounds play just fine, the only part I’m stuck with is making the position of the sound change.

Thanks in advance. [import]uid: 84115 topic_id: 28686 reply_id: 328686[/import]

After a few weeks I finally stumbled across the answer, so if anyone else needs it then here’s what I’ve done:

First, the sounds had to be mono - not stereo.
Second, I had presumed that the al.position x value used screen dimensions, and that -display.contentWidth* 0.5 would be over to the left. This was incorrect, it turns out that I needed to set it to -1 for left and 1 for right:

local soundPos = 1  
   
--i is always 1 or 2 (i.e. left and right)  
if i == 1 then  
 soundPos = -soundPos  
end  
   
--set the x position of the sound source  
al.Source(sounds[i].Source, al.POSITION, soundPos, 0.0, 0.0)  
   
--position listener in the middle  
al.Listener(al.POSITION, 0.0, 0.0, 0.0)  
   
audio.play(sounds.....etc)  
  

Now I have left sounds through the left speaker only, and right sounds through the right speaker only. If you needed to be somewhere in between I’m not too sure how you would do this, as even if I change the position to ± 0.0001 it still moves the sound 100% to the left or right channel. Heopfully this helps someone though :slight_smile: [import]uid: 84115 topic_id: 28686 reply_id: 117689[/import]

Hey Alan,

Sorry, I think this got a little bit buried - it was really good of you to come back and post your solution, I am sure it will help others. (I have never had to play sound through only one speaker so this is fascinating to me!)

Great stuff!

Peach :slight_smile: [import]uid: 52491 topic_id: 28686 reply_id: 117705[/import]

No problem, I suspect that the sound can be even further fine tuned. I was pointed to an app called OpenAl Explorer (I’m told it was made in Corona) which demonstrates how you can move the position of the sound in relation to the listener - but I haven’t come across any source code to be able to do it quite as nicely myself:

http://itunes.apple.com/us/app/openal-explorer/id504578957?mt=8

Also this blog entry is extremely useful for people who need to change pitch, dopplerFactor etc:

http://www.coronalabs.com/blog/2011/07/27/the-secretundocumented-audio-apis-in-corona-sdk/#comment-6079 [import]uid: 84115 topic_id: 28686 reply_id: 117711[/import]

Ah I remember reading about that app on the forum at some point; awesome stuff!

RE that blog entry, funny you should mention that, I just posted that link in another thread - it’s a great resource, thanks for posting it here too :slight_smile: [import]uid: 52491 topic_id: 28686 reply_id: 117851[/import]