mirror of
https://github.com/ppy/osu.git
synced 2024-11-11 11:28:00 +08:00
Improve silence detection in MutedNotification
Instead of checking the master and music volumes separately to see if they're <= 1%, check the aggregate of the two volumes to see if it's <= -60 dB. When muted notification is activated, restore the aggregate volume level to -30 dB.
This commit is contained in:
parent
7cdedfb6ca
commit
dfd966e039
@ -264,15 +264,23 @@ namespace osu.Game.Tests.Visual.Gameplay
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void TestMutedNotificationMasterVolume()
|
||||
public void TestMutedNotificationHighMasterVolume()
|
||||
{
|
||||
addVolumeSteps("master volume", () => audioManager.Volume.Value = 0, () => audioManager.Volume.Value == 0.5);
|
||||
addVolumeSteps("high master volume", () =>
|
||||
{
|
||||
audioManager.Volume.Value = 0.1;
|
||||
audioManager.VolumeTrack.Value = 0.01;
|
||||
}, () => audioManager.Volume.Value == 0.1 && audioManager.VolumeTrack.Value == 0.32);
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void TestMutedNotificationTrackVolume()
|
||||
public void TestMutedNotificationLowMasterVolume()
|
||||
{
|
||||
addVolumeSteps("music volume", () => audioManager.VolumeTrack.Value = 0, () => audioManager.VolumeTrack.Value == 0.5);
|
||||
addVolumeSteps("low master volume", () =>
|
||||
{
|
||||
audioManager.Volume.Value = 0.01;
|
||||
audioManager.VolumeTrack.Value = 0.1;
|
||||
}, () => audioManager.Volume.Value == 0.03 && audioManager.VolumeTrack.Value == 1);
|
||||
}
|
||||
|
||||
[Test]
|
||||
|
@ -544,14 +544,14 @@ namespace osu.Game.Screens.Play
|
||||
|
||||
private int restartCount;
|
||||
|
||||
private const double volume_requirement = 0.01;
|
||||
private const double volume_requirement = 1e-3; // -60 dB
|
||||
|
||||
private void showMuteWarningIfNeeded()
|
||||
{
|
||||
if (!muteWarningShownOnce.Value)
|
||||
{
|
||||
// Checks if the notification has not been shown yet and also if master volume is muted, track/music volume is muted or if the whole game is muted.
|
||||
if (volumeOverlay?.IsMuted.Value == true || audioManager.Volume.Value <= volume_requirement || audioManager.VolumeTrack.Value <= volume_requirement)
|
||||
if (volumeOverlay?.IsMuted.Value == true || audioManager.Volume.Value * audioManager.VolumeTrack.Value <= volume_requirement)
|
||||
{
|
||||
notificationOverlay?.Post(new MutedNotification());
|
||||
muteWarningShownOnce.Value = true;
|
||||
@ -581,11 +581,20 @@ namespace osu.Game.Screens.Play
|
||||
volumeOverlay.IsMuted.Value = false;
|
||||
|
||||
// Check values before resetting, as the user may have only had mute enabled, in which case we might not need to adjust volumes.
|
||||
// Note that we only restore halfway to ensure the user isn't suddenly overloaded by unexpectedly high volume.
|
||||
if (audioManager.Volume.Value <= volume_requirement)
|
||||
audioManager.Volume.Value = 0.5f;
|
||||
if (audioManager.VolumeTrack.Value <= volume_requirement)
|
||||
audioManager.VolumeTrack.Value = 0.5f;
|
||||
// Note that we only restore to -30 dB to ensure the user isn't suddenly overloaded by unexpectedly high volume.
|
||||
if (audioManager.Volume.Value * audioManager.VolumeTrack.Value <= volume_requirement)
|
||||
{
|
||||
// Prioritize increasing music over master volume as to avoid also increasing effects volume.
|
||||
const double target = 0.031622776601684; // 10 ^ (-30 / 20)
|
||||
double result = target / Math.Max(0.01, audioManager.Volume.Value);
|
||||
if (result > 1)
|
||||
{
|
||||
audioManager.Volume.Value = target;
|
||||
audioManager.VolumeTrack.Value = 1;
|
||||
}
|
||||
else
|
||||
audioManager.VolumeTrack.Value = result;
|
||||
}
|
||||
|
||||
return true;
|
||||
};
|
||||
|
Loading…
Reference in New Issue
Block a user