CachedSaturday 01 of January, 2005 [12:09:56 UTC]

This is a cached version of the page. (Click here to view the Google cache of the page instead.)

Gentoo Linux Documentation -- Gentoo Linux ALSA Guide
Gentoo Logo
Gentoo Logo Side

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

USE Flags

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.

Kernel Modules

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. Additionally, make sure you disable Open Sound System in your kernel configuration. If you don't, your system may try to use these drivers rather than the alsa ones. If you see a message about 'sound card not detected' and you are sure you have the correct driver, this is probably the reason.

Warning: If you use a 2.6 kernel, you may use the drivers provided in the kernel, but we still recommend that you use media-sound/alsa-driver as they are more up to date than what is provided in the kernel tree. If you still wish to use the drivers provided with your kernel, you can skip the rest of this section and continue with Installing the ALSA Utils.

The first step in installing your sound drivers is figuring out what sound card you have. If you don't already know, an easy trick is to search for "audio" in the output of the lspci command. You can install this tool 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


Warning: If you have multiple sound cards in your system, separate them with a comma in the ALSA_CARDS variable. Ex: ALSA_CARDS="via82xx,emu10k1"

If you want OSS compatibility (highly recommended), you should add 'oss' to your USE flags in /etc/make.conf. After that, you are ready to install alsa-driver:

Code ListingĀ 2.3: Installing ALSA Drivers

# emerge alsa-driver

Important: Whenever you (re)compile your kernel sources, chances are that the ALSA drivers will be deleted. It is therefore adviseable to rerun emerge alsa-driver every time you (re)compile your kernel. Note that this will compile the drivers for the kernel in /usr/src/linux, NOT the running kernel.

Installing the ALSA Utils

If the in-kernel OSS compatibility is not sufficient for your needs, you will want to install alsa-oss. This will provide you with the 'aoss' executable which can be used as demonstrated:

Code ListingĀ 2.4: More OSS compatibility layer

# emerge alsa-oss
# aoss mpg123 music.mp3

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 necessary modules at boot time. For the soundcard in our example:

Code ListingĀ 3.1: /etc/modules.d/alsa

alias snd-card-0 snd-via82xx
# The following is only needed when you want OSS compatibility
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

# modules-update

Verifying the Device Files

This should be done automatically for you on recent installs, but if you run into problems, check that your ALSA devices and permissions are set correctly by your /dev manager. If you use DevFS, check /etc/devfsd.conf

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 boot runlevel:

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

# 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 started.

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

(If you prefer an ncurses method:)

# alsamixer


# amixer set Master 100 unmute
# amixer set PCM 100 unmute
(Only if the above isn't sufficient:)
# amixer set Center 100 unmute
# amixer set Surround 100 unmute
# amixer set Headphone 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.

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 http://www.parabola.demon.co.uk/alsa/awe64.html.

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 or timidity-shompatches which will give you some soundfonts. You can have multiple soundfont configurations installed, and you can place your own in /usr/share/timidity/. To switch between different timidity configurations, you should use the timidity-update tool provided in the timidity++ package.

Code ListingĀ 4.4: Installing soundfonts

# emerge timidity-eawpatches
# timidity-update -g -s eawpatches


# emerge timidity-shompatches
# timidity-update -g -s shompatches

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 aplaymidi from the ALSA Utils to test your MIDI configuration.

To see what MIDI output ports are available on your system, use the -l option:

Code ListingĀ 4.6: Viewing the MIDI output ports

# aplaymidi -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.7: Playing a MIDI file

# aplaymidi -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

ALSA_TOOLS="as10k1 ac3dec"

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
filename:    /lib/modules/2.4.22-ck2/snd-via82xx.o
description: "VIA VT82xx audio"
author:      "Jaroslav Kysela <perex@suse.cz>"
license:     "GPL"
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
             82xx bridge."
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.
             (VT82C686x only)"
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 =
             no VRA)

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.

Updated December 9, 2004
Vincent Verleye

Grant Goodyear

Arcady Genkin

Jeremy Huddleston

John P. Davis

Sven Vermeulen

Benny Chuang

Tiemo Kieft


Summary: This guide will show you how to set up the Advanced Linux Sound Architecture (ALSA) on Gentoo Linux. In addition to the Gentoo Linux Desktop Configuration Guide, this guide is supposed to give you more information on this subject.
$99/mo dedicated servers

No BS Dedicated Gentoo Linux Servers from vr.org.

Tek Alchemy

Tek Alchemy offers dedicated servers and other hosting solutions running Gentoo Linux.


php|architect is the monthly magazine for PHP professionals, available worldwide in print and electronic format. A percentage of all the sales will be donated back into the Gentoo project.


Seven L Networks provides customizable Dedicated Servers for your customized Gentoo install. Colocation and other hosting services are also provided.

The Gentoo Linux Store
Copyright 2001-2004 Gentoo Foundation, Inc. Questions, Comments, Corrections? Email www@gentoo.org.