From da2cecf07484521540a28c680c4a19392d93d833 Mon Sep 17 00:00:00 2001 From: Pauli Virtanen Date: Wed, 15 Oct 2025 20:11:36 +0300 Subject: [PATCH] alsa: acp: don't disable dB if negative max unless range is small Disabling dB volumes for max_dB < 0 was added in Pulseaudio in 2021, based on a device which had -128..-127.07 range. However, negative max_dB is valid value for USB devices, and there are devices that have it. Eg. Microsoft LifeChat LX-3000 has numid=6,iface=MIXER,name='Speaker Playback Volume' ; type=INTEGER,access=rw---R--,values=2,min=0,max=151,step=0 : values=150,150 | dBminmax-min=-28.37dB,max=-0.06dB and the dB range seems to be OK. Web search for "The decibel volume range for element" also gives other hits with seemingly OK looking ranges. Don't disable dB volume unless both the max is negative and the range is suspiciously small. This should still disable it for the device this check was originally added for. Link: https://gitlab.freedesktop.org/pulseaudio/pulseaudio/-/merge_requests/447 Link: https://gitlab.freedesktop.org/pulseaudio/pulseaudio/-/commit/10ac01a2066b3d0a58ecc3e3db98dd43c284a209 --- spa/plugins/alsa/acp/alsa-mixer.c | 12 ++++++++---- 1 file changed, 8 insertions(+), 4 deletions(-) diff --git a/spa/plugins/alsa/acp/alsa-mixer.c b/spa/plugins/alsa/acp/alsa-mixer.c index ec9726d8c..b18d7c6c9 100644 --- a/spa/plugins/alsa/acp/alsa-mixer.c +++ b/spa/plugins/alsa/acp/alsa-mixer.c @@ -1719,11 +1719,15 @@ static bool element_probe_volume(pa_alsa_element *e, snd_mixer_elem_t *me) { else e->has_dB = snd_mixer_selem_get_capture_dB_range(me, &min_dB, &max_dB) >= 0; - /* Assume decibel data to be incorrect if max_dB is negative. */ - if (e->has_dB && max_dB < 0 && !e->db_fix) { + /* Assume decibel data to be incorrect if max_dB is negative and dB range is + * suspiciously small (< 10 dB). This can happen eg. if USB device is using volume + * values as arbitrary scale ignoring USB standard on their meaning. + */ + if (e->has_dB && max_dB < 0 && SPA_ABS(max_dB - min_dB) < 10*100 && !e->db_fix) { pa_alsa_mixer_id_to_string(buf, sizeof(buf), &e->alsa_id); - pa_log_warn("The decibel volume range for element %s (%li dB - %li dB) has negative maximum. " - "Disabling the decibel range.", buf, min_dB, max_dB); + pa_log_warn("The decibel volume range for element %s (%0.2f dB to %0.2f dB) has negative maximum " + "and suspiciously small range. " + "Disabling the decibel range.", buf, min_dB/100.0, max_dB/100.0); e->has_dB = false; }