Audio delay/lag Android

I’m writing a game where I move an object by a swiping motion. Along with the motion a “whoosh” sound is to be played.

In the emulator all is well, but on the device (Samsung Galaxy S5) the audio is clearly delayed and the effect is awful. I have made a minimal example showing this below. The screen changes color when a (horizontal) swipe is detected and then the sound is played a bit delayed:

local MIN\_SWIPE\_LEN = 30 local bg = display.newRect(display.contentWidth/2, display.contentHeight/2, display.contentWidth, display.contentHeight); local whoshSound = audio.loadSound("audio/whosh.wav") -- Channel 1 local inSwipe = false local touchHandler = function(e) local dx = e.x - e.xStart local dy = e.y - e.yStart if (e.phase == "began") then end if (e.phase == "moved") then if (math.abs(dx) \> MIN\_SWIPE\_LEN and inSwipe == false) then bg:setFillColor(math.random(50,100)/100, math.random(50,100)/100, math.random(50,100)/100) audio.stop(1) audio.play(whoshSound, {channel=1,loops=0}) inSwipe = true end end if (e.phase == "ended") then inSwipe = false end return true end Runtime:addEventListener( "touch", touchHandler )

Am I doing anything wrong? 

I’m using Corona SDK Public 2014.2393

If I use the media.* library the las seems to be gone/reduced:

local whoshSoundID = media.newEventSound("audio/whosh.mp3") media.playEventSound(whoshSoundID)

But this makes playing other sounds (at the same time) difficult won’t it? Don’t see any audio channel functionality in that library.

Welcome to the world of Android. This is a known issue and has very little to do with Corona.

You’ve discovered the only solution to minimize lag on Android by using the media.* API for time-critical sound effects on Android (iOS doesn’t suffer from these lag issues). The drawback is that only one sound can be played at a time.

You can mix the audio.* and media.* APIs in your code and only use the media.* API for time-critical sound effects and the audio.* API where you need multi-channel support. I know it’s a trade-off, but it’s something that needs to be done.

This has been discussed/debated on countless threads on this forum. If you search these forums you’ll find several threads talking about this issue. In fact if you search native Android forums as well, you’ll also see similar complaints from native Android developers. Google have made improvements to the Audio implementations over the years, but the sad fact is that some devices lag worse than others, and it’s impossible to tell which ones will lag. The official word is that Android 4.2 should help reduce this lag significantly, but I’ve seen some people saying that even these newer versions can lag.

I’ve got a Google Nexus 7 running Android 4.4.4 which is just fine, whereas another of my Android devices running 4.0.4 is terrible…

Wow… I knew that earlier Android versions did have an issue with audio lag, but I also have heard that this has been greatly reduced for later android versions. That’s why I bothered to start this thread. I simply could not believe that this was an Android (4.4.2) issue…

Thanks, ingemar! This is good news as I can live with only one time critical sound effect. For now…

The weird thing is that I’ve seen the Galaxy S5 mentioned many times regarding audio-lag issues. I’d expect that a device of that caliber not having issues at all. Out of all the post-4.2 devices I’ve come into contact with I have yet to see audio lag worth mentioning. I think I’ll try to get my hands on a GS5 to do my own testing…

Hmm… yes, with my last device, the Nexus 4, I’m pretty sure I was not plagued with this. But that ran 4.4.4. Maybe it’s a GS5-specific issue then…

Yeah, that’s what I’m also starting to suspect…

If I use the media.* library the las seems to be gone/reduced:

local whoshSoundID = media.newEventSound("audio/whosh.mp3") media.playEventSound(whoshSoundID)

But this makes playing other sounds (at the same time) difficult won’t it? Don’t see any audio channel functionality in that library.

Welcome to the world of Android. This is a known issue and has very little to do with Corona.

You’ve discovered the only solution to minimize lag on Android by using the media.* API for time-critical sound effects on Android (iOS doesn’t suffer from these lag issues). The drawback is that only one sound can be played at a time.

You can mix the audio.* and media.* APIs in your code and only use the media.* API for time-critical sound effects and the audio.* API where you need multi-channel support. I know it’s a trade-off, but it’s something that needs to be done.

This has been discussed/debated on countless threads on this forum. If you search these forums you’ll find several threads talking about this issue. In fact if you search native Android forums as well, you’ll also see similar complaints from native Android developers. Google have made improvements to the Audio implementations over the years, but the sad fact is that some devices lag worse than others, and it’s impossible to tell which ones will lag. The official word is that Android 4.2 should help reduce this lag significantly, but I’ve seen some people saying that even these newer versions can lag.

I’ve got a Google Nexus 7 running Android 4.4.4 which is just fine, whereas another of my Android devices running 4.0.4 is terrible…

Wow… I knew that earlier Android versions did have an issue with audio lag, but I also have heard that this has been greatly reduced for later android versions. That’s why I bothered to start this thread. I simply could not believe that this was an Android (4.4.2) issue…

Thanks, ingemar! This is good news as I can live with only one time critical sound effect. For now…

The weird thing is that I’ve seen the Galaxy S5 mentioned many times regarding audio-lag issues. I’d expect that a device of that caliber not having issues at all. Out of all the post-4.2 devices I’ve come into contact with I have yet to see audio lag worth mentioning. I think I’ll try to get my hands on a GS5 to do my own testing…

Hmm… yes, with my last device, the Nexus 4, I’m pretty sure I was not plagued with this. But that ran 4.4.4. Maybe it’s a GS5-specific issue then…

Yeah, that’s what I’m also starting to suspect…