Audio in XNA
Xna4.png

Introduction

This tutorial is an introduction to doing audio in XNA. In this tutorial, we will see the options available for playing sound (both background music and sound effects) in your game.

Audio in XNA

There are two general methods for playing sound in XNA. The first way, which is new in XNA 3.0, is to play music and sound effects directly. This method is extremely simple to do, and so it will be the first thing we talk about. However, the ideal/preferred method is to use Microsoft's Cross-Platform Audio Creation Tool (XACT). This is a fairly nice and powerful tool that lets you do lots of stuff with audio. The intent of this product is to separate the audio from the programming. This way, an audio engineer, who knows nothing about programming, can have complete control over how the game's sound functions. There is a little more work that goes into this since you will have to work the XACT stuff into your project, but like everything else in XNA, it isn't too bad. There are a couple of tutorials here that go over how to do this. XACT ships with XNA Game Studio and is free to use.

XACT has one limitation, however. It requires .wav files. .wav files are often very large. If you want a full-length piece of music for your background music, you might have to be willing to deal with a file that is 50 MB or 100 MB in size.

Both of these methods have their advantages and disadvantages. I would recommend learning how to use both methods because I think you will find both of them useful.

What's Next?

Now that we've been introduced to how audio works in XNA, let's go on and try some out. Probably the easiest place to start is in the tutorial on playing sound effects, and then continue on to the tutorial on playing-background-music. If you want to start with XACT, though, go to the Using XACT tutorial.


Troubleshooting.png Having problems with this tutorial? Try the troubleshooting page!