Skip to content

Commit da07d70

Browse files
committed
es8311 volume: logarithmic mapping
1 parent e615c18 commit da07d70

File tree

1 file changed

+8
-1
lines changed

1 file changed

+8
-1
lines changed

src/Driver/es8311/es8311.c

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -659,7 +659,14 @@ error_t es8311_codec_get_voice_volume(int *volume)
659659
*volume = 0;
660660
res = RESULT_FAIL;
661661
} else {
662-
*volume = regv * 100 / 256;
662+
// Inverse of the logarithmic mapping used in set_voice_volume
663+
if (regv <= 0) {
664+
*volume = 0;
665+
} else {
666+
double v = (double)regv / 255.0;
667+
*volume = (int)((pow(10.0, v * log10(10.0)) - 1.0) / 9.0 * 100.0 + 0.5);
668+
if (*volume > 100) *volume = 100;
669+
}
663670
}
664671
AD_LOGD( "GET: res:%d, volume:%d", regv, *volume);
665672
return res;

0 commit comments

Comments
 (0)