PipeWire: Difference between revisions
Jonniecache (talk | contribs) |
Describe how to turn off sound for X11 urgency hints as an example for extraConfig |
||
(10 intermediate revisions by 6 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 43: | Line 61: | ||
}; | }; | ||
}; | }; | ||
</syntaxhighlight> | </syntaxhighlight>{{Note|This config may break wireplumber, so that the following options were no longer available for Bluetooth headsets | ||
- High Fidelity Playback (A2DP Sink, codec SBC) | |||
- High Fidelity Playback (A2DP Sink, codec SBC-XQ) | |||
- High Fidelity Playback (A2DP Sink, codec AAC)}} | |||
Or, to disable automatic HSP/HFP and A2DP mode switching, which is part of the <code>11-bluetooth-policy</code> configuration:<syntaxhighlight lang="nix"> | Or, to disable automatic HSP/HFP and A2DP mode switching, which is part of the <code>11-bluetooth-policy</code> configuration:<syntaxhighlight lang="nix"> | ||
Line 51: | 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 103: | 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 169: | 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 186: | 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 239: | 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 267: | Line 296: | ||
* Ensure the audio interface and Ardour are set to the same sample rate. Ardour8 will accept a configuration where its sample rate does not match the audio interface's sample rate, when using PipeWire, but will not actually be able to record audio unless they match. If you are unable to successfully activate a track's record button, this may be the issue. | * Ensure the audio interface and Ardour are set to the same sample rate. Ardour8 will accept a configuration where its sample rate does not match the audio interface's sample rate, when using PipeWire, but will not actually be able to record audio unless they match. If you are unable to successfully activate a track's record button, this may be the issue. | ||
=== Sound pops a few seconds after playback stops === | === Sound pops a few seconds after playback stops OR audio takes a long time to start playing after a couple of seconds === | ||
By default Wireplumber suspends a sink after 5 seconds of no playback which can create a sound pop on sensitive audio equipment. You can disable this by providing extra configuration to wireplumber but first you need to find out the name of the problematic sink in the wireplumber namespace. | By default Wireplumber suspends a sink after 5 seconds of no playback which can create a sound pop on sensitive audio equipment, or a noticeable delay on equipment that takes a moment to start back up. You can disable this by providing extra configuration to wireplumber but first you need to find out the name of the problematic sink in the wireplumber namespace (or blanket disable the functionality). | ||
<ol> | <ol> | ||
<li>'''Find out the name of the sink''' | <li>'''Find out the name of the sink (Optional)''' | ||
<ol> | <ol> | ||
<li>Run <code>pw-top</code> to monitor pipewire processes</li> | <li>Run <code>pw-top</code> to monitor pipewire processes</li> | ||
Line 279: | Line 308: | ||
<li>'''Add configuration''': | <li>'''Add configuration''': | ||
If you want to blanket do this for all devices, you can use <code>~alsa_input.*</code> and <code>~alsa_output.*</code> to match all input and output devices. You can also use (from the step above) an exact device if you only want to change the setting for that single device. In that case you can match only a single device, and replace the node name with EG: <code>alsa_output.usb-ASUSTeK_Xonar_SoundCard-00.iec958-stereo</code>, and it will target that specific device. | |||
<syntaxhighlight lang="nix"> | <syntaxhighlight lang="nix"> | ||
# Disable suspend of Toslink output to prevent audio popping. | # Disable suspend of Toslink output to prevent audio popping. | ||
Line 287: | Line 316: | ||
matches = [ | matches = [ | ||
{ | { | ||
"node.name" = "alsa_output. | "node.name" = "~alsa_input.*"; | ||
} | |||
{ | |||
"node.name" = "~alsa_output.*"; | |||
} | } | ||
]; | ]; | ||
Line 308: | Line 340: | ||
</ol> | </ol> | ||
=== Eliminating audio startup delay after suspend or boot === | |||
In addition to audio popping, some HTPC systems may experience a delay when audio playback starts after resuming from suspend or system boot. This occurs even if suspension is disabled as described above. | |||
<ol> | |||
<li>'''Identify your sink''' using the method in the previous section.</li> | |||
<li>'''Enhance configuration''': | |||
<syntaxhighlight lang="nix"> | |||
# Disable node suspend on NVIDIA graphics | |||
services.pipewire.wireplumber.extraConfig."99-disable-suspend"."monitor.alsa.rules" = [ | |||
{ | |||
matches = [ { "node.name" = "alsa_output.pci-0000_01_00.1.hdmi-stereo-extra1"; } ]; | |||
actions.update-props = { | |||
"session.suspend-timeout-seconds" = 0; | |||
"node.always-process" = true; | |||
"dither.method" = "wannamaker3"; | |||
"dither.noise" = 1; | |||
}; | |||
} | |||
]; | |||
</syntaxhighlight> | |||
This configuration prevents audio popping and keeps the audio pipeline active, effectively reducing startup delay from ~5s to ~1s. Adding the dither settings further eliminates the remaining delay. | |||
</li> | |||
Line 315: | Line 370: | ||
==See also== | ==See also== | ||
* https://github.com/NixOS/nixpkgs/issues/102547 | * https://github.com/NixOS/nixpkgs/issues/102547 | ||
* https://gitlab.freedesktop.org/pipewire/pipewire/-/issues/3858 | |||
[[Category:Audio]] | [[Category:Audio]] |