Pipewire: Latency instellen
Pipewire: Set Latency

Pipewire: Set Latency

Tux in space

This page was last updated June 25, 2022

I'm still having a lot of trouble understanding exactly how pipewire works. The first thing I had to figure out is how to set the latency that pipewire should use on my system. In this case my Laptop which I mainly use as a pipewire test platform (specifications can be found at this page).

Latency is important to me as someone who mostly uses live instruments. High latency means that there can be a lot of time between producing a sound and when that sound comes out of the computer speaker. I want to keep the time between making sound and hearing that sound on the computer as low as possible.

By default, PipeWire is set to use 1024 frames at a sample rate of 48000Hz. It's too complex to explain what frames and sample rates and how they affect shooting. On this page is a reasonable description for audio playback to get an idea. This gives a latency of about 24 milliseconds on my system, this produces a kind of echo effect which is very annoying.

TL;DR

In the first I use the following command to open Ardour:

PIPEWIRE_LATENCY=128/48000 flatpak run org.ardour.Ardour

In the second, I use the following command to open Carla:

PIPEWIRE_LATENCY=128/48000 flatpak run studio.kx.carla

In the third I check if the settings are inherited by pipewire:

pw-top

Standard way:

Pipewire's default settings give about 24 milleseconds of latency on my system. On my previous Pulse/Jack/ALSA installation, I could reliably achieve a latency of about 1 millisecond, which was almost unheard of or noticeable.

I believe pipewire's preferred way is to set up the whole system with a terminal command like this:

To set the sample rate use:

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

To set frames (PipeWire uses the term quantums) use:

pw-metadata -n settings 0 clock.force

However, this method causes many problems on my system (probably that I have not configured things properly yet). For example, some programs start to play audio slowly or quickly, or videos play slowly or quickly.

My way:

Personally, for now I can only get it done in the following way, reliable. I have to start every program that I start that I want to use with a certain frame/sample rate with those settings. Very terminal-difficult all, unfortunately.

For this test I'm using the following PipeWire version:

$ pipewire --version

pipewire
Compiled with libpipewire 0.3.51
Linked with libpipewire 0.3.51

On the internet I came across the following method to start individual programs with a certain pipewire latency setting (if I understood correctly pipewire uses 1024/48000 by default):

PIPEWIRE_LATENCY=128/48000 Ardour

However, this doesn't work on my system because I've transferred almost everything to flatpaks, to run flatpaks in a terminal you can use the following:

flatpak run org.ardour.Ardour

I didn't know what frame rate the audio chip on my laptop uses by default, this is often 48000Hz, but sometimes it can be 44100Hz. With the following terminal command:

pactl list sinks

I got the following information:

Sink #1236
	State: SUSPENDED
	Name: alsa_output.pci-0000_06_00.6.analog-stereo
	Description: Family 17h (Models 10h-1fh) HD Audio Controller Analoog stereo
	Driver: PipeWire
	Sample Specification: s32le 2ch 48000Hz
	Channel Map: front-left,front-right
	Owner Module: 4294967295
	Mute: no
	Volume: front-left: 62912 /  96% / -1,06 dB,   front-right: 62912 /  96% / -1,06 dB
	        balance 0,00
	Base Volume: 65536 / 100% / 0,00 dB
	Monitor Source: alsa_output.pci-0000_06_00.6.analog-stereo.monitor
	Latency: 0 usec, configured 0 usec
	Flags: HARDWARE HW_MUTE_CTRL HW_VOLUME_CTRL DECIBEL_VOLUME LATENCY 
	Properties:
		alsa.card = "1"
		alsa.card_name = "HD-Audio Generic"
		alsa.class = "generic"
		alsa.device = "0"
		alsa.driver_name = "snd_hda_intel"
		alsa.id = "ALC274 Analog"
		alsa.long_card_name = "HD-Audio Generic at 0xfc5c0000 irq 107"
		alsa.name = "ALC274 Analog"
		alsa.resolution_bits = "16"
		alsa.subclass = "generic-mix"
		alsa.subdevice = "0"
		alsa.subdevice_name = "subdevice #0"
		api.alsa.card.longname = "HD-Audio Generic at 0xfc5c0000 irq 107"
		api.alsa.card.name = "HD-Audio Generic"
		api.alsa.path = "front:1"
		api.alsa.pcm.card = "1"
		api.alsa.pcm.stream = "playback"
		audio.channels = "2"
		audio.position = "FL,FR"
		card.profile.device = "3"
		device.api = "alsa"
		device.class = "sound"
		device.id = "100"
		device.profile.description = "Analoog stereo"
		device.profile.name = "analog-stereo"
		device.routes = "2"
		factory.name = "api.alsa.pcm.sink"
		media.class = "Audio/Sink"
		device.description = "Family 17h (Models 10h-1fh) HD Audio Controller Analoog stereo"
		node.name = "alsa_output.pci-0000_06_00.6.analog-stereo"
		node.nick = "ALC274 Analog"
		node.pause-on-idle = "false"
		object.path = "alsa:pcm:1:front:1:playback"
		priority.driver = "1009"
		priority.session = "1009"
		factory.id = "18"
		client.id = "34"
		clock.quantum-limit = "8192"
		node.driver = "true"
		factory.mode = "merge"
		audio.adapt.follower = ""
		library.name = "audioconvert/libspa-audioconvert"
		object.id = "46"
		object.serial = "1236"
		node.max-latency = "16384/48000"
	Ports:
		analog-output-speaker: Luidsprekers (
                  type: Speaker, 
                  priority: 10000, 
                  availability group: Legacy 3, 
                  availability unknown)
		analog-output-headphones: Analoge koptelefoon (
                  type: Headphones, 
                  priority: 9900, 
                  availability group: Legacy 4, 
                  not available)
	Active Port: analog-output-speaker
	Formats:
		pcm

