summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMax Kellermann <max@musicpd.org>2021-08-06 17:55:23 +0200
committerMax Kellermann <max@musicpd.org>2021-08-06 17:55:59 +0200
commit5f5b5f63af7018095513ff84ac6d08418fdb42c9 (patch)
tree3dc3010d6f3b38dbf3e038e6610293e09ecc5438
parentad6e303047397a9ef6cf9790e309f1cf438f21c8 (diff)
mixer/alsa: move code to NormalizedToPercent()
-rw-r--r--src/mixer/plugins/AlsaMixerPlugin.cxx9
1 files changed, 7 insertions, 2 deletions
diff --git a/src/mixer/plugins/AlsaMixerPlugin.cxx b/src/mixer/plugins/AlsaMixerPlugin.cxx
index 23b641cca..fd4c6817d 100644
--- a/src/mixer/plugins/AlsaMixerPlugin.cxx
+++ b/src/mixer/plugins/AlsaMixerPlugin.cxx
@@ -97,6 +97,11 @@ public:
void SetVolume(unsigned volume) override;
private:
+ [[gnu::const]]
+ static unsigned NormalizedToPercent(double normalized) noexcept {
+ return lround(100 * normalized);
+ }
+
[[gnu::pure]]
double GetNormalizedVolume() const noexcept {
return get_normalized_playback_volume(elem,
@@ -280,7 +285,7 @@ AlsaMixer::GetVolume()
throw FormatRuntimeError("snd_mixer_handle_events() failed: %s",
snd_strerror(err));
- return lround(100 * GetNormalizedVolume());
+ return NormalizedToPercent(GetNormalizedVolume());
}
void
@@ -289,7 +294,7 @@ AlsaMixer::SetVolume(unsigned volume)
assert(handle != nullptr);
double cur = GetNormalizedVolume();
- int delta = volume - lround(100.*cur);
+ int delta = volume - NormalizedToPercent(cur);
int err = set_normalized_playback_volume(elem, cur + 0.01*delta, delta);
if (err < 0)
throw FormatRuntimeError("failed to set ALSA volume: %s",