Page 1 of 1

Choosing a default sound card

Posted: Fri Sep 21, 2012 1:57 am
by kyelo
I know how to set up /etc/asound.conf to use card 0, the bcm2835 chip as hw:0,0

I know how to set up /etc/asound.conf to use a Logitech USB headset, which becomes card 1 when it is plugged into the Pi, and it is represented as hw:1,0.

Is there a way to set up /etc/asound.conf so that if the USB headset is not plugged in, the system defaults to hw:0,0/bcm2835, and if the USB headset is plugged in the system defaults to hw:1,0/usb-audio?

As I have been using it, I have been manually changing the /etc/asound.conf to comply with whichever device I want to use. There must be an easier way!

Re: Choosing a default sound card

Posted: Wed Sep 26, 2012 3:47 pm
by elatllat
I don't know the proper way of doing that,
but you could use dnotify to trigger a script to swap conf files,etc for you.

Re: Choosing a default sound card

Posted: Wed Sep 26, 2012 5:04 pm
by kyelo
I think I may have stumbled onto a solution...at least it seems to have been working for 2-3 days.

Go to /etc/modprobe.d/alsa-base.conf, and comment out the line "options snd-usb-audio index=-2". This line seems to set a lower loading priority for module snd-usb-audio than snd-bcm2835. Since snd-bcm2835 is loaded first, it gets assigned to card 0, and snd-usb-audio is loaded second it is assigned card 1.

So if the line is commented out, and at boot-time the USB headset is plugged in and discovered, its module (snd-usb-audio) is loaded first and assigned card 0. If at boot-time the the USB headset is not detected, the snd-usb-audio is not loaded, and snd-bcm2835 is assigned to card 0. That way the hardware assignment in "/etc/asound.conf (of "hw:0,0") will work with both hardware.

So if I want to use the USB headset, after plugging it in, I just need to reboot. I am pretty much a nooby, so if this information is not correct I would appreciate some feedback.

Re: Choosing a default sound card

Posted: Sun Nov 25, 2012 12:00 am
by MountainRider
kyelo wrote:I know how to set up /etc/asound.conf to use a Logitech USB headset, which becomes card 1 when it is plugged into the Pi, and it is represented as hw:1,0.
Can you post your "/etc/asound.conf" for this? I am having trouble with my Turtle Beach Amigo II. No matter what I do, I can't get ALSA to recognize the USB adapter as the default sound card.

Re: Choosing a default sound card

Posted: Sun Nov 25, 2012 12:17 am
by MountainRider
kyelo wrote:Go to /etc/modprobe.d/alsa-base.conf, and comment out the line "options snd-usb-audio index=-2". This line seems to set a lower loading priority for module snd-usb-audio than snd-bcm2835. Since snd-bcm2835 is loaded first, it gets assigned to card 0, and snd-usb-audio is loaded second it is assigned card 1.
When I do this, the driver for the on board audio device (snd-bcm2835) does not get loaded, so my USB adapter is the only sound device reported. However, aplay still does not recognize it as the default device and I have to run "aplay -D sysdefault:CARD=Audio <wave file name>" to get any audio out of the USB adapter.

Re: Choosing a default sound card

Posted: Sun Nov 25, 2012 12:26 pm
by ski522
Don't comment the line out, instead use

Code: Select all

options snd-usb-audio index=0 

Re: Choosing a default sound card

Posted: Sun Nov 25, 2012 6:24 pm
by s7mx1
Pulseaudio will do exactly what you want.

Re: Choosing a default sound card

Posted: Sun Nov 25, 2012 8:02 pm
by kyelo
MountainRider wrote:
Can you post your "/etc/asound.conf" for this? I am having trouble with my Turtle Beach Amigo II. No matter what I do, I can't get ALSA to recognize the USB adapter as the default sound card.
Here is my /etc/asound.conf:

Code: Select all

pcm.mmap0 {
    type mmap_emul;
    slave {
      pcm "hw:0,0";
    }
}

pcm.!default {
  type plug;
  slave {
    pcm mmap0;
  }
}
There may be other ways to accomplish what you want, but this works for me.

When I boot with the USB headset plugged in, it is recognized as card 0 and used by the system (and the built-in bcm2835 is recognized as card 1). When I boot without the USB headset plugged in, the bcm2835 is listed as card 0 and controls the output, sending it to the 3.5mm jack or HDMI if that is being used.

I have no experience with or knowledge of pulse audio, so that might be easier.

Re: Choosing a default sound card

Posted: Sun May 12, 2013 7:47 pm
by aguirrech
USB sound card must be fixed as hw 0,0 in " /etc/modprobe.d/alsa-base.conf " :

options snd-usb-audio index=0

And make the usb card as the default device in ” /etc/asound.conf ”
Just erase all and replace with this :

pcm.!default {
type hw
card 0
}
ctl.!default {
type hw
card 0
}