Basic ALSA Configuration

In this article I’ll show you how to setup ALSA, with a working .asoundrc configuration file that supports multiple applications!

1- Installation

Gentoo Linux:

emerge --sync && emerge -av media-sound/alsa-utils

Void Linux:

xbps-install -Su && xbps-install -S alsa-utils

Arch Linux:

pacman -Syu alsa-utils

2- Unmuting Channels

Once ALSA is installed, we need to unmute the master channel for our sound card. We can do that using the ncurses interface of alsamixer (Use F6 to switch to your default soundcard, then press F5 to show all options):

If you can’t record sound using your internal microphone make sure that the Mic and Capture channels are unmuted (pressing the spacebar key on the Capture channel should switch from ——- to L R CAPTURE, this is necessary for the microphone to work).

3- ALSA Services

These are (alsa-restore, alsa-state, alsasound… etc). In most distros, these services are automatically enabled, however just to be safe, let’s see how we can enable and start them on:

4- Default Sound Card & Sound from Multiple Applications

After you’ve done all the previous steps, ALSA should be working perfectly. Sound from multiple applications which is supported by alsa’s dmix plug-in is enabled by default. However, on some setups (like mine), the default sound card may not be your main sound card (for example HDMI and Intel HD Audio PCH):

The HDMI soundcard is given an index of 0, and your main PCH soundcard is given an index of 1. Thus the default card chosen by ALSA is the HDMI card. Therefore, you’ll hear nothing. To fix this, first we need to tell if the soundcard drivers and codecs are built into the kernel or left as modules.

In the latter, we can easily fix this problem by specifying our default sound card as a kernel parameter. Create a file in /etc/modprobe.d called alsa.conf or whatever_you_like.conf:

touch /etc/modprobe.d/alsa.conf

And put the following in it:

options snd-hda-intel index=1,0

This swaps the index numbers of both cards giving your main PCH sound card an index of 0, and your HDMI soundcard an index of 1.

However, if your soundcard drivers and codecs are built into the kernel. That previous line won’t do a thing. You have to tell ALSA when you’re starting an X session which card you want to use as your default soundcard. Therefore you need to create a file in your home directory called .asoundrc:

touch ~/.asoundrc

Now here’s a custom configuration that I use to swap both cards, and enable sound from multiple applications without sacrificing any sound quality whatsoever:

This defines 3 character arrays that will hold our volume controlling commands respectively.

Now, let’s map these commands to the hexadecimal code of your multimedia volume keys. To find out the hexadecimal code of your multimedia volume keys, fire up a terminal in a X session, focus on the shown window, press your shortcut keys and copy the codes. You should get something like this: