Gentoo Linux ALSA Guide
1. The Advanced Linux Sound Architecture
What is ALSA?
ALSA is the Advanced Linux Sound Architecture, a project dedicated to the
development of a high-quality Linux sound subsystem. It has replaced OSS
(Open Sound System) as default sound subsystem in the 2.6 kernel series.
ALSA provides efficient support for all types of audio interfaces, is fully
modularized, is SMP and thread-safe and provides a high-quality user space
library called alsa-lib to simplify application programming. It also
provides a backwards compatibility layer with OSS.
2. Installing ALSA
Gentoo provides an alsa USE flag which you should set in
/etc/make.conf to allow our available packages to compile with
ALSA support. If you have oss in your USE variable as well, ALSA will
compile with OSS backward compatibility.
First of all, before continuing, make sure your kernel has Sound Card
Support enabled. If you used genkernel to build your kernel, then
this is automatically true. Otherwise reconfigure your kernel.
If you use a 2.6 kernel you can skip the rest of this section and continue with
Installing the ALSA Utils as 2.6 already has the
necessary ALSA drivers in it. Of course, don't forget to enable support for the
sound card you have when configuring your kernel.
Users of 2.4 kernel sources will have to install the necessary ALSA drivers for
their soundcard. First find out what soundcard you have. An easy trick is to
search for "audio" in the output of the lspci command. You can install
it with emerge pciutils.
Code Listing 2.1: Finding out the soundcard type
# lspci | grep -i audio
Multimedia audio controller: VIA Technologies, Inc. VT82C686 AC97 Audio Controller (rev 64).
Now go to the ALSA Soundcard
Matrix and search for your soundcard. In the above example you should go
to the "VIA" manufacturer. You will receive a table with the known chipsets of
that vendor. The chipset in the above example is "via82c686"; the "Details" link
then informs me that the driver is called via82xx. This is all the
information you need, so you can safely discard the rest of that document.
Based on this information we can now install the alsa-driver for our
soundcard. First edit /etc/make.conf and add a new option
called ALSA_CARDS to it. Inside this variable you declare the soundcard driver
you want to use:
Code Listing 2.2: Editing /etc/make.conf for ALSA_CARDS
Now install alsa-driver:
Code Listing 2.3: Installing ALSA Drivers
# emerge alsa-driver
Whenever you (re)compile your kernel sources, chances are that the ALSA drivers
will be overwritten. It is therefore adviseable to rerun emerge
alsa-driver every time you (re)compile your kernel after having
rebooted into the new kernel.
Installing the ALSA Utils
If you want backwards compatibility with OSS, you need to install
Code Listing 2.4: Installing the ALSA OSS compatibility layer
# emerge alsa-oss
Now install the ALSA Utils on your system (this is mandatory):
Code Listing 2.5: Installing ALSA Utils
# emerge alsa-utils
Now that the utils are installed, it is time to configure ALSA...
3. Configuring ALSA
Automatically Loading the Kernel Modules
If you use a modular kernel (such as when using genkernel) you have to
edit /etc/modules.d/alsa so that it activates the necesary modules
at boot time. For the soundcard in our example:
Code Listing 3.1: /etc/modules.d/alsa
alias snd-card-0 snd-via82xx
alias sound-slot-0 snd-card-0
alias /dev/mixer snd-mixer-oss
alias /dev/dsp snd-pcm-oss
alias /dev/midi snd-seq-oss
Now run modules-update to save the changes you made to the
alsa file into /etc/modules.conf:
Code Listing 3.2: Running modules-update
Verifying the Device Files
If you use DevFS (which is the default for Gentoo installations) make sure that
/etc/devfsd.conf has the ALSA devices and permissions correctly
Code Listing 3.3: /etc/devfsd.conf
# ALSA/OSS stuff
# Comment/change these if you want to change the permissions on
# the audio devices
LOOKUP snd MODLOAD ACTION snd
LOOKUP dsp MODLOAD
LOOKUP mixer MODLOAD
LOOKUP midi MODLOAD
REGISTER sound/.* PERMISSIONS root.audio 660
REGISTER snd/.* PERMISSIONS root.audio 660
Having ALSA Activated at Boot
To activate ALSA support at boot, add the alsasound init script to the
Code Listing 3.4: Adding alsasound to the boot runlevel
# rc-update add alsasound boot
# /etc/init.d/alsasound start
Unmute the Channels
By default, all sound channels are muted. To fix this, run amixer:
Code Listing 3.5: Running amixer
If amixer produces lots of output then you're ready to unmute the
channels. If you receive an error, doublecheck that your soundcard module is
Now unmute the Master and PCM channels. If this isn't sufficient,
also unmute the Center and Surround channels.
Code Listing 3.6: Unmuting the sound channels
# amixer set Master 100 unmute
# amixer set PCM 100 unmute
# amixer set Center 100 unmute
# amixer set Surround 100 unmute
To check if your sound works, play a wave file (using aplay), mp3 (using
mpg123 or even mplayer) or any other sound file for that matter.
To fine-tune the sound channel settings you can use the alsamixer
4. Activating MIDI Support
Installing the Necessary Packages
Some soundcards come with onboard MIDI synthesizers. To use them, you must first
install the awesfx package:
Code Listing 4.1: Installing the awesfx package
# emerge awesfx
If you have a collection of sound fonts somewhere, place them in
/usr/share/sfbank. For instance, the SBLive has a sound font file
called 8MBGMSFX.SF2 or CT4GMSFX.SF2.
After copying over the sound font, select them using asfxload:
Code Listing 4.2: Loading the sound font
# asfxload /usr/share/sfbank/8MBGMSFX.SF2
You must have this command run every time you boot, so it is adviseable to add
it to /etc/conf.d/local.start as well.
If you can't find soundfonts on your driver CD you can download some online from
Timidity++ Virtual Synthesizer
If your sound card does not come with a hardware synthesizer (or you don't want
to use it), you can use timidity++ to provide you with a virtual
synthesizer. Start by emerging this package:
Code Listing 4.3: Installing Timidity++
# emerge timidity++
For timidity to play sounds, it needs a soundfont. If you do not have any,
install timidity-eawpatches which will give you some soundfonts.
Code Listing 4.4: Installing timidity-eawpatches
# emerge timidity-eawpatches
Don't forget to add timidity to the default runlevel.
Code Listing 4.5: Adding timidity to the default runlevel
# rc-update add timidity default
# /etc/init.d/timidity start
Testing MIDI Support
You can use pmidi to test your MIDI configuration:
Code Listing 4.6: Installing pmidi
# emerge pmidi
To see what MIDI output ports are available on your system, use the -l
Code Listing 4.7: Viewing the MIDI output ports
# pmidi -l
If all looks fine, try playing a MIDI file to make sure everything works. With
the -p option you define what MIDI port you want to use.
Code Listing 4.8: Playing a MIDI file
# pmidi -p 65:0 "Final Fantasy 7 - Aerith' Theme.mid"
5. Final Remarks
Tools and Firmware
Some specific sound cards can benefit from certain tools provided by the
alsa-tools and alsa-firmware packages. If you need
alsa-tools, be sure to define the ALSA_TOOLS variable in
/etc/make.conf with the tools you require. For instance:
Code Listing 5.1: Selecting ALSA Tools in /etc/make.conf
Then install the alsa-tools (and/or alsa-firmware) package(s):
Code Listing 5.2: Installing ALSA Tools
# emerge alsa-tools
Activating Joystick Support
If your soundcard has a joystick plug, you might be interested in activating
joystick support for your soundcard. If so, start by verifying if your soundcard
driver has a joystick parameter. You can verify this by running modinfo
against your kernel module. For instance, for the snd-via82xx:
Code Listing 5.3: Running modinfo
# modinfo snd-via82xx
description: "VIA VT82xx audio"
author: "Jaroslav Kysela <[email protected]>"
parm: index int array (min = 1, max = 8), description "Index value for
VIA 82xx bridge."
parm: id string array (min = 1, max = 8), description "ID string for VIA
parm: enable int array (min = 1, max = 8), description "Enable audio part
of VIA 82xx bridge."
parm: mpu_port long array (min = 1, max = 8), description "MPU-401 port.
parm: joystick int array (min = 1, max = 8), description "Enable
joystick. (VT82C686x only)"
parm: ac97_clock int array (min = 1, max = 8), description "AC'97 codec
clock (default 48000Hz)."
parm: dxs_support int array (min = 1, max = 8), description "Support for
DXS channels (0 = auto, 1 = enable, 2 = disable, 3 = 48k only, 4 =
If it has the joystick parameter, append joystick=1 to your
options line in /etc/modules.d/alsa. For instance:
Code Listing 5.4: Adding the joystick parameter
alias snd-card-0 snd-via82xx
options snd-via82xx joystick=1
The contents of this document are licensed under the Creative Commons - Attribution / Share Alike license.