diff options
author | Chris Johnson <jinx6568@sover.net> | 2018-09-02 22:35:13 -0400 |
---|---|---|
committer | Chris Johnson <jinx6568@sover.net> | 2018-09-02 22:35:13 -0400 |
commit | b4f55328448d087a68e6f658638fb3d38d86be12 (patch) | |
tree | 217a6d4c9ecc1c34e15e3f9e3774cc9858e39bfa /plugins/MacVST/BuildATPDF/source | |
parent | dea49efc0e05cdd55c00ce701aecef2bd742fc8c (diff) | |
download | airwindows-lv2-port-b4f55328448d087a68e6f658638fb3d38d86be12.tar.gz airwindows-lv2-port-b4f55328448d087a68e6f658638fb3d38d86be12.tar.bz2 airwindows-lv2-port-b4f55328448d087a68e6f658638fb3d38d86be12.zip |
Ditherbox… and individual dithers
Diffstat (limited to 'plugins/MacVST/BuildATPDF/source')
-rwxr-xr-x | plugins/MacVST/BuildATPDF/source/BuildATPDF.cpp | 190 | ||||
-rwxr-xr-x | plugins/MacVST/BuildATPDF/source/BuildATPDF.h | 83 | ||||
-rwxr-xr-x | plugins/MacVST/BuildATPDF/source/BuildATPDFProc.cpp | 242 |
3 files changed, 515 insertions, 0 deletions
diff --git a/plugins/MacVST/BuildATPDF/source/BuildATPDF.cpp b/plugins/MacVST/BuildATPDF/source/BuildATPDF.cpp new file mode 100755 index 0000000..e9f01a8 --- /dev/null +++ b/plugins/MacVST/BuildATPDF/source/BuildATPDF.cpp @@ -0,0 +1,190 @@ +/* ======================================== + * BuildATPDF - BuildATPDF.h + * Copyright (c) 2016 airwindows, All rights reserved + * ======================================== */ + +#ifndef __BuildATPDF_H +#include "BuildATPDF.h" +#endif + +AudioEffect* createEffectInstance(audioMasterCallback audioMaster) {return new BuildATPDF(audioMaster);} + +BuildATPDF::BuildATPDF(audioMasterCallback audioMaster) : + AudioEffectX(audioMaster, kNumPrograms, kNumParameters) +{ + A = 0.5; + B = 0.5; + C = 0.5; + D = 0.5; + E = 0.5; + F = 0.5; + G = 0.5; + H = 0.5; + I = 0.5; + J = 0.5; + //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 +} + +BuildATPDF::~BuildATPDF() {} +VstInt32 BuildATPDF::getVendorVersion () {return 1000;} +void BuildATPDF::setProgramName(char *name) {vst_strncpy (_programName, name, kVstMaxProgNameLen);} +void BuildATPDF::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 BuildATPDF::getChunk (void** data, bool isPreset) +{ + float *chunkData = (float *)calloc(kNumParameters, sizeof(float)); + chunkData[0] = A; + chunkData[1] = B; + chunkData[2] = C; + chunkData[3] = D; + chunkData[4] = E; + chunkData[5] = F; + chunkData[6] = G; + chunkData[7] = H; + chunkData[8] = I; + chunkData[9] = J; + /* 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 BuildATPDF::setChunk (void* data, VstInt32 byteSize, bool isPreset) +{ + float *chunkData = (float *)data; + A = pinParameter(chunkData[0]); + B = pinParameter(chunkData[1]); + C = pinParameter(chunkData[2]); + D = pinParameter(chunkData[3]); + E = pinParameter(chunkData[4]); + F = pinParameter(chunkData[5]); + G = pinParameter(chunkData[6]); + H = pinParameter(chunkData[7]); + I = pinParameter(chunkData[8]); + J = pinParameter(chunkData[9]); + /* 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 BuildATPDF::setParameter(VstInt32 index, float value) { + switch (index) { + case kParamA: A = value; break; + case kParamB: B = value; break; //percent. Using this value, it'll be 0-100 everywhere + case kParamC: C = value; break; + case kParamD: D = value; break; + case kParamE: E = value; break; + case kParamF: F = value; break; + case kParamG: G = value; break; + case kParamH: H = value; break; + case kParamI: I = value; break; + case kParamJ: J = value; break; + default: throw; // unknown parameter, shouldn't happen! + } +} + +float BuildATPDF::getParameter(VstInt32 index) { + switch (index) { + case kParamA: return A; break; + case kParamB: return B; break; + case kParamC: return C; break; + case kParamD: return D; break; + case kParamE: return E; break; + case kParamF: return F; break; + case kParamG: return G; break; + case kParamH: return H; break; + case kParamI: return I; break; + case kParamJ: return J; 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 BuildATPDF::getParameterName(VstInt32 index, char *text) { + switch (index) { + case kParamA: vst_strncpy (text, "First", kVstMaxParamStrLen); break; + case kParamB: vst_strncpy (text, "Second", kVstMaxParamStrLen); break; + case kParamC: vst_strncpy (text, "Third", kVstMaxParamStrLen); break; + case kParamD: vst_strncpy (text, "Fourth", kVstMaxParamStrLen); break; + case kParamE: vst_strncpy (text, "Fifth", kVstMaxParamStrLen); break; + case kParamF: vst_strncpy (text, "Sixth", kVstMaxParamStrLen); break; + case kParamG: vst_strncpy (text, "Seventh", kVstMaxParamStrLen); break; + case kParamH: vst_strncpy (text, "Eighth", kVstMaxParamStrLen); break; + case kParamI: vst_strncpy (text, "Ninth", kVstMaxParamStrLen); break; + case kParamJ: vst_strncpy (text, "Tenth", kVstMaxParamStrLen); break; + default: break; // unknown parameter, shouldn't happen! + } //this is our labels for displaying in the VST host +} + +void BuildATPDF::getParameterDisplay(VstInt32 index, char *text) { + switch (index) { + case kParamA: float2string ((A*2)-1, text, kVstMaxParamStrLen); break; + case kParamB: float2string ((B*2)-1, text, kVstMaxParamStrLen); break; + case kParamC: float2string ((C*2)-1, text, kVstMaxParamStrLen); break; + case kParamD: float2string ((D*2)-1, text, kVstMaxParamStrLen); break; + case kParamE: float2string ((E*2)-1, text, kVstMaxParamStrLen); break; + case kParamF: float2string ((F*2)-1, text, kVstMaxParamStrLen); break; + case kParamG: float2string ((G*2)-1, text, kVstMaxParamStrLen); break; + case kParamH: float2string ((H*2)-1, text, kVstMaxParamStrLen); break; + case kParamI: float2string ((I*2)-1, text, kVstMaxParamStrLen); break; + case kParamJ: float2string ((J*2)-1, text, kVstMaxParamStrLen); break; + + default: break; // unknown parameter, shouldn't happen! + } //this displays the values and handles 'popups' where it's discrete choices +} + +void BuildATPDF::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; + case kParamD: vst_strncpy (text, " ", kVstMaxParamStrLen); break; + case kParamE: vst_strncpy (text, " ", kVstMaxParamStrLen); break; + case kParamF: vst_strncpy (text, " ", kVstMaxParamStrLen); break; + case kParamG: vst_strncpy (text, " ", kVstMaxParamStrLen); break; + case kParamH: vst_strncpy (text, " ", kVstMaxParamStrLen); break; + case kParamI: vst_strncpy (text, " ", kVstMaxParamStrLen); break; + case kParamJ: vst_strncpy (text, " ", kVstMaxParamStrLen); break; + default: break; // unknown parameter, shouldn't happen! + } +} + +VstInt32 BuildATPDF::canDo(char *text) +{ return (_canDo.find(text) == _canDo.end()) ? -1: 1; } // 1 = yes, -1 = no, 0 = don't know + +bool BuildATPDF::getEffectName(char* name) { + vst_strncpy(name, "BuildATPDF", kVstMaxProductStrLen); return true; +} + +VstPlugCategory BuildATPDF::getPlugCategory() {return kPlugCategEffect;} + +bool BuildATPDF::getProductString(char* text) { + vst_strncpy (text, "airwindows BuildATPDF", kVstMaxProductStrLen); return true; +} + +bool BuildATPDF::getVendorString(char* text) { + vst_strncpy (text, "airwindows", kVstMaxVendorStrLen); return true; +} diff --git a/plugins/MacVST/BuildATPDF/source/BuildATPDF.h b/plugins/MacVST/BuildATPDF/source/BuildATPDF.h new file mode 100755 index 0000000..4de6dc8 --- /dev/null +++ b/plugins/MacVST/BuildATPDF/source/BuildATPDF.h @@ -0,0 +1,83 @@ +/* ======================================== + * BuildATPDF - BuildATPDF.h + * Created 8/12/11 by SPIAdmin + * Copyright (c) 2011 __MyCompanyName__, All rights reserved + * ======================================== */ + +#ifndef __BuildATPDF_H +#define __BuildATPDF_H + +#ifndef __audioeffect__ +#include "audioeffectx.h" +#endif + +#include <set> +#include <string> +#include <math.h> + +enum { + kParamA = 0, + kParamB = 1, + kParamC = 2, + kParamD = 3, + kParamE = 4, + kParamF = 5, + kParamG = 6, + kParamH = 7, + kParamI = 8, + kParamJ = 9, + kNumParameters = 10 +}; // + +const int kNumPrograms = 0; +const int kNumInputs = 2; +const int kNumOutputs = 2; +const unsigned long kUniqueId = 'bltp'; //Change this to what the AU identity is! + +class BuildATPDF : + public AudioEffectX +{ +public: + BuildATPDF(audioMasterCallback audioMaster); + ~BuildATPDF(); + 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 bL[11]; + double bR[11]; + double f[11]; + //default stuff + + float A; + float B; + float C; + float D; + float E; + float F; + float G; + float H; + float I; + float J; + //parameters. Always 0-1, and we scale/alter them elsewhere. + +}; + +#endif diff --git a/plugins/MacVST/BuildATPDF/source/BuildATPDFProc.cpp b/plugins/MacVST/BuildATPDF/source/BuildATPDFProc.cpp new file mode 100755 index 0000000..dfea125 --- /dev/null +++ b/plugins/MacVST/BuildATPDF/source/BuildATPDFProc.cpp @@ -0,0 +1,242 @@ +/* ======================================== + * BuildATPDF - BuildATPDF.h + * Copyright (c) 2016 airwindows, All rights reserved + * ======================================== */ + +#ifndef __BuildATPDF_H +#include "BuildATPDF.h" +#endif + +void BuildATPDF::processReplacing(float **inputs, float **outputs, VstInt32 sampleFrames) +{ + float* in1 = inputs[0]; + float* in2 = inputs[1]; + float* out1 = outputs[0]; + float* out2 = outputs[1]; + + f[0] = (A*2)-1; + f[1] = (B*2)-1; + f[2] = (C*2)-1; + f[3] = (D*2)-1; + f[4] = (E*2)-1; + f[5] = (F*2)-1; + f[6] = (G*2)-1; + f[7] = (H*2)-1; + f[8] = (I*2)-1; + f[9] = (J*2)-1; + double currentDither; + 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. + } + + inputSampleL *= 8388608.0; + inputSampleR *= 8388608.0; + //0-1 is now one bit, now we dither + + bL[9] = bL[8]; bL[8] = bL[7]; bL[7] = bL[6]; bL[6] = bL[5]; + bL[5] = bL[4]; bL[4] = bL[3]; bL[3] = bL[2]; bL[2] = bL[1]; + bL[1] = bL[0]; bL[0] = (rand()/(double)RAND_MAX); + + currentDither = (bL[0] * f[0]); + currentDither += (bL[1] * f[1]); + currentDither += (bL[2] * f[2]); + currentDither += (bL[3] * f[3]); + currentDither += (bL[4] * f[4]); + currentDither += (bL[5] * f[5]); + currentDither += (bL[6] * f[6]); + currentDither += (bL[7] * f[7]); + currentDither += (bL[8] * f[8]); + currentDither += (bL[9] * f[9]); + inputSampleL += currentDither; + + + bR[9] = bR[8]; bR[8] = bR[7]; bR[7] = bR[6]; bR[6] = bR[5]; + bR[5] = bR[4]; bR[4] = bR[3]; bR[3] = bR[2]; bR[2] = bR[1]; + bR[1] = bR[0]; bR[0] = (rand()/(double)RAND_MAX); + + currentDither = (bR[0] * f[0]); + currentDither += (bR[1] * f[1]); + currentDither += (bR[2] * f[2]); + currentDither += (bR[3] * f[3]); + currentDither += (bR[4] * f[4]); + currentDither += (bR[5] * f[5]); + currentDither += (bR[6] * f[6]); + currentDither += (bR[7] * f[7]); + currentDither += (bR[8] * f[8]); + currentDither += (bR[9] * f[9]); + inputSampleR += currentDither; + + inputSampleL = floor(inputSampleL); + inputSampleR = floor(inputSampleR); + + inputSampleL /= 8388608.0; + inputSampleR /= 8388608.0; + + *out1 = inputSampleL; + *out2 = inputSampleR; + + *in1++; + *in2++; + *out1++; + *out2++; + } +} + +void BuildATPDF::processDoubleReplacing(double **inputs, double **outputs, VstInt32 sampleFrames) +{ + double* in1 = inputs[0]; + double* in2 = inputs[1]; + double* out1 = outputs[0]; + double* out2 = outputs[1]; + + f[0] = (A*2)-1; + f[1] = (B*2)-1; + f[2] = (C*2)-1; + f[3] = (D*2)-1; + f[4] = (E*2)-1; + f[5] = (F*2)-1; + f[6] = (G*2)-1; + f[7] = (H*2)-1; + f[8] = (I*2)-1; + f[9] = (J*2)-1; + double currentDither; + 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. + } + + inputSampleL *= 8388608.0; + inputSampleR *= 8388608.0; + //0-1 is now one bit, now we dither + + bL[9] = bL[8]; bL[8] = bL[7]; bL[7] = bL[6]; bL[6] = bL[5]; + bL[5] = bL[4]; bL[4] = bL[3]; bL[3] = bL[2]; bL[2] = bL[1]; + bL[1] = bL[0]; bL[0] = (rand()/(double)RAND_MAX); + + currentDither = (bL[0] * f[0]); + currentDither += (bL[1] * f[1]); + currentDither += (bL[2] * f[2]); + currentDither += (bL[3] * f[3]); + currentDither += (bL[4] * f[4]); + currentDither += (bL[5] * f[5]); + currentDither += (bL[6] * f[6]); + currentDither += (bL[7] * f[7]); + currentDither += (bL[8] * f[8]); + currentDither += (bL[9] * f[9]); + inputSampleL += currentDither; + + + bR[9] = bR[8]; bR[8] = bR[7]; bR[7] = bR[6]; bR[6] = bR[5]; + bR[5] = bR[4]; bR[4] = bR[3]; bR[3] = bR[2]; bR[2] = bR[1]; + bR[1] = bR[0]; bR[0] = (rand()/(double)RAND_MAX); + + currentDither = (bR[0] * f[0]); + currentDither += (bR[1] * f[1]); + currentDither += (bR[2] * f[2]); + currentDither += (bR[3] * f[3]); + currentDither += (bR[4] * f[4]); + currentDither += (bR[5] * f[5]); + currentDither += (bR[6] * f[6]); + currentDither += (bR[7] * f[7]); + currentDither += (bR[8] * f[8]); + currentDither += (bR[9] * f[9]); + inputSampleR += currentDither; + + inputSampleL = floor(inputSampleL); + inputSampleR = floor(inputSampleR); + + inputSampleL /= 8388608.0; + inputSampleR /= 8388608.0; + + *out1 = inputSampleL; + *out2 = inputSampleR; + + *in1++; + *in2++; + *out1++; + *out2++; + } +}
\ No newline at end of file |