// Copyright (c) ppy Pty Ltd . Licensed under the MIT Licence. // See the LICENCE file in the repository root for full licence text. using osu.Framework.Audio.Sample; using osu.Framework.Utils; namespace osu.Game.Audio { public static class SamplePlaybackHelper { /// /// Plays the provided with a randomised pitch. /// /// The to be played. /// The amount of pitch variation to allow. /// The that was used for playback. public static SampleChannel? PlayWithRandomPitch(Sample? sample, double pitchVariation = 0.2f) { var chan = sample?.GetChannel(); if (chan == null) return null; chan.Frequency.Value = RNG.NextDouble(1 - pitchVariation, 1 + pitchVariation); chan.Play(); return chan; } /// /// Plays a random sample from the given array, with a randomised pitch. /// /// An array of to play. /// The amount of pitch variation to allow. /// The that was used for playback. public static SampleChannel? PlayWithRandomPitch(Sample?[]? samples, double pitchVariation = 0.2f) => PlayWithRandomPitch(samples?[RNG.Next(0, samples.Length)], pitchVariation); } }