What's the best way to work around audio delay problem on android?

Hi all,

I am currently developing a game in which lots of enemies die in a short time frame(but no enemies die together at the same time). I’ve found that the sound that the device is supposed to play when an enemy dies gets delayed by about .5-1 second, (even if just one of the enemies dies, as opposed to multiple in succession)

The logic for my game is pretty simple. when the enemies get touched, the sound plays, and they die. But on the device, animations of enemies’ dying get played faster than the sound. I am just using

punchSound = audio.loadSound( “audio/fx_punch_or_whack.mp3” )

at the load scene time and

audio.play(punchSound)

when the enemy gets touched.

The device I tested my game on was Galaxy S III from Samsung.
so I did a bit of research into this problem, and some replies by staff to the similar posts mention that it’s a native Android problem, not a problem with Android, and that I will find the same problem with any other apps or games I play on Android. After reading this, I went back to one of the more famous games on Android, “Dragonflight,” to see if the sound indeed was getting delayed, but I could not sense the delay at all. The sound occurred right when it was supposed to, which leads me to believe that either I am doing something wrong, or there is a workaround to this problem.

If there is a solution to my problem, please let me know. [import]uid: 145747 topic_id: 34573 reply_id: 334573[/import]

oops, I meant not a problem with Corona, not “not a problem with Android” [import]uid: 145747 topic_id: 34573 reply_id: 137473[/import]

To improve the latency issues you can use the Corona SDK media.* API for short sound effects when you detect an Android device. You can continue to use the Audio API when running on iOS.
You’ll still experience some latency issues on Android even with the media.* API though.

This is a known issue with Android which has been improved in 4.1 (JellyBean). I’ve used the Audio API on devices with the latest Android release which provides acceptable results on my testing devices.
However, to keep backward compatibility with older devices, I regress to the media API on Android for the time being.

You can still use the audio API for background music/narration on android…

[import]uid: 70847 topic_id: 34573 reply_id: 137481[/import]

Thank you for your response, ingemar. I will try that and see if that improves my situation! [import]uid: 145747 topic_id: 34573 reply_id: 137488[/import]

For short lived time dependant sounds, you probably should use the media.* library instead of audio.* While we would recommend audio of media because it’s using the standard software layer to implement audio, Google can’t seem to get OpenAL to play in a timely fashion. The media.* api plays at the hardware layer and has its limitations like not being able to control volume, etc. [import]uid: 199310 topic_id: 34573 reply_id: 137528[/import]

I tried media.* library and the latency seems to be much less! Thanks for your help! :slight_smile:

I will use this library for now, but I am wondering if there is a plan to merge these libraries together for consistency. It’s nice that media library is far more functional than audio library on Android, but I’d rather have more functionalities available for all devices rather than using a limited library. Does Google have plans for improving the compatibility of OpenAL with Android in the near future, or are we waiting just hoping for an update? I know it’s not your fault that the audio library is functioning slower on Android devices, but if Google is not planning these updates in the near future, then maybe there is a room to consider using audio API other than openAL, at least for Android platforms. As I mentioned, I did check out other games to see if their sound effects also lagged, but I didn’t notice any lag, so my assumption is that they are using an audio API other than openAL. Just a thought :slight_smile:

[import]uid: 145747 topic_id: 34573 reply_id: 137570[/import]

The engineers are very aware of this problem and I know we want our SDK to rock audio, but a lot depends on Google does and I’m not sure anyone really knows what they are doing. Audio seems to be a difficult thing for the vendors to get right. It seems like every release of iOS something breaks audio. Google is making OpenAL worse. [import]uid: 199310 topic_id: 34573 reply_id: 137572[/import]

oops, I meant not a problem with Corona, not “not a problem with Android” [import]uid: 145747 topic_id: 34573 reply_id: 137473[/import]

To improve the latency issues you can use the Corona SDK media.* API for short sound effects when you detect an Android device. You can continue to use the Audio API when running on iOS.
You’ll still experience some latency issues on Android even with the media.* API though.

This is a known issue with Android which has been improved in 4.1 (JellyBean). I’ve used the Audio API on devices with the latest Android release which provides acceptable results on my testing devices.
However, to keep backward compatibility with older devices, I regress to the media API on Android for the time being.

You can still use the audio API for background music/narration on android…

[import]uid: 70847 topic_id: 34573 reply_id: 137481[/import]

Thank you for your response, ingemar. I will try that and see if that improves my situation! [import]uid: 145747 topic_id: 34573 reply_id: 137488[/import]

For short lived time dependant sounds, you probably should use the media.* library instead of audio.* While we would recommend audio of media because it’s using the standard software layer to implement audio, Google can’t seem to get OpenAL to play in a timely fashion. The media.* api plays at the hardware layer and has its limitations like not being able to control volume, etc. [import]uid: 199310 topic_id: 34573 reply_id: 137528[/import]

I tried media.* library and the latency seems to be much less! Thanks for your help! :slight_smile:

I will use this library for now, but I am wondering if there is a plan to merge these libraries together for consistency. It’s nice that media library is far more functional than audio library on Android, but I’d rather have more functionalities available for all devices rather than using a limited library. Does Google have plans for improving the compatibility of OpenAL with Android in the near future, or are we waiting just hoping for an update? I know it’s not your fault that the audio library is functioning slower on Android devices, but if Google is not planning these updates in the near future, then maybe there is a room to consider using audio API other than openAL, at least for Android platforms. As I mentioned, I did check out other games to see if their sound effects also lagged, but I didn’t notice any lag, so my assumption is that they are using an audio API other than openAL. Just a thought :slight_smile:

[import]uid: 145747 topic_id: 34573 reply_id: 137570[/import]

The engineers are very aware of this problem and I know we want our SDK to rock audio, but a lot depends on Google does and I’m not sure anyone really knows what they are doing. Audio seems to be a difficult thing for the vendors to get right. It seems like every release of iOS something breaks audio. Google is making OpenAL worse. [import]uid: 199310 topic_id: 34573 reply_id: 137572[/import]