How to make Raspberry Pi use an external USB sound card as a default

17

10

Does anyone know how to change the sound card boot priority?

All tutorials are telling me to edit /etc/modprobe.d/alsa-base.conf, but the file is missing in Raspbian Jesse.

Carl Hudson

Posted 2015-10-20T18:38:22.863

Reputation: 173

Upvote for coming right up in Google - June 2018 – SDsolar – 2018-06-05T19:39:59.663

Answers

10

The file your looking for is located in /usr/share/alsa/alsa.conf. Its not called alsa-base.conf just alsa.conf

All the relevent text is in that file just run sudo nano /usr/share/alsa/alsa.conf change the default sound card to 1 or whatever one you prefer obviously 0 is default so not that one i also deleted the # from the line that says... load card-specific configuration files (on request) and now i have the sound coming from my cirrus audio card running debian 8 jessie on ras pi2

Breeskeeper

Posted 2015-10-20T18:38:22.863

Reputation: 124

1I've done a few quick formatting fixes. Perhaps a copy of the relevant part of the alsa config file would make your answer even better. – Journeyman Geek – 2015-10-22T01:10:34.897

2Isn't "load card-specific configuration files (on request)" a comment? – SILENT – 2015-12-02T01:45:27.623

It is indeed just a comment to explain the code block below it – PTS – 2015-12-14T17:14:46.940

Yep. Partial answer. Not enough authoritative info here for me to decide on upvoting. ...and that line is a comment that is not executable. And the block itself is not commented out. – SDsolar – 2018-06-05T19:43:52.237

13

This worked for me on Raspbian Jessie.

If you don't need the onboard audio chip (i.e. analog output or hdmi audio), disable it and then the USB audio device can become the primary device:

  1. Disable onboard audio.
    • Open /etc/modprobe.d/raspi-blacklist.conf and add blacklist snd_bcm2835.
  2. Allow the USB audio device to be the default device.
    • Open /lib/modprobe.d/aliases.conf and comment out the line options snd-usb-audio index=-2
  3. Reboot
    • sudo reboot
  4. Test it out.
    • $ aplay /usr/share/sounds/alsa/Front_Center.wav

leif81

Posted 2015-10-20T18:38:22.863

Reputation: 367

I updated the answer to use a different strategy for disabling onboard audio. This way is better because it doesn't break the desktop audio applet. – leif81 – 2017-03-28T15:10:34.620

The first step is crucial but I hadn't found it anywhere else. Upvote. The rest is outdated. June 2018: Already knew to go into /usr/share/alsa/alsa.conf and change it to say both default.ctl.card 1 and default.pcm.card 1 - then after all this, reboot and try alsa -l to see only the USB showing and that it is card #1. I installed mplayer for the test and it is great. They have locked this question to answers so here it is. – SDsolar – 2018-06-05T19:56:02.123

@SDsolar Glad to help. Though I don't think Step 2 is outdated? You have an alternate way to set the device as default. Good to know. – leif81 – 2018-06-06T04:03:35.773

It could be a version issue. For instance, my 16.04 LTS systems were both immediately upgraded from the 14.04 install CD. So there are vestiges of both ways of doing things, particularly things involved with the boot process that changed under v15. In my case, the modprobe.d files exist but they are all blank. So in the end it is good that this answer shows both ways if you include my comment. --> You definitely solved my biggest issue with alsamixer by blacklisting bcm2835. I searched high and low and only your answer had that last piece of the puzzle. TNX MCH – SDsolar – 2018-06-06T16:35:44.933

3

I had problems with this on recent versions of Raspbian (Jessie).

There is a file called aliases.conf in /lib/modprobe.d which contains the line options snd-usb-audio index=-2. That line overrides the /etc/modprobe.d/ files, so you need to change that one. Comment out with a # the line options snd-usb-audio index=-2

In /usr/share/alsa/alsa.conf I un-commented “load card-specific configuration files (on request)” and I also replaced the content of .asoundrc which is a hidden file in your home folder with:

pcm.!default plughw:Device
ctl.!default plughw:Device

