| View previous topic :: View next topic |
| Author |
Message |
Alighieri Tux's lil' helper


Joined: 27 Jan 2005 Posts: 88
|
Posted: Tue Aug 30, 2005 4:00 am Post subject: Set default alsa card on usb speaker hotplug |
|
|
I bought a pair of usb speakers and wanted alsa to automatically switch to the usb-audio card when the device is plugged into the usb port. First, make sure you have usb-audio configured. Plugin the speakers and cat /proc/asound/cards. You should see your usb-audio device. Then put the following
| Code: |
#!/bin/sh
CARDNUM=`sed -n 's/\(^[0-9]\).*/\1/p' < /proc/asound/cards | tail -n 1`
cat<<EOF > /etc/asound.conf
pcm.!default {
type hw
card $CARDNUM
}
ctl.!default {
type hw
card $CARDNUM
}
EOF
|
in /etc/dev.d/sound/alsa-default.dev (name is unimportant, but must end in .dev). Make it executable. Whenever there is a sound hotplug event, the default alsa card will be the last one listed in /proc/asound/cards. This also works when the speakers are unplugged (returns to card 0). |
|
| Back to top |
|
 |
BlueShadow n00b

Joined: 30 Nov 2004 Posts: 24 Location: Switzerland
|
Posted: Mon Dec 05, 2005 4:08 pm Post subject: |
|
|
Well that is exactly what I tried to do. I have an Creative Soundblaster MP3 USB-Card.
This works just great, I only had to adopt your script for my asound.conf.
Thx very much |
|
| Back to top |
|
 |
henri Apprentice

Joined: 15 Nov 2002 Posts: 181 Location: Germany
|
Posted: Fri Jun 30, 2006 9:31 am Post subject: |
|
|
Hi Alighieri,
really: Great! It was also exactly what I was searching for
It would be very nice if this hint could be added to the gentoo ALSA howto because laptops become more and more common and external USB speakers will probabely be the choice of many users.
But I had to change the CARDNUM fetching line from...
| Code: | | CARDNUM=`sed -n 's/\(^[0-9]\).*/\1/p' < /proc/asound/cards | tail -n 1` |
...to...
| Code: | | CARDNUM=`grep -o -e '[[:digit:]]' < /proc/asound/cards | tail -n 1` |
Many thanks for your posting,
yours Henri |
|
| Back to top |
|
 |
|