IXAudio2Voice::SetVolume method

Sets the overall volume level for the voice.


HRESULT SetVolume(
  [infloat  Volume,
  [in] UINT32 OperationSet = XAUDIO2_COMMIT_NOW


Volume [in]

Overall volume level to use. See Remarks for more information on volume levels.

OperationSet [in]

Identifies this call as part of a deferred batch. See the XAudio2 Operation Sets overview for more information.

Return value

Returns S_OK if successful, an error code otherwise. See XAudio2 Error Codes for descriptions of error codes.


SetVolume controls a voice's master input volume level. The master volume level is applied at different times depending on the type of voice. For submix and mastering voices the volume level is applied just before the voice's built in filter and effect chain is applied. For source voices the master volume level is applied after the voice's filter and effect chain is applied.

Volume levels are expressed as floating-point amplitude multipliers between -XAUDIO2_MAX_VOLUME_LEVEL and XAUDIO2_MAX_VOLUME_LEVEL (-2²⁴ to 2²⁴), with a maximum gain of 144.5 dB. A volume level of 1.0 means there is no attenuation or gain and 0 means silence. Negative levels can be used to invert the audio's phase. See XAudio2 Volume and Pitch Control for additional information on volume control.

Note  IXAudio2Voice::GetVolume always returns the volume most recently set by IXAudio2Voice::SetVolume. However, it may not actually be in effect yet: it only takes effect the next time the audio engine runs after the IXAudio2Voice::SetVolume call (or after the corresponding IXAudio2::CommitChanges call, if IXAudio2Voice::SetVolume was called with a deferred operation ID).

Platform Requirements

Windows 10 (XAudio2.9); Windows 8, Windows Phone 8 (XAudio 2.8); DirectX SDK (XAudio 2.7)




See also

How to: Change Voice Volume
How to: Use Submix Voices