So, here's the fix which allows you to even switch between Stereo and 5.1 at runtime, without touching the pulseaudio CLI.
Pulseaudio manages the input/output configuration through so-called profile set configuration files. More information on this is available upstream.
The thing is, the profile shipped with pulseaudio for the raspberry Pi HDMI output ... only contains stereo (as of bullseye).
[General]
auto-profiles = yes
[Mapping digital-stereo]
description = Digital Stereo
device-strings = hw:%f
fallback = yes
priority = 1
direction = output
channel-map = left,right
paths-output = hdmi-output-0
In order to be able to switch between stereo and 5.1, you can do the following:
Place the following in a convenient location, I chose /etc/pulse/profile-sets/rpi-hdmi.conf (creating the directories):
[General]
auto-profiles = yes
[Mapping digital-stereo]
description = Digital Stereo
device-strings = hw:%f
priority = 1
direction = output
channel-map = left,right
paths-output = hdmi-output-0
[Mapping hdmi-surround]
description = Digital Surround 5.1
device-strings = hw:%f
paths-output = hdmi-output-0
channel-map = front-left,front-right,lfe,center,rear-left,rear-right
priority = 3
direction = output
Disable udev in your /etc/pulse/default.pa by adding a # in front of the line load-module module-udev-detect.
Load the sink manually by adding, to the bottom of the default.pa, the following:
load-module module-alsa-card card_name=hdmi sink_name=alsa_output.hw_0_0 device_id=b1 tsched=false profile_set=/etc/pulse/profile-sets/rpi-hdmi.conf
Restart pulseaudio or the entire Raspberry Pi
You should now be able to switch between modes in the configuration tab of the pavucontrol utility. If your Pi is running headless (without any screen), you can access the pulse server remotely using PULSE_SERVER=1.2.3.4 pavucontrol, where you need to substitute 1.2.3.4 with the IP address of your Raspberry Pi.
Make sure to adapt the path to your modified rpi-hdmi.conf if you put it in a different location.
This is tested to work on a Raspberry Pi 2B running latest Raspbian/Raspberry Pi OS Bullseye, connected to a Denon AVR-1910. I use a custom boot config because I have no TV attached and I also don't have the Denon online all the time, so the Pi may not detect it properly as HDMI sink:
dtparam=audio=on
hdmi_force_hotplug=1
hdmi_edid_file=1
hdmi_force_edid_audio=1
hdmi_group=1
hdmi_mode=5
hdmi_pixel_encoding=1
/usr/share/pulseaudio/alsa-mixer/profile-sets/default.conftochannel-map = front-left,front-right,lfe,front-center,rear-left,rear-rightas per https://forums.raspberrypi.com/viewtopic.php?p=1959978&hilit=hdmi+surround+alsa#p1959978In current release, surround works out of the box and the stops above are not needed. But I guess given how the original question is structured, this is the way to go, so I will accept it.
– sup Mar 22 '22 at 14:27