Sound on native Android is too low with many audio files

Hi,

I’m developing a game which involves a lot of audio clips, and I have detected that when I publish to Android, many of them play at a very low volume. It’s only Android related, as in web and iPhone the audios play correctly. I cannot understand what the problem is, as all the audios are recorded in the same conditions and have the same formats, bitrates, etc…
What’s more strange is, if I scan the QR code from Cocos Creator with an Android device to test it in Chrome, the sounds play at the correct volume.
I’ve already spent two days with this and cannot find what the problem is, I’ve tried to change bitrates, put them in mono instead of stereo, etc… but it’s always the same: Android is the only platform where many of the audios doesn’t work properly.
Have you ever found this problem, is there something I’m forgiving??

Thanks.

We haven’t found this problem.
What’s the version of Cocos Creator you’re using?
Does it only happen on specific android device or on all android devices?
And could you provide a simple demo to reproduce this issue? Thanks.

I’m using Cocos Creator version 3.7.2, and it’s happening in all Android devices I’ve tested.

As an example, I have 2 buttons, each of them plays a different sound. In this links you can find both sounds:

If you play them, they have similar volume and work fine in web and iOS. But in native Android, the second one plays much lower than the first.

Got it, I will have a try.

I created a demo project by creator 3.7.2 and test to play your mp3 files.
I didn’t find the low volume issue on my android devices.

AudioBugTest.zip (290.1 KB)

This is my test project.

Hi,

I’ve downloaded your project. While in web both sounds have equal volume, when I compile in Android there’s one much louder than the other. I’ve uploaded a video to try to show:

Button 2 volume plays lower than Button 1, in the real game there are audios that play really low. I’ve put these ones for testing because they were them both recorded in the same conditions by the same person.

I could hear the difference in the video you updated.Did you test the demo by phone speaker or earplugs?
We didn’t receive any developers who report the same issue and we could not reproduce the issue on our android phones.

I’ve tested now both methods, by phone speaker it happens as you can see, by earplugs surprisingly there is no problem, all sounds play at their correct volume.
My devices are a Samsung Galaxy Tab A8 with Android 13 and an LG Nexus 5X with Android 8.1.0. I don’t know my customer’s devices but I know this also happens to him.

That’s strange.

I only could find that mode_juguem.mp3 is played by native/cocos/audio/android/PcmAudioPlayer.cpp while mode_competicio.mp3 is played by UrlAudioPlayer.cpp.

The difference between them is that we mix all audios that played by PcmAudioPlayer in engine side while the audios played by UrlAudioPlayer are mixed by system.
PcmAudioPlayer’s playing performance is better and it supports 32 clips played at the same time with only use one OpenSLES player instance, while each UrlAudioPlayer uses a OpenSLES player instance. Android system has a limitation of UrlAudioPlayer instances at system level, it means that Android system could only create 32 OpenSLES instances at most.

Perhaps, you could modify threshold to force all your clips played by PcmAudioPlayer and have a test again.

You could modify the AudioPlayerProvider.cpp file

static AudioFileIndicator gAudioFileIndicator[] = {
    {"default", 128000}, // If we could not handle the audio format, return default value, the position should be first.
    {".wav", 1024000},
    {".ogg", 128000},
    {".mp3", 160000}};  // modify this line , make the value bigger to force use `PcmAudioPlayer`

One thing you have to notice is that PcmAudioPlayer needs to decode all pcm data in the mp3 file before it plays, so if the mp3 file is too large, you’d better to preload the audios before playing them.

To modify the AudioPlayerProvider.cpp file for testing, you could modify it directly in engine folder bundled in Cocos Creator, or you could customize the engine and update engine location setting. You could refer to https://docs.cocos.com/creator/manual/en/advanced-topics/engine-customization.html for more details.

I’ve made the following change and now all the sounds play correctly. Thanks for your indications!

1 Like

OK, good to know that the workaround works.

1 Like