Question

I can't figure this out, how do I route a SourceVoice through a Submixvoice? The C++ examples on the net suggest I can use effect chains, but there's no EffectChain constructor or functions that accept voices. Here're the basics:

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;
        }
    }
Was it helpful?

Solution

You can use the VoiceSendDescriptor class to route source voices to submix voices

VoiceSendDescriptor vs = new VoiceSendDescriptor(VoiceSendFlags.None, sm);
sv.SetOutputVoices(vs);
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top