The downside of this solution is the desktop sound applet won't appear. So to control volume use the alsamixer application or physical sound level buttons on the USB sound dongle.

References for this:

  1. https://www.raspberrypi.org/forums/viewtopic.php?f=28&t=124016&p=857433&hilit=usb+audio#p857433
  2. http://alsa.opensrc.org/Asoundrc#Default_PCM_device.

Digitalfix

Posted 2015-10-20T18:38:22.863

Reputation: 31

2

The method described here at the Raspberry Pi StackExchange worked for me. I am running Raspian Jessie.

The new piece of information was that I had to create a new .conf file and not edit /usr/share/alsa/alsa.conf:

To reorder my cards, I first create a file named /etc/modprobe.d/alsa base.conf. It can be named anything you want as long as it ends with .conf. I then added the following:

# This sets the index value of the cards but doesn't reorder.
options snd_usb_audio index=0   
options snd_bcm2835 index=1

# Does the reordering.
options snd slots=snd_usb_audio,snd_bcm2835

Lennart Hennigs

Posted 2015-10-20T18:38:22.863

Reputation: 21

2

I wasn't satisfied with the previous answers giving a bit ambiguous instructions, so I figured I would document a more clear solution.

A good post here shows how to test which device and card you are seeking to use.

Find your hardware device number and card number using aplay -l before and after pluggin your usb device in.

For my system, the usb device is listed as card 1: CODEC [USB Audio CODEC], device 0 ...

You can confirm the device is working with

aplay -D hw:1,0 InsertYourWavFileHere.wav

Make sure to copy a valid wav audio file into your current directory and rename appropriately. If this works, then you can hardcode these values such that they will become defaults for aplay among all other audio handled by alsa (most cases)

To edit your default values you alsa config file as others have stated:

sudo nano /usr/share/alsa/alsa.conf

The specific lines you will want to change are a few pages down. You can search with Cntl+W or just scroll down.

Change:

defaults.pcm.card 0 defaults.pcm.device 0

To:

defaults.pcm.card 1 defaults.pcm.device 0

Save the config file by pressing control+x, then nano will ask you to confirm your edits and you press Y and Enter.

topher217

Posted 2015-10-20T18:38:22.863

Reputation: 181

Can you explain what you’re talking about when you say, “copy a valid wav audio file into your current directory and rename appropriately”? Is this referring to the aplay command to “confirm the device is working”? Isn’t it good enough to specify a valid wav audio file by its current name and full path? – G-Man Says 'Reinstate Monica' – 2017-12-06T17:59:46.527

@G-man Yes, specifying any wav audio file by its full or valid path should be fine.

In my particular example I had used InsertYourWavFileHere.wav but this could just as easily be replaced with ./audio/test.wav if you had a wav file in the audio subdirectory named test.wav for example. If that were the case, then

aplay -D hw:1,0 ./audio/test.wav

should work just as well. – topher217 – 2017-12-06T21:59:18.173

0

After change alsa.conf (defaults.ctl.card 1 defaults.pcm.card 1) and (load card-specific configuration files (on request)) you have to modify your asoundrc file and put in:

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

It will be ok

bouziat jacques

Posted 2015-10-20T18:38:22.863

Reputation: 1

0

I've given a full writeup here that covers all of the above and much more. Including clearing up some misconceptions and pitfalls in the ALSA config files.

The relevant essential is to disable the Broadcom audio module called snd_bcm2835 and make sure that snd_usb_audio is loaded fist and only. This can be done in either of 2 ways.

  • In the /boot/config.txt file
  • In the module blacklist file.

Then set you ALSA config to point to the snd_usb_audio index.

not2qubit

Posted 2015-10-20T18:38:22.863

Reputation: 1 234

-1

I have tried lots of people's suggestions for config changes. Kodi continued to put audio out to hdmi. I finally found that Kodi has a setting in System | Audio which allows you to choose which audio card to output to! So obvious once you see it.

Pete .T.

Posted 2015-10-20T18:38:22.863

Reputation: 1