diff options
author | airwindows <jinx6568@sover.net> | 2018-02-25 18:40:25 -0500 |
---|---|---|
committer | airwindows <jinx6568@sover.net> | 2018-02-25 18:40:25 -0500 |
commit | bb21995711adcd0ebdc62697480c2f8981b61162 (patch) | |
tree | 828abf7ad643b9d2a4e78e04487ff156ac818a9c /plugins/LinuxVST/src | |
parent | 1fc3148c06290bb569384375549979ea74ad785d (diff) | |
download | airwindows-lv2-port-bb21995711adcd0ebdc62697480c2f8981b61162.tar.gz airwindows-lv2-port-bb21995711adcd0ebdc62697480c2f8981b61162.tar.bz2 airwindows-lv2-port-bb21995711adcd0ebdc62697480c2f8981b61162.zip |
ElectroHat
Diffstat (limited to 'plugins/LinuxVST/src')
-rwxr-xr-x | plugins/LinuxVST/src/ElectroHat/ElectroHat.cpp | 173 | ||||
-rwxr-xr-x | plugins/LinuxVST/src/ElectroHat/ElectroHat.h | 82 | ||||
-rwxr-xr-x | plugins/LinuxVST/src/ElectroHat/ElectroHatProc.cpp | 306 |
3 files changed, 561 insertions, 0 deletions
diff --git a/plugins/LinuxVST/src/ElectroHat/ElectroHat.cpp b/plugins/LinuxVST/src/ElectroHat/ElectroHat.cpp new file mode 100755 index 0000000..33d1058 --- /dev/null +++ b/plugins/LinuxVST/src/ElectroHat/ElectroHat.cpp @@ -0,0 +1,173 @@ +/* ======================================== + * ElectroHat - ElectroHat.h + * Copyright (c) 2016 airwindows, All rights reserved + * ======================================== */ + +#ifndef __ElectroHat_H +#include "ElectroHat.h" +#endif + +AudioEffect* createEffectInstance(audioMasterCallback audioMaster) {return new ElectroHat(audioMaster);} + +ElectroHat::ElectroHat(audioMasterCallback audioMaster) : + AudioEffectX(audioMaster, kNumPrograms, kNumParameters) +{ + A = 0.0; + B = 0.5; + C = 1.0; + D = 0.1; + E = 1.0; + storedSampleL = 0.0; + storedSampleR = 0.0; + lastSampleL = 0.0; + lastSampleR = 0.0; + tik = 3746926; + lok = 0; + flip = true; + + 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 +} + +ElectroHat::~ElectroHat() {} +VstInt32 ElectroHat::getVendorVersion () {return 1000;} +void ElectroHat::setProgramName(char *name) {vst_strncpy (_programName, name, kVstMaxProgNameLen);} +void ElectroHat::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 ElectroHat::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; + /* 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 ElectroHat::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]); + /* 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 ElectroHat::setParameter(VstInt32 index, float value) { + switch (index) { + case kParamA: A = value; break; + case kParamB: B = value; break; + case kParamC: C = value; break; + case kParamD: D = value; break; + case kParamE: E = value; break; + default: throw; // unknown parameter, shouldn't happen! + } +} + +float ElectroHat::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; + default: break; // unknown parameter, shouldn't happen! + } return 0.0; //we only need to update the relevant name, this is simple to manage +} + +void ElectroHat::getParameterName(VstInt32 index, char *text) { + switch (index) { + case kParamA: vst_strncpy (text, "HiHat", kVstMaxParamStrLen); break; + case kParamB: vst_strncpy (text, "Trim", kVstMaxParamStrLen); break; + case kParamC: vst_strncpy (text, "Bright", kVstMaxParamStrLen); break; + case kParamD: vst_strncpy (text, "Output", kVstMaxParamStrLen); break; + case kParamE: vst_strncpy (text, "Dry/Wet", kVstMaxParamStrLen); break; + default: break; // unknown parameter, shouldn't happen! + } //this is our labels for displaying in the VST host +} + +void ElectroHat::getParameterDisplay(VstInt32 index, char *text) { + switch (index) { + case kParamA: switch((VstInt32)( A * 5.999 )) //0 to almost edge of # of params + { + case 0: vst_strncpy (text, "Syn Hat", kVstMaxParamStrLen); break; + case 1: vst_strncpy (text, "Electro", kVstMaxParamStrLen); break; + case 2: vst_strncpy (text, "Dense", kVstMaxParamStrLen); break; + case 3: vst_strncpy (text, "606 St", kVstMaxParamStrLen); break; + case 4: vst_strncpy (text, "808 St", kVstMaxParamStrLen); break; + case 5: vst_strncpy (text, "909 St", kVstMaxParamStrLen); break; + default: break; // unknown parameter, shouldn't happen! + } break; + case kParamB: float2string (B, text, kVstMaxParamStrLen); break; + case kParamC: float2string (C, text, kVstMaxParamStrLen); break; + case kParamD: float2string (D, text, kVstMaxParamStrLen); break; + case kParamE: float2string (E, text, kVstMaxParamStrLen); break; + + + default: break; // unknown parameter, shouldn't happen! + } //this displays the values and handles 'popups' where it's discrete choices +} + +void ElectroHat::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; + default: break; // unknown parameter, shouldn't happen! + } +} + +VstInt32 ElectroHat::canDo(char *text) +{ return (_canDo.find(text) == _canDo.end()) ? -1: 1; } // 1 = yes, -1 = no, 0 = don't know + +bool ElectroHat::getEffectName(char* name) { + vst_strncpy(name, "ElectroHat", kVstMaxProductStrLen); return true; +} + +VstPlugCategory ElectroHat::getPlugCategory() {return kPlugCategEffect;} + +bool ElectroHat::getProductString(char* text) { + vst_strncpy (text, "airwindows ElectroHat", kVstMaxProductStrLen); return true; +} + +bool ElectroHat::getVendorString(char* text) { + vst_strncpy (text, "airwindows", kVstMaxVendorStrLen); return true; +} diff --git a/plugins/LinuxVST/src/ElectroHat/ElectroHat.h b/plugins/LinuxVST/src/ElectroHat/ElectroHat.h new file mode 100755 index 0000000..e8aa325 --- /dev/null +++ b/plugins/LinuxVST/src/ElectroHat/ElectroHat.h @@ -0,0 +1,82 @@ +/* ======================================== + * ElectroHat - ElectroHat.h + * Created 8/12/11 by SPIAdmin + * Copyright (c) 2011 __MyCompanyName__, All rights reserved + * ======================================== */ + +#ifndef __ElectroHat_H +#define __ElectroHat_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, + kNumParameters = 5 +}; // + +const int kNumPrograms = 0; +const int kNumInputs = 2; +const int kNumOutputs = 2; +const unsigned long kUniqueId = 'elec'; //Change this to what the AU identity is! + +class ElectroHat : + public AudioEffectX +{ +public: + ElectroHat(audioMasterCallback audioMaster); + ~ElectroHat(); + 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; + + long double fpNShapeLA; + long double fpNShapeLB; + long double fpNShapeRA; + long double fpNShapeRB; + bool fpFlip; + //default stuff + + double storedSampleL; + double storedSampleR; + double lastSampleL; + double lastSampleR; + int tik; + int lok; + bool flip; + + float A; + float B; + float C; + float D; + float E; //parameters. Always 0-1, and we scale/alter them elsewhere. + +}; + +#endif diff --git a/plugins/LinuxVST/src/ElectroHat/ElectroHatProc.cpp b/plugins/LinuxVST/src/ElectroHat/ElectroHatProc.cpp new file mode 100755 index 0000000..69b1a00 --- /dev/null +++ b/plugins/LinuxVST/src/ElectroHat/ElectroHatProc.cpp @@ -0,0 +1,306 @@ +/* ======================================== + * ElectroHat - ElectroHat.h + * Copyright (c) 2016 airwindows, All rights reserved + * ======================================== */ + +#ifndef __ElectroHat_H +#include "ElectroHat.h" +#endif + +void ElectroHat::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(); + bool highSample = false; + if (getSampleRate() > 64000) highSample = true; + //we will go to another dither for 88 and 96K + float fpTemp; + long double fpOld = 0.618033988749894848204586; //golden ratio! + long double fpNew = 1.0 - fpOld; + + double drySampleL; + double drySampleR; + double tempSampleL; + double tempSampleR; + long double inputSampleL; + long double inputSampleR; + + int deSyn = (VstInt32)( A * 5.999 )+1; + double increment = B; + double brighten = C; + double outputlevel = D; + double wet = E; + double dry = 1.0-wet; + + if (deSyn == 4) {deSyn = 1; increment = 0.411; brighten = 0.87;} + //606 preset + if (deSyn == 5) {deSyn = 2; increment = 0.111; brighten = 1.0;} + //808 preset + if (deSyn == 6) {deSyn = 2; increment = 0.299; brighten = 0.359;} + //909 preset + int tok = deSyn + 1; + increment *= 0.98; + increment += 0.01; + increment += (double)tok; + double fosA = increment; + double fosB = fosA * increment; + double fosC = fosB * increment; + double fosD = fosC * increment; + double fosE = fosD * increment; + double fosF = fosE * increment; + int posA = fosA; + int posB = fosB; + int posC = fosC; + int posD = fosD; + int posE = fosE; + int posF = fosF; + int posG = posF*posE*posD*posC*posB; //factorial + + while (--sampleFrames >= 0) + { + inputSampleL = *in1; + inputSampleR = *in2; + drySampleL = inputSampleL; + drySampleR = inputSampleR; + + inputSampleL = fabs(inputSampleL)*outputlevel; + inputSampleR = fabs(inputSampleR)*outputlevel; + + if (flip) { //will always be true unless we have high sample rate + tik++; + tik = tik % posG; + tok = tik * tik; tok = tok % posF; + tok *= tok; tok = tok % posE; + tok *= tok; tok = tok % posD; + tok *= tok; tok = tok % posC; + tok *= tok; tok = tok % posB; + tok *= tok; tok = tok % posA; + + inputSampleL = tok*inputSampleL; + if ((abs(lok-tok)<abs(lok+tok))&&(deSyn == 1)) {inputSampleL = -tok*inputSampleL;} + if ((abs(lok-tok)>abs(lok+tok))&&(deSyn == 2)) {inputSampleL = -tok*inputSampleL;} + if ((abs(lok-tok)<abs(lok+tok))&&(deSyn == 3)) {inputSampleL = -tok*inputSampleL;} + + inputSampleR = tok*inputSampleR; + if ((abs(lok-tok)<abs(lok+tok))&&(deSyn == 1)) {inputSampleR = -tok*inputSampleR;} + if ((abs(lok-tok)>abs(lok+tok))&&(deSyn == 2)) {inputSampleR = -tok*inputSampleR;} + if ((abs(lok-tok)<abs(lok+tok))&&(deSyn == 3)) {inputSampleR = -tok*inputSampleR;} + + lok = tok; + + tempSampleL = inputSampleL; + inputSampleL = inputSampleL - (lastSampleL*brighten); + lastSampleL = tempSampleL; + + tempSampleR = inputSampleR; + inputSampleR = inputSampleR - (lastSampleR*brighten); + lastSampleR = tempSampleR; + } else { //we have high sample rate and this is an interpolate sample + inputSampleL = lastSampleL; + inputSampleR = lastSampleR; + //not really interpolating, just sample-and-hold + } + + if (highSample) { + flip = !flip; + } else { + flip = true; + } + + tempSampleL = inputSampleL; + inputSampleL += storedSampleL; + storedSampleL = tempSampleL; + + tempSampleR = inputSampleR; + inputSampleR += storedSampleR; + storedSampleR = tempSampleR; + + if (wet !=1.0) { + inputSampleL = (inputSampleL * wet) + (drySampleL * dry); + inputSampleR = (inputSampleR * wet) + (drySampleR * dry); + } + + //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 + + *out1 = inputSampleL; + *out2 = inputSampleR; + + *in1++; + *in2++; + *out1++; + *out2++; + } +} + +void ElectroHat::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(); + bool highSample = false; + if (getSampleRate() > 64000) highSample = true; + //we will go to another dither for 88 and 96K + double fpTemp; + long double fpOld = 0.618033988749894848204586; //golden ratio! + long double fpNew = 1.0 - fpOld; + + double drySampleL; + double drySampleR; + double tempSampleL; + double tempSampleR; + long double inputSampleL; + long double inputSampleR; + + int deSyn = (VstInt32)( A * 5.999 )+1; + double increment = B; + double brighten = C; + double outputlevel = D; + double wet = E; + double dry = 1.0-wet; + + if (deSyn == 4) {deSyn = 1; increment = 0.411; brighten = 0.87;} + //606 preset + if (deSyn == 5) {deSyn = 2; increment = 0.111; brighten = 1.0;} + //808 preset + if (deSyn == 6) {deSyn = 2; increment = 0.299; brighten = 0.359;} + //909 preset + int tok = deSyn + 1; + increment *= 0.98; + increment += 0.01; + increment += (double)tok; + double fosA = increment; + double fosB = fosA * increment; + double fosC = fosB * increment; + double fosD = fosC * increment; + double fosE = fosD * increment; + double fosF = fosE * increment; + int posA = fosA; + int posB = fosB; + int posC = fosC; + int posD = fosD; + int posE = fosE; + int posF = fosF; + int posG = posF*posE*posD*posC*posB; //factorial + + while (--sampleFrames >= 0) + { + inputSampleL = *in1; + inputSampleR = *in2; + drySampleL = inputSampleL; + drySampleR = inputSampleR; + + inputSampleL = fabs(inputSampleL)*outputlevel; + inputSampleR = fabs(inputSampleR)*outputlevel; + + if (flip) { //will always be true unless we have high sample rate + tik++; + tik = tik % posG; + tok = tik * tik; tok = tok % posF; + tok *= tok; tok = tok % posE; + tok *= tok; tok = tok % posD; + tok *= tok; tok = tok % posC; + tok *= tok; tok = tok % posB; + tok *= tok; tok = tok % posA; + + inputSampleL = tok*inputSampleL; + if ((abs(lok-tok)<abs(lok+tok))&&(deSyn == 1)) {inputSampleL = -tok*inputSampleL;} + if ((abs(lok-tok)>abs(lok+tok))&&(deSyn == 2)) {inputSampleL = -tok*inputSampleL;} + if ((abs(lok-tok)<abs(lok+tok))&&(deSyn == 3)) {inputSampleL = -tok*inputSampleL;} + + inputSampleR = tok*inputSampleR; + if ((abs(lok-tok)<abs(lok+tok))&&(deSyn == 1)) {inputSampleR = -tok*inputSampleR;} + if ((abs(lok-tok)>abs(lok+tok))&&(deSyn == 2)) {inputSampleR = -tok*inputSampleR;} + if ((abs(lok-tok)<abs(lok+tok))&&(deSyn == 3)) {inputSampleR = -tok*inputSampleR;} + + lok = tok; + + tempSampleL = inputSampleL; + inputSampleL = inputSampleL - (lastSampleL*brighten); + lastSampleL = tempSampleL; + + tempSampleR = inputSampleR; + inputSampleR = inputSampleR - (lastSampleR*brighten); + lastSampleR = tempSampleR; + } else { //we have high sample rate and this is an interpolate sample + inputSampleL = lastSampleL; + inputSampleR = lastSampleR; + //not really interpolating, just sample-and-hold + } + + if (highSample) { + flip = !flip; + } else { + flip = true; + } + + tempSampleL = inputSampleL; + inputSampleL += storedSampleL; + storedSampleL = tempSampleL; + + tempSampleR = inputSampleR; + inputSampleR += storedSampleR; + storedSampleR = tempSampleR; + + if (wet !=1.0) { + inputSampleL = (inputSampleL * wet) + (drySampleL * dry); + inputSampleR = (inputSampleR * wet) + (drySampleR * dry); + } + + //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 + + *out1 = inputSampleL; + *out2 = inputSampleR; + + *in1++; + *in2++; + *out1++; + *out2++; + } +}
\ No newline at end of file |