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.4.3 May 09, 2004 Introduction
What is ALSA?

The Advanced Linux Sound Architecture (ALSA) is a project to improve the Linux sound subsystem by rewriting large chunks of it. It has replaced the Open Sound System (OSS) as the default sound subsystem in the 2.6 kernel, but it can be used with either 2.4 or 2.6 kernels.

ALSA provides audio and MIDI functionality for Linux.

Quoted from http://www.alsa-project.org, ALSA has the following features:

  • Efficient support for all types of audio interfaces, from consumer soundcards to professional multichannel audio interfaces
  • Fully modularized sound drivers
  • SMP and thread-safe design
  • User space library (alsa-lib) to simplify application programming and provide higher level functionality
  • Support for the older OSS API, providing binary compatibility for most OSS programs

There's lots more to ALSA however, like support for Full Duplex playback and recording, multiple soundcard support, hardware mixing of streams, extensive mixer capabilities (to support advanced features of new soundcards), ...

Why use ALSA?

Your sound card may be supported by modules available in the 2.4 kernel (these are also provided in the 2.6 kernel under the 'Open Sound System (DEPRECATED)' option). Additionally, you might be able to use the commercial OSS/4Front sound driver system. If you wish to use either of these systems, then you should read through the Linux Sound HOWTO.

The OSS/4Front drivers have some limitations, however. Being commercial is one. ALSA is an attempt to go beyond these limitations with an open source development model. ALSA is a fully GPL and LGPL'ed sound driver system that provides a professional quality system for recording, playback, and MIDI sequencing.

What cards does ALSA support?

ALSA tries to support as many (new) cards as possible by providing open-source drivers. However, some vendors may provide binary-only packages.

To know if your card is supported, you can find a Soundcard Matrix of supported and not-supported cards here: http://www.alsa-project.org/alsa-doc/.

Installation
Gentoo USE flags

To compile programs with ALSA-support, be sure to add alsa to your USE-variable. However, several tools don't support alsa yet, and require OSS. ALSA provides OSS-emulation if you define oss in your USE-variable before you start.

Kernel modules

When using the 2.4 kernels, you'll need to compile the alsa drivers separately from the rest of the kernel. If you are using a 2.6 kernel, you have the option of using the ALSA drivers included in the kernel or those provided by the alsa-driver package.

First we'll make sure that our kernel configuration is ready for use with ALSA. All you need in your kernel configuration is having Sound Card Support set to be built as a module (M). This will build soundcore.o.

Possibly, this will also work if you build 'Sound Card Support' in the kernel (Y) instead of building it as a module (M). However, the official ALSA documentation suggests building it as a module, since ALSA will try loading it.

If you already have a working kernel configuration, make sure you remove all sound drivers (except for Sound Card Support). If you wish to do this without having to reboot, you could do like this:

# cd /usr/src/linux
# cp .config ~/
# make mrproper
# cp ~/.config .
# make menuconfig

Now select Sound Card Support as Module (M) and deselect all other sound drivers. If you are using 2.6 with the ALSA modules provided by the kernel, select the drivers for your sound card as well (look in the ALSA modules section below if you need help choosing the right drivers). Exit and say Y to save your kernel configuration. After that, build the modules:

# make dep clean
# make modules modules_install
# make
# make modules_install

If you compiled 2.6 with the ALSA modules provided by the kernel, please skip to Configuration of ALSA below.

Before installing your new modules, this last line will delete all your previous modules, even the ones from a previous ALSA installation.

This means, whenever you recompile your kernel later on, you MUST recompile alsa-driver.
ALSA modules

Now it's time to install the ALSA drivers for your soundcard(s). If your soundcard is PCI, you can find out the name and type of your soundcard by looking at the output of /proc/pci.

# grep audio /proc/pci
If you had a previous sound setup and there are still non-ALSA sound modules loaded, unload them now. Check with lsmod and use rmmod to unload all sound-related modules on your system. If rmmod complains about not being able to unload the modules because they are in use, try using /etc/init.c/alsasound stop to remove them.

We could simply do an emerge alsa-driver now, this would compile and install all ALSA sound drivers.

However, to save some time, lookup the Module Name of your soundcard(s) on the ALSA Soundcard Matrix by following the Details link in the Driver and Docs column in the row of the chipset of your soundcard. Mine is snd-emu10k1, since I have an SBlive! soundcard, with the EMU10K1 chipset. We'll set ALSA_CARDS environment to the value of the module name before emerging (but without the snd prefix), so emerge will only compile the drivers we need.

