Very easy way to set Pipewire sample rate and buffer size defaults!

Discuss anything new and newsworthy! See http://planet.linuxaudio.org and https://libreav.org/news for more Linux Audio News!

Announcements of proprietary software may fit better in the Marketplace.


Moderators: raboof, MattKingUSA, khz

User avatar
Audiojunkie
Established Member
Posts: 392
Joined: Thu Feb 21, 2019 4:27 pm
Has thanked: 382 times
Been thanked: 153 times

Very easy way to set Pipewire sample rate and buffer size defaults!

Post by Audiojunkie »

I was interested in updating myself from the last time that I read the documentation on Pipewire (over a year ago), and I thought it would be interesting to share some of the new stuff that I discovered. This is apparently not very new information, because it's been out for about a year. However, it was new to me, and I don't think I saw it posted elsewhere. We no longer need to manually configure the config files to change the pipewire sample rate and buffer size. This makes things MUCH easier!! It's still done from the command line, but no more digging into the .conf files and manually editing them anymore!

https://gitlab.freedesktop.org/pipewire ... e-settings

For example:

pw-metadata -n settings 0 clock force-quantum 256

And pw-metadata -n settings 0 clock.force-rate 48000

That's it!!

Here's Wim's brief explanation:

Set a specific sample rate and buffer size?

pw-metadata -n settings 0 clock.force-rate <samplerate>
pw-metadata -n settings 0 clock.force-quantum <buffersize>

Confirm the actuall sample rate and buffer size?

pw-metadata -n settings

Reset pipewire to the default configuration?

pw-metadata -n settings 0 clock.force-rate 0
pw-metadata -n settings 0 clock.force-quantum 0

This is VERY VERY cool news!!!

Of course, from the very beginning, we were able to:

Update your Launchers (shortcuts) and prepend with: PIPEWIRE_LATENCY=256/48000 appname

So, we always had an easy way to start a program with the desired settings, but now we can easily set permanent defaults. :D

Either way, this means I don't plan to ever manually edit my jack.conf file for pipewire ever again!! :D

a.d.
Established Member
Posts: 32
Joined: Wed Nov 25, 2020 3:48 pm
Has thanked: 9 times
Been thanked: 6 times

Re: Very easy way to set Pipewire sample rate and buffer size defaults!

Post by a.d. »

The environmental variable approach has never worked for me. I've only had success using the pw-metadata commands.

User avatar
Audiojunkie
Established Member
Posts: 392
Joined: Thu Feb 21, 2019 4:27 pm
Has thanked: 382 times
Been thanked: 153 times

Re: Very easy way to set Pipewire sample rate and buffer size defaults!

Post by Audiojunkie »

a.d. wrote: Mon May 22, 2023 6:58 pm

The environmental variable approach has never worked for me. I've only had success using the pw-metadata commands.

My guess would be that this approach is probably dependent upon what the distro has set up for paths, or what the individual that is manually installing pipewire has set up. I haven't tried it yet, but I plan to do so. Since I'm using Fedora, I have confidence that pipewire is probably set up properly for me. What distro are you using? Did you install Pipewire manually or did it come installed with the distro?

a.d.
Established Member
Posts: 32
Joined: Wed Nov 25, 2020 3:48 pm
Has thanked: 9 times
Been thanked: 6 times

Re: Very easy way to set Pipewire sample rate and buffer size defaults!

Post by a.d. »

I use Arch, and followed the wiki. Reaper doesn't give a fig about my PipeWire environmental variables. Things work just fine with the commands.

User avatar
Audiojunkie
Established Member
Posts: 392
Joined: Thu Feb 21, 2019 4:27 pm
Has thanked: 382 times
Been thanked: 153 times

Re: Very easy way to set Pipewire sample rate and buffer size defaults!

Post by Audiojunkie »

a.d. wrote: Mon May 22, 2023 10:35 pm

I use Arch, and followed the wiki. Reaper doesn't give a fig about my PipeWire environmental variables. Things work just fine with the commands.

I'm not convinced it is a problem with Reaper. I still think it has to do with paths. In the Arch distro, you have to set all of that stuff up by yourself. Try opening a different audio app with those environment variables. If the different app doesn't work either, that is a good sign that the problem doesn't have anything to do with Reaper. I would suggest going to the Arch wiki and mentioning that apps are not recognizing these environment variables and see what changes they suggest. I'm willing to bet it's something simple like defining the path so that the system knows where to look for those commands.

