Adjusting Volume (XACT)
This section demonstrates how to initialize the audio engine, and how to use categories to change the playback volume of a group of sounds.Categories control the sound volume levels for groups of sounds in the Microsoft Cross-Platform Audio Creation Tool (XACT). These categories are collections that can hold one or more references to cues. Global variables linked to runtime parameter controls (RPC) within the XACT project control individual cue volumes. This topic explains how to use categories to control the volume of groups of sounds.
- For more information about using global variables and RPCs, see XACT Variables and XACT Runtime Parameter Controls.
- For more information about creating categories within your XACT project, see Making XACT Categories.
- For more information about how XACT automatically adjusts the volume based on distance, see Applying 3D Audio Effects (XACT).
The code in this topic shows you the technique for changing sound volume levels. You can download a complete code sample for this topic, including full source code and any additional supporting files required by the sample.
Changing Sound Volume Levels
The example assumes you already built an XACT sound bank and wave bank. If not, see Adding a Sound File (XACT) to learn how to do this.
To change sound volume levels
// Audio objects AudioEngine engine; SoundBank soundBank; WaveBank waveBank; AudioCategory musicCategory;
// Update the audio engine. engine.Update();
Call AudioEngine.GetCategory to retrieve a category of sounds whose volume you want to change, and then pass in the name of the category you created in the XACT project.
// Get the category. musicCategory = engine.GetCategory("Music");
Call AudioCategory.SetVolume to specify the desired volume.
// Set the category volume. musicCategory.SetVolume(musicVolume);
Normal volume value should be between 0.0 (silence) and 1.0 (full volume, as authored). Values greater than 1.0 will make the volume louder than designed. A volume of 2.0, for example, adds +6 decibels to the authored level.
Related Overview Topics
- Getting Started with XACT
Introduces the Microsoft Cross-Platform Audio Creation Tool (XACT).
- Adding a Sound File (XACT)
Demonstrates how to add wave (.wav) files to an XACT project that can be built and interpreted by an XNA Game Studio game to play audio.
- Playing Sounds from an XACT Project
Demonstrates how to initialize the audio engine, to load sound banks and wave banks created using XACT, and then to play a sound by using a Cue object.
- Playing Background Music (XACT)
Demonstrates how to specify sound (.wav) files as background music.
- Creating and Playing Sounds
Provides overviews about audio technology, and presents predefined scenarios to demonstrate how to use audio.