diff --git a/osu.Game/Audio/Effects/AudioFilter.cs b/osu.Game/Audio/Effects/AudioFilter.cs index bfa9b31242..8db457ae67 100644 --- a/osu.Game/Audio/Effects/AudioFilter.cs +++ b/osu.Game/Audio/Effects/AudioFilter.cs @@ -1,10 +1,8 @@ // Copyright (c) ppy Pty Ltd . Licensed under the MIT Licence. // See the LICENCE file in the repository root for full licence text. -using System.Diagnostics; using ManagedBass.Fx; using osu.Framework.Audio.Mixing; -using osu.Framework.Caching; using osu.Framework.Graphics; namespace osu.Game.Audio.Effects @@ -26,8 +24,6 @@ namespace osu.Game.Audio.Effects private readonly BQFParameters filter; private readonly BQFType type; - private readonly Cached filterApplication = new Cached(); - private int cutoff; /// @@ -42,7 +38,7 @@ namespace osu.Game.Audio.Effects return; cutoff = value; - filterApplication.Invalidate(); + updateFilter(); } } @@ -64,18 +60,9 @@ namespace osu.Game.Audio.Effects fQ = 0.7f }; - Cutoff = getInitialCutoff(type); - } + cutoff = getInitialCutoff(type); - protected override void Update() - { - base.Update(); - - if (!filterApplication.IsValid) - { - updateFilter(cutoff); - filterApplication.Validate(); - } + updateFilter(); } private int getInitialCutoff(BQFType type) @@ -93,13 +80,13 @@ namespace osu.Game.Audio.Effects } } - private void updateFilter(int newValue) + private void updateFilter() { switch (type) { case BQFType.LowPass: // Workaround for weird behaviour when rapidly setting fCenter of a low-pass filter to nyquist - 1hz. - if (newValue >= MAX_LOWPASS_CUTOFF) + if (Cutoff >= MAX_LOWPASS_CUTOFF) { ensureDetached(); return; @@ -109,7 +96,7 @@ namespace osu.Game.Audio.Effects // Workaround for weird behaviour when rapidly setting fCenter of a high-pass filter to 1hz. case BQFType.HighPass: - if (newValue <= 1) + if (Cutoff <= 1) { ensureDetached(); return; @@ -120,17 +107,8 @@ namespace osu.Game.Audio.Effects ensureAttached(); - int filterIndex = mixer.Effects.IndexOf(filter); - - if (filterIndex < 0) return; - - if (mixer.Effects[filterIndex] is BQFParameters existingFilter) - { - existingFilter.fCenter = newValue; - - // required to update effect with new parameters. - mixer.Effects[filterIndex] = existingFilter; - } + filter.fCenter = Cutoff; + mixer.UpdateEffect(filter); } private void ensureAttached() @@ -138,8 +116,7 @@ namespace osu.Game.Audio.Effects if (IsAttached) return; - Debug.Assert(!mixer.Effects.Contains(filter)); - mixer.Effects.Add(filter); + mixer.AddEffect(filter); IsAttached = true; } @@ -148,8 +125,7 @@ namespace osu.Game.Audio.Effects if (!IsAttached) return; - Debug.Assert(mixer.Effects.Contains(filter)); - mixer.Effects.Remove(filter); + mixer.RemoveEffect(filter); IsAttached = false; }