Script for setting quantum(buffer) in Pipewire

Optimize your system for ultimate performance.

Moderators: MattKingUSA, khz

Post Reply
User avatar
Largos
Established Member
Posts: 639
Joined: Mon Oct 05, 2020 12:21 pm
Has thanked: 72 times
Been thanked: 186 times

Script for setting quantum(buffer) in Pipewire

Post by Largos »

Pipewire is designed for applications to state the quantum(buffer) they wish to use. This is confusing for users used to JACK which specifies a buffer value that applications follow. As a result, if the application doesn't state quantum then the applications used the default set in the config file. There are applications which change a setting that can force all applications to use the same buffer but this is unnecessary and misses the point of having a dynamic quantum and also these applications are changing the command temporarily until the next boot or pipewire restart.

For that purpose, I made a script that creates/modifies a user level config file and restarts the pipewire server using a syscontrol command. So people can change their default quantum, the change be persistent and it not need any knowledge of editing a config file to do so.

Code: Select all

#!/bin/bash
directory=~/.config/pipewire/pipewire.conf.d/
file=~/.config/pipewire/pipewire.conf.d/quantumsetting.conf

if ! [ -e "$directory" ] ; then
    mkdir - p "$directory"
fi


PS3='Select the default quantum: '
options=("16" "32" "64" "128" "256" "512" "1024" "2048" "4096" "8192")
select opt in "${options[@]}"
do
    case $opt in
        "16")
            echo "The default quantum is now $opt"
            break
            ;;
        "32")
            echo "The default quantum is now $opt"
            break
            ;;
        "64")
            echo "The default quantum is now $opt"
            break
            ;;
        "128")
            echo "The default quantum is now $opt"
            break
            ;;
        "256")
            echo "The default quantum is now $opt"
            break
            ;;
        "512")
            echo "The default quantum is now $opt"
            break
            ;;
        "1024")
            echo "The default quantum is now $opt"
            break
            ;;
        "2048")
            echo "The default quantum is now $opt"
            break
            ;;
        "4096")
            echo "The default quantum is now $opt"
            break
            ;;
        "8192")
            echo "The default quantum is now $opt"
            break
            ;;
        *) echo "invalid option $REPLY";;
    esac
done


echo "context.properties = {" > "$file"
echo "  default.clock.quantum  = $opt" >> "$file"
echo "}" >> "$file"

# Delete or comment out following line if you are using a non systemd distro like Devuan or Artix.
systemctl --user restart pipewire.service
Attachments
quantumconfig.tar.gz
(562 Bytes) Downloaded 44 times
User avatar
Audiojunkie
Established Member
Posts: 403
Joined: Thu Feb 21, 2019 4:27 pm
Has thanked: 392 times
Been thanked: 157 times

Re: Script for setting quantum(buffer) in Pipewire

Post by Audiojunkie »

Very cool!! Thanks, Largo!

Post Reply