Super User is a question and answer site for computer enthusiasts and power users. It's 100% free, no registration required.

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

My new USB audio speaker appeared as the second device in Alsa. I managed to make it the primary one:

$ cat /proc/asound/modules 
 0 snd_usb_audio
 1 snd_hda_intel
$ cat /proc/asound/cards
 0 [Speaker        ]: USB-Audio - uBoom Q Speaker
                      uBoom Q Speaker at usb-0000:00:1d.1-1, full speed
 1 [Intel          ]: HDA-Intel - HDA Intel
                      HDA Intel at 0x80000000 irq 16

by adding these lines to /etc/modprobe.d/alsa-base.conf:

options snd_hda_intel index=1
options snd_usb_audio index=0

Now, when I boot USB-Audio works by default everywhere. The problem is — when I disconnect it (or boot without it), I see

$ cat /proc/asound/modules 
 1 snd_hda_intel

and nothing works because there's no 0-th device:

$ aplay
ALSA lib confmisc.c:768:(parse_card) cannot find card '0'

The thing I want is a way to re-assign device indexes. If the solution is a script — I'm going to create a udev rule with it.

Currently, I change 'index=?' back to the default '0,1', invoke alsa force-reload and it helps. Any better way?

Note: there's no asoundconf in my distro (KUbuntu Lucid) :(

share|improve this question

try installling asoundconf-gtk but take care of

share|improve this answer
up vote 1 down vote accepted

First, let's deal with Alsa devices' indexes. Plug in your USB Speaker and invoke sudo alsa force-reload so Alsa finds it.

List cards indexes and their drivers:

$ cat /proc/asound/modules 
 0 snd_hda_intel
 1 snd_usb_audio

Show more detailed info:

$ cat /proc/asound/cards
 0 [Intel          ]: HDA-Intel - HDA Intel
                      HDA Intel at 0x80000000 irq 16
 1 [Speaker        ]: USB-Audio - uBoom Q Speaker
                      uBoom Q Speaker at usb-0000:00:1d.0-1, full speed

We want to have 'Speaker' with index=0.

Add these lines to /etc/modprobe.d/alsa-base.conf to make USB Speaker the default device, if present:

options snd_hda_intel index=-2
options snd_usb_audio index=-1

This makes USB-Speaker more preferable than the Builtin-card. Issue sudo alsa force-reload, voila! Now you can see with cat /proc/asound/cards how cards appear & disappear when you plug in/off your USB-Speaker.

Here's another receipt how to choose which of the 2 available cards will the next launched application use.

Add these lines to /etc/asound.conf:

$ cat /etc/asound.conf.switch 
#=== CARD 'card0'
pcm.card0-hw { type hw ; card 0 ; }
ctl.card0-hw { type hw ; card 0 ; }

pcm.card0 { type dmix ;
    ipc_key 4109 ; ipc_perm 0660 ;
    slave { pcm "hw:0,0"
        channels 2 ; period_size 1024 ; buffer_size 4096 ; rate 44100 ; period_time 0 ;
    bindings { 0 0 ; 1 1 ; }

#=== CARD 'card1'
pcm.card1-hw { type hw ; card 1 ; }
ctl.card1-hw { type hw ; card 1 ; }

pcm.card1 { type dmix ;
    ipc_key 1949 ; ipc_perm 0660 ;
    slave { pcm "hw:1,0"
        channels 2 ; period_size 1024 ; buffer_size 4096 ; rate 44100 ; period_time 0 ;
    bindings { 0 0 ; 1 1 ; }

This will create two 'dmix' playback devices: 'card0' & 'card1'. They will allow you to switch between them without problems.

Now, put this in ~/.asoundrc:

# Define new virtual devices
pcm.this                { type plug ; slave.pcm "card1" ; }
ctl.this                ctl.card1-hw
# Set default device
pcm.!default    pcm.this
ctl.!default    ctl.this

to switch to the second card. Replace all '1's with '0's to switch back. A small script will be handy :)

NOTE: In this manual we created several new Alsa devices: 'this', 'card0-hw', 'card0', 'card1-hw', 'card1'. You can refer to them:

$ amixer -D 'this' scontrols
Simple mixer control 'PCM',0

P.S. I'm not in common with how Alsa really works and may have made terrible mistakes :) Please correct me if there's a better way. But still, this works :)

share|improve this answer

I tried the simple edit of alsa-base.conf setting the onboard to -2 and the usb to -1 but this didn't work.

however, when I set BOTH to -1 (with the onboard listed first), then I could switch back and forth.

I do have to perform an alsa force-reload at each change, though.

share|improve this answer

I'm trying to resolve the same problem: automatically rerouting audio stream when an USB sound card is plugged into the system, so I decided to write a new rule for udev:


SUBSYSTEMS=="usb", ATTRS{idVendor}=="****", ATTRS{idProduct}=="****", RUN+="/usr/local/bin/"

of course, you must replace the '*'s with numbers according to your device (use lsusb to know which ones)

The script is very simple :

ln -sf /path/to/custom/asoundrc /home/<user>/.asoundrc

Another rule may be added to revert the configuration when the device is removed (sorry, I'm still working on it)

share|improve this answer

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.