mirror of
https://github.com/ppy/osu.git
synced 2024-11-11 10:33:30 +08:00
Adjust AudioFilter
to framework-side changes
Co-authored-by: Dan Balasescu <smoogipoo@smgi.me>
This commit is contained in:
parent
da4160439e
commit
7f08008059
@ -1,10 +1,8 @@
|
|||||||
// Copyright (c) ppy Pty Ltd <contact@ppy.sh>. Licensed under the MIT Licence.
|
// 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.
|
// See the LICENCE file in the repository root for full licence text.
|
||||||
|
|
||||||
using System.Diagnostics;
|
|
||||||
using ManagedBass.Fx;
|
using ManagedBass.Fx;
|
||||||
using osu.Framework.Audio.Mixing;
|
using osu.Framework.Audio.Mixing;
|
||||||
using osu.Framework.Caching;
|
|
||||||
using osu.Framework.Graphics;
|
using osu.Framework.Graphics;
|
||||||
|
|
||||||
namespace osu.Game.Audio.Effects
|
namespace osu.Game.Audio.Effects
|
||||||
@ -26,8 +24,6 @@ namespace osu.Game.Audio.Effects
|
|||||||
private readonly BQFParameters filter;
|
private readonly BQFParameters filter;
|
||||||
private readonly BQFType type;
|
private readonly BQFType type;
|
||||||
|
|
||||||
private readonly Cached filterApplication = new Cached();
|
|
||||||
|
|
||||||
private int cutoff;
|
private int cutoff;
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
@ -42,7 +38,7 @@ namespace osu.Game.Audio.Effects
|
|||||||
return;
|
return;
|
||||||
|
|
||||||
cutoff = value;
|
cutoff = value;
|
||||||
filterApplication.Invalidate();
|
updateFilter();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -64,18 +60,9 @@ namespace osu.Game.Audio.Effects
|
|||||||
fQ = 0.7f
|
fQ = 0.7f
|
||||||
};
|
};
|
||||||
|
|
||||||
Cutoff = getInitialCutoff(type);
|
cutoff = getInitialCutoff(type);
|
||||||
}
|
|
||||||
|
|
||||||
protected override void Update()
|
updateFilter();
|
||||||
{
|
|
||||||
base.Update();
|
|
||||||
|
|
||||||
if (!filterApplication.IsValid)
|
|
||||||
{
|
|
||||||
updateFilter(cutoff);
|
|
||||||
filterApplication.Validate();
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
private int getInitialCutoff(BQFType type)
|
private int getInitialCutoff(BQFType type)
|
||||||
@ -93,13 +80,13 @@ namespace osu.Game.Audio.Effects
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private void updateFilter(int newValue)
|
private void updateFilter()
|
||||||
{
|
{
|
||||||
switch (type)
|
switch (type)
|
||||||
{
|
{
|
||||||
case BQFType.LowPass:
|
case BQFType.LowPass:
|
||||||
// Workaround for weird behaviour when rapidly setting fCenter of a low-pass filter to nyquist - 1hz.
|
// 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();
|
ensureDetached();
|
||||||
return;
|
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.
|
// Workaround for weird behaviour when rapidly setting fCenter of a high-pass filter to 1hz.
|
||||||
case BQFType.HighPass:
|
case BQFType.HighPass:
|
||||||
if (newValue <= 1)
|
if (Cutoff <= 1)
|
||||||
{
|
{
|
||||||
ensureDetached();
|
ensureDetached();
|
||||||
return;
|
return;
|
||||||
@ -120,17 +107,8 @@ namespace osu.Game.Audio.Effects
|
|||||||
|
|
||||||
ensureAttached();
|
ensureAttached();
|
||||||
|
|
||||||
int filterIndex = mixer.Effects.IndexOf(filter);
|
filter.fCenter = Cutoff;
|
||||||
|
mixer.UpdateEffect(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;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
private void ensureAttached()
|
private void ensureAttached()
|
||||||
@ -138,8 +116,7 @@ namespace osu.Game.Audio.Effects
|
|||||||
if (IsAttached)
|
if (IsAttached)
|
||||||
return;
|
return;
|
||||||
|
|
||||||
Debug.Assert(!mixer.Effects.Contains(filter));
|
mixer.AddEffect(filter);
|
||||||
mixer.Effects.Add(filter);
|
|
||||||
IsAttached = true;
|
IsAttached = true;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -148,8 +125,7 @@ namespace osu.Game.Audio.Effects
|
|||||||
if (!IsAttached)
|
if (!IsAttached)
|
||||||
return;
|
return;
|
||||||
|
|
||||||
Debug.Assert(mixer.Effects.Contains(filter));
|
mixer.RemoveEffect(filter);
|
||||||
mixer.Effects.Remove(filter);
|
|
||||||
IsAttached = false;
|
IsAttached = false;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user