在Windows 8应用程序中使用SharpDX XAudio2自定义XAPO

时间:2012-10-23 17:15:33

标签: c# windows-8 sharpdx xaudio2

我在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)
  {
  }
}

如果我删除该行以启用效果,则空进程方法永远不会运行。如果我保留它,会发生以下无用错误:

The Error I receive

1 个答案:

答案 0 :(得分:0)

这是SharpDX实施的一个问题。请参阅SharpDX Google代码页上的Issue 272

  

问题:错误阻止了效果和SubMixVoices   工作

     

文件: Voice.cs

     

原因: EffectChain // SendList在设置后始终会重新设置   通过函数调用。这两种情况都是由于缺少其他环境造   以下几行:

     

SetOutputVoices(?(VoiceSendDescriptors)NULL);在功能上   SetOutputVoices

     

     

SetEffectChain((EffectChain)空?);在函数SetEffectChain

通过下载包含此修复程序的最新源代码并从头开始构建二进制文件来解决此问题。