<?xml version='1.0' encoding="UTF-8"?>
<!-- $Header: /var/cvsroot/gentoo/xml/htdocs/doc/en/alsa-guide.xml,v 1.73 2007/02/17 19:03:36 nightmorph 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="fox2mike@gentoo.org">Shyam Mani</mail>
</author>
<author title="Author">
  <mail link="nightmorph@gentoo.org">Joshua Saddler</mail>
</author>
<author title="Contributor">
  <mail link="flameeyes@gentoo.org">Diego Pettenò</mail>
</author>

<abstract>
This document helps a user setup ALSA on Gentoo Linux.
</abstract>

<!-- The content of this document is licensed under the CC-BY-SA license -->
<!-- See http://creativecommons.org/licenses/by-sa/2.5 -->
<license/>

<version>2.17</version>
<date>2007-02-17</date>

<chapter>
<title>Introduction</title>
<section>
<title>What is ALSA?</title>
<body>

<p>
ALSA, which stands for <e>Advanced Linux Sound Architecture</e>, provides 
audio and MIDI (<e>Musical Instrument Digital Interface</e>) functionality to 
the Linux operating system. ALSA is the default sound subsystem in the 2.6 
kernel thereby replacing OSS (<e>Open Sound System</e>), which was used in the 
2.4 kernels.
</p>

<p>
ALSA's main features include efficient support for all types of audio 
interfaces ranging from consumer sound cards to professional sound 
equipment, fully modularized drivers, SMP and thread safety, backward 
compatibility with OSS and a user-space library <c>alsa-lib</c> to make 
application development a breeze.
</p>

</body>
</section>
<section>
<title>ALSA on Gentoo</title>
<body>

<p>
One of Gentoo's main strengths lies in giving the user maximum control over 
how a system is installed/configured. ALSA on Gentoo follows the same 
principle. There are two ways you can get ALSA support up and running on your 
system. We shall look at them in detail in the next chapter.
</p>

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

<chapter>
<title>Installing ALSA</title>
<section>
<title>Options</title>
<body>

<warn>
The methods shown below are mutually exclusive. You cannot have ALSA compiled 
in your kernel and use <c>media-sound/alsa-driver</c>. It <e>will</e> fail.
</warn>

<p>
The two options are :
</p>

<ol>
  <li>Use ALSA provided by your kernel.</li>
  <li>Use Gentoo's <c>media-sound/alsa-driver</c> package.</li>
</ol>

<p>
The in-kernel drivers and the <c>alsa-driver</c> package can vary a little; it's
possible that features and fixes found in one might not yet be incorporated into
the other. The upstream developers are aware of this, but the two drivers are
effectively separate branches of the ALSA project; they are not entirely
identical. You should be aware that they might function slightly differently, so
if one doesn't work for you, try the other! We shall take a peek into both
before finally deciding on one.
</p>

<p>
If you were to use ALSA provided by the kernel, the following are the pros and 
cons :
</p>

<table>
<tr>
  <th>Kernel ALSA</th>
  <th>Pros and Cons</th>
</tr>
<tr>
  <th>+</th>
  <ti>
    No need to emerge yet another package; drivers are integrated into kernel.
  </ti>
</tr>
<tr>
  <th>+</th>
  <ti>One shot solution, no repeating emerges.</ti>
</tr>
<tr>
  <th>-</th>
  <ti>Might be a slightly different version than <c>alsa-driver</c>.</ti>
</tr>
</table>

<p>
And, if you were to use alsa-driver,
</p>

<table>
<tr>
  <th>alsa-driver</th>
  <th>Pros and Cons</th>
</tr>
<tr>
  <th>+</th>
  <ti>Possibly the latest drivers from the ALSA Project.</ti>
</tr>
<tr>
  <th>+</th>
  <ti>Useful if you intend to develop audio drivers.</ti>
</tr>
<tr>
  <th>-</th>
  <ti>Every kernel recompile requires a re-emerge of <c>alsa-driver</c>.</ti>
</tr>
<tr>
  <th>-</th>
  <ti>Needs certain kernel config options disabled to work correctly.</ti>
</tr>
</table>

</body>
</section>
<section>
<title>So...</title>
<body>

