Example #1
0
    void OnAudioFilterRead(float[] data, int channels)
    {
        if (channels != 2)
        {
            error = "This filter only supports stereo audio (given:" + channels + ")";
            return;
        }

        for (var i = 0; i < data.Length; i += 2)
        {
            var input = 0.5f * (data [i] + data [i + 1]);

            var temp0 = allpassCoeff * allpass1.Last;
            temp0 += input;
            temp0  = allpass1.Tick(temp0) - allpassCoeff * temp0;

            var temp1 = allpassCoeff * allpass2.Last;
            temp1 += temp0;
            temp1  = allpass2.Tick(temp1) - allpassCoeff * temp1;

            var out1 = comb1.Tick(temp1 + comb1Coeff * comb1.Last);
            var out2 = comb2.Tick(temp1 + comb2Coeff * comb2.Last);

            out1 = wetMix * out1 + (1.0f - wetMix) * data [i];
            out2 = wetMix * out2 + (1.0f - wetMix) * data [i + 1];

            data [i]     = out1;
            data [i + 1] = out2;
        }
    }
    void OnAudioFilterRead(float[] data, int channels)
    {
        for (int i = 0; i < data.Length; i += 2)
        {
            var smpL = data [i] * gain;
            var smpR = data [i + 1] * gain;

            smpL = left.Tick(smpL);
            smpR = right.Tick(smpR);

            var input = 0.5f * (smpL + smpR);
            var temp0 = allpassCoeff * allpass1.Last;
            temp0 += input;
            temp0  = allpass1.Tick(temp0) - allpassCoeff * temp0;
            var temp1 = allpassCoeff * allpass2.Last;
            temp1 += temp0;
            temp1  = allpass2.Tick(temp1) - allpassCoeff * temp1;
            var out1 = comb1.Tick(temp1 + comb1Coeff * comb1.Last);
            var out2 = comb2.Tick(temp1 + comb2Coeff * comb2.Last);
            out1 = fadeMix * out1 + (1.0f - fadeMix) * smpL;
            out2 = fadeMix * out2 + (1.0f - fadeMix) * smpR;
            smpL = out1;
            smpR = out2;

            smpL = eL.Process(smpL);
            smpR = eR.Process(smpR);

            data [i]     = smpL < -1?-1:smpL > 1?1:smpL;
            data [i + 1] = smpR < -1?-1:smpR > 1?1:smpR;
        }
    }
        // Tick function.
        public StereoFrame Tick(float input)
        {
            const float AllpassCoeff = 0.7f;

            var temp0 = AllpassCoeff * allpassLine1.NextOut;

            temp0 += input;
            temp0  = allpassLine1.Tick(temp0) - AllpassCoeff * temp0;

            var temp1 = AllpassCoeff * allpassLine2.NextOut;

            temp1 += temp0;
            temp1  = allpassLine2.Tick(temp1) - AllpassCoeff * temp1;

            var out1 = combLine1.Tick(temp1 + combCoeff1 * combLine1.NextOut);
            var out2 = combLine2.Tick(temp1 + combCoeff2 * combLine2.NextOut);

            return(new StereoFrame(out1, out2));
        }