# env ALSA_CARDS='emu10k1' emerge alsa-driver 
# env ALSA_CARDS='emu10k1' emerge \>=media-sound/alsa-driver-1.0.2c
2.6 kernels require alsa-driver to be at least version 1.0.2c. You can also add this value in /etc/make.conf, so when you have to emerge the alsa-driver later on you can just run emerge alsa-driver. For example, like this: echo 'ALSA_CARDS="emu10k1"' >> /etc/make.conf When you want to install ALSA drivers for more than one soundcard, you could set ALSA_CARDS to a space-separated list of drivers; like this: env ALSA_CARDS='emu10k1 intel8x0 ens1370' emerge alsa-driver If you want to have OSS compatibility, make sure to emerge alsa-oss, it is the ALSA/OSS compatibility wrapper. If you plan on recompiling your kernels numerous times, it might be adviseable to emerge alsa-driver with --buildpkg. This will create a binary package for it. Later, after recompiling your kernel, you can just do emerge --usepkg alsa-driver which will install the binary package instead of recompiling it completely. If 'depmod -a' ever complains about sound drivers having unreferenced symbols when you do this, you will need to recompile the alsa-driver package from source.

After this, the ALSA modules should be installed on your system.

Configuration of ALSA

Let's start configuring now to get ALSA working properly. We'll need to edit some files, to let our system know about the freshly installed ALSA modules.

First, install alsa-utils on your system:

# emerge alsa-utils

Hereafter, we need to edit /etc/modules.d/alsa.

There is no need to edit /etc/modules.conf. Instead, always edit files in /etc/modules.d and run modules-update to generate /etc/modules.conf from the updated data.
## and then run `modules-update' command.
## Read alsa-driver's INSTALL file in /usr/share/doc for more info.
##
##  ALSA portion
alias snd-card-0 snd-emu10k1
## alias snd-card-1 snd-intel8x0
## alias snd-card-2 snd-ens1370
##  OSS/Free portion
alias sound-slot-0 snd-card-0
## alias sound-slot-1 snd-card-1
## alias sound-slot-2 snd-card-2
##
If you have more than one soundcard, add more snd-card and snd-slot aliases and adjust the cards_limit value at the end of the file. You can find examples for configurations with two or more soundcards in Chapter 6 of the ALSA Howto.

Last thing to do in this file, almost at the end, check if these lines are there and uncommented:

alias /dev/mixer snd-mixer-oss
alias /dev/dsp snd-pcm-oss
alias /dev/midi snd-seq-oss

After double-checking the file /etc/modules.d/alsa to make sure everyting is ok, run modules-update.

# modules-update
Running modules-update here will insert the data from /etc/modules.d/alsa into /etc/modules.conf

You should also verify 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
Notice that devfsd.conf sets /dev/sound permissions to be root.audio. Thus, for non-root users to use audio they will have to be part of the audio group.
Starting ALSA
Adding alsasound to a runlevel

An init script is provided for you which will install all necessary sound drivers for your card (including the OSS support drivers if you set USE=oss). The first thing to do now is to make ALSA startup at boot time:

# rc-update add alsasound boot
Note that the alsasound script should be added to the "boot" runlevel, not the "default" runlevel.
Running and unmuting

Since we're Linux users, we don't want to reboot. So we'll start the alsasound script manually.

# /etc/init.d/alsasound start

ALSA is running now. If everything is ok, you should be able to see the ALSA modules loaded when running lsmod. However, sound won't work yet, because the channels are still muted. We need amixer to fix this.

# amixer

If you got this far, now unmute Master and PCM channels. Some hardware even requires you to unmute the center channel or even the surround channel.

# amixer set Master 100 unmute
# amixer set PCM 100 unmute
Only if the above doesn't succeed on its own:
# amixer set Center 100 unmute
# amixer set Surround 100 unmute
Test the sound:
# aplay $KDEDIR/share/sounds/pop.wav (pop.wav is part of KDE)

We check to see if sound is working by using the aplay (alsa play) command. If you hear a pop, then sound is indeed working. Then, adjust the volume settings to your liking; the ncurses-based alsamixer is a great way to get them "just so".

When you reboot your system, the alsasound init script will properly save and restore your volume settings.

MIDI Support
Hardware Synthesizer

Some sound cards (SBLive, Audigy, and others) come with onboard MIDI synthesizers. To use them, you must first install the awesfx package.