<p>
The differences between <c>alsa-driver</c> and the in-kernel ALSA drivers are
quite subtle, as mentioned earlier. Since there are not any huge differences,
this guide will go through the process of using the ALSA provided by the kernel
<e>first</e> for ease of use. However, if you run into problems, try switching
to <c>alsa-driver</c>. Before reporting any sound related issues to <uri
link="https://bugs.gentoo.org">Gentoo Bugzilla</uri>, please try to reproduce
them using <c>alsa-driver</c> and file the bug report no matter what the
result.
</p>

</body>
</section>
<section id="lspci">
<title>Before you proceed</title>
<body>

<p>
Whichever method of install you choose, you need to know what drivers your 
sound card uses. In most cases, sound cards (onboard and otherwise) are PCI
based and <c>lspci</c> will help you in digging out the required  information.
Please <c>emerge sys-apps/pciutils</c> to get <c>lspci</c>, if you don't have it
installed already. In case you have a USB sound card, <c>lsusb</c> from
<c>sys-apps/usbutils</c> <e>might</e> be of help. For ISA cards, try using
<c>sys-apps/isapnptools</c>. Also, the following pages <e>may</e> help users
with ISA based sound cards.
</p>

<ul>
  <li>
  <uri link="http://www.roestock.demon.co.uk/isapnptools/">The ISAPNPTOOLS
  Page</uri>
  </li>
  <li>
  <uri link="http://www2.linuxjournal.com/article/3269">LinuxJournal PnP
  Article</uri>
  </li>
  <li>
  <uri link="http://www.tldp.org/HOWTO/Sound-HOWTO/x320.html">TLDP Sound
  HowTo</uri>
  </li>
</ul>

<note>
For ease of use/explanation, we assume the user has a PCI based sound card for
the remainder of this guide.
</note>

<p>
We now proceed to find out details about the sound card.
</p>

<pre caption="Soundcard Details">
# <i>lspci -v | grep -i audio</i>
0000:00:0a.0 Multimedia audio controller: Creative Labs SB Live! EMU10k1 (rev 06)
</pre>

<p>
We now know that the sound card on the machine is a Sound Blaster Live! and 
the card manufacturer is Creative Labs. Head over to the 
<uri link="http://www.alsa-project.org/alsa-doc/"> ALSA Soundcard Matrix</uri> 
page and select Creative Labs from the drop down menu. You will be taken to 
the Creative Labs matrix page where you can see that the SB Live! uses the 
<c>emu10k1</c> module. That is the information we need for now. If you are 
interested in detailed information, you can click on the link next to the 
"Details" and that will take you to the <c>emu10k1</c> specific page.
</p>

<p>
If you intend to use MIDI, then you should add <c>midi</c> to your USE flags in
<path>/etc/make.conf</path> before emerging any ALSA packages. Later in the
guide, we will show you how to set up <uri link="#midi">MIDI support</uri>.
</p>

<pre caption="MIDI support in /etc/make.conf">
<comment>(If you want MIDI support)</comment>
USE="midi"

