From 23d8856773cef451f4de2d7cec721e086ac4882a Mon Sep 17 00:00:00 2001 From: Aloshi Date: Wed, 9 Jul 2014 16:17:59 -0500 Subject: [PATCH] Fixed VolumeControl::getVolume() rounding bug on Windows. --- es-app/src/VolumeControl.cpp | 5 +++-- es-app/src/guis/GuiMenu.cpp | 2 +- 2 files changed, 4 insertions(+), 3 deletions(-) diff --git a/es-app/src/VolumeControl.cpp b/es-app/src/VolumeControl.cpp index 1097ae2e1..394bab6be 100644 --- a/es-app/src/VolumeControl.cpp +++ b/es-app/src/VolumeControl.cpp @@ -284,7 +284,7 @@ int VolumeControl::getVolume() const mixerControlDetails.cbDetails = sizeof(MIXERCONTROLDETAILS_UNSIGNED); if (mixerGetControlDetails((HMIXEROBJ)mixerHandle, &mixerControlDetails, MIXER_GETCONTROLDETAILSF_VALUE) == MMSYSERR_NOERROR) { - volume = (uint8_t)((value.dwValue * 100) / 65535); + volume = (uint8_t)round((value.dwValue * 100) / 65535); } else { @@ -297,7 +297,8 @@ int VolumeControl::getVolume() const float floatVolume = 0.0f; //0-1 if (endpointVolume->GetMasterVolumeLevelScalar(&floatVolume) == S_OK) { - volume = (uint8_t)(floatVolume * 100.0f); + volume = (uint8_t)round(floatVolume * 100.0f); + LOG(LogInfo) << " getting volume as " << volume << " ( from float " << floatVolume << ")"; } else { diff --git a/es-app/src/guis/GuiMenu.cpp b/es-app/src/guis/GuiMenu.cpp index 080b74b24..5eee21b8a 100644 --- a/es-app/src/guis/GuiMenu.cpp +++ b/es-app/src/guis/GuiMenu.cpp @@ -75,7 +75,7 @@ GuiMenu::GuiMenu(Window* window) : GuiComponent(window), mMenu(window, "MAIN MEN auto volume = std::make_shared(mWindow, 0.f, 100.f, 1.f, "%"); volume->setValue((float)VolumeControl::getInstance()->getVolume()); s->addWithLabel("SYSTEM VOLUME", volume); - s->addSaveFunc([volume] { VolumeControl::getInstance()->setVolume((int)volume->getValue()); }); + s->addSaveFunc([volume] { VolumeControl::getInstance()->setVolume((int)round(volume->getValue())); }); // disable sounds auto sounds_enabled = std::make_shared(mWindow);