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.

Complete Sample

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.

Download ChangeSoundVolume_Sample.zip

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

  1. Create an AudioEngine, WaveBank, and SoundBank at game start.

    // Audio objects
    AudioEngine engine;
    SoundBank soundBank;
    WaveBank waveBank;
    AudioCategory musicCategory;
    
  2. Call the AudioEngine.Update method of the AudioEngine during game update to allow the audio engine to process audio data.

    // Update the audio engine.
    engine.Update();
    
  3. 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");
    
  4. 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