Adaptive sample rate and bit perfect playback with PipeWire
PipeWire can dynamically change the output sample rate to match that of the audio file being played. No resampling will take place in this case, and the DAC will play the audio losslessly.
Check the supported sample rates of the DAC, assuming we’ll be using card0 and stream0:
cat /proc/asound/card0/stream0
The supported sample rates will be listed under Rates:
Rates: 44100, 48000, 88200, 96000
Create a custom PipeWire configuration file that specifies the allowed sample rates:
nano ~/.config/pipewire/pipewire.conf.d/99-sample-rate.conf
With the following content. Replace the sample rates with the actual supported rates:
context.properties = {
default.clock.allowed-rates = [ 44100 48000 88200 96000 ]
}
Restart the PipeWire daemons:
systemctl --user restart pipewire pipewire-pulse
Verify that the configuration has taken effect:
pw-metadata -n settings
Troubleshooting
To check the sample rate and bit depth of a given audio file (e.g., foo.flac), use soxi provided by the sox package:
soxi foo.flac
To play foo.flac using the PipeWire interface with mpv:
mpv --ao=pipewire foo.flac
To play foo.flac using the PulseAudio (pipewire-pulse) interface with mpv:
mpv --ao=pulse foo.flac
To view the PipeWire node and device statistics in real time:
pw-top
To view the details of a specific PipeWire node (e.g., with an ID of 123):
pw-cli i 123
References
https://bbs.archlinux.org/viewtopic.php?id=290859
https://wiki.archlinux.org/title/PipeWire#Changing_the_allowed_sample_rate(s)
https://gitlab.freedesktop.org/pipewire/pipewire/-/work_items/1523