O'Reilly logo

Learning XNA 3.0 by Aaron Reed

Stay ahead with the world's most comprehensive technology and business learning platform.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, tutorials, and more.

Start Free Trial

No credit card required

Implementing XACT Audio Files in Code

The first step in implementing the XACT audio project in your XNA project is to include the file you saved from XACT in your XNA project. Remember that previously you copied the .wav files to the Content\Audio directory within your project, but you didn't include those files in your XNA project through Visual Studio. As I mentioned previously, the only file that you actually need to include in the XNA game project is the project file you created in XACT. Hopefully, you named the XACT project file GameAudio.xap and saved it in the project's Content\Audio directory. If so, add it to your project now by right-clicking the Content\Audio folder in Solution Explorer, selecting Add → Existing Item, and browsing to your GameAudio.xap file.

To load the data from your XACT project file into objects that you can use to play the sounds in XNA, you need to add the following class-level variables at the top of your Game1 class:

AudioEngine audioEngine;
WaveBank waveBank;
SoundBank soundBank;
Cue trackCue;

The first variable represents something called a sound engine. This object will be used in the creation of your WaveBank and SoundBank objects and is the core object used for XNA sound. As you've probably already guessed, the WaveBank and SoundBank objects will correspond to the sound and wave bank sections of your XACT file. The Cue object is used to pull out individual cues from the sound bank to play those cues. You can play a cue without holding onto a ...

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, interactive tutorials, and more.

Start Free Trial

No credit card required