Profile of the Boot Process of a Debian System. Profile of the Boot Process of a Debian System, generated using a custom Python script. … read more

Jvterm. Homepage of the JVTerm terminal emulator. … read more

Publication: Fast-Dm: a Free Programm for Efficient Diffusion Model Analysis. Fast-DM, a flexible and fast computer program, allows estimating all parameters of Ratcliff's diffusion model. … read more

Using the ALSA Sound System

By Jochen Voss, last updated 2011-09-17

This page summarises 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.

Configuration

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 recognise 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 esd or 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:
 0 [VirMIDI        ]: VirMIDI - VirMIDI
                      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
  0: [ 0]   : control
  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 /etc/asound.conf or .asoundrc in your home directory) containing statements like the following ones:
defaults.ctl.card 1
defaults.pcm.card 1
defaults.timer.card 1

This file would make card 1 the default. The card number (1 in this example) is taken from the /proc/asound/cards file. 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?
Use alsamixer to make sure that you selected your microphon 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 ardour and it worked quite well.

Programs

Volume Control / Mixers

program version remarks
alsamixer 1.0.10 Text modus mixer. Works well. You can choose which sound card to use with the -c option. +
aumix 2.8 Needs OSS emulation. Defaults to soundcard 0 (by using /dev/mixer by default. You can select a different mixer with the -d option. -
GNOME
mixer applet
gnome-applets
2.12.2
Supports ALSA but ignores default soundcard setting (it uses card 1 in the system described above when the default is card 2). There is no way to manually make it use the correct card. -
GNOME
settings daemon
gnome-control-center
2.12.2
This daemon is running while I am logged into GNOME and for some reason it keeps the device /dev/snd/controlC0 (the mixer of the virtual midi device) open all the time, presumably to preserve volume settings between logins. Whatever it is trying to do, it will not work by using this device. -
GNOME
volume control
2.12.0 This allows selecting a sound device and remembers your settings. Ignores the ALSA default device setting. +-

Table 1. This table summarises the ALSA support of different mixers on a Debian GNU/Linux system.

Daemons / frameworks

program version remarks
esd Esound
0.2.36
The sound daemon currently used by the GNOME desktop environment. Can be compiled to work with ALSA. +
gstreamer 2.12.0 Can be configured to use ALSA using gstreamer-properties. Works well. +
jack 0.100.0 Uses ALSA by default. The daemon ignores the default device setting, but you can select a device manually. +-

Table 2. This table summarises the ALSA support of different sound daemons and frameworks on a Debian GNU/Linux system.

Applications

program version remarks
alsaplayer 0.99.76 Works well with ALSA (no surprise). +
audacity 1.2.4 Uses OSS. When using the ALSA's OSS emulation, the program insists on using card 0. -
ardour 0.99 Uses JACK to connect to the sound hardware. +
xmms 1.2.10 Can be configured to use ALSA (at the Audio I/O Plugins pane of the preferences window), works well. +

Table 3. This table summarises the ALSA support of different applications on a Debian GNU/Linux system.

References

Copyright © 2011, Jochen Voss. All content on this website (including text, pictures, and any other original works), unless otherwise noted, is licensed under a Creative Commons Attribution-Share Alike 3.0 License.