XAudio2 Reference
This section provides detailed reference information for the XAudio2 API, which is a low-level audio API for Windows that provides powerful audio manipulation and mixing capabilities for game developers.
Key Interfaces
The core functionality of XAudio2 is accessed through several key interfaces:
-
IXAudio2
: The central engine interface. Used to create submixes, mastering voices, source voices, and process audio. -
IXAudio2MasteringVoice
: Represents the output device (e.g., speakers, headphones). -
IXAudio2SourceVoice
: Represents an audio source (e.g., a sound effect, music track). -
IXAudio2SubmixVoice
: Used for intermediate processing and mixing of audio streams.
IXAudio2
Interface
The IXAudio2
interface is the primary entry point for XAudio2 functionality. You obtain an instance of this interface by calling the XAudio2Create
function.
Methods
Method | Description |
---|---|
CreateMasteringVoice(...) |
Creates a mastering voice, which represents the audio output device. |
CreateSourceVoice(...) |
Creates a source voice for playing audio data. |
CreateSubmixVoice(...) |
Creates a submix voice for routing and processing audio streams. |
StartEngine() |
Starts the XAudio2 engine. |
StopEngine() |
Stops the XAudio2 engine. |
CommitChanges() |
Applies all pending audio graph changes. |
IXAudio2MasteringVoice
Interface
The IXAudio2MasteringVoice
interface controls the output of audio to the system's audio device. It typically receives audio from other voices (source or submix).
Methods
Method | Description |
---|---|
GetVoiceDetails(...) |
Retrieves details about the mastering voice. |
SetVolume(...) |
Sets the volume for the mastering voice. |
SetOutputMatrix(...) |
Configures the audio channel routing from the mastering voice to the output device. |
IXAudio2SourceVoice
Interface
The IXAudio2SourceVoice
interface is used to play audio samples. It's where you submit audio buffers to be processed and mixed.
Methods
Method | Description |
---|---|
SubmitSourceBuffer(...) |
Submits an audio buffer to be played. |
Start(...) |
Starts playback on the source voice. |
Stop(...) |
Stops playback on the source voice. |
FlushSourceBuffers() |
Removes all pending audio buffers from the voice. |
SetSourceSampleRate(...) |
Sets the sample rate for the source voice. |
IXAudio2SubmixVoice
Interface
IXAudio2SubmixVoice
allows for grouping and processing multiple audio streams before they reach the mastering voice. This is useful for effects chains and advanced mixing.
Methods
Method | Description |
---|---|
SetEffectChain(...) |
Applies a chain of audio effects to the submix voice. |
EnableEffect(...) |
Enables a specific effect in the chain. |
DisableEffect(...) |
Disables a specific effect in the chain. |
Note: This reference provides a high-level overview. For full API details, including parameter descriptions and return values, please consult the official DirectX SDK documentation.
Important: Proper management of audio voices and buffers is crucial for performance and preventing audio glitches. Always ensure voices are destroyed when no longer needed.