Game Creation with XNA/Audio Sound/XACT

From Wikibooks, open books for an open world
Jump to navigation Jump to search

XACT (Cross-platform audio creation tool) is an audio creation and authoring tool from Microsoft. It comes with a graphical interface that allows sound designers to create audio resources for games, that can be integrated into XNA projects, offering the game developer a convenient way of accessing these sounds. It is part of Microsofts DirectX SDK and XNA Game Studio.

Sound in XNA[edit | edit source]

To simply play a single audio file XNA you don’t have to use the heavy-weight XACT framework. Just import the file into your project’s Content folder and use Microsoft.Xna.Framework.Media.

Song mySongsName;
mySong = Content.Load<Song>("theSongsAssetName");
MediaPlayer.Play(mySongsName);

XACT[edit | edit source]

XACT is Microsoft‘s approach to establish an audio creation tool for all platforms. It can be used to develop software for Windows (XP, Vista and 7) and the Xbox. Technically XACT sits on top of other frameworks, which are specific to a single platform. XACT is not (yet) available on Microsoft’s mobile operating system’s such as (Zune and Windows Phone 7). The basic architecture of XACT looks like this:

XACT supports playback of “normal” mono and stereo audio as well as of complex three dimensional audio.

XACT itself consists of three parts. A graphical User Interface which is meant to be used by sound designers. An API to integrate the audio into your code and an command line tool to call some of its functions during the build process.

XACT Graphical User Interface[edit | edit source]

XACT’s Graphical User Interface is known as Authoring Tool and is a part of the XNA Game Studio and the DirectX Software Development Kit. It lets you organise sounds in logical units, so they can be accessed easily by name with the API afterwards. Microsoft’s goal was to make the process of organizing the sounds as easy as possible. Designers can edit the sounds without writing any code.

After installing it can be found under All Programs > Microsoft DirectX SDK > DirectX Utilities > Microsoft Cross-Platform Audio Creation Tool (XACT).

XACT main concept is based on Wave Banks, Sound Banks and Cues. Wave Banks are collections of actual audio files. Sound Banks instead just consist of commands or meta data, which specify cue points and related things. Those cue points are called events in this context. Supported events are play, stop, marker, set volume and set pitch.

XACT also supports categories. Categories are used to group sounds to specify a certain set of features for those sounds. Each category may have multiple subcategories.

A Wave Bank supports two different modes “In Memory” and “Streaming”. As the name already says “In Memory” loads the complete audio data into the memory. This lets you access cues very fast but is not practical for long audio files, of course.

XACT supports only uncompressed files in formats like .wav or .aiff (and WMA in newer versions). Inside the Wave Bank you can also specify if the audio data should be stored compressed (as xWMA) or as PCM.

Effects are also available in XACT. It uses a digital sound processor which is described on MSDN. It supports various usual effects like a reverb and a delay.

Another feature of XACT are variables. The variables are basically the settings for several usual audio options like volume but also for more advanced ones like distance and orientation angle. Those values can then be modified while playing the sound in the code as described afterwards.

The authoring tool saves the data in .xap format which can be used to import the XACT project as an asset into your XNA project. The file does not contain the audio data itself, it only has references, which should stay in place.

XACT Authoring Tool Screenshot

XACT API[edit | edit source]

The API is providing the interface to be used in the games code. When a .xap project is located in your Content folder the content pipeline makes sure that all needed files are accessible within your code. Nevertheless there are still some objects which must be instantiated in your Initialize() method of your Game class.

Those objects are of type AudioEngine, WaveBank and SoundBank. A basic version can be found on MSDN and looks like this:

engine = new AudioEngine("Content\\PlaySound.xgs");
soundBank = new SoundBank(engine, "Content\\Sound Bank.xsb");
waveBank = new WaveBank(engine, "Content\\Wave Bank.xwb");

The instantiated AudioEngine object can then be updated inside the Update() method. It has it’s own Update() method, which should be called in there.

To modify 3D sound you can use predefined variables or your own variables specified via the Authoring Tool. This task can be done by using objects of type AudioEmitter and AudioListener.

XACT command line tool[edit | edit source]

The command line tool can be used to build some XACT packages during the build process of your entire game. It is named XACT Auditioning Utility. It can be found in the “Tools” sub folder inside the application’s main folder.

It can be also used to test .xap and other files created by the authoring tool.

References[edit | edit source]

Microsoft XNA Game Studio 3.0 Unleashed, 2009 by Chad Carter (ISBN-13: 9780672330223)

Authors[edit | edit source]

  • Christoph Guttandin
  • Ronny Gerasch