Tips for USB Soundcards

My laptop speakers suck, so if a USB sound card is available, I'd rather use it. For this to work, I need the following to happen:

I had some hints from this Gentoo wiki page, but it refers to the old dev.d system. My laptop runs Ubuntu Feisty Fawn, which uses udev instead.

The first step is to write a couple udev rules to execute a script. I'm not sure my rules are the best, but here they are:

      DRIVER=="snd-usb-audio", ACTION=="add", RUN+="/home/jesse/bin/"

      SUBSYSTEM=="sound", ACTION=="remove", RUN+="/home/jesse/bin/"

I stuck them in /etc/udev/rules.d/50-snd-usb.rules.

Next, I wrote the simple script. My idea was to use symlinks to choose between two different /etc/asound.conf files. Here's the script:


         rm /etc/asound.conf

         if [ "${ACTION}" == "add" ] 
           ln -s /etc/asound.conf.usb /etc/asound.conf
           ln -s /etc/asound.conf.onboard /etc/asound.conf


Finally, create the two asound.conf files, asound.conf.onboard and asound.conf.usb. These two files are exactly the same, except for the following code at the bottom:

         pcm.!default {
                 type plug
                 slave.pcm "hda-intel"

         ctl.!default {
                 type hw
                 card "0"

For asound.conf.usb, we change slave.pcm to "usb-audio" and card to "1".

One last thing: my USB sound card has no volume control, so I want to control the volume using the multimedia keys on the laptop. Normally, no problem: I've already set the default card control, so if I had bound the keys to change, say, PCM, then it would change the PCM of either the USB card or the onboard card, as desired. But my onboard card has two PCMs, so I prefer to change its Master setting, while my USB card has no Master control at all.

So, here's my solution. I set the keys as follows:
XF86AudioLowerVolumeamixer -c 1 set PCM 5%- || amixer -c 0 set Master 5%-
XF86AudioRaiseVolumeamixer -c 1 set PCM 5%+ || amixer -c 0 set Master 5%+
XF86AudioMuteamixer -c 1 set PCM toggle || amixer -c 0 set Master toggle
This way, the multimedia keys try to control card 1 (the USB card). If that fails (say, if the USB card is not present), then they will instead control card 0.

Because I use enlightenment, I used e16keyedit to make those changes. For other window managers, you'll have to use the appropriate tool.


Jesse Hughes
Last modified: Fri Aug 8 11:07:24 EDT 2008