Fixed VolumeControl::getVolume() rounding bug on Windows.

This commit is contained in:
Aloshi 2014-07-09 16:17:59 -05:00
parent 07598b3d6f
commit 23d8856773
2 changed files with 4 additions and 3 deletions

View file

@ -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
{

View file

@ -75,7 +75,7 @@ GuiMenu::GuiMenu(Window* window) : GuiComponent(window), mMenu(window, "MAIN MEN
auto volume = std::make_shared<SliderComponent>(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<SwitchComponent>(mWindow);