This tutorial contains a brief introduction to using variables, categories, and RPCs within the Microsoft Cross-Platform Audio Creation Tool (XACT) engine.
The full working source code for this tutorial is in:
<Installed SDK Location>\Samples\C++\XACT\Tutorials\Tut03_Variable
XACT categories group XACT sounds into sets that can be adjusted as a whole. For example, all sounds of a specific category can paused or have their volume changed. All sounds belong to a root category called "Global" which can be used to control all of the sounds at once, but the sounds can also belong to sub-categories as defined by the XACT project. Typically, a game would create a "Music", "Sound FX", and "Dialog" category so all of these could be adjusted independently by the user.
Retrieving a category index is similar to retrieving a cue index. Just call IXACTEngine::GetCategory with the string name of the category and store the return value:
iMusicCategory = pXACTEngine->GetCategory( "Music" ); iGlobalCategory = pXACTEngine->GetCategory( "Global" );
For more information on categories, see Making XACT Categories.
To pause all sounds of a specific category, simply call IXACTEngine::Pause like so:
pXACTEngine->Pause( iMusicCategory, TRUE );
To adjust the volume of all sounds of a specific category, simple call IXACTEngine::SetVolume with the category index like so:
pXACTEngine->SetVolume( iGlobalCategory, fVolume );
The volume is a floating point scale where 0.0 means -96db, 1.0 means 0db, and 2.0 means +6db.
Variables are defined in an XACT project and are set by the game engine based on a game state, such as the RPM level of a car engine. The XACT project defines how this value, which is linked to a set of sounds, adjusts the sounds using a runtime parameter control (RPC). The RPC could change a sound pitch or volume based on the value of the variable. This allows the audio designer to have full control of how the sound responds to this floating point value.
Getting the index of a variable is similar to getting the index of a cue or category:
iVariable = pXACTEngine->GetGlobalVariableIndex( "RPM" );
To change a global variable, call IXACTEngine::SetGlobalVariable like this:
pXACTEngine->SetGlobalVariable( iVariable, nValue );
Where nValue could be any game state the audio designer and game programmer agree they need.