If you have worked on current Linux audio for a while, you have seen that ALSA, by far the most common and compatible audio hardware driver set, likes to give numbers to its hardware. Its numbers usually start with 0, as in ‘hw:0′, ‘hw:1′, et cetera. The problem is that the numbers it gives, often have nothing to do with what the system needs to work well.
For instance, until today, if I booted my PC with my USB MIDI interface removed, my sound card was hw:0. But if I booted my PC with the MIDI in, my sound card was hw:1, the MIDI interface was hw:0, and sound in general didn’t work at all, because the default card was still hw:0. I learned this the hard way, two minutes before the band was to play, and I didn’t have time to reboot. Sigh.
But I just learned a better way. Two new items. First, in addition to numbers, ALSA gives alphanumeric names. And second, we can tell ALSA to choose specific cards, by name, as default for all audio. There is a kludgy way to do this using negative numbers, which I used years ago; but that drove me crazy, and doesn’t always help!
There is another confusion which was recently explained to me. ALSA understands its hardware in three levels: there is the “card”, the “device”, and the “subdevice”. A sound card very often has more than one device; devices often have sub-devices. For instance, one very expensive sound card will have one alphanumeric name (we’ll say “XYZ”); but it may well have a stereo device (“XYZ,1″), a 5.1 surround output device (“XYZ,2″), and two or three input devices (“XYZ,3″ and “XYZ,4″), and each of these devices has subdevices representing each channel.
Here are my steps:
1. First find out the alphanumeric name of the sound card you want to use. Go to a terminal, and do this:
cat /proc/asound/cards
I have exactly one sound card engaged; the motherboard sound is turned off in BIOS (and this BIOS, happily, really does shut it off when told to do so). Thus the command above shows only one card right now:
0 [HD2 ]: Prodigy71HD2 - Audiotrak Prodigy HD2
Audiotrak Prodigy HD2 at 0xef80, irq 10
The string in the brackets is the alphanumeric name of this card: ‘HD2′. In most ALSA configuration locations, one uses it like this: ‘hw:HD2′. If sound still doesn’t work as desired, it is more than possible that devices within the card need to be specified explicitly, e.g., ‘hw:HD2,1′, ‘hw:HD2,2′, et cetera. Some trial and error may be necessary. For large-scale multitrack hardware, there still is one name, but the device numbers can go very high, especially for something like a 24-track USB box. Testing is really the next step:
2. We can set the default sound card for ALSA, for all users, to the above. We do this by creating (or replacing) the text file /etc/asound.conf. On this system, it is:
pcm.!default {
type hw
card HD2
}
ctl.!default {
type hw
card HD2
}
and the following on my hardware does exactly the same thing:
pcm.!default {
type hw
card HD2,0
}
ctl.!default {
type hw
card HD2,0
}
Now we’re probably not done for all sound on your machine. Most audio hardware of which I’m aware requires one or more methods of mixing multiple audio streams for stability, simply because multiple apps will be trying to sound off at the same time once in a while. ALSA docs say this is automatic, but frankly, it’s not, and this is why a configuration involving PulseAudio and ALSA is the emerging desktop standard, and all of PulseAudio, Jack, and ALSA becomes a very good idea if high-test audio with Jack is desired, as it is here.
3. I would get Jack running next, it is an important part of your toolkit. The default setup may or may not work, I wouldn’t worry about it too much. In the ‘Interface:’ field of the setup dialog for qjackctl, you should type in the alphanumeric name into the fields, instead of the menu-presets, a la for me:
hw:HD2
qjackctl also can help identify the devices within a given card. Check out the automatically identified items in the pull-down menus for the output and input devices; it can be quite educational, especially when results are studied in Google.
I find that this step, moving from numeric to alphanumeric ALSA device names, is a very good one in stabilizing a Linux sound system.
MIDI default?