mixer/alsa: move code to GetNormalizedVolume()
This commit is contained in:
parent
b0e9538855
commit
ad6e303047
@ -95,6 +95,13 @@ public:
|
|||||||
void Close() noexcept override;
|
void Close() noexcept override;
|
||||||
int GetVolume() override;
|
int GetVolume() override;
|
||||||
void SetVolume(unsigned volume) 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");
|
static constexpr Domain alsa_mixer_domain("alsa_mixer");
|
||||||
@ -273,7 +280,7 @@ AlsaMixer::GetVolume()
|
|||||||
throw FormatRuntimeError("snd_mixer_handle_events() failed: %s",
|
throw FormatRuntimeError("snd_mixer_handle_events() failed: %s",
|
||||||
snd_strerror(err));
|
snd_strerror(err));
|
||||||
|
|
||||||
return lround(100 * get_normalized_playback_volume(elem, SND_MIXER_SCHN_FRONT_LEFT));
|
return lround(100 * GetNormalizedVolume());
|
||||||
}
|
}
|
||||||
|
|
||||||
void
|
void
|
||||||
@ -281,7 +288,7 @@ AlsaMixer::SetVolume(unsigned volume)
|
|||||||
{
|
{
|
||||||
assert(handle != nullptr);
|
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 delta = volume - lround(100.*cur);
|
||||||
int err = set_normalized_playback_volume(elem, cur + 0.01*delta, delta);
|
int err = set_normalized_playback_volume(elem, cur + 0.01*delta, delta);
|
||||||
if (err < 0)
|
if (err < 0)
|
||||||
|
Loading…
Reference in New Issue
Block a user