aboutsummaryrefslogtreecommitdiffstats
path: root/src/mixer
diff options
context:
space:
mode:
authorMax Kellermann <max@duempel.org>2014-05-12 12:46:14 +0200
committerMax Kellermann <max@duempel.org>2014-05-12 12:46:14 +0200
commit073e9d06ec756d839fd61b14e95711c13e6c1c87 (patch)
tree36b54c5924db410d09e0a850e61fa89492e5189b /src/mixer
parentfd1b04932a07e146a0a3c4ce52ace068a112587b (diff)
downloadmpd-073e9d06ec756d839fd61b14e95711c13e6c1c87.tar.gz
mpd-073e9d06ec756d839fd61b14e95711c13e6c1c87.tar.xz
mpd-073e9d06ec756d839fd61b14e95711c13e6c1c87.zip
mixer/software: keep attribute "volume" in the 0..100 range
The attribute must be 0..100 and not 0..1024. Previously, the code was inconsistent.
Diffstat (limited to 'src/mixer')
-rw-r--r--src/mixer/plugins/SoftwareMixerPlugin.cxx26
1 files changed, 19 insertions, 7 deletions
diff --git a/src/mixer/plugins/SoftwareMixerPlugin.cxx b/src/mixer/plugins/SoftwareMixerPlugin.cxx
index 0cde682f6..f14766002 100644
--- a/src/mixer/plugins/SoftwareMixerPlugin.cxx
+++ b/src/mixer/plugins/SoftwareMixerPlugin.cxx
@@ -49,6 +49,9 @@ class SoftwareMixer final : public Mixer {
*/
bool owns_filter;
+ /**
+ * The current volume in percent (0..100).
+ */
unsigned volume;
public:
@@ -93,19 +96,28 @@ software_mixer_init(gcc_unused EventLoop &event_loop,
return new SoftwareMixer(listener);
}
+gcc_const
+static unsigned
+PercentVolumeToSoftwareVolume(unsigned volume)
+{
+ assert(volume <= 100);
+
+ if (volume >= 100)
+ return PCM_VOLUME_1;
+ else if (volume > 0)
+ return pcm_float_to_volume((exp(volume / 25.0) - 1) /
+ (54.5981500331F - 1));
+ else
+ return 0;
+}
+
bool
SoftwareMixer::SetVolume(unsigned new_volume, gcc_unused Error &error)
{
assert(new_volume <= 100);
- if (new_volume >= 100)
- new_volume = PCM_VOLUME_1;
- else if (new_volume > 0)
- new_volume = pcm_float_to_volume((exp(new_volume / 25.0) - 1) /
- (54.5981500331F - 1));
-
volume = new_volume;
- volume_filter_set(filter, new_volume);
+ volume_filter_set(filter, PercentVolumeToSoftwareVolume(new_volume));
return true;
}