volume_mapping: get rid of exp10 workaround

exp10 is a GNU function, is not part of C++, and is not available
everywhere.

pow(10,x) is an alternative that works just as well. It is used in musl as
the implementation of exp10.

Signed-off-by: Rosen Penev <rosenp@gmail.com>
This commit is contained in:
Rosen Penev 2020-02-03 15:26:50 -08:00
parent 3ec9fcfc44
commit a78841d6a9
No known key found for this signature in database
GPG Key ID: 36D31CFA845F0E3B

View File

@ -34,11 +34,6 @@
#include <stdbool.h>
#include "volume_mapping.h"
#ifdef __UCLIBC__
/* 10^x = 10^(log e^x) = (e^x)^log10 = e^(x * log 10) */
#define exp10(x) (exp((x) * log(10)))
#endif /* __UCLIBC__ */
#define MAX_LINEAR_DB_SCALE 24
static inline bool use_linear_dB_scale(long dBmin, long dBmax)
@ -111,9 +106,9 @@ static double get_normalized_volume(snd_mixer_elem_t *elem,
if (use_linear_dB_scale(min, max))
return (value - min) / (double)(max - min);
normalized = exp10((value - max) / 6000.0);
normalized = pow(10, (value - max) / 6000.0);
if (min != SND_CTL_TLV_DB_GAIN_MUTE) {
min_norm = exp10((min - max) / 6000.0);
min_norm = pow(10, (min - max) / 6000.0);
normalized = (normalized - min_norm) / (1 - min_norm);
}
@ -159,7 +154,7 @@ static int set_normalized_volume(snd_mixer_elem_t *elem,
}
if (min != SND_CTL_TLV_DB_GAIN_MUTE) {
min_norm = exp10((min - max) / 6000.0);
min_norm = pow(10, (min - max) / 6000.0);
volume = volume * (1 - min_norm) + min_norm;
}
value = lrint_dir(6000.0 * log10(volume), dir) + max;