From dfd966e039e49a3582b519146440b866ae00705c Mon Sep 17 00:00:00 2001 From: Mike Will Date: Wed, 31 Jan 2024 18:47:47 -0500 Subject: [PATCH 01/20] 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. --- .../Visual/Gameplay/TestScenePlayerLoader.cs | 16 +++++++++---- osu.Game/Screens/Play/PlayerLoader.cs | 23 +++++++++++++------ 2 files changed, 28 insertions(+), 11 deletions(-) diff --git a/osu.Game.Tests/Visual/Gameplay/TestScenePlayerLoader.cs b/osu.Game.Tests/Visual/Gameplay/TestScenePlayerLoader.cs index f97372e9b6..2798d77373 100644 --- a/osu.Game.Tests/Visual/Gameplay/TestScenePlayerLoader.cs +++ b/osu.Game.Tests/Visual/Gameplay/TestScenePlayerLoader.cs @@ -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] diff --git a/osu.Game/Screens/Play/PlayerLoader.cs b/osu.Game/Screens/Play/PlayerLoader.cs index 232de53ac3..6282041f2c 100644 --- a/osu.Game/Screens/Play/PlayerLoader.cs +++ b/osu.Game/Screens/Play/PlayerLoader.cs @@ -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; }; From 3122211268346b9c57e3ea8b96e77090251f06e5 Mon Sep 17 00:00:00 2001 From: Mike Will Date: Fri, 2 Feb 2024 02:12:46 -0500 Subject: [PATCH 02/20] Change silence threshold and target restore volume level --- osu.Game/Screens/Play/PlayerLoader.cs | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/osu.Game/Screens/Play/PlayerLoader.cs b/osu.Game/Screens/Play/PlayerLoader.cs index 6282041f2c..9ec7197429 100644 --- a/osu.Game/Screens/Play/PlayerLoader.cs +++ b/osu.Game/Screens/Play/PlayerLoader.cs @@ -544,7 +544,7 @@ namespace osu.Game.Screens.Play private int restartCount; - private const double volume_requirement = 1e-3; // -60 dB + private const double volume_requirement = 0.01; private void showMuteWarningIfNeeded() { @@ -581,11 +581,11 @@ 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 to -30 dB to ensure the user isn't suddenly overloaded by unexpectedly high volume. + // Note that we only restore to -20 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) + const double target = 0.1; double result = target / Math.Max(0.01, audioManager.Volume.Value); if (result > 1) { From f4a2d5f3f489c1332f7e200747dd9b665337db7a Mon Sep 17 00:00:00 2001 From: Mike Will Date: Fri, 2 Feb 2024 02:41:58 -0500 Subject: [PATCH 03/20] Round off inaccuracies in the aggregate volume before evaluating --- osu.Game/Screens/Play/PlayerLoader.cs | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/osu.Game/Screens/Play/PlayerLoader.cs b/osu.Game/Screens/Play/PlayerLoader.cs index 9ec7197429..50c95ce525 100644 --- a/osu.Game/Screens/Play/PlayerLoader.cs +++ b/osu.Game/Screens/Play/PlayerLoader.cs @@ -551,7 +551,8 @@ namespace osu.Game.Screens.Play 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 * audioManager.VolumeTrack.Value <= volume_requirement) + double aggregate = Math.Floor(audioManager.Volume.Value * audioManager.VolumeTrack.Value * 100) / 100; + if (volumeOverlay?.IsMuted.Value == true || aggregate <= volume_requirement) { notificationOverlay?.Post(new MutedNotification()); muteWarningShownOnce.Value = true; @@ -582,7 +583,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 to -20 dB to ensure the user isn't suddenly overloaded by unexpectedly high volume. - if (audioManager.Volume.Value * audioManager.VolumeTrack.Value <= volume_requirement) + double aggregate = Math.Floor(audioManager.Volume.Value * audioManager.VolumeTrack.Value * 100) / 100; + if (aggregate <= volume_requirement) { // Prioritize increasing music over master volume as to avoid also increasing effects volume. const double target = 0.1; From 5d9200b4fe02c4ed0f287fe0f43c5f2433b52ec9 Mon Sep 17 00:00:00 2001 From: Mike Will Date: Fri, 2 Feb 2024 02:59:02 -0500 Subject: [PATCH 04/20] Update tests to reflect new restore target volume --- osu.Game.Tests/Visual/Gameplay/TestScenePlayerLoader.cs | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/osu.Game.Tests/Visual/Gameplay/TestScenePlayerLoader.cs b/osu.Game.Tests/Visual/Gameplay/TestScenePlayerLoader.cs index 2798d77373..99bb006071 100644 --- a/osu.Game.Tests/Visual/Gameplay/TestScenePlayerLoader.cs +++ b/osu.Game.Tests/Visual/Gameplay/TestScenePlayerLoader.cs @@ -268,9 +268,9 @@ namespace osu.Game.Tests.Visual.Gameplay { addVolumeSteps("high master volume", () => { - audioManager.Volume.Value = 0.1; + audioManager.Volume.Value = 0.15; audioManager.VolumeTrack.Value = 0.01; - }, () => audioManager.Volume.Value == 0.1 && audioManager.VolumeTrack.Value == 0.32); + }, () => audioManager.Volume.Value == 0.15 && audioManager.VolumeTrack.Value == 0.67); } [Test] @@ -279,8 +279,8 @@ namespace osu.Game.Tests.Visual.Gameplay addVolumeSteps("low master volume", () => { audioManager.Volume.Value = 0.01; - audioManager.VolumeTrack.Value = 0.1; - }, () => audioManager.Volume.Value == 0.03 && audioManager.VolumeTrack.Value == 1); + audioManager.VolumeTrack.Value = 0.15; + }, () => audioManager.Volume.Value == 0.1 && audioManager.VolumeTrack.Value == 1); } [Test] From c60e110976ca7214c200d90da45bdd165cb0b39c Mon Sep 17 00:00:00 2001 From: Mike Will Date: Fri, 2 Feb 2024 03:09:19 -0500 Subject: [PATCH 05/20] Try to fix code quality issues raised by workflow --- osu.Game/Screens/Play/PlayerLoader.cs | 9 ++++----- 1 file changed, 4 insertions(+), 5 deletions(-) diff --git a/osu.Game/Screens/Play/PlayerLoader.cs b/osu.Game/Screens/Play/PlayerLoader.cs index 50c95ce525..1d0ecfc12d 100644 --- a/osu.Game/Screens/Play/PlayerLoader.cs +++ b/osu.Game/Screens/Play/PlayerLoader.cs @@ -551,8 +551,7 @@ namespace osu.Game.Screens.Play 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. - double aggregate = Math.Floor(audioManager.Volume.Value * audioManager.VolumeTrack.Value * 100) / 100; - if (volumeOverlay?.IsMuted.Value == true || aggregate <= volume_requirement) + if (volumeOverlay?.IsMuted.Value == true || Math.Floor(audioManager.Volume.Value * audioManager.VolumeTrack.Value * 100) / 100 <= volume_requirement) { notificationOverlay?.Post(new MutedNotification()); muteWarningShownOnce.Value = true; @@ -583,11 +582,11 @@ 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 to -20 dB to ensure the user isn't suddenly overloaded by unexpectedly high volume. - double aggregate = Math.Floor(audioManager.Volume.Value * audioManager.VolumeTrack.Value * 100) / 100; - if (aggregate <= volume_requirement) + if (Math.Floor(audioManager.Volume.Value * audioManager.VolumeTrack.Value * 100) / 100 <= volume_requirement) { - // Prioritize increasing music over master volume as to avoid also increasing effects volume. const double target = 0.1; + + // Prioritize increasing music over master volume as to avoid also increasing effects volume. double result = target / Math.Max(0.01, audioManager.Volume.Value); if (result > 1) { From 29a28905820bb1242cda326a2e4610e058bef1c2 Mon Sep 17 00:00:00 2001 From: Mike Will Date: Fri, 2 Feb 2024 03:46:05 -0500 Subject: [PATCH 06/20] fix code quality error #2 --- osu.Game/Screens/Play/PlayerLoader.cs | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/osu.Game/Screens/Play/PlayerLoader.cs b/osu.Game/Screens/Play/PlayerLoader.cs index 1d0ecfc12d..40ffa844da 100644 --- a/osu.Game/Screens/Play/PlayerLoader.cs +++ b/osu.Game/Screens/Play/PlayerLoader.cs @@ -584,10 +584,10 @@ namespace osu.Game.Screens.Play // Note that we only restore to -20 dB to ensure the user isn't suddenly overloaded by unexpectedly high volume. if (Math.Floor(audioManager.Volume.Value * audioManager.VolumeTrack.Value * 100) / 100 <= volume_requirement) { - const double target = 0.1; - // Prioritize increasing music over master volume as to avoid also increasing effects volume. + const double target = 0.1; double result = target / Math.Max(0.01, audioManager.Volume.Value); + if (result > 1) { audioManager.Volume.Value = target; From 906560f66d971778ab8ec00866b3aa3d0afb8caa Mon Sep 17 00:00:00 2001 From: Mike Will Date: Fri, 2 Feb 2024 04:06:22 -0500 Subject: [PATCH 07/20] Fix mute button test Lowering the master volume in the previous test meant that the volume levels would end up being modified. --- osu.Game.Tests/Visual/Gameplay/TestScenePlayerLoader.cs | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/osu.Game.Tests/Visual/Gameplay/TestScenePlayerLoader.cs b/osu.Game.Tests/Visual/Gameplay/TestScenePlayerLoader.cs index 99bb006071..04b681989f 100644 --- a/osu.Game.Tests/Visual/Gameplay/TestScenePlayerLoader.cs +++ b/osu.Game.Tests/Visual/Gameplay/TestScenePlayerLoader.cs @@ -289,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.Volume.Value = 0.5f; audioManager.VolumeTrack.Value = 0.5f; volumeOverlay.IsMuted.Value = true; - }, () => !volumeOverlay.IsMuted.Value && audioManager.VolumeTrack.Value == 0.5f); + }, () => !volumeOverlay.IsMuted.Value && audioManager.Volume.Value == 0.5f && audioManager.VolumeTrack.Value == 0.5f); } /// From e4ec8c111b90542c8705e73eaabca6bf9557f63f Mon Sep 17 00:00:00 2001 From: Mike Will Date: Fri, 2 Feb 2024 05:48:57 -0500 Subject: [PATCH 08/20] give better volume names to `addVolumeSteps` --- osu.Game.Tests/Visual/Gameplay/TestScenePlayerLoader.cs | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/osu.Game.Tests/Visual/Gameplay/TestScenePlayerLoader.cs b/osu.Game.Tests/Visual/Gameplay/TestScenePlayerLoader.cs index 04b681989f..67e94a2960 100644 --- a/osu.Game.Tests/Visual/Gameplay/TestScenePlayerLoader.cs +++ b/osu.Game.Tests/Visual/Gameplay/TestScenePlayerLoader.cs @@ -266,7 +266,7 @@ namespace osu.Game.Tests.Visual.Gameplay [Test] public void TestMutedNotificationHighMasterVolume() { - addVolumeSteps("high master volume", () => + addVolumeSteps("master and music volumes", () => { audioManager.Volume.Value = 0.15; audioManager.VolumeTrack.Value = 0.01; @@ -276,7 +276,7 @@ namespace osu.Game.Tests.Visual.Gameplay [Test] public void TestMutedNotificationLowMasterVolume() { - addVolumeSteps("low master volume", () => + addVolumeSteps("master and music volumes", () => { audioManager.Volume.Value = 0.01; audioManager.VolumeTrack.Value = 0.15; From 2ab967f783fd25d95e9142bffb79eb78e03e7cbc Mon Sep 17 00:00:00 2001 From: Mike Will Date: Fri, 2 Feb 2024 13:27:26 -0500 Subject: [PATCH 09/20] Increase precision of aggregate volume rounding It should be large enough to account for true accuracy but small enough to disregard any hair-thin inaccuracy found at the very end of the float value. --- osu.Game/Screens/Play/PlayerLoader.cs | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/osu.Game/Screens/Play/PlayerLoader.cs b/osu.Game/Screens/Play/PlayerLoader.cs index 40ffa844da..aafa93c122 100644 --- a/osu.Game/Screens/Play/PlayerLoader.cs +++ b/osu.Game/Screens/Play/PlayerLoader.cs @@ -551,7 +551,7 @@ namespace osu.Game.Screens.Play 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 || Math.Floor(audioManager.Volume.Value * audioManager.VolumeTrack.Value * 100) / 100 <= volume_requirement) + if (volumeOverlay?.IsMuted.Value == true || Math.Floor(audioManager.Volume.Value * audioManager.VolumeTrack.Value * 1e6) / 1e6 <= volume_requirement) { notificationOverlay?.Post(new MutedNotification()); muteWarningShownOnce.Value = true; @@ -582,7 +582,7 @@ 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 to -20 dB to ensure the user isn't suddenly overloaded by unexpectedly high volume. - if (Math.Floor(audioManager.Volume.Value * audioManager.VolumeTrack.Value * 100) / 100 <= volume_requirement) + if (Math.Floor(audioManager.Volume.Value * audioManager.VolumeTrack.Value * 1e6) / 1e6 <= volume_requirement) { // Prioritize increasing music over master volume as to avoid also increasing effects volume. const double target = 0.1; From 9a5348598af58008e0c22897964f81bf27d34ee0 Mon Sep 17 00:00:00 2001 From: Mike Will Date: Fri, 2 Feb 2024 14:22:24 -0500 Subject: [PATCH 10/20] Replace aggregate rounding method with a float cast --- osu.Game/Screens/Play/PlayerLoader.cs | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/osu.Game/Screens/Play/PlayerLoader.cs b/osu.Game/Screens/Play/PlayerLoader.cs index aafa93c122..6154e443ef 100644 --- a/osu.Game/Screens/Play/PlayerLoader.cs +++ b/osu.Game/Screens/Play/PlayerLoader.cs @@ -551,7 +551,7 @@ namespace osu.Game.Screens.Play 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 || Math.Floor(audioManager.Volume.Value * audioManager.VolumeTrack.Value * 1e6) / 1e6 <= volume_requirement) + if (volumeOverlay?.IsMuted.Value == true || (float)(audioManager.Volume.Value * audioManager.VolumeTrack.Value) <= volume_requirement) { notificationOverlay?.Post(new MutedNotification()); muteWarningShownOnce.Value = true; @@ -582,7 +582,7 @@ 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 to -20 dB to ensure the user isn't suddenly overloaded by unexpectedly high volume. - if (Math.Floor(audioManager.Volume.Value * audioManager.VolumeTrack.Value * 1e6) / 1e6 <= volume_requirement) + if ((float)(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.1; From a9eac5924de12073d39e8c9b2b57f83be6185de2 Mon Sep 17 00:00:00 2001 From: Salman Ahmed Date: Fri, 16 Feb 2024 01:18:13 +0300 Subject: [PATCH 11/20] Remove seemingly unnecessary float casts --- osu.Game/Screens/Play/PlayerLoader.cs | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/osu.Game/Screens/Play/PlayerLoader.cs b/osu.Game/Screens/Play/PlayerLoader.cs index 6154e443ef..fff1118622 100644 --- a/osu.Game/Screens/Play/PlayerLoader.cs +++ b/osu.Game/Screens/Play/PlayerLoader.cs @@ -550,8 +550,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 || (float)(audioManager.Volume.Value * audioManager.VolumeTrack.Value) <= volume_requirement) + if (volumeOverlay?.IsMuted.Value == true || aggregateVolumeTrack <= volume_requirement) { notificationOverlay?.Post(new MutedNotification()); muteWarningShownOnce.Value = true; @@ -580,9 +582,11 @@ namespace osu.Game.Screens.Play volumeOverlay.IsMuted.Value = false; + double aggregateVolumeTrack = audioManager.Volume.Value * audioManager.VolumeTrack.Value; + // 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 to -20 dB to ensure the user isn't suddenly overloaded by unexpectedly high volume. - if ((float)(audioManager.Volume.Value * audioManager.VolumeTrack.Value) <= volume_requirement) + if (aggregateVolumeTrack <= volume_requirement) { // Prioritize increasing music over master volume as to avoid also increasing effects volume. const double target = 0.1; From d81b148b099e56f1a9ff8d7a20d282e7b970d7a9 Mon Sep 17 00:00:00 2001 From: Salman Ahmed Date: Fri, 16 Feb 2024 01:23:18 +0300 Subject: [PATCH 12/20] Remove mention of decibel units in comment Decibels are irrelevant in the volume bindables, as mentioned in PR already. --- osu.Game/Screens/Play/PlayerLoader.cs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/osu.Game/Screens/Play/PlayerLoader.cs b/osu.Game/Screens/Play/PlayerLoader.cs index fff1118622..c755923ace 100644 --- a/osu.Game/Screens/Play/PlayerLoader.cs +++ b/osu.Game/Screens/Play/PlayerLoader.cs @@ -585,7 +585,7 @@ namespace osu.Game.Screens.Play double aggregateVolumeTrack = audioManager.Volume.Value * audioManager.VolumeTrack.Value; // 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 to -20 dB to ensure the user isn't suddenly overloaded by unexpectedly high volume. + // Note that we only restore to 10% to ensure the user isn't suddenly overloaded by unexpectedly high volume. if (aggregateVolumeTrack <= volume_requirement) { // Prioritize increasing music over master volume as to avoid also increasing effects volume. From 5431781f80692d8fc36a5a301126148b00ca916c Mon Sep 17 00:00:00 2001 From: Salman Ahmed Date: Fri, 16 Feb 2024 01:23:26 +0300 Subject: [PATCH 13/20] Bring back target volume to 50% --- osu.Game/Screens/Play/PlayerLoader.cs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/osu.Game/Screens/Play/PlayerLoader.cs b/osu.Game/Screens/Play/PlayerLoader.cs index c755923ace..d3f75fe15e 100644 --- a/osu.Game/Screens/Play/PlayerLoader.cs +++ b/osu.Game/Screens/Play/PlayerLoader.cs @@ -589,7 +589,7 @@ namespace osu.Game.Screens.Play if (aggregateVolumeTrack <= volume_requirement) { // Prioritize increasing music over master volume as to avoid also increasing effects volume. - const double target = 0.1; + const double target = 0.5; double result = target / Math.Max(0.01, audioManager.Volume.Value); if (result > 1) From 6751f95eb648b42cdb55baa83efcb07a757ea9a7 Mon Sep 17 00:00:00 2001 From: Salman Ahmed Date: Fri, 16 Feb 2024 01:28:47 +0300 Subject: [PATCH 14/20] Adjust test cases and approximate equality --- osu.Game.Tests/Visual/Gameplay/TestScenePlayerLoader.cs | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/osu.Game.Tests/Visual/Gameplay/TestScenePlayerLoader.cs b/osu.Game.Tests/Visual/Gameplay/TestScenePlayerLoader.cs index 67e94a2960..02a0ae6e6c 100644 --- a/osu.Game.Tests/Visual/Gameplay/TestScenePlayerLoader.cs +++ b/osu.Game.Tests/Visual/Gameplay/TestScenePlayerLoader.cs @@ -268,9 +268,9 @@ namespace osu.Game.Tests.Visual.Gameplay { addVolumeSteps("master and music volumes", () => { - audioManager.Volume.Value = 0.15; - audioManager.VolumeTrack.Value = 0.01; - }, () => audioManager.Volume.Value == 0.15 && audioManager.VolumeTrack.Value == 0.67); + audioManager.Volume.Value = 0.6; + audioManager.VolumeTrack.Value = 0.15; + }, () => Precision.AlmostEquals(audioManager.Volume.Value, 0.6) && Precision.AlmostEquals(audioManager.VolumeTrack.Value, 0.83)); } [Test] @@ -280,7 +280,7 @@ namespace osu.Game.Tests.Visual.Gameplay { audioManager.Volume.Value = 0.01; audioManager.VolumeTrack.Value = 0.15; - }, () => audioManager.Volume.Value == 0.1 && audioManager.VolumeTrack.Value == 1); + }, () => Precision.AlmostEquals(audioManager.Volume.Value, 0.5) && Precision.AlmostEquals(audioManager.VolumeTrack.Value, 1)); } [Test] From 7530b1f362451eb18e6fcfaceb5154f4bddddac6 Mon Sep 17 00:00:00 2001 From: Salman Ahmed Date: Fri, 16 Feb 2024 01:31:52 +0300 Subject: [PATCH 15/20] Adjust comment again --- osu.Game/Screens/Play/PlayerLoader.cs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/osu.Game/Screens/Play/PlayerLoader.cs b/osu.Game/Screens/Play/PlayerLoader.cs index d3f75fe15e..060074890c 100644 --- a/osu.Game/Screens/Play/PlayerLoader.cs +++ b/osu.Game/Screens/Play/PlayerLoader.cs @@ -585,7 +585,7 @@ namespace osu.Game.Screens.Play double aggregateVolumeTrack = audioManager.Volume.Value * audioManager.VolumeTrack.Value; // 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 to 10% to ensure the user isn't suddenly overloaded by unexpectedly high volume. + // Note that we only restore halfway to ensure the user isn't suddenly overloaded by unexpectedly high volume. if (aggregateVolumeTrack <= volume_requirement) { // Prioritize increasing music over master volume as to avoid also increasing effects volume. From 22dafd8e9c0b4622c37a263cfbeab788312f09e4 Mon Sep 17 00:00:00 2001 From: Mike Will Date: Thu, 15 Feb 2024 18:56:09 -0500 Subject: [PATCH 16/20] fix typo --- osu.Game.Tests/Visual/Gameplay/TestScenePlayerLoader.cs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/osu.Game.Tests/Visual/Gameplay/TestScenePlayerLoader.cs b/osu.Game.Tests/Visual/Gameplay/TestScenePlayerLoader.cs index 02a0ae6e6c..702912ef45 100644 --- a/osu.Game.Tests/Visual/Gameplay/TestScenePlayerLoader.cs +++ b/osu.Game.Tests/Visual/Gameplay/TestScenePlayerLoader.cs @@ -269,7 +269,7 @@ namespace osu.Game.Tests.Visual.Gameplay addVolumeSteps("master and music volumes", () => { audioManager.Volume.Value = 0.6; - audioManager.VolumeTrack.Value = 0.15; + audioManager.VolumeTrack.Value = 0.01; }, () => Precision.AlmostEquals(audioManager.Volume.Value, 0.6) && Precision.AlmostEquals(audioManager.VolumeTrack.Value, 0.83)); } From 9f53185fa99558f2475052febd3e6218eaadf15b Mon Sep 17 00:00:00 2001 From: Salman Ahmed Date: Fri, 16 Feb 2024 10:47:56 +0300 Subject: [PATCH 17/20] Revert changes to muted notification action --- osu.Game/Screens/Play/PlayerLoader.cs | 20 ++++---------------- 1 file changed, 4 insertions(+), 16 deletions(-) diff --git a/osu.Game/Screens/Play/PlayerLoader.cs b/osu.Game/Screens/Play/PlayerLoader.cs index 060074890c..11e6528ba9 100644 --- a/osu.Game/Screens/Play/PlayerLoader.cs +++ b/osu.Game/Screens/Play/PlayerLoader.cs @@ -582,24 +582,12 @@ namespace osu.Game.Screens.Play volumeOverlay.IsMuted.Value = false; - double aggregateVolumeTrack = audioManager.Volume.Value * audioManager.VolumeTrack.Value; - // 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 (aggregateVolumeTrack <= volume_requirement) - { - // Prioritize increasing music over master volume as to avoid also increasing effects volume. - const double target = 0.5; - 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; - } + if (audioManager.Volume.Value <= volume_requirement) + audioManager.Volume.Value = 0.5; + if (audioManager.VolumeTrack.Value <= volume_requirement) + audioManager.VolumeTrack.Value = 0.5; return true; }; From 6a1d118b21be6bb1f5c2cac38e6f9708c68b1bd6 Mon Sep 17 00:00:00 2001 From: Salman Ahmed Date: Fri, 16 Feb 2024 10:52:27 +0300 Subject: [PATCH 18/20] Adjust tests again --- .../Visual/Gameplay/TestScenePlayerLoader.cs | 16 ++++++++-------- 1 file changed, 8 insertions(+), 8 deletions(-) diff --git a/osu.Game.Tests/Visual/Gameplay/TestScenePlayerLoader.cs b/osu.Game.Tests/Visual/Gameplay/TestScenePlayerLoader.cs index 702912ef45..6eb2532d45 100644 --- a/osu.Game.Tests/Visual/Gameplay/TestScenePlayerLoader.cs +++ b/osu.Game.Tests/Visual/Gameplay/TestScenePlayerLoader.cs @@ -264,13 +264,13 @@ namespace osu.Game.Tests.Visual.Gameplay } [Test] - public void TestMutedNotificationHighMasterVolume() + public void TestMutedNotificationLowMusicVolume() { addVolumeSteps("master and music volumes", () => { - audioManager.Volume.Value = 0.6; + audioManager.Volume.Value = 0.25; audioManager.VolumeTrack.Value = 0.01; - }, () => Precision.AlmostEquals(audioManager.Volume.Value, 0.6) && Precision.AlmostEquals(audioManager.VolumeTrack.Value, 0.83)); + }, () => Precision.AlmostEquals(audioManager.Volume.Value, 0.25) && Precision.AlmostEquals(audioManager.VolumeTrack.Value, 0.5)); } [Test] @@ -279,8 +279,8 @@ namespace osu.Game.Tests.Visual.Gameplay addVolumeSteps("master and music volumes", () => { audioManager.Volume.Value = 0.01; - audioManager.VolumeTrack.Value = 0.15; - }, () => Precision.AlmostEquals(audioManager.Volume.Value, 0.5) && Precision.AlmostEquals(audioManager.VolumeTrack.Value, 1)); + audioManager.VolumeTrack.Value = 0.25; + }, () => Precision.AlmostEquals(audioManager.Volume.Value, 0.5) && Precision.AlmostEquals(audioManager.VolumeTrack.Value, 0.25)); } [Test] @@ -289,10 +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.Volume.Value = 0.5f; - audioManager.VolumeTrack.Value = 0.5f; + audioManager.Volume.Value = 0.5; + audioManager.VolumeTrack.Value = 0.5; volumeOverlay.IsMuted.Value = true; - }, () => !volumeOverlay.IsMuted.Value && audioManager.Volume.Value == 0.5f && audioManager.VolumeTrack.Value == 0.5f); + }, () => !volumeOverlay.IsMuted.Value && audioManager.Volume.Value == 0.5 && audioManager.VolumeTrack.Value == 0.5); } /// From 952c5b0d189e5b8a5e2b0490b8788dffdd1db1bf Mon Sep 17 00:00:00 2001 From: Salman Ahmed Date: Fri, 16 Feb 2024 11:13:41 +0300 Subject: [PATCH 19/20] Use `Precision.AlmostBigger` --- osu.Game/Screens/Play/PlayerLoader.cs | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/osu.Game/Screens/Play/PlayerLoader.cs b/osu.Game/Screens/Play/PlayerLoader.cs index 11e6528ba9..8b167dfb3a 100644 --- a/osu.Game/Screens/Play/PlayerLoader.cs +++ b/osu.Game/Screens/Play/PlayerLoader.cs @@ -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; @@ -553,7 +554,7 @@ namespace osu.Game.Screens.Play 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 || aggregateVolumeTrack <= volume_requirement) + if (volumeOverlay?.IsMuted.Value == true || Precision.AlmostBigger(volume_requirement, aggregateVolumeTrack)) { notificationOverlay?.Post(new MutedNotification()); muteWarningShownOnce.Value = true; From 583e71634f309ce5e7d56ffcd2796644ad981c4b Mon Sep 17 00:00:00 2001 From: Salman Ahmed Date: Fri, 16 Feb 2024 11:17:54 +0300 Subject: [PATCH 20/20] Always bring master/music volume to 50% --- osu.Game.Tests/Visual/Gameplay/TestScenePlayerLoader.cs | 8 ++++---- osu.Game/Screens/Play/PlayerLoader.cs | 6 ++---- 2 files changed, 6 insertions(+), 8 deletions(-) diff --git a/osu.Game.Tests/Visual/Gameplay/TestScenePlayerLoader.cs b/osu.Game.Tests/Visual/Gameplay/TestScenePlayerLoader.cs index 6eb2532d45..c6827d4197 100644 --- a/osu.Game.Tests/Visual/Gameplay/TestScenePlayerLoader.cs +++ b/osu.Game.Tests/Visual/Gameplay/TestScenePlayerLoader.cs @@ -268,9 +268,9 @@ namespace osu.Game.Tests.Visual.Gameplay { addVolumeSteps("master and music volumes", () => { - audioManager.Volume.Value = 0.25; + audioManager.Volume.Value = 0.6; audioManager.VolumeTrack.Value = 0.01; - }, () => Precision.AlmostEquals(audioManager.Volume.Value, 0.25) && Precision.AlmostEquals(audioManager.VolumeTrack.Value, 0.5)); + }, () => Precision.AlmostEquals(audioManager.Volume.Value, 0.6) && Precision.AlmostEquals(audioManager.VolumeTrack.Value, 0.5)); } [Test] @@ -279,8 +279,8 @@ namespace osu.Game.Tests.Visual.Gameplay addVolumeSteps("master and music volumes", () => { audioManager.Volume.Value = 0.01; - audioManager.VolumeTrack.Value = 0.25; - }, () => Precision.AlmostEquals(audioManager.Volume.Value, 0.5) && Precision.AlmostEquals(audioManager.VolumeTrack.Value, 0.25)); + audioManager.VolumeTrack.Value = 0.6; + }, () => Precision.AlmostEquals(audioManager.Volume.Value, 0.5) && Precision.AlmostEquals(audioManager.VolumeTrack.Value, 0.6)); } [Test] diff --git a/osu.Game/Screens/Play/PlayerLoader.cs b/osu.Game/Screens/Play/PlayerLoader.cs index 8b167dfb3a..aa62256348 100644 --- a/osu.Game/Screens/Play/PlayerLoader.cs +++ b/osu.Game/Screens/Play/PlayerLoader.cs @@ -585,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.5; - if (audioManager.VolumeTrack.Value <= volume_requirement) - audioManager.VolumeTrack.Value = 0.5; + audioManager.Volume.Value = Math.Max(audioManager.Volume.Value, 0.5); + audioManager.VolumeTrack.Value = Math.Max(audioManager.VolumeTrack.Value, 0.5); return true; };