LinuxQuestions.org

LinuxQuestions.org (/questions/)
-   Linux - Software (http://www.linuxquestions.org/questions/linux-software-2/)
-   -   usb speakers as default (http://www.linuxquestions.org/questions/linux-software-2/usb-speakers-as-default-649705/)

edgjerp 06-16-2008 01:58 PM

usb speakers as default
 
I have a set of usb speakers for my laptop. when I play music using audacious, (and other gui players) I can change settings to send the music through them.

but for waking up in the morning I have a script that calls mplayer to play a random song from my library. I have not figured out how to make the system use the usb speakers for default system wide.

tredegar 06-17-2008 08:20 AM

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?

edgjerp 06-17-2008 12:11 PM

thanks! now my script-launched mplayer uses the usb speakers.

tredegar 06-26-2008 02:12 PM

Quote:

now my script-launched mplayer uses the usb speakers.
But I have discovered that this may not work always.
Please see this thread for a more robust script:
http://www.linuxquestions.org/questi...0/#post3196077
You'll have to adapt it a bit to recognise your USB soundcard's unique identifier, but this should be easy once you have read the post.

Naimbora 02-16-2013 04:28 PM

Hi,

Iwas just following the steps but Idont have the alsa-utils file in the directory /etc/init.d/ . I only have alsa-restore and alsa-store files. How can restart the sound system?

Cheers!

tredegar 02-17-2013 04:12 AM

Welcome to LQ!

This thread is over 4 years old, and many things have changed with linux since then, including the way sound cards are handled.

So, please start a new thread with the details of your problem.

Also, it is important for you to tell us the linux distribution you are using (eg "Mint 14" or "Fedora 18"), because the different distributions sometimes handle things very differently.


All times are GMT -5. The time now is 05:48 AM.