Pipewire natively supports a filter to create a 7.1 virtual surround sound device that will work with any headphones or earphones. It’s not well documented, so I decided to write a step-by-step guide for enabling it in Pop!
How it Works
Sound is distorted by your head and shoulders relative to your ears in slightly different ways based on the direction the sound is coming from. The distortion, which is known as HRIR (head-related impulse response), is how our brains are able to interpret sound spatially, despite ours ears only being capable of receiving stereo audio.
Pipewire is able to achieve a convincing 7.1 surround sound effect either by using either a SOFA (spatially oriented acoustic data) spatializer, or a HRTF (head-related transfer function) convolver to interpolate a replicated 7.1 HRIR input onto a 7.1 surround input, mimicking the natural process by which we hear sound spatially.
A replicated 7.1 HRIR input is created by placing microphones in the ears of an artificial dummy, and measuring the differences in sound it experienced while listening to a 7.1 surround sound system. Which is why we perceive surround sound in headphones.
SOFA takes this technology to the next level with a more advanced algorithm that can process many additional forms of data inputs to improve the surround sound effect.
Option 1: SOFA Spatializer
Step 1: Copy the following 7.1 SOFA spatializer filter-chain config locally. This creates a virtual output sink with 7.1 surround sound channels.
mkdir -p ~/.config/pipewire/filter-chain.conf.d/
curl -o ~/.config/pipewire/filter-chain.conf.d/spatializer.conf \
https://gist.githubusercontent.com/mmstick/039422a63c73a09e998d08608abaee43/raw/9c4dfef5a447fe25a47e3492e518e134e57ee9d4/7.1-spatializer.conf
Step 2: Download a SOFA DTF for the filter to utilize as its input.
sudo mkdir -p /usr/share/pipewire/sofa/
sudo curl -o /usr/share/pipewire/sofa/dtf.sofa \
https://sofacoustics.org/data/database_sofa_0.6/ari/dtf%20b_nh724.sofa
Then go to Step 4 below
Option 2: HRIR Convolver
Step 1: Copy the 7.1 filter-chain config locally. This creates a virtual output sink with 7.1 surround sound channels.
mkdir -p ~/.config/pipewire/filter-chain.conf.d/
cp /usr/share/pipewire/filter-chain/sink-virtual-surround-7.1-hesuvi.conf \
~/.config/pipewire/filter-chain.conf.d/virtual-surround.conf
Step 2: Download a 7.1 HRIR wav file from the HRTF Database, such as Atmos or CMSS-3D. Then move it into your local pipewire configuration.
mkdir -p ~/.config/pipewire/hrir/
mv ~/Downloads/atmos.wav ~/.config/pipewire/hrir/atmos.wav
Step 3: Edit the copied virtual-surround config to use this wav file.
sed -i "s#hrir_hesuvi/hrir.wav#${HOME}/.config/pipewire/hrir/atmos.wav#g" \
~/.config/pipewire/filter-chain.conf.d/virtual-surround.conf
Start the filter and test it
Step 4: Start pipewire with the filter-chain config. The virtual surround device will now exist as long as this is running in the background.
pipewire -c filter-chain.conf
Step 5: Select the virtual surround sink output device and try it out.
- https://www2.iis.fraunhofer.de/AAC/7.1auditionOutLeader_v2_rtb.mp4
- https://www.youtube.com/watch?v=ClpEj1ayNSs
Side Effects
There’s a slight audio latency increase from using virtual surround sound, depending on how fast the CPU is. It is a simple process though so the performance cost is slight.
Stereo audio sources should have the same sound before and after. Surround sound content will sound as they were intended to be heard, and it could help with dialogue in some movies being difficult to hear. Especially if you are able to configure the volume of the center speaker channel where dialogue is usually played.
Help
Any help with finding a way to automate this when plugging in headphones would be great.
The config file doesn’t seem to support environment variables: for it throws an error in the logs when i use the
${HOME}
variable.I can’t find any docs on if it supports any environment vars - does it work for you?
The above sed command will automatically convert it before writing the replacement.
(I don’t see comments below the post - only saw this in my inbox right now?)
Aha, I did the change manually, forgetting that sed would substitute the var. Would be great if Pipewire was aware of environment variables, but that’s not an issue to complain about here I guess :)