<?xml version="1.0" encoding="UTF-8"?>
<!-- $Header: /var/cvsroot/gentoo/xml/htdocs/doc/en/alsa-guide.xml,v 1.45 2004/12/02 20:27:35 dertobi123 Exp $ -->
<!DOCTYPE guide SYSTEM "/dtd/guide.dtd">

<guide link="/doc/en/alsa-guide.xml">
<title>Gentoo Linux ALSA Guide</title>
<author title="Author">
  <mail link="zu@pandora.be">Vincent Verleye</mail>
</author>
<author title="Author">
  <mail link="g2boojum@gentoo.org">Grant Goodyear</mail>
</author>
<author title="Author">
  <mail link="agenkin@gentoo.org">Arcady Genkin</mail>
</author>
<author title="Author">
  <mail link="eradicator@gentoo.org">Jeremy Huddleston</mail>
</author>
<author title="Editor"><!-- zhen@gentoo.org -->
  John P. Davis
</author>
<author title="Editor">
  <mail link="swift@gentoo.org">Sven Vermeulen</mail>
</author>
<author title="Editor">
  <mail link="bennyc@gentoo.org">Benny Chuang</mail>
</author>
<author title="Editor">
  <mail link="blubber@gentoo.org">Tiemo Kieft</mail>
</author>
<author title="Editor">
  <mail link="erwin@gentoo.org">Erwin</mail>
</author>

<abstract>
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.
</abstract>

<license/>

<version>1.5.7</version>
<date>2004-12-02</date>

<chapter>
<title>The Advanced Linux Sound Architecture</title>
<section>
<title>What is ALSA?</title>
<body>

<p>
ALSA is the <e>Advanced Linux Sound Architecture</e>, a project dedicated to the
development of a high-quality Linux sound subsystem. It has replaced OSS
(<e>Open Sound System</e>) as default sound subsystem in the 2.6 kernel series.
</p>

<p>
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 <e>alsa-lib</e> to simplify application programming. It also
provides a backwards compatibility layer with OSS.
</p>

</body>
</section>
</chapter>
<chapter>
<title>Installing ALSA</title>
<section>
<title>USE Flags</title>
<body>

<p>
Gentoo provides an <c>alsa</c> USE flag which you should set in
<path>/etc/make.conf</path> to allow our available packages to compile with
ALSA support. If you have <c>oss</c> in your USE variable as well, ALSA will
compile with OSS backward compatibility.
</p>

</body>
</section>
<section>
<title>Kernel Modules</title>
<body>

<p>
First of all, before continuing, make sure your kernel has <e>Sound Card
Support</e> enabled. If you used <c>genkernel</c> to build your kernel, then
this is automatically true. Otherwise reconfigure your kernel.
</p>

<warn>
If you use a 2.6 kernel you can skip the rest of this section and continue with
<uri link="#alsa-utils">Installing the ALSA Utils</uri> 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.
</warn>

<p>
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 <c>lspci</c> command. You can install
it with <c>emerge pciutils</c>.
</p>

<pre caption="Finding out the soundcard type">
# <i>lspci | grep -i audio</i>
Multimedia audio controller: VIA Technologies, Inc. VT82C686 AC97 Audio Controller (rev 64).
</pre>

<p>
Now go to the <uri link="http://www.alsa-project.org/alsa-doc">ALSA Soundcard
Matrix</uri> 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 <path>via82xx</path>. This is all the
information you need, so you can safely discard the rest of that document.
</p>

<p>
Based on this information we can now install the <c>alsa-driver</c> for our
soundcard. First edit <path>/etc/make.conf</path> and <e>add</e> a new option
called ALSA_CARDS to it. Inside this variable you declare the soundcard driver
you want to use:
</p>

<pre caption="Editing /etc/make.conf for ALSA_CARDS">
ALSA_CARDS="via82xx"
</pre>

<p>
Now install <c>alsa-driver</c>:
</p>

<pre caption="Installing ALSA Drivers">
# <i>emerge alsa-driver</i>
</pre>

<impo>
Whenever you (re)compile your kernel sources, chances are that the ALSA drivers
will be overwritten. It is therefore adviseable to rerun <c>emerge
alsa-driver</c> every time you (re)compile your kernel <e>after</e> having
rebooted into the new kernel.
</impo>

