Skip to content

Commit 217ea61

Browse files
committed
Sound: properly round percent values
Fix #1558
1 parent ba78859 commit 217ea61

File tree

3 files changed

+3
-3
lines changed

3 files changed

+3
-3
lines changed

src/detection/sound/sound_linux.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ static void paSinkInfoCallback(pa_context *c, const pa_sink_info *i, int eol, vo
1818
ffStrbufInitS(&device->name, i->description);
1919
ffStrbufTrimRightSpace(&device->name);
2020
ffStrbufTrimLeft(&device->name, ' ');
21-
device->volume = i->mute ? 0 : (uint8_t) (i->volume.values[0] * 100 / PA_VOLUME_NORM);
21+
device->volume = i->mute ? 0 : (uint8_t) ((i->volume.values[0] * 100 + PA_VOLUME_NORM / 2 /*round*/) / PA_VOLUME_NORM);
2222
device->active = i->active_port && i->active_port->available != PA_PORT_AVAILABLE_NO;
2323
device->main = false;
2424
}

src/detection/sound/sound_nbsd.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,7 @@ const char* ffDetectSound(FFlist* devices)
4141
ffStrbufInitS(&device->name, ad.name);
4242
ffStrbufTrimRightSpace(&device->name);
4343
ffStrbufInitF(&device->platformApi, "%s", "SunAudio");
44-
device->volume = (uint8_t) (ai.play.gain * 100 / AUDIO_MAX_GAIN);
44+
device->volume = (uint8_t) ((ai.play.gain * 100 + AUDIO_MAX_GAIN / 2) / AUDIO_MAX_GAIN);
4545
device->active = true;
4646
device->main = defaultDev == idev;
4747
}

src/detection/sound/sound_obsd.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -80,7 +80,7 @@ const char* ffDetectSound(FFlist* devices)
8080
if (!bundle.mute[i])
8181
totalLevel += bundle.level[i];
8282
}
83-
device->volume = (uint8_t) (totalLevel * 100 / bundle.iLevel);
83+
device->volume = (uint8_t) ((totalLevel * 100 + bundle.iLevel / 2) / bundle.iLevel);
8484

8585
return NULL;
8686
}

0 commit comments

Comments
 (0)