From 3a8e7005a980bcbdca7c56b2c236ecbcb6b0b7ca Mon Sep 17 00:00:00 2001 From: Colin Guthrie Date: Fri, 8 Oct 2010 16:46:43 +0100 Subject: [PATCH] tlv: Ensure that min-is-mute flag is honored in snd_tlv_convert_from_dB() Thanks to Clemens Ladisch for identifying the issue and the original patch. Discussion here: http://thread.gmane.org/gmane.linux.alsa.devel/77688 --- src/control/tlv.c | 21 +++++++++++++-------- 1 files changed, 13 insertions(+), 8 deletions(-) diff --git a/src/control/tlv.c b/src/control/tlv.c index ba52752..d525f29 100644 --- a/src/control/tlv.c +++ b/src/control/tlv.c @@ -326,16 +326,21 @@ int snd_tlv_convert_from_dB(unsigned int *tlv, long rangemin, long rangemax, min = tlv[2]; step = (tlv[3] & 0xffff); max = min + (int)(step * (rangemax - rangemin)); - if (db_gain <= min) - *value = rangemin; - else if (db_gain >= max) + if (db_gain >= max) *value = rangemax; else { - long v = (db_gain - min) * (rangemax - rangemin); - if (xdir > 0) - v += (max - min) - 1; - v = v / (max - min) + rangemin; - *value = v; + if (db_gain <= min) + *value = rangemin; + else { + long v = (db_gain - min) * (rangemax - rangemin); + if (xdir > 0) + v += (max - min) - 1; + v = v / (max - min) + rangemin; + *value = v; + } + if (*value == rangemin && xdir > 0 && (tlv[3] & 0x10000) && + db_gain > SND_CTL_TLV_DB_GAIN_MUTE) + (*value)++; } return 0; } -- 1.7.3.1