public abstract class XAudio2 : ComObject
XAudio2 is the class for the XAudio2 object that manages all audio engine states, the audio processing thread, the voice graph, and so forth.
CommitAll
Value which can be used in combination with the CommitChanges method to commit all changes.
public const Int32 CommitAll
Constant Value
CommitNow
Values which indicates that the made changes should be commited instantly.
public const Int32 CommitNow
Constant Value
DefaultChannels
Value which indicates that the default number of channels should be used.
public const Int32 DefaultChannels
Constant Value
DefaultFrequencyRatio
The default value for the frequency ratio is 4.
public const Single DefaultFrequencyRatio
Constant Value
DefaultSampleRate
Values which indicates that the default sample rate should be used.
public const Int32 DefaultSampleRate
Constant Value
MaxAudioChannels
The maximum number of supported channels is 64.
public const Int32 MaxAudioChannels
Constant Value
MaxFrequencyRatio
Maximum frequency ratio is 1024.
public const Single MaxFrequencyRatio
Constant Value
MaximumSampleRate
Maximum sample rate is 200 kHz.
public const Int32 MaximumSampleRate
Constant Value
MinFrequencyRatio
The minimum frequency ratio is 1/1024.
public const Single MinFrequencyRatio
Constant Value
MinimumSampleRate
Minimum sample rate is 1000 Hz.
public const Int32 MinimumSampleRate
Constant Value
QuantumDenominator
The denominator of a quantum unit. In 10ms chunks (= 1/100 seconds).
public const Int32 QuantumDenominator
Constant Value
XAudio2(IntPtr ptr, XAudio2Version version)
Initializes a new instance of the XAudio2 class.
protected void XAudio2(IntPtr ptr, XAudio2Version version)
Parameters
ptr
IntPtrNative pointer of the XAudio2Voice object.
version
XAudio2VersionThe XAudio2 subversion to use.
CommitChanges()
Atomically applies a set of operations that are tagged with a given identifier.
public void CommitChanges()
CommitChanges(Int32 operationSet)
Atomically applies a set of operations that are tagged with a given identifier.
CommitChangesNative(Int32 operationSet)
Atomically applies a set of operations that are tagged with a given identifier.
public abstract Int32 CommitChangesNative(Int32 operationSet)
Parameters
operationSet
Int32Identifier of the set of operations to be applied. To commit all pending operations, pass CommitAll.
Returns
HRESULT
CreateMasteringVoice()
Creates and configures a mastering voice.
public XAudio2MasteringVoice CreateMasteringVoice()
Returns
If successful, returns a new XAudio2MasteringVoice object.
CreateMasteringVoice(Int32 inputChannels, Int32 inputSampleRate)
Creates and configures a mastering voice.
public XAudio2MasteringVoice CreateMasteringVoice(Int32 inputChannels, Int32 inputSampleRate)
Parameters
inputChannels
Int32Number of channels the mastering voice expects in its input audio. inputChannels must be less than or equal to MaxAudioChannels. You can set InputChannels to DefaultChannels, which causes XAudio2 to try to detect the system speaker configuration setup.
inputSampleRate
Int32Sample rate of the input audio data of the mastering voice. This rate must be a multiple of QuantumDenominator. inputSampleRate must be between MinimumSampleRate and MaximumSampleRate. You can set InputSampleRate to DefaultSampleRate, with the default being determined by the current platform.
Returns
If successful, returns a new XAudio2MasteringVoice object.
CreateMasteringVoice(Int32 inputChannels, Int32 inputSampleRate, object device)
Creates and configures a mastering voice.
public XAudio2MasteringVoice CreateMasteringVoice(Int32 inputChannels, Int32 inputSampleRate, object device)
Parameters
inputChannels
Int32Number of channels the mastering voice expects in its input audio. inputChannels must be less than or equal to MaxAudioChannels. You can set InputChannels to DefaultChannels, which causes XAudio2 to try to detect the system speaker configuration setup.
inputSampleRate
Int32Sample rate of the input audio data of the mastering voice. This rate must be a multiple of QuantumDenominator. inputSampleRate must be between MinimumSampleRate and MaximumSampleRate. You can set InputSampleRate to DefaultSampleRate, with the default being determined by the current platform.
device
objectIdentifier of the device to receive the output audio. Specifying the default value of NULL (for XAudio2.8) or 0 (for XAudio2.7) causes XAudio2 to select the global default audio device.
Returns
If successful, returns a new XAudio2MasteringVoice object.
CreateMasteringVoice(Int32 inputChannels, Int32 inputSampleRate, object device, Nullable effectChain, AudioStreamCategory streamCategory)
Creates and configures a mastering voice.
public XAudio2MasteringVoice CreateMasteringVoice(Int32 inputChannels, Int32 inputSampleRate, object device, Nullable effectChain, AudioStreamCategory streamCategory)
Parameters
inputChannels
Int32Number of channels the mastering voice expects in its input audio. inputChannels must be less than or equal to MaxAudioChannels. You can set InputChannels to DefaultChannels, which causes XAudio2 to try to detect the system speaker configuration setup.
inputSampleRate
Int32Sample rate of the input audio data of the mastering voice. This rate must be a multiple of QuantumDenominator. inputSampleRate must be between MinimumSampleRate and MaximumSampleRate. You can set InputSampleRate to DefaultSampleRate, with the default being determined by the current platform.
device
objectIdentifier of the device to receive the output audio. Specifying the default value of NULL (for XAudio2.8) or 0 (for XAudio2.7) causes XAudio2 to select the global default audio device.
effectChain
NullableEffectChain structure that describes an effect chain to use in the mastering voice, or NULL to use no effects.
streamCategory
AudioStreamCategoryThe audio stream category to use for this mastering voice.
Returns
If successful, returns a new XAudio2MasteringVoice object.
CreateMasteringVoiceNative(IntPtr& pMasteringVoice, Int32 inputChannels, Int32 inputSampleRate, Int32 flags, object device, Nullable effectChain, AudioStreamCategory streamCategory)
Creates and configures a mastering voice.
public abstract Int32 CreateMasteringVoiceNative(IntPtr& pMasteringVoice, Int32 inputChannels, Int32 inputSampleRate, Int32 flags, object device, Nullable effectChain, AudioStreamCategory streamCategory)
Parameters
pMasteringVoice
IntPtr&If successful, returns a pointer to the new XAudio2MasteringVoice object.
inputChannels
Int32Number of channels the mastering voice expects in its input audio. inputChannels must be less than or equal to MaxAudioChannels. You can set InputChannels to DefaultChannels, which causes XAudio2 to try to detect the system speaker configuration setup.
inputSampleRate
Int32Sample rate of the input audio data of the mastering voice. This rate must be a multiple of QuantumDenominator. inputSampleRate must be between MinimumSampleRate and MaximumSampleRate. You can set InputSampleRate to DefaultSampleRate, with the default being determined by the current platform.
flags
Int32Flags that specify the behavior of the mastering voice. Must be 0.
device
objectIdentifier of the device to receive the output audio. Specifying the default value of NULL (for XAudio2.8) or 0 (for XAudio2.7) causes XAudio2 to select the global default audio device.
effectChain
NullableEffectChain structure that describes an effect chain to use in the mastering voice, or NULL to use no effects.
streamCategory
AudioStreamCategoryThe audio stream category to use for this mastering voice.
Returns
HRESULT
CreateMasteringVoicePtr(Int32 inputChannels, Int32 inputSampleRate, Int32 flags, object device, Nullable effectChain, AudioStreamCategory streamCategory)
Creates and configures a mastering voice.
public IntPtr CreateMasteringVoicePtr(Int32 inputChannels, Int32 inputSampleRate, Int32 flags, object device, Nullable effectChain, AudioStreamCategory streamCategory)
Parameters
inputChannels
Int32Number of channels the mastering voice expects in its input audio. inputChannels must be less than or equal to MaxAudioChannels. You can set InputChannels to DefaultChannels, which causes XAudio2 to try to detect the system speaker configuration setup.
inputSampleRate
Int32Sample rate of the input audio data of the mastering voice. This rate must be a multiple of QuantumDenominator. inputSampleRate must be between MinimumSampleRate and MaximumSampleRate. You can set InputSampleRate to DefaultSampleRate, with the default being determined by the current platform.
flags
Int32Flags that specify the behavior of the mastering voice. Must be 0.
device
objectIdentifier of the device to receive the output audio. Specifying the default value of NULL (for XAudio2.8) or 0 (for XAudio2.7) causes XAudio2 to select the global default audio device.
effectChain
NullableEffectChain structure that describes an effect chain to use in the mastering voice, or NULL to use no effects.
streamCategory
AudioStreamCategoryThe audio stream category to use for this mastering voice.
Returns
If successful, returns a pointer to the new XAudio2MasteringVoice object.
CreateSourceVoice(WaveFormat sourceFormat)
Creates and configures a source voice.
public XAudio2SourceVoice CreateSourceVoice(WaveFormat sourceFormat)
Parameters
sourceFormat
WaveFormatPointer to a WaveFormat. The following formats are supported:
The number of channels in a source voice must be less than or equal to MaxAudioChannels. The sample rate of a source voice must be between MinimumSampleRate and MaximumSampleRate .
Returns
If successful, returns a new XAudio2SourceVoice object.
CreateSourceVoice(WaveFormat sourceFormat, VoiceFlags flags)
Creates and configures a source voice.
public XAudio2SourceVoice CreateSourceVoice(WaveFormat sourceFormat, VoiceFlags flags)
Parameters
sourceFormat
WaveFormatPointer to a WaveFormat. The following formats are supported:
The number of channels in a source voice must be less than or equal to MaxAudioChannels. The sample rate of a source voice must be between MinimumSampleRate and MaximumSampleRate .
flags
VoiceFlagsVoiceFlags that specify the behavior of the source voice. A flag can be None or a combination of one or more of the following. Possible values are NoPitch, NoSampleRateConversition and UseFilter. Music is not supported on Windows.
Returns
If successful, returns a new XAudio2SourceVoice object.
CreateSourceVoice(WaveFormat sourceFormat, VoiceFlags flags, Single maxFrequencyRatio, IXAudio2VoiceCallback voiceCallback, Nullable sendList, Nullable effectChain)
Creates and configures a source voice. For more information see http://msdn.microsoft.com/en-us/library/windows/desktop/microsoft.directx_sdk.ixaudio2.ixaudio2.createsourcevoice(v=vs.85).aspx.
public XAudio2SourceVoice CreateSourceVoice(WaveFormat sourceFormat, VoiceFlags flags, Single maxFrequencyRatio, IXAudio2VoiceCallback voiceCallback, Nullable sendList, Nullable effectChain)
Parameters
sourceFormat
WaveFormatPointer to a WaveFormat. The following formats are supported:
The number of channels in a source voice must be less than or equal to MaxAudioChannels. The sample rate of a source voice must be between MinimumSampleRate and MaximumSampleRate .
flags
VoiceFlagsVoiceFlags that specify the behavior of the source voice. A flag can be None or a combination of one or more of the following. Possible values are NoPitch, NoSampleRateConversition and UseFilter. Music is not supported on Windows.
maxFrequencyRatio
SingleHighest allowable frequency ratio that can be set on this voice. The value for this argument must be between MinFrequencyRatio and MaxFrequencyRatio.
voiceCallback
IXAudio2VoiceCallbackClient-provided callback interface, IXAudio2VoiceCallback. This parameter is optional and can be null.
sendList
NullableList of VoiceSends structures that describe the set of destination voices for the source voice. If sendList is NULL, the send list defaults to a single output to the first mastering voice created.
effectChain
NullableList of EffectChain structures that describe an effect chain to use in the source voice. This parameter is optional and can be null.
Returns
If successful, returns a new XAudio2SourceVoice object.
CreateSourceVoiceNative(IntPtr& pSourceVoice, IntPtr sourceFormat, VoiceFlags flags, Single maxFrequencyRatio, IXAudio2VoiceCallback voiceCallback, Nullable sendList, Nullable effectChain)
Creates and configures a source voice. For more information see http://msdn.microsoft.com/en-us/library/windows/desktop/microsoft.directx_sdk.ixaudio2.ixaudio2.createsourcevoice(v=vs.85).aspx.
public abstract Int32 CreateSourceVoiceNative(IntPtr& pSourceVoice, IntPtr sourceFormat, VoiceFlags flags, Single maxFrequencyRatio, IXAudio2VoiceCallback voiceCallback, Nullable sendList, Nullable effectChain)
Parameters
pSourceVoice
IntPtr&If successful, returns a pointer to the new XAudio2SourceVoice object.
sourceFormat
IntPtrPointer to a WaveFormat. The following formats are supported:
The number of channels in a source voice must be less than or equal to MaxAudioChannels. The sample rate of a source voice must be between MinimumSampleRate and MaximumSampleRate.
flags
VoiceFlagsVoiceFlags that specify the behavior of the source voice. A flag can be None or a combination of one or more of the following. Possible values are NoPitch, NoSampleRateConversition and UseFilter. Music is not supported on Windows.
maxFrequencyRatio
SingleHighest allowable frequency ratio that can be set on this voice. The value for this argument must be between MinFrequencyRatio and MaxFrequencyRatio.
voiceCallback
IXAudio2VoiceCallbackClient-provided callback interface, IXAudio2VoiceCallback. This parameter is optional and can be null.
sendList
NullableList of VoiceSends structures that describe the set of destination voices for the source voice. If sendList is NULL, the send list defaults to a single output to the first mastering voice created.
effectChain
NullableList of EffectChain structures that describe an effect chain to use in the source voice. This parameter is optional and can be null.
Returns
HRESULT
CreateSourceVoicePtr(WaveFormat sourceFormat, VoiceFlags flags, Single maxFrequencyRatio, IXAudio2VoiceCallback voiceCallback, Nullable sendList, Nullable effectChain)
Creates and configures a source voice. For more information see http://msdn.microsoft.com/en-us/library/windows/desktop/microsoft.directx_sdk.ixaudio2.ixaudio2.createsourcevoice(v=vs.85).aspx.
public IntPtr CreateSourceVoicePtr(WaveFormat sourceFormat, VoiceFlags flags, Single maxFrequencyRatio, IXAudio2VoiceCallback voiceCallback, Nullable sendList, Nullable effectChain)
Parameters
sourceFormat
WaveFormatPointer to a WaveFormat. The following formats are supported:
The number of channels in a source voice must be less than or equal to MaxAudioChannels. The sample rate of a source voice must be between MinimumSampleRate and MaximumSampleRate .
flags
VoiceFlagsVoiceFlags that specify the behavior of the source voice. A flag can be None or a combination of one or more of the following. Possible values are NoPitch, NoSampleRateConversition and UseFilter. Music is not supported on Windows.
maxFrequencyRatio
SingleHighest allowable frequency ratio that can be set on this voice. The value for this argument must be between MinFrequencyRatio and MaxFrequencyRatio.
voiceCallback
IXAudio2VoiceCallbackClient-provided callback interface, IXAudio2VoiceCallback. This parameter is optional and can be null.
sendList
NullableList of VoiceSends structures that describe the set of destination voices for the source voice. If sendList is NULL, the send list defaults to a single output to the first mastering voice created.
effectChain
NullableList of EffectChain structures that describe an effect chain to use in the source voice. This parameter is optional and can be null.
Returns
If successful, returns a pointer to the new XAudio2SourceVoice object.
CreateSubmixVoice(Int32 inputChannels, Int32 inputSampleRate, VoiceFlags flags)
Creates and configures a submix voice.
public XAudio2SubmixVoice CreateSubmixVoice(Int32 inputChannels, Int32 inputSampleRate, VoiceFlags flags)
Parameters
inputChannels
Int32Number of channels in the input audio data of the submix voice. The inputChannels must be less than or equal to MaxAudioChannels.
inputSampleRate
Int32Sample rate of the input audio data of submix voice. This rate must be a multiple of QuantumDenominator. InputSampleRate must be between MinimumSampleRate and MaximumSampleRate.
flags
VoiceFlagsFlags that specify the behavior of the submix voice. It can be None or UseFilter.
Returns
On success, returns a new XAudio2SubmixVoice object.
CreateSubmixVoice(Int32 inputChannels, Int32 inputSampleRate, VoiceFlags flags, Int32 processingStage, Nullable sendList, Nullable effectChain)
Creates and configures a submix voice.
public XAudio2SubmixVoice CreateSubmixVoice(Int32 inputChannels, Int32 inputSampleRate, VoiceFlags flags, Int32 processingStage, Nullable sendList, Nullable effectChain)
Parameters
inputChannels
Int32Number of channels in the input audio data of the submix voice. The inputChannels must be less than or equal to MaxAudioChannels.
inputSampleRate
Int32Sample rate of the input audio data of submix voice. This rate must be a multiple of QuantumDenominator. InputSampleRate must be between MinimumSampleRate and MaximumSampleRate.
flags
VoiceFlagsFlags that specify the behavior of the submix voice. It can be None or UseFilter.
processingStage
Int32An arbitrary number that specifies when this voice is processed with respect to other submix voices, if the XAudio2 engine is running other submix voices. The voice is processed after all other voices that include a smaller processingStage value and before all other voices that include a larger processingStage value. Voices that include the same processingStage value are processed in any order. A submix voice cannot send to another submix voice with a lower or equal processingStage value. This prevents audio being lost due to a submix cycle.
sendList
NullableList of VoiceSends structures that describe the set of destination voices for the submix voice. If sendList is NULL, the send list will default to a single output to the first mastering voice created.
effectChain
NullableList of EffectChain structures that describe an effect chain to use in the submix voice. This parameter is optional and can be null.
Returns
On success, returns a new XAudio2SubmixVoice object.
CreateSubmixVoiceNative(IntPtr& pSubmixVoice, Int32 inputChannels, Int32 inputSampleRate, VoiceFlags flags, Int32 processingStage, Nullable sendList, Nullable effectChain)
Creates and configures a submix voice.
public abstract Int32 CreateSubmixVoiceNative(IntPtr& pSubmixVoice, Int32 inputChannels, Int32 inputSampleRate, VoiceFlags flags, Int32 processingStage, Nullable sendList, Nullable effectChain)
Parameters
pSubmixVoice
IntPtr&On success, returns a pointer to the new XAudio2SubmixVoice object.
inputChannels
Int32Number of channels in the input audio data of the submix voice. The inputChannels must be less than or equal to MaxAudioChannels.
inputSampleRate
Int32Sample rate of the input audio data of submix voice. This rate must be a multiple of QuantumDenominator. InputSampleRate must be between MinimumSampleRate and MaximumSampleRate.
flags
VoiceFlagsFlags that specify the behavior of the submix voice. It can be None or UseFilter.
processingStage
Int32An arbitrary number that specifies when this voice is processed with respect to other submix voices, if the XAudio2 engine is running other submix voices. The voice is processed after all other voices that include a smaller processingStage value and before all other voices that include a larger processingStage value. Voices that include the same processingStage value are processed in any order. A submix voice cannot send to another submix voice with a lower or equal processingStage value. This prevents audio being lost due to a submix cycle.
sendList
NullableList of VoiceSends structures that describe the set of destination voices for the submix voice. If sendList is NULL, the send list will default to a single output to the first mastering voice created.
effectChain
NullableList of EffectChain structures that describe an effect chain to use in the submix voice. This parameter is optional and can be null.
Returns
HRESULT
CreateSubmixVoicePtr(Int32 inputChannels, Int32 inputSampleRate, VoiceFlags flags, Int32 processingStage, Nullable sendList, Nullable effectChain)
Creates and configures a submix voice.
public IntPtr CreateSubmixVoicePtr(Int32 inputChannels, Int32 inputSampleRate, VoiceFlags flags, Int32 processingStage, Nullable sendList, Nullable effectChain)
Parameters
inputChannels
Int32Number of channels in the input audio data of the submix voice. The inputChannels must be less than or equal to MaxAudioChannels.
inputSampleRate
Int32Sample rate of the input audio data of submix voice. This rate must be a multiple of QuantumDenominator. InputSampleRate must be between MinimumSampleRate and MaximumSampleRate.
flags
VoiceFlagsFlags that specify the behavior of the submix voice. It can be None or UseFilter.
processingStage
Int32An arbitrary number that specifies when this voice is processed with respect to other submix voices, if the XAudio2 engine is running other submix voices. The voice is processed after all other voices that include a smaller processingStage value and before all other voices that include a larger processingStage value. Voices that include the same processingStage value are processed in any order. A submix voice cannot send to another submix voice with a lower or equal processingStage value. This prevents audio being lost due to a submix cycle.
sendList
NullableList of VoiceSends structures that describe the set of destination voices for the submix voice. If sendList is NULL, the send list will default to a single output to the first mastering voice created.
effectChain
NullableList of EffectChain structures that describe an effect chain to use in the submix voice. This parameter is optional and can be null.
Returns
On success, returns a pointer to the new XAudio2SubmixVoice object.
CreateXAudio2()
Creates a new instance of the XAudio2 class. If no supported XAudio2 version is available, the CreateXAudio2 method throws an NotSupportedException.
public static XAudio2 CreateXAudio2()
Returns
A new XAudio2 instance.
CreateXAudio2(Nullable processor)
Creates a new instance of the XAudio2 class. If no supported XAudio2 version is available, the CreateXAudio2 method throws an NotSupportedException.
public static XAudio2 CreateXAudio2(Nullable processor)
Parameters
processor
NullableThe XAudio2Processor to use.
Returns
A new XAudio2 instance.
GetDefaultDevice()
Returns the default device.
protected abstract object GetDefaultDevice()
Returns
The default device.
GetPerformanceDataNative(PerformanceData& performanceData)
Returns current resource usage details, such as available memory or CPU usage.
public abstract void GetPerformanceDataNative(PerformanceData& performanceData)
Parameters
performanceData
PerformanceData&On success, pointer to an PerformanceData structure that is returned.
Returns
HRESULT
RegisterForCallbacks(IXAudio2EngineCallback callback)
Adds an IXAudio2EngineCallback from the XAudio2 engine callback list.
RegisterForCallbacksNative(IXAudio2EngineCallback callback)
Adds an IXAudio2EngineCallback from the XAudio2 engine callback list.
public abstract Int32 RegisterForCallbacksNative(IXAudio2EngineCallback callback)
Parameters
callback
IXAudio2EngineCallbackIXAudio2EngineCallback object to add to the XAudio2 engine callback list.
Returns
HRESULT
SetDebugConfiguration(DebugConfiguration debugConfiguration)
Changes debug logging options for XAudio2.
public void SetDebugConfiguration(DebugConfiguration debugConfiguration)
Parameters
debugConfiguration
DebugConfigurationDebugConfiguration structure that contains the new debug configuration.
SetDebugConfigurationNative(DebugConfiguration debugConfiguration, IntPtr reserved)
Changes debug logging options for XAudio2.
public abstract void SetDebugConfigurationNative(DebugConfiguration debugConfiguration, IntPtr reserved)
Parameters
debugConfiguration
DebugConfigurationDebugConfiguration structure that contains the new debug configuration.
reserved
IntPtrReserved parameter. Must me NULL.
Returns
HRESULT
StartEngine()
Starts the audio processing thread.
StartEngineNative()
Starts the audio processing thread.
public abstract Int32 StartEngineNative()
Returns
HRESULT
StopEngine()
Stops the audio processing thread.
public abstract void StopEngine()
UnregisterForCallbacks(IXAudio2EngineCallback callback)
Removes an IXAudio2EngineCallback from the XAudio2 engine callback list.
public abstract void UnregisterForCallbacks(IXAudio2EngineCallback callback)
Parameters
callback
IXAudio2EngineCallbackIXAudio2EngineCallback object to remove from the XAudio2 engine callback list. If the given interface is present more than once in the list, only the first instance in the list will be removed.
DefaultDevice
Gets the default device which can be used to create a mastering voice.
public object DefaultDevice { get; }
PerformanceData
Gets current resource usage details, such as available memory or CPU usage.
public PerformanceData PerformanceData { get; }
Version
Gets the XAudio2Version of the XAudio2 object.
public XAudio2Version Version { get; set; }