cheatsheet.zwischenspeicher.info

Some tech documentation and snippets, finally organized.

ALSA: changing audio device priority

ALSA enumerates available audio devices in the order their corresponding kernel modules are loaded, so e.g. connecting an audio capable HDMI device can break on-board sound. For a permanent and system wide change of audio device priority, this order can be manipulated by adding a simple configuration file with the suffix .conf to the folder /etc/modprobe.d/.

First it needs to get a list of the loaded sound modules:

$ cat /proc/asound/modules
 0 MODULE_X
 1 MODULE_Y
 2 MODULE_Z

In the best case, all audio devices use different kernel modules, which will be listed, one per line, with the key options and an index value:

### File: /etc/modprobe.d/alsa.conf

options MODULE_1 index=0
options MODULE_2 index=1
options MODULE_3 index=2

If there are several audio devices based on the same chipset, additionally their associated card IDs need to be specified. The command

$ aplay -l | grep ^card

will return the necessary identifiers in the second column, right after card #:. Add them to the respective lines in /etc/modprobe.d/alsa.conf as new column three, between module name and index number.

To be prepared for the occasional use of a USB audio adapter, I suggest to additionally list the snd-usb-audio module and assign it index=0.

Here my current configuration:

### File: /etc/modprobe.d/alsa.conf

options snd-usb-audio               index=0
options snd-hda-intel   id=VT82xx   index=1
options snd-hda-intel   id=HDMI     index=2

Although this is Linux, the easiest way to make the changes take effect is to reboot the system ;)


If you have several devices with the same ID, you can make ALSA directly address the hardware by adding the following entries to /etc/asound.conf or ~/asoundrc - the respective card number can again be determined with the command aplay -l.

### File: /etc/asound.conf 
###       OR
###       ~/.asoundrc

pcm.!default {
    type hw
    card 1
}

ctl.!default {
    type hw
    card 1
}

Note: This way no other applications can access the sound card concurrently.


As a last solution, it is possible to fully disable specific cards with a line like the following in /etc/modprobe.d/alsa.conf:

### File: /etc/modprobe.d/alsa.conf

options snd-hda-intel   enable=0,1

The array will disable (0) the first and enable (1) the second of two cards.