diff options
Diffstat (limited to 'plugins/MacVST/Gatelope/source/GatelopeProc.cpp')
-rwxr-xr-x | plugins/MacVST/Gatelope/source/GatelopeProc.cpp | 436 |
1 files changed, 436 insertions, 0 deletions
diff --git a/plugins/MacVST/Gatelope/source/GatelopeProc.cpp b/plugins/MacVST/Gatelope/source/GatelopeProc.cpp new file mode 100755 index 0000000..dc81def --- /dev/null +++ b/plugins/MacVST/Gatelope/source/GatelopeProc.cpp @@ -0,0 +1,436 @@ +/* ======================================== + * Gatelope - Gatelope.h + * Copyright (c) 2016 airwindows, All rights reserved + * ======================================== */ + +#ifndef __Gatelope_H +#include "Gatelope.h" +#endif + +void Gatelope::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(); + //speed settings around release + double threshold = pow(A,2); + //gain settings around threshold + double trebledecay = pow(1.0-B,2)/4196.0; + double bassdecay = pow(1.0-C,2)/8192.0; + double slowAttack = (pow(D,3)*3)+0.003; + double wet = E; + slowAttack /= overallscale; + trebledecay /= overallscale; + bassdecay /= overallscale; + trebledecay += 1.0; + bassdecay += 1.0; + double attackSpeed; + double highestSample; + //this VST version comes from the AU, Gatelinked, because it's stereo. + //if used on a mono track it'll act like the mono N to N + + while (--sampleFrames >= 0) + { + long double inputSampleL = *in1; + long double inputSampleR = *in2; + + static int noisesourceL = 0; + static int noisesourceR = 850010; + int residue; + double applyresidue; + + noisesourceL = noisesourceL % 1700021; noisesourceL++; + residue = noisesourceL * noisesourceL; + residue = residue % 170003; residue *= residue; + residue = residue % 17011; residue *= residue; + residue = residue % 1709; residue *= residue; + residue = residue % 173; residue *= residue; + residue = residue % 17; + applyresidue = residue; + applyresidue *= 0.00000001; + applyresidue *= 0.00000001; + inputSampleL += applyresidue; + if (inputSampleL<1.2e-38 && -inputSampleL<1.2e-38) { + inputSampleL -= applyresidue; + } + + noisesourceR = noisesourceR % 1700021; noisesourceR++; + residue = noisesourceR * noisesourceR; + residue = residue % 170003; residue *= residue; + residue = residue % 17011; residue *= residue; + residue = residue % 1709; residue *= residue; + residue = residue % 173; residue *= residue; + residue = residue % 17; + applyresidue = residue; + applyresidue *= 0.00000001; + applyresidue *= 0.00000001; + inputSampleR += applyresidue; + if (inputSampleR<1.2e-38 && -inputSampleR<1.2e-38) { + inputSampleR -= applyresidue; + } + //for live air, we always apply the dither noise. Then, if our result is + //effectively digital black, we'll subtract it again. We want a 'air' hiss + double drySampleL = inputSampleL; + double drySampleR = inputSampleR; + + if (fabs(inputSampleL) > fabs(inputSampleR)) { + attackSpeed = slowAttack - (fabs(inputSampleL)*slowAttack*0.5); + highestSample = fabs(inputSampleL); + } else { + attackSpeed = slowAttack - (fabs(inputSampleR)*slowAttack*0.5); //we're triggering off the highest amplitude + highestSample = fabs(inputSampleR); //and making highestSample the abs() of that amplitude + } + + if (attackSpeed < 0.0) attackSpeed = 0.0; + //softening onset click depending on how hard we're getting it + + if (flip) + { + if (highestSample > threshold) + { + treblefreq += attackSpeed; + if (treblefreq > 1.0) treblefreq = 1.0; + bassfreq -= attackSpeed; + bassfreq -= attackSpeed; + if (bassfreq < 0.0) bassfreq = 0.0; + iirLowpassAL = iirLowpassBL = inputSampleL; + iirHighpassAL = iirHighpassBL = 0.0; + iirLowpassAR = iirLowpassBR = inputSampleR; + iirHighpassAR = iirHighpassBR = 0.0; + } + else + { + treblefreq -= bassfreq; + treblefreq /= trebledecay; + treblefreq += bassfreq; + bassfreq -= treblefreq; + bassfreq /= bassdecay; + bassfreq += treblefreq; + } + + if (treblefreq >= 1.0) { + iirLowpassAL = inputSampleL; + iirLowpassAR = inputSampleR; + } else { + iirLowpassAL = (iirLowpassAL * (1.0 - treblefreq)) + (inputSampleL * treblefreq); + iirLowpassAR = (iirLowpassAR * (1.0 - treblefreq)) + (inputSampleR * treblefreq); + } + + if (bassfreq > 0.0) { + iirHighpassAL = (iirHighpassAL * (1.0 - bassfreq)) + (inputSampleL * bassfreq); + iirHighpassAR = (iirHighpassAR * (1.0 - bassfreq)) + (inputSampleR * bassfreq); + } else { + iirHighpassAL = 0.0; + iirHighpassAR = 0.0; + } + + if (treblefreq > bassfreq) { + inputSampleL = (iirLowpassAL - iirHighpassAL); + inputSampleR = (iirLowpassAR - iirHighpassAR); + } else { + inputSampleL = 0.0; + inputSampleR = 0.0; + } + } + else + { + if (highestSample > threshold) + { + treblefreq += attackSpeed; + if (treblefreq > 1.0) treblefreq = 1.0; + bassfreq -= attackSpeed; + bassfreq -= attackSpeed; + if (bassfreq < 0.0) bassfreq = 0.0; + iirLowpassAL = iirLowpassBL = inputSampleL; + iirHighpassAL = iirHighpassBL = 0.0; + iirLowpassAR = iirLowpassBR = inputSampleR; + iirHighpassAR = iirHighpassBR = 0.0; + } + else + { + treblefreq -= bassfreq; + treblefreq /= trebledecay; + treblefreq += bassfreq; + bassfreq -= treblefreq; + bassfreq /= bassdecay; + bassfreq += treblefreq; + } + + if (treblefreq >= 1.0) { + iirLowpassBL = inputSampleL; + iirLowpassBR = inputSampleR; + } else { + iirLowpassBL = (iirLowpassBL * (1.0 - treblefreq)) + (inputSampleL * treblefreq); + iirLowpassBR = (iirLowpassBR * (1.0 - treblefreq)) + (inputSampleR * treblefreq); + } + + if (bassfreq > 0.0) { + iirHighpassBL = (iirHighpassBL * (1.0 - bassfreq)) + (inputSampleL * bassfreq); + iirHighpassBR = (iirHighpassBR * (1.0 - bassfreq)) + (inputSampleR * bassfreq); + } else { + iirHighpassBL = 0.0; + iirHighpassBR = 0.0; + } + + if (treblefreq > bassfreq) { + inputSampleL = (iirLowpassBL - iirHighpassBL); + inputSampleR = (iirLowpassBR - iirHighpassBR); + } else { + inputSampleL = 0.0; + inputSampleR = 0.0; + } + } + //done full gated envelope filtered effect + inputSampleL = ((1-wet)*drySampleL)+(wet*inputSampleL); + inputSampleR = ((1-wet)*drySampleR)+(wet*inputSampleR); + //we're going to set up a dry/wet control instead of a min. threshold + + flip = !flip; + + //noise shaping to 32-bit floating point + float fpTemp = inputSampleL; + fpNShapeL += (inputSampleL-fpTemp); + inputSampleL += fpNShapeL; + //if this confuses you look at the wordlength for fpTemp :) + fpTemp = inputSampleR; + fpNShapeR += (inputSampleR-fpTemp); + inputSampleR += fpNShapeR; + //for deeper space and warmth, we try a non-oscillating noise shaping + //that is kind of ruthless: it will forever retain the rounding errors + //except we'll dial it back a hair at the end of every buffer processed + //end noise shaping on 32 bit output + + *out1 = inputSampleL; + *out2 = inputSampleR; + + *in1++; + *in2++; + *out1++; + *out2++; + } + fpNShapeL *= 0.999999; + fpNShapeR *= 0.999999; + //we will just delicately dial back the FP noise shaping, not even every sample + //this is a good place to put subtle 'no runaway' calculations, though bear in mind + //that it will be called more often when you use shorter sample buffers in the DAW. + //So, very low latency operation will call these calculations more often. +} + +void Gatelope::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(); + //speed settings around release + double threshold = pow(A,2); + //gain settings around threshold + double trebledecay = pow(1.0-B,2)/4196.0; + double bassdecay = pow(1.0-C,2)/8192.0; + double slowAttack = (pow(D,3)*3)+0.003; + double wet = E; + slowAttack /= overallscale; + trebledecay /= overallscale; + bassdecay /= overallscale; + trebledecay += 1.0; + bassdecay += 1.0; + double attackSpeed; + double highestSample; + //this VST version comes from the AU, Gatelinked, because it's stereo. + //if used on a mono track it'll act like the mono N to N + + while (--sampleFrames >= 0) + { + long double inputSampleL = *in1; + long double inputSampleR = *in2; + + static int noisesourceL = 0; + static int noisesourceR = 850010; + int residue; + double applyresidue; + + noisesourceL = noisesourceL % 1700021; noisesourceL++; + residue = noisesourceL * noisesourceL; + residue = residue % 170003; residue *= residue; + residue = residue % 17011; residue *= residue; + residue = residue % 1709; residue *= residue; + residue = residue % 173; residue *= residue; + residue = residue % 17; + applyresidue = residue; + applyresidue *= 0.00000001; + applyresidue *= 0.00000001; + inputSampleL += applyresidue; + if (inputSampleL<1.2e-38 && -inputSampleL<1.2e-38) { + inputSampleL -= applyresidue; + } + + noisesourceR = noisesourceR % 1700021; noisesourceR++; + residue = noisesourceR * noisesourceR; + residue = residue % 170003; residue *= residue; + residue = residue % 17011; residue *= residue; + residue = residue % 1709; residue *= residue; + residue = residue % 173; residue *= residue; + residue = residue % 17; + applyresidue = residue; + applyresidue *= 0.00000001; + applyresidue *= 0.00000001; + inputSampleR += applyresidue; + if (inputSampleR<1.2e-38 && -inputSampleR<1.2e-38) { + inputSampleR -= applyresidue; + } + //for live air, we always apply the dither noise. Then, if our result is + //effectively digital black, we'll subtract it again. We want a 'air' hiss + double drySampleL = inputSampleL; + double drySampleR = inputSampleR; + + if (fabs(inputSampleL) > fabs(inputSampleR)) { + attackSpeed = slowAttack - (fabs(inputSampleL)*slowAttack*0.5); + highestSample = fabs(inputSampleL); + } else { + attackSpeed = slowAttack - (fabs(inputSampleR)*slowAttack*0.5); //we're triggering off the highest amplitude + highestSample = fabs(inputSampleR); //and making highestSample the abs() of that amplitude + } + + if (attackSpeed < 0.0) attackSpeed = 0.0; + //softening onset click depending on how hard we're getting it + + if (flip) + { + if (highestSample > threshold) + { + treblefreq += attackSpeed; + if (treblefreq > 1.0) treblefreq = 1.0; + bassfreq -= attackSpeed; + bassfreq -= attackSpeed; + if (bassfreq < 0.0) bassfreq = 0.0; + iirLowpassAL = iirLowpassBL = inputSampleL; + iirHighpassAL = iirHighpassBL = 0.0; + iirLowpassAR = iirLowpassBR = inputSampleR; + iirHighpassAR = iirHighpassBR = 0.0; + } + else + { + treblefreq -= bassfreq; + treblefreq /= trebledecay; + treblefreq += bassfreq; + bassfreq -= treblefreq; + bassfreq /= bassdecay; + bassfreq += treblefreq; + } + + if (treblefreq >= 1.0) { + iirLowpassAL = inputSampleL; + iirLowpassAR = inputSampleR; + } else { + iirLowpassAL = (iirLowpassAL * (1.0 - treblefreq)) + (inputSampleL * treblefreq); + iirLowpassAR = (iirLowpassAR * (1.0 - treblefreq)) + (inputSampleR * treblefreq); + } + + if (bassfreq > 0.0) { + iirHighpassAL = (iirHighpassAL * (1.0 - bassfreq)) + (inputSampleL * bassfreq); + iirHighpassAR = (iirHighpassAR * (1.0 - bassfreq)) + (inputSampleR * bassfreq); + } else { + iirHighpassAL = 0.0; + iirHighpassAR = 0.0; + } + + if (treblefreq > bassfreq) { + inputSampleL = (iirLowpassAL - iirHighpassAL); + inputSampleR = (iirLowpassAR - iirHighpassAR); + } else { + inputSampleL = 0.0; + inputSampleR = 0.0; + } + } + else + { + if (highestSample > threshold) + { + treblefreq += attackSpeed; + if (treblefreq > 1.0) treblefreq = 1.0; + bassfreq -= attackSpeed; + bassfreq -= attackSpeed; + if (bassfreq < 0.0) bassfreq = 0.0; + iirLowpassAL = iirLowpassBL = inputSampleL; + iirHighpassAL = iirHighpassBL = 0.0; + iirLowpassAR = iirLowpassBR = inputSampleR; + iirHighpassAR = iirHighpassBR = 0.0; + } + else + { + treblefreq -= bassfreq; + treblefreq /= trebledecay; + treblefreq += bassfreq; + bassfreq -= treblefreq; + bassfreq /= bassdecay; + bassfreq += treblefreq; + } + + if (treblefreq >= 1.0) { + iirLowpassBL = inputSampleL; + iirLowpassBR = inputSampleR; + } else { + iirLowpassBL = (iirLowpassBL * (1.0 - treblefreq)) + (inputSampleL * treblefreq); + iirLowpassBR = (iirLowpassBR * (1.0 - treblefreq)) + (inputSampleR * treblefreq); + } + + if (bassfreq > 0.0) { + iirHighpassBL = (iirHighpassBL * (1.0 - bassfreq)) + (inputSampleL * bassfreq); + iirHighpassBR = (iirHighpassBR * (1.0 - bassfreq)) + (inputSampleR * bassfreq); + } else { + iirHighpassBL = 0.0; + iirHighpassBR = 0.0; + } + + if (treblefreq > bassfreq) { + inputSampleL = (iirLowpassBL - iirHighpassBL); + inputSampleR = (iirLowpassBR - iirHighpassBR); + } else { + inputSampleL = 0.0; + inputSampleR = 0.0; + } + } + //done full gated envelope filtered effect + inputSampleL = ((1-wet)*drySampleL)+(wet*inputSampleL); + inputSampleR = ((1-wet)*drySampleR)+(wet*inputSampleR); + //we're going to set up a dry/wet control instead of a min. threshold + + flip = !flip; + + //noise shaping to 64-bit floating point + double fpTemp = inputSampleL; + fpNShapeL += (inputSampleL-fpTemp); + inputSampleL += fpNShapeL; + //if this confuses you look at the wordlength for fpTemp :) + fpTemp = inputSampleR; + fpNShapeR += (inputSampleR-fpTemp); + inputSampleR += fpNShapeR; + //for deeper space and warmth, we try a non-oscillating noise shaping + //that is kind of ruthless: it will forever retain the rounding errors + //except we'll dial it back a hair at the end of every buffer processed + //end noise shaping on 64 bit output + + *out1 = inputSampleL; + *out2 = inputSampleR; + + *in1++; + *in2++; + *out1++; + *out2++; + } + fpNShapeL *= 0.999999; + fpNShapeR *= 0.999999; + //we will just delicately dial back the FP noise shaping, not even every sample + //this is a good place to put subtle 'no runaway' calculations, though bear in mind + //that it will be called more often when you use shorter sample buffers in the DAW. + //So, very low latency operation will call these calculations more often. +} |