diff options
author | airwindows <jinx6568@sover.net> | 2018-04-29 21:14:57 -0400 |
---|---|---|
committer | airwindows <jinx6568@sover.net> | 2018-04-29 21:14:57 -0400 |
commit | af4c5c5652338c3a63c055d14cf1a5f239c608d9 (patch) | |
tree | f021c7832e7885eb9f3d0ab8b8660463104e802e /plugins/MacVST/AtmosphereBuss/source | |
parent | 77480fdccec98b86af77977b3b905b0a3ad9aadf (diff) | |
download | airwindows-lv2-port-af4c5c5652338c3a63c055d14cf1a5f239c608d9.tar.gz airwindows-lv2-port-af4c5c5652338c3a63c055d14cf1a5f239c608d9.tar.bz2 airwindows-lv2-port-af4c5c5652338c3a63c055d14cf1a5f239c608d9.zip |
Atmosphere
Diffstat (limited to 'plugins/MacVST/AtmosphereBuss/source')
3 files changed, 823 insertions, 0 deletions
diff --git a/plugins/MacVST/AtmosphereBuss/source/AtmosphereBuss.cpp b/plugins/MacVST/AtmosphereBuss/source/AtmosphereBuss.cpp new file mode 100755 index 0000000..c2a517a --- /dev/null +++ b/plugins/MacVST/AtmosphereBuss/source/AtmosphereBuss.cpp @@ -0,0 +1,165 @@ +/* ======================================== + * AtmosphereBuss - AtmosphereBuss.h + * Copyright (c) 2016 airwindows, All rights reserved + * ======================================== */ + +#ifndef __AtmosphereBuss_H +#include "AtmosphereBuss.h" +#endif + +AudioEffect* createEffectInstance(audioMasterCallback audioMaster) {return new AtmosphereBuss(audioMaster);} + +AtmosphereBuss::AtmosphereBuss(audioMasterCallback audioMaster) : + AudioEffectX(audioMaster, kNumPrograms, kNumParameters) +{ + A = 1.0; + + gainchase = -90.0; + settingchase = -90.0; + chasespeed = 350.0; + + fpNShapeL = 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; + + fpNShapeR = 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; + //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 +} + +AtmosphereBuss::~AtmosphereBuss() {} +VstInt32 AtmosphereBuss::getVendorVersion () {return 1000;} +void AtmosphereBuss::setProgramName(char *name) {vst_strncpy (_programName, name, kVstMaxProgNameLen);} +void AtmosphereBuss::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 AtmosphereBuss::getChunk (void** data, bool isPreset) +{ + float *chunkData = (float *)calloc(kNumParameters, sizeof(float)); + chunkData[0] = A; + /* 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 AtmosphereBuss::setChunk (void* data, VstInt32 byteSize, bool isPreset) +{ + float *chunkData = (float *)data; + A = pinParameter(chunkData[0]); + /* 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 AtmosphereBuss::setParameter(VstInt32 index, float value) { + switch (index) { + case kParamA: A = value; break; + default: throw; // unknown parameter, shouldn't happen! + } +} + +float AtmosphereBuss::getParameter(VstInt32 index) { + switch (index) { + case kParamA: return A; 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 AtmosphereBuss::getParameterName(VstInt32 index, char *text) { + switch (index) { + case kParamA: vst_strncpy (text, "Input", kVstMaxParamStrLen); break; + default: break; // unknown parameter, shouldn't happen! + } //this is our labels for displaying in the VST host +} + +void AtmosphereBuss::getParameterDisplay(VstInt32 index, char *text) { + switch (index) { + case kParamA: float2string (A, text, kVstMaxParamStrLen); break; + default: break; // unknown parameter, shouldn't happen! + } //this displays the values and handles 'popups' where it's discrete choices +} + +void AtmosphereBuss::getParameterLabel(VstInt32 index, char *text) { + switch (index) { + case kParamA: vst_strncpy (text, "", kVstMaxParamStrLen); break; + default: break; // unknown parameter, shouldn't happen! + } +} + +VstInt32 AtmosphereBuss::canDo(char *text) +{ return (_canDo.find(text) == _canDo.end()) ? -1: 1; } // 1 = yes, -1 = no, 0 = don't know + +bool AtmosphereBuss::getEffectName(char* name) { + vst_strncpy(name, "AtmosphereBuss", kVstMaxProductStrLen); return true; +} + +VstPlugCategory AtmosphereBuss::getPlugCategory() {return kPlugCategEffect;} + +bool AtmosphereBuss::getProductString(char* text) { + vst_strncpy (text, "airwindows AtmosphereBuss", kVstMaxProductStrLen); return true; +} + +bool AtmosphereBuss::getVendorString(char* text) { + vst_strncpy (text, "airwindows", kVstMaxVendorStrLen); return true; +} diff --git a/plugins/MacVST/AtmosphereBuss/source/AtmosphereBuss.h b/plugins/MacVST/AtmosphereBuss/source/AtmosphereBuss.h new file mode 100755 index 0000000..79a5d23 --- /dev/null +++ b/plugins/MacVST/AtmosphereBuss/source/AtmosphereBuss.h @@ -0,0 +1,106 @@ +/* ======================================== + * AtmosphereBuss - AtmosphereBuss.h + * Created 8/12/11 by SPIAdmin + * Copyright (c) 2011 __MyCompanyName__, All rights reserved + * ======================================== */ + +#ifndef __AtmosphereBuss_H +#define __AtmosphereBuss_H + +#ifndef __audioeffect__ +#include "audioeffectx.h" +#endif + +#include <set> +#include <string> +#include <math.h> + +enum { + kParamA = 0, + kNumParameters = 1 +}; // + +const int kNumPrograms = 0; +const int kNumInputs = 2; +const int kNumOutputs = 2; +const unsigned long kUniqueId = 'atbs'; //Change this to what the AU identity is! + +class AtmosphereBuss : + public AudioEffectX +{ +public: + AtmosphereBuss(audioMasterCallback audioMaster); + ~AtmosphereBuss(); + 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; + + double gainchase; + double settingchase; + double chasespeed; + + long double fpNShapeL; + 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 fpNShapeR; + 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; + + float A; +}; + +#endif diff --git a/plugins/MacVST/AtmosphereBuss/source/AtmosphereBussProc.cpp b/plugins/MacVST/AtmosphereBuss/source/AtmosphereBussProc.cpp new file mode 100755 index 0000000..6530a7e --- /dev/null +++ b/plugins/MacVST/AtmosphereBuss/source/AtmosphereBussProc.cpp @@ -0,0 +1,552 @@ +/* ======================================== + * AtmosphereBuss - AtmosphereBuss.h + * Copyright (c) 2016 airwindows, All rights reserved + * ======================================== */ + +#ifndef __AtmosphereBuss_H +#include "AtmosphereBuss.h" +#endif + +void AtmosphereBuss::processReplacing(float **inputs, float **outputs, VstInt32 sampleFrames) +{ + float* in1 = inputs[0]; + float* in2 = inputs[1]; + float* out1 = outputs[0]; + float* out2 = outputs[1]; + float fpTemp; + double overallscale = 1.0; + overallscale /= 44100.0; + overallscale *= getSampleRate(); + double drySampleL; + double drySampleR; + long double inputSampleL; + long double inputSampleR; + + long double clamp; + double inputgain = A; + + if (settingchase != inputgain) { + chasespeed *= 2.0; + settingchase = inputgain; + } + if (chasespeed > 2500.0) chasespeed = 2500.0; + if (gainchase < 0.0) gainchase = inputgain; + + 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; + + while (--sampleFrames >= 0) + { + inputSampleL = *in1; + 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 + + chasespeed *= 0.9999; + chasespeed -= 0.01; + if (chasespeed < 350.0) chasespeed = 350.0; + //we have our chase speed compensated for recent fader activity + + gainchase = (((gainchase*chasespeed)+inputgain)/(chasespeed+1.0)); + //gainchase is chasing the target, as a simple multiply gain factor + + if (1.0 != gainchase) { + inputSampleL *= gainchase; + inputSampleR *= gainchase; + } + //done with trim control + + drySampleL = inputSampleL; + drySampleR = inputSampleR; + + 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; + + + 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 L input sample again for use next time + + 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; + + if (inputSampleL > 1.0) inputSampleL = 1.0; + if (inputSampleL < -1.0) inputSampleL = -1.0; + if (inputSampleR > 1.0) inputSampleR = 1.0; + if (inputSampleR < -1.0) inputSampleR = -1.0; + //without this, you can get a NaN condition where it spits out DC offset at full blast! + + inputSampleL = asin(inputSampleL); + inputSampleR = asin(inputSampleR); + //amplitude aspect + + 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 R input sample again for use next time + + //noise shaping to 32-bit floating point + 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 AtmosphereBuss::processDoubleReplacing(double **inputs, double **outputs, VstInt32 sampleFrames) +{ + double* in1 = inputs[0]; + double* in2 = inputs[1]; + double* out1 = outputs[0]; + double* out2 = outputs[1]; + double fpTemp; + double overallscale = 1.0; + overallscale /= 44100.0; + overallscale *= getSampleRate(); + double drySampleL; + double drySampleR; + long double inputSampleL; + long double inputSampleR; + + long double clamp; + double inputgain = A; + + if (settingchase != inputgain) { + chasespeed *= 2.0; + settingchase = inputgain; + } + if (chasespeed > 2500.0) chasespeed = 2500.0; + if (gainchase < 0.0) gainchase = inputgain; + + 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; + + while (--sampleFrames >= 0) + { + inputSampleL = *in1; + 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 + + chasespeed *= 0.9999; + chasespeed -= 0.01; + if (chasespeed < 350.0) chasespeed = 350.0; + //we have our chase speed compensated for recent fader activity + + gainchase = (((gainchase*chasespeed)+inputgain)/(chasespeed+1.0)); + //gainchase is chasing the target, as a simple multiply gain factor + + if (1.0 != gainchase) { + inputSampleL *= gainchase; + inputSampleR *= gainchase; + } + //done with trim control + + drySampleL = inputSampleL; + drySampleR = inputSampleR; + + 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; + + + 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 L input sample again for use next time + + 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; + + if (inputSampleL > 1.0) inputSampleL = 1.0; + if (inputSampleL < -1.0) inputSampleL = -1.0; + if (inputSampleR > 1.0) inputSampleR = 1.0; + if (inputSampleR < -1.0) inputSampleR = -1.0; + //without this, you can get a NaN condition where it spits out DC offset at full blast! + + inputSampleL = asin(inputSampleL); + inputSampleR = asin(inputSampleR); + //amplitude aspect + + 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 R input sample again for use next time + + //noise shaping to 64-bit floating point + 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. +}
\ No newline at end of file |