</body>
</section>
<section id="alsa-utils">
<title>Installing the ALSA Utils</title>
<body>

<p>
If you want backwards compatibility with OSS, you need to install
<c>alsa-oss</c>:
</p>

<pre caption="Installing the ALSA OSS compatibility layer">
# <i>emerge alsa-oss</i>
</pre>

<p>
Now install the ALSA Utils on your system (this is mandatory):
</p>

<pre caption="Installing ALSA Utils">
# <i>emerge alsa-utils</i>
</pre>

<p>
Now that the utils are installed, it is time to configure ALSA...
</p>

</body>
</section>
</chapter>
<chapter>
<title>Configuring ALSA</title>
<section>
<title>Automatically Loading the Kernel Modules</title>
<body>

<p>
If you use a modular kernel (such as when using <c>genkernel</c>) you have to
edit <path>/etc/modules.d/alsa</path> so that it activates the necesary modules
at boot time. For the soundcard in our example:
</p>

<pre caption="/etc/modules.d/alsa">
alias snd-card-0 snd-via82xx
<comment># The following is only needed when you want OSS compatibility</comment>
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
</pre>

<p>
Now run <c>modules-update</c> to save the changes you made to the
<path>alsa</path> file into <path>/etc/modules.conf</path>:
</p>

<pre caption="Running modules-update">
# <i>modules-update</i>
</pre>

</body>
</section>
<section>
<title>Verifying the Device Files</title>
<body>

<p>
If you use DevFS (which is the default for Gentoo installations) make sure that
<path>/etc/devfsd.conf</path> has the ALSA devices and permissions correctly
registered:
</p>

<pre caption="/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
</pre>

</body>
</section>
<section>
<title>Having ALSA Activated at Boot</title>
<body>

<p>
To activate ALSA support at boot, add the <c>alsasound</c> init script to the
boot runlevel:
</p>

<pre caption="Adding alsasound to the boot runlevel">
# <i>rc-update add alsasound boot</i>
# <i>/etc/init.d/alsasound start</i>
</pre>

</body>
</section>
<section>
<title>Unmute the Channels</title>
<body>

<p>
By default, all sound channels are muted. To fix this, run <c>amixer</c>:
</p>

<pre caption="Running amixer">
# <i>amixer</i>
</pre>

<p>
If <c>amixer</c> produces lots of output then you're ready to unmute the
channels. If you receive an error, doublecheck that your soundcard module is
started.
</p>

<p>
Now unmute the <e>Master</e> and <e>PCM</e> channels. If this isn't sufficient,
also unmute the <e>Center</e> and <e>Surround</e> channels.
</p>

