Applying a 3D Positional Effect to a Cue (XACT)
The XNA Framework audio system contains support for 3D audio positioning effects. It uses the AudioEmitter and AudioListener classes, and the Cue.Apply3D method. The effects simulate 3D positioning for sound by adjusting speaker mix for cues that use the 3D values.
The speaker mix is the only effect that is automatically applied using this method. Attenuation and Doppler shift pitch modification effects must be applied via creation of runtime parameter controls (RPC) in the Microsoft Cross-Platform Audio Creation Tool (XACT). See Applying 3D Audio Effects (XACT) and Apply3D for more information.
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 basic 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 Cue
To retrieve and play a cue in 3D
Create an XACT project and add it to a new XNA Game Studio project as described in Adding a Sound File (XACT).
The project should contain at least one cue.
Call Cue.Apply3D on the cue you retrieved in the prior step.
Call Cue.Play to begin play back of the cue.
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 Cue.Apply3D method automatically sets the speaker mix for any sound played by this cue 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 Sound
- Demonstrates how to apply 3D positioning effects to a SoundEffect.
- Adding a Sound File (XACT)
- Demonstrates how to add wave (.wav) files to an XACT project that can be built and interpreted by an XNA Game Studio game to play audio.
- Applying 3D Audio Effects (XACT)
- Demonstrates how to apply attenuation and Doppler 3D audio effects in code.
- Audio Attenuation and Doppler Pitch Shifting Overview (XACT)
- Provides an overview of attenuation and Doppler pitch shifting.
- Getting Started with XACT
- Introduces the Microsoft Cross-Platform Audio Creation Tool (XACT).
- AudioListener Class
- Represents a 3D audio listener.
- AudioEmitter Class
- Represents a 3D audio emitter.
- Cue Class
- Defines methods for managing the playback of sounds.
- AudioEngine Class
- Represents the audio engine. Applications use the methods of the audio engine to instantiate and manipulate core audio objects.