The following article is being reproduced, as is, with the prior permission of the author, and all the rights rest with the original author. The original version can be found at Using the ALSA Sound System. One more thing, it is a really cool article and Jochen Voss has put huge effort into it, kudos.
This page summarizes things I learned while trying to understand and use the Advanced Linux Sound Architecture (ALSA) on my Debian GNU/Linux system. I would be happy to receive suggestions to improve or extend this web page.
This section gives some help with ALSA configuration issues. In order to avoid complications, we avoid use of external programs in figuring things out.
Is ALSA present in your kernel?
Check for the presence of a
/proc/asound/ directory. If the directory exists, you have ALSA support in your kernel.
Why does program xyz not recognize my sound card?
On current Linux systems there are several, partially conflicting ways to access the sound card: using ALSA (this is what we aim for here), using OSS (this is an older sound system, but still used by many programs), or by connecting to a sound daemon like
artsd (which in turn might use ALSA or OSS to connect to the system). Probably your program is trying to use the wrong method to play sound.
Programs using OSS can be used with ALSA by enabling the OSS compatibility layer of ALSA. You might need to load additional kernel modules to enable this. Check the file
/dev/sndstat. If the file exists and can be read, you have the OSS compatibility layer enabled. It should list audio devices which correspond to the ALSA devices on your system.
Programs using esd can be used with ALSA by compiling esd with ALSA support.
What sound cards are known to the system?
Check the contents of the
/proc/asound/cards file. Each entry there corresponds to a (real or simulated) sound card. On my system I get the following:
Virtual MIDI Card 1
1 [V8237 ]: VIA8237 - VIA 8237
VIA 8237 with ALC850 at 0x1000, irq 21
2 [Revolution51 ]: ICE1724 - M Audio Revolution-5.1
M Audio Revolution-5.1 at 0xb800, irq 16
3 [system ]: USB-Audio - iMic USB audio system
Griffin Technology, Inc iMic USB audio ...
Card 0 is a virtual MIDI card. It does not correspond to any hardware and I do not yet know what it is good for. Entry 1 is for the built-in sound hardware on my ASUS A8V main-board (since it has an interrupt, irq 19, assigned this one must be hardware). Card 2 is a M-Audio Revolution 5.1 card. Card 3 is a simple USB sound card (an iMic USB adapter), good for connecting a microphone and an external speaker.
What features do these sound cards have?
There are several ways to find out. For example /proc/asound/devices contains an entry for every component of every device ALSA knows about. For the system described above I get
1: : sequencer
8: [ 0- 0]: raw midi
9: [ 0- 1]: raw midi
10: [ 0- 2]: raw midi
11: [ 0- 3]: raw midi
32: [ 1] : control
33: : timer
48: [ 1- 0]: digital audio playback
49: [ 1- 1]: digital audio playback
56: [ 1- 0]: digital audio capture
57: [ 1- 1]: digital audio capture
64: [ 2] : control
80: [ 2- 0]: digital audio playback
81: [ 2- 1]: digital audio playback
82: [ 2- 2]: digital audio playback
88: [ 2- 0]: digital audio capture
96: [ 3] : control
112: [ 3- 0]: digital audio playback
120: [ 3- 0]: digital audio capture
There are different groups of devices: "control" (used by the system to set the volume, mute channels, etc.), "playback", "capture" (reading audio data into the computer), "raw midi", "sequencer" and "timer" (I don't know yet what the latter two do).
How do I set the default device?
Create a configuration file (either for the whole system at
.asoundrcin your home directory) containing statements like the following ones:
This file would make card 1 the default. The card number (1 in this example) is taken from the
/proc/asound/cardsfile. For a description of the ALSA configuration file format see the ALSA library API documentation.
Why does program xyz hang on start-up?
Sound devices can be only opened by one program at a time. For example if you have the esd daemon running (it is often started automatically when you log into a GNOME desktop), other programs won't be able to open the sound device simultaneously and might just silently wait until esd quits.
You can solve this problem by either stopping all other programs which access the sound device or by using one of the sound daemons and having all programs access the sound hardware through the daemon (the sound daemon can handle simultaneous connections from several programs).
Connecting a Microphone
In this section I give some hints on how a microphone can be connected to the computer to record sound using the ALSA interface.
How do I connect an analog microphone?
Most sound-cards use 3.5mm mini-jack connectors. Make sure that your card has a separate "microphone" connector. If you want to connect a microphone via the "line in" connector, you will need an external amplifier.
How do I connect a USB microphone?
Just plug it into a USB port and make sure that you have USB sound support enabled in you kernel.
Why do I record only silence?
alsamixerto make sure that you selected your microphone input for capturing data (use the "Capture" view) and that the volume is up for both the microphone line and the capture device.
Why is there a lot of noise and distorted sound in my recording?
The built-in sound hardware which comes with most computers is not of high quality. For example the on-board sound hardware on my system (see above) always adds a lot of noise to any recordings from the microphone. Another problem could be the operational noise from your computer (ventilation etc.). Some programs can remove noise from recordings, but this is no real replacement for using good hardware.
How do I record sound?
Once you have a microphone successfully connected to your machine there are many programs to record sound. I tried
ardourand it worked quite well.
Volume Control / Mixers
Daemons / Frameworks
- Official ALSA site,containing the ALSA library API documentation
- ALSA opensrc.org web site
- Planet CCRMA at home sound package collection for Red Hat/Fedora systems.
- Linux Audio Developer's Simple Plugin API (LADSPA)