Raspberry Pi – Setting Up Your Audio

The first thing to note is that we are aiming to get out analog audio jack working. If this is not your goal and you are trying to get audio over HDMI to work then you simply need to follow the same directions and substitute “2” instead of “1” when you are told in the instructions below. Be on the lookout:

Step 1:

Install your libraries. Alsa, mpg321 and lame:

sudo apt-get install alsa-utils
sudo apt-get install mpg321
sudo apt-get install lame

Step 2:

Load the driver:

sudo modprobe snd_bcm2835

Step 3:

Make sure you can find the right driver:

sudo lsmod | grep 2835

Step 4:

For this next part, if you are wanting to get analog audio working use a “1” if you are using HDMI use a “2”. The rule is “0” = auto.

sudo amixer cset numid=3 1

Step 5:

Test is out. You can test it a couple different ways but one of them is to use wget to get a file from online and then play it.

wget http://secretemessages.s3.amazonaws.com/output.wav
aplay output.wav

You can also test out an mp3 using the same process, find an mp3 online and play it.

wget wget http://www.freespecialeffects.co.uk/soundfx/household/bubbling_water_1.mp3
mpg321 bubbling_water_1.mp3

If all has gone well that your audio works.

Troubleshooting:

If you run into errors about unrecognized PCM cards and shit, just modify: /usr/share/alsa/alsa.conf and replace the lines about “pcm.front cards.pcm.front” to something like “pcm.front cards.pcm.default“.

If you hear your speakers pop but no sound, try adjusting the volume. Run the following command:

alsamixer

When the gui pops up, press the number “9” to turn the volume up to 9. This should allow you to hear the sound. When you want to save your alsamixer settings enter…

sudo alsactl store

Also I added the modprobe line in step 2 to my f~/.bashrc file so it automatically does it on startup, I know that probably not the way it was intended to work but what the hell.

One last note: there is a great resource for controlling audio with alsa here: http://blog.scphillips.com/2013/01/sound-configuration-on-raspberry-pi-with-alsa/

3 thoughts on “Raspberry Pi – Setting Up Your Audio

  1. Thank you!! This has been very useful. One small question though, if I want to listen to the audio then after the wget command I need to type the command “mpg321 bubbling_water_1.mp3”. Why do you think that is the case?

Leave a Reply

Your email address will not be published. Required fields are marked *

This site uses Akismet to reduce spam. Learn how your comment data is processed.