Sound in Debian GNU/Linux

From NewbieDOC

--Chris Lale 11:46, 20 December 2006 (CET)

Contents

1 Abstract

This article explains how to set up sound in Debian GNU/Linux. It has been tested using Etch.

2 Install ALSA packages

ALSA is the Advanced Linux Sound Architecture. It may already be installed on a desktop system. If not, install these packages.

alsa-base

The "alsa-base" package contains various configuration files for the ALSA drivers. For ALSA to work on a system with a given sound card, there must be an ALSA driver for that card in the kernel. Linux 2.6 as shipped in linux-image packages contains ALSA drivers for all supported sound cards in the form of loadable modules.

For either Linux 2.6 or Linux 2.4 a custom alsa-modules package can be built from the sources in the "alsa-source" package using the "make-kpkg" utility (included in the "kernel-package" package). This is not covered here.

alsa-utils

The "alsa-utils" package contains utilities for configuring and using ALSA, including:

  • amixer: command line mixer
  • alsaconf: utility for configuring sound cards
  • alsamixer: curses mixer
  • amidi: read from and write to ALSA RawMIDI ports
  • aplay, arecord: command line playback and recording
  • aplaymidi, arecordmidi: command line MIDI playback and recording
  • aconnect, aseqnet, aseqdump: command line MIDI sequencer control
  • speaker-test: a utility for testing that sound is working
alsamixergui

The "alsamixergui" package is a GUI (Graphical User Interface) tool for the X Window System. It is a frontend for the alasmixer mixer program for use with the ALSA soundcard drivers. It supports multiple soundcards with multiple devices. It provides exactly the same functionality as "alsamixer".

alsaplayer

Alsaplayer is a generic music player that can play back a large number of file formats. It is a CLI (Command Line Interface) application.

totem-xine

Totem is a simple media player for the Gnome desktop based on xine. It will play any xine supported file, including audio files.

3 Check your hardware

Many motherboards now have integrated sound. If you have any trouble getting a PCI sound card to work, it may be because the system had auto-detected the integrated sound. You can find out whether you have more than one sound card using the "lspci" command to list PCI cards. Filter the output using "grep" to find only "audio" cards. The output for two cards would look something like this.

$ lspci | grep -i audio
00:0e.0 Multimedia audio controller: C-Media Electronics Inc CM8738 (rev 10)
00:11.5 Multimedia audio controller: VIA Technologies, Inc. VT8233/A/8235/8237 AC97 Audio Controller (rev 60)
 
Note
Note: 
Use the -i option with the grep command because the output from lspci may contain "Audio" instead of "audio".
 

4 Choose and configure a card

In a terminal, or in a terminal window, switch user ("su") to user root

$ su
(password for user root)
#

Run "alsaconf" to select and configure a sound card. The output to the terminal should look something like this. (The sound card selection dialogue itself is curses-based.)

# alsaconf
Terminating processes: 2497.
Unloading ALSA sound driver modules: snd-seq-dummy snd-seq-oss snd-seq-midi
snd-seq-midi-event snd-seq snd-cmipci snd-via82xx-modem snd-via82xx
snd-ac97-codec snd-ac97-bus snd-opl3-lib snd-pcm-oss snd-mixer-oss
snd-hwdep snd-pcm snd-mpu401-uart snd-rawmidi snd-seq-device snd-timer snd-page-alloc.
Building card database...

(Sound card selection dialogue)

Running update-modules...
Loading driver...
Setting default volumes...

Now ALSA is ready to use.

Exit from user root.

# exit
$

5 Test that ALSA sound is working

5.1 Test and adjust levels

Make sure that your speakers, or headphones, are connected to the sound card and run "speaker-test" from a terminal/terminal window. You can stop "speaker-test" using the "Ctrl-C" key combination.

$ speaker-test

You should hear static/white noise.

Adjust the sound levels with "alsamixer" (CLI) or "alsamixergui" (GUI).

If you are using "alsamixer", run "speaker-test" in one terminal/terminal window and "alsamixer" in a second terminal/terminal window. You can quit "alsamixer" using the "Esc" key.

