How to: Change Voice Volume

This topic shows you how you can change the volume of a voice at an overall level, at each output channel, or between each channel of a voice and another voice in its sendlist.

To set an overall volume level for the voice's input

  • Use the SetVolume function.

    pSourceVoice->SetVolume(1.0);
    

To set the volume of the voice's output channels

  1. Create an array of floating point numbers that contain the desired volumes of all the output channels in the voice.

    The array will have one entry for each channel in the voice.

    float SourceVoiceChannelVolumes[1] = {1.0};
    
  2. Use the SetChannelVolumes function to set the volume of the output channels.

    hr = pSourceVoice->SetChannelVolumes(1,SourceVoiceChannelVolumes);
    

To set the volume of connections

Set the connection volume between the voice and a voice in its sendlist.

  1. Create an array of floating point numbers that defines an output matrix if the voice sends to another voice.

    Note

    The array must have a number of entries equal to source voice channels × destination voice channels. In this example, the mapping is from a voice with one channel to a voice with two channels.

     

    float outputMatrix[2] = {1.0f,0.05f};
    
  2. Use the SetOutputMatrix function to set the output matrix.

    pSourceVoice->SetOutputMatrix(pSubmixVoice,1,2,outputMatrix);
    

XAudio2 Programming Guide

How to: Build a Basic Audio Processing Graph

XAudio2 Volume and Pitch Control