How to output stereo sound on multiple channels of a surround output?

My computer has 4 sound output jacks, that are meant to be used as 7.1 surround output. However, I only ever have stereo sound to play. I would like to connect speakers to one jack and headphones to another one, and have the same stereo sound output to both at the same time. That way, I can simply turn/put on whichever I want to use. I would not need to change the connections or select the correct output via software.

Additionally, I have a subwoofer to supplement the speakers. I can connect it to one channel (e.g. right) of another jack, but it would need to have the right and left channel mixed into this one channel, as the subwoofer only has a mono input.

I use Pulseaudio 13.99 on Ubuntu 20.10.

How can I duplicate the stereo sound to multiple output jacks, and mix both sides into one for the subwoofer?


The Solution

Via pavucontrol (PulseAudio Volume Control), I set the sound card to work as a 4.1 output. That way, the front and rear jacks get enabled fully, and one channel of the center-subwoofer jack. Exactly as I need it. If I wanted to connect more than 3 devices, I could also use 7.1 output to enable all 4 jacks.

pavucontrol: enable 4.1 output

I added a custom pulsaudio configuration file ~/.config/pulse/default.pa:

# load the system defaults
.include /etc/pulse/default.pa

# create a stereo sink, duplicating to front, and rear jack,
# as well as mixing into the right channel of
# center-subwoofer jack (i.e. the subwoofer channel)
load-module module-remap-sink sink_name=duplicate sink_properties="device.description='duplicate to front, rear, and subwoofer'" master=alsa_output.pci-0000_00_1b.0.analog-surround-41 channels=6 master_channel_map=front-left,front-right,rear-left,rear-right,lfe,lfe channel_map=front-left,front-right,front-left,front-right,front-left,front-right remix=no

set-default-sink duplicate

The master= parameter specifies the name of the 4.1 output I found via pacmd list-sinks, which also shows the names of all available channels for master_channel_map=. lfe stands for "low frequency emitter", i.e. the subwoofer.

3 sink(s) available.
    index: 0
    name: <alsa_output.pci-0000_00_1b.0.analog-surround-41>
    driver: <module-alsa-card.c>
…
    channel map: front-left,front-right,rear-left,rear-right,lfe
             Surround 4.1
…

After forcing a restart of PulseAudio with pulseaudio -k, I can select the newly created virtual output and sound plays on all three jacks as desired.

Parameter Details

The virtual sink's name set with sink_name= can be any name that is not already in use by another sink. The description in sink_properties= is optional and can be anything.

master_channel_map= specifies the original sink's channels that I want to map to. I specified lfe twice, because I want to map both left and right channel to it. channels= specifies the number of channels in master_channel_map=.

channel_map= specifies which channels the newly created virtual sink shall have, and to which channel of the original sink they are mapped to. There have to be exactly as many entries as in master_channel_map=.

remix=no disables needless remixing between channels, as recommeded in the PulseAudio documentation.