Skip to content

Commit

Permalink
Merge pull request #27226 from peppy/no-audio-filter-funny-business
Browse files Browse the repository at this point in the history
Ensure audio filters can't be attached before load (or post-disposal)
  • Loading branch information
bdach authored Feb 19, 2024
2 parents 398eaee + 998d820 commit d7b1e3b
Showing 1 changed file with 15 additions and 1 deletion.
16 changes: 15 additions & 1 deletion osu.Game/Audio/Effects/AudioFilter.cs
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
using System.Diagnostics;
using ManagedBass.Fx;
using osu.Framework.Audio.Mixing;
using osu.Framework.Caching;
using osu.Framework.Graphics;

namespace osu.Game.Audio.Effects
Expand All @@ -22,6 +23,8 @@ public partial class AudioFilter : Component, ITransformableFilter

private bool isAttached;

private readonly Cached filterApplication = new Cached();

private int cutoff;

/// <summary>
Expand All @@ -36,7 +39,7 @@ public int Cutoff
return;

cutoff = value;
updateFilter(cutoff);
filterApplication.Invalidate();
}
}

Expand All @@ -61,6 +64,17 @@ public AudioFilter(AudioMixer mixer, BQFType type = BQFType.LowPass)
Cutoff = getInitialCutoff(type);
}

protected override void Update()
{
base.Update();

if (!filterApplication.IsValid)
{
updateFilter(cutoff);
filterApplication.Validate();
}
}

private int getInitialCutoff(BQFType type)
{
switch (type)
Expand Down

0 comments on commit d7b1e3b

Please sign in to comment.