From ad6e303047397a9ef6cf9790e309f1cf438f21c8 Mon Sep 17 00:00:00 2001 From: Max Kellermann Date: Fri, 6 Aug 2021 17:53:24 +0200 Subject: [PATCH] mixer/alsa: move code to GetNormalizedVolume() --- src/mixer/plugins/AlsaMixerPlugin.cxx | 11 +++++++++-- 1 file changed, 9 insertions(+), 2 deletions(-) diff --git a/src/mixer/plugins/AlsaMixerPlugin.cxx b/src/mixer/plugins/AlsaMixerPlugin.cxx index 9d264993a..23b641cca 100644 --- a/src/mixer/plugins/AlsaMixerPlugin.cxx +++ b/src/mixer/plugins/AlsaMixerPlugin.cxx @@ -95,6 +95,13 @@ public: void Close() noexcept override; int GetVolume() override; void SetVolume(unsigned volume) override; + +private: + [[gnu::pure]] + double GetNormalizedVolume() const noexcept { + return get_normalized_playback_volume(elem, + SND_MIXER_SCHN_FRONT_LEFT); + } }; static constexpr Domain alsa_mixer_domain("alsa_mixer"); @@ -273,7 +280,7 @@ AlsaMixer::GetVolume() throw FormatRuntimeError("snd_mixer_handle_events() failed: %s", snd_strerror(err)); - return lround(100 * get_normalized_playback_volume(elem, SND_MIXER_SCHN_FRONT_LEFT)); + return lround(100 * GetNormalizedVolume()); } void @@ -281,7 +288,7 @@ AlsaMixer::SetVolume(unsigned volume) { assert(handle != nullptr); - double cur = get_normalized_playback_volume(elem, SND_MIXER_SCHN_FRONT_LEFT); + double cur = GetNormalizedVolume(); int delta = volume - lround(100.*cur); int err = set_normalized_playback_volume(elem, cur + 0.01*delta, delta); if (err < 0)