Sound: properly round percent values

Fix #1558
This commit is contained in:
Carter Li
2025-02-14 14:05:37 +08:00
parent ba7885913d
commit 217ea61568
3 changed files with 3 additions and 3 deletions
+1 -1
View File
@@ -18,7 +18,7 @@ static void paSinkInfoCallback(pa_context *c, const pa_sink_info *i, int eol, vo
ffStrbufInitS(&device->name, i->description);
ffStrbufTrimRightSpace(&device->name);
ffStrbufTrimLeft(&device->name, ' ');
device->volume = i->mute ? 0 : (uint8_t) (i->volume.values[0] * 100 / PA_VOLUME_NORM);
device->volume = i->mute ? 0 : (uint8_t) ((i->volume.values[0] * 100 + PA_VOLUME_NORM / 2 /*round*/) / PA_VOLUME_NORM);
device->active = i->active_port && i->active_port->available != PA_PORT_AVAILABLE_NO;
device->main = false;
}
+1 -1
View File
@@ -41,7 +41,7 @@ const char* ffDetectSound(FFlist* devices)
ffStrbufInitS(&device->name, ad.name);
ffStrbufTrimRightSpace(&device->name);
ffStrbufInitF(&device->platformApi, "%s", "SunAudio");
device->volume = (uint8_t) (ai.play.gain * 100 / AUDIO_MAX_GAIN);
device->volume = (uint8_t) ((ai.play.gain * 100 + AUDIO_MAX_GAIN / 2) / AUDIO_MAX_GAIN);
device->active = true;
device->main = defaultDev == idev;
}
+1 -1
View File
@@ -80,7 +80,7 @@ const char* ffDetectSound(FFlist* devices)
if (!bundle.mute[i])
totalLevel += bundle.level[i];
}
device->volume = (uint8_t) (totalLevel * 100 / bundle.iLevel);
device->volume = (uint8_t) ((totalLevel * 100 + bundle.iLevel / 2) / bundle.iLevel);
return NULL;
}