Skip to content

Commit e615c18

Browse files
committed
ES8311: volume use logarithmic scale
1 parent 14ac903 commit e615c18

File tree

1 file changed

+9
-1
lines changed

1 file changed

+9
-1
lines changed

src/Driver/es8311/es8311.c

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,8 +22,10 @@
2222
*
2323
*/
2424

25+
2526
#include <string.h>
2627
#include <assert.h>
28+
#include <math.h>
2729
#include "es8311.h"
2830

2931
#ifndef BIT
@@ -636,7 +638,13 @@ error_t es8311_codec_set_voice_volume(int volume)
636638
} else if (volume > 100) {
637639
volume = 100;
638640
}
639-
int vol = (volume) * 2550 / 1000;
641+
// Use a logarithmic scale for more natural volume control
642+
int vol = 0;
643+
if (volume == 0) {
644+
vol = 0;
645+
} else {
646+
vol = (int)(255.0 * log10(9.0 * volume / 100.0 + 1.0) / log10(10.0));
647+
}
640648
es8311_write_reg(ES8311_DAC_REG32, vol);
641649
return res;
642650
}

0 commit comments

Comments
 (0)