# emerge awesfx

Now, you should place your sound fonts in /usr/share/sfbank/. You can probably get the sound fonts off of the windows driver CD for your sound card. With the SBLive, one of the included sound font files is called 8MBGMSFX.SF2.

On some recents CD supplied with a SBLive, the font file is called CT4GMSFX.SF2. If it is your case, please replace all occurrences of 8MBGMSFX.SF2 with CT4GMSFX.SF2 in the examples.

After copying over the sound font you want to use, you need to select it for use with /usr/bin/sfxload.

# /usr/bin/sfxload /usr/share/sfbank/8MBGMSFX.SF2
You may wish to place this command in /etc/conf.d/local.start or in the startup script for your sound card (/etc/alsa.d/emu10k1) to make sure it gets loaded at startup.

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++

A sample configuration file will be installed for you in /usr/share/timitidy/config/timidity.cfg. If you don't have a timidity++ configuration setup yet, you can just use this one.

# cp /usr/share/timidity/config/timidity.cfg /usr/share/timidity

Now, you need to enable the init script to run when your system boots and enable it now.

# rc-update add timidity default
# /etc/init.d/timidity start

Note that there is a configuration file for the init script that you can modify in /etc/conf.d/timidity, and sane defaults have been chosen for you.

Testing MIDI Support

You can use pmidi to test out your MIDI configuration. To do so, you need to first emerge its package.

# emerge pmidi

The '-l' command line option to pmidi will list all detected MIDI output ports, and '-p' can be used to select the one for playback. Check to see what MIDI output ports are available on your system:

# pmidi -l
 Port     Client name                       Port name
 64:0     Rawmidi 0 - EMU10K1 MPU-401 (U    EMU10K1 MPU-401 (UART)
 65:0     Emu10k1 WaveTable                 Emu10k1 Port 0
 65:1     Emu10k1 WaveTable                 Emu10k1 Port 1
 65:2     Emu10k1 WaveTable                 Emu10k1 Port 2
 65:3     Emu10k1 WaveTable                 Emu10k1 Port 3
# pmidi -l
 Port     Client name                       Port name
 64:0     Rawmidi 0 - ES1371                ES1371
128:0     TiMidity                          TiMidity port 0
128:1     TiMidity                          TiMidity port 1
128:2     TiMidity                          TiMidity port 2
128:3     TiMidity                          TiMidity port 3

Now, try playing a MIDI file to make sure everything works:

# pmidi -p 65:0 Final\ Fantasy\ 7\ -\ Aerith\'s\ Theme.mid
or
# pmidi -p 128:0 Final\ Fantasy\ 7\ -\ Aerith\'s\ Theme.mid
Final Notes
After kernel-upgrades...

When you ever rebuild your kernel, or upgrade to another kernel, you'll have to rebuild the ALSA modules.

Although you might have installed alsa-driver, alsa-lib and alsa-utils, only the first will have to be installed again, since it will put the alsa modules in /lib/modules/*/kernel/sound/pci/.

# emerge alsa-driver
alsa-tools and alsa-firmware

The alsa-tools and alsa-firmware packages contain tools useful to only users of specific sound cards. Most users will not need these. If you do need alsa-tools, you can set the environment variable 'ALSA_TOOLS' to install just the needed tools for your card:

# env ALSA_TOOLS='as10k1 ac3dec' emerge alsa-tools
Mixing versions

Often times, different versions of alsa-driver, alsa-lib, alsa-utils, alsa-tools, and alsa-oss will work with each other, but it is recommended that you try to keep the versions in sync.

/etc/modules.autoload

You won't have to edit this file for use with ALSA. After doing rc-update add alsasound boot, the correct modules will be loaded at startup.

Known bugs This guide lags behind on the alsa-development. Chances are these bugs are already fixed when you read this.
  • If you have lots of noise when using oss emulation, add options snd-pcm-oss dsp_map=1 to /etc/modules.d/alsa
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 snd-<your chipset>. 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, then append joystick=1 to your options line in /etc/modules.d/alsa. For instance, for the snd-via82xx:

alias snd-card-0 snd-via82xx
options snd-via82xx joystick=1
More links...

You could check these for additional info:

  • The Gentoo Linux Desktop Configuration Guide
  • ALSA Project Homepage
  • ALSA Users Documentation
  • ALSA Howto's and FAQ's
  • Linux Sound HOWTO
  • Sound and MIDI Software For Linux