我想不通,如何通过 Submixvoice 路由 SourceVoice?网上的 C++ 示例建议我可以使用效果链,但是没有 EffectChain 构造函数或接受声音的函数。以下是基础知识:
private XAudio2 xa = null;
private MasteringVoice mv = null;
private SourceVoice sv = null;
private SubmixVoice sm = null;
private SoundStream ss = null;
private AudioBuffer ab = null;
private WaveFormat wf = null;
private FilterParameters fp;
private bool sv_playing = false;
private void button1_Click(object sender, EventArgs e)
{
if (null == xa)
{
xa = new XAudio2();
mv = new MasteringVoice(xa);
var nativefilestream = new NativeFileStream(
@"c:\dev\beat_loop.wav",
NativeFileMode.Open,
NativeFileAccess.Read,
NativeFileShare.Read);
ss = new SoundStream(nativefilestream);
wf = ss.Format;
ab = new AudioBuffer
{
Stream = ss.ToDataStream(),
AudioBytes = (int)ss.Length,
Flags = BufferFlags.EndOfStream
};
fp.Frequency = 1.0f;
fp.OneOverQ = 1.0f;
fp.Type = FilterType.LowPassFilter;
}
if (sv_playing)
{
if (null != sv)
{
sv.Stop();
sv.Dispose();
sv = null;
}
}
if (null == sv)
{
sv = new SourceVoice(xa, wf,VoiceFlags.None,1.0f, true);
sv.SubmitSourceBuffer(ab, ss.DecodedPacketsInfo);
sv.BufferEnd += new Action<IntPtr>(sv_BufferEnd);
sm = new SubmixVoice(xa, ss.Format.Channels, ss.Format.SampleRate, VoiceSendFlags.UseFilter,10);
sm.SetFilterParameters(fp);
// HOW DO I TELL sv TO ROUTE THROUGH sm??
sv.Start();
sv_playing = true;
}
}