1
0
mirror of https://github.com/ppy/osu.git synced 2025-03-19 01:17:19 +08:00

Apply some renaming and code quality fixes

This commit is contained in:
Dean Herbert 2021-10-07 18:47:52 +09:00
parent f98dd1b811
commit 0348c6c7e5
3 changed files with 23 additions and 12 deletions

View File

@ -66,10 +66,10 @@ namespace osu.Game.Tests.Visual.Audio
}
[Test]
public void TestLowPass() => testFilter(lowpassFilter, lowpassFilter.MaxCutoff, 0);
public void TestLowPass() => testFilter(lowpassFilter, AudioFilter.MAX_LOWPASS_CUTOFF, 0);
[Test]
public void TestHighPass() => testFilter(highpassFilter, 0, highpassFilter.MaxCutoff);
public void TestHighPass() => testFilter(highpassFilter, 0, AudioFilter.MAX_LOWPASS_CUTOFF);
private void testFilter(Filter filter, int cutoffFrom, int cutoffTo)
{

View File

@ -11,11 +11,19 @@ namespace osu.Game.Audio.Effects
{
public class Filter : Component, ITransformableFilter
{
public readonly int MaxCutoff = 22049; // nyquist - 1hz
/// <summary>
/// The maximum cutoff frequency that can be used with a low-pass filter.
/// This is equal to nyquist - 1hz.
/// </summary>
public const int MAX_LOWPASS_CUTOFF = 22049; // nyquist - 1hz
private readonly AudioMixer mixer;
private readonly BQFParameters filter;
private readonly BQFType type;
/// <summary>
/// The current cutoff of this filter.
/// </summary>
public BindableNumber<int> Cutoff { get; }
/// <summary>
@ -37,7 +45,7 @@ namespace osu.Game.Audio.Effects
break;
case BQFType.LowPass:
initialCutoff = MaxCutoff;
initialCutoff = MAX_LOWPASS_CUTOFF;
break;
default:
@ -48,8 +56,9 @@ namespace osu.Game.Audio.Effects
Cutoff = new BindableNumber<int>(initialCutoff)
{
MinValue = 1,
MaxValue = MaxCutoff
MaxValue = MAX_LOWPASS_CUTOFF
};
filter = new BQFParameters
{
lFilter = type,
@ -82,13 +91,13 @@ namespace osu.Game.Audio.Effects
// Workaround for weird behaviour when rapidly setting fCenter of a low-pass filter to nyquist - 1hz.
if (type == BQFType.LowPass)
{
if (cutoff.NewValue >= MaxCutoff)
if (cutoff.NewValue >= MAX_LOWPASS_CUTOFF)
{
detachFilter();
return;
}
if (cutoff.OldValue >= MaxCutoff && cutoff.NewValue < MaxCutoff)
if (cutoff.OldValue >= MAX_LOWPASS_CUTOFF && cutoff.NewValue < MAX_LOWPASS_CUTOFF)
attachFilter();
}
@ -108,11 +117,13 @@ namespace osu.Game.Audio.Effects
var filterIndex = mixer.Effects.IndexOf(filter);
if (filterIndex < 0) return;
var existingFilter = mixer.Effects[filterIndex] as BQFParameters;
if (existingFilter == null) return;
if (mixer.Effects[filterIndex] is BQFParameters existingFilter)
{
existingFilter.fCenter = cutoff.NewValue;
existingFilter.fCenter = cutoff.NewValue;
mixer.Effects[filterIndex] = existingFilter;
// required to update effect with new parameters.
mixer.Effects[filterIndex] = existingFilter;
}
}
protected override void Dispose(bool isDisposing)

View File

@ -89,7 +89,7 @@ namespace osu.Game.Overlays
{
base.PopOut();
lpFilter.CutoffTo(lpFilter.MaxCutoff, 100, Easing.InCubic);
lpFilter.CutoffTo(AudioFilter.MAX_LOWPASS_CUTOFF, 100, Easing.InCubic);
if (CurrentDialog?.State.Value == Visibility.Visible)
{