Blog
Surround Sound on a Raspberry Pi 3 2024-10-06
In this post, we are going to cover how to play videos on a Raspberry Pi 3 with multiple audio channels (i.e. 5.1 Surround Sound) over the HDMI port.
By default, a Raspberry Pi 3 uses ALSA for audio, and we'll assume you're using that instead of PulseAudio.
Installing VLC
First up, we are going to need to install vlc
to play videos and audio from the command line, as the old omxplayer
is deprecated:
sudo apt-get install --no-install-recommends vlc-bin vlc-plugin-base
The command above will not install the vlc-plugin-qt
package, which I think is good for a headless setup of VLC. We only care about running vlc
from the command line.
Configuring HDMI settings
The next step is setting some configuration in /boot/config.txt
for the Raspberry Pi. Here are the relevant entries in my file:
# Stop rPi from sending active source message over CEC at start-up
hdmi_ignore_cec_init=1
# Pretends CEC is not supported at all by TV.
# Ignoring CEC prevents weird situations where the rPi wants to set itself
# as the active source when the receiver is turned on
hdmi_ignore_cec=0
# Enable audio (loads snd_bcm2835)
dtparam=audio=on
The only important line is this one dtparam=audio=on
. The others are just nice when your Raspberry Pi is connected to a TV or receiver.
Configuring ALSA
Next, we need to modify either /etc/asound.conf
or ~/.asoundrc
. I prefer modifying the latter. Here's what it looks like:
pcm.!surround51 {
type route
slave.pcm "hw:0,0"
slave.channels 8
ttable {
0.0= 1
1.1= 1
2.4= 1
3.5= 1
4.3= 1
5.2= 1
6.6= 0
7.7= 0
}
}
This creates a device called surround51
that sends 6 channels of audio to hw:0,0
under the hood. You need to ensure that hw:0,0
is the HDMI audio device. Check this with aplay -l
. Here's what I get on my system when I run aplay -l
:
**** List of PLAYBACK Hardware Devices ****
card 0: b1 [bcm2835 HDMI 1], device 0: bcm2835 HDMI 1 [bcm2835 HDMI 1]
Subdevices: 4/4
Subdevice #0: subdevice #0
Subdevice #1: subdevice #1
Subdevice #2: subdevice #2
Subdevice #3: subdevice #3
card 1: Headphones [bcm2835 Headphones], device 0: bcm2835 Headphones [bcm2835 Headphones]
Subdevices: 4/4
Subdevice #0: subdevice #0
Subdevice #1: subdevice #1
Subdevice #2: subdevice #2
Subdevice #3: subdevice #3
For some folks, you may need to use hw:0,1
instead. On my system, I have already used raspi-config
to set the HDMI port as the audio output instead of the 3.5" audio jack, which is probably why it's hw:0,1
. I should also note that I had to fiddle a bit with the channel mapping in the ttable
section of the .asoundrc
file. YMMV.
At this point, you should be able to run speaker-test -c 6 -D surround51
to test each speaker individually.
Configure VLC
Finally, you need to configure VLC to always use the surround51
ALSA audio device with 6 channel audio. To do this, create / modify the ~/.config/vlc/vlcrc
file:
[alsa]
alsa-audio-device=surround51
# 4199 = 5.1 surround
alsa-audio-channels=4199
Then, run vlc
on a video file to play it. I'd recommend trying something like this 5.1 surround sound test video.
Additional Resources / Ideas
- https://forums.raspberrypi.com/viewtopic.php?t=307369
- https://raspberrypi.stackexchange.com/questions/68288/hdmi-passthrough-with-raspbian
- https://github.com/raspberrypi/linux/issues/528 – Run
vcgencmd hdmi_stream_channels 1
. Can be permanently enabled with linehdmi_stream_channels=1
in/boot/config.txt
. Also consider atno_hdmi_resample=1
- https://forums.raspberrypi.com/viewtopic.php?t=207610 – PulseAudio configuration
- https://www.mythtv.org/wiki/Raspberry_Pi#Digital_Audio_with_ALSA
Hopefully, this helps you enjoy 5.1 surround sound with your favorite movies!
Blog Post Index
- 2024-12-14 Typora – A Brief Review of the Best Markdown Editor
- 2024-11-06 nushell – A Shell Using Structured Data
- 2024-10-07 Building a Markdown Blog with Caddy
- 2024-10-06 Surround Sound on a Raspberry Pi 3
- 2024-10-03 Building a Markdown Website with Caddy
- 2024-09-25 My Git Configuration
- 2024-09-11 Why Databases
- 2024-09-06 New Website