Ubuntu – Volume widget issue with sound card hotplugging

soundsoundcardvolume-control

When plugging a USB sound card may sometimes cause the current audio output (ie. Banshee and PC speakers) to switch immediately. But the volume controls (sound widget in systray, volume keyboard keys) are stuck on the old sound card.

Plug a soundcard and amplifier while the volume is set to ultra high for the pc speakers. You can't control the volume without opening the sound settings or alsamixer. This could probably cause neighbour disturbance in some countries. You can't control it with the sound widget of the systray nor the volume keyboard keys.

How to disable auto switch of hardware audio output, or enable auto switch of software volume controls ? It would be great to make the software behaviour consistent with the hardware's.

Ubuntu 11.10 vanilla up to date.

Best Answer

You can achive what you want by using an udev rule that is written to act upon certain events. In this case these events are to plug usb sound card and to unplug it. According to this forum answer, possible solution is like following:

  1. Open the file that has usb sound card udev rules:

    sudo -H nautilus /etc/udev/rules.d/10-usb-sound-card.rules
    
  2. Paste and copy

    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'"
    
  3. Save the file and give

    sudo udevadm trigger --action=add /etc/udev/rules.d/10-usb-sound-card.rules
    

command. Then test this rule by pluging and unpluging your usb sound card.

I hope this will help you.