Valid HTML 4.01 Transitional
Prev: UEFI Booting for OpenSuSE Next: VoIP Versus Intrusion Alarm
(Index)
Jim Carter's Bugfixes

Bugs in the Belfry: Fixing ALSAsound .asoundrc

James F. Carter
2017-08-07
Symptom:

Nothing has changed in your sound setup for three years, and sound is playing correctly, e.g. aplay /usr/share/sounds/alsa/test.wav or similary for PulseAudio. Then you sneeze, and sound stops playing. Tested under strace, the program (alsamixer, this time) does not fail. And then when you try to write down the complete symptom set, it starts working again.

What's happening:

I have no solid evidence. It feels to me like a race condition, or an uninitialized variable, or an overflow in the buffer containing one of the strings from ~/.asoundrc .

How to fix:

The device called default is special: it is used if no device is specified to play on (or capture from). It can be defined in ~/.asoundrc by this motif:

pcm.!default = pcm.azalia;

I've found that when ALSA is failing, if I put the '!' before default it (usually) starts working again. Later if I remove it, ALSA may or may not continue to work. '!' means that the assigned value takes precedence over other assignments.

Appendix on ALSA resources:
Appendix on .asoundrc Format

Here's an example of a very simple stanza in .asoundrc:

# AMD emulation of Soundblaster or Intel Azalia, with ATTR{id} = SB
pcm.azalia = {
	type	= hw;
	card	= SB;
	device	= 0;
};
ctl.azalia = {
	type	= hw;
	card	= SB;
};

pcm.!default	= pcm.azalia;

Appendix on device numbering:

In the modern kernel with udev and systemd, device drivers are loaded in parallel, producing a guaranteed race condition for picking device numbers, so major and sometimes minor numbers can change from one boot to the next. Recommended to mitigate this:


Prev: UEFI Booting for OpenSuSE Next: VoIP Versus Intrusion Alarm
(Index)