ALSA
![]()
ALSA (Advanced Linux Sound Architecture) is the part of the Linux kernel, that provides an API for applications and sound servers to interact with the sound card. Applications can either directly interact with ALSA or talk to a sound server. An application that does not interact with ALSA directly installed Firefox. It requires the use of a sound server:
+---------+ +---------------+
| firefox | | application 2 |---------------+
+---------+ +---------------+ |
| |
| talks to an sound server |
V |
+------------+ +------+ +----------+ |
| pulseaudio | | jack | | pipewire | |
+------------+ +------+ +----------+ | talks to ALSA directly
| | | |
V | | |
+--------------+ | | |
| linux kernel |<--+ | |
| - ALSA |<------------+ |
+--------------+<---------------------------+
|
| linux kernel (ALSA) talks to the soundcard
V
+------------+
| sound card |
+------------+
ALSA is also a user space library that provides functions like effects, down mixing and routing.
Prior to ALSA, there was OSS (Open Sound System), but this has been deprecated for nearly 20 years. OSS can still be installed and used today, however it is quite tricky and not recommended.
Packages
alsa-utils: installs thealsamixerand various other utilities likespeaker-test.libasound2: ALSA user space library and its standard plugins. Required configuration files are included as well.libasound2-plugins: Additional plugins for the user space library, like rate converters and up-/down mixing plugins.apulse: Converts PulseAudio API calls to ALSA API calls. This is required for applications such as Firefox, which don't use ALSA directly but rather PulseAudio.
Setup
User setup
The user needs to be in the "audio" group that he can play audio. To add a user to the audio group run:
sudo adduser yourusername audio
Configuration
The ALSA configuration files are located in /etc/alsa/conf.d directory. Most
required files are already present with common default values. To change the
ALSA configuration, add a new file in here.
Changing the default card
Sometimes, the wrong default audio card is selected. This might occur when a laptop is plugged into an audio interface. Most likely the laptop's internal sound card is the default, even though we want to output audio over the audio interface (why is it plugged in otherwise). To change the default card, first list them:
cat /proc/asound/cards
Or
aplay -l
By default, ALSA uses the sound card with the index 0. If this is not the sound card, that you want to play audio from, either force the cards to load in a different order, or change the default card:
- Force the cards to load in a different order:
To do this, you need to edit
/etc/modprobe.d/sound.conf:
options snd-trident index=0
options snd-usb-audio index=1
- Change the default card
To do this, edit either
/etc/asound.confor$HOME/.asoundrc. A sample configuration could look like this:
defaults.pcm.card
defaults.pcm.device
Testing the audio
To test the sound output, you can use any audio player. The alsa-utils
package provides aplay, which is quite handy for this task. With aplay you
can play uncompressed WAV files:
aplay /usr/share/sounds/alsa/Noise.wav