pcm_meter: give the s16 scope a level for DSD streams
The s16 scope cannot convert DSD, so scopes see nothing on a DSD source -
needles sit still on a format that is increasingly common on USB DACs.
DSD carries no sample values, only a bit density: over a short window the
proportion of ones is the amplitude, one half being silence. One S16
sample per frame can therefore be recovered by counting the bits of that
frame and smoothing the result, which is what a scope needs - a level,
not a reconstruction. Counting bits is invariant to their order, so the
LE and BE variants share one code path and only the width of a frame
matters.
Two things set the quality, and both follow the format's own definition
rather than a tuning choice. The count is noisy - 32 bits give a standard
deviation of 0.5/sqrt(32) - hence a per-channel exponential average whose
time constant comes from the rate, so it is a duration and behaves the
same from DSD64 to DSD512. And the scale: 0 dBFS in DSD is a 50%
modulation index, so a full-scale signal swings the density between 25%
and 75% only; referring to the whole range would read 6 dB low.
Measured on x86-64 with a DSD-capable USB DAC, playing the same master in
both formats: native DSD64 reads min 2 / max 21 / mean 7.1 where the FLAC
96/24 of the same track reads min 2 / max 22 / mean 7.6. The DAC keeps
receiving DSD_U32_BE bit-perfect; this only feeds the scope.
Closes: https://github.com/alsa-project/alsa-lib/pull/517 Signed-off-by: Julien Gainza <gainza.julien@gmail.com> Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com> Signed-off-by: Jaroslav Kysela <perex@perex.cz>