1
0
mirror of https://github.com/ppy/osu.git synced 2025-01-28 02:02:53 +08:00

Merge pull request #27390 from peppy/cutoff-fix

Fix low pass filter getting stuck in multiple locations
This commit is contained in:
Bartłomiej Dach 2024-02-26 16:19:16 +01:00 committed by GitHub
commit ab90b756e7
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
4 changed files with 45 additions and 18 deletions

View File

@ -17,12 +17,15 @@ namespace osu.Game.Audio.Effects
/// </summary>
public const int MAX_LOWPASS_CUTOFF = 22049; // nyquist - 1hz
/// <summary>
/// Whether this filter is currently attached to the audio track and thus applying an adjustment.
/// </summary>
public bool IsAttached { get; private set; }
private readonly AudioMixer mixer;
private readonly BQFParameters filter;
private readonly BQFType type;
private bool isAttached;
private readonly Cached filterApplication = new Cached();
private int cutoff;
@ -132,22 +135,22 @@ namespace osu.Game.Audio.Effects
private void ensureAttached()
{
if (isAttached)
if (IsAttached)
return;
Debug.Assert(!mixer.Effects.Contains(filter));
mixer.Effects.Add(filter);
isAttached = true;
IsAttached = true;
}
private void ensureDetached()
{
if (!isAttached)
if (!IsAttached)
return;
Debug.Assert(mixer.Effects.Contains(filter));
mixer.Effects.Remove(filter);
isAttached = false;
IsAttached = false;
}
protected override void Dispose(bool isDisposing)

View File

@ -115,6 +115,11 @@ namespace osu.Game.Collections
};
}
public override bool IsPresent => base.IsPresent
// Safety for low pass filter potentially getting stuck in applied state due to
// transforms on `this` causing children to no longer be updated.
|| lowPassFilter.IsAttached;
protected override void PopIn()
{
lowPassFilter.CutoffTo(300, 100, Easing.OutCubic);

View File

@ -27,6 +27,12 @@ namespace osu.Game.Overlays
public PopupDialog CurrentDialog { get; private set; }
public override bool IsPresent => Scheduler.HasPendingTasks
|| dialogContainer.Children.Count > 0
// Safety for low pass filter potentially getting stuck in applied state due to
// transforms on `this` causing children to no longer be updated.
|| lowPassFilter.IsAttached;
public DialogOverlay()
{
AutoSizeAxes = Axes.Y;
@ -95,8 +101,6 @@ namespace osu.Game.Overlays
}
}
public override bool IsPresent => Scheduler.HasPendingTasks || dialogContainer.Children.Count > 0;
protected override bool BlockNonPositionalInput => true;
protected override void PopIn()

View File

@ -78,8 +78,8 @@ namespace osu.Game.Screens.Play
private readonly BindableDouble volumeAdjustment = new BindableDouble(1);
private AudioFilter lowPassFilter = null!;
private AudioFilter highPassFilter = null!;
private AudioFilter? lowPassFilter;
private AudioFilter? highPassFilter;
private SkinnableSound sampleRestart = null!;
@ -158,7 +158,7 @@ namespace osu.Game.Screens.Play
}
[BackgroundDependencyLoader]
private void load(SessionStatics sessionStatics, AudioManager audio, OsuConfigManager config)
private void load(SessionStatics sessionStatics, OsuConfigManager config)
{
muteWarningShownOnce = sessionStatics.GetBindable<bool>(Static.MutedAudioNotificationShownOnce);
batteryWarningShownOnce = sessionStatics.GetBindable<bool>(Static.LowBatteryNotificationShownOnce);
@ -205,8 +205,6 @@ namespace osu.Game.Screens.Play
},
},
idleTracker = new IdleTracker(750),
lowPassFilter = new AudioFilter(audio.TrackMixer),
highPassFilter = new AudioFilter(audio.TrackMixer, BQFType.HighPass),
sampleRestart = new SkinnableSound(new SampleInfo(@"Gameplay/restart", @"pause-retry-click"))
};
@ -284,8 +282,9 @@ namespace osu.Game.Screens.Play
// stop the track before removing adjustment to avoid a volume spike.
Beatmap.Value.Track.Stop();
Beatmap.Value.Track.RemoveAdjustment(AdjustableProperty.Volume, volumeAdjustment);
lowPassFilter.CutoffTo(AudioFilter.MAX_LOWPASS_CUTOFF);
highPassFilter.CutoffTo(0);
lowPassFilter?.RemoveAndDisposeImmediately();
highPassFilter?.RemoveAndDisposeImmediately();
}
public override bool OnExiting(ScreenExitEvent e)
@ -425,6 +424,12 @@ namespace osu.Game.Screens.Play
settingsScroll.FadeInFromZero(500, Easing.Out)
.MoveToX(0, 500, Easing.OutQuint);
AddRangeInternal(new[]
{
lowPassFilter = new AudioFilter(audioManager.TrackMixer),
highPassFilter = new AudioFilter(audioManager.TrackMixer, BQFType.HighPass),
});
lowPassFilter.CutoffTo(1000, 650, Easing.OutQuint);
highPassFilter.CutoffTo(300).Then().CutoffTo(0, 1250); // 1250 is to line up with the appearance of MetadataInfo (750 delay + 500 fade-in)
@ -437,13 +442,23 @@ namespace osu.Game.Screens.Play
content.StopTracking();
content.ScaleTo(0.7f, CONTENT_OUT_DURATION * 2, Easing.OutQuint);
content.FadeOut(CONTENT_OUT_DURATION, Easing.OutQuint);
content.FadeOut(CONTENT_OUT_DURATION, Easing.OutQuint)
// Safety for filter potentially getting stuck in applied state due to
// transforms on `this` causing children to no longer be updated.
.OnComplete(_ =>
{
highPassFilter?.RemoveAndDisposeImmediately();
highPassFilter = null;
lowPassFilter?.RemoveAndDisposeImmediately();
lowPassFilter = null;
});
settingsScroll.FadeOut(CONTENT_OUT_DURATION, Easing.OutQuint)
.MoveToX(settingsScroll.DrawWidth, CONTENT_OUT_DURATION * 2, Easing.OutQuint);
lowPassFilter.CutoffTo(AudioFilter.MAX_LOWPASS_CUTOFF, CONTENT_OUT_DURATION);
highPassFilter.CutoffTo(0, CONTENT_OUT_DURATION);
lowPassFilter?.CutoffTo(AudioFilter.MAX_LOWPASS_CUTOFF, CONTENT_OUT_DURATION);
highPassFilter?.CutoffTo(0, CONTENT_OUT_DURATION);
}
private void pushWhenLoaded()