Switching between internal and USB sound cards without rebooting

As my headphone jack is broken and my internal sound card gives problems with most kernels, I have recently purchased a USB sound card. Even if the card was not expensive, sound quality is noticeably better with the external card.

The problem I found with ALSA was switching from one sound card to the other without rebooting the computer (or installing PulseAudio or any other of the several complicated solutions one can find googling around).

This guy’s solution is the simplest I could find this far:

Create an /etc/udev/rules.d/00_local.rules containing:

# Default to using additional (USB) sound cards when they are available.
KERNEL=="pcmC[D0-9cp]*", ACTION=="add", PROGRAM="/bin/sh -c 'K=%k; K=$${K#pcmC}; K=$${K%%D*}; echo defaults.ctl.card $$K > /etc/asound.conf; echo defaults.pcm.card $$K >>/etc/asound.conf'"
KERNEL=="pcmC[D0-9cp]*", ACTION=="remove", PROGRAM="/bin/sh -c 'echo defaults.ctl.card 0 > /etc/asound.conf; echo defaults.pcm.card 0 >>/etc/asound.conf'"

Only programs started after the USB sound card is plugged in will use it.

If the USB card was plugged during booting, you will possibly need to unplug it and replug it for it to be picked up.