diff options
author | Chris Johnson <jinx6568@sover.net> | 2018-10-22 18:04:06 -0400 |
---|---|---|
committer | Chris Johnson <jinx6568@sover.net> | 2018-10-22 18:04:06 -0400 |
commit | 633be2e22c6648c901f08f3b4cd4e8e14ea86443 (patch) | |
tree | 1e272c3d2b5bd29636b9f9f521af62734e4df012 /plugins/MacVST/AQuickVoiceClip/source | |
parent | 057757aa8eb0a463caf0cdfdb5894ac5f723ff3f (diff) | |
download | airwindows-lv2-port-633be2e22c6648c901f08f3b4cd4e8e14ea86443.tar.gz airwindows-lv2-port-633be2e22c6648c901f08f3b4cd4e8e14ea86443.tar.bz2 airwindows-lv2-port-633be2e22c6648c901f08f3b4cd4e8e14ea86443.zip |
Updates (in case my plane crashes)
Diffstat (limited to 'plugins/MacVST/AQuickVoiceClip/source')
3 files changed, 1194 insertions, 0 deletions
diff --git a/plugins/MacVST/AQuickVoiceClip/source/AQuickVoiceClip.cpp b/plugins/MacVST/AQuickVoiceClip/source/AQuickVoiceClip.cpp new file mode 100755 index 0000000..9b5ea81 --- /dev/null +++ b/plugins/MacVST/AQuickVoiceClip/source/AQuickVoiceClip.cpp @@ -0,0 +1,166 @@ +/* ======================================== + * AQuickVoiceClip - AQuickVoiceClip.h + * Copyright (c) 2016 airwindows, All rights reserved + * ======================================== */ + +#ifndef __AQuickVoiceClip_H +#include "AQuickVoiceClip.h" +#endif + +AudioEffect* createEffectInstance(audioMasterCallback audioMaster) {return new AQuickVoiceClip(audioMaster);} + +AQuickVoiceClip::AQuickVoiceClip(audioMasterCallback audioMaster) : + AudioEffectX(audioMaster, kNumPrograms, kNumParameters) +{ + A = 0.42; + LataLast6Sample = LataLast5Sample = LataLast4Sample = 0.0; + LataLast3Sample = LataLast2Sample = LataLast1Sample = 0.0; + LataHalfwaySample = LataHalfDrySample = LataHalfDiffSample = 0.0; + LataDrySample = LataDiffSample = LataPrevDiffSample = 0.0; + + RataLast6Sample = RataLast5Sample = RataLast4Sample = 0.0; + RataLast3Sample = RataLast2Sample = RataLast1Sample = 0.0; + RataHalfwaySample = RataHalfDrySample = RataHalfDiffSample = 0.0; + RataDrySample = RataDiffSample = RataPrevDiffSample = 0.0; + + LlastSample = 0.0; + LlastOutSample = 0.0; + LlastOut2Sample = 0.0; + LlastOut3Sample = 0.0; + LlpDepth = 0.0; + Lovershoot = 0.0; + Loverall = 0; + LiirSampleA = 0.0; + LiirSampleB = 0.0; + LiirSampleC = 0.0; + LiirSampleD = 0.0; + + RlastSample = 0.0; + RlastOutSample = 0.0; + RlastOut2Sample = 0.0; + RlastOut3Sample = 0.0; + RlpDepth = 0.0; + Rovershoot = 0.0; + Roverall = 0; + RiirSampleA = 0.0; + RiirSampleB = 0.0; + RiirSampleC = 0.0; + RiirSampleD = 0.0; + flip = true; + + ataK1 = -0.646; //first FIR shaping of interpolated sample, brightens + ataK2 = 0.311; //second FIR shaping of interpolated sample, thickens + ataK6 = -0.093; //third FIR shaping of interpolated sample, brings air + ataK7 = 0.057; //fourth FIR shaping of interpolated sample, thickens + ataK8 = -0.023; //fifth FIR shaping of interpolated sample, brings air + ataK3 = 0.114; //add raw to interpolated dry, toughens + ataK4 = 0.886; //remainder of interpolated dry, adds up to 1.0 + ataK5 = 0.431; //subtract this much prev. diff sample, brightens. 0.431 becomes flat + + fpNShapeLA = 0.0; + fpNShapeLB = 0.0; + fpNShapeRA = 0.0; + fpNShapeRB = 0.0; + fpFlip = true; + //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 +} + +AQuickVoiceClip::~AQuickVoiceClip() {} +VstInt32 AQuickVoiceClip::getVendorVersion () {return 1000;} +void AQuickVoiceClip::setProgramName(char *name) {vst_strncpy (_programName, name, kVstMaxProgNameLen);} +void AQuickVoiceClip::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 AQuickVoiceClip::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 AQuickVoiceClip::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 AQuickVoiceClip::setParameter(VstInt32 index, float value) { + switch (index) { + case kParamA: A = value; break; + default: throw; // unknown parameter, shouldn't happen! + } +} + +float AQuickVoiceClip::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 AQuickVoiceClip::getParameterName(VstInt32 index, char *text) { + switch (index) { + case kParamA: vst_strncpy (text, "Highpass", kVstMaxParamStrLen); break; + default: break; // unknown parameter, shouldn't happen! + } //this is our labels for displaying in the VST host +} + +void AQuickVoiceClip::getParameterDisplay(VstInt32 index, char *text) { + switch (index) { + case kParamA: float2string ((pow(A,3)*2070)+30, text, kVstMaxParamStrLen); break; + default: break; // unknown parameter, shouldn't happen! + } //this displays the values and handles 'popups' where it's discrete choices +} + +void AQuickVoiceClip::getParameterLabel(VstInt32 index, char *text) { + switch (index) { + case kParamA: vst_strncpy (text, "hz", kVstMaxParamStrLen); break; + default: break; // unknown parameter, shouldn't happen! + } +} + +VstInt32 AQuickVoiceClip::canDo(char *text) +{ return (_canDo.find(text) == _canDo.end()) ? -1: 1; } // 1 = yes, -1 = no, 0 = don't know + +bool AQuickVoiceClip::getEffectName(char* name) { + vst_strncpy(name, "AQuickVoiceClip", kVstMaxProductStrLen); return true; +} + +VstPlugCategory AQuickVoiceClip::getPlugCategory() {return kPlugCategEffect;} + +bool AQuickVoiceClip::getProductString(char* text) { + vst_strncpy (text, "airwindows AQuickVoiceClip", kVstMaxProductStrLen); return true; +} + +bool AQuickVoiceClip::getVendorString(char* text) { + vst_strncpy (text, "airwindows", kVstMaxVendorStrLen); return true; +} diff --git a/plugins/MacVST/AQuickVoiceClip/source/AQuickVoiceClip.h b/plugins/MacVST/AQuickVoiceClip/source/AQuickVoiceClip.h new file mode 100755 index 0000000..dc8f5fa --- /dev/null +++ b/plugins/MacVST/AQuickVoiceClip/source/AQuickVoiceClip.h @@ -0,0 +1,128 @@ +/* ======================================== + * AQuickVoiceClip - AQuickVoiceClip.h + * Created 8/12/11 by SPIAdmin + * Copyright (c) 2011 __MyCompanyName__, All rights reserved + * ======================================== */ + +#ifndef __AQuickVoiceClip_H +#define __AQuickVoiceClip_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 = 'aqvc'; //Change this to what the AU identity is! + +class AQuickVoiceClip : + public AudioEffectX +{ +public: + AQuickVoiceClip(audioMasterCallback audioMaster); + ~AQuickVoiceClip(); + 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 LataLast6Sample; + double LataLast5Sample; + double LataLast4Sample; + double LataLast3Sample; + double LataLast2Sample; + double LataLast1Sample; + double LataHalfwaySample; + double LataHalfDrySample; + double LataHalfDiffSample; + double LataLastDiffSample; + double LataDrySample; + double LataDiffSample; + double LataPrevDiffSample; + + double RataLast6Sample; + double RataLast5Sample; + double RataLast4Sample; + double RataLast3Sample; + double RataLast2Sample; + double RataLast1Sample; + double RataHalfwaySample; + double RataHalfDrySample; + double RataHalfDiffSample; + double RataLastDiffSample; + double RataDrySample; + double RataDiffSample; + double RataPrevDiffSample; + + double ataK1; + double ataK2; + double ataK3; + double ataK4; + double ataK5; + double ataK6; + double ataK7; + double ataK8; //end antialiasing variables + + double LlastSample; + double LlastOutSample; + double LlastOut2Sample; + double LlastOut3Sample; + double LlpDepth; + double Lovershoot; + double Loverall; + double LiirSampleA; + double LiirSampleB; + double LiirSampleC; + double LiirSampleD; + + double RlastSample; + double RlastOutSample; + double RlastOut2Sample; + double RlastOut3Sample; + double RlpDepth; + double Rovershoot; + double Roverall; + double RiirSampleA; + double RiirSampleB; + double RiirSampleC; + double RiirSampleD; + bool flip; + + long double fpNShapeLA; + long double fpNShapeLB; + long double fpNShapeRA; + long double fpNShapeRB; + bool fpFlip; + //default stuff + + float A; +}; + +#endif diff --git a/plugins/MacVST/AQuickVoiceClip/source/AQuickVoiceClipProc.cpp b/plugins/MacVST/AQuickVoiceClip/source/AQuickVoiceClipProc.cpp new file mode 100755 index 0000000..69dc283 --- /dev/null +++ b/plugins/MacVST/AQuickVoiceClip/source/AQuickVoiceClipProc.cpp @@ -0,0 +1,900 @@ +/* ======================================== + * AQuickVoiceClip - AQuickVoiceClip.h + * Copyright (c) 2016 airwindows, All rights reserved + * ======================================== */ + +#ifndef __AQuickVoiceClip_H +#include "AQuickVoiceClip.h" +#endif + +void AQuickVoiceClip::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(); + + double softness = 0.484416; + double hardness = 1.0 - softness; + double iirAmount = ((pow(A,3)*2070)+30)/8000.0; + iirAmount /= overallscale; + double altAmount = (1.0 - iirAmount); + double cancelnew = 0.0682276; + double cancelold = 1.0 - cancelnew; + double lpSpeed = 0.0009; + double cliplevel = 0.98; + double refclip = 0.5; //preset to cut out gain quite a lot. 91%? no touchy unless clip + + double LmaxRecent; + bool LclipOnset; + double LpassThrough; + double LoutputSample; + double LdrySample; + + double RmaxRecent; + bool RclipOnset; + double RpassThrough; + double RoutputSample; + double RdrySample; + + float fpTemp; + long double fpOld = 0.618033988749894848204586; //golden ratio! + long double fpNew = 1.0 - fpOld; + + long double inputSampleL; + long double inputSampleR; + + while (--sampleFrames >= 0) + { + inputSampleL = *in1; + inputSampleR = *in2; + if (inputSampleL<1.2e-38 && -inputSampleL<1.2e-38) { + static int noisesource = 0; + //this declares a variable before anything else is compiled. It won't keep assigning + //it to 0 for every sample, it's as if the declaration doesn't exist in this context, + //but it lets me add this denormalization fix in a single place rather than updating + //it in three different locations. The variable isn't thread-safe but this is only + //a random seed and we can share it with whatever. + noisesource = noisesource % 1700021; noisesource++; + int residue = noisesource * noisesource; + residue = residue % 170003; residue *= residue; + residue = residue % 17011; residue *= residue; + residue = residue % 1709; residue *= residue; + residue = residue % 173; residue *= residue; + residue = residue % 17; + double applyresidue = residue; + applyresidue *= 0.00000001; + applyresidue *= 0.00000001; + inputSampleL = applyresidue; + } + if (inputSampleR<1.2e-38 && -inputSampleR<1.2e-38) { + static int noisesource = 0; + noisesource = noisesource % 1700021; noisesource++; + int residue = noisesource * noisesource; + residue = residue % 170003; residue *= residue; + residue = residue % 17011; residue *= residue; + residue = residue % 1709; residue *= residue; + residue = residue % 173; residue *= residue; + residue = residue % 17; + double applyresidue = residue; + applyresidue *= 0.00000001; + applyresidue *= 0.00000001; + inputSampleR = applyresidue; + //this denormalization routine produces a white noise at -300 dB which the noise + //shaping will interact with to produce a bipolar output, but the noise is actually + //all positive. That should stop any variables from going denormal, and the routine + //only kicks in if digital black is input. As a final touch, if you save to 24-bit + //the silence will return to being digital black again. + } + LpassThrough = LataDrySample = inputSampleL; + RpassThrough = RataDrySample = inputSampleR; + + LataHalfDrySample = LataHalfwaySample = (inputSampleL + LataLast1Sample + (LataLast2Sample*ataK1) + (LataLast3Sample*ataK2) + (LataLast4Sample*ataK6) + (LataLast5Sample*ataK7) + (LataLast6Sample*ataK8)) / 2.0; + LataLast6Sample = LataLast5Sample; LataLast5Sample = LataLast4Sample; LataLast4Sample = LataLast3Sample; LataLast3Sample = LataLast2Sample; LataLast2Sample = LataLast1Sample; LataLast1Sample = inputSampleL; + //setting up oversampled special antialiasing + RataHalfDrySample = RataHalfwaySample = (inputSampleR + RataLast1Sample + (RataLast2Sample*ataK1) + (RataLast3Sample*ataK2) + (RataLast4Sample*ataK6) + (RataLast5Sample*ataK7) + (RataLast6Sample*ataK8)) / 2.0; + RataLast6Sample = RataLast5Sample; RataLast5Sample = RataLast4Sample; RataLast4Sample = RataLast3Sample; RataLast3Sample = RataLast2Sample; RataLast2Sample = RataLast1Sample; RataLast1Sample = inputSampleR; + //setting up oversampled special antialiasing + LclipOnset = false; + RclipOnset = false; + + + LmaxRecent = fabs( LataLast6Sample ); + if (fabs( LataLast5Sample ) > LmaxRecent ) LmaxRecent = fabs( LataLast5Sample ); + if (fabs( LataLast4Sample ) > LmaxRecent ) LmaxRecent = fabs( LataLast4Sample ); + if (fabs( LataLast3Sample ) > LmaxRecent ) LmaxRecent = fabs( LataLast3Sample ); + if (fabs( LataLast2Sample ) > LmaxRecent ) LmaxRecent = fabs( LataLast2Sample ); + if (fabs( LataLast1Sample ) > LmaxRecent ) LmaxRecent = fabs( LataLast1Sample ); + if (fabs( inputSampleL ) > LmaxRecent ) LmaxRecent = fabs( inputSampleL ); + //this gives us something that won't cut out in zero crossings, to interpolate with + + RmaxRecent = fabs( RataLast6Sample ); + if (fabs( RataLast5Sample ) > RmaxRecent ) RmaxRecent = fabs( RataLast5Sample ); + if (fabs( RataLast4Sample ) > RmaxRecent ) RmaxRecent = fabs( RataLast4Sample ); + if (fabs( RataLast3Sample ) > RmaxRecent ) RmaxRecent = fabs( RataLast3Sample ); + if (fabs( RataLast2Sample ) > RmaxRecent ) RmaxRecent = fabs( RataLast2Sample ); + if (fabs( RataLast1Sample ) > RmaxRecent ) RmaxRecent = fabs( RataLast1Sample ); + if (fabs( inputSampleR ) > RmaxRecent ) RmaxRecent = fabs( inputSampleR ); + //this gives us something that won't cut out in zero crossings, to interpolate with + + LmaxRecent *= 2.0; + RmaxRecent *= 2.0; + //by refclip this is 1.0 and fully into the antialiasing + if (LmaxRecent > 1.0) LmaxRecent = 1.0; + if (RmaxRecent > 1.0) RmaxRecent = 1.0; + //and it tops out at 1. Higher means more antialiasing, lower blends into passThrough without antialiasing + + LataHalfwaySample -= Loverall; + RataHalfwaySample -= Roverall; + //subtract dist-cancel from input after getting raw input, before doing anything + + LdrySample = LataHalfwaySample; + RdrySample = RataHalfwaySample; + + + //begin L channel for the clipper + if (LlastSample >= refclip) + { + LlpDepth += 0.1; + if (LataHalfwaySample < refclip) + { + LlastSample = ((refclip*hardness) + (LataHalfwaySample * softness)); + } + else LlastSample = refclip; + } + + if (LlastSample <= -refclip) + { + LlpDepth += 0.1; + if (LataHalfwaySample > -refclip) + { + LlastSample = ((-refclip*hardness) + (LataHalfwaySample * softness)); + } + else LlastSample = -refclip; + } + + if (LataHalfwaySample > refclip) + { + LlpDepth += 0.1; + if (LlastSample < refclip) + { + LataHalfwaySample = ((refclip*hardness) + (LlastSample * softness)); + } + else LataHalfwaySample = refclip; + } + + if (LataHalfwaySample < -refclip) + { + LlpDepth += 0.1; + if (LlastSample > -refclip) + { + LataHalfwaySample = ((-refclip*hardness) + (LlastSample * softness)); + } + else LataHalfwaySample = -refclip; + } + ///end L channel for the clipper + + //begin R channel for the clipper + if (RlastSample >= refclip) + { + RlpDepth += 0.1; + if (RataHalfwaySample < refclip) + { + RlastSample = ((refclip*hardness) + (RataHalfwaySample * softness)); + } + else RlastSample = refclip; + } + + if (RlastSample <= -refclip) + { + RlpDepth += 0.1; + if (RataHalfwaySample > -refclip) + { + RlastSample = ((-refclip*hardness) + (RataHalfwaySample * softness)); + } + else RlastSample = -refclip; + } + + if (RataHalfwaySample > refclip) + { + RlpDepth += 0.1; + if (RlastSample < refclip) + { + RataHalfwaySample = ((refclip*hardness) + (RlastSample * softness)); + } + else RataHalfwaySample = refclip; + } + + if (RataHalfwaySample < -refclip) + { + RlpDepth += 0.1; + if (RlastSample > -refclip) + { + RataHalfwaySample = ((-refclip*hardness) + (RlastSample * softness)); + } + else RataHalfwaySample = -refclip; + } + ///end R channel for the clipper + + LoutputSample = LlastSample; + RoutputSample = RlastSample; + + LlastSample = LataHalfwaySample; + RlastSample = RataHalfwaySample; + + LataHalfwaySample = LoutputSample; + RataHalfwaySample = RoutputSample; + //swap around in a circle for one final ADClip, + //this time not tracking overshoot anymore + //end interpolated sample + //begin raw sample- inputSample and ataDrySample handled separately here + + inputSampleL -= Loverall; + inputSampleR -= Roverall; + //subtract dist-cancel from input after getting raw input, before doing anything + + LdrySample = inputSampleL; + RdrySample = inputSampleR; + + //begin second L clip + if (LlastSample >= refclip) + { + LlpDepth += 0.1; + if (inputSampleL < refclip) + { + LlastSample = ((refclip*hardness) + (inputSampleL * softness)); + } + else LlastSample = refclip; + } + + if (LlastSample <= -refclip) + { + LlpDepth += 0.1; + if (inputSampleL > -refclip) + { + LlastSample = ((-refclip*hardness) + (inputSampleL * softness)); + } + else LlastSample = -refclip; + } + + if (inputSampleL > refclip) + { + LlpDepth += 0.1; + if (LlastSample < refclip) + { + inputSampleL = ((refclip*hardness) + (LlastSample * softness)); + } + else inputSampleL = refclip; + } + + if (inputSampleL < -refclip) + { + LlpDepth += 0.1; + if (LlastSample > -refclip) + { + inputSampleL = ((-refclip*hardness) + (LlastSample * softness)); + } + else inputSampleL = -refclip; + } + //end second L clip + + //begin second R clip + if (RlastSample >= refclip) + { + RlpDepth += 0.1; + if (inputSampleR < refclip) + { + RlastSample = ((refclip*hardness) + (inputSampleR * softness)); + } + else RlastSample = refclip; + } + + if (RlastSample <= -refclip) + { + RlpDepth += 0.1; + if (inputSampleR > -refclip) + { + RlastSample = ((-refclip*hardness) + (inputSampleR * softness)); + } + else RlastSample = -refclip; + } + + if (inputSampleR > refclip) + { + RlpDepth += 0.1; + if (RlastSample < refclip) + { + inputSampleR = ((refclip*hardness) + (RlastSample * softness)); + } + else inputSampleR = refclip; + } + + if (inputSampleR < -refclip) + { + RlpDepth += 0.1; + if (RlastSample > -refclip) + { + inputSampleR = ((-refclip*hardness) + (RlastSample * softness)); + } + else inputSampleR = -refclip; + } + //end second R clip + + LoutputSample = LlastSample; + RoutputSample = RlastSample; + LlastSample = inputSampleL; + RlastSample = inputSampleR; + inputSampleL = LoutputSample; + inputSampleR = RoutputSample; + + LataHalfDrySample = (LataDrySample*ataK3)+(LataHalfDrySample*ataK4); + LataHalfDiffSample = (LataHalfwaySample - LataHalfDrySample)/2.0; + LataLastDiffSample = LataDiffSample*ataK5; + LataDiffSample = (inputSampleL - LataDrySample)/2.0; + LataDiffSample += LataHalfDiffSample; + LataDiffSample -= LataLastDiffSample; + inputSampleL = LataDrySample; + inputSampleL += LataDiffSample; + + RataHalfDrySample = (RataDrySample*ataK3)+(RataHalfDrySample*ataK4); + RataHalfDiffSample = (RataHalfwaySample - RataHalfDrySample)/2.0; + RataLastDiffSample = RataDiffSample*ataK5; + RataDiffSample = (inputSampleR - RataDrySample)/2.0; + RataDiffSample += RataHalfDiffSample; + RataDiffSample -= RataLastDiffSample; + inputSampleR = RataDrySample; + inputSampleR += RataDiffSample; + + Loverall = (Loverall * cancelold) + (LataDiffSample * cancelnew); + Roverall = (Roverall * cancelold) + (RataDiffSample * cancelnew); + //apply all the diffs to a lowpassed IIR + + + if (flip) + { + LiirSampleA = (LiirSampleA * altAmount) + (inputSampleL * iirAmount); + inputSampleL -= LiirSampleA; + LiirSampleC = (LiirSampleC * altAmount) + (LpassThrough * iirAmount); + LpassThrough -= LiirSampleC; + + RiirSampleA = (RiirSampleA * altAmount) + (inputSampleR * iirAmount); + inputSampleR -= RiirSampleA; + RiirSampleC = (RiirSampleC * altAmount) + (RpassThrough * iirAmount); + RpassThrough -= RiirSampleC; + } + else + { + LiirSampleB = (LiirSampleB * altAmount) + (inputSampleL * iirAmount); + inputSampleL -= LiirSampleB; + LiirSampleD = (LiirSampleD * altAmount) + (LpassThrough * iirAmount); + LpassThrough -= LiirSampleD; + + RiirSampleB = (RiirSampleB * altAmount) + (inputSampleR * iirAmount); + inputSampleR -= RiirSampleB; + RiirSampleD = (RiirSampleD * altAmount) + (RpassThrough * iirAmount); + RpassThrough -= RiirSampleD; + } + flip = !flip; + //highpass section + + LlastOut3Sample = LlastOut2Sample; + LlastOut2Sample = LlastOutSample; + LlastOutSample = inputSampleL; + + RlastOut3Sample = RlastOut2Sample; + RlastOut2Sample = RlastOutSample; + RlastOutSample = inputSampleR; + + + LlpDepth -= lpSpeed; + RlpDepth -= lpSpeed; + + if (LlpDepth > 0.0) + { + if (LlpDepth > 1.0) LlpDepth = 1.0; + inputSampleL *= (1.0-LlpDepth); + inputSampleL += (((LlastOutSample + LlastOut2Sample + LlastOut3Sample) / 3.6)*LlpDepth); + } + + if (RlpDepth > 0.0) + { + if (RlpDepth > 1.0) RlpDepth = 1.0; + inputSampleR *= (1.0-RlpDepth); + inputSampleR += (((RlastOutSample + RlastOut2Sample + RlastOut3Sample) / 3.6)*RlpDepth); + } + + if (LlpDepth < 0.0) LlpDepth = 0.0; + if (RlpDepth < 0.0) RlpDepth = 0.0; + + //noise shaping to 32-bit floating point + if (fpFlip) { + fpTemp = inputSampleL; + fpNShapeLA = (fpNShapeLA*fpOld)+((inputSampleL-fpTemp)*fpNew); + inputSampleL += fpNShapeLA; + fpTemp = inputSampleR; + fpNShapeRA = (fpNShapeRA*fpOld)+((inputSampleR-fpTemp)*fpNew); + inputSampleR += fpNShapeRA; + } + else { + fpTemp = inputSampleL; + fpNShapeLB = (fpNShapeLB*fpOld)+((inputSampleL-fpTemp)*fpNew); + inputSampleL += fpNShapeLB; + fpTemp = inputSampleR; + fpNShapeRB = (fpNShapeRB*fpOld)+((inputSampleR-fpTemp)*fpNew); + inputSampleR += fpNShapeRB; + } + fpFlip = !fpFlip; + //end noise shaping on 32 bit output + + inputSampleL *= (1.0-LmaxRecent); + inputSampleR *= (1.0-RmaxRecent); + inputSampleL += (LpassThrough * LmaxRecent); + inputSampleR += (RpassThrough * RmaxRecent); + //there's our raw signal, without antialiasing. Brings up low level stuff and softens more when hot + + if (inputSampleL > cliplevel) inputSampleL = cliplevel; + if (inputSampleL < -cliplevel) inputSampleL = -cliplevel; + if (inputSampleR > cliplevel) inputSampleR = cliplevel; + if (inputSampleR < -cliplevel) inputSampleR = -cliplevel; + //final iron bar + + + *out1 = inputSampleL; + *out2 = inputSampleR; + + *in1++; + *in2++; + *out1++; + *out2++; + } +} + +void AQuickVoiceClip::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(); + + double softness = 0.484416; + double hardness = 1.0 - softness; + double iirAmount = ((pow(A,3)*2070)+30)/8000.0; + iirAmount /= overallscale; + double altAmount = (1.0 - iirAmount); + double cancelnew = 0.0682276; + double cancelold = 1.0 - cancelnew; + double lpSpeed = 0.0009; + double cliplevel = 0.98; + double refclip = 0.5; //preset to cut out gain quite a lot. 91%? no touchy unless clip + + double LmaxRecent; + bool LclipOnset; + double LpassThrough; + double LoutputSample; + double LdrySample; + + double RmaxRecent; + bool RclipOnset; + double RpassThrough; + double RoutputSample; + double RdrySample; + + double fpTemp; //this is different from singlereplacing + long double fpOld = 0.618033988749894848204586; //golden ratio! + long double fpNew = 1.0 - fpOld; + + long double inputSampleL; + long double inputSampleR; + + while (--sampleFrames >= 0) + { + inputSampleL = *in1; + inputSampleR = *in2; + if (inputSampleL<1.2e-38 && -inputSampleL<1.2e-38) { + static int noisesource = 0; + //this declares a variable before anything else is compiled. It won't keep assigning + //it to 0 for every sample, it's as if the declaration doesn't exist in this context, + //but it lets me add this denormalization fix in a single place rather than updating + //it in three different locations. The variable isn't thread-safe but this is only + //a random seed and we can share it with whatever. + noisesource = noisesource % 1700021; noisesource++; + int residue = noisesource * noisesource; + residue = residue % 170003; residue *= residue; + residue = residue % 17011; residue *= residue; + residue = residue % 1709; residue *= residue; + residue = residue % 173; residue *= residue; + residue = residue % 17; + double applyresidue = residue; + applyresidue *= 0.00000001; + applyresidue *= 0.00000001; + inputSampleL = applyresidue; + } + if (inputSampleR<1.2e-38 && -inputSampleR<1.2e-38) { + static int noisesource = 0; + noisesource = noisesource % 1700021; noisesource++; + int residue = noisesource * noisesource; + residue = residue % 170003; residue *= residue; + residue = residue % 17011; residue *= residue; + residue = residue % 1709; residue *= residue; + residue = residue % 173; residue *= residue; + residue = residue % 17; + double applyresidue = residue; + applyresidue *= 0.00000001; + applyresidue *= 0.00000001; + inputSampleR = applyresidue; + //this denormalization routine produces a white noise at -300 dB which the noise + //shaping will interact with to produce a bipolar output, but the noise is actually + //all positive. That should stop any variables from going denormal, and the routine + //only kicks in if digital black is input. As a final touch, if you save to 24-bit + //the silence will return to being digital black again. + } + LpassThrough = LataDrySample = inputSampleL; + RpassThrough = RataDrySample = inputSampleR; + + LataHalfDrySample = LataHalfwaySample = (inputSampleL + LataLast1Sample + (LataLast2Sample*ataK1) + (LataLast3Sample*ataK2) + (LataLast4Sample*ataK6) + (LataLast5Sample*ataK7) + (LataLast6Sample*ataK8)) / 2.0; + LataLast6Sample = LataLast5Sample; LataLast5Sample = LataLast4Sample; LataLast4Sample = LataLast3Sample; LataLast3Sample = LataLast2Sample; LataLast2Sample = LataLast1Sample; LataLast1Sample = inputSampleL; + //setting up oversampled special antialiasing + RataHalfDrySample = RataHalfwaySample = (inputSampleR + RataLast1Sample + (RataLast2Sample*ataK1) + (RataLast3Sample*ataK2) + (RataLast4Sample*ataK6) + (RataLast5Sample*ataK7) + (RataLast6Sample*ataK8)) / 2.0; + RataLast6Sample = RataLast5Sample; RataLast5Sample = RataLast4Sample; RataLast4Sample = RataLast3Sample; RataLast3Sample = RataLast2Sample; RataLast2Sample = RataLast1Sample; RataLast1Sample = inputSampleR; + //setting up oversampled special antialiasing + LclipOnset = false; + RclipOnset = false; + + + LmaxRecent = fabs( LataLast6Sample ); + if (fabs( LataLast5Sample ) > LmaxRecent ) LmaxRecent = fabs( LataLast5Sample ); + if (fabs( LataLast4Sample ) > LmaxRecent ) LmaxRecent = fabs( LataLast4Sample ); + if (fabs( LataLast3Sample ) > LmaxRecent ) LmaxRecent = fabs( LataLast3Sample ); + if (fabs( LataLast2Sample ) > LmaxRecent ) LmaxRecent = fabs( LataLast2Sample ); + if (fabs( LataLast1Sample ) > LmaxRecent ) LmaxRecent = fabs( LataLast1Sample ); + if (fabs( inputSampleL ) > LmaxRecent ) LmaxRecent = fabs( inputSampleL ); + //this gives us something that won't cut out in zero crossings, to interpolate with + + RmaxRecent = fabs( RataLast6Sample ); + if (fabs( RataLast5Sample ) > RmaxRecent ) RmaxRecent = fabs( RataLast5Sample ); + if (fabs( RataLast4Sample ) > RmaxRecent ) RmaxRecent = fabs( RataLast4Sample ); + if (fabs( RataLast3Sample ) > RmaxRecent ) RmaxRecent = fabs( RataLast3Sample ); + if (fabs( RataLast2Sample ) > RmaxRecent ) RmaxRecent = fabs( RataLast2Sample ); + if (fabs( RataLast1Sample ) > RmaxRecent ) RmaxRecent = fabs( RataLast1Sample ); + if (fabs( inputSampleR ) > RmaxRecent ) RmaxRecent = fabs( inputSampleR ); + //this gives us something that won't cut out in zero crossings, to interpolate with + + LmaxRecent *= 2.0; + RmaxRecent *= 2.0; + //by refclip this is 1.0 and fully into the antialiasing + if (LmaxRecent > 1.0) LmaxRecent = 1.0; + if (RmaxRecent > 1.0) RmaxRecent = 1.0; + //and it tops out at 1. Higher means more antialiasing, lower blends into passThrough without antialiasing + + LataHalfwaySample -= Loverall; + RataHalfwaySample -= Roverall; + //subtract dist-cancel from input after getting raw input, before doing anything + + LdrySample = LataHalfwaySample; + RdrySample = RataHalfwaySample; + + + //begin L channel for the clipper + if (LlastSample >= refclip) + { + LlpDepth += 0.1; + if (LataHalfwaySample < refclip) + { + LlastSample = ((refclip*hardness) + (LataHalfwaySample * softness)); + } + else LlastSample = refclip; + } + + if (LlastSample <= -refclip) + { + LlpDepth += 0.1; + if (LataHalfwaySample > -refclip) + { + LlastSample = ((-refclip*hardness) + (LataHalfwaySample * softness)); + } + else LlastSample = -refclip; + } + + if (LataHalfwaySample > refclip) + { + LlpDepth += 0.1; + if (LlastSample < refclip) + { + LataHalfwaySample = ((refclip*hardness) + (LlastSample * softness)); + } + else LataHalfwaySample = refclip; + } + + if (LataHalfwaySample < -refclip) + { + LlpDepth += 0.1; + if (LlastSample > -refclip) + { + LataHalfwaySample = ((-refclip*hardness) + (LlastSample * softness)); + } + else LataHalfwaySample = -refclip; + } + ///end L channel for the clipper + + //begin R channel for the clipper + if (RlastSample >= refclip) + { + RlpDepth += 0.1; + if (RataHalfwaySample < refclip) + { + RlastSample = ((refclip*hardness) + (RataHalfwaySample * softness)); + } + else RlastSample = refclip; + } + + if (RlastSample <= -refclip) + { + RlpDepth += 0.1; + if (RataHalfwaySample > -refclip) + { + RlastSample = ((-refclip*hardness) + (RataHalfwaySample * softness)); + } + else RlastSample = -refclip; + } + + if (RataHalfwaySample > refclip) + { + RlpDepth += 0.1; + if (RlastSample < refclip) + { + RataHalfwaySample = ((refclip*hardness) + (RlastSample * softness)); + } + else RataHalfwaySample = refclip; + } + + if (RataHalfwaySample < -refclip) + { + RlpDepth += 0.1; + if (RlastSample > -refclip) + { + RataHalfwaySample = ((-refclip*hardness) + (RlastSample * softness)); + } + else RataHalfwaySample = -refclip; + } + ///end R channel for the clipper + + LoutputSample = LlastSample; + RoutputSample = RlastSample; + + LlastSample = LataHalfwaySample; + RlastSample = RataHalfwaySample; + + LataHalfwaySample = LoutputSample; + RataHalfwaySample = RoutputSample; + //swap around in a circle for one final ADClip, + //this time not tracking overshoot anymore + //end interpolated sample + //begin raw sample- inputSample and ataDrySample handled separately here + + inputSampleL -= Loverall; + inputSampleR -= Roverall; + //subtract dist-cancel from input after getting raw input, before doing anything + + LdrySample = inputSampleL; + RdrySample = inputSampleR; + + //begin second L clip + if (LlastSample >= refclip) + { + LlpDepth += 0.1; + if (inputSampleL < refclip) + { + LlastSample = ((refclip*hardness) + (inputSampleL * softness)); + } + else LlastSample = refclip; + } + + if (LlastSample <= -refclip) + { + LlpDepth += 0.1; + if (inputSampleL > -refclip) + { + LlastSample = ((-refclip*hardness) + (inputSampleL * softness)); + } + else LlastSample = -refclip; + } + + if (inputSampleL > refclip) + { + LlpDepth += 0.1; + if (LlastSample < refclip) + { + inputSampleL = ((refclip*hardness) + (LlastSample * softness)); + } + else inputSampleL = refclip; + } + + if (inputSampleL < -refclip) + { + LlpDepth += 0.1; + if (LlastSample > -refclip) + { + inputSampleL = ((-refclip*hardness) + (LlastSample * softness)); + } + else inputSampleL = -refclip; + } + //end second L clip + + //begin second R clip + if (RlastSample >= refclip) + { + RlpDepth += 0.1; + if (inputSampleR < refclip) + { + RlastSample = ((refclip*hardness) + (inputSampleR * softness)); + } + else RlastSample = refclip; + } + + if (RlastSample <= -refclip) + { + RlpDepth += 0.1; + if (inputSampleR > -refclip) + { + RlastSample = ((-refclip*hardness) + (inputSampleR * softness)); + } + else RlastSample = -refclip; + } + + if (inputSampleR > refclip) + { + RlpDepth += 0.1; + if (RlastSample < refclip) + { + inputSampleR = ((refclip*hardness) + (RlastSample * softness)); + } + else inputSampleR = refclip; + } + + if (inputSampleR < -refclip) + { + RlpDepth += 0.1; + if (RlastSample > -refclip) + { + inputSampleR = ((-refclip*hardness) + (RlastSample * softness)); + } + else inputSampleR = -refclip; + } + //end second R clip + + LoutputSample = LlastSample; + RoutputSample = RlastSample; + LlastSample = inputSampleL; + RlastSample = inputSampleR; + inputSampleL = LoutputSample; + inputSampleR = RoutputSample; + + LataHalfDrySample = (LataDrySample*ataK3)+(LataHalfDrySample*ataK4); + LataHalfDiffSample = (LataHalfwaySample - LataHalfDrySample)/2.0; + LataLastDiffSample = LataDiffSample*ataK5; + LataDiffSample = (inputSampleL - LataDrySample)/2.0; + LataDiffSample += LataHalfDiffSample; + LataDiffSample -= LataLastDiffSample; + inputSampleL = LataDrySample; + inputSampleL += LataDiffSample; + + RataHalfDrySample = (RataDrySample*ataK3)+(RataHalfDrySample*ataK4); + RataHalfDiffSample = (RataHalfwaySample - RataHalfDrySample)/2.0; + RataLastDiffSample = RataDiffSample*ataK5; + RataDiffSample = (inputSampleR - RataDrySample)/2.0; + RataDiffSample += RataHalfDiffSample; + RataDiffSample -= RataLastDiffSample; + inputSampleR = RataDrySample; + inputSampleR += RataDiffSample; + + Loverall = (Loverall * cancelold) + (LataDiffSample * cancelnew); + Roverall = (Roverall * cancelold) + (RataDiffSample * cancelnew); + //apply all the diffs to a lowpassed IIR + + + if (flip) + { + LiirSampleA = (LiirSampleA * altAmount) + (inputSampleL * iirAmount); + inputSampleL -= LiirSampleA; + LiirSampleC = (LiirSampleC * altAmount) + (LpassThrough * iirAmount); + LpassThrough -= LiirSampleC; + + RiirSampleA = (RiirSampleA * altAmount) + (inputSampleR * iirAmount); + inputSampleR -= RiirSampleA; + RiirSampleC = (RiirSampleC * altAmount) + (RpassThrough * iirAmount); + RpassThrough -= RiirSampleC; + } + else + { + LiirSampleB = (LiirSampleB * altAmount) + (inputSampleL * iirAmount); + inputSampleL -= LiirSampleB; + LiirSampleD = (LiirSampleD * altAmount) + (LpassThrough * iirAmount); + LpassThrough -= LiirSampleD; + + RiirSampleB = (RiirSampleB * altAmount) + (inputSampleR * iirAmount); + inputSampleR -= RiirSampleB; + RiirSampleD = (RiirSampleD * altAmount) + (RpassThrough * iirAmount); + RpassThrough -= RiirSampleD; + } + flip = !flip; + //highpass section + + LlastOut3Sample = LlastOut2Sample; + LlastOut2Sample = LlastOutSample; + LlastOutSample = inputSampleL; + + RlastOut3Sample = RlastOut2Sample; + RlastOut2Sample = RlastOutSample; + RlastOutSample = inputSampleR; + + + LlpDepth -= lpSpeed; + RlpDepth -= lpSpeed; + + if (LlpDepth > 0.0) + { + if (LlpDepth > 1.0) LlpDepth = 1.0; + inputSampleL *= (1.0-LlpDepth); + inputSampleL += (((LlastOutSample + LlastOut2Sample + LlastOut3Sample) / 3.6)*LlpDepth); + } + + if (RlpDepth > 0.0) + { + if (RlpDepth > 1.0) RlpDepth = 1.0; + inputSampleR *= (1.0-RlpDepth); + inputSampleR += (((RlastOutSample + RlastOut2Sample + RlastOut3Sample) / 3.6)*RlpDepth); + } + + if (LlpDepth < 0.0) LlpDepth = 0.0; + if (RlpDepth < 0.0) RlpDepth = 0.0; + + //noise shaping to 64-bit floating point + if (fpFlip) { + fpTemp = inputSampleL; + fpNShapeLA = (fpNShapeLA*fpOld)+((inputSampleL-fpTemp)*fpNew); + inputSampleL += fpNShapeLA; + fpTemp = inputSampleR; + fpNShapeRA = (fpNShapeRA*fpOld)+((inputSampleR-fpTemp)*fpNew); + inputSampleR += fpNShapeRA; + } + else { + fpTemp = inputSampleL; + fpNShapeLB = (fpNShapeLB*fpOld)+((inputSampleL-fpTemp)*fpNew); + inputSampleL += fpNShapeLB; + fpTemp = inputSampleR; + fpNShapeRB = (fpNShapeRB*fpOld)+((inputSampleR-fpTemp)*fpNew); + inputSampleR += fpNShapeRB; + } + fpFlip = !fpFlip; + //end noise shaping on 64 bit output + + inputSampleL *= (1.0-LmaxRecent); + inputSampleR *= (1.0-RmaxRecent); + inputSampleL += (LpassThrough * LmaxRecent); + inputSampleR += (RpassThrough * RmaxRecent); + //there's our raw signal, without antialiasing. Brings up low level stuff and softens more when hot + + if (inputSampleL > cliplevel) inputSampleL = cliplevel; + if (inputSampleL < -cliplevel) inputSampleL = -cliplevel; + if (inputSampleR > cliplevel) inputSampleR = cliplevel; + if (inputSampleR < -cliplevel) inputSampleR = -cliplevel; + //final iron bar + + + *out1 = inputSampleL; + *out2 = inputSampleR; + + *in1++; + *in2++; + *out1++; + *out2++; + } +}
\ No newline at end of file |