Fields (11) Methods (31) Properties (3)
Namespace: CSCore.XAudio2

Syntax

public abstract class XAudio2 : ComObject

Base Type

Summary

XAudio2 is the class for the XAudio2 object that manages all audio engine states, the audio processing thread, the voice graph, and so forth.

Uses

Used by

Fields

CommitAll

Value which can be used in combination with the CommitChanges method to commit all changes.

public const Int32 CommitAll

Constant Value

0

CommitNow

Values which indicates that the made changes should be commited instantly.

public const Int32 CommitNow

Constant Value

0

DefaultChannels

Value which indicates that the default number of channels should be used.

public const Int32 DefaultChannels

Constant Value

0

DefaultFrequencyRatio

The default value for the frequency ratio is 4.

public const Single DefaultFrequencyRatio

Constant Value

4

DefaultSampleRate

Values which indicates that the default sample rate should be used.

public const Int32 DefaultSampleRate

Constant Value

0

MaxAudioChannels

The maximum number of supported channels is 64.

public const Int32 MaxAudioChannels

Constant Value

64

MaxFrequencyRatio

Maximum frequency ratio is 1024.

public const Single MaxFrequencyRatio

Constant Value

1024

MaximumSampleRate

Maximum sample rate is 200 kHz.

public const Int32 MaximumSampleRate

Constant Value

200000

MinFrequencyRatio

The minimum frequency ratio is 1/1024.

public const Single MinFrequencyRatio

Constant Value

0,0009765625

MinimumSampleRate

Minimum sample rate is 1000 Hz.

public const Int32 MinimumSampleRate

Constant Value

1000

QuantumDenominator

The denominator of a quantum unit. In 10ms chunks (= 1/100 seconds).

public const Int32 QuantumDenominator

Constant Value

100

Methods

XAudio2(IntPtr ptr, XAudio2Version version)

Initializes a new instance of the XAudio2 class.

protected void XAudio2(IntPtr ptr, XAudio2Version version)

Parameters

ptr

IntPtr

Native pointer of the XAudio2Voice object.

version

XAudio2Version

The 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.

public void CommitChanges(Int32 operationSet)

Parameters

operationSet

Int32

Identifier of the set of operations to be applied. To commit all pending operations, pass CommitAll.

CommitChangesNative(Int32 operationSet)

Atomically applies a set of operations that are tagged with a given identifier.

public abstract Int32 CommitChangesNative(Int32 operationSet)

Parameters

operationSet

Int32

Identifier 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.

public XAudio2MasteringVoice CreateMasteringVoice(Int32 inputChannels, Int32 inputSampleRate)

Parameters

inputChannels

Int32

Number 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

Int32

Sample 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.

save

reset

Drag to pan - Use Mousewheel + Ctrl to zoom

public XAudio2MasteringVoice CreateMasteringVoice(Int32 inputChannels, Int32 inputSampleRate, object device)

Parameters

inputChannels

Int32

Number 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

Int32

Sample 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

object

Identifier 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.

public XAudio2MasteringVoice CreateMasteringVoice(Int32 inputChannels, Int32 inputSampleRate, object device, Nullable effectChain, AudioStreamCategory streamCategory)

Parameters

inputChannels

Int32

Number 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

Int32

Sample 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

object

Identifier 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

Nullable

EffectChain structure that describes an effect chain to use in the mastering voice, or NULL to use no effects.

streamCategory

AudioStreamCategory

The audio stream category to use for this mastering voice.

Returns

If successful, returns a new XAudio2MasteringVoice object.

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

Int32

Number 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

Int32

Sample 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

Int32

Flags that specify the behavior of the mastering voice. Must be 0.

device

object

Identifier 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

Nullable

EffectChain structure that describes an effect chain to use in the mastering voice, or NULL to use no effects.

streamCategory

AudioStreamCategory

The audio stream category to use for this mastering voice.

Returns

HRESULT

public IntPtr CreateMasteringVoicePtr(Int32 inputChannels, Int32 inputSampleRate, Int32 flags, object device, Nullable effectChain, AudioStreamCategory streamCategory)

Parameters

inputChannels

Int32

Number 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

Int32

Sample 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

Int32

Flags that specify the behavior of the mastering voice. Must be 0.

device

object

Identifier 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

Nullable

EffectChain structure that describes an effect chain to use in the mastering voice, or NULL to use no effects.

streamCategory

AudioStreamCategory

The 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

WaveFormat

