Scenario: you have two sound cards. You want to at the click of an icon switch from one sound card to the other. Here’s an example of how to set it up.

Create definitions for your cards in /etc/asound.conf:


pcm.usb {
        type hw
        card 1
        device 0
        channels 2
}
pcm.desktop {
        type hw
        card 0
        device 0
        channels 2
}
pcm.!default {
    type plug
    slave.pcm "desktop"
}

Several things are going on here. The first two blocks are providing names for the sound cards in my system. You can find the correct values for card and device by typing “aplay -l” on the command line. For channels, choose 2 unless you have a surround sound system. The !default block defines the system default, i.e. which of the cards is used if you don’t specify which to use.

Next, create additional files for each of your sound cards:

/usr/sound/.asoundrc_desktop


pcm.!default {
    type plug
    slave.pcm "desktop"
}

/usr/sound/.asoundrc_usb


pcm.!default {
    type plug
    slave.pcm "usb"
}

Finally, create executable scripts to do the switching:

/bin/alsa_usb


cp /usr/sound/.asoundrc_usb ~/.asoundrc

/bin/alsa_desktop


cp /usr/sound/.asoundrc_desktop ~/.asoundrc

Make icons or menu items that point to these scripts, and test them out. Most programs (e.g. firefox, xmms, etc) will have to be restarted after you switch from one card to the other in order to pick up the change.

I would love to be able to make programs use both soundcards at the same time, but haven’t cracked that nut yet. Solutions appreciated if you have that working.



Related Comments (1)