Adjusting Pitch and Volume
The SoundEffect.Play method allows you to specify the pitch and volume of a sound to play. 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.
The code in this topic shows you the technique for changing a sound's pitch or volume. You can download a complete code sample for this topic, including full source code and any additional supporting files required by the sample.
Change Pitch and Volume of Sound
To adjust the pitch and volume of a sound
soundfile = TitleContainer.OpenStream(@"Content\tx0_fire1.wav"); soundEffect = SoundEffect.FromStream(soundfile); soundInstance = soundEffect.CreateInstance();
// Play Sound soundInstance.Play();
Play the sound using SoundEffectInstance.Play.
// Pitch takes values from -1 to 1 soundInstance.Pitch = pitch; // Volume only takes values from 0 to 1 soundInstance.Volume = volume;
- Playing a Sound
Demonstrates how to play a simple sound by using SoundEffect.
- Looping a Sound
Demonstrates how to loop a sound.
- Creating and Playing Sounds
Provides overviews about audio technology, and presents predefined scenarios to demonstrate how to use audio.