diff options
author | airwindows <jinx6568@sover.net> | 2018-02-18 21:33:36 -0500 |
---|---|---|
committer | airwindows <jinx6568@sover.net> | 2018-02-18 21:33:36 -0500 |
commit | 1fc3148c06290bb569384375549979ea74ad785d (patch) | |
tree | f2f51046dd9f5870b82f4a6c3b1ae92df4d26b0e /plugins/MacVST/VoiceOfTheStarship/source | |
parent | 23a80ee10cb65213fd06ce3dd053395f1ec639c3 (diff) | |
download | airwindows-lv2-port-1fc3148c06290bb569384375549979ea74ad785d.tar.gz airwindows-lv2-port-1fc3148c06290bb569384375549979ea74ad785d.tar.bz2 airwindows-lv2-port-1fc3148c06290bb569384375549979ea74ad785d.zip |
VoiceOfTheStarship
Diffstat (limited to 'plugins/MacVST/VoiceOfTheStarship/source')
3 files changed, 646 insertions, 0 deletions
diff --git a/plugins/MacVST/VoiceOfTheStarship/source/VoiceOfTheStarship.cpp b/plugins/MacVST/VoiceOfTheStarship/source/VoiceOfTheStarship.cpp new file mode 100755 index 0000000..c30bd47 --- /dev/null +++ b/plugins/MacVST/VoiceOfTheStarship/source/VoiceOfTheStarship.cpp @@ -0,0 +1,144 @@ +/* ======================================== + * VoiceOfTheStarship - VoiceOfTheStarship.h + * Copyright (c) 2016 airwindows, All rights reserved + * ======================================== */ + +#ifndef __VoiceOfTheStarship_H +#include "VoiceOfTheStarship.h" +#endif + +AudioEffect* createEffectInstance(audioMasterCallback audioMaster) {return new VoiceOfTheStarship(audioMaster);} + +VoiceOfTheStarship::VoiceOfTheStarship(audioMasterCallback audioMaster) : + AudioEffectX(audioMaster, kNumPrograms, kNumParameters) +{ + A = 0.5; + B = 0.0; + position = 99999999; + quadratic = 0; + noiseAL = 0.0; + noiseBL = 0.0; + noiseCL = 0.0; + flipL = false; + noiseAR = 0.0; + noiseBR = 0.0; + noiseCR = 0.0; + flipR = false; + filterflip = false; + for(int count = 0; count < 11; count++) {bL[count] = 0.0; bR[count] = 0.0; f[count] = 0.0;} + lastAlgorithm = 0; + + 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 +} + +VoiceOfTheStarship::~VoiceOfTheStarship() {} +VstInt32 VoiceOfTheStarship::getVendorVersion () {return 1000;} +void VoiceOfTheStarship::setProgramName(char *name) {vst_strncpy (_programName, name, kVstMaxProgNameLen);} +void VoiceOfTheStarship::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 VoiceOfTheStarship::getChunk (void** data, bool isPreset) +{ + float *chunkData = (float *)calloc(kNumParameters, sizeof(float)); + chunkData[0] = A; + chunkData[1] = B; + /* 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 VoiceOfTheStarship::setChunk (void* data, VstInt32 byteSize, bool isPreset) +{ + float *chunkData = (float *)data; + A = pinParameter(chunkData[0]); + B = pinParameter(chunkData[1]); + /* 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 VoiceOfTheStarship::setParameter(VstInt32 index, float value) { + switch (index) { + case kParamA: A = value; break; + case kParamB: B = value; break; + default: throw; // unknown parameter, shouldn't happen! + } +} + +float VoiceOfTheStarship::getParameter(VstInt32 index) { + switch (index) { + case kParamA: return A; break; + case kParamB: return B; 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 VoiceOfTheStarship::getParameterName(VstInt32 index, char *text) { + switch (index) { + case kParamA: vst_strncpy (text, "Filter", kVstMaxParamStrLen); break; + case kParamB: vst_strncpy (text, "Algrthm", kVstMaxParamStrLen); break; + default: break; // unknown parameter, shouldn't happen! + } //this is our labels for displaying in the VST host +} + +void VoiceOfTheStarship::getParameterDisplay(VstInt32 index, char *text) { + switch (index) { + case kParamA: float2string (A, text, kVstMaxParamStrLen); break; + case kParamB: float2string (floor(B*16.9), text, kVstMaxParamStrLen); break; + default: break; // unknown parameter, shouldn't happen! + } //this displays the values and handles 'popups' where it's discrete choices +} + +void VoiceOfTheStarship::getParameterLabel(VstInt32 index, char *text) { + switch (index) { + case kParamA: vst_strncpy (text, "", kVstMaxParamStrLen); break; + case kParamB: vst_strncpy (text, "", kVstMaxParamStrLen); break; + default: break; // unknown parameter, shouldn't happen! + } +} + +VstInt32 VoiceOfTheStarship::canDo(char *text) +{ return (_canDo.find(text) == _canDo.end()) ? -1: 1; } // 1 = yes, -1 = no, 0 = don't know + +bool VoiceOfTheStarship::getEffectName(char* name) { + vst_strncpy(name, "VoiceOfTheStarship", kVstMaxProductStrLen); return true; +} + +VstPlugCategory VoiceOfTheStarship::getPlugCategory() {return kPlugCategEffect;} + +bool VoiceOfTheStarship::getProductString(char* text) { + vst_strncpy (text, "airwindows VoiceOfTheStarship", kVstMaxProductStrLen); return true; +} + +bool VoiceOfTheStarship::getVendorString(char* text) { + vst_strncpy (text, "airwindows", kVstMaxVendorStrLen); return true; +} diff --git a/plugins/MacVST/VoiceOfTheStarship/source/VoiceOfTheStarship.h b/plugins/MacVST/VoiceOfTheStarship/source/VoiceOfTheStarship.h new file mode 100755 index 0000000..febb344 --- /dev/null +++ b/plugins/MacVST/VoiceOfTheStarship/source/VoiceOfTheStarship.h @@ -0,0 +1,87 @@ +/* ======================================== + * VoiceOfTheStarship - VoiceOfTheStarship.h + * Created 8/12/11 by SPIAdmin + * Copyright (c) 2011 __MyCompanyName__, All rights reserved + * ======================================== */ + +#ifndef __VoiceOfTheStarship_H +#define __VoiceOfTheStarship_H + +#ifndef __audioeffect__ +#include "audioeffectx.h" +#endif + +#include <set> +#include <string> +#include <math.h> + +enum { + kParamA = 0, + kParamB = 1, + kNumParameters = 2 +}; // + +const int kNumPrograms = 0; +const int kNumInputs = 2; +const int kNumOutputs = 2; +const unsigned long kUniqueId = 'vots'; //Change this to what the AU identity is! + +class VoiceOfTheStarship : + public AudioEffectX +{ +public: + VoiceOfTheStarship(audioMasterCallback audioMaster); + ~VoiceOfTheStarship(); + 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 noiseAL; + double noiseBL; + double noiseCL; + double noiseAR; + double noiseBR; + double noiseCR; + + int position; + int quadratic; + bool flipL; + bool flipR; + bool filterflip; + + double bL[11]; + double bR[11]; + + double f[11]; + + int lastAlgorithm; + + long double fpNShapeLA; + long double fpNShapeLB; + long double fpNShapeRA; + long double fpNShapeRB; + bool fpFlip; + //default stuff + + float A; + float B; +}; + +#endif diff --git a/plugins/MacVST/VoiceOfTheStarship/source/VoiceOfTheStarshipProc.cpp b/plugins/MacVST/VoiceOfTheStarship/source/VoiceOfTheStarshipProc.cpp new file mode 100755 index 0000000..32979d0 --- /dev/null +++ b/plugins/MacVST/VoiceOfTheStarship/source/VoiceOfTheStarshipProc.cpp @@ -0,0 +1,415 @@ +/* ======================================== + * VoiceOfTheStarship - VoiceOfTheStarship.h + * Copyright (c) 2016 airwindows, All rights reserved + * ======================================== */ + +#ifndef __VoiceOfTheStarship_H +#include "VoiceOfTheStarship.h" +#endif + +void VoiceOfTheStarship::processReplacing(float **inputs, float **outputs, VstInt32 sampleFrames) +{ + float* in1 = inputs[0]; + float* in2 = inputs[1]; + float* out1 = outputs[0]; + float* out2 = outputs[1]; + double cutoff = pow((A*0.89)+0.1,3); + if (cutoff > 1.0) cutoff = 1.0; + double invcutoff = 1.0 - cutoff; + //this is the lowpass + + double overallscale = ((1.0-A)*9.0)+1.0; + double gain = overallscale; + if (gain > 1.0) {f[0] = 1.0; gain -= 1.0;} else {f[0] = gain; gain = 0.0;} + if (gain > 1.0) {f[1] = 1.0; gain -= 1.0;} else {f[1] = gain; gain = 0.0;} + if (gain > 1.0) {f[2] = 1.0; gain -= 1.0;} else {f[2] = gain; gain = 0.0;} + if (gain > 1.0) {f[3] = 1.0; gain -= 1.0;} else {f[3] = gain; gain = 0.0;} + if (gain > 1.0) {f[4] = 1.0; gain -= 1.0;} else {f[4] = gain; gain = 0.0;} + if (gain > 1.0) {f[5] = 1.0; gain -= 1.0;} else {f[5] = gain; gain = 0.0;} + if (gain > 1.0) {f[6] = 1.0; gain -= 1.0;} else {f[6] = gain; gain = 0.0;} + if (gain > 1.0) {f[7] = 1.0; gain -= 1.0;} else {f[7] = gain; gain = 0.0;} + if (gain > 1.0) {f[8] = 1.0; gain -= 1.0;} else {f[8] = gain; gain = 0.0;} + if (gain > 1.0) {f[9] = 1.0; gain -= 1.0;} else {f[9] = gain; gain = 0.0;} + //this is the moving average with remainders + if (overallscale < 1.0) overallscale = 1.0; + f[0] /= overallscale; + f[1] /= overallscale; + f[2] /= overallscale; + f[3] /= overallscale; + f[4] /= overallscale; + f[5] /= overallscale; + f[6] /= overallscale; + f[7] /= overallscale; + f[8] /= overallscale; + f[9] /= overallscale; + //and now it's neatly scaled, too + + int lowcut = floor(B*16.9); + if (lastAlgorithm != lowcut) { + noiseAL = 0.0; noiseBL = 0.0; noiseCL = 0.0; + noiseAR = 0.0; noiseBR = 0.0; noiseCR = 0.0; + for(int count = 0; count < 11; count++) {bL[count] = 0.0; bR[count] = 0.0;} + lastAlgorithm = lowcut; + } + //cuts the noise back to 0 if we are changing algorithms, + //because that also changes gains and can make loud pops. + //We still get pops, but they'd be even worse + int dcut; + if (lowcut > 15) {lowcut = 1151; dcut= 11517;} + if (lowcut == 15) {lowcut = 113; dcut= 1151;} + if (lowcut == 14) {lowcut = 71; dcut= 719;} + if (lowcut == 13) {lowcut = 53; dcut= 541;} + if (lowcut == 12) {lowcut = 31; dcut= 311;} + if (lowcut == 11) {lowcut = 23; dcut= 233;} + if (lowcut == 10) {lowcut = 19; dcut= 191;} + if (lowcut == 9) {lowcut = 17; dcut= 173;} + if (lowcut == 8) {lowcut = 13; dcut= 131;} + if (lowcut == 7) {lowcut = 11; dcut= 113;} + if (lowcut == 6) {lowcut = 7; dcut= 79;} + if (lowcut == 5) {lowcut = 6; dcut= 67;} + if (lowcut == 4) {lowcut = 5; dcut= 59;} + if (lowcut == 3) {lowcut = 4; dcut= 43;} + if (lowcut == 2) {lowcut = 3; dcut= 37;} + if (lowcut == 1) {lowcut = 2; dcut= 23;} + if (lowcut < 1) {lowcut = 1; dcut= 11;} + //this is the mechanism for cutting back subs without filtering + + double rumbletrim = sqrt(lowcut); + //this among other things is just to give volume compensation + double inputSampleL; + double inputSampleR; + + float fpTemp; + double fpOld = 0.618033988749894848204586; //golden ratio! + double fpNew = 1.0 - fpOld; + + while (--sampleFrames >= 0) + { + inputSampleL = *in1; + inputSampleR = *in2; + //we then ignore this! + + quadratic -= 1; + if (quadratic < 0) + { + position += 1; + quadratic = position * position; + quadratic = quadratic % 170003; //% is C++ mod operator + quadratic *= quadratic; + quadratic = quadratic % 17011; //% is C++ mod operator + quadratic *= quadratic; + quadratic = quadratic % 1709; //% is C++ mod operator + quadratic *= quadratic; + quadratic = quadratic % dcut; //% is C++ mod operator + quadratic *= quadratic; + quadratic = quadratic % lowcut; + //sets density of the centering force + if (noiseAL < 0) {flipL = true;} + else {flipL = false;} + if (noiseAR < 0) {flipR = true;} + else {flipR = false;} + //every time we come here, we force the random walk to be + //toward the center of the waveform. Without this, + //it's a pure random walk that will generate DC. + } + + if (flipL) noiseAL += (rand()/(double)RAND_MAX); + else noiseAL -= (rand()/(double)RAND_MAX); + if (flipR) noiseAR += (rand()/(double)RAND_MAX); + else noiseAR -= (rand()/(double)RAND_MAX); + //here's the guts of the random walk + + if (filterflip) + { + noiseBL *= invcutoff; noiseBL += (noiseAL*cutoff); + inputSampleL = noiseBL; + noiseBR *= invcutoff; noiseBR += (noiseAR*cutoff); + inputSampleR = noiseBR; + } + else + { + noiseCL *= invcutoff; noiseCL += (noiseAL*cutoff); + inputSampleL = noiseCL; + noiseCR *= invcutoff; noiseCR += (noiseAR*cutoff); + inputSampleR = noiseCR; + } + //now we have the output of the filter as inputSample. + //this filter is shallower than a straight IIR: it's interleaved + + + + + 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] = inputSampleL; + + 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] = inputSampleR; + + inputSampleL *= f[0]; + inputSampleL += (bL[1] * f[1]); + inputSampleL += (bL[2] * f[2]); + inputSampleL += (bL[3] * f[3]); + inputSampleL += (bL[4] * f[4]); + inputSampleL += (bL[5] * f[5]); + inputSampleL += (bL[6] * f[6]); + inputSampleL += (bL[7] * f[7]); + inputSampleL += (bL[8] * f[8]); + inputSampleL += (bL[9] * f[9]); + + inputSampleR *= f[0]; + inputSampleR += (bR[1] * f[1]); + inputSampleR += (bR[2] * f[2]); + inputSampleR += (bR[3] * f[3]); + inputSampleR += (bR[4] * f[4]); + inputSampleR += (bR[5] * f[5]); + inputSampleR += (bR[6] * f[6]); + inputSampleR += (bR[7] * f[7]); + inputSampleR += (bR[8] * f[8]); + inputSampleR += (bR[9] * f[9]); + + inputSampleL *= 0.1; + inputSampleR *= 0.1; + inputSampleL *= invcutoff; + inputSampleR *= invcutoff; + inputSampleL /= rumbletrim; + inputSampleR /= rumbletrim; + + flipL = !flipL; + flipR = !flipR; + filterflip = !filterflip; + + + //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 VoiceOfTheStarship::processDoubleReplacing(double **inputs, double **outputs, VstInt32 sampleFrames) +{ + double* in1 = inputs[0]; + double* in2 = inputs[1]; + double* out1 = outputs[0]; + double* out2 = outputs[1]; + double cutoff = pow((A*0.89)+0.1,3); + if (cutoff > 1.0) cutoff = 1.0; + double invcutoff = 1.0 - cutoff; + //this is the lowpass + + double overallscale = ((1.0-A)*9.0)+1.0; + double gain = overallscale; + if (gain > 1.0) {f[0] = 1.0; gain -= 1.0;} else {f[0] = gain; gain = 0.0;} + if (gain > 1.0) {f[1] = 1.0; gain -= 1.0;} else {f[1] = gain; gain = 0.0;} + if (gain > 1.0) {f[2] = 1.0; gain -= 1.0;} else {f[2] = gain; gain = 0.0;} + if (gain > 1.0) {f[3] = 1.0; gain -= 1.0;} else {f[3] = gain; gain = 0.0;} + if (gain > 1.0) {f[4] = 1.0; gain -= 1.0;} else {f[4] = gain; gain = 0.0;} + if (gain > 1.0) {f[5] = 1.0; gain -= 1.0;} else {f[5] = gain; gain = 0.0;} + if (gain > 1.0) {f[6] = 1.0; gain -= 1.0;} else {f[6] = gain; gain = 0.0;} + if (gain > 1.0) {f[7] = 1.0; gain -= 1.0;} else {f[7] = gain; gain = 0.0;} + if (gain > 1.0) {f[8] = 1.0; gain -= 1.0;} else {f[8] = gain; gain = 0.0;} + if (gain > 1.0) {f[9] = 1.0; gain -= 1.0;} else {f[9] = gain; gain = 0.0;} + //this is the moving average with remainders + if (overallscale < 1.0) overallscale = 1.0; + f[0] /= overallscale; + f[1] /= overallscale; + f[2] /= overallscale; + f[3] /= overallscale; + f[4] /= overallscale; + f[5] /= overallscale; + f[6] /= overallscale; + f[7] /= overallscale; + f[8] /= overallscale; + f[9] /= overallscale; + //and now it's neatly scaled, too + + int lowcut = floor(B*16.9); + if (lastAlgorithm != lowcut) { + noiseAL = 0.0; noiseBL = 0.0; noiseCL = 0.0; + noiseAR = 0.0; noiseBR = 0.0; noiseCR = 0.0; + for(int count = 0; count < 11; count++) {bL[count] = 0.0; bR[count] = 0.0;} + lastAlgorithm = lowcut; + } + //cuts the noise back to 0 if we are changing algorithms, + //because that also changes gains and can make loud pops. + //We still get pops, but they'd be even worse + int dcut; + if (lowcut > 15) {lowcut = 1151; dcut= 11517;} + if (lowcut == 15) {lowcut = 113; dcut= 1151;} + if (lowcut == 14) {lowcut = 71; dcut= 719;} + if (lowcut == 13) {lowcut = 53; dcut= 541;} + if (lowcut == 12) {lowcut = 31; dcut= 311;} + if (lowcut == 11) {lowcut = 23; dcut= 233;} + if (lowcut == 10) {lowcut = 19; dcut= 191;} + if (lowcut == 9) {lowcut = 17; dcut= 173;} + if (lowcut == 8) {lowcut = 13; dcut= 131;} + if (lowcut == 7) {lowcut = 11; dcut= 113;} + if (lowcut == 6) {lowcut = 7; dcut= 79;} + if (lowcut == 5) {lowcut = 6; dcut= 67;} + if (lowcut == 4) {lowcut = 5; dcut= 59;} + if (lowcut == 3) {lowcut = 4; dcut= 43;} + if (lowcut == 2) {lowcut = 3; dcut= 37;} + if (lowcut == 1) {lowcut = 2; dcut= 23;} + if (lowcut < 1) {lowcut = 1; dcut= 11;} + //this is the mechanism for cutting back subs without filtering + + double rumbletrim = sqrt(lowcut); + //this among other things is just to give volume compensation + double inputSampleL; + double inputSampleR; + + double fpTemp; + long double fpOld = 0.618033988749894848204586; //golden ratio! + long double fpNew = 1.0 - fpOld; + + while (--sampleFrames >= 0) + { + inputSampleL = *in1; + inputSampleR = *in2; + //we then ignore this! + + quadratic -= 1; + if (quadratic < 0) + { + position += 1; + quadratic = position * position; + quadratic = quadratic % 170003; //% is C++ mod operator + quadratic *= quadratic; + quadratic = quadratic % 17011; //% is C++ mod operator + quadratic *= quadratic; + quadratic = quadratic % 1709; //% is C++ mod operator + quadratic *= quadratic; + quadratic = quadratic % dcut; //% is C++ mod operator + quadratic *= quadratic; + quadratic = quadratic % lowcut; + //sets density of the centering force + if (noiseAL < 0) {flipL = true;} + else {flipL = false;} + if (noiseAR < 0) {flipR = true;} + else {flipR = false;} + //every time we come here, we force the random walk to be + //toward the center of the waveform. Without this, + //it's a pure random walk that will generate DC. + } + + if (flipL) noiseAL += (rand()/(double)RAND_MAX); + else noiseAL -= (rand()/(double)RAND_MAX); + if (flipR) noiseAR += (rand()/(double)RAND_MAX); + else noiseAR -= (rand()/(double)RAND_MAX); + //here's the guts of the random walk + + if (filterflip) + { + noiseBL *= invcutoff; noiseBL += (noiseAL*cutoff); + inputSampleL = noiseBL; + noiseBR *= invcutoff; noiseBR += (noiseAR*cutoff); + inputSampleR = noiseBR; + } + else + { + noiseCL *= invcutoff; noiseCL += (noiseAL*cutoff); + inputSampleL = noiseCL; + noiseCR *= invcutoff; noiseCR += (noiseAR*cutoff); + inputSampleR = noiseCR; + } + //now we have the output of the filter as inputSample. + //this filter is shallower than a straight IIR: it's interleaved + + + + + 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] = inputSampleL; + + 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] = inputSampleR; + + inputSampleL *= f[0]; + inputSampleL += (bL[1] * f[1]); + inputSampleL += (bL[2] * f[2]); + inputSampleL += (bL[3] * f[3]); + inputSampleL += (bL[4] * f[4]); + inputSampleL += (bL[5] * f[5]); + inputSampleL += (bL[6] * f[6]); + inputSampleL += (bL[7] * f[7]); + inputSampleL += (bL[8] * f[8]); + inputSampleL += (bL[9] * f[9]); + + inputSampleR *= f[0]; + inputSampleR += (bR[1] * f[1]); + inputSampleR += (bR[2] * f[2]); + inputSampleR += (bR[3] * f[3]); + inputSampleR += (bR[4] * f[4]); + inputSampleR += (bR[5] * f[5]); + inputSampleR += (bR[6] * f[6]); + inputSampleR += (bR[7] * f[7]); + inputSampleR += (bR[8] * f[8]); + inputSampleR += (bR[9] * f[9]); + + inputSampleL *= 0.1; + inputSampleR *= 0.1; + inputSampleL *= invcutoff; + inputSampleR *= invcutoff; + inputSampleL /= rumbletrim; + inputSampleR /= rumbletrim; + + flipL = !flipL; + flipR = !flipR; + filterflip = !filterflip; + + //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 |