1
0
mirror of https://github.com/ppy/osu.git synced 2024-11-11 09:07:52 +08:00

Adjust AudioFilter to framework-side changes

Co-authored-by: Dan Balasescu <smoogipoo@smgi.me>
This commit is contained in:
Bartłomiej Dach 2024-06-18 07:27:54 +02:00
parent da4160439e
commit 7f08008059
No known key found for this signature in database

View File

@ -1,10 +1,8 @@
// Copyright (c) ppy Pty Ltd <contact@ppy.sh>. 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;
/// <summary>
@ -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;
}