$ alsamixer
(Quit using Esc)

5.2 Play a sound file

You can play a sound file with "aplay" (CLI) or "totem" (GUI).

$ aplay test.wav
(Ctrl-C to interrupt)

Totem may be available from the Gnome Applications menu as "Movie Player".

6 Setting default sound card

(Adapted from a post to the debian-user list by Felipe Sateler on 19 Dec 2006 - if I were a newbie how would I get sound?)

If you have two sound cards you must configure them so that they come up in the right order. This is an example of a system with a "SB Live!" PCI card and an integrated sound card. This configuration makes sure that the SB card is the default card.

$ cat /etc/modprobe.d/sound
alias snd-card-0 snd-emu10k1
options snd-emu10k1 index=0

alias snd-card-1 snd-via82xx
options snd-via82xx index=1
$

This configuration makes sure that the SB card (snd-emu10k1) is the default card. You can adjust your own configuration by editing the files /etc/modprobe.d/sound:

# nano /etc/modprobe.d/sound

Note that alsaconf doesn't do this.

7 Troubleshooting

7.1 Check file permissions

The normal user should be in group "audio".

$ groups
chris dialout cdrom floppy audio video plugdev

If "audio" does not appear in the list of groups, add the user to group audio. (You must switch user to root to do this.) The following example would add normal user "chris" to group "audio".

$ su
(password for user root)
# adduser chris audio
...
# exit

And do not forget: this user must logout and login before it works.

7.2 Another way of testing the speakers

You must do this as user root. (Kill with Ctrl-C.)

# cat /dev/urandom > /dev/audio
(Ctrl-C)

You should get static/white noise.

7.3 Some applications (OSS applications) produce no sound in ALSA

(Section added by --Chris Lale 18:11, 12 July 2007 (CEST)

ALSA is able to emulate OSS, so applications written for or configured for OSS should work transparently. These applications include, for example, XMMS, Audacity and RealPlayer. If you find that these applications give no sound and produce error messages when they are run, it may be a problem caused by running alsaconf (bug .html#432678 alsa-utils: alsaconf kills OSS applications). There are more details about this issue in the Debian-User list ([1] and [2]).

This is caused when alsaconf removes the kernel module snd_pcm_oss and fails to reload it, thus destroying the device /dev/dsp. Check that /dev/dsp exists:

# file /dev/dsp

If the device exists, you should get a message like

/dev/dsp: character special (14/3)

and the problem lies elsewhere. If the device does not exist you should get a message like:

/dev/dsp: ERROR: cannot open `/dev/dsp' (No such file or directory)

You can restore functionality temporarily by loading the module manually:

# modprobe snd_pcm_oss

However, the problem will recur next time you run alsaconf. There may also be other modules that alsaconf has failed to reload. This may cause other problems. The problem in alsaconf is the result of the presence of the file /etc/modprobe.conf. This causes /etc/modprobe.d/ to be ignored by Debian packages (including alsaconf) which store their configuration files in /etc/modprobe.d/. The permanent solution is to move /etc/modprobe.conf out of the way. Do not delete it just in case there are modules listed in it by other applications that you may need to know about if those applications start misbehaving. Rename the file instead:

# mv /etc/modprobe.conf /etc/modprobe.conf.obsolete

Now run alsaconf again and everything should work.

7.3.1 Alsaconf is broken and will not be fixed in Debian Etch

(Section added by --Chris Lale 09:18, 18 September 2007 (CEST))

Alsaconf is so buggy that it is best not to use it at the moment (according to [bug no 432678]).

You now have to use udevtrigger instead of alsaconf. See [bug no 430624].

Run udevtrigger as user root:

# udevtrigger --verbose

This should reload the modules you need. On next reboot, your system will find your soundcard. The module management is done by udev. You should not need to use alsaconf any more. If this does not work for you, please send a message to the [Debian-User list] with the details.

Alsaconf will be fixed for PnP cards in 1.0.14-2 upload - Unstable (Sid) and Testing (Lenny) - see http://lists.debian.org/debian-user/2007/09/msg01370.html.

Content is available under GNU Free Documentation License 1.2, unless otherwise stated.