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.

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.

  • Quack Doc@lemmy.world
    link
    fedilink
    English
    arrow-up
    3
    ·
    1 year ago

    Great guide, It’s worth noting that you can also use SOFA filters too! HRTF is a very “Per-person” thing, Before downloading a filter, Highly reccomended to play the demo tracks first (may need to scroll right). IF none of them really do it for you, you can also try using SOFA filters instead, clubfritz is a very common sofa filter. though sadly I dont think there is a way to preview them before setting up a filter then swapping out the names

  • M4775@lemmy.world
    link
    fedilink
    English
    arrow-up
    2
    ·
    1 year ago

    Looking at the documentation for Pipewire it seems like it’s a case of “work it out yourself”. Getting this integrated/functional is no small task. Nice job!

  • Delta_44@lemmy.world
    link
    fedilink
    English
    arrow-up
    1
    ·
    11 months ago

    @mmstick@lemmy.world Since Pop_Os still has GNOME as default DE, the simplest way to automate the service start (which is the main thing to do, since it’s just a copy-paste of command now, right?) is like that:

  • mrhrdr@lemmy.world
    link
    fedilink
    English
    arrow-up
    1
    ·
    1 year ago

    Hey, thank you so much for this!

    I seem to be misunderstanding some step though: I have copy-pasted the steps above and put the atmos.wav file in the hrir directory, but I don’t get any sound in my headphones when I select the Virtual Surround sink with connected headphones? I get sound when I select the regular Headphone device.

    Is this meant to work out of the box when I connect my headphones in the regular jack on my laptop, or does it only work with a USB DAC?

    • Michael Murphy (S76)@lemmy.worldOPM
      link
      fedilink
      English
      arrow-up
      1
      ·
      edit-2
      1 year ago

      I’m using it with onboard audio at the moment. You may need to log out and log back in, and then start the filter-chain config before launching anything else. If not, running it with PIPEWIRE_DEBUG=3 might help.

      • mrhrdr@lemmy.world
        link
        fedilink
        English
        arrow-up
        1
        ·
        1 year ago

        Thanks, the PIPEWIRE_DEBUG=3 thing showed what’s wrong: it uses a relative path to find the atmos.wav, so when I changed to use an absolute path it worked.

        It might have something to do with my .config/pipewire directory being a symlink to my dotfiles, but now I know that it works! Thanks again :)

          • mrhrdr@lemmy.world
            link
            fedilink
            English
            arrow-up
            1
            ·
            edit-2
            1 year ago

            The config file doesn’t seem to support environment variables: for me 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?

              • mrhrdr@lemmy.world
                link
                fedilink
                English
                arrow-up
                1
                ·
                1 year ago

                (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 :)