How To: Change the Pitch or Volume of a Sound
Demonstrates how to change pitch and volume of a playing sound.
The Complete Sample
The code in this topic shows you the technique. You can download a complete code sample for this topic, including full source code and any additional supporting files required by the sample.
SoundEffect.Play method allows you to specify the pitch and volume of a sound for playing the sound. However, after you call Play, you cannot modify the sound. Using SoundEffectInstance for a given SoundEffect allows you to change the pitch and volume of a sound at any time during playback. Simple Sound Manipulation
SoundEffect using the method shown in How To: Play a Sound.
SoundEffectInstance, and set it to the return value of SoundEffect.CreateInstance.
protected override void LoadContent()
soundEffect = Content.Load<SoundEffect>( "tx0_fire1");
soundInstance = soundEffect.CreateInstance();
SoundEffectInstance.Play to play the sound.
if (playerOne.Buttons.A == ButtonState.Pressed)
// Play Sound
Pitch and Volume to the desired values.
// Pitch takes values from -1 to 1
float pitch = playerOne.ThumbSticks.Left.X;
// Volume only takes values from 0 to 1
float volume = (playerOne.ThumbSticks.Right.X+1)/2;
soundInstance.Pitch = pitch;
soundInstance.Volume = volume;