Enable Analogue Audio Output (Raspberry Pi)

If you want to enable the Raspberry Pi to play sounds using the analogue 3.5mm jack output you need to make sure the right kernel modules are loaded and that the audio mixer is configured to use the right output.

Start by checking that the sound module for Raspberry Pi is loaded using the following command to list all the active kernel modules and check to see if any match the name of the sound module.

To do this you need to be running as root.

$ su


$ sudo -i

Then list the installed kernel modules.

# lsmod | grep snd_bcm2835

If it you don’t see any output then this means that the modules are not yet loaded, so you will have to load them manually.

# modprobe snd_bcm2835

If the module is not available you will get an error message, which probably means that you need to update your firmware and kernel to a newer version.

# modprobe snd_bcm2835
FATAL: Module snd_bcm2835 not found.

To check that this worked repeat the first command again.

# lsmod |grep snd_bcm2835
snd_bcm2835            16432  0 
snd_pcm                77728  1 snd_bcm2835
snd                    58744  3 snd_bcm2835,snd_timer,snd_pcm

This time it shows the sound modules have been loaded, if they were not automatically loaded then you need to add the sound module for the Raspberry Pi to /etc/modules.

# vi /etc/modules 

# /etc/modules: kernel modules to load at boot time.
# This file contains the names of kernel modules that should be
# loaded at boot time, one per line. Lines beginning with "#" are
# ignored. Parameters can be specified after the module name.

As well as configuring the sound module to load automatically you also need to install ALSA (Advance Linux Sound Architecture) which provides audio and MIDI functionality.

# apt-get install alsa-utils
Reading package lists... Done
Building dependency tree       
Reading state information... Done
The following extra packages will be installed:
  libasound2 libsamplerate0

If the HDMI cable is connected then the audio output will default to HDMI, otherwise it should use the analogue 3.5mm headphone output. If necessary you can force the Raspberry Pi to use the analog output with the following command.

# amixer cset numid=3 1 
numid=3,iface=MIXER,name='PCM Playback Route'
  ; type=INTEGER,access=rw------,values=1,min=0,max=2,step=0
  : values=1

To test that everything is working use the following command to play one of the test sounds installed with the ALSA package.

# speaker-test -t sine -f 440 -c 2 -s 1
# speaker-test -t sine -f 440 -c 2 -s 2
# aplay /usr/share/sounds/alsa/Front_Center.wav

To play MP3 files from the command line you will need to install an MP3 player, the example below shows how to install mpg123 which worked for me.

# apt-get install mpg123
Reading package lists... Done
Building dependency tree       
Reading state information... Done
The following extra packages will be installed:
  libltdl7 libmpg123-0

You can also use omxplayer to play MP3s and videos, however is wasn’t in the official repository so you may have to download the package your self from here.

I used version 0.3 since I did not need DBUS support. When you have download the installation package use dpkg to install it.

# wget -c 'insert link to download here'
# dpkg -i omxplayer_0.3.0~git20130815~c99bc80_armhf.deb

When running omxplayer you can specify which output to use from the command line. To use the analogue audio output.

# omxplayer -o local *.mp3

Alternativly to use the HDMI audio output.

# omxplayer -o hdmi *.mp3

The plus and minus keys can be used to adjust the volume.

Raspberry Pi is a trademark of the Raspberry Pi Foundation

This entry was posted in Hardware and tagged , . Bookmark the permalink.

2 Responses to Enable Analogue Audio Output (Raspberry Pi)

  1. Thanks for this post! Gave me the command I needed to do analogue when HDMI is output to CRT via adapter.

  2. diantahoc says:

    Awesome! Thank you for this helpful post.

Leave a Reply

Please log in using one of these methods to post your comment:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s