Pipewire configuration for low latency

Optimize your system for ultimate performance.

Moderators: MattKingUSA, khz

User avatar
ycollette
Established Member
Posts: 87
Joined: Sun Jul 03, 2016 8:53 pm
Has thanked: 14 times
Been thanked: 16 times
Contact:

Pipewire configuration for low latency

Post by ycollette »

Hello,

I am struggling to configure pipewire to use in real time.
I want to play a guitar throught guitarix with a ~10 ms latency (256 samples / 48000 Hz was the configuration I used with jack).
I copied the configuration files from /usr/share/pipewire to ~/.conf/pipewire.
I removed ~/.conf/pipewire/client.conf and renamed client-rt.conf to client.conf.
I replaced all the 44100 occurrences by 48000 and every 1024 occurrences by 256.
I added my user name to the pipewire group.
I restarted my PC (the systemctl --user restart pipewire.service doesn’t seem to work fine wrt configuration files).
After that. I start my guitarix session via raysession…
I clearly hear that the latency corresponds to a 1024 samples buffer, not a 256 samples one …
When I checked via pw-top the latency, there is still a 1024 buffer on the alsa side.

Does somebody succeed to configure pipewire to be useable in real time ?

Best regards,

Yann
Kott
Established Member
Posts: 816
Joined: Thu Mar 21, 2013 12:55 am
Location: Vladivostok
Has thanked: 65 times
Been thanked: 120 times

Re: Pipewire configuration for low latency

Post by Kott »

Hi,

I didn't pipewire yet, but i've read that you need to set

Code: Select all

PIPEWIRE_LATENCY
env for running application with desired buffer https://github.com/PipeWire/pipewire#usage
christobal
Established Member
Posts: 108
Joined: Sun Sep 01, 2019 12:58 pm
Has thanked: 21 times
Been thanked: 11 times

Re: Pipewire configuration for low latency

Post by christobal »

I use qjackctl to configure buffer size (doesnt work for freq, just buffer afaik). I havent tested with recording a guitar quite yet, but everything on my system seems to indicate that it is running whatever I set in qjackctl. CPU use goes up as one would expect and if I go to low (48k/32) and try to play multitracks with tons of plugins i get xrun galore, whereas with higher buffer no problems.


I didnt do any other specific configuration for low latency.
OS: Manjaro
Amp: Echolette M40 / NG51S Tape Echo
Strings: Martin D15M, Yamaha FG-180, Alhambra 5P, Yamaha Revstar
silvabaral
Posts: 1
Joined: Fri Aug 13, 2021 2:19 pm

Re: Pipewire configuration for low latency

Post by silvabaral »

Hi

I'm not an english native speaker

In manjaro, I look for the "jack.conf" file.

