Audio Questions: What Channel?

Newbie Question:
I’ve gotten a sound associated with an image object to not restart playing every time a new touch event begins (which happens as it’s dragged or tapped on).

If I add more sounds, how do I know what channel a sound has - I only knew because I tested the number “1”. But I want the program to figure it out itself so I don’t have to manually code in the number of every channel. I Looked through the audio API at http://developer.anscamobile.com/reference/audio
but nothing seems to tell you what channel a sound is playing in?

Here’s the section in question:

function myImage.touch(self, event)   
 if event.phase == "began" then  
 self.storeX = self.x   
 self.storeY = self.y   
 --if audio.isChannelPlaying(1) ~= false then print("audio channel 1 playing" ) end --TEST CHANNEL  
if audio.isChannelPlaying(1) ~= true then audio.play( mySound ) end -- PLAY SOUND  
 elseif event.phase == "moved" then  
 local x = (event.x - event.xStart) + self.storeX   
 local y = (event.y - event.yStart) + self.storeY   
 self.x, self.y = x, y   
 elseif event.phase == "ended" then print( "ended" ) -- for testing  
 end   
 return true  
end  
  

Thanks

Eric [import]uid: 128346 topic_id: 23774 reply_id: 323774[/import]

The channel assigned to a sound is returned by the audio.play() function, but if you have a case where you do not want sounds to pile up, like you describe, your best bet is to manage the channel for that sound explicitly – reserve that channel, and then specify that channel in your call to play(), then you always know that channel 1 is your channel for that sound. [import]uid: 44647 topic_id: 23774 reply_id: 95618[/import]

Makes sense.

I wonder where one should put the audio.reserveChannels( ) command – near where you load the sound (audio.loadSound) perhaps, like right before it, or does it matter? I guess it doesn’t matter, as long as it’s before the play command, since sounds are not loaded into channels, only played etc. in them.

As evidence for this, the API description for audio.loadSound() mentions sounds may be used on multiple channels:
“…Files that are loaded completely into memory may be reused/played/shared simultaneously on multiple channels so you only need to load one instance of the file.” [import]uid: 128346 topic_id: 23774 reply_id: 95622[/import]