diff --git a/CHANGELOG.md b/CHANGELOG.md
index 1dd2a2a..acd6850 100644
--- a/CHANGELOG.md
+++ b/CHANGELOG.md
@@ -16,6 +16,7 @@ Additions
- Added InputHandler.InvertPressBehavior
- Added ReverseInput, ReverseOutput and AndThen to Easings
- Added an Enum constructor to GenericInput
+- Added RandomPitchModifier and GetRandomPitch to SoundEffectInfo
Improvements
- Allow comparing Keybind and Combination based on the amount of modifiers they have
diff --git a/MLEM/Sound/SoundEffectInfo.cs b/MLEM/Sound/SoundEffectInfo.cs
index 65e8445..9ca9115 100644
--- a/MLEM/Sound/SoundEffectInfo.cs
+++ b/MLEM/Sound/SoundEffectInfo.cs
@@ -1,29 +1,39 @@
+using System;
using Microsoft.Xna.Framework.Audio;
using MLEM.Extensions;
namespace MLEM.Sound {
///
/// A sound effect info is a wrapper around that additionally stores , and information.
- /// Additionally, a can be created using .
+ /// Additionally, a can be applied, a can be created using , and more.
///
public class SoundEffectInfo {
+ private static readonly Random Random = new Random();
+
///
/// The that is played by this info.
///
public readonly SoundEffect Sound;
+
///
/// Volume, ranging from 0.0 (silence) to 1.0 (full volume). Volume during playback is scaled by SoundEffect.MasterVolume.
///
public float Volume;
///
/// Pitch adjustment, ranging from -1.0 (down an octave) to 0.0 (no change) to 1.0 (up an octave).
+ /// To incorporate , you can use .
///
public float Pitch;
///
/// Pan value ranging from -1.0 (left speaker) to 0.0 (centered), 1.0 (right speaker).
///
public float Pan;
+ ///
+ /// A value that allows randomly modifying every time or are used.
+ /// The random modifier that is added onto will be between - and .
+ ///
+ public float RandomPitchModifier;
///
/// Creates a new sound effect info with the given values.
@@ -39,12 +49,23 @@ namespace MLEM.Sound {
this.Pan = pan;
}
+ ///
+ /// Returns a random pitch for this sound effect info that is between - and + .
+ /// If is 0, this method always returns .
+ ///
+ /// A random pitch to use to play this sound effect
+ public float GetRandomPitch() {
+ if (this.RandomPitchModifier == 0)
+ return this.Pitch;
+ return this.Pitch + ((float) Random.NextDouble() * 2 - 1) * this.RandomPitchModifier;
+ }
+
///
/// Plays this info's once.
///
/// False if more sounds are currently playing than the platform allows
public bool Play() {
- return this.Sound.Play(this.Volume, this.Pitch, this.Pan);
+ return this.Sound.Play(this.Volume, this.GetRandomPitch(), this.Pan);
}
///
@@ -53,7 +74,7 @@ namespace MLEM.Sound {
/// The value to set the returned instance's to. Defaults to false.
/// A new sound effect instance, with this info's data applied
public SoundEffectInstance CreateInstance(bool isLooped = false) {
- return this.Sound.CreateInstance(this.Volume, this.Pitch, this.Pan, isLooped);
+ return this.Sound.CreateInstance(this.Volume, this.GetRandomPitch(), this.Pan, isLooped);
}
}