Gentoo Linux ALSA Guide Vincent Verleye Grant Goodyear Arcady Genkin Jeremy Huddleston John P. Davis Sven Vermeulen Benny Chuang Tiemo Kieft Erwin 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. 1.5.5 2004-10-31 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.

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.

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.

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

ALSA_CARDS="via82xx"

Now install alsa-driver:

# 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 alsa-oss:

# emerge alsa-oss

Now install the ALSA Utils on your system (this is mandatory):

# emerge alsa-utils

Now that the utils are installed, it is time to configure ALSA...

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:

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:

# 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 registered:

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

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

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

# 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

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 application.

Activating MIDI Support
Installing the Necessary Packages

Some soundcards come with onboard MIDI synthesizers. To use them, you must first install 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:

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

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

# emerge timidity-eawpatches

Don't forget to add 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:

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

# aplaymidi -p 65:0 "Final Fantasy 7 - Aerith' Theme.mid"
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:

ALSA_TOOLS="as10k1 ac3dec"

Then install the alsa-tools (and/or alsa-firmware) package(s):

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

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

alias snd-card-0 snd-via82xx
options snd-via82xx joystick=1
Resources
  • The ALSA Project
  • ALSA Howto's and FAQs
  • Linux Sound/MIDI Software