(...)
# global properties for all jack clients
jack.properties = {
#node.latency = 1024/48000
(...)


You must uncomment this "#node.latency" line and set 256/48000 or another you may want

Restart, open Carla and verify if the change was made.

Pipewire is running ok for me. Some things are more easy to do.

Look for the explanation about substituition of your audio system for pipewire on the arch wiki, even if you are not running an arch-based distribution, to understand how it works, then you can adapt to the yours
User avatar
ycollette
Established Member
Posts: 87
Joined: Sun Jul 03, 2016 8:53 pm
Has thanked: 14 times
Been thanked: 16 times
Contact:

Re: Pipewire configuration for low latency

Post by ycollette »

Thanks a lot for these answers.
I am still not able to get the same behavior as with jack. Still a lot of XRuns and the latency is still a problem.
Somebody pointed out that a patch related to alsa was submitted recently and maybe the next version will be a good candidate to test:
https://gitlab.freedesktop.org/pipewire ... 93699b125f

I cross my fingers ...
gimmeapill
Established Member
Posts: 564
Joined: Thu Mar 12, 2015 8:41 am
Has thanked: 44 times
Been thanked: 8 times

Re: Pipewire configuration for low latency

Post by gimmeapill »

Not luck here either. The best I could achieve is 17ms round trip (Arch Linux)
But...I found two things:

1 - How to set the freq & fixed buffer size dynamically (no pw restart or conf file editing needed):

Code: Select all

pw-metadata -n settings 0 clock.force-rate 48000
pw-metadata -n settings 0 clock.force-quantum 64
(all runtime settings there: https://gitlab.freedesktop.org/pipewire ... e-settings)

2 - How to set the RT priority for the pipewire thread:
The rtkit method doesn't seem to work on my system, but there's an alternative way that can be set in pipewire.conf & jack.conf:

Code: Select all

..
    # Uses RTKit to boost the data thread priority.
    #{ name = libpipewire-module-rtkit
    #    args = {
    #       nice.level   = -11
    #       rt.prio      = 88
    #       rt.time.soft = 2000000
    #       rt.time.hard = 2000000
    #   }
    #   flags = [ ifexists nofail ]
    #}

    # Set thread priorities without using RTKit.
    { name = libpipewire-module-rt
        args = {
            nice.level   = -11
            rt.prio      = 88
            rt.time.soft = 2000000
            rt.time.hard = 2000000
        }
        flags = [ ifexists nofail ]
    }
...
-> this resulted in the pipewire thread to run at prio 89.
Unfortunately the performance is still not adequate for Guitarix & co (possibly because of that alsa bug), but we're making progress ;-)
christobal
Established Member
Posts: 108
Joined: Sun Sep 01, 2019 12:58 pm
Has thanked: 21 times
Been thanked: 11 times

Re: Pipewire configuration for low latency

Post by christobal »

Dunno if it is of interest, but it seems Unfa is doing some benchmarking of roundtrip latency at the moment for an upcoming video.


Some of his results are here:

https://pad.gieszer.link/sheet/#/2/shee ... hxncBJBD0/

He seems to be getting as low as 5-6 ms on best case scenarios.


Edit: seems like the Liquorix Kernel is getting the lowest latency.
OS: Manjaro
Amp: Echolette M40 / NG51S Tape Echo
Strings: Martin D15M, Yamaha FG-180, Alhambra 5P, Yamaha Revstar
gimmeapill
Established Member
Posts: 564
Joined: Thu Mar 12, 2015 8:41 am
Has thanked: 44 times
Been thanked: 8 times

Re: Pipewire configuration for low latency

Post by gimmeapill »

Thanks, that is very interesting: none of the sub 10ms round trip latency figures were achieved with the stock Arch or RT kernel, but with RT-BFQ or LQX.
Also it seems that we can have now different buffer sizes between input and output - this might open the door to further tweaking
WforWoollyMammoth
Established Member
Posts: 118
Joined: Thu Oct 24, 2019 4:32 pm
Has thanked: 3 times
Been thanked: 16 times

Re: Pipewire configuration for low latency

Post by WforWoollyMammoth »

gimmeapill wrote: Sun Oct 24, 2021 8:06 am Thanks, that is very interesting: none of the sub 10ms round trip latency figures were achieved with the stock Arch or RT kernel, but with RT-BFQ or LQX.
Also it seems that we can have now different buffer sizes between input and output - this might open the door to further tweaking
Do those "tuned" kernels have the new ALSA USB audio driver? I don't think it's going to be included in the main(line) kernel until 5.15.x (don't quote me on that, but that's the latest info I got from Phoronix).

Kernel variations shouldn't have a notable effect on round trip latency values in general, right? The differences have mostly to do with how quickly you're going to have xruns when the CPU / DSP load increases.
User avatar
ycollette
Established Member
Posts: 87
Joined: Sun Jul 03, 2016 8:53 pm
Has thanked: 14 times
Been thanked: 16 times
Contact:

Re: Pipewire configuration for low latency

Post by ycollette »

I found some interesting links about tuning for low latency. I will try this on Friday.

The tuning you must make for low latency:
https://gitlab.freedesktop.org/pipewire ... nce-tuning

And something about rtkit:
https://githubmate.com/repo/heftig/rtkit/issues/25
robbert-vdh
Established Member
Posts: 219
Joined: Mon Mar 01, 2021 10:56 pm
Has thanked: 51 times
Been thanked: 92 times
Contact:

Re: Pipewire configuration for low latency

Post by robbert-vdh »

You may also want to give my configuration a try: https://github.com/robbert-vdh/dotfiles#pipewire

As mentioned there you may need to adjust the ALSA period size if everything sounds all garbled.
User avatar
ycollette
Established Member
Posts: 87
Joined: Sun Jul 03, 2016 8:53 pm
Has thanked: 14 times
Been thanked: 16 times
Contact:

Re: Pipewire configuration for low latency

Post by ycollette »

Thanks for this link. Your configuration system is quite interesting ...
User avatar
sysrqer
Established Member
Posts: 2516
Joined: Thu Nov 14, 2013 11:47 pm
Has thanked: 319 times
Been thanked: 147 times
Contact:

Re: Pipewire configuration for low latency

Post by sysrqer »

robbert-vdh wrote: Mon Jan 03, 2022 5:38 pm You may also want to give my configuration a try: https://github.com/robbert-vdh/dotfiles#pipewire

As mentioned there you may need to adjust the ALSA period size if everything sounds all garbled.
What's the benefit or reason for using wireplumber instead of the session manager?
robbert-vdh
Established Member
Posts: 219
Joined: Mon Mar 01, 2021 10:56 pm
Has thanked: 51 times
Been thanked: 92 times
Contact:

Re: Pipewire configuration for low latency

Post by robbert-vdh »

The reference pipewire-media-session implementation is no longer supported and has been superseded by wireplumber. Wireplumber also handles multi output devices in the Pro Audio profile better without needing to set up virtual sinks.
User avatar
sysrqer
Established Member
Posts: 2516
Joined: Thu Nov 14, 2013 11:47 pm
Has thanked: 319 times
Been thanked: 147 times
Contact:

Re: Pipewire configuration for low latency

Post by sysrqer »

ycollette wrote: Mon Jan 03, 2022 10:54 am I found some interesting links about tuning for low latency. I will try this on Friday.

The tuning you must make for low latency:
https://gitlab.freedesktop.org/pipewire ... nce-tuning
I just tried this and I'm a bit confused about the RLIMITs section. I've added the suggested file but I do not have a pipewire group. Is this necessary, or rather is this different than the settings in the pipewire config?
Post Reply