Games sound pool alternatives?

redbeardrob

Member
Licensed User
Longtime User
What's the best way to play sound fx? I keep having issues with soundpool and am wondering if there are any alternatives.

I got rid of the stuttering frame rate it was causing by putting it in an audio handler on its own thread, but I still get some crunchy problems playing too many sounds at once. I really don't think it's a hardware limitation, since this is 2022 and phones play fortnight, but it definitely seems like one of many problems inherent to soundpool. I'm not looking for an entire engine to redo my game in, just a way to play sound. I have everything else done and am just trying to clean up sound performance at this point.
Thanks so much for any input!
 

stevel05

Expert
Licensed User
Longtime User
It's difficult to give you advice without knowing exactly how you have implemented it.

For example:
Are you loading many sounds at once? or on demand?
How many sounds? How big are the sound files? What is the duration of the sound files?
What format are the sound files Mp3 / Wav?

Give us some more information and we might be able to help.
 

redbeardrob

Member
Licensed User
Longtime User
I am loading about 70 mp3 files on initial load that are generally all under 2 or 3 seconds. I am not attached to mp3 format if there's a better choice. They play when things happen in an action game, and there can be a lot going on at once. All sounds need to be available. Sometimes it works fine, other times the sounds cut in and out and make the music from the media player cut in and out too.

I have limited polyphony to 4 sounds at once in an attempt to limit cpu, I don't think that's unreasonable. And I still get problems.

The sound pool is running off it's own thread playing sounds from a que of sfx, not being allowed to try to start more than 2 per frame.

I utilize priorities on the sounds so that it should cut lower priority sfx and keep some order on its own.

My internal profiling tool shows the main thread using less than half the time between frames for Cpu and gpu combined, so there should be overhead.


The GPU watch developer tool for Android usually shows a CPU spike of around 50-60% when it's happening, otherwise it sits around 20-30% utilization.

My test device is an S10, it can play Minecraft and stuff fine, so I don't think it should be a hardware issue, I think it's a problem with the way sound pool works.


From what I understand, the sound files are already switched to an internally used format on load, but if changing them will somehow help I'm all for it. I just want it to work and I don't think 4 note polyphony should be that hard. I honestly would use more if it weren't struggling as is.

I can't run sound pool off the main thread or it stutters frame draw.

Does the thread it's on need some kind of priority boost? Is there a better api? Or will changing formats and quality make a difference?

I'm open to suggestions and just figuring someone knows better than me cause games exist on Android that run fine. I don't think I can give you more details? If sound file sample rate matters I can look, but I think sound pool would automatically truncate sounds that would be over the 1mb limit from what the Android web page says. Thanks for any help!
 

stevel05

Expert
Licensed User
Longtime User
I haven't worked with games or anything that demanding, so have never had a problem with soundpool, there are some threads on StackOverflow about some issues and you might find some optimization suggestion there that may help you.

As you say, the files are stored internally once loaded, So unless you were constantly loading files, it shouldn't make too much difference which format you use. Wav files would probably load slightly quicker even though they will be bigger, as they would not have to be decompressed.

The other option would be to look at using OpenSL, I just did a quick search on the forum and Informatix created a library 9 years ago which he is not supporting, but might be worth a try it just to see if there is an improvement. Assuming it is still working with recent operating systems.

How much RAM is left while the game is running?
 

redbeardrob

Member
Licensed User
Longtime User
Thank you so much! That's the type of thing I was hoping to see and could not find. I had tried everything from stack overflow to mitigate soundpool issues and best I could do was replace app wide stuttering with stuttering sound.

Open SL completely removes the Cpu spikes and the stuttering, and works along side the media player, which is great cause this implementation of OpenSL does not currently support pause and resume for music, but it's got potential for Sound effects. It does have some clicking sometimes and does not have any priority management built in, but it might be better than sound pool for me, I need to play with it.

It has introduced a crash on one sound so far I'm going to try to figure out, and I'll see if this goes anywhere.

Thanks so much.

It's understandable but a shame that Informatix doesn't want anything to do with it, there's as lot of potential in OpenSL. I might have to look into the "native wrapper library" and see if it can just port the whole Open SL C library. I've never messed with any of that but it would be incredible to have more of the Open SL features available. If anyone gets bored and wants to try that I would appreciate it, otherwise I'm going to try to work out where this crash is tomorrow and see if it's good enough to move forward with in it's current state, or where I need to put focus.

Oh and RAM was not an issue, 4gb free and the app uses 27-256mb
 

stevel05

Expert
Licensed User
Longtime User
No problem.

If you do look at creating a wrapper library there is information on Android Developers web site that you may find useful.


Let me know how it goes.
 

redbeardrob

Member
Licensed User
Longtime User
For if anyone else ends up here, Open SL is for sure the way to go, and it looks like it's good enough in this state to beat sound pool.

Turns out it doesn't need a priority system when you can just up the max channels. I'm running 30 sounds at once and there's no performance hit or problems, and no need to run on a separate thread. The clicking also went away by setting the stereo source to true on initialization. It's just better than sound pool in every way unless you need the pitch function, just gotta use wav files and sometimes it's picky about them.

Since it's good enough for my purposes I won't do that wrapper now, but maybe once I finish this project I'll look into learning it.
 
Cookies are required to use this site. You must accept them to continue using the site. Learn more…