<comment>(If you don't need MIDI)</comment>
USE="-midi"
</pre>

</body>
</section>
<section id="kernel">
<title>Using ALSA provided by your Kernel</title>
<body>

<p>
If you're a person who likes to keep things simple like I do, then this is 
the way to go.
</p>

<note>
Since the 2005.0 release, Gentoo Linux uses 2.6 as the default kernel. Unless
you are specifically using the 2.4 profile, <c>gentoo-sources</c> will be a
2.6 kernel on <e>most</e> architectures. Please check that your kernel is a 
2.6 series kernel. This method will <e>not</e> work on a 2.4 kernel.
</note>

<p>
Let us now configure the kernel to enable ALSA.
</p>

<impo>
<c>genkernel</c> users should now run <c>genkernel --menuconfig all</c> and
then follow the instructions in <uri link="#doc_chap2_pre3">Kernel Options for
ALSA</uri>.
</impo>

<pre caption="Heading over to the source">
# <i>cd /usr/src/linux</i>
# <i>make menuconfig</i>
</pre>

<note>
The above example assumes that <path>/usr/src/linux</path> symlink points to
the kernel sources you want to use. Please ensure the same before proceeding.
</note>

<p>
Now we will look at some of the options we will have to enable in the 2.6
kernel to ensure proper ALSA support for our sound card.
</p>

<p>
Please note that for ease of use, all examples show ALSA built as modules.  It
is advisable to follow the same as it then allows the use of <c>alsaconf</c>
which is a boon when you want to configure your card. Please do <e>not</e> skip
the <uri link="#alsa-config">Configuration</uri> section of this document. If
you still like to have options built-in, ensure that you make changes to your
config accordingly.
</p>

<pre caption="Kernel Options for ALSA">
Device Drivers  ---&gt;
   Sound  ---&gt;
   
<comment>(This needs to be enabled)</comment>
&lt;M&gt; Sound card support

<comment>(Make sure OSS is disabled)</comment>
Open Sound System   ---&gt;
   &lt; &gt; Open Sound System (DEPRECATED)

<comment>(Move one step back and enter ALSA)</comment>
Advanced Linux Sound Architecture  ---&gt;
   &lt;M&gt; Advanced Linux Sound Architecture
   <comment>(Select this if you want MIDI sequencing and routing)</comment>
   &lt;M&gt; Sequencer support
   <comment>(Old style /dev/mixer* and /dev/dsp* support. Recommended.)</comment>
   &lt;M&gt; OSS Mixer API
   &lt;M&gt; OSS PCM (digital audio) API 

<comment>(You now have a choice of devices to enable support for. Generally,
you will have one type of device and not more. If you have more than one 
sound card, please enable them all here.)</comment>

<comment>(Mostly for testing and development purposes, not needed for normal 
users unless you know what you are doing.)</comment>
Generic devices  ---&gt;
   
<comment>(For ISA Sound cards)</comment>
ISA devices   ---&gt;
<comment>(IF you had the Gravis, you would select this option)</comment>
   &lt;M&gt; Gravis UltraSound Extreme

<comment>(Move one level back and into PCI devices. Most sound cards today are 
PCI devices)</comment>
PCI devices   ---&gt;
   <comment>(We now select the emu10k1 driver for our card)</comment>
   &lt;M&gt; Emu10k1 (SB Live!, Audigy, E-mu APS)
   <comment>(Or an Intel card would be)</comment>
   &lt;M&gt; Intel/SiS/nVidia/AMD/ALi AC97 Controller
   <comment>(Or if you have a VIA Card)</comment>
   &lt;M&gt; VIA 82C686A/B, 8233/8235 AC97 Controller

<comment>(Move one level back and select in case you have an USB sound card)</comment>
USB Devices   ---&gt;
</pre>

<p>
Now that your options are set, you can (re)compile the kernel and ALSA support
for your card should be functional once you reboot into the new kernel. Don't
forget to update your GRUB configuration to use the newly built kernel.
You can now proceed to <uri link="#alsa-utilities">ALSA Utilities</uri> and 
see if everything is working as it should.
</p>

</body>
</section>
<section id="alsa-driver">
<title>Using the ALSA Driver package</title>
<body>

<p>
So you've decided to go the <c>alsa-driver</c> way. Let's get started then. 
There are a few minor things to be done to ensure only the drivers for your 
sound card are compiled. Although this is not really necessary, it cuts down 
on the unnecessary drivers that will be compiled otherwise.
</p>

<p>
If you don't have an idea of what drivers your sound card might need, please 
take a look at the <uri link="#lspci">lspci</uri> section of this guide. Once 
you have your driver name (<c>emu10k1</c> in our example), edit 
<path>/etc/make.conf</path> and add a variable, <c>ALSA_CARDS</c>.
</p>

<pre caption="Adding ALSA_CARDS to make.conf">
<comment>(For one sound card)</comment>
ALSA_CARDS="emu10k1"
<comment>(For more than one, separate names with spaces)</comment>
ALSA_CARDS="emu10k1 via82xx"
</pre>

<p>
If you have compiled your kernel and want to use <c>alsa-driver</c>, please 
ensure the following before proceeding, else <c>alsa-driver</c> is likely to 
fail. The next code listing gives you one way of performing the checks.
</p>

<note>
<c>genkernel</c> users can proceed with <uri link="#doc_chap2_pre6">Installing
alsa-driver</uri> as their configuration is in sync with the one shown below by
default.
</note>

<ol>
  <li>
  <c>CONFIG_SOUND</c> is set. (Basic Sound support enabled)
  </li>
  <li>
  <c>CONFIG_SOUND_PRIME</c> is not set. (In-built OSS support disabled)
  </li>
  <li>
  <c>CONFIG_SND</c> is not set. (In-built ALSA support disabled)
  </li>
  <li>
  <path>/usr/src/linux</path> points to the kernel you want ALSA working on.
  </li>
</ol>

<pre caption=".config checks">
<comment>(Assuming the linux symlink points to the correct kernel)</comment>
# <i>cd /usr/src/linux</i>
# <i>grep SOUND .config</i>
<comment>(1. is true)</comment>
CONFIG_SOUND=y
<comment>(2. is true)</comment>
CONFIG_SOUND_PRIME is not set
# <i>grep SND .config</i>
<comment>(and 3. is true)</comment>
CONFIG_SND is not set
</pre>

<p>
Now all you have to do is type the magic words... and no, it's not abracadabra.
</p>

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

<impo>
Please note that you will have to run <c>emerge alsa-driver</c> after every
kernel (re)compile, as the earlier drivers are deleted. To make this task
easier, you may want to emerge the <c>module-rebuild</c> package, which will
keep track of module packages and rebuild them for you. First run
<c>module-rebuild populate</c> to create the list, and then after every kernel
(re)compile, you just run <c>module-rebuild rebuild</c>, and your external
modules will be rebuilt.
</impo>

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

<chapter>
<title>Configuring/Testing ALSA</title>
<section id="alsa-utilities">
<title>ALSA Utilities</title>
<body>

<p>
<c>alsa-utils</c> forms an integral part of ALSA as it has a truckload of 
programs that are highly useful, including the ALSA Initscripts. Hence we 
strongly recommend that you install <c>alsa-utils</c>
</p>

<pre caption="Install alsa-utils">
# <i>emerge alsa-utils</i>
</pre>

<note>
If you activated ALSA in your <uri link="#kernel">kernel</uri> <e>and</e> did 
not compile ALSA as modules, please proceed to the 
<uri link="#initscript">ALSA Initscript</uri> section. The rest of you need 
to configure ALSA. This is made very easy by the existence of the 
<c>alsaconf</c> tool provided by <c>alsa-utils</c>.
</note>

</body>
</section>
<section id="alsa-config">
<title>Configuration</title>
<body>

<p>
Recent versions of <c>udev</c> (<c>>=udev-103</c>) provide some degree of
kernel-level autoconfiguration of your sound card. If possible, try to rely on
just letting your kernel automatically setup your sound card for you. Otherwise,
use <c>alsaconf</c> to configure your card, as shown below.
</p>

<note>
Please shut down any programs that <e>might</e> access the sound card while 
running <c>alsaconf</c>.
</note>

<p>
Another way to configure your sound card is to run <c>alsaconf</c>. Just type
<c>alsaconf</c> in a shell as root.
</p>

<pre caption="Invoking alsaconf">
# <i>alsaconf</i>
</pre>

<p>
You will now see a neat menu guided interface that will automatically probe 
your devices and try to find out your sound card. You will be asked to pick 
your sound card from a list. Once that's done, it will ask you permission to 
automatically make required changes to <path>/etc/modules.d/alsa</path>. 
It will then adjust your volume settings to optimum levels, run
<c>modules-update</c> and start the <path>/etc/init.d/alsasound</path> service.
Once <c>alsaconf</c> exits, you can proceed with setting up the ALSA
initscript. 
</p>

</body>
</section>
<section id="initscript">
<title>ALSA Initscript</title>
<body>

<p>
We're now almost all setup. Whichever method you chose to install ALSA, you'll 
need to have something load your modules or initialize ALSA and restore your 
volume settings when your system comes up. The ALSA Initscript handles all of 
this for you and is called <c>alsasound</c>. Add it to the boot runlevel.
</p>

<pre caption="Adding ALSA to the boot runlevel">
# <i>rc-update add alsasound boot</i>
 * alsasound added to runlevel boot
 * rc-update complete.
</pre>

<p>
Next, just check the <path>/etc/conf.d/alsasound</path> file and ensure that  
SAVE_ON_STOP variable is set to yes. This saves your sound settings when you 
shutdown your system.
</p>

</body>
</section>
<section>
<title>Audio Group</title>
<body>

<p>
Before we move on to testing, there's one last <e>important</e> thing that needs
to be setup. Rule of thumb in a *nix OS : Do not run as root unless needed.
This applies here as well ;) How? Well, most of the times you should be logged
in as a user and would like to listen to music or access your soundcard. For
that to happen, you need to be in the "audio" group. At this point, we'll add
users to the audio group, so that they won't have any issues when they want to
access sound devices. We'll use <c>gpasswd</c> here and you need to be logged in
as root for this to work.
</p>

