Resources:

Overview

Here we talk about the Audio Library in XNA, which is all about XACT. If you are at the beginning of the project, skip this topic. However sounds and music is not something you want to forget! They make half of the athmosphere if not two third! The ealrier you start with it, the better it is at the end.

The XNA Audio Library is based on the Cross-Platform Audio Creation Tool (XACT) from Microsoft. XACT is a combination of graphical tool for authoring audio content, and an API that is responsible for interpreting the authored XACT files and playing audio in response to game events. In other words you are going to use the "Microsoft Cross-Platform Audio Creation Tool" installed together with XNA, and thanks to this program you will be able load the wave files, create your sound bank with sounds and cues, and finally bring everything inside your game project.

Audio Authoring

In this section we discuss the main topics related to audio authoring. Let's have a look to the XACT:

XACT_shot.jpg

The use of this program is quite intuitive. You can start playing around with it. The main concept you need to know are:

  • Wave Bank: The wave bank will contain all the wave files of your game. Read this if you need further details.

  • Sound Bank: A sound bank is a collection of instructions that specify how and when to play sounds. In the game code you will invoke sounds with cues (which will invoke sounds). To fill sound banks you have to create sounds and associate them with the wave files by creating a track. The drag and drop interface should be intuitive enough. Cues are simply cues of sounds, used for instance for a set of music tracks you want to play one after the other. Read this for further details.

For a full list of detailed topics, visit this link.

Programming with XACT

The best way to go is learn by doing. Start with How To: Play a Sound. Here we summarize the process.

Once you have created an XACT project and saved it to a file as an .xap file, add the .xap file and any wave files the XACT project uses as input to your XNA Game Studio game, and the Content Pipeline will build the needed files for you to access your content at run time.

An XACT project builds a set of files: a global settings file (.xgs), one or more wave banks (.xwb), and one or more sound banks (.xsb). These files may be provided to AudioEngine, WaveBank, and SoundBank constructors, respectively.

To initialize the XACT engine, you must create a new AudioEngine and provide the path to the global settings file. Then, load any wave banks you need by creating new WaveBank objects, and load any sound banks that you need by creating SoundBank objects. Once you have loaded the necessary files, you can access cues that the audio designer has created by calling GetCue on the SoundBank that contains the Cue that you want to retrieve. Each Cue instance that you retrieve is unique, even when retrieving multiple cues with the same name. This allows multiple instances of the same Cue to exist and play simultaneously.

You can play, pause, resume, and stop Cue objects by using, respectively, the Play, Pause, Resume, and Stop methods. See How To: Play a Sound for information about how to play a cue, and How To: Stop or Pause a Sound for more information about how to pause, resume, and stop cues.

Periodically, you must call Update to allow the audio engine to process audio data.

For more advanced projects, you can also access AudioCategory objects for controlling the playback of sound categories by calling GetCategory. Also, to access variables that the audio designer has tied to playback changes in volume, pitch, or DSP effects, you can call GetGlobalVariable. For more information about how to use categories to change sound volume levels, see How To: Change Sound Volume Levels.

How To?


Page URL: https://twiki.graphics.ethz.ch/bin/view/GameClass/AudioLibrary
2024-04-19
© 2024 Eidgenössische Technische Hochschule Zürich