Sounds and Android

I have tried everything i can think of to fix the delay in my soundfx. Im running the game on galaxy s4 with android 4.3 and ether the sounds are super delayed or the game lags very badly. In total im only trying to load up 2 sounds at the moment on a level i would not consider very physics heavy. Im not sure what to do my game is about 80% complete but i can find a suitiable fix for this and its really holding up my release. Anyone have any suggestions?

I used this first because my soundfx are all under 3 seconds each and because it allows for more then 1 channel to be in use. My game becomes very laggy sounds are not very delayed but everything else is. Movment, buttons, animations and so on.

media.playEventSound( soundID )

Then i tried this and the lag goes away completely along with sound delay however this only allows for 1 channel to be in use at a time. My game requiers the ability to play more then just one sound at time.

media.playSound( soundID )

Next up was the newer audio api. The sound delay with this is so bad that when the user would press jump the player would hit the ground before the sound effect would play.

audio.loadSound() audio.loadStream()

Can you provide the exact code you are using to call your sounds? I have quite a few sfx running in my game and the majority of my personal testing is on Android. I don’t see much of a lag. Here’s what I use to call my sfx:

local function loadHealthIncSound() healthIncSFX = audio.loadSound("media/sfx/healthIn3.wav") end local function healthIncSound() healthIncSoundChannel = audio.play( healthIncSFX ) end -- In some other scene... music.healthIncSound()

Have you read through the audio tutorial that Rob put up? I found it very useful in understanding how my sounds and music would be handled:

http://www.coronalabs.com/blog/2013/06/04/tutorial-handling-cross-scene-audio/

I do this at the top of my level file.

local deathfx = audio.loadSound( "sound/fx/death.wav" ) local function playDeath() deathPlay = audio.play( deathfx ) end

Here i play the sound if death is true

local function hasDied () -- This function has a runtime listener if death == true then playDeath() -- Play the sound elseif death == false then --Do something end end

Question @panc software what does your config look like and what frequency are your audio files saved as?

There’s nothing special about my config; Pretty standard 480x320, plus I don’t think that would have an effect on audio performance.

As far as my sound files, I’ve got a mix between mp3s and wavs. Most of the wavs are at 705kbps. I can’t imagine that makes much of a difference, but you be the judge there.

I now recall that I was having some significant lag issues with testing on iOS (Android was fine) and when I switched from loadStream to loadSound they seemed to be resolved. Have you tried mapping your sfx to a button to test the best way to call them? I’d suggest starting with hardcoded button mapping with the sound explicitly loaded and played when you press it. 

If you don’t want to try that, I’d suggest forward declaring your sound variable at the start of your module. Something like this:

local deathfx deathfx = audio.loadSound( "sound/fx/death.wav" ) local function playDeath() deathPlay = audio.play( deathfx ) end

Maybe that will help? Sound can be very finicky with Corona so I’m not surprised that issues arise. Let me know if you are still running into issues.

Reason i asked is cause in config you can specify your “audioPlayFrequency” i was not sure if you did this or not. To avoid sample rate conversions from occuring i set my frequency to 44100 in config and re sampled all my audio files to match but the delay still persists. Ill give what you said a try and report back.

Yea, my config is pretty vanilla as far as audio setup is concerned. In trying to remember what issues I has when I was implementing my SFX.

Have you tried running the sample apps that come with corona to have a control group? That helped me to isolate where my issues were coming from.

I tried everything i can think of im going to have to just deal and use media.playSound. I may take another look at this in the future and see if i can solve the problem then but for now ill just deal.

Can you provide the exact code you are using to call your sounds? I have quite a few sfx running in my game and the majority of my personal testing is on Android. I don’t see much of a lag. Here’s what I use to call my sfx:

local function loadHealthIncSound() healthIncSFX = audio.loadSound("media/sfx/healthIn3.wav") end local function healthIncSound() healthIncSoundChannel = audio.play( healthIncSFX ) end -- In some other scene... music.healthIncSound()

Have you read through the audio tutorial that Rob put up? I found it very useful in understanding how my sounds and music would be handled:

http://www.coronalabs.com/blog/2013/06/04/tutorial-handling-cross-scene-audio/

I do this at the top of my level file.

local deathfx = audio.loadSound( "sound/fx/death.wav" ) local function playDeath() deathPlay = audio.play( deathfx ) end

Here i play the sound if death is true

local function hasDied () -- This function has a runtime listener if death == true then playDeath() -- Play the sound elseif death == false then --Do something end end

Question @panc software what does your config look like and what frequency are your audio files saved as?

There’s nothing special about my config; Pretty standard 480x320, plus I don’t think that would have an effect on audio performance.

As far as my sound files, I’ve got a mix between mp3s and wavs. Most of the wavs are at 705kbps. I can’t imagine that makes much of a difference, but you be the judge there.

I now recall that I was having some significant lag issues with testing on iOS (Android was fine) and when I switched from loadStream to loadSound they seemed to be resolved. Have you tried mapping your sfx to a button to test the best way to call them? I’d suggest starting with hardcoded button mapping with the sound explicitly loaded and played when you press it. 

If you don’t want to try that, I’d suggest forward declaring your sound variable at the start of your module. Something like this:

local deathfx deathfx = audio.loadSound( "sound/fx/death.wav" ) local function playDeath() deathPlay = audio.play( deathfx ) end

Maybe that will help? Sound can be very finicky with Corona so I’m not surprised that issues arise. Let me know if you are still running into issues.

Reason i asked is cause in config you can specify your “audioPlayFrequency” i was not sure if you did this or not. To avoid sample rate conversions from occuring i set my frequency to 44100 in config and re sampled all my audio files to match but the delay still persists. Ill give what you said a try and report back.

Yea, my config is pretty vanilla as far as audio setup is concerned. In trying to remember what issues I has when I was implementing my SFX.

Have you tried running the sample apps that come with corona to have a control group? That helped me to isolate where my issues were coming from.

I tried everything i can think of im going to have to just deal and use media.playSound. I may take another look at this in the future and see if i can solve the problem then but for now ill just deal.