Pointer 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.

public XAudio2SourceVoice CreateSourceVoice(WaveFormat sourceFormat, VoiceFlags flags)

Parameters

sourceFormat

WaveFormat

Pointer 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

VoiceFlags

VoiceFlags 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

WaveFormat

Pointer 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

VoiceFlags

VoiceFlags 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

Single

Highest allowable frequency ratio that can be set on this voice. The value for this argument must be between MinFrequencyRatio and MaxFrequencyRatio.

voiceCallback

IXAudio2VoiceCallback

Client-provided callback interface, IXAudio2VoiceCallback. This parameter is optional and can be null.

sendList

Nullable

List 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

Nullable

List 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

IntPtr

Pointer 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

VoiceFlags

VoiceFlags 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

Single

Highest allowable frequency ratio that can be set on this voice. The value for this argument must be between MinFrequencyRatio and MaxFrequencyRatio.

voiceCallback

IXAudio2VoiceCallback

Client-provided callback interface, IXAudio2VoiceCallback. This parameter is optional and can be null.

sendList

Nullable

List 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

Nullable

List 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

WaveFormat

Pointer 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

VoiceFlags

VoiceFlags 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

Single

Highest allowable frequency ratio that can be set on this voice. The value for this argument must be between MinFrequencyRatio and MaxFrequencyRatio.

voiceCallback

IXAudio2VoiceCallback

Client-provided callback interface, IXAudio2VoiceCallback. This parameter is optional and can be null.

sendList

Nullable

List 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

Nullable

List 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.

public XAudio2SubmixVoice CreateSubmixVoice(Int32 inputChannels, Int32 inputSampleRate, VoiceFlags flags)

Parameters

inputChannels

Int32

Number of channels in the input audio data of the submix voice. The inputChannels must be less than or equal to MaxAudioChannels.

inputSampleRate

Int32

Sample 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

VoiceFlags

Flags that specify the behavior of the submix voice. It can be None or UseFilter.

Returns

On success, returns a new XAudio2SubmixVoice object.

public XAudio2SubmixVoice CreateSubmixVoice(Int32 inputChannels, Int32 inputSampleRate, VoiceFlags flags, Int32 processingStage, Nullable sendList, Nullable effectChain)

Parameters

inputChannels

Int32

Number of channels in the input audio data of the submix voice. The inputChannels must be less than or equal to MaxAudioChannels.

inputSampleRate

Int32

Sample 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

VoiceFlags

Flags that specify the behavior of the submix voice. It can be None or UseFilter.

processingStage

Int32

An 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

Nullable

List 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

Nullable

List 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.

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

Int32

Number of channels in the input audio data of the submix voice. The inputChannels must be less than or equal to MaxAudioChannels.

inputSampleRate

Int32

Sample 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

VoiceFlags

Flags that specify the behavior of the submix voice. It can be None or UseFilter.

processingStage

Int32

An 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

Nullable

List 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

Nullable

List of EffectChain structures that describe an effect chain to use in the submix voice. This parameter is optional and can be null.

Returns

HRESULT

public IntPtr CreateSubmixVoicePtr(Int32 inputChannels, Int32 inputSampleRate, VoiceFlags flags, Int32 processingStage, Nullable sendList, Nullable effectChain)

Parameters

inputChannels

Int32

Number of channels in the input audio data of the submix voice. The inputChannels must be less than or equal to MaxAudioChannels.

inputSampleRate

Int32

Sample 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

VoiceFlags

Flags that specify the behavior of the submix voice. It can be None or UseFilter.

processingStage

Int32

An 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

Nullable

List 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

Nullable

List 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

Nullable

The 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.

public void RegisterForCallbacks(IXAudio2EngineCallback callback)

Parameters

callback

IXAudio2EngineCallback

IXAudio2EngineCallback object to add to 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

IXAudio2EngineCallback

IXAudio2EngineCallback 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

DebugConfiguration

DebugConfiguration structure that contains the new debug configuration.

public abstract void SetDebugConfigurationNative(DebugConfiguration debugConfiguration, IntPtr reserved)

Parameters

debugConfiguration

DebugConfiguration

DebugConfiguration structure that contains the new debug configuration.

reserved

IntPtr

Reserved parameter. Must me NULL.

Returns

HRESULT

StartEngine()

Starts the audio processing thread.

public void StartEngine()

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

IXAudio2EngineCallback

IXAudio2EngineCallback 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.

Properties

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; }