Skip to content

Commit 23d8856

Browse files
committed
Fixed VolumeControl::getVolume() rounding bug on Windows.
1 parent 07598b3 commit 23d8856

File tree

2 files changed

+4
-3
lines changed

2 files changed

+4
-3
lines changed

es-app/src/VolumeControl.cpp

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -284,7 +284,7 @@ int VolumeControl::getVolume() const
284284
mixerControlDetails.cbDetails = sizeof(MIXERCONTROLDETAILS_UNSIGNED);
285285
if (mixerGetControlDetails((HMIXEROBJ)mixerHandle, &mixerControlDetails, MIXER_GETCONTROLDETAILSF_VALUE) == MMSYSERR_NOERROR)
286286
{
287-
volume = (uint8_t)((value.dwValue * 100) / 65535);
287+
volume = (uint8_t)round((value.dwValue * 100) / 65535);
288288
}
289289
else
290290
{
@@ -297,7 +297,8 @@ int VolumeControl::getVolume() const
297297
float floatVolume = 0.0f; //0-1
298298
if (endpointVolume->GetMasterVolumeLevelScalar(&floatVolume) == S_OK)
299299
{
300-
volume = (uint8_t)(floatVolume * 100.0f);
300+
volume = (uint8_t)round(floatVolume * 100.0f);
301+
LOG(LogInfo) << " getting volume as " << volume << " ( from float " << floatVolume << ")";
301302
}
302303
else
303304
{

es-app/src/guis/GuiMenu.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -75,7 +75,7 @@ GuiMenu::GuiMenu(Window* window) : GuiComponent(window), mMenu(window, "MAIN MEN
7575
auto volume = std::make_shared<SliderComponent>(mWindow, 0.f, 100.f, 1.f, "%");
7676
volume->setValue((float)VolumeControl::getInstance()->getVolume());
7777
s->addWithLabel("SYSTEM VOLUME", volume);
78-
s->addSaveFunc([volume] { VolumeControl::getInstance()->setVolume((int)volume->getValue()); });
78+
s->addSaveFunc([volume] { VolumeControl::getInstance()->setVolume((int)round(volume->getValue())); });
7979

8080
// disable sounds
8181
auto sounds_enabled = std::make_shared<SwitchComponent>(mWindow);

0 commit comments

Comments
 (0)