diff options
author | Max Kellermann <max@musicpd.org> | 2018-02-10 09:07:51 +0100 |
---|---|---|
committer | Max Kellermann <max@musicpd.org> | 2018-02-10 09:07:51 +0100 |
commit | bede564618e78d2a4eee5af329178be89ae34412 (patch) | |
tree | 8346a04a4421529e3970d392f6a9cdbebddfa212 /src/mixer | |
parent | e0ca4b865a2dcb581c90cff66e919b30312b45da (diff) |
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
Diffstat (limited to 'src/mixer')
-rw-r--r-- | src/mixer/plugins/volume_mapping.c | 7 |
1 files changed, 7 insertions, 0 deletions
diff --git a/src/mixer/plugins/volume_mapping.c b/src/mixer/plugins/volume_mapping.c index 4e559cf54..2078d346d 100644 --- a/src/mixer/plugins/volume_mapping.c +++ b/src/mixer/plugins/volume_mapping.c @@ -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); |