aboutsummaryrefslogtreecommitdiffstats
path: root/plugins/MacVST/DoublePaul/source
diff options
context:
space:
mode:
authorChris Johnson <jinx6568@sover.net>2018-09-02 22:35:13 -0400
committerChris Johnson <jinx6568@sover.net>2018-09-02 22:35:13 -0400
commitb4f55328448d087a68e6f658638fb3d38d86be12 (patch)
tree217a6d4c9ecc1c34e15e3f9e3774cc9858e39bfa /plugins/MacVST/DoublePaul/source
parentdea49efc0e05cdd55c00ce701aecef2bd742fc8c (diff)
downloadairwindows-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/DoublePaul/source')
-rwxr-xr-xplugins/MacVST/DoublePaul/source/DoublePaul.cpp79
-rwxr-xr-xplugins/MacVST/DoublePaul/source/DoublePaul.h59
-rwxr-xr-xplugins/MacVST/DoublePaul/source/DoublePaulProc.cpp246
3 files changed, 384 insertions, 0 deletions
diff --git a/plugins/MacVST/DoublePaul/source/DoublePaul.cpp b/plugins/MacVST/DoublePaul/source/DoublePaul.cpp
new file mode 100755
index 0000000..a5d374d
--- /dev/null
+++ b/plugins/MacVST/DoublePaul/source/DoublePaul.cpp
@@ -0,0 +1,79 @@
+/* ========================================
+ * DoublePaul - DoublePaul.h
+ * Copyright (c) 2016 airwindows, All rights reserved
+ * ======================================== */
+
+#ifndef __DoublePaul_H
+#include "DoublePaul.h"
+#endif
+
+AudioEffect* createEffectInstance(audioMasterCallback audioMaster) {return new DoublePaul(audioMaster);}
+
+DoublePaul::DoublePaul(audioMasterCallback audioMaster) :
+ AudioEffectX(audioMaster, kNumPrograms, kNumParameters)
+{
+ for(int count = 0; count < 11; count++) {bL[count] = 0.0;bR[count] = 0.0;}
+ //this is reset: values being initialized only once. Startup values, whatever they are.
+
+ _canDo.insert("plugAsChannelInsert"); // plug-in can be used as a channel insert effect.
+ _canDo.insert("plugAsSend"); // plug-in can be used as a send effect.
+ _canDo.insert("x2in2out");
+ setNumInputs(kNumInputs);
+ setNumOutputs(kNumOutputs);
+ setUniqueID(kUniqueId);
+ canProcessReplacing(); // supports output replacing
+ canDoubleReplacing(); // supports double precision processing
+ programsAreChunks(true);
+ vst_strncpy (_programName, "Default", kVstMaxProgNameLen); // default program name
+}
+
+DoublePaul::~DoublePaul() {}
+VstInt32 DoublePaul::getVendorVersion () {return 1000;}
+void DoublePaul::setProgramName(char *name) {vst_strncpy (_programName, name, kVstMaxProgNameLen);}
+void DoublePaul::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 DoublePaul::getChunk (void** data, bool isPreset)
+{
+ return kNumParameters * sizeof(float);
+}
+
+VstInt32 DoublePaul::setChunk (void* data, VstInt32 byteSize, bool isPreset)
+{
+ return 0;
+}
+
+void DoublePaul::setParameter(VstInt32 index, float value) {
+}
+
+float DoublePaul::getParameter(VstInt32 index) {
+ return 0.0; //we only need to update the relevant name, this is simple to manage
+}
+
+void DoublePaul::getParameterName(VstInt32 index, char *text) {
+}
+
+void DoublePaul::getParameterDisplay(VstInt32 index, char *text) {
+}
+
+void DoublePaul::getParameterLabel(VstInt32 index, char *text) {
+}
+
+VstInt32 DoublePaul::canDo(char *text)
+{ return (_canDo.find(text) == _canDo.end()) ? -1: 1; } // 1 = yes, -1 = no, 0 = don't know
+
+bool DoublePaul::getEffectName(char* name) {
+ vst_strncpy(name, "DoublePaul", kVstMaxProductStrLen); return true;
+}
+
+VstPlugCategory DoublePaul::getPlugCategory() {return kPlugCategEffect;}
+
+bool DoublePaul::getProductString(char* text) {
+ vst_strncpy (text, "airwindows DoublePaul", kVstMaxProductStrLen); return true;
+}
+
+bool DoublePaul::getVendorString(char* text) {
+ vst_strncpy (text, "airwindows", kVstMaxVendorStrLen); return true;
+}
diff --git a/plugins/MacVST/DoublePaul/source/DoublePaul.h b/plugins/MacVST/DoublePaul/source/DoublePaul.h
new file mode 100755
index 0000000..4cb0b88
--- /dev/null
+++ b/plugins/MacVST/DoublePaul/source/DoublePaul.h
@@ -0,0 +1,59 @@
+/* ========================================
+ * DoublePaul - DoublePaul.h
+ * Created 8/12/11 by SPIAdmin
+ * Copyright (c) 2011 __MyCompanyName__, All rights reserved
+ * ======================================== */
+
+#ifndef __DoublePaul_H
+#define __DoublePaul_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 = 'dbpa'; //Change this to what the AU identity is!
+
+class DoublePaul :
+ public AudioEffectX
+{
+public:
+ DoublePaul(audioMasterCallback audioMaster);
+ ~DoublePaul();
+ 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];
+
+};
+
+#endif
diff --git a/plugins/MacVST/DoublePaul/source/DoublePaulProc.cpp b/plugins/MacVST/DoublePaul/source/DoublePaulProc.cpp
new file mode 100755
index 0000000..66de94f
--- /dev/null
+++ b/plugins/MacVST/DoublePaul/source/DoublePaulProc.cpp
@@ -0,0 +1,246 @@
+/* ========================================
+ * DoublePaul - DoublePaul.h
+ * Copyright (c) 2016 airwindows, All rights reserved
+ * ======================================== */
+
+#ifndef __DoublePaul_H
+#include "DoublePaul.h"
+#endif
+
+void DoublePaul::processReplacing(float **inputs, float **outputs, VstInt32 sampleFrames)
+{
+ float* in1 = inputs[0];
+ float* in2 = inputs[1];
+ float* out1 = outputs[0];
+ float* out2 = outputs[1];
+
+ double currentDitherL;
+ double currentDitherR;
+
+ 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.
+ }
+
+ 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);
+
+ currentDitherL = (bL[0] * 0.061);
+ currentDitherL -= (bL[1] * 0.11);
+ currentDitherL += (bL[8] * 0.126);
+ currentDitherL -= (bL[7] * 0.23);
+ currentDitherL += (bL[2] * 0.25);
+ currentDitherL -= (bL[3] * 0.43);
+ currentDitherL += (bL[6] * 0.5);
+ currentDitherL -= bL[5];
+ currentDitherL += bL[4];
+ //this sounds different from doing it in order of sample position
+ //cumulative tiny errors seem to build up even at this buss depth
+ //considerably more pronounced at 32 bit float.
+ //Therefore we add the most significant components LAST.
+ //trying to keep values on like exponents of the floating point value.
+ inputSampleL += currentDitherL;
+
+ inputSampleL = floor(inputSampleL);
+ //done with L
+
+ 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);
+
+ currentDitherR = (bR[0] * 0.061);
+ currentDitherR -= (bR[1] * 0.11);
+ currentDitherR += (bR[8] * 0.126);
+ currentDitherR -= (bR[7] * 0.23);
+ currentDitherR += (bR[2] * 0.25);
+ currentDitherR -= (bR[3] * 0.43);
+ currentDitherR += (bR[6] * 0.5);
+ currentDitherR -= bR[5];
+ currentDitherR += bR[4];
+ //this sounds different from doing it in order of sample position
+ //cumulative tiny errors seem to build up even at this buss depth
+ //considerably more pronounced at 32 bit float.
+ //Therefore we add the most significant components LAST.
+ //trying to keep values on like exponents of the floating point value.
+ inputSampleR += currentDitherR;
+
+ inputSampleR = floor(inputSampleR);
+ //done with R
+
+ inputSampleL /= 8388608.0;
+ inputSampleR /= 8388608.0;
+
+ *out1 = inputSampleL;
+ *out2 = inputSampleR;
+
+ *in1++;
+ *in2++;
+ *out1++;
+ *out2++;
+ }
+}
+
+void DoublePaul::processDoubleReplacing(double **inputs, double **outputs, VstInt32 sampleFrames)
+{
+ double* in1 = inputs[0];
+ double* in2 = inputs[1];
+ double* out1 = outputs[0];
+ double* out2 = outputs[1];
+
+ double currentDitherL;
+ double currentDitherR;
+
+ 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.
+ }
+
+ 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);
+
+ currentDitherL = (bL[0] * 0.061);
+ currentDitherL -= (bL[1] * 0.11);
+ currentDitherL += (bL[8] * 0.126);
+ currentDitherL -= (bL[7] * 0.23);
+ currentDitherL += (bL[2] * 0.25);
+ currentDitherL -= (bL[3] * 0.43);
+ currentDitherL += (bL[6] * 0.5);
+ currentDitherL -= bL[5];
+ currentDitherL += bL[4];
+ //this sounds different from doing it in order of sample position
+ //cumulative tiny errors seem to build up even at this buss depth
+ //considerably more pronounced at 32 bit float.
+ //Therefore we add the most significant components LAST.
+ //trying to keep values on like exponents of the floating point value.
+ inputSampleL += currentDitherL;
+
+ inputSampleL = floor(inputSampleL);
+ //done with L
+
+ 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);
+
+ currentDitherR = (bR[0] * 0.061);
+ currentDitherR -= (bR[1] * 0.11);
+ currentDitherR += (bR[8] * 0.126);
+ currentDitherR -= (bR[7] * 0.23);
+ currentDitherR += (bR[2] * 0.25);
+ currentDitherR -= (bR[3] * 0.43);
+ currentDitherR += (bR[6] * 0.5);
+ currentDitherR -= bR[5];
+ currentDitherR += bR[4];
+ //this sounds different from doing it in order of sample position
+ //cumulative tiny errors seem to build up even at this buss depth
+ //considerably more pronounced at 32 bit float.
+ //Therefore we add the most significant components LAST.
+ //trying to keep values on like exponents of the floating point value.
+ inputSampleR += currentDitherR;
+
+ inputSampleR = floor(inputSampleR);
+ //done with R
+
+ inputSampleL /= 8388608.0;
+ inputSampleR /= 8388608.0;
+
+ *out1 = inputSampleL;
+ *out2 = inputSampleR;
+
+ *in1++;
+ *in2++;
+ *out1++;
+ *out2++;
+ }
+} \ No newline at end of file