diff options
author | Chris Johnson <jinx6568@sover.net> | 2018-06-10 21:25:10 -0400 |
---|---|---|
committer | Chris Johnson <jinx6568@sover.net> | 2018-06-10 21:25:10 -0400 |
commit | 0e17cd43f77cf0c74419a27284e85ceaa109f9ec (patch) | |
tree | bf252d2bcf798ce3472b9e388568d7e69e7d1a79 /plugins/LinuxVST | |
parent | 3a3c2dde62b7c28950898c469c376ad32ac63f39 (diff) | |
download | airwindows-lv2-port-0e17cd43f77cf0c74419a27284e85ceaa109f9ec.tar.gz airwindows-lv2-port-0e17cd43f77cf0c74419a27284e85ceaa109f9ec.tar.bz2 airwindows-lv2-port-0e17cd43f77cf0c74419a27284e85ceaa109f9ec.zip |
Distance2
Diffstat (limited to 'plugins/LinuxVST')
-rwxr-xr-x | plugins/LinuxVST/CMakeLists.txt | 1 | ||||
-rwxr-xr-x | plugins/LinuxVST/src/Distance2/Distance2.cpp | 181 | ||||
-rwxr-xr-x | plugins/LinuxVST/src/Distance2/Distance2.h | 114 | ||||
-rwxr-xr-x | plugins/LinuxVST/src/Distance2/Distance2Proc.cpp | 584 |
4 files changed, 880 insertions, 0 deletions
diff --git a/plugins/LinuxVST/CMakeLists.txt b/plugins/LinuxVST/CMakeLists.txt index 905178e..48481e0 100755 --- a/plugins/LinuxVST/CMakeLists.txt +++ b/plugins/LinuxVST/CMakeLists.txt @@ -17,6 +17,7 @@ add_airwindows_plugin(C5RawChannel) add_airwindows_plugin(Channel4) add_airwindows_plugin(Channel5) add_airwindows_plugin(CrunchyGrooveWear) +add_airwindows_plugin(Distance2) add_airwindows_plugin(ElectroHat) add_airwindows_plugin(EQ) add_airwindows_plugin(Golem) diff --git a/plugins/LinuxVST/src/Distance2/Distance2.cpp b/plugins/LinuxVST/src/Distance2/Distance2.cpp new file mode 100755 index 0000000..d6e26d8 --- /dev/null +++ b/plugins/LinuxVST/src/Distance2/Distance2.cpp @@ -0,0 +1,181 @@ +/* ======================================== + * Distance2 - Distance2.h + * Copyright (c) 2016 airwindows, All rights reserved + * ======================================== */ + +#ifndef __Distance2_H +#include "Distance2.h" +#endif + +AudioEffect* createEffectInstance(audioMasterCallback audioMaster) {return new Distance2(audioMaster);} + +Distance2::Distance2(audioMasterCallback audioMaster) : + AudioEffectX(audioMaster, kNumPrograms, kNumParameters) +{ + A = 0.85; + B = 0.618; + C = 0.618; + + thirdSampleL = lastSampleL = 0.0; + thirdSampleR = lastSampleR = 0.0; + + lastSampleAL = 0.0; + lastSampleBL = 0.0; + lastSampleCL = 0.0; + lastSampleDL = 0.0; + lastSampleEL = 0.0; + lastSampleFL = 0.0; + lastSampleGL = 0.0; + lastSampleHL = 0.0; + lastSampleIL = 0.0; + lastSampleJL = 0.0; + lastSampleKL = 0.0; + lastSampleLL = 0.0; + lastSampleML = 0.0; + + lastSampleAR = 0.0; + lastSampleBR = 0.0; + lastSampleCR = 0.0; + lastSampleDR = 0.0; + lastSampleER = 0.0; + lastSampleFR = 0.0; + lastSampleGR = 0.0; + lastSampleHR = 0.0; + lastSampleIR = 0.0; + lastSampleJR = 0.0; + lastSampleKR = 0.0; + lastSampleLR = 0.0; + lastSampleMR = 0.0; + + thresholdA = 0.618033988749894; + thresholdB = 0.679837387624884; + thresholdC = 0.747821126387373; + thresholdD = 0.82260323902611; + thresholdE = 0.904863562928721; + thresholdF = 0.995349919221593; + thresholdG = 1.094884911143752; + thresholdH = 1.204373402258128; + thresholdI = 1.32481074248394; + thresholdJ = 1.457291816732335; + thresholdK = 1.603020998405568; + thresholdL = 1.763323098246125; + thresholdM = 1.939655408070737; + + fpNShapeL = 0.0; + fpNShapeR = 0.0; + //this is reset: values being initialized only once. Startup values, whatever they are. + + _canDo.insert("plugAsChannelInsert"); // plug-in can be used as a channel insert effect. + _canDo.insert("plugAsSend"); // plug-in can be used as a send effect. + _canDo.insert("x2in2out"); + setNumInputs(kNumInputs); + setNumOutputs(kNumOutputs); + setUniqueID(kUniqueId); + canProcessReplacing(); // supports output replacing + canDoubleReplacing(); // supports double precision processing + programsAreChunks(true); + vst_strncpy (_programName, "Default", kVstMaxProgNameLen); // default program name +} + +Distance2::~Distance2() {} +VstInt32 Distance2::getVendorVersion () {return 1000;} +void Distance2::setProgramName(char *name) {vst_strncpy (_programName, name, kVstMaxProgNameLen);} +void Distance2::getProgramName(char *name) {vst_strncpy (name, _programName, kVstMaxProgNameLen);} +//airwindows likes to ignore this stuff. Make your own programs, and make a different plugin rather than +//trying to do versioning and preventing people from using older versions. Maybe they like the old one! + +static float pinParameter(float data) +{ + if (data < 0.0f) return 0.0f; + if (data > 1.0f) return 1.0f; + return data; +} + +VstInt32 Distance2::getChunk (void** data, bool isPreset) +{ + float *chunkData = (float *)calloc(kNumParameters, sizeof(float)); + chunkData[0] = A; + chunkData[1] = B; + chunkData[2] = C; + /* Note: The way this is set up, it will break if you manage to save settings on an Intel + machine and load them on a PPC Mac. However, it's fine if you stick to the machine you + started with. */ + + *data = chunkData; + return kNumParameters * sizeof(float); +} + +VstInt32 Distance2::setChunk (void* data, VstInt32 byteSize, bool isPreset) +{ + float *chunkData = (float *)data; + A = pinParameter(chunkData[0]); + B = pinParameter(chunkData[1]); + C = pinParameter(chunkData[2]); + /* We're ignoring byteSize as we found it to be a filthy liar */ + + /* calculate any other fields you need here - you could copy in + code from setParameter() here. */ + return 0; +} + +void Distance2::setParameter(VstInt32 index, float value) { + switch (index) { + case kParamA: A = value; break; + case kParamB: B = value; break; + case kParamC: C = value; break; + default: throw; // unknown parameter, shouldn't happen! + } +} + +float Distance2::getParameter(VstInt32 index) { + switch (index) { + case kParamA: return A; break; + case kParamB: return B; break; + case kParamC: return C; break; + default: break; // unknown parameter, shouldn't happen! + } return 0.0; //we only need to update the relevant name, this is simple to manage +} + +void Distance2::getParameterName(VstInt32 index, char *text) { + switch (index) { + case kParamA: vst_strncpy (text, "Atmosph", kVstMaxParamStrLen); break; + case kParamB: vst_strncpy (text, "Darken", kVstMaxParamStrLen); break; + case kParamC: vst_strncpy (text, "Dry/Wet", kVstMaxParamStrLen); break; + default: break; // unknown parameter, shouldn't happen! + } //this is our labels for displaying in the VST host +} + +void Distance2::getParameterDisplay(VstInt32 index, char *text) { + switch (index) { + case kParamA: float2string (A, text, kVstMaxParamStrLen); break; + case kParamB: float2string (B, text, kVstMaxParamStrLen); break; + case kParamC: float2string (C, text, kVstMaxParamStrLen); break; + default: break; // unknown parameter, shouldn't happen! + } //this displays the values and handles 'popups' where it's discrete choices +} + +void Distance2::getParameterLabel(VstInt32 index, char *text) { + switch (index) { + case kParamA: vst_strncpy (text, "", kVstMaxParamStrLen); break; + case kParamB: vst_strncpy (text, "", kVstMaxParamStrLen); break; + case kParamC: vst_strncpy (text, "", kVstMaxParamStrLen); break; + default: break; // unknown parameter, shouldn't happen! + } +} + +VstInt32 Distance2::canDo(char *text) +{ return (_canDo.find(text) == _canDo.end()) ? -1: 1; } // 1 = yes, -1 = no, 0 = don't know + +bool Distance2::getEffectName(char* name) { + vst_strncpy(name, "Distance2", kVstMaxProductStrLen); return true; +} + +VstPlugCategory Distance2::getPlugCategory() {return kPlugCategEffect;} + +bool Distance2::getProductString(char* text) { + vst_strncpy (text, "airwindows Distance2", kVstMaxProductStrLen); return true; +} + +bool Distance2::getVendorString(char* text) { + vst_strncpy (text, "airwindows", kVstMaxVendorStrLen); return true; +} diff --git a/plugins/LinuxVST/src/Distance2/Distance2.h b/plugins/LinuxVST/src/Distance2/Distance2.h new file mode 100755 index 0000000..dba008f --- /dev/null +++ b/plugins/LinuxVST/src/Distance2/Distance2.h @@ -0,0 +1,114 @@ +/* ======================================== + * Distance2 - Distance2.h + * Created 8/12/11 by SPIAdmin + * Copyright (c) 2011 __MyCompanyName__, All rights reserved + * ======================================== */ + +#ifndef __Distance2_H +#define __Distance2_H + +#ifndef __audioeffect__ +#include "audioeffectx.h" +#endif + +#include <set> +#include <string> +#include <math.h> + +enum { + kParamA = 0, + kParamB = 1, + kParamC = 2, + kNumParameters = 3 +}; // + +const int kNumPrograms = 0; +const int kNumInputs = 2; +const int kNumOutputs = 2; +const unsigned long kUniqueId = 'disu'; //Change this to what the AU identity is! + +class Distance2 : + public AudioEffectX +{ +public: + Distance2(audioMasterCallback audioMaster); + ~Distance2(); + virtual bool getEffectName(char* name); // The plug-in name + virtual VstPlugCategory getPlugCategory(); // The general category for the plug-in + virtual bool getProductString(char* text); // This is a unique plug-in string provided by Steinberg + virtual bool getVendorString(char* text); // Vendor info + virtual VstInt32 getVendorVersion(); // Version number + virtual void processReplacing (float** inputs, float** outputs, VstInt32 sampleFrames); + virtual void processDoubleReplacing (double** inputs, double** outputs, VstInt32 sampleFrames); + virtual void getProgramName(char *name); // read the name from the host + virtual void setProgramName(char *name); // changes the name of the preset displayed in the host + virtual VstInt32 getChunk (void** data, bool isPreset); + virtual VstInt32 setChunk (void* data, VstInt32 byteSize, bool isPreset); + virtual float getParameter(VstInt32 index); // get the parameter value at the specified index + virtual void setParameter(VstInt32 index, float value); // set the parameter at index to value + virtual void getParameterLabel(VstInt32 index, char *text); // label for the parameter (eg dB) + virtual void getParameterName(VstInt32 index, char *text); // name of the parameter + virtual void getParameterDisplay(VstInt32 index, char *text); // text description of the current value + virtual VstInt32 canDo(char *text); +private: + char _programName[kVstMaxProgNameLen + 1]; + std::set< std::string > _canDo; + + long double fpNShapeL; + long double fpNShapeR; + //default stuff + + long double lastSampleAL; + long double lastSampleBL; + long double lastSampleCL; + long double lastSampleDL; + long double lastSampleEL; + long double lastSampleFL; + long double lastSampleGL; + long double lastSampleHL; + long double lastSampleIL; + long double lastSampleJL; + long double lastSampleKL; + long double lastSampleLL; + long double lastSampleML; + + long double lastSampleAR; + long double lastSampleBR; + long double lastSampleCR; + long double lastSampleDR; + long double lastSampleER; + long double lastSampleFR; + long double lastSampleGR; + long double lastSampleHR; + long double lastSampleIR; + long double lastSampleJR; + long double lastSampleKR; + long double lastSampleLR; + long double lastSampleMR; + + long double thresholdA; + long double thresholdB; + long double thresholdC; + long double thresholdD; + long double thresholdE; + long double thresholdF; + long double thresholdG; + long double thresholdH; + long double thresholdI; + long double thresholdJ; + long double thresholdK; + long double thresholdL; + long double thresholdM; + + double thirdSampleL; + double lastSampleL; + + double thirdSampleR; + double lastSampleR; + + float A; + float B; + float C; +}; + +#endif diff --git a/plugins/LinuxVST/src/Distance2/Distance2Proc.cpp b/plugins/LinuxVST/src/Distance2/Distance2Proc.cpp new file mode 100755 index 0000000..ef5bf5b --- /dev/null +++ b/plugins/LinuxVST/src/Distance2/Distance2Proc.cpp @@ -0,0 +1,584 @@ +/* ======================================== + * Distance2 - Distance2.h + * Copyright (c) 2016 airwindows, All rights reserved + * ======================================== */ + +#ifndef __Distance2_H +#include "Distance2.h" +#endif + +void Distance2::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(); + thresholdA = 0.618033988749894 / overallscale; + thresholdB = 0.679837387624884 / overallscale; + thresholdC = 0.747821126387373 / overallscale; + thresholdD = 0.82260323902611 / overallscale; + thresholdE = 0.904863562928721 / overallscale; + thresholdF = 0.995349919221593 / overallscale; + thresholdG = 1.094884911143752 / overallscale; + thresholdH = 1.204373402258128 / overallscale; + thresholdI = 1.32481074248394 / overallscale; + thresholdJ = 1.457291816732335 / overallscale; + thresholdK = 1.603020998405568 / overallscale; + thresholdL = 1.763323098246125 / overallscale; + thresholdM = 1.939655408070737 / overallscale; + double softslew = (pow(A,3)*24)+.6; + softslew *= overallscale; + double filter = softslew * B; + double secondfilter = filter / 3.0; + double thirdfilter = filter / 5.0; + double offsetScale = A * 0.1618; + double levelcorrect = 1.0 + ((filter / 12.0) * A); + //bring in top slider again to manage boost level for lower settings + double wet = C; + double dry = 1.0 - wet; + + 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; + + double offsetL = offsetScale - (lastSampleL - inputSampleL); + double offsetR = offsetScale - (lastSampleR - inputSampleR); + + inputSampleL += (offsetL*offsetScale); //extra bit from Loud: offset air compression + inputSampleL *= wet; //clean up w. dry introduced + inputSampleL *= softslew; //scale into Atmosphere algorithm + + inputSampleR += (offsetR*offsetScale); //extra bit from Loud: offset air compression + inputSampleR *= wet; //clean up w. dry introduced + inputSampleR *= softslew; //scale into Atmosphere algorithm + + //left + long double clamp = inputSampleL - lastSampleAL; + if (clamp > thresholdA) inputSampleL = lastSampleAL + thresholdA; + if (-clamp > thresholdA) inputSampleL = lastSampleAL - thresholdA; + + clamp = inputSampleL - lastSampleBL; + if (clamp > thresholdB) inputSampleL = lastSampleBL + thresholdB; + if (-clamp > thresholdB) inputSampleL = lastSampleBL - thresholdB; + + clamp = inputSampleL - lastSampleCL; + if (clamp > thresholdC) inputSampleL = lastSampleCL + thresholdC; + if (-clamp > thresholdC) inputSampleL = lastSampleCL - thresholdC; + + clamp = inputSampleL - lastSampleDL; + if (clamp > thresholdD) inputSampleL = lastSampleDL + thresholdD; + if (-clamp > thresholdD) inputSampleL = lastSampleDL - thresholdD; + + clamp = inputSampleL - lastSampleEL; + if (clamp > thresholdE) inputSampleL = lastSampleEL + thresholdE; + if (-clamp > thresholdE) inputSampleL = lastSampleEL - thresholdE; + + clamp = inputSampleL - lastSampleFL; + if (clamp > thresholdF) inputSampleL = lastSampleFL + thresholdF; + if (-clamp > thresholdF) inputSampleL = lastSampleFL - thresholdF; + + clamp = inputSampleL - lastSampleGL; + if (clamp > thresholdG) inputSampleL = lastSampleGL + thresholdG; + if (-clamp > thresholdG) inputSampleL = lastSampleGL - thresholdG; + + clamp = inputSampleL - lastSampleHL; + if (clamp > thresholdH) inputSampleL = lastSampleHL + thresholdH; + if (-clamp > thresholdH) inputSampleL = lastSampleHL - thresholdH; + + clamp = inputSampleL - lastSampleIL; + if (clamp > thresholdI) inputSampleL = lastSampleIL + thresholdI; + if (-clamp > thresholdI) inputSampleL = lastSampleIL - thresholdI; + + clamp = inputSampleL - lastSampleJL; + if (clamp > thresholdJ) inputSampleL = lastSampleJL + thresholdJ; + if (-clamp > thresholdJ) inputSampleL = lastSampleJL - thresholdJ; + + clamp = inputSampleL - lastSampleKL; + if (clamp > thresholdK) inputSampleL = lastSampleKL + thresholdK; + if (-clamp > thresholdK) inputSampleL = lastSampleKL - thresholdK; + + clamp = inputSampleL - lastSampleLL; + if (clamp > thresholdL) inputSampleL = lastSampleLL + thresholdL; + if (-clamp > thresholdL) inputSampleL = lastSampleLL - thresholdL; + + clamp = inputSampleL - lastSampleML; + if (clamp > thresholdM) inputSampleL = lastSampleML + thresholdM; + if (-clamp > thresholdM) inputSampleL = lastSampleML - thresholdM; + + //right + clamp = inputSampleR - lastSampleAR; + if (clamp > thresholdA) inputSampleR = lastSampleAR + thresholdA; + if (-clamp > thresholdA) inputSampleR = lastSampleAR - thresholdA; + + clamp = inputSampleR - lastSampleBR; + if (clamp > thresholdB) inputSampleR = lastSampleBR + thresholdB; + if (-clamp > thresholdB) inputSampleR = lastSampleBR - thresholdB; + + clamp = inputSampleR - lastSampleCR; + if (clamp > thresholdC) inputSampleR = lastSampleCR + thresholdC; + if (-clamp > thresholdC) inputSampleR = lastSampleCR - thresholdC; + + clamp = inputSampleR - lastSampleDR; + if (clamp > thresholdD) inputSampleR = lastSampleDR + thresholdD; + if (-clamp > thresholdD) inputSampleR = lastSampleDR - thresholdD; + + clamp = inputSampleR - lastSampleER; + if (clamp > thresholdE) inputSampleR = lastSampleER + thresholdE; + if (-clamp > thresholdE) inputSampleR = lastSampleER - thresholdE; + + clamp = inputSampleR - lastSampleFR; + if (clamp > thresholdF) inputSampleR = lastSampleFR + thresholdF; + if (-clamp > thresholdF) inputSampleR = lastSampleFR - thresholdF; + + clamp = inputSampleR - lastSampleGR; + if (clamp > thresholdG) inputSampleR = lastSampleGR + thresholdG; + if (-clamp > thresholdG) inputSampleR = lastSampleGR - thresholdG; + + clamp = inputSampleR - lastSampleHR; + if (clamp > thresholdH) inputSampleR = lastSampleHR + thresholdH; + if (-clamp > thresholdH) inputSampleR = lastSampleHR - thresholdH; + + clamp = inputSampleR - lastSampleIR; + if (clamp > thresholdI) inputSampleR = lastSampleIR + thresholdI; + if (-clamp > thresholdI) inputSampleR = lastSampleIR - thresholdI; + + clamp = inputSampleR - lastSampleJR; + if (clamp > thresholdJ) inputSampleR = lastSampleJR + thresholdJ; + if (-clamp > thresholdJ) inputSampleR = lastSampleJR - thresholdJ; + + clamp = inputSampleR - lastSampleKR; + if (clamp > thresholdK) inputSampleR = lastSampleKR + thresholdK; + if (-clamp > thresholdK) inputSampleR = lastSampleKR - thresholdK; + + clamp = inputSampleR - lastSampleLR; + if (clamp > thresholdL) inputSampleR = lastSampleLR + thresholdL; + if (-clamp > thresholdL) inputSampleR = lastSampleLR - thresholdL; + + clamp = inputSampleR - lastSampleMR; + if (clamp > thresholdM) inputSampleR = lastSampleMR + thresholdM; + if (-clamp > thresholdM) inputSampleR = lastSampleMR - thresholdM; + + + lastSampleML = lastSampleLL; + lastSampleLL = lastSampleKL; + lastSampleKL = lastSampleJL; + lastSampleJL = lastSampleIL; + lastSampleIL = lastSampleHL; + lastSampleHL = lastSampleGL; + lastSampleGL = lastSampleFL; + lastSampleFL = lastSampleEL; + lastSampleEL = lastSampleDL; + lastSampleDL = lastSampleCL; + lastSampleCL = lastSampleBL; + lastSampleBL = lastSampleAL; + lastSampleAL = drySampleL; + //store the raw input sample again for use next time + + lastSampleMR = lastSampleLR; + lastSampleLR = lastSampleKR; + lastSampleKR = lastSampleJR; + lastSampleJR = lastSampleIR; + lastSampleIR = lastSampleHR; + lastSampleHR = lastSampleGR; + lastSampleGR = lastSampleFR; + lastSampleFR = lastSampleER; + lastSampleER = lastSampleDR; + lastSampleDR = lastSampleCR; + lastSampleCR = lastSampleBR; + lastSampleBR = lastSampleAR; + lastSampleAR = drySampleR; + //store the raw input sample again for use next time + + inputSampleL *= levelcorrect; + inputSampleL /= softslew; + inputSampleL -= (offsetL*offsetScale); + //begin IIR stage + inputSampleR *= levelcorrect; + inputSampleR /= softslew; + inputSampleR -= (offsetR*offsetScale); + //begin IIR stage + + inputSampleL += (thirdSampleL * thirdfilter); + inputSampleL /= (thirdfilter + 1.0); + inputSampleL += (lastSampleL * secondfilter); + inputSampleL /= (secondfilter + 1.0); + //do an IIR like thing to further squish superdistant stuff + inputSampleR += (thirdSampleR * thirdfilter); + inputSampleR /= (thirdfilter + 1.0); + inputSampleR += (lastSampleR * secondfilter); + inputSampleR /= (secondfilter + 1.0); + //do an IIR like thing to further squish superdistant stuff + + thirdSampleL = lastSampleL; + lastSampleL = inputSampleL; + inputSampleL *= levelcorrect; + + thirdSampleR = lastSampleR; + lastSampleR = inputSampleR; + inputSampleR *= levelcorrect; + + if (wet !=1.0) { + inputSampleL = (inputSampleL * wet) + (drySampleL * dry); + inputSampleR = (inputSampleR * wet) + (drySampleR * dry); + } + + //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 Distance2::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(); + thresholdA = 0.618033988749894 / overallscale; + thresholdB = 0.679837387624884 / overallscale; + thresholdC = 0.747821126387373 / overallscale; + thresholdD = 0.82260323902611 / overallscale; + thresholdE = 0.904863562928721 / overallscale; + thresholdF = 0.995349919221593 / overallscale; + thresholdG = 1.094884911143752 / overallscale; + thresholdH = 1.204373402258128 / overallscale; + thresholdI = 1.32481074248394 / overallscale; + thresholdJ = 1.457291816732335 / overallscale; + thresholdK = 1.603020998405568 / overallscale; + thresholdL = 1.763323098246125 / overallscale; + thresholdM = 1.939655408070737 / overallscale; + double softslew = (pow(A,3)*24)+.6; + softslew *= overallscale; + double filter = softslew * B; + double secondfilter = filter / 3.0; + double thirdfilter = filter / 5.0; + double offsetScale = A * 0.1618; + double levelcorrect = 1.0 + ((filter / 12.0) * A); + //bring in top slider again to manage boost level for lower settings + double wet = C; + double dry = 1.0 - wet; + + 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; + + double offsetL = offsetScale - (lastSampleL - inputSampleL); + double offsetR = offsetScale - (lastSampleR - inputSampleR); + + inputSampleL += (offsetL*offsetScale); //extra bit from Loud: offset air compression + inputSampleL *= wet; //clean up w. dry introduced + inputSampleL *= softslew; //scale into Atmosphere algorithm + + inputSampleR += (offsetR*offsetScale); //extra bit from Loud: offset air compression + inputSampleR *= wet; //clean up w. dry introduced + inputSampleR *= softslew; //scale into Atmosphere algorithm + + //left + long double clamp = inputSampleL - lastSampleAL; + if (clamp > thresholdA) inputSampleL = lastSampleAL + thresholdA; + if (-clamp > thresholdA) inputSampleL = lastSampleAL - thresholdA; + + clamp = inputSampleL - lastSampleBL; + if (clamp > thresholdB) inputSampleL = lastSampleBL + thresholdB; + if (-clamp > thresholdB) inputSampleL = lastSampleBL - thresholdB; + + clamp = inputSampleL - lastSampleCL; + if (clamp > thresholdC) inputSampleL = lastSampleCL + thresholdC; + if (-clamp > thresholdC) inputSampleL = lastSampleCL - thresholdC; + + clamp = inputSampleL - lastSampleDL; + if (clamp > thresholdD) inputSampleL = lastSampleDL + thresholdD; + if (-clamp > thresholdD) inputSampleL = lastSampleDL - thresholdD; + + clamp = inputSampleL - lastSampleEL; + if (clamp > thresholdE) inputSampleL = lastSampleEL + thresholdE; + if (-clamp > thresholdE) inputSampleL = lastSampleEL - thresholdE; + + clamp = inputSampleL - lastSampleFL; + if (clamp > thresholdF) inputSampleL = lastSampleFL + thresholdF; + if (-clamp > thresholdF) inputSampleL = lastSampleFL - thresholdF; + + clamp = inputSampleL - lastSampleGL; + if (clamp > thresholdG) inputSampleL = lastSampleGL + thresholdG; + if (-clamp > thresholdG) inputSampleL = lastSampleGL - thresholdG; + + clamp = inputSampleL - lastSampleHL; + if (clamp > thresholdH) inputSampleL = lastSampleHL + thresholdH; + if (-clamp > thresholdH) inputSampleL = lastSampleHL - thresholdH; + + clamp = inputSampleL - lastSampleIL; + if (clamp > thresholdI) inputSampleL = lastSampleIL + thresholdI; + if (-clamp > thresholdI) inputSampleL = lastSampleIL - thresholdI; + + clamp = inputSampleL - lastSampleJL; + if (clamp > thresholdJ) inputSampleL = lastSampleJL + thresholdJ; + if (-clamp > thresholdJ) inputSampleL = lastSampleJL - thresholdJ; + + clamp = inputSampleL - lastSampleKL; + if (clamp > thresholdK) inputSampleL = lastSampleKL + thresholdK; + if (-clamp > thresholdK) inputSampleL = lastSampleKL - thresholdK; + + clamp = inputSampleL - lastSampleLL; + if (clamp > thresholdL) inputSampleL = lastSampleLL + thresholdL; + if (-clamp > thresholdL) inputSampleL = lastSampleLL - thresholdL; + + clamp = inputSampleL - lastSampleML; + if (clamp > thresholdM) inputSampleL = lastSampleML + thresholdM; + if (-clamp > thresholdM) inputSampleL = lastSampleML - thresholdM; + + //right + clamp = inputSampleR - lastSampleAR; + if (clamp > thresholdA) inputSampleR = lastSampleAR + thresholdA; + if (-clamp > thresholdA) inputSampleR = lastSampleAR - thresholdA; + + clamp = inputSampleR - lastSampleBR; + if (clamp > thresholdB) inputSampleR = lastSampleBR + thresholdB; + if (-clamp > thresholdB) inputSampleR = lastSampleBR - thresholdB; + + clamp = inputSampleR - lastSampleCR; + if (clamp > thresholdC) inputSampleR = lastSampleCR + thresholdC; + if (-clamp > thresholdC) inputSampleR = lastSampleCR - thresholdC; + + clamp = inputSampleR - lastSampleDR; + if (clamp > thresholdD) inputSampleR = lastSampleDR + thresholdD; + if (-clamp > thresholdD) inputSampleR = lastSampleDR - thresholdD; + + clamp = inputSampleR - lastSampleER; + if (clamp > thresholdE) inputSampleR = lastSampleER + thresholdE; + if (-clamp > thresholdE) inputSampleR = lastSampleER - thresholdE; + + clamp = inputSampleR - lastSampleFR; + if (clamp > thresholdF) inputSampleR = lastSampleFR + thresholdF; + if (-clamp > thresholdF) inputSampleR = lastSampleFR - thresholdF; + + clamp = inputSampleR - lastSampleGR; + if (clamp > thresholdG) inputSampleR = lastSampleGR + thresholdG; + if (-clamp > thresholdG) inputSampleR = lastSampleGR - thresholdG; + + clamp = inputSampleR - lastSampleHR; + if (clamp > thresholdH) inputSampleR = lastSampleHR + thresholdH; + if (-clamp > thresholdH) inputSampleR = lastSampleHR - thresholdH; + + clamp = inputSampleR - lastSampleIR; + if (clamp > thresholdI) inputSampleR = lastSampleIR + thresholdI; + if (-clamp > thresholdI) inputSampleR = lastSampleIR - thresholdI; + + clamp = inputSampleR - lastSampleJR; + if (clamp > thresholdJ) inputSampleR = lastSampleJR + thresholdJ; + if (-clamp > thresholdJ) inputSampleR = lastSampleJR - thresholdJ; + + clamp = inputSampleR - lastSampleKR; + if (clamp > thresholdK) inputSampleR = lastSampleKR + thresholdK; + if (-clamp > thresholdK) inputSampleR = lastSampleKR - thresholdK; + + clamp = inputSampleR - lastSampleLR; + if (clamp > thresholdL) inputSampleR = lastSampleLR + thresholdL; + if (-clamp > thresholdL) inputSampleR = lastSampleLR - thresholdL; + + clamp = inputSampleR - lastSampleMR; + if (clamp > thresholdM) inputSampleR = lastSampleMR + thresholdM; + if (-clamp > thresholdM) inputSampleR = lastSampleMR - thresholdM; + + + lastSampleML = lastSampleLL; + lastSampleLL = lastSampleKL; + lastSampleKL = lastSampleJL; + lastSampleJL = lastSampleIL; + lastSampleIL = lastSampleHL; + lastSampleHL = lastSampleGL; + lastSampleGL = lastSampleFL; + lastSampleFL = lastSampleEL; + lastSampleEL = lastSampleDL; + lastSampleDL = lastSampleCL; + lastSampleCL = lastSampleBL; + lastSampleBL = lastSampleAL; + lastSampleAL = drySampleL; + //store the raw input sample again for use next time + + lastSampleMR = lastSampleLR; + lastSampleLR = lastSampleKR; + lastSampleKR = lastSampleJR; + lastSampleJR = lastSampleIR; + lastSampleIR = lastSampleHR; + lastSampleHR = lastSampleGR; + lastSampleGR = lastSampleFR; + lastSampleFR = lastSampleER; + lastSampleER = lastSampleDR; + lastSampleDR = lastSampleCR; + lastSampleCR = lastSampleBR; + lastSampleBR = lastSampleAR; + lastSampleAR = drySampleR; + //store the raw input sample again for use next time + + inputSampleL *= levelcorrect; + inputSampleL /= softslew; + inputSampleL -= (offsetL*offsetScale); + //begin IIR stage + inputSampleR *= levelcorrect; + inputSampleR /= softslew; + inputSampleR -= (offsetR*offsetScale); + //begin IIR stage + + inputSampleL += (thirdSampleL * thirdfilter); + inputSampleL /= (thirdfilter + 1.0); + inputSampleL += (lastSampleL * secondfilter); + inputSampleL /= (secondfilter + 1.0); + //do an IIR like thing to further squish superdistant stuff + inputSampleR += (thirdSampleR * thirdfilter); + inputSampleR /= (thirdfilter + 1.0); + inputSampleR += (lastSampleR * secondfilter); + inputSampleR /= (secondfilter + 1.0); + //do an IIR like thing to further squish superdistant stuff + + thirdSampleL = lastSampleL; + lastSampleL = inputSampleL; + inputSampleL *= levelcorrect; + + thirdSampleR = lastSampleR; + lastSampleR = inputSampleR; + inputSampleR *= levelcorrect; + + if (wet !=1.0) { + inputSampleL = (inputSampleL * wet) + (drySampleL * dry); + inputSampleR = (inputSampleR * wet) + (drySampleR * dry); + } + + //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. +} |