<pre caption="Adding users to the audio group">
<comment>(Substitute &lt;username&gt; with your user)</comment>
# <i>gpasswd -a &lt;username&gt; audio </i>
Adding user &lt;username&gt; to group audio
</pre>

</body>
</section>
<section>
<title>Volume Check!</title>
<body>

<p>
We've completed all the setups and prerequisites, so let's fire up ALSA. If 
you ran <c>alsaconf</c>, you can skip this step, since <c>alsaconf</c> already 
does this for you.
</p>

<pre caption="Start the service">
# <i>/etc/init.d/alsasound start</i> 
</pre>

<p>
Now that the required things have been taken care of, we need to check up on 
the volume as in certain cases, it is muted. We use <c>alsamixer</c> for this
purpose.
</p>

<pre caption="Starting alsamixer">
<comment>(Opens up a console program. Only required settings are shown)</comment>
# <i>alsamixer</i>
</pre>

<impo>
If you have issues starting up <c>alsamixer</c> and get errors such as
alsamixer: function snd_ctl_open failed for default: No such file or directory,
this is usually an issue with udev setting up the devices. Run <c>killall
udevd; udevstart</c> to reload <path>/dev</path> entries and fire up
<c>alsamixer</c>. It should solve the issue.
</impo>

<p>
This is how the ALSA Mixer <e>might</e> look the first time you open it. Pay 
attention to the Master and PCM channels which both have an MM below them. 
That means they are muted. If you try to play anything with <c>alsamixer</c> 
in this state, you will not hear anything on your speakers.
</p>

