Subscribe to Grim's Projects        RSS Feed
-----

Sound on an Arch Linux ARM Raspberry Pi

Icon Leave Comment
Getting sound to work on your Raspberry Pi isn't too difficult. Just seems like a lot of the information out there is somewhat scattered, and on Arch it also takes a little bit of system configuration. The first thing is that you need to load the sound module at boot. This is easily done with the following commands (all commands assume you've logged in as root user):
[root@alarmpi ~]$ echo "# Load snd-bcm2835.ko at boot" > /etc/modules-load.d/snd-bcm2835.conf
[root@alarmpi ~]$ echo "snd-bcm2835" >> /etc/modules-load.d/snd-bcm2835.conf
Most of the tutorials to test the sound will tell you to use modprobe snd-bcm2835, and that does indeed make the module available, but it only does so for that session. Which means you'd have to input that command every time you log on.

Next, we want to install our sound utility, in this case ALSA, or the Advanced Linux Sound Architecture and then reboot:
[root@alarmpi ~]$ pacman -S alsa-utils
[root@alarmpi ~]$ reboot
After you've logged in you'll want to launch the volume control to ensure the audio isn't muted.
[root@alarmpi ~]$ alsamixer
You'll get a colored bar at the center of your screen, if you see the letters MM at the bottom of the bar, then your audio is muted. Simply press the letter "M" on your keyboard to unmute, you should see the letter change to a number. You can raise or lower the volume with the up and down arrows. When you're done press the "Esc" key.

Now we need to determine HOW you want to output audio. Do you want to do it over the 3.5mm audio port or over HDMI port? There is one console command that controls these functions:
[root@alarmpi ~]$ amixer cset numid=3 0
This command means audio is automatically determined (it doesn't always work as you want it to).
[root@alarmpi ~]$ amixer cset numid=3 1
This command outputs audio over the 3.5mm audio port.
[root@alarmpi ~]$ amixer cset numid=3 2
This command outputs audio over the HDMI port. As you can see the command is the same, the only thing that changes is the final parameter, which can be either 0, 1, or 2, representing auto, 3.5mm port, hdmi port, respectively.

To test the audio we issue the following command:
[root@alarmpi ~]$ speaker-test -c 2
You will hear a series of static noise produced from your left and right speakers in succession. Press Ctrl + C to exit the test.

Let's say you want to test it over the 3.5mm port, your command input would look as follows:
[root@alarmpi ~]$ amixer cset numid=3 1
[root@alarmpi ~]$ speaker-test -c 2
Assuming you have speakers/headphones connected to the port you should hear the alternating static noise. Press Ctrl + C to exit. Don't forget to restore the auto setting (amixer cset numid=3 0) unless you intend to ALWAYS use the 3.5mm audio jack.

Let's say you want to test it over the HDMI port, your command input would be this:
[root@alarmpi ~]$ amixer cset numid=3 2
[root@alarmpi ~]$ speaker-test -c 2
It's very possible that you might not hear any audio. This is because some HDMI monitors have a special setting that needs to be enabled before you can get audio. This setting is found in the /boot/config.txt file. To set it, press Ctrl + C to exit the audio test, then input the following commands:
[root@alarmpi ~]$ echo "hdmi_drive=2" >> /boot/config.txt
[root@alarmpi ~]$ reboot
After rebooting, try the test again:
[root@alarmpi ~]$ amixer cset numid=3 2
[root@alarmpi ~]$ speaker-test -c 2
You should now hear the static noise alternate between your speakers. Press Ctrl + C to exit and don't forget to restore the auto setting (amixer cset numid=3 0) unless you intend to ALWAYS use the HDMI port for audio.

Now application which make use of ALSA will provide audio. This includes the RasPi's GPU enabled media player omxplayer. The "amixer cset numid=3 0" command leaves the task of determining where to output audio up to the RasPi. Inasmuch as I know, you can only output to one of the two audio ports, presumably if you don't have the HDMI port connected it will automatically output to the 3.5mm port and vice-versa. I suggest you experiment with this yourself using the "speaker-test -c 2" command to see what happens.

0 Comments On This Entry