User:SwifT/Wikified but not merged documents/ALSA guide

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

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  to make application development a breeze.

Before you proceed
First, you need to know what drivers your sound card uses. In most cases, sound cards (onboard and otherwise) are PCI based and  will help you in digging out the required information. Please  to get  , if you don't have it installed already. In case you have a USB sound card,  from    might be of help. For ISA cards, try using. Also, the following pages may help users with ISA based sound cards:


 * The ISAPNPTOOLS Page
 * LinuxJournal PnP Article
 * TLDP Sound HowTo

We now proceed to find out details about the sound card.

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 ALSA Soundcard Matrix page and select Creative Labs from the list. You will be taken to the Creative Labs matrix page where you can see that the SB Live! uses the  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  specific page.

If you intend to use MIDI, then you should add  to your USE flags in  before emerging any ALSA packages. Later in the guide, we will show you how to set up.

Configuring the kernel
Let us now configure the kernel to enable ALSA.

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

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  which is a boon when you want to configure your card. Please do not skip the section of this document. If you still like to have options built-in, ensure that you make changes to your config accordingly.

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 and see if everything is working as it should.

ALSA Utilities
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

Configuration
Recent versions of   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  to configure your card, as shown below.

To configure your sound card just type  in a shell as root.

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. It will then adjust your volume settings to optimum levels, run  and start the  service. Once  exits, you can proceed with setting up the ALSA initscript.

ALSA Initscript
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. Add it to the boot runlevel.

Next, just check the file and ensure that SAVE_ON_STOP variable is set to yes. This saves your sound settings when you shutdown your system.

Audio Group
Before we move on to testing, there's one last important 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  here and you need to be logged in as root for this to work.

Volume Check!
We've completed all the setups and prerequisites, so let's fire up ALSA. If you ran , you can skip this step, since   already does this for you.

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  for this purpose.

This is how the ALSA Mixer might 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  in this state, you will not hear anything on your speakers.

Now, we shall unmute the channels, and set volume levels as needed.


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

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.

Sound Check!
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. You could also use something more well known like. If you are an ogg fan, you could use  provided by. Use any player you are comfortable with. As always,  what you need.

And then play your favorite sound track...

ALSA and USE
You can now add the  use flag to  to ensure that your applications that support ALSA get built with it. Some architectures like x86 and amd64 have the flag enabled by default.

Issues?
If for some reason you're unable to hear sound, the first thing to do would be to check your 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.

is your friend. And in this case, is your best friend. We shall just take a short look at how much info is made available to us there.

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

And when you take a look at  as suggested, you're quite likely to see:

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

The solution is quite easy. We just need to manually remove the problem causing directory after you unmerge. Be sure to remove the correct kernel version and not the current one!

Another reason for error messages similar to the ones above could be a file in supplying a   parameter when it isn't required. Confirm that this is indeed the issue and find out which file is the culprit.

Usually it is a file called with the line. Remove this line and restart the  service and that should take care of this issue.

Setting up MIDI support
First, check to make sure that you enabled the  USE flag in. If you didn't, go ahead and add it now. You will also need to re-emerge any ALSA packages that use the  flag, such as   and.

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  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 for more information.

After copying over the Soundfont files, we can then play a midi file as shown. You can also add the  command to , so that the sound font is loaded every time the system starts up.

You can now play midi files using a program like. Run  to get a list of available ports and then pick one to play the file on.

Virtual Synthesizers
If your sound card lacks a hardware synthesizer, you could use a virtual one like. Installation is a breeze.

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  and. You can have multiple sound font configurations installed, and you can place your own in. To switch between different timidity configurations, you should use.

Don't forget to add  to the default runlevel.

You can now try out files.

Tools and Firmware
Some specific sound cards can benefit from certain tools provided by the  and   packages. You may install either with a simple.

Multiple sound cards
You can have more than one sound card in your system simultaneously, provided that you have built ALSA as modules in your kernel. You just need to specify which should be started first in. 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.

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.

Plugins
You may want to install some plugins for extra functionality. 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.

A big thank you to...
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.

Acknowledgements
We would like to thank the following authors and editors for their contributions to this guide:


 * Shyam Mani
 * Joshua Saddler
 * Diego Pettenò