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
This commit is contained in:
parent
e0ca4b865a
commit
bede564618
2
NEWS
2
NEWS
|
@ -1,6 +1,8 @@
|
|||
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);
|
||||
|
|
Loading…
Reference in New Issue