Then the sample rate is 48000Hz:

Sample Specification: s32le 2ch 48000Hz

On a Pulse/Jack/ALSA system I was used to looking for good settings with the sample rate in hand that were "safe" to use. One of those lists is here found on the Linux Musicians website (indispensable if you're producing audio on a GNU/Linux system).

I plan to test the following settings on my system:

  • 16 / 48000
  • 32 / 48000
  • 64 / 48000
  • 128 / 48000 (in Ardour gives about 2.7ms latency on my system)
  • 256 / 48000
  • 512 / 48000
  • 1024 / 48000 (in Ardour gives about 24ms latency on my system)
  • 2048 / 48000

To find the system names of flatpaks I use the following terminal command:

flatpak --user --columns=name,app list

This gives the following output:

Name                                     Application ID
Arduino IDE                              cc.arduino.arduinoide
Metronome                                com.adrienplazas.Metronome
GitKraken                                com.axosoft.GitKraken
Discord                                  com.discordapp.Discord
Barrier                                  com.github.debauchee.barrier
Flatseal                                 com.github.tchx84.Flatseal
Nextcloud Desktop                        com.nextcloud.desktopclient.nextcloud
OBS Studio                               com.obsproject.Studio
Transmission                             com.transmissionbt.Transmission
Audio Sharing                            de.haeckerfelix.AudioSharing
HandBrake                                fr.handbrake.ghb
Ardour                                   org.ardour.Ardour
Audacity                                 org.audacityteam.Audacity
Codecs                                   org.audacityteam.Audacity.Codecs
Chromium Web Browser                     org.chromium.Chromium
Codecs                                   org.chromium.Chromium.Codecs
TAP-plugins                              org.freedesktop.LinuxAudio.Plugins.TAP
SWH                                      org.freedesktop.LinuxAudio.Plugins.swh
Freedesktop Platform                     org.freedesktop.Platform
Mesa                                     org.freedesktop.Platform.GL.default
Mesa                                     org.freedesktop.Platform.GL.default
nvidia-510-68-02                         org.freedesktop.Platform.GL.nvidia-510-68-02
ffmpeg-full                              org.freedesktop.Platform.ffmpeg-full
openh264                                 org.freedesktop.Platform.openh264
Freedesktop SDK                          org.freedesktop.Sdk
Fritzing                                 org.fritzing.Fritzing
GNU Image Manipulation Program           org.gimp.GIMP
Déjà Dup-back-ups                        org.gnome.DejaDup
Gnome Klotski                            org.gnome.Klotski
Logboeken                                org.gnome.Logs
Gnome Mijnenveger                        org.gnome.Mines
GNOME Application Platform version 40    org.gnome.Platform
GNOME Application Platform version 41    org.gnome.Platform
GNOME Application Platform version 42    org.gnome.Platform
Polari                                   org.gnome.Polari
Klok                                     org.gnome.clocks
gThumb-afbeeldingsweergave               org.gnome.gThumb
Pop Gtk theme                            org.gtk.Gtk3theme.Pop-dark
Inkscape                                 org.inkscape.Inkscape
Adwaita theme                            org.kde.KStyle.Adwaita
KDE Application Platform                 org.kde.Platform
QGnomePlatform                           org.kde.PlatformTheme.QGnomePlatform
QtSNI                                    org.kde.PlatformTheme.QtSNI
Kdenlive                                 org.kde.kdenlive
Krita                                    org.kde.krita
Mixxx DJ Software                        org.mixxx.Mixxx
Helvum                                   org.pipewire.Helvum
Signal Desktop                           org.signal.Signal
Telegram Desktop                         org.telegram.desktop
Telegram Desktop Webview Add-on          org.telegram.desktop.webview
VLC                                      org.videolan.VLC
Carla                                    studio.kx.carla

With this information, I can put together the following command to start Ardour in a terminal:

PIPEWIRE_LATENCY=128/48000 flatpak run org.ardour.Ardour

This returns the following information in the terminal:

WARNING: Your system has a limit for maximum amount of locked memory!
         This might cause Ardour to run out of memory before your system runs
         out of memory. You can view the memory limit with 'ulimit -l', and it
         is normally controlled by /etc/security/limits.conf

WARNING: Could not check your glib-2.0 for mutex locking atomic operations.

Ardour6.9.0 (built using 6.9 and GCC version 11.2.0)
Ardour: [INFO]: Your system is configured to limit Ardour to 1048576 open files
Ardour: [INFO]: Loading system configuration file /app/etc/ardour6/system_config
Ardour: [INFO]: Loading user configuration file /home/remco/.var/app/org.ardour.Ardour/config/ardour6/config
Ardour: [INFO]: CPU vendor: AuthenticAMD
Ardour: [INFO]: AVX-capable processor
Ardour: [INFO]: AVX with FMA capable processor
Ardour: [INFO]: CPU brand: AMD Ryzen 7 5800H with Radeon Graphics         
Ardour: [INFO]: Using AVX and FMA optimized routines
Ardour: [INFO]: Loading plugin meta data file /app/share/ardour6/plugin_metadata/plugin_tags
Cannot xinstall SIGPIPE error handler
Ardour: [INFO]: Loading default ui configuration file /app/etc/ardour6/default_ui_config
Ardour: [INFO]: Loading user ui configuration file /home/remco/.var/app/org.ardour.Ardour/config/ardour6/ui_config
Ardour: [INFO]: Loading 452 MIDI patches from /app/share/ardour6/patchfiles
Gtk-Message: 12:00:08.693: Failed to load module "gail"
Gtk-Message: 12:00:08.693: Failed to load module "atk-bridge"
Gtk-Message: 12:00:08.693: Failed to load module "appmenu-gtk-module"
Gtk-Message: 12:00:08.696: Failed to load module "canberra-gtk-module"
Ardour: [INFO]: Loading color file /app/share/ardour6/themes/dark-ardour.colors
Ardour: [INFO]: Loading ui configuration file /app/etc/ardour6/clearlooks.rc
Ardour: [INFO]: Loading bindings from /app/etc/ardour6/ardour.keys
Loading ui configuration file /app/etc/ardour6/clearlooks.rc
Found nothing along /home/remco/.var/app/org.ardour.Ardour/config/ardour6/templates:/app/share/ardour6/templates
Scanning folders for bundled LV2s: /app/lib/ardour6/LV2
Set cursor set to default

If all goes well, Ardour is now also open. As long as Ardour is working properly, there's not too much reason to worry too much about the warnings in the terminal.

These settings give the following latency in Ardour on my system:

Ardour latency

With a second terminal window I open Carla with the same latency settings as Ardour (128/48000) to be able to connect the audio sources/sinks together. I use Carla because I know this program. The Helvum program can also be used, but has very limited options. There are a few more such programs available for pipewire. In the future there will probably be an article on this website where I describe that I have moved away from Carla.

PIPEWIRE_LATENCY=128/48000 flatpak run studio.kx.carla

Gives the following output:

LRDF Support not available (LADSPA-RDF will be disabled)
Gtk-Message: 12:11:34.927: Failed to load module "appmenu-gtk-module"
Gtk-Message: 12:11:34.971: Failed to load module "canberra-gtk-module"
Gtk-Message: 12:11:34.971: Failed to load module "canberra-gtk-module"
Qt: Session management error: Could not open network socket
Carla 2.4.3 started, status:
  Python version: 3.9.9
  Qt version:     5.15.3
  PyQt version:   5.15.6
  Binary dir:     /app/lib/carla
  Resources dir:  /app/share/carla/resources
Frontend pixel ratio is 1.0
libjack.so.0 loaded successfully!

With the following command you can see that pipewire has taken over the settings:

pw-top

gives the following output:

Leave a Reply

Your email address will not be published. Required fields are marked *

en_GBEnglish (UK)