Problems with Audio on Android since yesterday

We’ve been experiencing problems with audio channels on android builds of our app since the last day or so. 

Audio on certain channels seems to sporadically change its volume without any initiation for doing so in the programme and a substantial lag also seems to be present between the play() calls and the time the audio actually plays.

iOS builds don’t seem to have this problem nor do simulator versions on macOS/ Win.

Any insights would be appreciated. 

UPDATE:

It seems that the volume level problem occurs when I play another sound on the first available channel. I attempted to debug by printing this channel number of the said sound effect-- on iOS and desktop, an appropriate, free channel is usually picked (for e.g., channel 6) but when I debugged on Android, it returns 0 for the channel, which didn’t seem to make a lot of sense to me. 

I should also clarify that this is not because I am playing too many sounds-- at any given time, there are at least 25 free channels available

Have you changed versions of Corona recently?

Thanks

Rob

Hi Rob,

No, I’ve been on the same version for quite a while. I figured that I should build using the latest stable version to see if that would help and I did update Corona but the problem remains. 

I have gone over my code multiple times and there really is nothing exceptional about the implementation of how we’re playing the sound that causes this behaviour. What’s also interesting is that the channel which suffers from the sudden change in level is a reserved channel and we handle the volume, pause and resume operations of that channel manually-- one can maybe explain if sounds playing on the first available channel get mixed up but I don’t see why the system would interfere with a channel that is reserved right from the start of execution. 

Have you tried rolling back to an older version of your project to see if it works OK?

Can you post you code that you’re using to find the free channel, play the sound and determine that you’re getting 0 on Android?

Thanks

Rob

function soundManager.playImpactSound()

     local ch

     

     ch=audio.play(impactSound1)

     audio.setVolume(0.9, {channel=ch})

   

     toast.showToast("soundManager: impact played on channel "…ch)

end

That’s the essential code of the function where I play a preloaded sound called impactSound1 on an available channel, fetch a reference to the channel, set a volume and then call a toast script that slaps that string on top of the display. 

“ch” is 0 on android for some reason.

here is a handy function for playing soundFX… (taken from my sfx class)

function sfx.play( handle, timeDelay ) if handle then if timeDelay then timer.performWithDelay( timeDelay, function() local availableChannel = audio.findFreeChannel(6) if availableChannel \> 5 then audio.play( handle, { channel = availableChannel } ) end end) else local availableChannel = audio.findFreeChannel(6) if availableChannel \> 5 then audio.play( handle, { channel = availableChannel } ) end end end end

Thanks for posting this but I don’t see how this could resolve the problem we were facing-- doesn’t the standard play() call of the API anyway look for a free channel?

Also wanted to update anyone who might be interested that the problem turned out to be in the mp3 sound that we were using-- still don’t know what the exact issue with the sound was since we used the same encoding as we do for all other audio but when I changed this for another mp3 sound as a last resort, things went back to normal.

If anyone wants me to run any further tests to rule out issues in the SDK, just ask! 

Cheers!

Just for educational purposes… yes audio.play() will find a free channel but that might find a free “reserved” channel that you have set up for other purposes with different configuration.

For example, I reserve the first 5 channels for music but not all channels may be playing at the point I call audio.play() so therefore Corona might assign channel 3 when I don’t want it to.

I post code, not just for you, but for others too.

P.S. with a complicated audio setup it is always best practise to set your audio levels before loading sounds or streams.

It will NOT find a free channel that is also a reserved channel-- that is the very purpose of reserving channels. You example, as far as the API documentation goes, is wrong.  https://docs.coronalabs.com/api/library/audio/reserveChannels.html

You’re also quite welcome to post snippets of code for the community’s benefit-- never said you didn’t need to post the code that you did-- only responded to you based on the nature of the specific problem being discussed on the thread. 

You are correct with regard to the API… but I said _ “reserved” _ meaning a soft reserve not a hard reserve - via reserveChannels()

Yes, audio.play() should find a free channel. But that doesn’t mean that the OpenAL code on the particular device you’re testing on doesn’t have a bug in it’s library. Sometimes fixing bugs means working around them in particular in the Android world where you’re trying to run on 12 different operating system versions.

My advice is to find a free channel, make sure it’s not 0, and if so play your sound on that specific channel and don’t just blindly use the return value from audio.play.  

Rob

Wasn’t a problem with one device but with android builds running across 10-12 different devices and different versions of the Android OS. Anyway, as I said in an earlier post-- turned out to be the sound clip which was causing the behaviour. Marking as solved. 

Have you changed versions of Corona recently?

Thanks

Rob

Hi Rob,

No, I’ve been on the same version for quite a while. I figured that I should build using the latest stable version to see if that would help and I did update Corona but the problem remains. 

I have gone over my code multiple times and there really is nothing exceptional about the implementation of how we’re playing the sound that causes this behaviour. What’s also interesting is that the channel which suffers from the sudden change in level is a reserved channel and we handle the volume, pause and resume operations of that channel manually-- one can maybe explain if sounds playing on the first available channel get mixed up but I don’t see why the system would interfere with a channel that is reserved right from the start of execution. 

Have you tried rolling back to an older version of your project to see if it works OK?

Can you post you code that you’re using to find the free channel, play the sound and determine that you’re getting 0 on Android?

Thanks

Rob

function soundManager.playImpactSound()

     local ch

     

     ch=audio.play(impactSound1)

     audio.setVolume(0.9, {channel=ch})

   

     toast.showToast("soundManager: impact played on channel "…ch)

end

That’s the essential code of the function where I play a preloaded sound called impactSound1 on an available channel, fetch a reference to the channel, set a volume and then call a toast script that slaps that string on top of the display. 

“ch” is 0 on android for some reason.

here is a handy function for playing soundFX… (taken from my sfx class)

function sfx.play( handle, timeDelay ) if handle then if timeDelay then timer.performWithDelay( timeDelay, function() local availableChannel = audio.findFreeChannel(6) if availableChannel \> 5 then audio.play( handle, { channel = availableChannel } ) end end) else local availableChannel = audio.findFreeChannel(6) if availableChannel \> 5 then audio.play( handle, { channel = availableChannel } ) end end end end

Thanks for posting this but I don’t see how this could resolve the problem we were facing-- doesn’t the standard play() call of the API anyway look for a free channel?

Also wanted to update anyone who might be interested that the problem turned out to be in the mp3 sound that we were using-- still don’t know what the exact issue with the sound was since we used the same encoding as we do for all other audio but when I changed this for another mp3 sound as a last resort, things went back to normal.

If anyone wants me to run any further tests to rule out issues in the SDK, just ask! 

Cheers!