alsa-mixer: disable has_dB if max_dB is negative
authorBenjamin Valentin <benpicco@googlemail.com>
Mon, 28 Dec 2020 18:45:08 +0000 (19:45 +0100)
committerTanu Kaskinen <tanuk@iki.fi>
Mon, 18 Jan 2021 15:36:12 +0000 (17:36 +0200)
commit10ac01a2066b3d0a58ecc3e3db98dd43c284a209
tree77da1980c704a32335c6ddf5a1c0a8bea7836c02
parent4868fcf5f344af613172f61d9105c02f3f07e1ab
alsa-mixer: disable has_dB if max_dB is negative

Volume scaling in dB mode is broken if max dB is negative.

I have a Nobsound USB amplifier (1908:2220) that reports a dB range
of -127.07 dB to -128 dB in Alsa.
While this is likely a driver/device bug, in my naive imagination
userspace wouldn't bother too much with the absolute values and just set

out_dB(percent) = min_dB + (max_dB - min_dB) * percent

However, this is not what PulseAudio is doing, instead max_dB is used
as base_volume with which the desired software volume is multiplied
while min_dB does not seem to be taken into account.

The result is that with this device only a tiny portion of the volume
slider is usable.
Setting it to 97% already reaches min_dB which effectively turns any
(software) audio knob to an on/off switch.

To work around this, simply set the has_dB flag to false if max_dB is
negative.
This falls back to using raw Alsa values (ranging from 0 - 255), now
the settings in pavucontrol perfectly mirror those in alsamixer.

Part-of: <https://gitlab.freedesktop.org/pulseaudio/pulseaudio/-/merge_requests/447>
src/modules/alsa/alsa-mixer.c