Applying a 3D Positional Effect to a Sound
This topic demonstrates how to apply 3D positioning effects to a SoundEffect. The XNA Framework audio system contains support for 3D audio positioning effects. It uses the AudioEmitter and AudioListener classes, and the SoundEffectInstance.Apply3D method. The effects simulate 3D positioning for sound by adjusting speaker mix for cues that use the 3D values. Speaker mix is the only effect that is applied automatically using this method.
The following example uses a circular rotation around a stationary AudioListener to emphasize the 3D effect.
The code in this topic shows you the technique for applying 3D positional effects. You can download a complete code sample for this topic, including full source code and any additional supporting files required by the sample.
Applying Basic 3D Positional Effects to a SoundEffect
To retrieve and play a SoundEffect in 3D
Add a wave (.wmv) file to a new XNA Game Studio project as described in Playing a Sound.
The project should contain at least one SoundEffect.
In the the LoadContent method, set the SoundEffectInstance object to the return value of SoundEffect.CreateInstance.
Call SoundEffectInstance.Play to play the sound.
To process audio data
Set the Vector3 structure to the position from which you want the sound to come.
Set the AudioEmitter.Position property to this vector.
|Calling the SoundEffectInstance.Apply3D method automatically sets the speaker mix for any sound played by this sound effect to a value calculated by the difference in Position values between listener and emitter. In preparation for the mix, the sound is converted to monoaural. Any stereo information in the sound is discarded.|
- Applying a 3D Positional Effect to a Cue (XACT)
- Demonstrates how to apply a 3D positioning effect to a cue.
- 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.