PipeWire: Difference between revisions
Give the user more options to select how to fix audio. |
Add section "System-wide PipeWire" |
||
(7 intermediate revisions by 5 users not shown) | |||
Line 10: | Line 10: | ||
==Configuring PipeWire== | ==Configuring PipeWire== | ||
<syntaxhighlight lang="nix"> | <syntaxhighlight lang="nix"> | ||
# rtkit | # rtkit (optional, recommended) allows Pipewire to use the realtime scheduler for increased performance. | ||
security.rtkit.enable = true; | security.rtkit.enable = true; | ||
services.pipewire = { | services.pipewire = { | ||
Line 17: | Line 17: | ||
alsa.support32Bit = true; | alsa.support32Bit = true; | ||
pulse.enable = true; | pulse.enable = true; | ||
# If you want to use JACK applications, uncomment | # If you want to use JACK applications, uncomment the following | ||
#jack.enable = true; | #jack.enable = true; | ||
}; | }; | ||
</syntaxhighlight> | </syntaxhighlight> | ||
It is possible to use the | It is possible to use the {{nixos:option|services.pipewire.extraConfig}} option hierarchy in NixOS to create drop-in configuration files, if needed. For example, to disable the [https://docs.pipewire.org/page_module_x11_bell.html PipeWire x11-bell module] (which plays a sound on every X11 urgency hint), use: | ||
<syntaxhighlight lang="nix"> | |||
services.pipewire = { | |||
enable = true; | |||
# Disable X11 bell module, which plays a sound on urgency hint | |||
# (my prompt includes an urgency hint, so I want no sounds). | |||
extraConfig = { | |||
pipewire."99-silent-bell.conf" = { | |||
"context.properties" = { | |||
"module.x11.bell" = false; | |||
}; | |||
}; | |||
}; | |||
}; | |||
</syntaxhighlight> | |||
==Bluetooth Configuration== | ==Bluetooth Configuration== | ||
{{main|Bluetooth}} | |||
PipeWire can be configured to use specific codecs, by default all codecs and most connection modes are enabled, see [https://pipewire.pages.freedesktop.org/wireplumber/daemon/configuration/bluetooth.html#monitor-properties this link] for precise details of which connections modes are enabled by default. The mSBC codec provides slightly better sound quality in calls than regular HFP/HSP, while the SBC-XQ provides better sound quality for audio listening. For more information [https://www.guyrutenberg.com/2021/03/11/replacing-pulseaudio-with-pipewire/ see this link]. | PipeWire can be configured to use specific codecs, by default all codecs and most connection modes are enabled, see [https://pipewire.pages.freedesktop.org/wireplumber/daemon/configuration/bluetooth.html#monitor-properties this link] for precise details of which connections modes are enabled by default. The mSBC codec provides slightly better sound quality in calls than regular HFP/HSP, while the SBC-XQ provides better sound quality for audio listening. For more information [https://www.guyrutenberg.com/2021/03/11/replacing-pulseaudio-with-pipewire/ see this link]. | ||
Wireplumber ( | Wireplumber ({{nixos:option|services.pipewire.wireplumber}}) is the default modular session / policy manager for PipeWire in unstable. To add custom configuration you can use {{nixos:option|services.pipewire.wireplumber.extraConfig}} directly. For example: | ||
<syntaxhighlight lang="nix"> | <syntaxhighlight lang="nix"> | ||
Line 57: | Line 75: | ||
}; | }; | ||
}; | }; | ||
</syntaxhighlight>Alternatively you can set | </syntaxhighlight>Alternatively you can set {{nixos:option|services.pipewire.wireplumber.configPackages}} as well, adding derivations that output wireplumber config files in <code>$out/share/wireplumber/wireplumber.conf.d/*.conf</code>: | ||
<syntaxhighlight lang="nix"> | <syntaxhighlight lang="nix"> | ||
Line 109: | Line 127: | ||
All protocols (Pulseaudio/JACK) are now talking to the PipeWire protocol and are managed by the PipeWire daemon (therefore, applications can be managed by both Pulseaudio and JACK tools). For that reason, all graphical tools used for these protocols can be used: | All protocols (Pulseaudio/JACK) are now talking to the PipeWire protocol and are managed by the PipeWire daemon (therefore, applications can be managed by both Pulseaudio and JACK tools). For that reason, all graphical tools used for these protocols can be used: | ||
* pavucontrol: controls the volume (per-sink and per-app basis), the default outputs/inputs, the different profiles (for HDMI outputs/bluetooth devices), routes each application to a different input/output, etc. | * {{nixos:package|pavucontrol}}: controls the volume (per-sink and per-app basis), the default outputs/inputs, the different profiles (for HDMI outputs/bluetooth devices), routes each application to a different input/output, etc. | ||
* plasma-pa: a [[KDE|Plasma]] applet to change volume directly from the systray. Also deals with volume keys. | * {{nixos:package|kdePackages.plasma-pa}}: a [[KDE|Plasma]] applet to change volume directly from the systray. Also deals with volume keys. | ||
* qjackctl: with JACK emulation, provides a patchbay (to connect applications together). Note that JACK does not provide any way to change the volume of a single application; use Pulseaudio tools for that purpose. | * {{nixos:package|qjackctl}}: with JACK emulation, provides a patchbay (to connect applications together). Note that JACK does not provide any way to change the volume of a single application; use Pulseaudio tools for that purpose. | ||
* carla: with JACK emulation, provides a patchbay (make sure to go to "Patchbay" tab and check "Canvas > Show External"). | * {{nixos:package|carla}}: with JACK emulation, provides a patchbay (make sure to go to "Patchbay" tab and check "Canvas > Show External"). | ||
* catia/patchage: similar to qjackctl and carla. | * catia/{{nixos:package|patchage}}: similar to qjackctl and carla. | ||
* | * {{nixos:package|helvum}}: GTK-based patchbay for PipeWire (uses the PipeWire protocol). Volume control is planned for later. | ||
==Advanced Configuration== | ==Advanced Configuration== | ||
PipeWire can be extensively configured to fit the users' needs. Should the user want to do some fancy routing with null sinks, these can be defined directly in the config as shown below. | PipeWire can be extensively configured to fit the users' needs. | ||
=== Null sinks === | |||
Should the user want to do some fancy routing with null sinks, these can be defined directly in the config as shown below. | |||
This is especially convenient if the user has a multi-channel (8+, or something "weird" like 2x2, 3x2) soundcard that keeps confusing applications with too many channels or a bad channel layout. | This is especially convenient if the user has a multi-channel (8+, or something "weird" like 2x2, 3x2) soundcard that keeps confusing applications with too many channels or a bad channel layout. | ||
Line 175: | Line 196: | ||
In order to load the script on startup, it can be added to <code>~/.xprofile</code> or the specific DE/WM autostart config. Similarly, a one-shot user service can be created that runs the script. | In order to load the script on startup, it can be added to <code>~/.xprofile</code> or the specific DE/WM autostart config. Similarly, a one-shot user service can be created that runs the script. | ||
==Low-latency setup== | === Low-latency setup === | ||
Audio production and rhythm games require lower latency audio than general applications. PipeWire can achieve the required latency with much less CPU usage compared to PulseAudio, with the appropriate configuration. | Audio production and rhythm games require lower latency audio than general applications. PipeWire can achieve the required latency with much less CPU usage compared to PulseAudio, with the appropriate configuration. | ||
The minimum period size controls how small a buffer can be. The lower it is, the less latency there is. PipeWire has a value of 32/48000 by default, which amounts to 0.667ms. It can be brought lower if needed: | The minimum period size controls how small a buffer can be. The lower it is, the less latency there is. PipeWire has a value of 32/48000 by default, which amounts to 0.667ms. It can be brought lower if needed: | ||
Line 192: | Line 214: | ||
<strong>NOTE</strong>: Every setup is different, and a lot of factors determine your final latency, like CPU speed, RT/PREEMPTIVE kernels and soundcards supporting different audio formats. That's why 32/48000 isn't always a value that's going to work for everyone. The best way to get everything working is to keep increasing the quant value until you get no crackles (underruns) or until you get audio again (in case there wasn't any). This won't guarantee the lowest possible latency, but will provide a decent one paired with stable audio. | <strong>NOTE</strong>: Every setup is different, and a lot of factors determine your final latency, like CPU speed, RT/PREEMPTIVE kernels and soundcards supporting different audio formats. That's why 32/48000 isn't always a value that's going to work for everyone. The best way to get everything working is to keep increasing the quant value until you get no crackles (underruns) or until you get audio again (in case there wasn't any). This won't guarantee the lowest possible latency, but will provide a decent one paired with stable audio. | ||
===PulseAudio backend=== | ==== PulseAudio backend ==== | ||
Applications using the Pulse backend have a separate configuration. The default minimum value is 1024, so it needs to be tweaked if low-latency audio is desired. | Applications using the Pulse backend have a separate configuration. The default minimum value is 1024, so it needs to be tweaked if low-latency audio is desired. | ||
Line 245: | Line 267: | ||
</syntaxHighlight> | </syntaxHighlight> | ||
==Headless operation== | === Headless operation === | ||
PipeWire can run on a headless device (without a GUI) such as a Raspberry Pi connected to a speaker. In that case, it may be preferable to start PipeWire on boot and keep it running rather than only running during an interactive login session. Among other things, this helps prevent a race condition that may occur when socket activation fails to initialize audio devices in time for their first use, leading to one-time errors after reboots. The following additional configuration facilitates this: | PipeWire can run on a headless device (without a GUI) such as a Raspberry Pi connected to a speaker. In that case, it may be preferable to start PipeWire on boot and keep it running rather than only running during an interactive login session. Among other things, this helps prevent a race condition that may occur when socket activation fails to initialize audio devices in time for their first use, leading to one-time errors after reboots. The following additional configuration facilitates this: | ||
Line 258: | Line 281: | ||
Despite early activation, you may still experience a race condition that prevents audio from working if you play media immediately after a new login such as running an SSH command. If this occurs, try introducing a short delay (e.g. <code>sleep 5</code>) before invoking the media player application. | Despite early activation, you may still experience a race condition that prevents audio from working if you play media immediately after a new login such as running an SSH command. If this occurs, try introducing a short delay (e.g. <code>sleep 5</code>) before invoking the media player application. | ||
==== System-wide PipeWire ==== | |||
As an alternative to having lingering systemd user services, PipeWire can also run as a system-wide Systemd service. See {{nixos:option|services.pipewire.systemWide}} for more. | |||
{{file|/etc/nixos/configuration.nix|nix|3= | |||
services.pipewire.systemWide = true; | |||
services.pipewire.pulse.enable = true; # pipewire-pulse also supports running system-wide | |||
# PipeWire users must be in the `pipewire` group | |||
users.users.myservice1.extraGroups = [ "pipewire" ]; | |||
systemd.services.myservice2.serviceConfig.SupplementaryGroups = [ "pipewire" ]; | |||
}} | |||
==Troubleshooting== | ==Troubleshooting== |