EDIT: I did some more searching, and according to Wim the pw-metadata approach seems to be what he is recommending over the Environment Variable these days for everything. See:

https://gitlab.freedesktop.org/pipewire ... ssues/1523

I'd like to find more info on that, because it indeed appeared to be a viable way to do things before... But either way, if pw-metadata is the way it needs to be done from now on, it's still much easier than configuring .CONF files manually. :D

EDIT 2: Here's Wim's specific comment regarding the subject:

Question: In order to set the buffer size for Jack clients, you have to run the application with the PIPEWIRE_LATENCY environment variable. Does that mean I have to start all applications from console? Or do I have to change all .desktop files? This is very easy to do with the original Jack: a control program like qjackctl. There, you just choose which buffer you want and all applications use it. It should be like this.

Answer: No, see above. Settings via metadata on the fly or in config file, per app or globally.+

So, it looks like everything is meant to be configured through metadata from now on. :)

EDIT 3: Upon reading the page again, I can see that the environment variables are indeed still used, although I'm not clear on when and how. See cooments from the document below:

Some applications (Ardour, guitarix, etc) have an option to change the buffer size with a menu option.
The PIPEWIRE_LATENCY environment variable can be used to configure the latency of an application:

PIPEWIRE_LATENCY=256/48000 jack_simple_client

Will run this JACK client with a 256 samples buffer size.


So, in short, there are still some things to figure out, but it does look like pw-metadata is likely the primary recommended way of doing things, and there is something about the environment variables still for me to learn. :)

Last edited by Audiojunkie on Tue May 23, 2023 12:04 am, edited 3 times in total.
User avatar
thetotalchaos
Established Member
Posts: 211
Joined: Mon Sep 29, 2014 8:29 pm
Has thanked: 51 times
Been thanked: 9 times
Contact:

Re: Very easy way to set Pipewire sample rate and buffer size defaults!

Post by thetotalchaos »

Recently i am successfully using Pipecontrol, to set up Pipewire, even at real time.

https://github.com/portaloffreedom/PipeControl
https://aur.archlinux.org/pipecontrol.git

And using Patchance to set up connections.

https://github.com/Houston4444/Patchance
https://aur.archlinux.org/patchance.git

You can listen to my music at: https://totalchaos-music.bandcamp.com/

Take a journey to wonderland with The Butterfly Effect 2016
https://totalchaos-music.bandcamp.com/a ... fly-effect
GMoon
Established Member
Posts: 51
Joined: Sat Oct 03, 2020 1:10 pm
Has thanked: 11 times
Been thanked: 20 times

Re: Very easy way to set Pipewire sample rate and buffer size defaults!

Post by GMoon »

I'll have to try Patchance, it's great to have another option. Pipecontrol, hmmm, there's another.

ALSO, re: a pipewire-aware patchbay, RaySession works very well, also, plus it's possible to adjust the pipewire buffer size from the patchbay GUI. You don't need to use it for session-management if that's not necessary.

j_e_f_f_g
Established Member
Posts: 2032
Joined: Fri Aug 10, 2012 10:48 pm
Been thanked: 357 times

Re: Very easy way to set Pipewire sample rate and buffer size defaults!

Post by j_e_f_f_g »

This is supposed to make linux audio better????

It sure looks like the same results, but now with even more procedures that are prone to failure. In other words,, same as always.

Author of BackupBand at https://sourceforge.net/projects/backupband/files/
My fans show their support by mentioning my name in their signature.

User avatar
TheYke
Established Member
Posts: 53
Joined: Mon Dec 16, 2019 3:57 pm
Been thanked: 6 times

Re: Very easy way to set Pipewire sample rate and buffer size defaults!

Post by TheYke »

I recently put those and other commands into my config of the custom-menu extension for gnome. This way I have a drop-down menu on my bar where I can set my buffer sizes etc. with just one click. Quite neat, to be honest. Fingers crossed that the extension won't fail too soon, due to Gnome updates :D

User avatar
Audiojunkie
Established Member
Posts: 392
Joined: Thu Feb 21, 2019 4:27 pm
Has thanked: 382 times
Been thanked: 153 times

