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.
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.
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
i have been having difficulty trying to understand the naming conventions for the sofa files as posted in the ari databases, such that i could somehow choose one that i think would best suit. The documentation doesn’t really help, and i haven’t found a write up on it that addresses this in a mere human readable way, i am anything but a coder and don’t use matlab for anything. Any suggestions?
The following should work to automate turning on 7.1 when headphones plugged in. I would def suggest using at least two terminal instances to help with the copy/pasta goodness.
[Unit] Description=Run Pipewire with filter-chain when headphones are plugged in
Wants=sys-devices-pci0000:40-0000:40:01.1-0000:41:00.0-0000:42:08.0-0000:45:00.3-usb9-9\x2d2-9\x2d2:1.0-sound-card1-controlC1.device
BindsTo=sys-devices-pci0000:40-0000:40:01.1-0000:41:00.0-0000:42:08.0-0000:45:00.3-usb9-9\x2d2-9\x2d2:1.0-sound-card1-controlC1.device
Replace /path/to/pipewire with the actual path to the pipewire binary and /path/to/filter-chain.conf with the path to your filter-chain.conf configuration file. Also, replace your_username and your_groupname with your actual username and group name.
To obtain Wants, and BindsTo= path
Plug in desired device
ls /dev/input/by-id/
copy name of your device
eg: usb-Logitech_PRO_X_000000000000-event-if03
then:
sudo udevadm info --attribute-walk --path=$(udevadm info --query=path --name=/dev/input/by-id/usb-Logitech_PRO_X_000000000000-event-if03)
locate “looking at parent device” that matches to your device,
add to service file.
save file.
the udevadm command will also allow you to obtain info needed for the udev rule.
Have tested with logi headphones using the usb dac, and then the standard jack seems to work ok, in ubuntu appears as virtual-surround-sink,though I did have to choose this as my device manually. this should also stop the service if the device is unplugged.
To automate that you could edit the service Execstart entry :
Hi, thanks for this! However, I am struggling a bit to understand some part, especially the one about Wants and Bindto, using the udevadm command. Maybe you could explain a bit more details what you are doing? This is the output of the udevadm cmd. I am using the same headset (Logitech G Pro X), and I am trying to have the same audio experience as the one I get one Windows using Logitech G Hub, but it is really hard to understand everything.
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!
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?
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.
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 :)
@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: