BaReinhard's Tech Blog

A blog of various technologies, largely based around the Raspberry Pi.

Follow me on GitHub Follow me on Instagram

Raspberry Pi Sound Card Setup

So you finally got your USB sound card in the mail and you’re excited to start listening to higher quality audio. Only one problem, you plug it in and no sound is coming out of your speakers.

Fret not, there are only a couple simple steps we must take first.

First we must make sure we are up to date:

sudo apt-get update
sudo apt-get upgrade

Now that we are updated we can make sure that we have the proper alsa tools to properly handle the card

sudo apt-get install alsa-utils
sudo reboot

From there we can now list the sound cards available

aplay -l

You should receive the output similar to :

**** List of PLAYBACK Hardware Devices ****
card 0: ALSA [bcm2835 ALSA], device 0: bcm2835 ALSA [bcm2835 ALSA]
  Subdevices: 8/8
  Subdevice #0: subdevice #0
  Subdevice #1: subdevice #1
  Subdevice #2: subdevice #2
  Subdevice #3: subdevice #3
  Subdevice #4: subdevice #4
  Subdevice #5: subdevice #5
  Subdevice #6: subdevice #6
  Subdevice #7: subdevice #7
card 0: ALSA [bcm2835 ALSA], device 1: bcm2835 ALSA [bcm2835 IEC958/HDMI]
  Subdevices: 1/1
  Subdevice #0: subdevice #0
card 1: Device [USB Audio Device], device 0: USB Audio [USB Audio]
  Subdevices: 1/1
  Subdevice #0: subdevice #0

Next we will setup what cards will go in what slots by editing our alsa-base.conf file.

sudo nano /etc/modprobe.d/alsa-base.conf

options snd_bcm2835 index = 0

If you know for sure what module your usb sound card is you can place another line in alsa-base.conf to secure its spot. However, I find it easier just setting the bcm module as 0 and letting the other card be auto set. If you enter in a wrong module name it will not show your sound card in aplay -l and you won’t be able to use it.

Next we will be setting our asound.conf which tells the pi what card to use for different programs or as default. This file can get very advanced and intricate if the need arises, but for our usage here we just need something simple.

sudo nano /etc/asound.conf

pcm.!default {
  type hw card 1
ctl.!default {
  type hw card 1

Since we set the bcm module to 0, we want to use card 1, which is the USB sound card.

If you have a multi-user setup and desire different users to use different sound settings, you can set ~/.asoundrc to what we put in the /etc/asound.conf file.

If you have both /etc/asound.conf and ~/.asoundrc I believe that ~/.asoundrc will take priority, I have not tried this, due to my Pi’s only using one login. However, logically it makes sense for ~/.asoundrc to take priority.

Now with all that set you can reboot you pi and give it a shot!

One quick trick is using your new soundcard that has a mic port to allow for an auxillary cord playback simply use the following line of code:

arecord -D plughw:1 -f dat | aplay -D plughw:1 -f dat&

To kill the aux functionality simply run the command:

sudo pkill arecord

Hope you’ve found this useful. Enjoy!