我在 Windows 应用商店应用程序中使用 SharpDX 和 XAudio2。我正在尝试创建自定义 XAPO,但我什至无法开始。
应用程序的 OnNavigatedTo 方法:
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();
}
空自定义 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)
{
}
}
如果我删除该行以启用效果,则空处理方法永远不会运行。如果我保留它,则会发生以下无用的错误: