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/ClipOnly/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/ClipOnly/source')
-rwxr-xr-x | plugins/MacVST/ClipOnly/source/ClipOnly.cpp | 59 | ||||
-rwxr-xr-x | plugins/MacVST/ClipOnly/source/ClipOnly.h | 57 | ||||
-rwxr-xr-x | plugins/MacVST/ClipOnly/source/ClipOnlyProc.cpp | 268 |
3 files changed, 384 insertions, 0 deletions
diff --git a/plugins/MacVST/ClipOnly/source/ClipOnly.cpp b/plugins/MacVST/ClipOnly/source/ClipOnly.cpp new file mode 100755 index 0000000..7913ce4 --- /dev/null +++ b/plugins/MacVST/ClipOnly/source/ClipOnly.cpp @@ -0,0 +1,59 @@ +/* ======================================== + * ClipOnly - ClipOnly.h + * Copyright (c) 2016 airwindows, All rights reserved + * ======================================== */ + +#ifndef __ClipOnly_H +#include "ClipOnly.h" +#endif + +AudioEffect* createEffectInstance(audioMasterCallback audioMaster) {return new ClipOnly(audioMaster);} + +ClipOnly::ClipOnly(audioMasterCallback audioMaster) : + AudioEffectX(audioMaster, kNumPrograms, kNumParameters) +{ + lastSampleL = 0.0; + wasPosClipL = false; + wasNegClipL = false; + + lastSampleR = 0.0; + wasPosClipR = false; + wasNegClipR = false; + //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 +} + +ClipOnly::~ClipOnly() {} +VstInt32 ClipOnly::getVendorVersion () {return 1000;} +void ClipOnly::setProgramName(char *name) {vst_strncpy (_programName, name, kVstMaxProgNameLen);} +void ClipOnly::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! + + +VstInt32 ClipOnly::canDo(char *text) +{ return (_canDo.find(text) == _canDo.end()) ? -1: 1; } // 1 = yes, -1 = no, 0 = don't know + +bool ClipOnly::getEffectName(char* name) { + vst_strncpy(name, "ClipOnly", kVstMaxProductStrLen); return true; +} + +VstPlugCategory ClipOnly::getPlugCategory() {return kPlugCategEffect;} + +bool ClipOnly::getProductString(char* text) { + vst_strncpy (text, "airwindows ClipOnly", kVstMaxProductStrLen); return true; +} + +bool ClipOnly::getVendorString(char* text) { + vst_strncpy (text, "airwindows", kVstMaxVendorStrLen); return true; +} diff --git a/plugins/MacVST/ClipOnly/source/ClipOnly.h b/plugins/MacVST/ClipOnly/source/ClipOnly.h new file mode 100755 index 0000000..c3a7fdd --- /dev/null +++ b/plugins/MacVST/ClipOnly/source/ClipOnly.h @@ -0,0 +1,57 @@ +/* ======================================== + * ClipOnly - ClipOnly.h + * Created 8/12/11 by SPIAdmin + * Copyright (c) 2011 __MyCompanyName__, All rights reserved + * ======================================== */ + +#ifndef __ClipOnly_H +#define __ClipOnly_H + +#ifndef __audioeffect__ +#include "audioeffectx.h" +#endif + +#include <set> +#include <string> +#include <math.h> + +enum { + kNumParameters = 0 +}; + +const int kNumPrograms = 0; +const int kNumInputs = 2; +const int kNumOutputs = 2; +const unsigned long kUniqueId = 'cloy'; //Change this to what the AU identity is! + +class ClipOnly : + public AudioEffectX +{ +public: + ClipOnly(audioMasterCallback audioMaster); + ~ClipOnly(); + 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 canDo(char *text); +private: + char _programName[kVstMaxProgNameLen + 1]; + std::set< std::string > _canDo; + + float lastSampleL; + bool wasPosClipL; + bool wasNegClipL; + + float lastSampleR; + bool wasPosClipR; + bool wasNegClipR; + +}; + +#endif diff --git a/plugins/MacVST/ClipOnly/source/ClipOnlyProc.cpp b/plugins/MacVST/ClipOnly/source/ClipOnlyProc.cpp new file mode 100755 index 0000000..a060ea1 --- /dev/null +++ b/plugins/MacVST/ClipOnly/source/ClipOnlyProc.cpp @@ -0,0 +1,268 @@ +/* ======================================== + * ClipOnly - ClipOnly.h + * Copyright (c) 2016 airwindows, All rights reserved + * ======================================== */ + +#ifndef __ClipOnly_H +#include "ClipOnly.h" +#endif + +void ClipOnly::processReplacing(float **inputs, float **outputs, VstInt32 sampleFrames) +{ + float* in1 = inputs[0]; + float* in2 = inputs[1]; + float* out1 = outputs[0]; + float* out2 = outputs[1]; + + double hardness = 0.7390851332151606; // x == cos(x) + double softness = 1.0 - hardness; + double refclip = 0.9549925859; // -0.2dB + + float inputSampleL; + float 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. + } + + if (inputSampleL > 4.0) inputSampleL = 4.0; + if (inputSampleL < -4.0) inputSampleL = -4.0; + if (inputSampleR > 4.0) inputSampleR = 4.0; + if (inputSampleR < -4.0) inputSampleR = -4.0; + + if (wasPosClipL == true) { //current will be over + if (inputSampleL < lastSampleL) { //next one will NOT be over + lastSampleL = ((refclip*hardness) + (inputSampleL * softness)); + } + else { //still clipping, still chasing the target + lastSampleL = ((lastSampleL*hardness) + (refclip * softness)); + } + } + wasPosClipL = false; + if (inputSampleL > refclip) { //next will be over the true clip level. otherwise we directly use it + wasPosClipL = true; //set the clip flag + inputSampleL = ((refclip*hardness) + (lastSampleL * softness)); + } + + if (wasNegClipL == true) { //current will be -over + if (inputSampleL > lastSampleL) { //next one will NOT be -over + lastSampleL = ((-refclip*hardness) + (inputSampleL * softness)); + } + else { //still clipping, still chasing the target + lastSampleL = ((lastSampleL*hardness) + (-refclip * softness)); + } + } + wasNegClipL = false; + if (inputSampleL < -refclip) { //next will be -refclip. otherwise we directly use it + wasNegClipL = true; //set the clip flag + inputSampleL = ((-refclip*hardness) + (lastSampleL * softness)); + } + + if (wasPosClipR == true) { //current will be over + if (inputSampleR < lastSampleR) { //next one will NOT be over + lastSampleR = ((refclip*hardness) + (inputSampleR * softness)); + } + else { //still clipping, still chasing the target + lastSampleR = ((lastSampleR*hardness) + (refclip * softness)); + } + } + wasPosClipR = false; + if (inputSampleR > refclip) { //next will be over the true clip level. otherwise we directly use it + wasPosClipR = true; //set the clip flag + inputSampleR = ((refclip*hardness) + (lastSampleR * softness)); + } + + if (wasNegClipR == true) { //current will be -over + if (inputSampleR > lastSampleR) { //next one will NOT be -over + lastSampleR = ((-refclip*hardness) + (inputSampleR * softness)); + } + else { //still clipping, still chasing the target + lastSampleR = ((lastSampleR*hardness) + (-refclip * softness)); + } + } + wasNegClipR = false; + if (inputSampleR < -refclip) { //next will be -refclip. otherwise we directly use it + wasNegClipR = true; //set the clip flag + inputSampleR = ((-refclip*hardness) + (lastSampleR * softness)); + } + + *out1 = lastSampleL; + *out2 = lastSampleR; + lastSampleL = inputSampleL; + lastSampleR = inputSampleR; + + *in1++; + *in2++; + *out1++; + *out2++; + } +} + +void ClipOnly::processDoubleReplacing(double **inputs, double **outputs, VstInt32 sampleFrames) +{ + double* in1 = inputs[0]; + double* in2 = inputs[1]; + double* out1 = outputs[0]; + double* out2 = outputs[1]; + + double hardness = 0.7390851332151606; // x == cos(x) + double softness = 1.0 - hardness; + double refclip = 0.9549925859; // -0.2dB + + double inputSampleL; + 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. + } + + if (inputSampleL > 4.0) inputSampleL = 4.0; + if (inputSampleL < -4.0) inputSampleL = -4.0; + if (inputSampleR > 4.0) inputSampleR = 4.0; + if (inputSampleR < -4.0) inputSampleR = -4.0; + + if (wasPosClipL == true) { //current will be over + if (inputSampleL < lastSampleL) { //next one will NOT be over + lastSampleL = ((refclip*hardness) + (inputSampleL * softness)); + } + else { //still clipping, still chasing the target + lastSampleL = ((lastSampleL*hardness) + (refclip * softness)); + } + } + wasPosClipL = false; + if (inputSampleL > refclip) { //next will be over the true clip level. otherwise we directly use it + wasPosClipL = true; //set the clip flag + inputSampleL = ((refclip*hardness) + (lastSampleL * softness)); + } + + if (wasNegClipL == true) { //current will be -over + if (inputSampleL > lastSampleL) { //next one will NOT be -over + lastSampleL = ((-refclip*hardness) + (inputSampleL * softness)); + } + else { //still clipping, still chasing the target + lastSampleL = ((lastSampleL*hardness) + (-refclip * softness)); + } + } + wasNegClipL = false; + if (inputSampleL < -refclip) { //next will be -refclip. otherwise we directly use it + wasNegClipL = true; //set the clip flag + inputSampleL = ((-refclip*hardness) + (lastSampleL * softness)); + } + + if (wasPosClipR == true) { //current will be over + if (inputSampleR < lastSampleR) { //next one will NOT be over + lastSampleR = ((refclip*hardness) + (inputSampleR * softness)); + } + else { //still clipping, still chasing the target + lastSampleR = ((lastSampleR*hardness) + (refclip * softness)); + } + } + wasPosClipR = false; + if (inputSampleR > refclip) { //next will be over the true clip level. otherwise we directly use it + wasPosClipR = true; //set the clip flag + inputSampleR = ((refclip*hardness) + (lastSampleR * softness)); + } + + if (wasNegClipR == true) { //current will be -over + if (inputSampleR > lastSampleR) { //next one will NOT be -over + lastSampleR = ((-refclip*hardness) + (inputSampleR * softness)); + } + else { //still clipping, still chasing the target + lastSampleR = ((lastSampleR*hardness) + (-refclip * softness)); + } + } + wasNegClipR = false; + if (inputSampleR < -refclip) { //next will be -refclip. otherwise we directly use it + wasNegClipR = true; //set the clip flag + inputSampleR = ((-refclip*hardness) + (lastSampleR * softness)); + } + + *out1 = lastSampleL; + *out2 = lastSampleR; + lastSampleL = inputSampleL; + lastSampleR = inputSampleR; + + *in1++; + *in2++; + *out1++; + *out2++; + } +}
\ No newline at end of file |