Commit bede5646 authored by Max Kellermann's avatar Max Kellermann

mixer/alsa: work around rounding error at volume 0

Due to rounding errors, a slightly negative value can be passed to set_normalized_volume(), which will make the log10() call fail. Actually, volume 0 is already failing because log10(0) is illegal. So let's fix this by implementing two corner cases: <=0 and >=100. Closes #212
parent e0ca4b86
ver 0.20.17 (not yet released)
* output
- alsa: fix crash bug with 8 channels
* mixer
- alsa: fix rounding error at volume 0
* fix real-time and idle scheduling with Musl
* Android
- fix compatibility with Android 4.0
......
......@@ -139,6 +139,13 @@ static int set_normalized_volume(snd_mixer_elem_t *elem,
return set_raw[ctl_dir](elem, value);
}
/* two special cases to avoid rounding errors at 0% and
100% */
if (volume <= 0)
return set_dB[ctl_dir](elem, min, dir);
else if (volume >= 100)
return set_dB[ctl_dir](elem, max, dir);
if (use_linear_dB_scale(min, max)) {
value = lrint_dir(volume * (max - min), dir) + min;
return set_dB[ctl_dir](elem, value, dir);
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment