diff options
| author | Jaroslav Kysela <perex@perex.cz> | 2020-06-05 13:38:53 +0200 |
|---|---|---|
| committer | Jaroslav Kysela <perex@perex.cz> | 2020-06-05 17:04:18 +0200 |
| commit | d39f5acd9b4fd77c98dfdeb0aab18a91824a228a (patch) | |
| tree | 106ae00f38dfe929a0ec471e3fc9a0b1d1d9266c /src/control | |
| parent | 409cea07599806e8dbe7d78404349afdcef80ac3 (diff) | |
| download | alsa-lib-d39f5acd9b4fd77c98dfdeb0aab18a91824a228a.tar.gz | |
control: use more precise rounding in snd_ctl_ascii_value_parse()
Signed-off-by: Jaroslav Kysela <perex@perex.cz>
Diffstat (limited to 'src/control')
| -rw-r--r-- | src/control/ctlparse.c | 19 |
1 files changed, 11 insertions, 8 deletions
diff --git a/src/control/ctlparse.c b/src/control/ctlparse.c index b0bb5ee3..1ac31bb9 100644 --- a/src/control/ctlparse.c +++ b/src/control/ctlparse.c @@ -33,17 +33,20 @@ /* Function to convert from percentage to volume. val = percentage */ -#ifdef HAVE_SOFT_FLOAT -static inline long int convert_prange1(long val, long min, long max) +static inline long int convert_prange1(long perc, long min, long max) { - long temp = val * (max - min); - return temp / 100 + min + ((temp % 100) == 0 ? 0 : 1); -} -#else + long tmp; -#define convert_prange1(val, min, max) \ - ceil((val) * ((max) - (min)) * 0.01 + (min)) +#ifdef HAVE_SOFT_FLOAT + tmp = perc * (max - min); + tmp = tmp / 100 + ((tmp % 100) < 50 ? 0 : 1); +#else + tmp = rint((double)perc * (double)(max - min) * 0.01); #endif + if (tmp == 0 && perc > 0) + tmp++; + return tmp + min; +} #define check_range(val, min, max) \ ((val < min) ? (min) : ((val > max) ? (max) : (val))) |
