Plug in your USB speakers. Now
cat /proc/asound/cards
You'll see something like this:
Code:
tred@vaio:~$ cat /proc/asound/cards
0 [Intel ]: HDA-Intel - HDA Intel
HDA Intel at 0x80000000 irq 16
1 [Audio ]: USB-Audio - Bose USB Audio
Bose Corporation Bose USB Audio at usb-0000:00:1d.2-1, full speed
tred@vaio:~$
So I can see my USB speakers are at [1]
As root do the following:
Code:
cp /usr/share/alsa/alsa.conf /usr/share/alsa/alsa.conf.orig
Now, still as root, edit the file
/usr/share/alsa/alsa.conf and find this bit:
Code:
# defaults
defaults.ctl.card 0
defaults.pcm.card 0
Change the 0's to 1's
Save the file
Still as root, do
Code:
cp /usr/share/alsa/alsa.conf /usr/share/alsa/alsa.conf.USB
Restart the sound system,
Code:
sudo /etc/init.d/alsa-utils restart
And your USB speakers will be working.
I made an ugly hack, so that if the PC boots with the USB speakers plugged in, it uses them, otherwise, it uses the internal soundcard (Intel, in my case)
So I put this code at the end of
/etc/rc.local
Code:
# Simple control of Bose USB speakers
# If they are plugged in at boot, they'll be used,
# otherwise the internal soundcard will be used
#
# It may fail if anything is using the sound card when it is called
foo=$(cat /proc/asound/cards | grep Bose)
if [ "$foo" != "" ] ; then
# Use USB speakers
# echo Bose USB speakers detected >> /var/log/messages
cp /usr/share/alsa/alsa.conf.USB /usr/share/alsa/alsa.conf
/etc/init.d/alsa-utils restart
# BUT realplay defaults to using /dev/dsp, and doesn't know to use
# /dev/dsp1, so we need a another hack:
rm /dev/dsp
ln -sT /dev/dsp1 /dev/dsp;
else
# Use the original conf file
# echo No Bose USB speakers detected >> /var/log/messages
cp /usr/share/alsa/alsa.conf.orig /usr/share/alsa/alsa.conf
/etc/init.d/alsa-utils restart
fi
exit 0
I would have liked to do something clever with udev rules, so that when the USB speakers were plugged it, they were selected and configured automatically, and unselected when unplugged, but it got too complicated for my tiny brain, and I resorted to the above, which works fine
Anyone out there good with udev rules?