Blame SOURCES/0015-alsa-mixer-round-not-truncate-in-to_alsa_dB.patch

e44045
From 739a4b3d2318f05eb7101c2baa861e5c636125a5 Mon Sep 17 00:00:00 2001
e44045
From: Ian Ray <ian.ray@ge.com>
e44045
Date: Wed, 30 Aug 2017 11:09:48 +0300
e44045
Subject: [PATCH 15/48] alsa-mixer: round, not truncate, in to_alsa_dB
e44045
e44045
to_alsa_dB() returns a result rounded to two decimal places (instead of
e44045
using integer truncation) to avoid small errors when converting between
e44045
dB and volume.
e44045
e44045
Consider playback at -22 dB (which is supported by ALSA) but results in
e44045
the higher level of -21 dB plus software attenuation.
e44045
e44045
    pa_sw_volume_from_dB(-22) = 28172
e44045
    pa_sw_volume_to_dB(28172) = -21.9997351
e44045
    to_alsa_dB(-21.9997351)   = -2199
e44045
e44045
    ALSA value 106 = -2200
e44045
    ALSA value 107 = -2100
e44045
    ...
e44045
e44045
    rounding = +1  /* "accurate or first above" */
e44045
    snd_mixer_selem_ask_playback_dB_vol(me, -2199, rounding, &alsa_val)
e44045
    alsa_val = -2100
e44045
e44045
Signed-off-by: Ian Ray <ian.ray@ge.com>
e44045
---
e44045
 src/modules/alsa/alsa-mixer.c | 2 +-
e44045
 1 file changed, 1 insertion(+), 1 deletion(-)
e44045
e44045
diff --git a/src/modules/alsa/alsa-mixer.c b/src/modules/alsa/alsa-mixer.c
e44045
index f59cad39..aeaf12c4 100644
e44045
--- a/src/modules/alsa/alsa-mixer.c
e44045
+++ b/src/modules/alsa/alsa-mixer.c
e44045
@@ -700,7 +700,7 @@ void pa_alsa_path_set_free(pa_alsa_path_set *ps) {
e44045
 }
e44045
 
e44045
 static long to_alsa_dB(pa_volume_t v) {
e44045
-    return (long) (pa_sw_volume_to_dB(v) * 100.0);
e44045
+    return lround(pa_sw_volume_to_dB(v) * 100.0);
e44045
 }
e44045
 
e44045
 static pa_volume_t from_alsa_dB(long v) {
e44045
-- 
e44045
2.13.6
e44045