You are not logged in.

#1 2023-04-15 20:23:31

haigioli
Member
Registered: 2018-09-06
Posts: 63

[SOLVED] How do I reverse L and R channels in pipewire?

I'm somewhat new to pipewire and am facing an rather odd issue where my L and R audio channels are reversed over the speakers and headphones, even though the config shows FL, FR in the right order (default vanilla configs).  This is true across all audio devices on the system, including USB audio interfaces.  I'm trying to figure a way to permanently reverse them to the order they should be in, but can't figure this out.  I tried to follow the instructions on:

https://askubuntu.com/questions/1382581 … on-on-pipe

However, I can't get it to work, or make heads or tails of the pipewire wiki pages on this matter.  Running EasyEffects is not elegant in my view, for something so simple as switching channel outputs around.  I would very much like to make this work via configs, if possible.

I'm using wireplumber as my session manager, if that helps.

Since everything is vanilla in my configs, I don't know what to post here.  Please, advise and I'll do so.  Any help would be appreciated.

Last edited by haigioli (2023-04-17 02:20:30)

Offline

#2 2023-04-17 02:20:08

haigioli
Member
Registered: 2018-09-06
Posts: 63

Re: [SOLVED] How do I reverse L and R channels in pipewire?

After doing a lot of research, learning the rudiments of lua scripting, and a lot of trial and error, I've come up with a solution.  It's my sincere hope that this post will help others figure out their pipewire woes as they transition over from PulseAudio and Jack to this promising, but less well-documented system.  Here it goes...

First off, I copied the following sample configs to my local directory (make sure to create the directory under ~/.config/wireplumber/main.lua.d first):

cp /usr/share/wireplumber/main.lua.d/30-alsa-monitor.lua ~/.config/wireplumber/main.lua.d/
cp /usr/share/wireplumber/main.lua.d/50-alsa-config.lua ~/.config/wireplumber/main.lua.d/

Open ~/.config/wireplumber/main.lua.d/50-alsa-config.lua in a text editor and make the following changes to audio.channels and audio.position properties in order to flip the order of the L & R audio channels across all devices:

~/.config/wireplumber/main.lua.d/50-alsa-config.lua
...
     matches = {
      {
        -- Matches all sources.
        { "node.name", "matches", "alsa_input.*" },
      },
      {
        -- Matches all sinks.
        { "node.name", "matches", "alsa_output.*" },
      },
    },
    apply_properties = {
      ...
      ["audio.channels"]         = 2,
      ...
      ["audio.position"]         = "FR,FL",
      ...

In order commit these changes, assuming pipewire and wireplumber are both running on user-level systemd, save these changes and run the following command:

systemctl --user --now wireplumber

Now, when you test your headphones or speakers through whichever audio device system setting app you use to configure your audio devices, you should notice that the front left and front right channels have switched around.

If you have, say, a multichannel audio interface (check out this page to find out how to get your audio interface alsa input/output device name) that you want to create special settings for, you can do so by creating under the same main.lua.d directory a file with the following contents:

~/.config/wireplumber/main.lua.d/51-alsa-multichannelAudioInterface.lua

rule = {
  matches = {
    {
      { "node.name", "matches", "alsa_input.usb-audio-interface" },
    },
    {
      { "node.name", "matches", "alsa_output.usb-audio-interface" },
    },
  },
  apply_properties = {
    ["audio.channels"]         = 4,
    ["audio.format"]           = "S32LE",
    ["audio.rate"]             = 48000,
    ["audio.position"]         = "FR,FL,RR,RL",
    ["api.alsa.period-size"]   = 128,
    ["api.alsa.period-num"]    = 3,
  },
}

table.insert(alsa_monitor.rules, rule)

The above code will not only reverse the order of the channels, but also sets the number of channels, the audio bit rate, sample rate, period size, and period number to a default that you may use when running a DAW through pipewire-jack.

Remember to run `systemctl --user --now wireplumber` to set these changes into action.

If anyone finds something wrong with these configs, or can find a better way of getting these sorts of settings into play, kindly add to this thread.  For now, I shall mark this is SOLVED.

Last edited by haigioli (2023-04-17 02:30:34)

Offline

#3 2024-03-21 18:23:45

buttcake
Member
Registered: 2016-10-16
Posts: 37

Re: [SOLVED] How do I reverse L and R channels in pipewire?

Sorry if this is considered a necrobump but the .lua API has been deprecated. I've tried copying

/usr/share/wireplumber/wireplumber.conf.d/alsa-vm.conf

to

.config/wireplumber/wireplumber.conf.d/alsa-vm.conf

and adding

        audio.channels         = 2
        audio.position         = ["FR", "FL"]

in order to achive

# ALSA node property overrides for virtual machine hardware

monitor.alsa.rules = [
  # Generic PCI cards on any VM type
  {
    matches = [
      {
        node.name = "~alsa_input.pci.*"
        cpu.vm.name = "~.*"
      }
      {
        node.name = "~alsa_output.pci.*"
        cpu.vm.name = "~.*"
      }
    ]
    actions = {
      update-props = {
        api.alsa.period-size   = 1024
        api.alsa.headroom      = 2048
        audio.channels         = 2
        audio.position         = ["FR", "FL"]
      }
    }
  }
]

but it doesn't seem to work, even though originally I only had to copy and edit 50-alsa-config.lua. That being said I'm probably wrong in editing this file or I'm missing something.

EDIT:

monitor.alsa.rules = [
  {
    matches = [
      {
        node.name = "~alsa_output.pci.*"
      }
    ]
    actions = {
      update-props = {
        audio.position         = ["FR", "FL"]
      }
    }
  }
]

This has worked.

Last edited by buttcake (2024-03-21 18:36:40)

Offline

Board footer

Powered by FluxBB