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