1
0
mirror of https://github.com/ppy/osu.git synced 2025-01-12 17:35:10 +08:00

Merge pull request #26951 from myQwil/mute_detection

Improve silence detection in `MutedNotification`
This commit is contained in:
Salman Ahmed 2024-02-16 23:49:54 +03:00 committed by GitHub
commit 4bbb1bc67e
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
2 changed files with 21 additions and 11 deletions

View File

@ -264,15 +264,23 @@ namespace osu.Game.Tests.Visual.Gameplay
}
[Test]
public void TestMutedNotificationMasterVolume()
public void TestMutedNotificationLowMusicVolume()
{
addVolumeSteps("master volume", () => audioManager.Volume.Value = 0, () => audioManager.Volume.Value == 0.5);
addVolumeSteps("master and music volumes", () =>
{
audioManager.Volume.Value = 0.6;
audioManager.VolumeTrack.Value = 0.01;
}, () => Precision.AlmostEquals(audioManager.Volume.Value, 0.6) && Precision.AlmostEquals(audioManager.VolumeTrack.Value, 0.5));
}
[Test]
public void TestMutedNotificationTrackVolume()
public void TestMutedNotificationLowMasterVolume()
{
addVolumeSteps("music volume", () => audioManager.VolumeTrack.Value = 0, () => audioManager.VolumeTrack.Value == 0.5);
addVolumeSteps("master and music volumes", () =>
{
audioManager.Volume.Value = 0.01;
audioManager.VolumeTrack.Value = 0.6;
}, () => Precision.AlmostEquals(audioManager.Volume.Value, 0.5) && Precision.AlmostEquals(audioManager.VolumeTrack.Value, 0.6));
}
[Test]
@ -281,9 +289,10 @@ namespace osu.Game.Tests.Visual.Gameplay
addVolumeSteps("mute button", () =>
{
// Importantly, in the case the volume is muted but the user has a volume level set, it should be retained.
audioManager.VolumeTrack.Value = 0.5f;
audioManager.Volume.Value = 0.5;
audioManager.VolumeTrack.Value = 0.5;
volumeOverlay.IsMuted.Value = true;
}, () => !volumeOverlay.IsMuted.Value && audioManager.VolumeTrack.Value == 0.5f);
}, () => !volumeOverlay.IsMuted.Value && audioManager.Volume.Value == 0.5 && audioManager.VolumeTrack.Value == 0.5);
}
/// <remarks>

View File

@ -15,6 +15,7 @@ using osu.Framework.Graphics.Transforms;
using osu.Framework.Input;
using osu.Framework.Screens;
using osu.Framework.Threading;
using osu.Framework.Utils;
using osu.Game.Audio;
using osu.Game.Audio.Effects;
using osu.Game.Configuration;
@ -550,8 +551,10 @@ namespace osu.Game.Screens.Play
{
if (!muteWarningShownOnce.Value)
{
double aggregateVolumeTrack = audioManager.Volume.Value * audioManager.VolumeTrack.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 || Precision.AlmostBigger(volume_requirement, aggregateVolumeTrack))
{
notificationOverlay?.Post(new MutedNotification());
muteWarningShownOnce.Value = true;
@ -582,10 +585,8 @@ namespace osu.Game.Screens.Play
// 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;
audioManager.Volume.Value = Math.Max(audioManager.Volume.Value, 0.5);
audioManager.VolumeTrack.Value = Math.Max(audioManager.VolumeTrack.Value, 0.5);
return true;
};