How to: Use an XAPO in XAudio2
This topic shows you how to use an effect created with the XAPO API in an XAudio2 effect chain.
Create the XAPO as described in How to: Create an XAPO.
You can also implement run-time parameter functionality as described in How to: Add Run-time Parameter Support to an XAPO.
Create an instance of the XAPO.
IUnknown * pXAPO; pXAPO = new SimpleXAPO();
Populate an XAUDIO2_EFFECT_DESCRIPTOR structure with data.
XAUDIO2_EFFECT_DESCRIPTOR descriptor; descriptor.InitialState = true; descriptor.OutputChannels = 1; descriptor.pEffect = pXAPO;
Populate an XAUDIO2_EFFECT_CHAIN structure with data.
XAUDIO2_EFFECT_CHAIN chain; chain.EffectCount = 1; chain.pEffectDescriptors = &descriptor;
Apply the effect chain to an XAudio2 voice with the SetEffectChain function.
pVoice->SetEffectChain(&chain);
Note
An effect chain can also be applied to a voice when the voice is created by passing the chain as a parameter to IXAudio2::CreateSourceVoice, IXAudio2::CreateSubmixVoice, or IXAudio2::CreateMasteringVoice.
Release the effect with IUnknown::Release.
When you create an XAPO, it will have a reference count of 1. When the XAPO is passed to XAudio2 with SetEffectChain, XAudio2 increments the reference count on the XAPO. Releasing the client's reference to the XAPO allows XAudio2 to take ownership of the XAPO. If XAudio2 has the only reference to the XAPO, it will be disposed of when it is no longer being used by XAudio2. If the client code needs to maintain a reference to the XAPO for later reuse, for example, you should skip this step.
pXAPO->Release();
Populate the parameter structure, if any, associated with the effect. In this case, the percentage of full strength at which the effect should be applied.
XAPO_PARAMETERS XAPOParameters; XAPOParameters.Level = 0.75;
Pass the effect parameter structure to the effect by calling the SetEffectParameters function on the voice to which the effect is attached.
hr = pVoice->SetEffectParameters( 0, &XAPOParameters, sizeof( XAPO_PARAMETERS ) );
Related topics