Gentoo Forums
Gentoo Forums
Gentoo Forums
Quick Search: in
Set default alsa card on usb speaker hotplug
View unanswered posts
View posts from last 24 hours

 
Reply to topic    Gentoo Forums Forum Index Documentation, Tips & Tricks
View previous topic :: View next topic  
Author Message
Alighieri
Tux's lil' helper
Tux's lil' helper


Joined: 27 Jan 2005
Posts: 88

PostPosted: Tue Aug 30, 2005 4:00 am    Post subject: Set default alsa card on usb speaker hotplug Reply with quote

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
View user's profile Send private message
BlueShadow
n00b
n00b


Joined: 30 Nov 2004
Posts: 24
Location: Switzerland

PostPosted: Mon Dec 05, 2005 4:08 pm    Post subject: Reply with quote

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
View user's profile Send private message
henri
Apprentice
Apprentice


Joined: 15 Nov 2002
Posts: 182
Location: Germany

PostPosted: Fri Jun 30, 2006 9:31 am    Post subject: Reply with quote

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
View user's profile Send private message
Display posts from previous:   
Reply to topic    Gentoo Forums Forum Index Documentation, Tips & Tricks All times are GMT
Page 1 of 1

 
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum