Exemple #1
0
        static private void ApplyEffects(ref IWaveSource src, SoundEffectSettings ap)   // ap may be null
        {
            if (ap != null && ap.Any)
            {
                int extend = 0;
                if (ap.echoenabled)
                {
                    extend = ap.echodelay * 2;
                }
                if (ap.chorusenabled)
                {
                    extend = Math.Max(extend, 50);
                }
                if (ap.reverbenabled)
                {
                    extend = Math.Max(extend, 50);
                }

                if (extend > 0)
                {
                    //System.Diagnostics.Debug.WriteLine("Extend by " + extend + " ms due to effects");
                    src = src.AppendSource(x => new ExtendWaveSource(x, extend));
                }

                if (ap.chorusenabled)
                {
                    src = src.AppendSource(x => new DmoChorusEffect(x)
                    {
                        WetDryMix = ap.chorusmix, Feedback = ap.chorusfeedback, Delay = ap.chorusdelay, Depth = ap.chorusdepth
                    });
                }

                if (ap.reverbenabled)
                {
                    src = src.AppendSource(x => new DmoWavesReverbEffect(x)
                    {
                        InGain = 0, ReverbMix = ap.reverbmix, ReverbTime = ((float)ap.reverbtime) / 1000.0F, HighFrequencyRTRatio = ((float)ap.reverbhfratio) / 1000.0F
                    });
                }

                if (ap.distortionenabled)
                {
                    src = src.AppendSource(x => new DmoDistortionEffect(x)
                    {
                        Gain = ap.distortiongain, Edge = ap.distortionedge, PostEQCenterFrequency = ap.distortioncentrefreq, PostEQBandwidth = ap.distortionfreqwidth
                    });
                }

                if (ap.gargleenabled)
                {
                    src = src.AppendSource(x => new DmoGargleEffect(x)
                    {
                        RateHz = ap.garglefreq
                    });
                }

                if (ap.echoenabled)
                {
                    src = src.AppendSource(x => new DmoEchoEffect(x)
                    {
                        WetDryMix = ap.echomix, Feedback = ap.echofeedback, LeftDelay = ap.echodelay, RightDelay = ap.echodelay
                    });
                }

                if (ap.pitchshiftenabled)
                {
                    ISampleSource srs = src.ToSampleSource();
                    srs = srs.AppendSource(x => new PitchShifter(x)
                    {
                        PitchShiftFactor = ((float)ap.pitchshift) / 100.0F
                    });
                    src = srs.ToWaveSource();
                }
            }
        }