airwindows/plugins/MacVST/Chamber/source/ChamberProc.cpp
2022-11-21 09:20:21 -05:00

520 lines
23 KiB
C++
Executable file

/* ========================================
* Chamber - Chamber.h
* Copyright (c) 2016 airwindows, Airwindows uses the MIT license
* ======================================== */
#ifndef __Chamber_H
#include "Chamber.h"
#endif
void Chamber::processReplacing(float **inputs, float **outputs, VstInt32 sampleFrames)
{
float* in1 = inputs[0];
float* in2 = inputs[1];
float* out1 = outputs[0];
float* out2 = outputs[1];
double overallscale = 1.0;
overallscale /= 44100.0;
overallscale *= getSampleRate();
int cycleEnd = floor(overallscale);
if (cycleEnd < 1) cycleEnd = 1;
if (cycleEnd > 4) cycleEnd = 4;
//this is going to be 2 for 88.1 or 96k, 3 for silly people, 4 for 176 or 192k
if (cycle > cycleEnd-1) cycle = cycleEnd-1; //sanity check
double size = (pow(A,2)*0.9)+0.1;
double regen = (1.0-(pow(1.0-B,6)))*0.123;
double highpass = (pow(C,2.0))/sqrt(overallscale);
double lowpass = (1.0-pow(D,2.0))/sqrt(overallscale);
double interpolate = size*0.381966011250105;
double wet = E*2.0;
double dry = 2.0 - wet;
if (wet > 1.0) wet = 1.0;
if (wet < 0.0) wet = 0.0;
if (dry > 1.0) dry = 1.0;
if (dry < 0.0) dry = 0.0;
//this reverb makes 50% full dry AND full wet, not crossfaded.
//that's so it can be on submixes without cutting back dry channel when adjusted:
//unless you go super heavy, you are only adjusting the added verb loudness.
delayE = 19900*size;
delayF = delayE*0.618033988749894848204586;
delayG = delayF*0.618033988749894848204586;
delayH = delayG*0.618033988749894848204586;
delayA = delayH*0.618033988749894848204586;
delayB = delayA*0.618033988749894848204586;
delayC = delayB*0.618033988749894848204586;
delayD = delayC*0.618033988749894848204586;
delayI = delayD*0.618033988749894848204586;
delayJ = delayI*0.618033988749894848204586;
delayK = delayJ*0.618033988749894848204586;
delayL = delayK*0.618033988749894848204586;
//initially designed around the Fibonnaci series, Chamber uses
//delay coefficients that are all related to the Golden Ratio,
//Turns out that as you continue to sustain them, it turns from a
//chunky slapback effect into a smoother reverb tail that can
//sustain infinitely.
while (--sampleFrames >= 0)
{
double inputSampleL = *in1;
double inputSampleR = *in2;
if (fabs(inputSampleL)<1.18e-23) inputSampleL = fpdL * 1.18e-17;
if (fabs(inputSampleR)<1.18e-23) inputSampleR = fpdR * 1.18e-17;
double drySampleL = inputSampleL;
double drySampleR = inputSampleR;
iirCL = (iirCL*(1.0-highpass))+(inputSampleL*highpass); inputSampleL -= iirCL;
iirCR = (iirCR*(1.0-highpass))+(inputSampleR*highpass); inputSampleR -= iirCR;
//initial highpass
iirAL = (iirAL*(1.0-lowpass))+(inputSampleL*lowpass); inputSampleL = iirAL;
iirAR = (iirAR*(1.0-lowpass))+(inputSampleR*lowpass); inputSampleR = iirAR;
//initial filter
cycle++;
if (cycle == cycleEnd) { //hit the end point and we do a reverb sample
feedbackAL = (feedbackAL*(1.0-interpolate))+(previousAL*interpolate); previousAL = feedbackAL;
feedbackBL = (feedbackBL*(1.0-interpolate))+(previousBL*interpolate); previousBL = feedbackBL;
feedbackCL = (feedbackCL*(1.0-interpolate))+(previousCL*interpolate); previousCL = feedbackCL;
feedbackDL = (feedbackDL*(1.0-interpolate))+(previousDL*interpolate); previousDL = feedbackDL;
feedbackAR = (feedbackAR*(1.0-interpolate))+(previousAR*interpolate); previousAR = feedbackAR;
feedbackBR = (feedbackBR*(1.0-interpolate))+(previousBR*interpolate); previousBR = feedbackBR;
feedbackCR = (feedbackCR*(1.0-interpolate))+(previousCR*interpolate); previousCR = feedbackCR;
feedbackDR = (feedbackDR*(1.0-interpolate))+(previousDR*interpolate); previousDR = feedbackDR;
aIL[countI] = inputSampleL + (feedbackAL * regen);
aJL[countJ] = inputSampleL + (feedbackBL * regen);
aKL[countK] = inputSampleL + (feedbackCL * regen);
aLL[countL] = inputSampleL + (feedbackDL * regen);
aIR[countI] = inputSampleR + (feedbackAR * regen);
aJR[countJ] = inputSampleR + (feedbackBR * regen);
aKR[countK] = inputSampleR + (feedbackCR * regen);
aLR[countL] = inputSampleR + (feedbackDR * regen);
countI++; if (countI < 0 || countI > delayI) countI = 0;
countJ++; if (countJ < 0 || countJ > delayJ) countJ = 0;
countK++; if (countK < 0 || countK > delayK) countK = 0;
countL++; if (countL < 0 || countL > delayL) countL = 0;
double outIL = aIL[countI-((countI > delayI)?delayI+1:0)];
double outJL = aJL[countJ-((countJ > delayJ)?delayJ+1:0)];
double outKL = aKL[countK-((countK > delayK)?delayK+1:0)];
double outLL = aLL[countL-((countL > delayL)?delayL+1:0)];
double outIR = aIR[countI-((countI > delayI)?delayI+1:0)];
double outJR = aJR[countJ-((countJ > delayJ)?delayJ+1:0)];
double outKR = aKR[countK-((countK > delayK)?delayK+1:0)];
double outLR = aLR[countL-((countL > delayL)?delayL+1:0)];
//first block: now we have four outputs
aAL[countA] = (outIL - (outJL + outKL + outLL));
aBL[countB] = (outJL - (outIL + outKL + outLL));
aCL[countC] = (outKL - (outIL + outJL + outLL));
aDL[countD] = (outLL - (outIL + outJL + outKL));
aAR[countA] = (outIR - (outJR + outKR + outLR));
aBR[countB] = (outJR - (outIR + outKR + outLR));
aCR[countC] = (outKR - (outIR + outJR + outLR));
aDR[countD] = (outLR - (outIR + outJR + outKR));
countA++; if (countA < 0 || countA > delayA) countA = 0;
countB++; if (countB < 0 || countB > delayB) countB = 0;
countC++; if (countC < 0 || countC > delayC) countC = 0;
countD++; if (countD < 0 || countD > delayD) countD = 0;
double outAL = aAL[countA-((countA > delayA)?delayA+1:0)];
double outBL = aBL[countB-((countB > delayB)?delayB+1:0)];
double outCL = aCL[countC-((countC > delayC)?delayC+1:0)];
double outDL = aDL[countD-((countD > delayD)?delayD+1:0)];
double outAR = aAR[countA-((countA > delayA)?delayA+1:0)];
double outBR = aBR[countB-((countB > delayB)?delayB+1:0)];
double outCR = aCR[countC-((countC > delayC)?delayC+1:0)];
double outDR = aDR[countD-((countD > delayD)?delayD+1:0)];
//second block: four more outputs
aEL[countE] = (outAL - (outBL + outCL + outDL));
aFL[countF] = (outBL - (outAL + outCL + outDL));
aGL[countG] = (outCL - (outAL + outBL + outDL));
aHL[countH] = (outDL - (outAL + outBL + outCL));
aER[countE] = (outAR - (outBR + outCR + outDR));
aFR[countF] = (outBR - (outAR + outCR + outDR));
aGR[countG] = (outCR - (outAR + outBR + outDR));
aHR[countH] = (outDR - (outAR + outBR + outCR));
countE++; if (countE < 0 || countE > delayE) countE = 0;
countF++; if (countF < 0 || countF > delayF) countF = 0;
countG++; if (countG < 0 || countG > delayG) countG = 0;
countH++; if (countH < 0 || countH > delayH) countH = 0;
double outEL = aEL[countE-((countE > delayE)?delayE+1:0)];
double outFL = aFL[countF-((countF > delayF)?delayF+1:0)];
double outGL = aGL[countG-((countG > delayG)?delayG+1:0)];
double outHL = aHL[countH-((countH > delayH)?delayH+1:0)];
double outER = aER[countE-((countE > delayE)?delayE+1:0)];
double outFR = aFR[countF-((countF > delayF)?delayF+1:0)];
double outGR = aGR[countG-((countG > delayG)?delayG+1:0)];
double outHR = aHR[countH-((countH > delayH)?delayH+1:0)];
//third block: final outputs
feedbackAL = (outEL - (outFL + outGL + outHL));
feedbackBL = (outFL - (outEL + outGL + outHL));
feedbackCL = (outGL - (outEL + outFL + outHL));
feedbackDL = (outHL - (outEL + outFL + outGL));
feedbackAR = (outER - (outFR + outGR + outHR));
feedbackBR = (outFR - (outER + outGR + outHR));
feedbackCR = (outGR - (outER + outFR + outHR));
feedbackDR = (outHR - (outER + outFR + outGR));
//which we need to feed back into the input again, a bit
inputSampleL = (outEL + outFL + outGL + outHL)/8.0;
inputSampleR = (outER + outFR + outGR + outHR)/8.0;
//and take the final combined sum of outputs
if (cycleEnd == 4) {
lastRefL[0] = lastRefL[4]; //start from previous last
lastRefL[2] = (lastRefL[0] + inputSampleL)/2; //half
lastRefL[1] = (lastRefL[0] + lastRefL[2])/2; //one quarter
lastRefL[3] = (lastRefL[2] + inputSampleL)/2; //three quarters
lastRefL[4] = inputSampleL; //full
lastRefR[0] = lastRefR[4]; //start from previous last
lastRefR[2] = (lastRefR[0] + inputSampleR)/2; //half
lastRefR[1] = (lastRefR[0] + lastRefR[2])/2; //one quarter
lastRefR[3] = (lastRefR[2] + inputSampleR)/2; //three quarters
lastRefR[4] = inputSampleR; //full
}
if (cycleEnd == 3) {
lastRefL[0] = lastRefL[3]; //start from previous last
lastRefL[2] = (lastRefL[0]+lastRefL[0]+inputSampleL)/3; //third
lastRefL[1] = (lastRefL[0]+inputSampleL+inputSampleL)/3; //two thirds
lastRefL[3] = inputSampleL; //full
lastRefR[0] = lastRefR[3]; //start from previous last
lastRefR[2] = (lastRefR[0]+lastRefR[0]+inputSampleR)/3; //third
lastRefR[1] = (lastRefR[0]+inputSampleR+inputSampleR)/3; //two thirds
lastRefR[3] = inputSampleR; //full
}
if (cycleEnd == 2) {
lastRefL[0] = lastRefL[2]; //start from previous last
lastRefL[1] = (lastRefL[0] + inputSampleL)/2; //half
lastRefL[2] = inputSampleL; //full
lastRefR[0] = lastRefR[2]; //start from previous last
lastRefR[1] = (lastRefR[0] + inputSampleR)/2; //half
lastRefR[2] = inputSampleR; //full
}
if (cycleEnd == 1) {
lastRefL[0] = inputSampleL;
lastRefR[0] = inputSampleR;
}
cycle = 0; //reset
inputSampleL = lastRefL[cycle];
inputSampleR = lastRefR[cycle];
} else {
inputSampleL = lastRefL[cycle];
inputSampleR = lastRefR[cycle];
//we are going through our references now
}
switch (cycleEnd) //multi-pole average using lastRef[] variables
{
case 4:
lastRefL[8] = inputSampleL; inputSampleL = (inputSampleL+lastRefL[7])*0.5;
lastRefL[7] = lastRefL[8]; //continue, do not break
lastRefR[8] = inputSampleR; inputSampleR = (inputSampleR+lastRefR[7])*0.5;
lastRefR[7] = lastRefR[8]; //continue, do not break
case 3:
lastRefL[8] = inputSampleL; inputSampleL = (inputSampleL+lastRefL[6])*0.5;
lastRefL[6] = lastRefL[8]; //continue, do not break
lastRefR[8] = inputSampleR; inputSampleR = (inputSampleR+lastRefR[6])*0.5;
lastRefR[6] = lastRefR[8]; //continue, do not break
case 2:
lastRefL[8] = inputSampleL; inputSampleL = (inputSampleL+lastRefL[5])*0.5;
lastRefL[5] = lastRefL[8]; //continue, do not break
lastRefR[8] = inputSampleR; inputSampleR = (inputSampleR+lastRefR[5])*0.5;
lastRefR[5] = lastRefR[8]; //continue, do not break
case 1:
break; //no further averaging
}
iirBL = (iirBL*(1.0-lowpass))+(inputSampleL*lowpass); inputSampleL = iirBL;
iirBR = (iirBR*(1.0-lowpass))+(inputSampleR*lowpass); inputSampleR = iirBR;
//end filter
if (wet < 1.0) {inputSampleL *= wet; inputSampleR *= wet;}
if (dry < 1.0) {drySampleL *= dry; drySampleR *= dry;}
inputSampleL += drySampleL;
inputSampleR += drySampleR;
//this is our submix verb dry/wet: 0.5 is BOTH at FULL VOLUME
//purpose is that, if you're adding verb, you're not altering other balances
//begin 32 bit stereo floating point dither
int expon; frexpf((float)inputSampleL, &expon);
fpdL ^= fpdL << 13; fpdL ^= fpdL >> 17; fpdL ^= fpdL << 5;
inputSampleL += ((double(fpdL)-uint32_t(0x7fffffff)) * 5.5e-36l * pow(2,expon+62));
frexpf((float)inputSampleR, &expon);
fpdR ^= fpdR << 13; fpdR ^= fpdR >> 17; fpdR ^= fpdR << 5;
inputSampleR += ((double(fpdR)-uint32_t(0x7fffffff)) * 5.5e-36l * pow(2,expon+62));
//end 32 bit stereo floating point dither
*out1 = inputSampleL;
*out2 = inputSampleR;
*in1++;
*in2++;
*out1++;
*out2++;
}
}
void Chamber::processDoubleReplacing(double **inputs, double **outputs, VstInt32 sampleFrames)
{
double* in1 = inputs[0];
double* in2 = inputs[1];
double* out1 = outputs[0];
double* out2 = outputs[1];
double overallscale = 1.0;
overallscale /= 44100.0;
overallscale *= getSampleRate();
int cycleEnd = floor(overallscale);
if (cycleEnd < 1) cycleEnd = 1;
if (cycleEnd > 4) cycleEnd = 4;
//this is going to be 2 for 88.1 or 96k, 3 for silly people, 4 for 176 or 192k
if (cycle > cycleEnd-1) cycle = cycleEnd-1; //sanity check
double size = (pow(A,2)*0.9)+0.1;
double regen = (1.0-(pow(1.0-B,6)))*0.123;
double highpass = (pow(C,2.0))/sqrt(overallscale);
double lowpass = (1.0-pow(D,2.0))/sqrt(overallscale);
double interpolate = size*0.381966011250105;
double wet = E*2.0;
double dry = 2.0 - wet;
if (wet > 1.0) wet = 1.0;
if (wet < 0.0) wet = 0.0;
if (dry > 1.0) dry = 1.0;
if (dry < 0.0) dry = 0.0;
//this reverb makes 50% full dry AND full wet, not crossfaded.
//that's so it can be on submixes without cutting back dry channel when adjusted:
//unless you go super heavy, you are only adjusting the added verb loudness.
delayE = 19900*size;
delayF = delayE*0.618033988749894848204586;
delayG = delayF*0.618033988749894848204586;
delayH = delayG*0.618033988749894848204586;
delayA = delayH*0.618033988749894848204586;
delayB = delayA*0.618033988749894848204586;
delayC = delayB*0.618033988749894848204586;
delayD = delayC*0.618033988749894848204586;
delayI = delayD*0.618033988749894848204586;
delayJ = delayI*0.618033988749894848204586;
delayK = delayJ*0.618033988749894848204586;
delayL = delayK*0.618033988749894848204586;
//initially designed around the Fibonnaci series, Chamber uses
//delay coefficients that are all related to the Golden Ratio,
//Turns out that as you continue to sustain them, it turns from a
//chunky slapback effect into a smoother reverb tail that can
//sustain infinitely.
while (--sampleFrames >= 0)
{
double inputSampleL = *in1;
double inputSampleR = *in2;
if (fabs(inputSampleL)<1.18e-23) inputSampleL = fpdL * 1.18e-17;
if (fabs(inputSampleR)<1.18e-23) inputSampleR = fpdR * 1.18e-17;
double drySampleL = inputSampleL;
double drySampleR = inputSampleR;
iirCL = (iirCL*(1.0-highpass))+(inputSampleL*highpass); inputSampleL -= iirCL;
iirCR = (iirCR*(1.0-highpass))+(inputSampleR*highpass); inputSampleR -= iirCR;
//initial highpass
iirAL = (iirAL*(1.0-lowpass))+(inputSampleL*lowpass); inputSampleL = iirAL;
iirAR = (iirAR*(1.0-lowpass))+(inputSampleR*lowpass); inputSampleR = iirAR;
//initial filter
cycle++;
if (cycle == cycleEnd) { //hit the end point and we do a reverb sample
feedbackAL = (feedbackAL*(1.0-interpolate))+(previousAL*interpolate); previousAL = feedbackAL;
feedbackBL = (feedbackBL*(1.0-interpolate))+(previousBL*interpolate); previousBL = feedbackBL;
feedbackCL = (feedbackCL*(1.0-interpolate))+(previousCL*interpolate); previousCL = feedbackCL;
feedbackDL = (feedbackDL*(1.0-interpolate))+(previousDL*interpolate); previousDL = feedbackDL;
feedbackAR = (feedbackAR*(1.0-interpolate))+(previousAR*interpolate); previousAR = feedbackAR;
feedbackBR = (feedbackBR*(1.0-interpolate))+(previousBR*interpolate); previousBR = feedbackBR;
feedbackCR = (feedbackCR*(1.0-interpolate))+(previousCR*interpolate); previousCR = feedbackCR;
feedbackDR = (feedbackDR*(1.0-interpolate))+(previousDR*interpolate); previousDR = feedbackDR;
aIL[countI] = inputSampleL + (feedbackAL * regen);
aJL[countJ] = inputSampleL + (feedbackBL * regen);
aKL[countK] = inputSampleL + (feedbackCL * regen);
aLL[countL] = inputSampleL + (feedbackDL * regen);
aIR[countI] = inputSampleR + (feedbackAR * regen);
aJR[countJ] = inputSampleR + (feedbackBR * regen);
aKR[countK] = inputSampleR + (feedbackCR * regen);
aLR[countL] = inputSampleR + (feedbackDR * regen);
countI++; if (countI < 0 || countI > delayI) countI = 0;
countJ++; if (countJ < 0 || countJ > delayJ) countJ = 0;
countK++; if (countK < 0 || countK > delayK) countK = 0;
countL++; if (countL < 0 || countL > delayL) countL = 0;
double outIL = aIL[countI-((countI > delayI)?delayI+1:0)];
double outJL = aJL[countJ-((countJ > delayJ)?delayJ+1:0)];
double outKL = aKL[countK-((countK > delayK)?delayK+1:0)];
double outLL = aLL[countL-((countL > delayL)?delayL+1:0)];
double outIR = aIR[countI-((countI > delayI)?delayI+1:0)];
double outJR = aJR[countJ-((countJ > delayJ)?delayJ+1:0)];
double outKR = aKR[countK-((countK > delayK)?delayK+1:0)];
double outLR = aLR[countL-((countL > delayL)?delayL+1:0)];
//first block: now we have four outputs
aAL[countA] = (outIL - (outJL + outKL + outLL));
aBL[countB] = (outJL - (outIL + outKL + outLL));
aCL[countC] = (outKL - (outIL + outJL + outLL));
aDL[countD] = (outLL - (outIL + outJL + outKL));
aAR[countA] = (outIR - (outJR + outKR + outLR));
aBR[countB] = (outJR - (outIR + outKR + outLR));
aCR[countC] = (outKR - (outIR + outJR + outLR));
aDR[countD] = (outLR - (outIR + outJR + outKR));
countA++; if (countA < 0 || countA > delayA) countA = 0;
countB++; if (countB < 0 || countB > delayB) countB = 0;
countC++; if (countC < 0 || countC > delayC) countC = 0;
countD++; if (countD < 0 || countD > delayD) countD = 0;
double outAL = aAL[countA-((countA > delayA)?delayA+1:0)];
double outBL = aBL[countB-((countB > delayB)?delayB+1:0)];
double outCL = aCL[countC-((countC > delayC)?delayC+1:0)];
double outDL = aDL[countD-((countD > delayD)?delayD+1:0)];
double outAR = aAR[countA-((countA > delayA)?delayA+1:0)];
double outBR = aBR[countB-((countB > delayB)?delayB+1:0)];
double outCR = aCR[countC-((countC > delayC)?delayC+1:0)];
double outDR = aDR[countD-((countD > delayD)?delayD+1:0)];
//second block: four more outputs
aEL[countE] = (outAL - (outBL + outCL + outDL));
aFL[countF] = (outBL - (outAL + outCL + outDL));
aGL[countG] = (outCL - (outAL + outBL + outDL));
aHL[countH] = (outDL - (outAL + outBL + outCL));
aER[countE] = (outAR - (outBR + outCR + outDR));
aFR[countF] = (outBR - (outAR + outCR + outDR));
aGR[countG] = (outCR - (outAR + outBR + outDR));
aHR[countH] = (outDR - (outAR + outBR + outCR));
countE++; if (countE < 0 || countE > delayE) countE = 0;
countF++; if (countF < 0 || countF > delayF) countF = 0;
countG++; if (countG < 0 || countG > delayG) countG = 0;
countH++; if (countH < 0 || countH > delayH) countH = 0;
double outEL = aEL[countE-((countE > delayE)?delayE+1:0)];
double outFL = aFL[countF-((countF > delayF)?delayF+1:0)];
double outGL = aGL[countG-((countG > delayG)?delayG+1:0)];
double outHL = aHL[countH-((countH > delayH)?delayH+1:0)];
double outER = aER[countE-((countE > delayE)?delayE+1:0)];
double outFR = aFR[countF-((countF > delayF)?delayF+1:0)];
double outGR = aGR[countG-((countG > delayG)?delayG+1:0)];
double outHR = aHR[countH-((countH > delayH)?delayH+1:0)];
//third block: final outputs
feedbackAL = (outEL - (outFL + outGL + outHL));
feedbackBL = (outFL - (outEL + outGL + outHL));
feedbackCL = (outGL - (outEL + outFL + outHL));
feedbackDL = (outHL - (outEL + outFL + outGL));
feedbackAR = (outER - (outFR + outGR + outHR));
feedbackBR = (outFR - (outER + outGR + outHR));
feedbackCR = (outGR - (outER + outFR + outHR));
feedbackDR = (outHR - (outER + outFR + outGR));
//which we need to feed back into the input again, a bit
inputSampleL = (outEL + outFL + outGL + outHL)/8.0;
inputSampleR = (outER + outFR + outGR + outHR)/8.0;
//and take the final combined sum of outputs
if (cycleEnd == 4) {
lastRefL[0] = lastRefL[4]; //start from previous last
lastRefL[2] = (lastRefL[0] + inputSampleL)/2; //half
lastRefL[1] = (lastRefL[0] + lastRefL[2])/2; //one quarter
lastRefL[3] = (lastRefL[2] + inputSampleL)/2; //three quarters
lastRefL[4] = inputSampleL; //full
lastRefR[0] = lastRefR[4]; //start from previous last
lastRefR[2] = (lastRefR[0] + inputSampleR)/2; //half
lastRefR[1] = (lastRefR[0] + lastRefR[2])/2; //one quarter
lastRefR[3] = (lastRefR[2] + inputSampleR)/2; //three quarters
lastRefR[4] = inputSampleR; //full
}
if (cycleEnd == 3) {
lastRefL[0] = lastRefL[3]; //start from previous last
lastRefL[2] = (lastRefL[0]+lastRefL[0]+inputSampleL)/3; //third
lastRefL[1] = (lastRefL[0]+inputSampleL+inputSampleL)/3; //two thirds
lastRefL[3] = inputSampleL; //full
lastRefR[0] = lastRefR[3]; //start from previous last
lastRefR[2] = (lastRefR[0]+lastRefR[0]+inputSampleR)/3; //third
lastRefR[1] = (lastRefR[0]+inputSampleR+inputSampleR)/3; //two thirds
lastRefR[3] = inputSampleR; //full
}
if (cycleEnd == 2) {
lastRefL[0] = lastRefL[2]; //start from previous last
lastRefL[1] = (lastRefL[0] + inputSampleL)/2; //half
lastRefL[2] = inputSampleL; //full
lastRefR[0] = lastRefR[2]; //start from previous last
lastRefR[1] = (lastRefR[0] + inputSampleR)/2; //half
lastRefR[2] = inputSampleR; //full
}
if (cycleEnd == 1) {
lastRefL[0] = inputSampleL;
lastRefR[0] = inputSampleR;
}
cycle = 0; //reset
inputSampleL = lastRefL[cycle];
inputSampleR = lastRefR[cycle];
} else {
inputSampleL = lastRefL[cycle];
inputSampleR = lastRefR[cycle];
//we are going through our references now
}
switch (cycleEnd) //multi-pole average using lastRef[] variables
{
case 4:
lastRefL[8] = inputSampleL; inputSampleL = (inputSampleL+lastRefL[7])*0.5;
lastRefL[7] = lastRefL[8]; //continue, do not break
lastRefR[8] = inputSampleR; inputSampleR = (inputSampleR+lastRefR[7])*0.5;
lastRefR[7] = lastRefR[8]; //continue, do not break
case 3:
lastRefL[8] = inputSampleL; inputSampleL = (inputSampleL+lastRefL[6])*0.5;
lastRefL[6] = lastRefL[8]; //continue, do not break
lastRefR[8] = inputSampleR; inputSampleR = (inputSampleR+lastRefR[6])*0.5;
lastRefR[6] = lastRefR[8]; //continue, do not break
case 2:
lastRefL[8] = inputSampleL; inputSampleL = (inputSampleL+lastRefL[5])*0.5;
lastRefL[5] = lastRefL[8]; //continue, do not break
lastRefR[8] = inputSampleR; inputSampleR = (inputSampleR+lastRefR[5])*0.5;
lastRefR[5] = lastRefR[8]; //continue, do not break
case 1:
break; //no further averaging
}
iirBL = (iirBL*(1.0-lowpass))+(inputSampleL*lowpass); inputSampleL = iirBL;
iirBR = (iirBR*(1.0-lowpass))+(inputSampleR*lowpass); inputSampleR = iirBR;
//end filter
if (wet < 1.0) {inputSampleL *= wet; inputSampleR *= wet;}
if (dry < 1.0) {drySampleL *= dry; drySampleR *= dry;}
inputSampleL += drySampleL;
inputSampleR += drySampleR;
//this is our submix verb dry/wet: 0.5 is BOTH at FULL VOLUME
//purpose is that, if you're adding verb, you're not altering other balances
//begin 64 bit stereo floating point dither
//int expon; frexp((double)inputSampleL, &expon);
fpdL ^= fpdL << 13; fpdL ^= fpdL >> 17; fpdL ^= fpdL << 5;
//inputSampleL += ((double(fpdL)-uint32_t(0x7fffffff)) * 1.1e-44l * pow(2,expon+62));
//frexp((double)inputSampleR, &expon);
fpdR ^= fpdR << 13; fpdR ^= fpdR >> 17; fpdR ^= fpdR << 5;
//inputSampleR += ((double(fpdR)-uint32_t(0x7fffffff)) * 1.1e-44l * pow(2,expon+62));
//end 64 bit stereo floating point dither
*out1 = inputSampleL;
*out2 = inputSampleR;
*in1++;
*in2++;
*out1++;
*out2++;
}
}