From e3105fd4c80caec86c086e66b5bad55d2f5d29c5 Mon Sep 17 00:00:00 2001 From: Dean Herbert Date: Thu, 6 Aug 2020 19:16:26 +0900 Subject: [PATCH 1/3] Add more resilient logic for whether to avoid playing SkinnableSound on no volume --- .../Objects/Drawables/DrawableSpinner.cs | 6 ++---- osu.Game/Screens/Play/PauseOverlay.cs | 8 ++------ osu.Game/Skinning/SkinnableSound.cs | 12 +++++++++++- 3 files changed, 15 insertions(+), 11 deletions(-) diff --git a/osu.Game.Rulesets.Osu/Objects/Drawables/DrawableSpinner.cs b/osu.Game.Rulesets.Osu/Objects/Drawables/DrawableSpinner.cs index 7363da0de8..b74a9c7197 100644 --- a/osu.Game.Rulesets.Osu/Objects/Drawables/DrawableSpinner.cs +++ b/osu.Game.Rulesets.Osu/Objects/Drawables/DrawableSpinner.cs @@ -82,8 +82,6 @@ namespace osu.Game.Rulesets.Osu.Objects.Drawables private SkinnableSound spinningSample; - private const float minimum_volume = 0.0001f; - protected override void LoadSamples() { base.LoadSamples(); @@ -100,7 +98,7 @@ namespace osu.Game.Rulesets.Osu.Objects.Drawables AddInternal(spinningSample = new SkinnableSound(clone) { - Volume = { Value = minimum_volume }, + Volume = { Value = 0 }, Looping = true, }); } @@ -118,7 +116,7 @@ namespace osu.Game.Rulesets.Osu.Objects.Drawables } else { - spinningSample?.VolumeTo(minimum_volume, 200).Finally(_ => spinningSample.Stop()); + spinningSample?.VolumeTo(0, 200).Finally(_ => spinningSample.Stop()); } } diff --git a/osu.Game/Screens/Play/PauseOverlay.cs b/osu.Game/Screens/Play/PauseOverlay.cs index fa917cda32..3cdc558951 100644 --- a/osu.Game/Screens/Play/PauseOverlay.cs +++ b/osu.Game/Screens/Play/PauseOverlay.cs @@ -25,8 +25,6 @@ namespace osu.Game.Screens.Play protected override Action BackAction => () => InternalButtons.Children.First().Click(); - private const float minimum_volume = 0.0001f; - [BackgroundDependencyLoader] private void load(OsuColour colours) { @@ -37,10 +35,8 @@ namespace osu.Game.Screens.Play AddInternal(pauseLoop = new SkinnableSound(new SampleInfo("pause-loop")) { Looping = true, + Volume = { Value = 0 } }); - - // SkinnableSound only plays a sound if its aggregate volume is > 0, so the volume must be turned up before playing it - pauseLoop.VolumeTo(minimum_volume); } protected override void PopIn() @@ -55,7 +51,7 @@ namespace osu.Game.Screens.Play { base.PopOut(); - pauseLoop.VolumeTo(minimum_volume, TRANSITION_DURATION, Easing.OutQuad).Finally(_ => pauseLoop.Stop()); + pauseLoop.VolumeTo(0, TRANSITION_DURATION, Easing.OutQuad).Finally(_ => pauseLoop.Stop()); } } } diff --git a/osu.Game/Skinning/SkinnableSound.cs b/osu.Game/Skinning/SkinnableSound.cs index 27f6c37895..8c18e83e92 100644 --- a/osu.Game/Skinning/SkinnableSound.cs +++ b/osu.Game/Skinning/SkinnableSound.cs @@ -28,6 +28,16 @@ namespace osu.Game.Skinning public override bool RemoveWhenNotAlive => false; public override bool RemoveCompletedTransforms => false; + /// + /// Whether to play the underlying sample when aggregate volume is zero. + /// Note that this is checked at the point of calling ; changing the volume post-play will not begin playback. + /// Defaults to false unless . + /// + /// + /// Can serve as an optimisation if it is known ahead-of-time that this behaviour will not negatively affect behaviour. + /// + protected bool SkipPlayWhenZeroVolume => !Looping; + private readonly AudioContainer samplesContainer; public SkinnableSound(ISampleInfo hitSamples) @@ -87,7 +97,7 @@ namespace osu.Game.Skinning { samplesContainer.ForEach(c => { - if (c.AggregateVolume.Value > 0) + if (!SkipPlayWhenZeroVolume || c.AggregateVolume.Value > 0) c.Play(); }); } From 1090137da3d46e76f2be85d26dc14a6696393a84 Mon Sep 17 00:00:00 2001 From: Dean Herbert Date: Sat, 8 Aug 2020 23:23:02 +0900 Subject: [PATCH 2/3] Adjust comment to read better MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Co-authored-by: Bartłomiej Dach --- osu.Game/Skinning/SkinnableSound.cs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/osu.Game/Skinning/SkinnableSound.cs b/osu.Game/Skinning/SkinnableSound.cs index 8c18e83e92..7ee0b474de 100644 --- a/osu.Game/Skinning/SkinnableSound.cs +++ b/osu.Game/Skinning/SkinnableSound.cs @@ -34,7 +34,7 @@ namespace osu.Game.Skinning /// Defaults to false unless . /// /// - /// Can serve as an optimisation if it is known ahead-of-time that this behaviour will not negatively affect behaviour. + /// Can serve as an optimisation if it is known ahead-of-time that this behaviour is allowed in a given use case. /// protected bool SkipPlayWhenZeroVolume => !Looping; From ffb2e56a8d31e6b62c3715380967e5b63711b672 Mon Sep 17 00:00:00 2001 From: Dean Herbert Date: Sat, 8 Aug 2020 23:25:52 +0900 Subject: [PATCH 3/3] Reverse direction of bool to make mental parsing easier --- osu.Game/Skinning/SkinnableSound.cs | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/osu.Game/Skinning/SkinnableSound.cs b/osu.Game/Skinning/SkinnableSound.cs index 7739be693d..32f49367f0 100644 --- a/osu.Game/Skinning/SkinnableSound.cs +++ b/osu.Game/Skinning/SkinnableSound.cs @@ -37,7 +37,7 @@ namespace osu.Game.Skinning /// /// Can serve as an optimisation if it is known ahead-of-time that this behaviour is allowed in a given use case. /// - protected bool SkipPlayWhenZeroVolume => !Looping; + protected bool PlayWhenZeroVolume => Looping; private readonly AudioContainer samplesContainer; @@ -98,7 +98,7 @@ namespace osu.Game.Skinning { samplesContainer.ForEach(c => { - if (!SkipPlayWhenZeroVolume || c.AggregateVolume.Value > 0) + if (PlayWhenZeroVolume || c.AggregateVolume.Value > 0) c.Play(); }); }