This Time Self-Hosted
dark mode light mode Search

Minimising alsa-lib

As I said before, I’ve been working on trying to improve the ALSA packages in Gentoo, so you can see in 1.0.14 series that the ALSA_CARDS values are shown by portage so that you know which one you can enable, and at least for some of them you get a failure if you try to enable them without the correct configuration options in the kernel.

Today, I wanted to try minimising the footprint of alsa-lib, as that is a library that almost every system has loaded in a few instances.. the trick I had in mind (and I have locally realised) is to allow users to choose the PCM plugins they want to compile in the library… the PCM plugins are things like dmix and dsnoop (used for software mixing of, respectively, output and input), iec958 (passthrough digital audio) and plug (resampling), but they are not the only ones of course. They are the bricks that compose the asound.conf files.

Of course a normal system rarely uses all of the plugins that are usually built in alsa-lib, and for some particular setups (mine included), the used plugins are very very limited. That’s why attacking the amount of plugins built was my first choice, so I created an ALSA_PCM_PLUGINS variable and used that to decide what had to be built and what not; in my case just plug and iec958, as I use PulseAudio for software mixing (I also have some space for hardware mixing if I need to bypass PulseAudio) and plug is pretty much a Swiss knife.

Also, there’s the ALISP interpreter used for very complex setups, and there is the whole support for MIDI stuff (instruments, sequencers, sample loaders, rawmidi output) that is unlikely to be used on most of modern systems (MIDI has a pretty much limited use nowadays, considering the kind of sound cards we have available; even software like Audacious that play .mid files is simply using software synthesis rather than hardware instruments).

My pretty much limited setup shows now this:

[ebuild   R   ] media-libs/alsa-lib-1.0.14_rc1  USE="-alisp -debug -doc -midi"
ALSA_PCM_PLUGINS="-adpcm -alaw -asym -copy -dmix -dshare -dsnoop -empty
-extplug -file -hooks iec958 -ioplug -ladspa -lfloat -linear -meter -mulaw -multi
-null plug -rate -route -share -shm -softvol" 0 kB

and the size of the package (built with -ggdb) is down from 6.4MB to 3.4MB now, that’s almost half of the previous size. Considering that a big part of that package is composed of configuration files, the size of the library decreased sensibly.

I’m waiting to hear comments on gentoo-dev before proceeding with adding the variable, the defaults and the ebuild itself, but if all goes as I hope, alsa-lib from Gentoo would be also simpler to use on embedded devices.

Comments 4
  1. Interesting idea.I have only a limited understanding of how ALSA works, but I’d like to suggest some thoughts.I think dmix (and dsnoop?) should be included in the “sane default setting”, along with other “sane defaults”. Specifically:

    if ALSA_PCM_PLUGINS=="" # not set by the userthen ALSA_PCM_PLUGINS="${ALSA_PCM_PLUGINS} dmix dsnoop"

    I am mentioning this because in absence of software mixers like arts/esd/pulseaudio, it might be nice to allow them to have dmix as a fallback.

  2. I forgot to add it in the entry, but at least I remembered of this when I mailed gentoo-dev before 🙂 the default will be always to build *all* of the plugins; the user can decide to disable or enable them as he likes.

  3. This is a very welcome improvement. Nothing makes me happier then compiling out unused complexity.

  4. I stumbled on this on this post a while ago and gave it a shot on my computer which has lousy HDA audio (Athlon X2 4200+ AM2 on a nForce 430 with GeForce 6150 integrated graphics). Because aRts pissed me off a few years ago (when I was on Mandr*), I do not use any sound server.After several trials and errors, I have working notifications on KDE 3.5.9 and am able to use audacious. Savings were much less for me. The tbz2 went from 838 Kib to 678 Kib.ALSA_PCM_PLUGINS="dmix dsnoop iec958 plug empty asym softvol route rate"CFLAGS="-march=athlon-xp -O2 -pipe -fomit-frame-pointer -mno-tls-direct-seg-refs"Note that I am using the stable Hardened GCC (3.4.6), which means no Qt4 for me. Also, -march=athlon64 is broken in that GCC version. Last CFLAG is to make Xen happy.

Leave a Reply

This site uses Akismet to reduce spam. Learn how your comment data is processed.