Re: Very easy way to set Pipewire sample rate and buffer size defaults!

Post by Audiojunkie »

That’s a great idea!

Another way that would work well and not be reliant upon a gnome add-on would be to use an alias from the command line.

Another way would be to create a simple script with the options.

🙂

User avatar
Audiojunkie
Established Member
Posts: 392
Joined: Thu Feb 21, 2019 4:27 pm
Has thanked: 382 times
Been thanked: 153 times

Re: Very easy way to set Pipewire sample rate and buffer size defaults!

Post by Audiojunkie »

I've gone back again and read over the manual again and I can confirm the following:

Environment variables can be used to control the behavior of the PipeWire JACK client library.

https://gitlab.freedesktop.org/pipewire ... onfig-JACK


PIPEWIRE_LATENCY:

PIPEWIRE_LATENCY=<samples>/<rate> <application>

A quick way to configure the maximum buffer-size for a client. It will run this client with the specified buffer-size (or smaller).
PIPEWIRE_LATENCY=256/48000 jack_lsp is equivalent to PIPEWIRE_PROPS='{ node.latency=256/48000 }' jack_lsp

NOTE: A better way to start a jack session in a specific buffer-size is to force it with:

pw-metadata -n settings 0 clock.force-quantum <quantum>

This always works immediately and the buffer size will not change until the quantum is changed back to 0.


PIPEWIRE_RATE:

PIPEWIRE_RATE=1/<rate> <application>

A quick way to configure the rate of the graph. It will try to switch the samplerate of the graph. This can usually only be done with the graph is idle and the rate is part of the allowed sample rates.

PIPEWIRE_RATE=1/48000 jack_lsp is equivalent to PIPEWIRE_PROPS='{ node.rate=1/48000 }' jack_lsp
A better way to start a jack session in a specific rate is to force the rate with:

pw-metadata -n settings 0 clock.force-rate <rate>

This always works and the samplerate does not need to be in the allowed rates. The rate will also not change until it is set back to 0.


PIPEWIRE_QUANTUM:

PIPEWIRE_RATE=<buffersize>/<rate> <application>

Combines PIPEWIRE_LATENCY=<buffersize>/<rate> and PIPEWIRE_RATE=1/<rate> (see above). It can be used to set both a buffersize and samplerate at the same time.



It is important to note that while the above can be done, the listed "better" way is to use the pw-metadata command.

https://gitlab.freedesktop.org/pipewire ... g-PipeWire

Runtime Settings:

Some runtime settings can be changed with the settings metadata. You can list the current settings with:

pw-metadata -n settings

Log Settings:

To temporarily increase the log level of the PipeWire daemon, use:

pw-metadata -n settings 0 log.level <level>

samplerate Settings:

The default samplerate can be set with:

pw-metadata -n settings 0 clock.rate <value>

The allowed samplerates can be set with:

pw-metadata -n settings 0 clock.allowed-rates [ <value1> <value2> ... ]

To temporarily force the graph to operate in a fixed sample-rate use:

pw-metadata -n settings 0 clock.force-rate <samplerate>

Both DSP processing and devices will switch to the new rate immediately. Running streams (PulseAudio, native and ALSA applications) will automatically resample to match the new rate.

Switch back to the default behaviour with:

pw-metadata -n settings 0 clock.force-rate 0

Quantum Ranges:

The default quantum can be set with:

pw-metadata -n settings 0 clock.quantum <value>

Change the quantum ranges with:

pw-metadata -n settings 0 clock.min-quantum <value>
pw-metadata -n settings 0 clock.max-quantum <value>

These values are expressed against the clock.rate value. If the graph runs at an alternative rate, clock.quantum and clock.min-quantum will be scaled.

To temporarily force the graph to operate in a fixed buffer-size use:

pw-metadata -n settings 0 clock.force-quantum <buffer-size>

Switch back to the default behaviour with:

pw-metadata -n settings 0 clock.force-quantum 0

Last edited by Audiojunkie on Tue May 30, 2023 11:02 pm, edited 1 time in total.
User avatar
Audiojunkie
Established Member
Posts: 392
Joined: Thu Feb 21, 2019 4:27 pm
Has thanked: 382 times
Been thanked: 153 times

Re: Very easy way to set Pipewire sample rate and buffer size defaults!

