Overview of Microsoft Audio Technologies
The
audio technologies that Microsoft provides include a few APIs and tools
that are used to play and manipulate sound on Windows-based PCs and
Xbox 360 video game consoles. These audio APIs build upon each other, so
they are not technically different technologies, but rather are
different levels of audio APIs. For example, XAudio2 is a low-level
sound API. Everything you can do with sound can be done with this API
with the utmost control. XACT3 is an API and a GUI tool that provides
high-level control over sound, and it is built on top of XAudio2. In
other words, XACT3 is high-level enough that a lot of work happens
behind the scenes through XAudio2, while if you use XAudio2, you have to
directly do that work yourself. XACT3 uses XAudio2 internally and
essentially saves you the work of using XAudio2 directly with the
trade-off of low-level control.
You
can view the various audio systems’ documentation in the DirectX SDK,
XNA SDK, or XDK (Xbox 360 Development Kit) documentation. |
XACT3 and XAudio2 can play the following audio formats:
Pulse code modulation (PCM)
Adaptive differential pulse code modulation (ADPCM) on Windows
XMA on Xbox 360
xWMA (a subset of Microsoft’s WMA)
Additional Microsoft audio
technologies include X3DAudio, XAPO, XAPOFX, and the XMAEncoder
Library. X3DAudio is used by XAudio2 and XACT3 to play sounds in 3D—that
is, to play audio so that it sounds like it is emanating from a
specific position rather than being ambient and global. An example of
X3DAudio for XAudio2 called XAudio2Sound3D can be found in the DirectX
SDK Sample Browser.
XAPO is an API used to
create audio effects for XACT3 and XAudio2. XAPOFX is a library of XAPO
sound effects ready to be used with audio.
The XMAEncoder
Library is a statically linked library that developers can use to give
applications the ability to encode XMA content. The XMAEncoder is
available in the Xbox Development Kit.
Direct Sound
Direct
Sound is a sound API that is part of the DirectX SDK. Direct Sound is
deprecated, which means it is no longer being updated and presumably
will eventually be dropped from the DirectX SDK. Although you can still
use Direct Sound, it has been replaced with XAudio2. Other deprecated audio technologies
include the original XAudio, which was used in the original Xbox video
game console and has also been replaced with XAudio2 (now used for the
Xbox 360 and PC), and XACT, which has been replaced with XACT3. This
information is according to Microsoft’s documentation on their audio
technologies, which can be found in the DirectX SDK documentation.
Why Not Use Direct Sound?
Long ago there were two
audio APIs in the DirectX SDK: Direct Music and Direct Sound. Direct
Music allowed low-level control over audio playback, and Direct Sound
was a higher-level API that gave developers an easy way to play sound in
their applications. Direct Music was eventually dropped (and merged
with Direct Sound), and Direct Sound became the main audio API in
DirectX. When the Xbox video game console hit the market, XAudio was the
main API used for audio on that console. XAudio was eventually replaced
with XAudio2, which was packaged with the DirectX SDK. XACT3 is built
on top of XAudio2 and gives developers a ready-made high-level API and
tool for audio playback and control.
The big question is why
would you choose XAudio2 over XACT3? Put in simple terms, XAudio2 is
good for developers looking to build something like XACT3, while XACT3
is a ready-to-go high-level tool and API that can be used on the PC and
the Xbox 360. In addition to being available in the DirectX SDK, XACT is
available in the XNA Game Studio SDK. For advanced developers the
low-level control of XAudio2 might prove to be attractive enough to use
it.
Another way to think about
it is that XACT3 is useful for developers who want a ready-made audio
content creation API and tools instead of developing their own
implementation. It is also possible to use XACT3 and XAudio2 at the same
time if the need arises—for example, if you need signal processing,
mixing, and so forth, which XACT3 does not offer but XAudio2 does.
XACT3 is available in XNA, which is a C#-based game
development tool, and C++. You can obtain XACT3 by installing either the
XNA SDK or the DirectX SDK. XACT3
is Microsoft’s high-level audio technology that allows programmers and
sound designers to use the same code and audio content files on both
Windows-based PCs and Xbox 360 video game consoles. XACT3 is composed of
an audio API and as a stand-alone GUI toolset used to create the audio
files that are used by the audio API. When you compile audio content
with the XACT toolset, you can create output audio files for both the PC
and the Xbox 360.
When
using XNA, you don’t have to compile the files using the XACT toolset
because the XNA content pipeline does that job for you and prepares the
necessary files whether you are compiling for the Xbox 360 or Windows PC
platforms. |
For those familiar with previous versions of XACT, XACT3 has had the following features added to it.
XACT3 Tools
The XACT3 toolset is called
the Microsoft Cross-Platform Audio Creation Tool, and it is a GUI
application that is used, as mentioned earlier, to create the audio
files that will be loaded and used by the XACT3 API code base. This tool
creates files that can be used by either the Xbox 360 or Windows-based
PCs (XP and Vista). With the XACT3 tool you can group sound files into
cues that can be played any time in a game, and you can set various
properties of each cue such as pitch and volume. XACT3 has both a GUI
tool and a command-line tool. Both tools perform the same task, but the
GUI tool is much more convenient to use.
XACT3 allows
developers to organize audio content into packages called banks. Later
we will talk about these banks, which include sound and wave banks, and
how to create them in XACT3. The audio content itself includes the
following audio formats.
There
is one thing to consider when working with audio files created by
XACT3. The Windows PC and the Xbox 360 use different byte ordering for
variables. In other words the number 12 on the Xbox 360 would not read
as 12 on a Windows PC without reversing the bytes of the integer. This
is because the Xbox 360 uses big-endian order because of its PowerPC
hardware, while Windows-based PCs uses little-endian order, which is the
byte ordering used by x86 processors. Endian order is an important
topic for programmers and engineers who create cross-platform
applications, such as writing an application that works on Windows and
porting it to Mac (PowerPC-based Mac, that is).
Fortunately, if the issues ever does arise, all that
needs to be done to translate between byte ordering is to read a
variable (such as a float, integer, etc.) from a file, cast that
variable to a character pointer, and use array indexes to swap the first
element with the last and the second element with the third. In other
words, reverse the array of characters. This would only be done if you
know you were reading a file that was written in an incompatible endian
order, which is the responsibility of the programmer since there is no
way of knowing what endian order a file’s data is in unless you
purposely write some type of flag in your custom file formats for this
purpose (e.g., a single byte where 0 means little endian or 1 means big
endian). The same holds true for data sent over a network between two
machines that use different endian orders.
The
XACT3 toolset creates files in both endian orders. Since the Xbox 360
and Windows-based PCs use different endian orders, this is convenient
and means you do not have to write code to translate the byte ordering
between the platforms. The Windows files are saved in a folder called
Win, and Xbox 360 files are saved in a folder called Xbox when you build
XACT3 projects. |
A screenshot of the XACT3 GUI tool is shown in Figure 1.
You can launch the tool from the Start menu on Windows XP or Vista by
navigating to the DirectX SDK or XNA SDK folder, the DirectX Utilities
folder if you are using the DirectX SDK, or the Tools folder if you are
using XNA or Microsoft Cross-Platform Audio Creation Tool (XACT).
Creating XACT Audio Projects
To create a new audio
project, the first step is to open the XACT tool and select New Project
from the File menu. A dialog box should appear prompting you to choose a
name for your project for the project file that will be saved and the
location where you want this project saved (see Figure 9.1). Save the project and name it TestXACT. If
you are following along with the creation of this article’s XACT demo,
create a folder called XACT in your My Documents folder (or wherever you
wish) and save the XACT3 audio project in this folder. When you save
the audio project, there should be a TestXACT.xap file, which is the
XACT project file, and two folders titled Win (for Windows) and Xbox
(for Xbox 360) that were created by the tool as a result.
Creating XACT Wave Banks and Sound Banks
With the project
created, you can create a wave bank and a sound bank. A wave bank is
used to take multiple audio files and package them into a single file.
These wave bank files have the extension .XWB and allow developers to
manage a single file rather than many files. A sound bank has the
extension .XSB and packages multiple cues into a single file. The file
format is documented for wave banks for those interested in using it for
purposes outside of XACT, but the sound bank files are not documented.
A
cue in XACT3 is like an action. You play cues in XACT, and a cue has
properties associated with it that include the audio sound from the wave
bank that it will play when called and its volume and pitch. This is
useful because you can have multiple cues that are used to play a sound
different ways in a game. For example, you can take the sound of an
engine and create multiple cues that alter how that engine sounds so
that in a game the one sound clip is used to create different sound
effects.
The two types of wave banks
are in-memory and streaming. In-memory is used to store sounds that are
loaded and used in memory, while streaming is used to dynamically load
audio from the wave bank while it is being played. Streaming wave banks
are great for playing audio files that are large in size and in length.
In this book we’ll focus on in-memory wave banks, but once you are
familiar with playing audio in XACT3, you can follow the streaming wave
bank XACT3 sample from the DirectX SDK Sample Browser to see how to
utilize a wave bank for streaming.
To begin, create a new wave bank and sound bank by following these instructions.
1. | Select Wave Banks > New Wave Bank from the menu.
|
2. | Select Sound Banks > New Sound Bank from the menu.
|
3. | Select Window > Tile Horizontally from the menu to organize the newly created windows.
|
You should have a window that appears similar to Figure 2. From this point you can manually add audio files to the wave bank and then add cues to the sound bank.
To add a sound to the
wave bank, choose Wave Banks > Insert Wave File(s). From the dialog
box choose the file you want to add, and it will insert a new entry in
the wave bank window. To create a sound in the sound bank, select Sound
Banks > New Sound. To create a new cue, select Sound Banks > New
Cue from the menu. To associate the audio file from the wave bank to the
sound in the sound bank, simply drag and drop the audio from the wave
bank window to the sound entry in the sound bank. To associate a sound
with a cue, you do the same thing by dragging the sound entry from the
top of the sound bank to the cue. Remember, the cue is used by XACT to
access the sound to play it, stop it, and so forth. The sound in the
sound bank stores various properties such as volume, pitch, and so on.
The audio in the wave bank is the actual audio data.
You can set the name for the sound and wave banks in the properties section of each. |
There
is a shortcut to creating a sound and cue in the sound bank. Once
you’ve inserted the audio in the wave bank, you can drag and drop that
entry to an empty region in the cue window and, when you release the
mouse button, an entry for the sound and cue will be automatically
created with the same name as the audio file that was in the wave bank.
This method is commonly used since you have to have all three to play
sounds in XACT, and this method is faster than creating each entry
manually, especially if they use the same name anyway.
At this point save the
project and select File > Build to build the project. Once it is
built (if you’re developing it for Windows), you will have a file for
the sound bank, a file for the wave bank, and a file with the extension
.XGS. The XGS file stores global settings and variables that XACT3 can
load and use. You can set the variables in the variables section of the
properties panel. You can set variables such as the speed of the sound,
the number of instances, the orientation angle, and so forth. You don’t
need these settings to play a sound, but you can use them, which is done
in the DirectX SDK Sample Browser in a demo called XACT Tutorial 3:
Categories and Variables.