DirectX Audio API Reference
The DirectX Audio APIs provide a comprehensive set of tools for developers to integrate advanced audio functionalities into their Windows applications and games. This section details the core interfaces, structures, and functions used for audio playback, recording, mixing, and effects processing.
Core Components
The DirectX Audio subsystem is built around several key components:
- XAudio2: A low-level audio API designed for high-performance audio manipulation, ideal for games and real-time audio applications.
- DirectSound: An older but still relevant API for basic sound playback and mixing.
- Windows Audio Session API (WASAPI): A modern, low-latency audio architecture for applications that require fine-grained control over audio streams.
- Media Foundation: A framework for media playback and processing, which also includes audio capabilities.
XAudio2 Interfaces
XAudio2 provides a rich set of interfaces for managing audio data, effects, and playback devices.
IXAudio2
The primary interface for interacting with XAudio2. It's used to create voices, manage mastering, and access audio devices.
// Creating an XAudio2 engine instance IXAudio2* pXAudio2 = nullptr; HRESULT hr = XAudio2Create(&pXAudio2, 0, XAUDIO2_DEFAULT_PROCESSOR); if (SUCCEEDED(hr)) { // Engine created successfully }
IXAudio2MasteringVoice
Represents the audio device that the application will output sound to. All other voices are typically connected to the mastering voice.
IXAudio2SourceVoice
Represents a sound source. You submit audio buffers to a source voice for playback.
IXAudio2SubmixVoice
Used to create submixes for applying effects to multiple source voices collectively.
Common Structures and Enums
Several data structures and enumerations are fundamental to using the DirectX Audio APIs.
XAUDIO2_BUFFER
Defines the properties of an audio buffer to be submitted for playback.
Flags
: Flags that control buffer behavior.AudioBytes
: The size of the audio data in bytes.pAudioData
: A pointer to the audio data.PlayBegin
,PlayLength
,LoopBegin
,LoopLength
: Offsets and lengths for playback and looping.
XAUDIO2_VOICE_STATE
Provides the current state of an audio voice.
XAUDIO2_SEND_DESCRIPTOR
Describes a connection from one voice to another (a send).
Key Functions
These functions are commonly used when working with DirectX Audio.
XAudio2Create
Initializes the XAudio2 engine.
IXAudio2::CreateMasteringVoice
Creates a mastering voice for the default audio device.
IXAudio2::CreateSourceVoice
Creates a source voice for playing audio.
IXAudio2SourceVoice::SubmitSourceBuffer
Submits an audio buffer to a source voice for playback.
IXAudio2SourceVoice::StartVoice
Starts playback on a source voice.
IXAudio2SourceVoice::StopVoice
Stops playback on a source voice.
API Reference Table
Interface/Function | Description | Documentation Link |
---|---|---|
IXAudio2 |
Main XAudio2 engine interface. | Link to IXAudio2 docs |
XAudio2Create |
Initializes the XAudio2 engine. | Link to XAudio2Create docs |
IXAudio2::CreateMasteringVoice |
Creates a mastering voice. | Link to CreateMasteringVoice docs |
IXAudio2::CreateSourceVoice |
Creates a source voice. | Link to CreateSourceVoice docs |
IXAudio2SourceVoice::SubmitSourceBuffer |
Submits an audio buffer for playback. | Link to SubmitSourceBuffer docs |
XAUDIO2_BUFFER |
Structure representing an audio buffer. | Link to XAUDIO2_BUFFER docs |