<pre caption="Unmuting the sound channels">
# <i>amixer set Master 100 unmute</i>
# <i>amixer set PCM 100 unmute</i>
<comment>(Only if the above isn't sufficient:)</comment>
# <i>amixer set Center 100 unmute</i>
# <i>amixer set Surround 100 unmute</i>
# <i>amixer set Headphone 100 unmute</i>
</pre>

<p>
To check if your sound works, play a wave file (using <c>aplay</c>), mp3 (using
<c>mpg123</c> or even <c>mplayer</c>) or any other sound file for that matter.
</p>

<p>
To fine-tune the sound channel settings you can use the <c>alsamixer</c>
application.
</p>

</body>
</section>
</chapter>
<chapter>
<title>Activating MIDI Support</title>
<section>
<title>Installing the Necessary Packages</title>
<body>

<p>
Some soundcards come with onboard MIDI synthesizers. To use them, you must first
install the <c>awesfx</c> package:
</p>

<pre caption="Installing the awesfx package">
# <i>emerge awesfx</i>
</pre>

<p>
If you have a collection of sound fonts somewhere, place them in
<path>/usr/share/sfbank</path>. For instance, the SBLive has a sound font file
called <path>8MBGMSFX.SF2</path> or <path>CT4GMSFX.SF2</path>.
</p>

<p>
After copying over the sound font, select them using <c>asfxload</c>:
</p>

<pre caption="Loading the sound font">
# <i>asfxload /usr/share/sfbank/8MBGMSFX.SF2</i>
</pre>

<p>
You must have this command run every time you boot, so it is adviseable to add
it to <path>/etc/conf.d/local.start</path> as well.
</p>

<p>
If you can't find soundfonts on your driver CD you can download some online from
<uri>http://www.parabola.demon.co.uk/alsa/awe64.html</uri>.
</p>

</body>
</section>
<section>
<title>Timidity++ Virtual Synthesizer</title>
<body>

<p>
If your sound card does not come with a hardware synthesizer (or you don't want
to use it), you can use <c>timidity++</c> to provide you with a virtual
synthesizer. Start by emerging this package:
</p>

<pre caption="Installing Timidity++">
# <i>emerge timidity++</i>
</pre>

<p>
For timidity to play sounds, it needs a soundfont. If you do not have any,
install <c>timidity-eawpatches</c> which will give you some soundfonts.
</p>

<pre caption="Installing timidity-eawpatches">
# <i>emerge timidity-eawpatches</i>
</pre>

<p>
Don't forget to add <c>timidity</c> to the default runlevel.
</p>

<pre caption="Adding timidity to the default runlevel">
# <i>rc-update add timidity default</i>
# <i>/etc/init.d/timidity start</i>
</pre>

</body>
</section>
<section>
<title>Testing MIDI Support</title>
<body>

<p>
You can use <c>aplaymidi</c> from the ALSA Utils to test your MIDI
configuration.
</p>

<p>
To see what MIDI output ports are available on your system, use the <c>-l</c>
option:
</p>

<pre caption="Viewing the MIDI output ports">
# <i>aplaymidi -l</i>
</pre>

<p>
If all looks fine, try playing a MIDI file to make sure everything works. With
the <c>-p</c> option you define what MIDI port you want to use.
</p>

<pre caption="Playing a MIDI file">
# <i>aplaymidi -p 65:0 "Final Fantasy 7 - Aerith' Theme.mid"</i>
</pre>

</body>
</section>
</chapter>
<chapter>
<title>Final Remarks</title>
<section>
<title>Tools and Firmware</title>
<body>

<p>
Some specific sound cards can benefit from certain tools provided by the
<c>alsa-tools</c> and <c>alsa-firmware</c> packages. If you need
<c>alsa-tools</c>, be sure to define the ALSA_TOOLS variable in
<path>/etc/make.conf</path> with the tools you require. For instance:
</p>

<pre caption="Selecting ALSA Tools in /etc/make.conf">
ALSA_TOOLS="as10k1 ac3dec"
</pre>

<p>
Then install the <c>alsa-tools</c> (and/or <c>alsa-firmware</c>) package(s):
</p>

<pre caption="Installing ALSA Tools">
# <i>emerge alsa-tools</i>
</pre>

</body>
</section>
<section>
<title>Activating Joystick Support</title>
<body>

<p>
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 <c>modinfo</c>
against your kernel module. For instance, for the <c>snd-via82xx</c>:
</p>

<pre caption="Running modinfo">
# <i>modinfo snd-via82xx</i>
filename:    /lib/modules/2.4.22-ck2/snd-via82xx.o
description: "VIA VT82xx audio"
author:      "Jaroslav Kysela &lt;perex@suse.cz&gt;"
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)"
<i>parm:        joystick int array (min = 1, max = 8), description "Enable
             joystick. (VT82C686x only)"</i>
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)
</pre>

<p>
If it has the <c>joystick</c> parameter, append <c>joystick=1</c> to your
<c>options</c> line in <path>/etc/modules.d/alsa</path>. For instance:
</p>

<pre caption="Adding the joystick parameter">
alias snd-card-0 snd-via82xx
options snd-via82xx joystick=1
</pre>

</body>
</section>
<section>
<title>Resources</title>
<body>

<ul>
  <li><uri link="http://www.alsa-project.org">The ALSA Project</uri></li>
  <li><uri link="http://www.djcj.org">ALSA Howto's and FAQs</uri></li>
  <li><uri link="http://linux-sound.org">Linux Sound/MIDI Software</uri></li>
</ul>

</body>
</section>
</chapter>
</guide>
