alsa performance improvements


notaz

Certified Guru
Joined
Aug 23, 2005
Messages
4,913
Location
Lithuania
Website
notaz.gp2x.de
While looking at DraStic profiles I saw libasound is taking quite a lot, it turned out to be using ~2% CPU steadily. For this reason I usually used OSS for my emulators as figuring out where performance goes with ALSA lib looked too much work.

Finally I took a stab at it this weekend (with some help of Exophase) and it turned out it's mixing several shared memory buffers in some inefficient way, even if only single program is playing sound in the system. After diving into the code I've found a way to detect if there is one playing process or more and use much more efficient path if there is only one, plus implement all mixing with NEON.

After this the mixing is > 10 times faster and those 2% CPU become something barely measurable. The CPU usage when playing MP3s on mplayer go down from ~8% to 6% (5->3% when overclocked) and there is like ~1-2mA reduced current draw.

The new code is already in the feeds and all ALSA using programs (i.e. most of them) should be slightly faster after running OS update.
 
Fantastic work, I always use OpenAL myself for mobile (where available) but it is ace that anything using ALSA gets a nice win.

Out of interest, is it the view of yourself and Exophase that it could be optimized to a similar (although maybe not quite as much) extent event with multiple processes using the system? I have nothing in mind, just curious.
 
It is really nice that core libraries like SDL and ALSA are getting nicely optimized. E.g. Microbes and NubNub will also benefit (a bit) from this, since they use ALSA.

Do you know how SDL_mixer is doing its mixing? I suppose it does the mixing itself before sending anything to ALSA / OSS/ Pulse / whatever output you pick. Maybe you could put your NEON mixing code also in SDL_mixer.

Finally, I've noticed that libmikmod is kind of slow - it's fine for 4-channel Amiga mods, but it takes quite a large amount of cpu for something like 32-channel .xm's. Perhaps this is another place where your NEON mixing code could help.
 
What would we do without you guys? I'll just cheer a bit over here - YAY!!! HOORAYYY!   :D
 
OK, that sounds nice.

There's only one problem I have with such news: Is it noticeable?

Improving things is always great but if I only read numbers it doesn't tell much to me.

Are 2% speed improvement enough to notice it?

Also how much does the 1-2 mA reduction in power consumption.

How much longer can I listen to music now?

My Giga Pandora is badly broken and my CC Pandora is also in a bad condition.

I can't do any tests my self at the moment.
 
Fantastic work, I always use OpenAL myself for mobile (where available) but it is ace that anything using ALSA gets a nice win.
At least on pandora OpenAL will most likely still go through ALSA - there are 2 ways to reach audio hardware on pandora, either ALSA or OSS emulation, everything else is placed on top of that.

Do you know how SDL_mixer is doing its mixing? I suppose it does the mixing itself before sending anything to ALSA / OSS/ Pulse / whatever output you pick. Maybe you could put your NEON mixing code also in SDL_mixer.

Finally, I've noticed that libmikmod is kind of slow - it's fine for 4-channel Amiga mods, but it takes quite a large amount of cpu for something like 32-channel .xm's. Perhaps this is another place where your NEON mixing code could help.
I used SDL_mixer myself in apkenv (wasn't too impressed by it's limitation of only 1 music per app), but what's using libmikmod besides your game? It's not used it stuff I usually run, and there must be some intersection between "projects that would be nice if they were done" and "projects that I would like to do" to get motivation to do something.

So it's alsa-lib which is improved ?
Yes.

Are 2% speed improvement enough to notice it?
Depends on the person in question (Dunny said he noticed improvement in PandBAS), but for most it won't be noticeable at all.
 
Out of interest, is it the view of yourself and Exophase that it could be optimized to a similar (although maybe not quite as much) extent event with multiple processes using the system? I have nothing in mind, just curious.
Forgot to say that case with multiple streams also has been improved:

http://git.openpandora.org/cgi-bin/gitweb.cgi?p=openembedded.git;a=commitdiff;h=bb3feed69496c7d2e5145bc7dd0c406e4c10b5ea

What about battery life?

Is it noticeable if I just play music with Deadbeef?
It's hard to say, needs to be tested really, but I wouldn't expect it to give more that 5-10minutes at best.
 
Last edited by a moderator:
Thanks for the infos.

Psychology Students are horrible. They always ask what's noticeable ;) .

Of course I also appreciate your efforts :) .
 
Last edited by a moderator:
Do you know how SDL_mixer is doing its mixing? I suppose it does the mixing itself before sending anything to ALSA / OSS/ Pulse / whatever output you pick. Maybe you could put your NEON mixing code also in SDL_mixer.

Finally, I've noticed that libmikmod is kind of slow - it's fine for 4-channel Amiga mods, but it takes quite a large amount of cpu for something like 32-channel .xm's. Perhaps this is another place where your NEON mixing code could help.
I used SDL_mixer myself in apkenv (wasn't too impressed by it's limitation of only 1 music per app), but what's using libmikmod besides your game? It's not used it stuff I usually run, and there must be some intersection between "projects that would be nice if they were done" and "projects that I would like to do" to get motivation to do something.
I should check, but there are probably quite a few games that use mods as background music, and I guess some people just want to listen to their mod collection. But I guess SDL_mixer is more important than libmikmod as a target for optimization.
 
Sorry for OT but is there a chance we get JACK ported/implemented? I've tried to compile it using CodeBlocks but I'm getting some weird "missing symbols" error (don't want to go into details here).

The reason I ask is because most of the modern audio/MIDI apps is built on JACK presence. I'd love to have one day apps like Muse or Qtractor available for Pandora. Thanks in advance for your opinions.

P.S.: Of course is good to read that ALSA gets improved! ;-)
 
Last edited by a moderator:
Back
Top