I'm using SharpDX and XAudio2 in a Windows Store app. I'm trying to create a custom XAPO and I can't even get started.
OnNavigatedTo method for the app:
protected override void OnNavigatedTo(NavigationEventArgs e)
{
XAudio2 engine = new XAudio2();
MasteringVoice master = new MasteringVoice(engine);
NativeFileStream fileStream = new NativeFileStream(@"Assets\sample.wav", NativeFileMode.Open, NativeFileAccess.Read);
SoundStream soundStream = new SoundStream(fileStream);
SourceVoice source = new SourceVoice(engine, soundStream.Format);
AudioBuffer audioBuffer = new AudioBuffer()
{
Stream = soundStream.ToDataStream(),
AudioBytes = (int)soundStream.Length,
Flags = SharpDX.XAudio2.BufferFlags.EndOfStream
};
EmptyEffect customEffect = new EmptyEffect();
EffectDescriptor effectDescriptor = new EffectDescriptor(customEffect);
source.SetEffectChain(effectDescriptor);
source.EnableEffect(0);
source.SubmitSourceBuffer(audioBuffer, soundStream.DecodedPacketsInfo);
source.Start();
}
Empty Custom XAPO:
[StructLayout(LayoutKind.Sequential)]
public struct ModulatorParam
{
}
public class EmptyEffect : AudioProcessorBase<ModulatorParam>
{
public EmptyEffect()
{
RegistrationProperties = new RegistrationProperties()
{
Clsid = Utilities.GetGuidFromType(typeof(EmptyEffect)),
CopyrightInfo = "Copyright",
FriendlyName = "Modulator",
MaxInputBufferCount = 1,
MaxOutputBufferCount = 1,
MinInputBufferCount = 1,
MinOutputBufferCount = 1,
Flags = PropertyFlags.Default
};
}
public override void Process(BufferParameters[] inputProcessParameters, BufferParameters[] outputProcessParameters, bool isEnabled)
{
}
}
If I remove the line to enable the effect then the empty process method never runs. If I keep it in, the following useless error occurs:
This turned out to be an issue with the SharpDX implementation. See Issue 272 on the SharpDX Google Code page:
Issue: The errors are preventing both Effects and SubMixVoices not to work.
File: Voice.cs
Cause: The EffectChain // SendList always gets resetet after being set by the function call. Both cases caused by missing else surrounding the following lines:
SetOutputVoices((VoiceSendDescriptors?)null); in function SetOutputVoices
and
SetEffectChain((EffectChain?)null); in function SetEffectChain
Solved by downloading the latest source that includes this fix and building the binaries from scratch.