<figure link="/images/docs/alsa-mixermuted.png" short="AlsaMixer Muted" caption="The Alsa Mixer Main Window, Muted"/>

<p>
Now, we shall unmute the channels, and set volume levels as needed.
</p>

<warn>
Both Master <e>and</e> PCM need to be unmuted and set to audible volume levels
if you want to hear some output on your speakers.
</warn>

<ul>
  <li>
  To move between channels, use your left and right arrow keys. (&lt;- 
  &amp; -&gt;)
  </li>
  <li>
  To toggle mute, move to the specific channel, for example Master and press 
  the <e>m</e> key on the keyboard. 
  </li>
  <li>
  To increase and decrease the volume levels, use the up and down arrow keys 
  respectively.
  </li>
</ul>

<note>
Be careful when setting your Bass and Treble values. 50 is usually a good 
number for both. Extremely high values of Bass may cause <e>jarring</e> 
on speakers that are not designed to handle them.
</note>

<p>
After you're all done, your ALSA Mixer should look similar to the one below. 
Note the 00 instead of the MM and also the volume levels for some optimum 
settings.
</p>

<figure link="/images/docs/alsa-mixerunmuted.png" short="AlsaMixer Unmuted" caption="Alsa Mixer ready to roll"/>

</body>
</section>
<section>
<title>Sound Check!</title>
<body>

<p>
Finally. Some music. If everything above is perfect, you should now be able to
listen to some good music. A quick way to test is to use a command line tool
like <c>media-sound/madplay</c>. You could also use something more well known
like <c>mpg123</c>. If you are an ogg fan, you could use <c>ogg123</c> provided
by <c>media-sound/vorbis-tools</c>. Use any player you are comfortable with. As
always, <c>emerge</c> what you need.
</p>

<pre caption="Getting the software">
<comment>(Install the applications you want)</comment>
# <i>emerge madplay mpg123</i>
<comment>(To play .ogg files)</comment>
# <i>emerge vorbis-tools</i>
</pre>

<p>
And then play your favorite sound track...
</p>

<pre caption="Playing Music">
# <i>madplay -v /mnt/shyam/Music/Paul\ Oakenfold\ -\ Dread\ Rock.mp3</i>
MPEG Audio Decoder 0.15.2 (beta) - Copyright (C) 2000-2004 Robert Leslie et al.
          Title: Dread Rock
         Artist: Paul Oakenfold
          Album: Matrix Reloaded
           Year: 2003
          Genre: Soundtrack
                 Soundtrack
 00:04:19 Layer III, 160 kbps, 44100 Hz, joint stereo (MS), no CRC

