From 8851c533a776d200e8fff2b0c4a8a39dfd28213f Mon Sep 17 00:00:00 2001 From: manuaudio <188948351+manuaudio@users.noreply.github.com> Date: Thu, 12 Nov 2026 22:05:57 -0800 Subject: [PATCH] Let PipeWire follow the source's sample rate Ship a PipeWire drop-in that allows 44.1, 48, 88.2 and 96 kHz, so a stream starting on an idle device plays at its own rate instead of being resampled to 48 kHz. Rates the hardware can't do still resample, as today. The migration installs the drop-in for existing users and applies the same list to the running graph through pw-metadata, so it takes effect without restarting PipeWire. Anyone who already set allowed-rates is left alone. Co-Authored-By: Claude Opus 5.5 --- .../pipewire.conf.d/10-sample-rates.conf | 8 +++++++ migrations/1793769095.sh | 21 +++++++++++++++++++ 2 files changed, 29 insertions(+) create mode 100644 config/pipewire/pipewire.conf.d/10-sample-rates.conf create mode 100644 migrations/1793769095.sh diff --git a/config/pipewire/pipewire.conf.d/10-sample-rates.conf b/config/pipewire/pipewire.conf.d/10-sample-rates.conf new file mode 100644 index 000000000000..b64e5c5e6ff2 --- /dev/null +++ b/config/pipewire/pipewire.conf.d/10-sample-rates.conf @@ -0,0 +1,8 @@ +## Follow the source's sample rate instead of resampling everything to 48 kHz. +## When a stream starts on an idle device, PipeWire switches the device to the +## stream's rate if the hardware supports it, so 44.1 kHz music and 88.2/96 kHz +## recordings play without resampling. Rates the device can't do still resample. + +context.properties = { + default.clock.allowed-rates = [ 44100 48000 88200 96000 ] +} diff --git a/migrations/1793769095.sh b/migrations/1793769095.sh new file mode 100644 index 000000000000..87cd12dd2371 --- /dev/null +++ b/migrations/1793769095.sh @@ -0,0 +1,21 @@ +echo "Let PipeWire follow the source's sample rate" + +conf="pipewire/pipewire.conf.d/10-sample-rates.conf" +config_root="${XDG_CONFIG_HOME:-$HOME/.config}" + +# Leave anyone who already chose their rates alone, in any PipeWire config. +# PIPEWIRE_CONFIG_DIR is PipeWire's own override for /etc/pipewire. +rates_configured() { + local system="${PIPEWIRE_CONFIG_DIR:-/etc/pipewire}" + + grep -qsE '^[[:space:]]*default\.clock\.allowed-rates' \ + "$config_root/pipewire/pipewire.conf" "$config_root"/pipewire/pipewire.conf.d/*.conf \ + "$system/pipewire.conf" "$system"/pipewire.conf.d/*.conf +} + +if [[ ! -f $config_root/$conf ]] && ! rates_configured; then + install -Dm644 "$OMARCHY_PATH/config/$conf" "$config_root/$conf" + # PipeWire only reads conf.d at startup. Apply the rates to the running graph + # too, so the change takes effect now without interrupting playback. + pw-metadata -n settings 0 clock.allowed-rates "[ 44100 48000 88200 96000 ]" >/dev/null 2>&1 || true +fi