Post by Audiojunkie »

So, to sum everything up:

No one needs to edit the .CONF files to quickly change the Pipewire Sample rate and buffer size defaults. From now on, with pipewire the only configurations you need to worry about are the following commands listed below:

Again, here's Wim's brief explanation:

Set a specific sample rate and buffer size?

pw-metadata -n settings 0 clock.force-rate <samplerate>
pw-metadata -n settings 0 clock.force-quantum <buffersize>

Confirm the actuall sample rate and buffer size?

pw-metadata -n settings

Reset pipewire to the default configuration?

pw-metadata -n settings 0 clock.force-rate 0
pw-metadata -n settings 0 clock.force-quantum 0

Tapper
Established Member
Posts: 43
Joined: Fri Dec 14, 2012 1:41 pm
Has thanked: 3 times
Been thanked: 4 times

Re: Very easy way to set Pipewire sample rate and buffer size defaults!

Post by Tapper »

I wnt to add this link https://gitlab.freedesktop.org/pipewire ... nce-tuning. All buffer size settings will only affect the lattency. But setting 'preempt=full', RLIMITs (no, settings for 'audio' or 'realtime' groups won't work, only 'pipewire') and rtkit settings made my computer xrunless :)

nosleepjusthuh
Established Member
Posts: 16
Joined: Mon Apr 25, 2022 3:02 pm
Has thanked: 2 times
Been thanked: 10 times

Re: Very easy way to set Pipewire sample rate and buffer size defaults!

Post by nosleepjusthuh »

Just thought I'd contribute a little bash script for the basics outlined in the first post.

If you feel so inclined, remember to sudo chmod u+x the .sh file you make with this.

Code: Select all

#!/bin/bash

echo "Welcome to PipeManager!"
echo "======================="


while :
do
echo "S: Change sample rate | B: Change buffer size | V: View current settings | R: Restart pipewire | E: Exit program "
echo "======================="
read -p "Selection: " userselection

case $userselection in
	B)
		echo "Some examples of buffer sizes are 64, 128, 256, 512, 1024, 2048."
		read -p 'What would you like the buffer size to be?' buffersizevar
		pw-metadata -n settings 0 clock.force-quantum $buffersizevar
		;;
	S)
		echo "Some examples of sample rates are 44100, 48000, 88200, 96000."
		read -p 'What would you like the sample rate to be?' sampleratevar
		pw-metadata -n settings 0 clock.force-rate $sampleratevar
		;;		
	V)
		pw-metadata -n settings
		echo "======================="
		;;
	R)
		systemctl --user restart pipewire
		;;
	E)
		break
		;;		
esac
done
User avatar
GMaq
Established Member
Posts: 2774
Joined: Fri Sep 25, 2009 1:42 pm
Has thanked: 520 times
Been thanked: 555 times

Re: Very easy way to set Pipewire sample rate and buffer size defaults!

Post by GMaq »

nosleepjusthuh wrote: Wed Sep 20, 2023 3:42 pm

Just thought I'd contribute a little bash script for the basics outlined in the first post.

If you feel so inclined, remember to sudo chmod u+x the .sh file you make with this.

Code: Select all

#!/bin/bash

echo "Welcome to PipeManager!"
echo "======================="


while :
do
echo "S: Change sample rate | B: Change buffer size | V: View current settings | R: Restart pipewire | E: Exit program "
echo "======================="
read -p "Selection: " userselection

case $userselection in
	B)
		echo "Some examples of buffer sizes are 64, 128, 256, 512, 1024, 2048."
		read -p 'What would you like the buffer size to be?' buffersizevar
		pw-metadata -n settings 0 clock.force-quantum $buffersizevar
		;;
	S)
		echo "Some examples of sample rates are 44100, 48000, 88200, 96000."
		read -p 'What would you like the sample rate to be?' sampleratevar
		pw-metadata -n settings 0 clock.force-rate $sampleratevar
		;;		
	V)
		pw-metadata -n settings
		echo "======================="
		;;
	R)
		systemctl --user restart pipewire
		;;
	E)
		break
		;;		
esac
done

Very handy and thanks for sharing!

It might be cool to do up a YAD UI for it, I dabble with such things maybe when I get a bit of time..

This is only generating a pw-metadata command correct? It is not modifying any configs?

Post Reply