我无法弄清楚,我如何通过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:devbeat_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;
}
}
您可以使用VoiceSendDescriptor类将源声音路由到子混音
VoiceSendDescriptor vs = new VoiceSendDescriptor(VoiceSendFlags.None, sm);
sv.SetOutputVoices(vs);