The Advanced Linux Sound Architecture (ALSA) is intended to be a replacement for the Open Sound System (OSS), which is the current standard for Linux sound services. The ALSA architecture provides several important advantages over the standard drivers:
- ALSA is more modular than the standard Linux sound card drivers.
- ALSA is easier to install than other Linux sound configuration architectures.
- ALSA can emulate the standard OSS sound drivers.
- ALSA simplifies the process of configuring more than one sound card for your system.
- ALSA uses a very flexible interface, making it easier to develop applications that use sound.
- ALSA may be configured as a dummy driver on systems with no sound card installed.
What you need
- A 2.2 series or newer version of the Linux kernel running on an x86 computer
- Some familiarity with the Linux shell
- Experience compiling and installing the Linux kernel
With this knowledge and experience, you’re ready to begin. Installing ALSA is a seven-step process:
- Download ALSA.
- Determine the type of sound card your system is using.
- Compile the kernel with sound support.
- Install the ALSA drivers.
- Build the device files required by ALSA.
- Configure ALSA to use your sound card.
- Test ALSA on your system.
Step one: Download ALSA
Unfortunately, the ALSA packages are not yet available as binary executable programs. The source code for the ALSA packages must be downloaded from the Alsa-project site.
There are four packages you need to install ALSA:
- Alsa-driver: The ALSA kernel modules
- Alsaconf: The ALSA setup utility
- Alsa-utils: The sound card configuration utility
- Alsa-lib: The interface to ALSA
Step two: Identify your sound card
Once ALSA is downloaded, the next step is to identify your sound card. The ALSA Web site provides a list of cards and chipsets currently supported by ALSA. If you already know which type of card you’re running, check the sound card matrix at the ALSA Web site to confirm which module is required. The ALSA installation also includes an autoprobe capability, but if this method fails to detect your card properly, use one of the following methods to determine the type of sound card you have. In particular, you will need to know the chipset the card uses to load the correct module into the kernel.
If you use a PCI sound card, use the following command:
This command is included with the pciutils package and will provide useful information.
If you use an ISA card, use the command:
This command is part of the isapnptools package.
If you use a dual-boot system with Linux and Windows installed, run Windows and go to Start | Settings | Control Panel | System | Device Manager to identify your sound card.
Once you have identified your sound card, you’re ready to compile the Linux kernel with support for sound.
Step three: Compile the kernel with sound support
To enable sound support on a Linux system, two features need to be compiled into the kernel:
- Support for loadable modules
- Support for sound
This Daily Drill Down won’t cover the steps necessary to compile and install a new Linux kernel. It is assumed that you have the experience necessary to compile the kernel with the required support.
When you compile the kernel, remove any sound card drivers from the kernel prior to compiling. ALSA will load the driver required by your sound card later.
Step four: Install the ALSA drivers
Once the kernel is compiled and installed, the next step is to install the ALSA drivers. First, untar and uncompress the alsa-driver package with the command:
tar –Ixvf alsa-driver-0.5.10a.tar.bz2
The next step is to enter the directory containing the alsa-driver package with the command:
Prior to running the configure script in this directory, make sure of the configuration options you require. The following options are supported by the alsa-driver package:
- -with-isapnp=yes/no/auto: Selects the ALSA isapnp utility, or the standard Linux isapnp tool. If you don’t use an ISA sound card, select no.
- -with-sequencer=yes/no: Select yes if a MIDI driver is required.
- -with-oss=yes/no: Select yes for ALSA to emulate the OSS sound system.
- -with-cards: Provides a comma-separated list of the card or cards ALSA will provide support for. The option “ALL” will provide support for all ALSA-supported sound cards. The option “dummy” may be used if no sound card is installed, but sound support is required.
- -with-prefix=directory: The ALSA directory package includes C header files used to build other ALSA utilities. The default location is /usr/include. If another location is required, enter the directory path to that location (e.g., /usr/local/include).
On my system, I use a Creative SoundBlaster ensoniq PCI sound card, based on the ens1371 chipset. I don’t require the isapnp package, and I don’t use OSS emulation. However, I do need MIDI support, and I use the default location for the C header files. To configure ALSA with these options, I use the command
./configure –with-isapnp=no –with-sequencer=yes –with-oss=no –with-cards=ens1371
The next step is to build and install the modules with the following two commands:
The ALSA drivers and header files are then installed, and a script to load and unload ALSA when the system is booted and shut down is generated.
Step five: Building the ALSA device files
The next step is to create the ALSA device files. The alsa-driver package uses the snddevices script to create these files. The procedure ALSA uses to interface with your sound card relies heavily on the /proc filesystem. The snddevices script creates dynamic device files in /proc/asound/dev.
The snddevices script links /proc/asound/dev to /dev/snd and also creates entries in /dev to provide OSS emulation. To run the snddevices script, run the following command from the alsa-driver package directory as root:
On most Linux distributions, the group “audio” will own the device files created by this process. Only users who are members of this group will be able to read and write to the audio hardware (sound card). Users who require the ability to configure the sound card will need to be made members of this group.
If you are running a 2.2 series kernel, the /dev/sndstat file, which is used to provide information on installed OSS drivers, won’t work properly. The solution to this problem is to remove the /dev/sndstat file and create a new link to /proc/asound/sndstat with the commands
ln /dev/sndstat /proc/asound/sndstat
At this point, the ALSA drivers are installed, but they are not yet configured. The alsaconf utility creates ALSA configuration files automatically, but alsaconf requires that the ALSA libraries and the ALSA utilities be installed first.
The configuration process for the ALSA library and ALSA utility packages normally doesn’t present any problems. To configure the ALSA libraries, run the commands:
tar –Ixvf alsa-lib-0.5.10.tar.bz2
Repeat the process for the alsa-utils package. Once these packages are installed, you’re ready to start configuring ALSA.
Step six: Configuring ALSA with alsaconf
The alsaconf utility makes the process of setting up ALSA a lot simpler. This utility is actually a script that allows the user to select the sound card and then automatically generates the necessary configuration files.
Remember that ALSA also requires kernel modules to be loaded to provide support for a specific sound card. There are two common ways of loading kernel modules. The first is to use the modprobe command to load the appropriate module whenever support for the sound card is required. On my system, I would run the following command as root to load the kernel module for my sound card:
Unfortunately, this method requires that the kernel module for your sound card be loaded each time you boot your system. Another way of ensuring that the proper kernel module is loaded when the system is started is to ensure that the module is associated with the sound in the /etc/modules.conf file. This file is read when the system is booted and tells modprobe which modules are associated with which device on your system. The alsaconf utility is used to automate the process of creating the correct entry in the /etc/modules.conf file. The first step is to untar and uncompress the alsaconf package with the command:
tar –zxvf alsaconf-0.4.3b.tar.gz
Next, run the command
and then run the command
When alsaconf is running, take the following steps:
- Select the correct sound card type for your system.
- Choose an identifier for your card or select the default CARD_0.
- Select “no more cards” when you have made your choices.
- The alsaconf script will now generate the appropriate /etc/conf.modules file for your system and will try to start ALSA.
Step seven: Test ALSA on your system
Assuming ALSA will start successfully, the /proc/asound directory will be created. To confirm that this directory exists, run the command
If the directory has been created, the output to the previous command will be similar to the following:
|16:||[0- 0]:||Digital audio playback|
|24:||[0- 0]:||Digital audio capture|
The exact output of this command will depend on the sound card you are using and its capabilities.
When ALSA first runs, all audio channels are set to mute by the mixer. This means that you have to adjust the volume level before you hear any sound. Almost all sound cards come with their own playback and recording packages, and on Linux systems, all of these tools are controlled by ALSA. With ALSA, either the console-based alsamix utility or the gtk-based gamix may be used to control sound volume and recording settings for your system.
If you run GMIX (the GNOME mixer tool), simply uncheck the mute setting and set the volume levels for the channels you are going to use. Once you have the settings you want, save your configuration with the command
The aplay utility is a console-based tool that will allow you to play sample sounds in several formats. If you have Gnome installed, try the command
If you don’t hear any sound, don’t panic. Troubleshooting sound on Linux systems is not always easy, but it isn’t impossible. First, check your speakers. Make sure they have power and are connected to your sound card properly. If that doesn’t work, read the ALSA FAQ for possible solutions. Then recheck everything on the system.
ALSA is an ongoing project aimed at replacing the OSS as the Linux sound standard. In this Daily Drill Down, we covered a step-by-step process for installing ALSA on your Linux system. We covered the packages required to install ALSA, the procedures involved in installing each of these packages, and how to use the alsaconf and aplay utilities to configure and test ALSA-based sound on your system.
Subscribe to the Developer Insider Newsletter
From the hottest programming languages to commentary on the Linux OS, get the developer and open source news and tips you need to know. Delivered Tuesdays and Thursdays