# <i>ogg123 Paul\ Oakenfold\ -\ Dread\ Rock.ogg</i>
Audio Device:   Advanced Linux Sound Architecture (ALSA) output

Playing: Paul Oakenfold - Dread Rock.ogg
Ogg Vorbis stream: 2 channel, 44100 Hz
Genre: Soundtrack
Transcoded: mp3;160
Title: Dread Rock
Artist: Paul Oakenfold
Date: 2003
Album: Matrix Reloaded
Time: 00:11.31 [04:28.75] of 04:40.06  (200.6 kbps)  Output Buffer  96.9%
</pre>

</body>
</section>
<section>
<title>ALSA and USE</title>
<body>

<p>
You can now add the <c>alsa</c> use flag to <path>/etc/make.conf</path> to
ensure that your applications that support ALSA get built with it. Some
architectures like x86 and amd64 have the flag enabled by default.
</p>

</body>
</section>
<section>
<title>Issues?</title>
<body>

<p>
If for some reason you're unable to hear sound, the first thing to do would 
be to check your <uri link="#doc_chap3_pre6">alsamixer</uri> settings. 80% of 
the issues lie with muted channels or low volume. Also check your Window 
Manager's sound applet and verify that volumes are set to audible levels.
</p>

<p>
<path>/proc</path> is your friend. And in this case, <path>/proc/asound</path> 
is your best friend. We shall just take a short look at how much info is made 
available to us there.
</p>

<pre caption="Fun with /proc/asound">
<comment>(First and foremost, if /proc/asound/cards shows your card, ALSA has 
picked up your sound card fine.)</comment>
# <i>cat /proc/asound/cards</i>
0 [Live           ]: EMU10K1 - Sound Blaster Live!
                     Sound Blaster Live! (rev.6, serial:0x80271102) at 0xb800, irq 11

<comment>(If you run ALSA off the kernel like I do and wonder how far behind 
you are from alsa-driver, this displays current running ALSA version)</comment>
# <i>cat /proc/asound/version</i>
Advanced Linux Sound Architecture Driver Version 1.0.8 (Thu Jan 13 09:39:32 2005 UTC).

<comment>(ALSA OSS emulation details)</comment>
# <i>cat /proc/asound/oss/sndstat</i>
Sound Driver:3.8.1a-980706 (ALSA v1.0.8 emulation code)
Kernel: Linux airwolf.zion 2.6.11ac1 #2 Wed May 4 00:35:08 IST 2005 i686
Config options: 0

Installed drivers:
Type 10: ALSA emulation

Card config:
Sound Blaster Live! (rev.6, serial:0x80271102) at 0xb800, irq 11

Audio devices:
0: EMU10K1 (DUPLEX)

Synth devices: NOT ENABLED IN CONFIG

Midi devices:
0: EMU10K1 MPU-401 (UART)

Timers:
7: system timer

Mixers:
0: SigmaTel STAC9721/23
</pre>

<p>
The other most common issue users face is the dreaded "Unknown symbol in module"
error. An example of the same is shown below.
</p>

<pre caption="Unknown Symbol in module error">
# <i>/etc/init.d/alsasound start</i>
 * Loading ALSA modules ...
 *   Loading: snd-card-0 ...                                              [ ok ]
 *   Loading: snd-pcm-oss ...
WARNING: Error inserting snd_mixer_oss
(/lib/modules/2.6.12-gentoo-r6/kernel/sound/core/oss/snd-mixer-oss.ko): Unknown
symbol in module, or unknown parameter (see dmesg) FATAL: Error inserting
snd_pcm_oss
(/lib/modules/2.6.12-gentoo-r6/kernel/sound/core/oss/snd-pcm-oss.ko): Unknown
symbol in module, or unknown parameter (see dmesg)                             
                                                                          [ !! ]
 *   Loading: snd-mixer-oss ...
FATAL: Error inserting snd_mixer_oss
(/lib/modules/2.6.12-gentoo-r6/kernel/sound/core/oss/snd-mixer-oss.ko): Unknown
symbol in module, or unknown parameter (see dmesg)                             
                                                                          [ !! ]
 *   Loading: snd-seq ...                                                 [ ok ]
 *   Loading: snd-emu10k1-synth ...                                       [ ok ]
 *   Loading: snd-seq-midi ...                                            [ ok ]
 * Restoring Mixer Levels ...                                             [ ok ]
