Was this page helpful?
Your feedback about this content is important. Let us know what you think.
Additional feedback?
1500 characters remaining
Export (0) Print
Expand All

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.

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

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.

Community Additions

ADD
Show:
© 2015 Microsoft