this post was submitted on 20 Jul 2023
77 points (98.7% liked)

Pop!_OS (Linux)

5158 readers
1 users here now

Pop!_OS is an operating system developed by System76 for STEM and creative professionals who use their computer as a tool to discover and create. Unleash your potential on secure, reliable open source software. Based on your exceptional curiosity, we sense you have a lot of it.

Unleash your potential

Whether this is your first experience with Linux, or your latest adventure, all are welcome to discuss and ask questions about Pop!_OS and COSMIC. Keep the discussions friendly though, and remember to assume good intentions whenever you reply. We're all here because we have a shared love for Linux and open source software.

System76 Logo

Support us by buying System76 hardware for you or your company! Or by donating on the Pop!_OS website through the "Support Pop" button. Pop!_OS and COSMIC are fully funded by System76 hardware sales. All systems are assembled in the USA. With your support, we'll work to push the Linux desktop forward with COSMIC.

Links

Guides

Hardware

Recommended

Community Rules

Follow the Code of Conduct

All posts on pop_os must adhere to the Pop!_OS community Code of Conduct. https://github.com/pop-os/code-of-conduct

Be helpful

Posts to pop_os must be helpful. When responding to a user asking for help, do not provide tongue-in-cheek responses like "RTM" or links to LMGTFY. Linking to direct sources that answer the asker's question is fine, but it's advised to provide some explanation as to how you got to that source.

Critique should be constructive

We within the Pop!_OS community welcome helpful criticism or ideas on ways to improve. However, basic "It's bad" or other simple negative comments don't help anyone fix anything. When voicing a complaint about something, try to point out ways the complaint could be improved or worked around, so that we can make a better product for it.

This rule applies to both Pop!_OS and its projects as well as other products available from third-parties.

Don't post malicious "advice"

It can be funny to joke about malicious commands, however this is not the venue for it. Do not advise users to run commands which will lock up their systems, steal their data, or erase their drive. Examples of this include (but are not limited to) fork bombs, rm, etc.

Posts violating this rule will be removed, even if the post is clearly in jest. Repeated offences may lead to a ban. You may understand that the command isn't serious, but a new user might not.

No personal attacks

Posts making a personal attack on any user will not be tolerated.

No hate speech

Hate speech of any kind will not be tolerated. Any violations will be removed, and are grounds for a ban.

founded 1 year ago
MODERATORS
 

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.

you are viewing a single comment's thread
view the rest of the comments
[–] [email protected] 1 points 1 year ago* (last edited 1 year ago) (1 children)

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.

[–] [email protected] 1 points 1 year ago (1 children)

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

[–] [email protected] 1 points 1 year ago (1 children)

I've updated instructions to insert by absolute path rather than relative.

[–] [email protected] 1 points 1 year ago (1 children)

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?

[–] [email protected] 1 points 1 year ago (1 children)

The above sed command will automatically convert it before writing the replacement.

[–] [email protected] 1 points 1 year ago (1 children)

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

[–] [email protected] 2 points 1 year ago

Check out the new guide for a SOFA spatializer