</pre>

<p>
And when you take a look at <c>dmesg</c> as suggested, you're quite likely to
see:
</p>

<pre caption="dmesg output">
<comment>(Only relevant portions are shown below)</comment>
# <i>dmesg | less</i>
ACPI: PCI Interrupt 0000:02:06.0[A] -> Link [APC3] -> GSI 18 (level, low) -> IRQ 209
snd_mixer_oss: Unknown symbol snd_unregister_oss_device
snd_mixer_oss: Unknown symbol snd_register_oss_device
snd_mixer_oss: Unknown symbol snd_mixer_oss_notify_callback
snd_mixer_oss: Unknown symbol snd_oss_info_register
snd_pcm_oss: Unknown symbol snd_unregister_oss_device
snd_pcm_oss: Unknown symbol snd_register_oss_device
snd_pcm_oss: Unknown symbol snd_mixer_oss_ioctl_card
snd_pcm_oss: Unknown symbol snd_oss_info_register
snd_mixer_oss: Unknown symbol snd_unregister_oss_device
snd_mixer_oss: Unknown symbol snd_register_oss_device
snd_mixer_oss: Unknown symbol snd_mixer_oss_notify_callback
snd_mixer_oss: Unknown symbol snd_oss_info_register
</pre>

<p>
The above issue is caused when you switch from <c>alsa-driver</c> to in-kernel
ALSA because when you unmerge <c>alsa-driver</c> the module files are config
protected and hence get left behind. So, when you switch to in-kernel
drivers, running <c>modprobe</c> gives you a mix of <c>alsa-driver</c> and
in-kernel modules thus causing the above errors.
</p>

<p>
The solution is quite easy. We just need to manually remove the problem causing
directory after you unmerge <c>alsa-driver</c>. Be sure to remove the correct
kernel version and not the current one!
</p>

<pre caption="Removing the alsa-driver modules">
# <i>rm -rf /lib/modules/$(uname -r)/alsa-driver</i>
</pre>

<p>
Another reason for error messages similar to the ones above could be a file in
<path>/etc/modules.d</path> supplying a <c>device_mode</c> parameter when it
isn't required. Confirm that this is indeed the issue and find out which file
is the culprit.
</p>

<pre caption="Confirming and searching for device_mode">
<comment>(Check dmesg to confirm)</comment>
# <i>dmesg | grep device_mode</i>
snd: Unknown parameter `device_mode'
<comment>(Now, to get to the source of the issue)</comment>
# <i>grep device_mode /etc/modules.d/*</i>
</pre>

<p>
Usually it is a file called <path>alsa</path> with the line <c>options snd
device_mode=0666</c>. Remove this line and restart the alsasound service and
that should take care of this issue.
</p>

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

<chapter>
<title>Other things ALSA</title>
<section id="midi">
<title>Setting up MIDI support</title>
<body>

<p>
First, check to make sure that you enabled the <c>midi</c> USE flag in
<path>/etc/make.conf</path>.
</p>

<pre caption="MIDI support in /etc/make.conf">
USE="midi"
</pre>

<p>
If you didn't previously enable <c>midi</c>, go ahead and add it to
<path>/etc/make.conf</path> now. You will also need to re-emerge any ALSA
packages that use the <c>midi</c> flag, such as <c>alsa-lib</c>,
<c>alsa-utils</c>, and <c>alsa-driver</c>.
</p>

<p>
If your sound card is one of those that come with on-board MIDI synthesizers 
and you would like to listen to some .mid files, you have to install 
<c>awesfx</c> which is basically a set of utilities for controlling the AWE32 
driver. We need to install it first. If you don't have a hardware synthesizer, 
you can use a virtual one. Please see the section on 
<uri link="#vsynth">Virtual Synthesizers</uri> for more information.
</p>

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

<note>
You will need to copy over SoundFont (SF2) files from your sound card's driver 
CD or a Windows installation into <path>/usr/share/sounds/sf2/</path>. For 
example a sound font file for the Creative SBLive! card would be 8MBGMSFX.SF2.
</note>

<p>
After copying over the Soundfont files, we can then play a midi file as shown.
You can also add the <c>asfxload</c> command to 
<path>/etc/conf.d/local.start</path>, so that the sound font is loaded 
every time the system starts up.
</p>

<note>
<path>/mnt</path> paths mentioned in the code listing(s) below will <e>not</e> 
be the same in your machine. They are just an example. Please be careful to 
change the path to suit your machine.
</note>

<pre caption="Loading Soundfonts">
<comment>(First, copy the Soundfont)</comment>
# <i>cp /mnt/win2k/Program\ Files/CreativeSBLive2k/SFBank/8MBGMSFX.SF2 /usr/share/sounds/sf2/</i> 
<comment>(Or get it from your SoundBlaster CD)</comment>
# <i>cp /mnt/cdrom/AUDIO/ENGLISH/SFBANK/8MBGMSFX.SF2 /usr/share/sounds/sf2/</i>
<comment>(We load the specific Soundfont)</comment>
# <i>asfxload /usr/share/sounds/sf2/8MBGMSFX.SF2</i>
</pre>

<p>
You can now play midi files using a program like <c>aplaymidi</c>. Run 
<c>aplaymidi -l</c> to get a list of available ports and then pick one 
to play the file on.
</p>

<pre caption="Playing MIDI">
<comment>(Check open ports)</comment>
# <i>aplaymidi -l</i>
 Port    Client name                      Port name
 64:0    EMU10K1 MPU-401 (UART)           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
<comment>(Pick a port, and play a mid file)</comment>
# <i> aplaymidi --port=65:0 /mnt/shyam/music/midi/mi2.mid</i>
</pre>

</body>
</section>
<section id="vsynth">
<title>Virtual Synthesizers</title>
<body>

<p>
If your sound card lacks a hardware synthesizer, you could use a virtual one
like <c>timidity++</c>. Installation is a breeze.
</p>

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

<p>
For timidity to play sounds, it needs a sound font. Fortunately, the ebuild will
install some sound font packages for you. There are a few other font packages
available in Portage, such as <c>timidity-freepats</c> and
<c>timidity-eawpatches</c>. You can have multiple sound font configurations
installed, and you can place your own in <path>/usr/share/timidity/</path>.  To
switch between different timidity configurations, you should use
<c>eselect</c>.
</p>

<pre caption="Changing configurations">
# <i>eselect timidity list</i>
# <i>eselect timidity set 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>

<p>
You can now try out <uri link="#doc_chap4_pre3">Playing MIDI</uri> files.
</p>

</body>
</section>
<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. You may install either with
a simple <c>emerge</c>.
</p>

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

</body>
</section>
<section>
<title>Multiple sound cards</title>
<body>

<p>
You can more than one sound card in your system simultaneously, provided that
you have built ALSA as modules in your kernel (or have installed
<c>alsa-driver</c> instead).  You just need to specify which should be started
first in <path>/etc/modules.d/alsa</path>. Your cards are identified by their
driver names inside this file. 0 is the first card, 1 is the second, and so on.
Here's an example for a system with two sound cards.
</p>

<pre caption="Two sound cards in /etc/modules.d/alsa">
options snd-emu10k1 index=0
options snd-via82xx index=1
</pre>

<p>
Or, if you have two cards that use the same driver, you specify them on the same
line, using comma-separated numbers. Here's an example for a system with three
sound cards, two of which are the same Intel High Definition Audio card.
</p>

<pre caption="Multiple sound cards in /etc/modules.d/alsa">
options snd-ymfpci index=0
options snd-hda-intel index=1,2
</pre>

</body>
</section>
<section>
<title>Plugins</title>
<body>

<p>
You may want to install some plugins for extra functionality.
<c>alsa-plugins</c> is a collection of useful plugins, which include: PulseAudio
output, a sample rate converter, jack (a low-latency audio server), and an
encoder that lets you output 6-channel audio through digital S/PDIF connections
(both optical and coaxial). You can choose which of its plugins you want
installed by adding their USE flags to <path>/etc/portage/package.use</path>.
</p>

<pre caption="Installing alsa-plugins">
# <i>emerge -avt alsa-plugins</i>
</pre>

</body>
</section>
<section>
<title>A big thank you to...</title>
<body>

<p>
Everyone who contributed to the earlier version of the Gentoo ALSA Guide:
Vincent Verleye, Grant Goodyear, Arcady Genkin, Jeremy Huddleston, 
John P. Davis, Sven Vermeulen, Benny Chuang, Tiemo Kieft and Erwin.
</p>

</body>
</section>
<section>
<title>References</title>
<body>

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

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