Media API Sounds Cutting Off

I’m not having luck finding the post where Josh explained this, but basically here’s the problem.

  1. There **WAS** a lag/delay in sounds played through OpenSL, which the audio.* API uses. This was fixed recently by Google in Android 4.2. This has been fixed in our code since the last public build 971. So on Google 4.2 devices, our audio.* API works perfectly. If your device is using an older version of Android, the OpenSL libraries are going to lag.

  2. We offer the less preferred media.* libraries which doesn’t have the lag problem, but can only play one sound at a time and doesn’t have volume controls. This uses the Java SoundPool class which is more direct access to the hardware. While it lacks the lag problem since it’s writing to the hardware, your experience on different devices may vary. If you’re sounds are getting cut off, that sounds like the next sound is trying to play. Make sure you trim off any dead air time from the beginning and ending of your audio clips to minimize this.

[import]uid: 199310 topic_id: 35971 reply_id: 143026[/import]

Thanks,

I’ll code my app to use the Audio API on all but Android < 4.2.

I’d like to add that this sound cut_off problem can be solved by running some sounds using the media.playsound(reward.wav) function. It’s best to preload the sounds at launch and then stop them but it works well enough. I feel this solution should be put into the documentation and not just on forums though. Anyway, I don’t need to consider switching away from Corona now :slight_smile:

I am glad that the audio problem will be fixed as 4.2 become common. Google really messed things up with their OS it seems. I’m glad they are now fixing audio and touch lag but it should have been done long ago. [import]uid: 92709 topic_id: 35971 reply_id: 143048[/import]

Only one sound can be played using the media API. Calling it again with a different sound file will stop the existing sound and play the new sound.

The audio API can handle up to 32 channels at the moment. You can use audio.findFreeChannel() to let the system choose an available channel for you when you have many sounds competing for the same time.
As for the audio-delay on Android it’s unfortunately not possible to know how bad it will be. Some devices are bad some others not so bad and acceptable.

For the sake of clarity, on iOS there’s no delay when using the Audio API. [import]uid: 70847 topic_id: 35971 reply_id: 142996[/import]

Really?? This is quite ridiculous then. I thought the Media API was a substitute for Audio API on Android, not a hobbled workaround. Many Android games can handle multiple sounds so there’s no way this is some issue entirely on the Android side.

This really should be made Priority Number 1 .

I almost feel like my entire efforts are going to be wasted if people start down voting my game because the audio is so crap. I note again that the audio issue only became apparent for me when they replaced the AudioTrack path with OpenSL-ES in the Audio API. It was fine before that and continues to be fine on my Galaxy S1. A version of my game built using an older Corona Build also has no lag on my Galaxy S3 because it was compiled before this change. Please make it an option!!! [import]uid: 92709 topic_id: 35971 reply_id: 143001[/import]

The weird thing is that for me, the audio lag was improved after CoronaLabs changed to OpenSL-ES.
Again this highlights the difficulty of the problem. AudioTrack had an unacceptable lag on my device, which is a Galaxy S1 Player running Gingerbread. [import]uid: 70847 topic_id: 35971 reply_id: 143006[/import]

Yes, I remember you mentioning that in another thread. I don’t get it since my S1 works great. What version is your S1 Android?

Still, it can’t just be Android’s fault since there are many games on the Google market that handle multiple sounds without delay. I wish I would get an answer on this observation. And also, if Corona could perhaps talk to Google themselves to try to get to the bottom of this.

It is a seriously big issue… I can’t understand why it can’t be handled when they’ve done such amazing work on other parts of the SDK like notifications. [import]uid: 92709 topic_id: 35971 reply_id: 143008[/import]

I agree that it’s frustrating, however I’m confident that the guys at CoronaLabs are doing all they can to try to get better audio on Android. [import]uid: 70847 topic_id: 35971 reply_id: 143009[/import]

I’m not having luck finding the post where Josh explained this, but basically here’s the problem.

  1. There **WAS** a lag/delay in sounds played through OpenSL, which the audio.* API uses. This was fixed recently by Google in Android 4.2. This has been fixed in our code since the last public build 971. So on Google 4.2 devices, our audio.* API works perfectly. If your device is using an older version of Android, the OpenSL libraries are going to lag.

  2. We offer the less preferred media.* libraries which doesn’t have the lag problem, but can only play one sound at a time and doesn’t have volume controls. This uses the Java SoundPool class which is more direct access to the hardware. While it lacks the lag problem since it’s writing to the hardware, your experience on different devices may vary. If you’re sounds are getting cut off, that sounds like the next sound is trying to play. Make sure you trim off any dead air time from the beginning and ending of your audio clips to minimize this.

[import]uid: 199310 topic_id: 35971 reply_id: 143026[/import]

Thanks,

I’ll code my app to use the Audio API on all but Android < 4.2.

I’d like to add that this sound cut_off problem can be solved by running some sounds using the media.playsound(reward.wav) function. It’s best to preload the sounds at launch and then stop them but it works well enough. I feel this solution should be put into the documentation and not just on forums though. Anyway, I don’t need to consider switching away from Corona now :slight_smile:

I am glad that the audio problem will be fixed as 4.2 become common. Google really messed things up with their OS it seems. I’m glad they are now fixing audio and touch lag but it should have been done long ago. [import]uid: 92709 topic_id: 35971 reply_id: 143048[/import]