From e3a0464e90ab8f5bdcef1b4716fc9cfdff0a00c5 Mon Sep 17 00:00:00 2001 From: Dean Herbert Date: Sat, 7 Mar 2026 23:39:17 +0900 Subject: [PATCH] Update a few sample playback usages to use new helper method --- .../Containers/OsuRearrangeableListContainer.cs | 8 ++------ osu.Game/Graphics/UserInterface/HoverClickSounds.cs | 13 +++---------- osu.Game/Graphics/UserInterface/HoverSounds.cs | 5 ++--- osu.Game/Screens/Edit/Timing/MetronomeDisplay.cs | 10 ++-------- 4 files changed, 9 insertions(+), 27 deletions(-) diff --git a/osu.Game/Graphics/Containers/OsuRearrangeableListContainer.cs b/osu.Game/Graphics/Containers/OsuRearrangeableListContainer.cs index fcc48d80ea..ab0bd6007e 100644 --- a/osu.Game/Graphics/Containers/OsuRearrangeableListContainer.cs +++ b/osu.Game/Graphics/Containers/OsuRearrangeableListContainer.cs @@ -10,7 +10,7 @@ using osu.Framework.Audio.Sample; using osu.Framework.Bindables; using osu.Framework.Graphics; using osu.Framework.Graphics.Containers; -using osu.Framework.Utils; +using osu.Game.Audio; namespace osu.Game.Graphics.Containers { @@ -52,12 +52,8 @@ namespace osu.Game.Graphics.Containers if (Time.Current - sampleLastPlaybackTime <= 35) return; - var channel = sampleSwap?.GetChannel(); - if (channel == null) - return; + SamplePlaybackHelper.PlayWithRandomPitch(sampleSwap, pitchVariation: 0.04); - channel.Frequency.Value = 0.96 + RNG.NextDouble(0.08); - channel.Play(); sampleLastPlaybackTime = Time.Current; } diff --git a/osu.Game/Graphics/UserInterface/HoverClickSounds.cs b/osu.Game/Graphics/UserInterface/HoverClickSounds.cs index b8f97cab5e..ef95288be7 100644 --- a/osu.Game/Graphics/UserInterface/HoverClickSounds.cs +++ b/osu.Game/Graphics/UserInterface/HoverClickSounds.cs @@ -8,6 +8,7 @@ using osu.Framework.Audio.Sample; using osu.Framework.Extensions; using osu.Framework.Input.Events; using osu.Framework.Utils; +using osu.Game.Audio; using osuTK.Input; namespace osu.Game.Graphics.UserInterface @@ -55,15 +56,7 @@ namespace osu.Game.Graphics.UserInterface return base.OnClick(e); } - public void PlayClickSample() - { - var channel = Enabled.Value ? sampleClick?.GetChannel() : sampleClickDisabled?.GetChannel(); - - if (channel != null) - { - channel.Frequency.Value = 0.99 + RNG.NextDouble(0.02); - channel.Play(); - } - } + public void PlayClickSample() => + SamplePlaybackHelper.PlayWithRandomPitch(Enabled.Value ? sampleClick : sampleClickDisabled, pitchVariation: 0.01); } } diff --git a/osu.Game/Graphics/UserInterface/HoverSounds.cs b/osu.Game/Graphics/UserInterface/HoverSounds.cs index cd67a0f935..b305104eee 100644 --- a/osu.Game/Graphics/UserInterface/HoverSounds.cs +++ b/osu.Game/Graphics/UserInterface/HoverSounds.cs @@ -9,7 +9,7 @@ using osu.Framework.Audio.Sample; using osu.Framework.Bindables; using osu.Framework.Extensions; using osu.Framework.Graphics; -using osu.Framework.Utils; +using osu.Game.Audio; namespace osu.Game.Graphics.UserInterface { @@ -43,8 +43,7 @@ namespace osu.Game.Graphics.UserInterface if (!Enabled.Value) return; - sampleHover.Frequency.Value = 0.98 + RNG.NextDouble(0.04); - sampleHover.Play(); + SamplePlaybackHelper.PlayWithRandomPitch(sampleHover, pitchVariation: 0.02); } } } diff --git a/osu.Game/Screens/Edit/Timing/MetronomeDisplay.cs b/osu.Game/Screens/Edit/Timing/MetronomeDisplay.cs index f91a67a7e3..50787726fb 100644 --- a/osu.Game/Screens/Edit/Timing/MetronomeDisplay.cs +++ b/osu.Game/Screens/Edit/Timing/MetronomeDisplay.cs @@ -15,6 +15,7 @@ using osu.Framework.Input.Events; using osu.Framework.Threading; using osu.Framework.Timing; using osu.Framework.Utils; +using osu.Game.Audio; using osu.Game.Beatmaps.ControlPoints; using osu.Game.Graphics; using osu.Game.Graphics.Containers; @@ -414,14 +415,7 @@ namespace osu.Game.Screens.Edit.Timing if (!IsBeatSyncedWithTrack || !EnableClicking) return; - var channel = beatIndex % timingPoint.TimeSignature.Numerator == 0 ? sampleTickDownbeat?.GetChannel() : sampleTick?.GetChannel(); - - if (channel == null) - return; - - channel.Frequency.Value = RNG.NextDouble(0.98f, 1.02f); - channel.Play(); - + SamplePlaybackHelper.PlayWithRandomPitch(beatIndex % timingPoint.TimeSignature.Numerator == 0 ? sampleTickDownbeat : sampleTick, 0.02f); Ticked?.Invoke(); } }