Tuesday, March 18, 2014

Getting sound to work on the Raspberry Pi

I wanted to try out audio on the Raspberry Pi, using the Raspbian OS. Here's how I got it to work.

The installer I used for Raspbian was the minimal network installer by hifi. This will use up only about 150MB of space and will not install a desktop, so you'll save a lot of resources with this approach.

After installing Raspbian, this is what I needed to do in order to get sound output.

First, login as root (default password = raspbian - change it ASAP!).

Update the package list for APT, the package installer tool of Debian:
apt-get update

Install ALSA.
apt-get install alsa-base

At this point I discovered that the minimal installer doesn't include the sound card module of the raspi.

Alsa's aplay is a  wav file player, and with it I could check which sound devices are available:

aplay -L

The output:
    Discard all samples (playback) or generate zero samples (capture)

... and when trying to enable the sound card module, I got an error:
modprobe snd_bcm2835

libkmod: ERROR ../libkmod/libkmod.c:554 kmod_search_moddep: could not open moddep file '/lib/modules/3.10-3-rpi/modules.dep.bin'

Just in case, I installed apt-utils first and configured some packages the minimal Rasbpian installer had left unconfigured:
apt-get install apt-utils
dpkg-reconfigure -au

Then to update the raspberry pi firmware and kernel!
apt-get install git-core
apt-get install rpi-update

After the update process, I checked the firmware version:
uname -a
Linux pi 3.10-3-rpi #1 Debian 3.10.11-1+rpi3 (2014-01-01) armv6l GNU/Linux

Then a reboot and check the version again:
uname -a
Linux pi 3.10.33+ #656 PREEMPT Fri Mar 14 18:19:28 GMT 2014 armv6l GNU/Linux

Now, modprobe will enable the sound card!
modprobe snd_bcm2835

And the sound is working! You can try this out with speaker-test (ctrl-c to break):

Or you can use aplay and the sounds included in ALSA:
aplay /usr/share/sounds/alsa/Front_Left.wav

1 comment:

  1. this tutorial worked for me! thanks a lot!