Beispiel #1
0
        public override void Run()
        {
            Channel channel = System.PlaySound(sound, mainGroup, true);

            var channelHead = channel.GetDSP(ChannelControlDSPIndex.DspHead);

            DspConnection reverbConnection = reverbUnit.AddInput(channelHead, DSPConnectionType.Send);

            channel.Paused = false;

            do
            {
                OnUpdate();

                System.Update();

                reverbConnection.Mix = wetVolume;
                mainGroup.Volume     = dryVolume;

                DrawText("==================================================");
                DrawText("Convolution Example.");
                DrawText("Copyright (c) Firelight Technologies 2004-2018.");
                DrawText("==================================================");
                DrawText("Press Up and Down arrows to change dry mix");
                DrawText("Press Left and Right Arrows to change wet mix");
                DrawText($"Wet mix: {wetVolume}, Dry mix: {dryVolume}");
                DrawText("Press Esc to Quit.");

                Sleep(50);
            }while (!ShouldEndExample);
        }
        public override void Initialize()
        {
            base.Initialize();

            //In this special case, we want to use stereo output and not worry about
            //varying matrix sizes depending on user speaker mode.
            System.SetSoftwareFormat(48_000, SpeakerMode.Stereo, 0);

            //Initialize FMOD
            System.Init(32);

            sound = System.CreateSound(MediaPath("drumloop.wav"), Mode.Loop_Normal);

            channel = System.PlaySound(sound);

            //Create DSP Effects

            lowPass = System.CreateDSPByType(DSPType.LowPass);
            lowPass.SetParameterFloat(0, 1000f); //Lowpass Cutoff
            lowPass.SetParameterFloat(1, 4f);    //Lowpass Resonance

            highPass = System.CreateDSPByType(DSPType.HighPass);
            highPass.SetParameterFloat(0, 4000f); //Highpass Cutoff
            highPass.SetParameterFloat(1, 4f);    //Highpass Resonance

            //Build the DSP Network

            ///When a sound is played, a subnetwork is set up in the DSP Network which looks like this.
            ///Wavetable is the drumloop sound, and it feeds its data from the right to left

            //[DSPHEAD]<------------[DSPCHANNELMIXER]<------------[CHANNEL HEAD]<------------[WAVETABLE - DRUMLOOP.WAV]
            Dsp head, channelMixer;

            ChannelGroup masterGroup = System.MasterChannelGroup;

            head         = masterGroup.GetDSP(ChannelControlDSPIndex.DspHead);
            channelMixer = head.GetInput(0).Dsp;

            ///Now disconnect channel dsp head from the wavetable to look like this.
            //[DSPHEAD]             [DSPCHANNELMIXER]<------------[CHANNEL HEAD]<------------[WAVETABLE - DRUMLOOP.WAV]

            head.DisconnectFrom(channelMixer);

            ///Now connect the 2 effects to the channel DSP head.
            ///Store the 2 connections this makes to we can set their matrix later

            /*
             *        [DSPLOWPASS]
             *       /x
             * [DSPHEAD]             [DSPCHANNELMIXER]<------------[CHANNEL HEAD]<------------[WAVETABLE - DRUMLOOP.WAV]
             *       \y
             *        [DSPHIGHPASS]
             */
            DspConnection lowPassConnection, highPassConnection;

            lowPassConnection  = head.AddInput(lowPass);
            highPassConnection = head.AddInput(highPass);

            ///Now connect the channelMixer to the 2 effects

            /*
             *        [DSPLOWPASS]
             *       /x          \
             * [DSPHEAD]             [DSPCHANNELMIXER]<------------[CHANNEL HEAD]<------------[WAVETABLE - DRUMLOOP.WAV]
             *       \y          /
             *        [DSPHIGHPASS]
             */

            //Ignore the connections, we don't care about them
            lowPass.AddInput(channelMixer);
            highPass.AddInput(channelMixer);

            //Now the drumloop will be twice as loud, because it is being split into 2, then recombined at the end.
            //What we really want is th only feed the head<-lowpass through the left speaker for that effect, and
            //head<-highpass to the right speaker for that effect.
            //We can do that simply by setting the pan, or speaker matrix of the connections.

            /*
             *        [DSPLOWPASS]
             *       /x=1,0      \
             * [DSPHEAD]             [DSPCHANNELMIXER]<------------[CHANNEL HEAD]<------------[WAVETABLE - DRUMLOOP.WAV]
             *       \y=0,1      /
             *        [DSPHIGHPASS]
             */

            float[] lowPassMatrix = new float[2 * 2] {
                1, 0, 0, 0
            };
            float[] highPassMatrix = new float[2 * 2] {
                0, 0, 0, 1
            };

            //Upgrade the signal coming from the channel mixer from Mono to Stereo. Otherwise the lowpass and highpass will get mono signals.
            channelMixer.SetChannelFormat(default, 0, SpeakerMode.Stereo);