clang format
This commit is contained in:
@@ -1,2 +1,25 @@
|
||||
---
|
||||
BasedOnStyle: LLVM
|
||||
ColumnLimit: 140
|
||||
ColumnLimit: "120"
|
||||
ConstructorInitializerIndentWidth: "0"
|
||||
IndentWidth: "4"
|
||||
TabWidth: "4"
|
||||
UseTab: Always
|
||||
AccessModifierOffset: "-4"
|
||||
AllowShortIfStatementsOnASingleLine: AllIfsAndElse
|
||||
AllowShortBlocksOnASingleLine: Always
|
||||
AllowShortLoopsOnASingleLine: true
|
||||
AllowShortEnumsOnASingleLine: false
|
||||
AlwaysBreakTemplateDeclarations: Yes
|
||||
PackConstructorInitializers: Never
|
||||
BreakConstructorInitializers: BeforeComma
|
||||
PointerAlignment: Left
|
||||
ReferenceAlignment: Left
|
||||
ConstructorInitializerIndentWidth: 4
|
||||
SpaceBeforeCpp11BracedList: true
|
||||
SeparateDefinitionBlocks: Always
|
||||
|
||||
BreakBeforeBraces: WebKit
|
||||
|
||||
EmptyLineBeforeAccessModifier: LogicalBlock
|
||||
Cpp11BracedListStyle: true
|
||||
|
||||
@@ -5,7 +5,8 @@ namespace trnr {
|
||||
// Clipper based on ClipOnly2 by Chris Johnson
|
||||
class aw_cliponly2 {
|
||||
public:
|
||||
aw_cliponly2() {
|
||||
aw_cliponly2()
|
||||
{
|
||||
samplerate = 44100;
|
||||
|
||||
lastSampleL = 0.0;
|
||||
@@ -14,15 +15,17 @@ public:
|
||||
lastSampleR = 0.0;
|
||||
wasPosClipR = false;
|
||||
wasNegClipR = false;
|
||||
for (int x = 0; x < 16; x++) {intermediateL[x] = 0.0; intermediateR[x] = 0.0;}
|
||||
//this is reset: values being initialized only once. Startup values, whatever they are.
|
||||
for (int x = 0; x < 16; x++) {
|
||||
intermediateL[x] = 0.0;
|
||||
intermediateR[x] = 0.0;
|
||||
}
|
||||
// this is reset: values being initialized only once. Startup values, whatever they are.
|
||||
}
|
||||
|
||||
void set_samplerate(double _samplerate) {
|
||||
samplerate = _samplerate;
|
||||
}
|
||||
void set_samplerate(double _samplerate) { samplerate = _samplerate; }
|
||||
|
||||
void process_block(double** inputs, double** outputs, long sample_frames) {
|
||||
void process_block(double** inputs, double** outputs, long sample_frames)
|
||||
{
|
||||
double* in1 = inputs[0];
|
||||
double* in2 = inputs[1];
|
||||
double* out1 = outputs[0];
|
||||
@@ -32,47 +35,65 @@ public:
|
||||
overallscale /= 44100.0;
|
||||
overallscale *= samplerate;
|
||||
|
||||
int spacing = floor(overallscale); //should give us working basic scaling, usually 2 or 4
|
||||
if (spacing < 1) spacing = 1; if (spacing > 16) spacing = 16;
|
||||
int spacing = floor(overallscale); // should give us working basic scaling, usually 2 or 4
|
||||
if (spacing < 1) spacing = 1;
|
||||
if (spacing > 16) spacing = 16;
|
||||
|
||||
while (--sample_frames >= 0)
|
||||
{
|
||||
while (--sample_frames >= 0) {
|
||||
double inputSampleL = *in1;
|
||||
double inputSampleR = *in2;
|
||||
|
||||
//begin ClipOnly2 stereo as a little, compressed chunk that can be dropped into code
|
||||
if (inputSampleL > 4.0) inputSampleL = 4.0; if (inputSampleL < -4.0) inputSampleL = -4.0;
|
||||
if (wasPosClipL == true) { //current will be over
|
||||
if (inputSampleL<lastSampleL) lastSampleL=0.7058208+(inputSampleL*0.2609148);
|
||||
else lastSampleL = 0.2491717+(lastSampleL*0.7390851);
|
||||
} wasPosClipL = false;
|
||||
if (inputSampleL>0.9549925859) {wasPosClipL=true;inputSampleL=0.7058208+(lastSampleL*0.2609148);}
|
||||
if (wasNegClipL == true) { //current will be -over
|
||||
if (inputSampleL > lastSampleL) lastSampleL=-0.7058208+(inputSampleL*0.2609148);
|
||||
else lastSampleL=-0.2491717+(lastSampleL*0.7390851);
|
||||
} wasNegClipL = false;
|
||||
if (inputSampleL<-0.9549925859) {wasNegClipL=true;inputSampleL=-0.7058208+(lastSampleL*0.2609148);}
|
||||
// begin ClipOnly2 stereo as a little, compressed chunk that can be dropped into code
|
||||
if (inputSampleL > 4.0) inputSampleL = 4.0;
|
||||
if (inputSampleL < -4.0) inputSampleL = -4.0;
|
||||
if (wasPosClipL == true) { // current will be over
|
||||
if (inputSampleL < lastSampleL) lastSampleL = 0.7058208 + (inputSampleL * 0.2609148);
|
||||
else lastSampleL = 0.2491717 + (lastSampleL * 0.7390851);
|
||||
}
|
||||
wasPosClipL = false;
|
||||
if (inputSampleL > 0.9549925859) {
|
||||
wasPosClipL = true;
|
||||
inputSampleL = 0.7058208 + (lastSampleL * 0.2609148);
|
||||
}
|
||||
if (wasNegClipL == true) { // current will be -over
|
||||
if (inputSampleL > lastSampleL) lastSampleL = -0.7058208 + (inputSampleL * 0.2609148);
|
||||
else lastSampleL = -0.2491717 + (lastSampleL * 0.7390851);
|
||||
}
|
||||
wasNegClipL = false;
|
||||
if (inputSampleL < -0.9549925859) {
|
||||
wasNegClipL = true;
|
||||
inputSampleL = -0.7058208 + (lastSampleL * 0.2609148);
|
||||
}
|
||||
intermediateL[spacing] = inputSampleL;
|
||||
inputSampleL = lastSampleL; //Latency is however many samples equals one 44.1k sample
|
||||
for (int x = spacing; x > 0; x--) intermediateL[x-1] = intermediateL[x];
|
||||
lastSampleL = intermediateL[0]; //run a little buffer to handle this
|
||||
inputSampleL = lastSampleL; // Latency is however many samples equals one 44.1k sample
|
||||
for (int x = spacing; x > 0; x--) intermediateL[x - 1] = intermediateL[x];
|
||||
lastSampleL = intermediateL[0]; // run a little buffer to handle this
|
||||
|
||||
if (inputSampleR > 4.0) inputSampleR = 4.0; if (inputSampleR < -4.0) inputSampleR = -4.0;
|
||||
if (wasPosClipR == true) { //current will be over
|
||||
if (inputSampleR<lastSampleR) lastSampleR=0.7058208+(inputSampleR*0.2609148);
|
||||
else lastSampleR = 0.2491717+(lastSampleR*0.7390851);
|
||||
} wasPosClipR = false;
|
||||
if (inputSampleR>0.9549925859) {wasPosClipR=true;inputSampleR=0.7058208+(lastSampleR*0.2609148);}
|
||||
if (wasNegClipR == true) { //current will be -over
|
||||
if (inputSampleR > lastSampleR) lastSampleR=-0.7058208+(inputSampleR*0.2609148);
|
||||
else lastSampleR=-0.2491717+(lastSampleR*0.7390851);
|
||||
} wasNegClipR = false;
|
||||
if (inputSampleR<-0.9549925859) {wasNegClipR=true;inputSampleR=-0.7058208+(lastSampleR*0.2609148);}
|
||||
if (inputSampleR > 4.0) inputSampleR = 4.0;
|
||||
if (inputSampleR < -4.0) inputSampleR = -4.0;
|
||||
if (wasPosClipR == true) { // current will be over
|
||||
if (inputSampleR < lastSampleR) lastSampleR = 0.7058208 + (inputSampleR * 0.2609148);
|
||||
else lastSampleR = 0.2491717 + (lastSampleR * 0.7390851);
|
||||
}
|
||||
wasPosClipR = false;
|
||||
if (inputSampleR > 0.9549925859) {
|
||||
wasPosClipR = true;
|
||||
inputSampleR = 0.7058208 + (lastSampleR * 0.2609148);
|
||||
}
|
||||
if (wasNegClipR == true) { // current will be -over
|
||||
if (inputSampleR > lastSampleR) lastSampleR = -0.7058208 + (inputSampleR * 0.2609148);
|
||||
else lastSampleR = -0.2491717 + (lastSampleR * 0.7390851);
|
||||
}
|
||||
wasNegClipR = false;
|
||||
if (inputSampleR < -0.9549925859) {
|
||||
wasNegClipR = true;
|
||||
inputSampleR = -0.7058208 + (lastSampleR * 0.2609148);
|
||||
}
|
||||
intermediateR[spacing] = inputSampleR;
|
||||
inputSampleR = lastSampleR; //Latency is however many samples equals one 44.1k sample
|
||||
for (int x = spacing; x > 0; x--) intermediateR[x-1] = intermediateR[x];
|
||||
lastSampleR = intermediateR[0]; //run a little buffer to handle this
|
||||
//end ClipOnly2 stereo as a little, compressed chunk that can be dropped into code
|
||||
inputSampleR = lastSampleR; // Latency is however many samples equals one 44.1k sample
|
||||
for (int x = spacing; x > 0; x--) intermediateR[x - 1] = intermediateR[x];
|
||||
lastSampleR = intermediateR[0]; // run a little buffer to handle this
|
||||
// end ClipOnly2 stereo as a little, compressed chunk that can be dropped into code
|
||||
|
||||
*out1 = inputSampleL;
|
||||
*out2 = inputSampleR;
|
||||
@@ -94,7 +115,7 @@ private:
|
||||
double lastSampleR;
|
||||
double intermediateR[16];
|
||||
bool wasPosClipR;
|
||||
bool wasNegClipR; //Stereo ClipOnly2
|
||||
//default stuff
|
||||
bool wasNegClipR; // Stereo ClipOnly2
|
||||
// default stuff
|
||||
};
|
||||
}
|
||||
} // namespace trnr
|
||||
@@ -6,22 +6,27 @@ namespace trnr {
|
||||
// soft clipper based on ClipSoftly by Chris Johnson
|
||||
class aw_clipsoftly {
|
||||
public:
|
||||
aw_clipsoftly() {
|
||||
aw_clipsoftly()
|
||||
{
|
||||
samplerate = 44100;
|
||||
|
||||
lastSampleL = 0.0;
|
||||
lastSampleR = 0.0;
|
||||
for (int x = 0; x < 16; x++) {intermediateL[x] = 0.0; intermediateR[x] = 0.0;}
|
||||
fpdL = 1.0; while (fpdL < 16386) fpdL = rand()*UINT32_MAX;
|
||||
fpdR = 1.0; while (fpdR < 16386) fpdR = rand()*UINT32_MAX;
|
||||
//this is reset: values being initialized only once. Startup values, whatever they are.
|
||||
for (int x = 0; x < 16; x++) {
|
||||
intermediateL[x] = 0.0;
|
||||
intermediateR[x] = 0.0;
|
||||
}
|
||||
fpdL = 1.0;
|
||||
while (fpdL < 16386) fpdL = rand() * UINT32_MAX;
|
||||
fpdR = 1.0;
|
||||
while (fpdR < 16386) fpdR = rand() * UINT32_MAX;
|
||||
// this is reset: values being initialized only once. Startup values, whatever they are.
|
||||
}
|
||||
|
||||
void set_samplerate(double _samplerate) {
|
||||
samplerate = _samplerate;
|
||||
}
|
||||
void set_samplerate(double _samplerate) { samplerate = _samplerate; }
|
||||
|
||||
void process_block(double** inputs, double** outputs, long sample_frames) {
|
||||
void process_block(double** inputs, double** outputs, long sample_frames)
|
||||
{
|
||||
double* in1 = inputs[0];
|
||||
double* in2 = inputs[1];
|
||||
double* out1 = outputs[0];
|
||||
@@ -30,48 +35,54 @@ public:
|
||||
double overallscale = 1.0;
|
||||
overallscale /= 44100.0;
|
||||
overallscale *= samplerate;
|
||||
int spacing = floor(overallscale); //should give us working basic scaling, usually 2 or 4
|
||||
if (spacing < 1) spacing = 1; if (spacing > 16) spacing = 16;
|
||||
int spacing = floor(overallscale); // should give us working basic scaling, usually 2 or 4
|
||||
if (spacing < 1) spacing = 1;
|
||||
if (spacing > 16) spacing = 16;
|
||||
|
||||
while (--sample_frames >= 0)
|
||||
{
|
||||
while (--sample_frames >= 0) {
|
||||
double inputSampleL = *in1;
|
||||
double inputSampleR = *in2;
|
||||
if (fabs(inputSampleL)<1.18e-23) inputSampleL = fpdL * 1.18e-17;
|
||||
if (fabs(inputSampleR)<1.18e-23) inputSampleR = fpdR * 1.18e-17;
|
||||
if (fabs(inputSampleL) < 1.18e-23) inputSampleL = fpdL * 1.18e-17;
|
||||
if (fabs(inputSampleR) < 1.18e-23) inputSampleR = fpdR * 1.18e-17;
|
||||
|
||||
double softSpeed = fabs(inputSampleL);
|
||||
if (softSpeed < 1.0) softSpeed = 1.0; else softSpeed = 1.0/softSpeed;
|
||||
if (softSpeed < 1.0) softSpeed = 1.0;
|
||||
else softSpeed = 1.0 / softSpeed;
|
||||
if (inputSampleL > 1.57079633) inputSampleL = 1.57079633;
|
||||
if (inputSampleL < -1.57079633) inputSampleL = -1.57079633;
|
||||
inputSampleL = sin(inputSampleL)*0.9549925859; //scale to what cliponly uses
|
||||
inputSampleL = (inputSampleL*softSpeed)+(lastSampleL*(1.0-softSpeed));
|
||||
inputSampleL = sin(inputSampleL) * 0.9549925859; // scale to what cliponly uses
|
||||
inputSampleL = (inputSampleL * softSpeed) + (lastSampleL * (1.0 - softSpeed));
|
||||
|
||||
softSpeed = fabs(inputSampleR);
|
||||
if (softSpeed < 1.0) softSpeed = 1.0; else softSpeed = 1.0/softSpeed;
|
||||
if (softSpeed < 1.0) softSpeed = 1.0;
|
||||
else softSpeed = 1.0 / softSpeed;
|
||||
if (inputSampleR > 1.57079633) inputSampleR = 1.57079633;
|
||||
if (inputSampleR < -1.57079633) inputSampleR = -1.57079633;
|
||||
inputSampleR = sin(inputSampleR)*0.9549925859; //scale to what cliponly uses
|
||||
inputSampleR = (inputSampleR*softSpeed)+(lastSampleR*(1.0-softSpeed));
|
||||
inputSampleR = sin(inputSampleR) * 0.9549925859; // scale to what cliponly uses
|
||||
inputSampleR = (inputSampleR * softSpeed) + (lastSampleR * (1.0 - softSpeed));
|
||||
|
||||
intermediateL[spacing] = inputSampleL;
|
||||
inputSampleL = lastSampleL; //Latency is however many samples equals one 44.1k sample
|
||||
for (int x = spacing; x > 0; x--) intermediateL[x-1] = intermediateL[x];
|
||||
lastSampleL = intermediateL[0]; //run a little buffer to handle this
|
||||
inputSampleL = lastSampleL; // Latency is however many samples equals one 44.1k sample
|
||||
for (int x = spacing; x > 0; x--) intermediateL[x - 1] = intermediateL[x];
|
||||
lastSampleL = intermediateL[0]; // run a little buffer to handle this
|
||||
|
||||
intermediateR[spacing] = inputSampleR;
|
||||
inputSampleR = lastSampleR; //Latency is however many samples equals one 44.1k sample
|
||||
for (int x = spacing; x > 0; x--) intermediateR[x-1] = intermediateR[x];
|
||||
lastSampleR = intermediateR[0]; //run a little buffer to handle this
|
||||
inputSampleR = lastSampleR; // Latency is however many samples equals one 44.1k sample
|
||||
for (int x = spacing; x > 0; x--) intermediateR[x - 1] = intermediateR[x];
|
||||
lastSampleR = intermediateR[0]; // run a little buffer to handle this
|
||||
|
||||
//begin 64 bit stereo floating point dither
|
||||
//int expon; frexp((double)inputSampleL, &expon);
|
||||
fpdL ^= fpdL << 13; fpdL ^= fpdL >> 17; fpdL ^= fpdL << 5;
|
||||
//inputSampleL += ((double(fpdL)-uint32_t(0x7fffffff)) * 1.1e-44l * pow(2,expon+62));
|
||||
//frexp((double)inputSampleR, &expon);
|
||||
fpdR ^= fpdR << 13; fpdR ^= fpdR >> 17; fpdR ^= fpdR << 5;
|
||||
//inputSampleR += ((double(fpdR)-uint32_t(0x7fffffff)) * 1.1e-44l * pow(2,expon+62));
|
||||
//end 64 bit stereo floating point dither
|
||||
// begin 64 bit stereo floating point dither
|
||||
// int expon; frexp((double)inputSampleL, &expon);
|
||||
fpdL ^= fpdL << 13;
|
||||
fpdL ^= fpdL >> 17;
|
||||
fpdL ^= fpdL << 5;
|
||||
// inputSampleL += ((double(fpdL)-uint32_t(0x7fffffff)) * 1.1e-44l * pow(2,expon+62));
|
||||
// frexp((double)inputSampleR, &expon);
|
||||
fpdR ^= fpdR << 13;
|
||||
fpdR ^= fpdR >> 17;
|
||||
fpdR ^= fpdR << 5;
|
||||
// inputSampleR += ((double(fpdR)-uint32_t(0x7fffffff)) * 1.1e-44l * pow(2,expon+62));
|
||||
// end 64 bit stereo floating point dither
|
||||
|
||||
*out1 = inputSampleL;
|
||||
*out2 = inputSampleR;
|
||||
@@ -92,6 +103,6 @@ private:
|
||||
double intermediateR[16];
|
||||
uint32_t fpdL;
|
||||
uint32_t fpdR;
|
||||
//default stuff
|
||||
// default stuff
|
||||
};
|
||||
}
|
||||
} // namespace trnr
|
||||
160
clip/aw_tube2.h
160
clip/aw_tube2.h
@@ -6,7 +6,8 @@ namespace trnr {
|
||||
// modeled tube preamp based on tube2 by Chris Johnson
|
||||
class aw_tube2 {
|
||||
public:
|
||||
aw_tube2() {
|
||||
aw_tube2()
|
||||
{
|
||||
samplerate = 44100;
|
||||
|
||||
A = 0.5;
|
||||
@@ -17,24 +18,21 @@ public:
|
||||
previousSampleD = 0.0;
|
||||
previousSampleE = 0.0;
|
||||
previousSampleF = 0.0;
|
||||
fpdL = 1.0; while (fpdL < 16386) fpdL = rand()*UINT32_MAX;
|
||||
fpdR = 1.0; while (fpdR < 16386) fpdR = rand()*UINT32_MAX;
|
||||
//this is reset: values being initialized only once. Startup values, whatever they are.
|
||||
fpdL = 1.0;
|
||||
while (fpdL < 16386) fpdL = rand() * UINT32_MAX;
|
||||
fpdR = 1.0;
|
||||
while (fpdR < 16386) fpdR = rand() * UINT32_MAX;
|
||||
// this is reset: values being initialized only once. Startup values, whatever they are.
|
||||
}
|
||||
|
||||
void set_input(double value) {
|
||||
A = clamp(value);
|
||||
}
|
||||
void set_input(double value) { A = clamp(value); }
|
||||
|
||||
void set_tube(double value) {
|
||||
B = clamp(value);
|
||||
}
|
||||
void set_tube(double value) { B = clamp(value); }
|
||||
|
||||
void set_samplerate(double _samplerate) {
|
||||
samplerate = _samplerate;
|
||||
}
|
||||
void set_samplerate(double _samplerate) { samplerate = _samplerate; }
|
||||
|
||||
void process_block(double **inputs, double **outputs, long sampleframes) {
|
||||
void process_block(double** inputs, double** outputs, long sampleframes)
|
||||
{
|
||||
double* in1 = inputs[0];
|
||||
double* in2 = inputs[1];
|
||||
double* out1 = outputs[0];
|
||||
@@ -45,18 +43,17 @@ public:
|
||||
overallscale *= samplerate;
|
||||
|
||||
double inputPad = A;
|
||||
double iterations = 1.0-B;
|
||||
int powerfactor = (9.0*iterations)+1;
|
||||
double iterations = 1.0 - B;
|
||||
int powerfactor = (9.0 * iterations) + 1;
|
||||
double asymPad = (double)powerfactor;
|
||||
double gainscaling = 1.0/(double)(powerfactor+1);
|
||||
double outputscaling = 1.0 + (1.0/(double)(powerfactor));
|
||||
double gainscaling = 1.0 / (double)(powerfactor + 1);
|
||||
double outputscaling = 1.0 + (1.0 / (double)(powerfactor));
|
||||
|
||||
while (--sampleframes >= 0)
|
||||
{
|
||||
while (--sampleframes >= 0) {
|
||||
double inputSampleL = *in1;
|
||||
double inputSampleR = *in2;
|
||||
if (fabs(inputSampleL)<1.18e-23) inputSampleL = fpdL * 1.18e-17;
|
||||
if (fabs(inputSampleR)<1.18e-23) inputSampleR = fpdR * 1.18e-17;
|
||||
if (fabs(inputSampleL) < 1.18e-23) inputSampleL = fpdL * 1.18e-17;
|
||||
if (fabs(inputSampleR) < 1.18e-23) inputSampleR = fpdR * 1.18e-17;
|
||||
|
||||
if (inputPad < 1.0) {
|
||||
inputSampleL *= inputPad;
|
||||
@@ -65,94 +62,110 @@ public:
|
||||
|
||||
if (overallscale > 1.9) {
|
||||
double stored = inputSampleL;
|
||||
inputSampleL += previousSampleA; previousSampleA = stored; inputSampleL *= 0.5;
|
||||
inputSampleL += previousSampleA;
|
||||
previousSampleA = stored;
|
||||
inputSampleL *= 0.5;
|
||||
stored = inputSampleR;
|
||||
inputSampleR += previousSampleB; previousSampleB = stored; inputSampleR *= 0.5;
|
||||
} //for high sample rates on this plugin we are going to do a simple average
|
||||
inputSampleR += previousSampleB;
|
||||
previousSampleB = stored;
|
||||
inputSampleR *= 0.5;
|
||||
} // for high sample rates on this plugin we are going to do a simple average
|
||||
|
||||
if (inputSampleL > 1.0) inputSampleL = 1.0;
|
||||
if (inputSampleL < -1.0) inputSampleL = -1.0;
|
||||
if (inputSampleR > 1.0) inputSampleR = 1.0;
|
||||
if (inputSampleR < -1.0) inputSampleR = -1.0;
|
||||
|
||||
//flatten bottom, point top of sine waveshaper L
|
||||
// flatten bottom, point top of sine waveshaper L
|
||||
inputSampleL /= asymPad;
|
||||
double sharpen = -inputSampleL;
|
||||
if (sharpen > 0.0) sharpen = 1.0+sqrt(sharpen);
|
||||
else sharpen = 1.0-sqrt(-sharpen);
|
||||
inputSampleL -= inputSampleL*fabs(inputSampleL)*sharpen*0.25;
|
||||
//this will take input from exactly -1.0 to 1.0 max
|
||||
if (sharpen > 0.0) sharpen = 1.0 + sqrt(sharpen);
|
||||
else sharpen = 1.0 - sqrt(-sharpen);
|
||||
inputSampleL -= inputSampleL * fabs(inputSampleL) * sharpen * 0.25;
|
||||
// this will take input from exactly -1.0 to 1.0 max
|
||||
inputSampleL *= asymPad;
|
||||
//flatten bottom, point top of sine waveshaper R
|
||||
// flatten bottom, point top of sine waveshaper R
|
||||
inputSampleR /= asymPad;
|
||||
sharpen = -inputSampleR;
|
||||
if (sharpen > 0.0) sharpen = 1.0+sqrt(sharpen);
|
||||
else sharpen = 1.0-sqrt(-sharpen);
|
||||
inputSampleR -= inputSampleR*fabs(inputSampleR)*sharpen*0.25;
|
||||
//this will take input from exactly -1.0 to 1.0 max
|
||||
if (sharpen > 0.0) sharpen = 1.0 + sqrt(sharpen);
|
||||
else sharpen = 1.0 - sqrt(-sharpen);
|
||||
inputSampleR -= inputSampleR * fabs(inputSampleR) * sharpen * 0.25;
|
||||
// this will take input from exactly -1.0 to 1.0 max
|
||||
inputSampleR *= asymPad;
|
||||
//end first asym section: later boosting can mitigate the extreme
|
||||
//softclipping of one side of the wave
|
||||
//and we are asym clipping more when Tube is cranked, to compensate
|
||||
// end first asym section: later boosting can mitigate the extreme
|
||||
// softclipping of one side of the wave
|
||||
// and we are asym clipping more when Tube is cranked, to compensate
|
||||
|
||||
//original Tube algorithm: powerfactor widens the more linear region of the wave
|
||||
double factor = inputSampleL; //Left channel
|
||||
// original Tube algorithm: powerfactor widens the more linear region of the wave
|
||||
double factor = inputSampleL; // Left channel
|
||||
for (int x = 0; x < powerfactor; x++) factor *= inputSampleL;
|
||||
if ((powerfactor % 2 == 1) && (inputSampleL != 0.0)) factor = (factor/inputSampleL)*fabs(inputSampleL);
|
||||
if ((powerfactor % 2 == 1) && (inputSampleL != 0.0)) factor = (factor / inputSampleL) * fabs(inputSampleL);
|
||||
factor *= gainscaling;
|
||||
inputSampleL -= factor;
|
||||
inputSampleL *= outputscaling;
|
||||
factor = inputSampleR; //Right channel
|
||||
factor = inputSampleR; // Right channel
|
||||
for (int x = 0; x < powerfactor; x++) factor *= inputSampleR;
|
||||
if ((powerfactor % 2 == 1) && (inputSampleR != 0.0)) factor = (factor/inputSampleR)*fabs(inputSampleR);
|
||||
if ((powerfactor % 2 == 1) && (inputSampleR != 0.0)) factor = (factor / inputSampleR) * fabs(inputSampleR);
|
||||
factor *= gainscaling;
|
||||
inputSampleR -= factor;
|
||||
inputSampleR *= outputscaling;
|
||||
|
||||
if (overallscale > 1.9) {
|
||||
double stored = inputSampleL;
|
||||
inputSampleL += previousSampleC; previousSampleC = stored; inputSampleL *= 0.5;
|
||||
inputSampleL += previousSampleC;
|
||||
previousSampleC = stored;
|
||||
inputSampleL *= 0.5;
|
||||
stored = inputSampleR;
|
||||
inputSampleR += previousSampleD; previousSampleD = stored; inputSampleR *= 0.5;
|
||||
} //for high sample rates on this plugin we are going to do a simple average
|
||||
//end original Tube. Now we have a boosted fat sound peaking at 0dB exactly
|
||||
inputSampleR += previousSampleD;
|
||||
previousSampleD = stored;
|
||||
inputSampleR *= 0.5;
|
||||
} // for high sample rates on this plugin we are going to do a simple average
|
||||
// end original Tube. Now we have a boosted fat sound peaking at 0dB exactly
|
||||
|
||||
//hysteresis and spiky fuzz L
|
||||
// hysteresis and spiky fuzz L
|
||||
double slew = previousSampleE - inputSampleL;
|
||||
if (overallscale > 1.9) {
|
||||
double stored = inputSampleL;
|
||||
inputSampleL += previousSampleE; previousSampleE = stored; inputSampleL *= 0.5;
|
||||
} else previousSampleE = inputSampleL; //for this, need previousSampleC always
|
||||
if (slew > 0.0) slew = 1.0+(sqrt(slew)*0.5);
|
||||
else slew = 1.0-(sqrt(-slew)*0.5);
|
||||
inputSampleL -= inputSampleL*fabs(inputSampleL)*slew*gainscaling;
|
||||
//reusing gainscaling that's part of another algorithm
|
||||
inputSampleL += previousSampleE;
|
||||
previousSampleE = stored;
|
||||
inputSampleL *= 0.5;
|
||||
} else previousSampleE = inputSampleL; // for this, need previousSampleC always
|
||||
if (slew > 0.0) slew = 1.0 + (sqrt(slew) * 0.5);
|
||||
else slew = 1.0 - (sqrt(-slew) * 0.5);
|
||||
inputSampleL -= inputSampleL * fabs(inputSampleL) * slew * gainscaling;
|
||||
// reusing gainscaling that's part of another algorithm
|
||||
if (inputSampleL > 0.52) inputSampleL = 0.52;
|
||||
if (inputSampleL < -0.52) inputSampleL = -0.52;
|
||||
inputSampleL *= 1.923076923076923;
|
||||
//hysteresis and spiky fuzz R
|
||||
// hysteresis and spiky fuzz R
|
||||
slew = previousSampleF - inputSampleR;
|
||||
if (overallscale > 1.9) {
|
||||
double stored = inputSampleR;
|
||||
inputSampleR += previousSampleF; previousSampleF = stored; inputSampleR *= 0.5;
|
||||
} else previousSampleF = inputSampleR; //for this, need previousSampleC always
|
||||
if (slew > 0.0) slew = 1.0+(sqrt(slew)*0.5);
|
||||
else slew = 1.0-(sqrt(-slew)*0.5);
|
||||
inputSampleR -= inputSampleR*fabs(inputSampleR)*slew*gainscaling;
|
||||
//reusing gainscaling that's part of another algorithm
|
||||
inputSampleR += previousSampleF;
|
||||
previousSampleF = stored;
|
||||
inputSampleR *= 0.5;
|
||||
} else previousSampleF = inputSampleR; // for this, need previousSampleC always
|
||||
if (slew > 0.0) slew = 1.0 + (sqrt(slew) * 0.5);
|
||||
else slew = 1.0 - (sqrt(-slew) * 0.5);
|
||||
inputSampleR -= inputSampleR * fabs(inputSampleR) * slew * gainscaling;
|
||||
// reusing gainscaling that's part of another algorithm
|
||||
if (inputSampleR > 0.52) inputSampleR = 0.52;
|
||||
if (inputSampleR < -0.52) inputSampleR = -0.52;
|
||||
inputSampleR *= 1.923076923076923;
|
||||
//end hysteresis and spiky fuzz section
|
||||
// end hysteresis and spiky fuzz section
|
||||
|
||||
//begin 64 bit stereo floating point dither
|
||||
//int expon; frexp((double)inputSampleL, &expon);
|
||||
fpdL ^= fpdL << 13; fpdL ^= fpdL >> 17; fpdL ^= fpdL << 5;
|
||||
//inputSampleL += ((double(fpdL)-uint32_t(0x7fffffff)) * 1.1e-44l * pow(2,expon+62));
|
||||
//frexp((double)inputSampleR, &expon);
|
||||
fpdR ^= fpdR << 13; fpdR ^= fpdR >> 17; fpdR ^= fpdR << 5;
|
||||
//inputSampleR += ((double(fpdR)-uint32_t(0x7fffffff)) * 1.1e-44l * pow(2,expon+62));
|
||||
//end 64 bit stereo floating point dither
|
||||
// begin 64 bit stereo floating point dither
|
||||
// int expon; frexp((double)inputSampleL, &expon);
|
||||
fpdL ^= fpdL << 13;
|
||||
fpdL ^= fpdL >> 17;
|
||||
fpdL ^= fpdL << 5;
|
||||
// inputSampleL += ((double(fpdL)-uint32_t(0x7fffffff)) * 1.1e-44l * pow(2,expon+62));
|
||||
// frexp((double)inputSampleR, &expon);
|
||||
fpdR ^= fpdR << 13;
|
||||
fpdR ^= fpdR >> 17;
|
||||
fpdR ^= fpdR << 5;
|
||||
// inputSampleR += ((double(fpdR)-uint32_t(0x7fffffff)) * 1.1e-44l * pow(2,expon+62));
|
||||
// end 64 bit stereo floating point dither
|
||||
|
||||
*out1 = inputSampleL;
|
||||
*out2 = inputSampleR;
|
||||
@@ -176,12 +189,13 @@ private:
|
||||
|
||||
uint32_t fpdL;
|
||||
uint32_t fpdR;
|
||||
//default stuff
|
||||
// default stuff
|
||||
|
||||
float A;
|
||||
float B;
|
||||
|
||||
double clamp(double& value) {
|
||||
double clamp(double& value)
|
||||
{
|
||||
if (value > 1) {
|
||||
value = 1;
|
||||
} else if (value < 0) {
|
||||
@@ -190,4 +204,4 @@ private:
|
||||
return value;
|
||||
}
|
||||
};
|
||||
}
|
||||
} // namespace trnr
|
||||
@@ -5,7 +5,8 @@ namespace trnr {
|
||||
// mulaw companding based on code by Emilie Gillet / Mutable Instruments
|
||||
class mulaw {
|
||||
public:
|
||||
int8_t encode_samples(int16_t pcm_val) {
|
||||
int8_t encode_samples(int16_t pcm_val)
|
||||
{
|
||||
int16_t mask;
|
||||
int16_t seg;
|
||||
uint8_t uval;
|
||||
@@ -28,15 +29,15 @@ public:
|
||||
else if (pcm_val <= 0xfff) seg = 6;
|
||||
else if (pcm_val <= 0x1fff) seg = 7;
|
||||
else seg = 8;
|
||||
if (seg >= 8)
|
||||
return static_cast<uint8_t>(0x7f ^ mask);
|
||||
if (seg >= 8) return static_cast<uint8_t>(0x7f ^ mask);
|
||||
else {
|
||||
uval = static_cast<uint8_t>((seg << 4) | ((pcm_val >> (seg + 1)) & 0x0f));
|
||||
return (uval ^ mask);
|
||||
}
|
||||
}
|
||||
|
||||
int16_t decode_samples(uint8_t u_val) {
|
||||
int16_t decode_samples(uint8_t u_val)
|
||||
{
|
||||
int16_t t;
|
||||
u_val = ~u_val;
|
||||
t = ((u_val & 0xf) << 3) + 0x84;
|
||||
@@ -44,4 +45,4 @@ public:
|
||||
return ((u_val & 0x80) ? (0x84 - t) : (t - 0x84));
|
||||
}
|
||||
};
|
||||
}
|
||||
} // namespace trnr
|
||||
@@ -1,18 +1,22 @@
|
||||
#pragma once
|
||||
#include <stdlib.h>
|
||||
#include <cstdint>
|
||||
#include <cmath>
|
||||
#include <cstdint>
|
||||
#include <stdlib.h>
|
||||
|
||||
namespace trnr {
|
||||
// ulaw compansion based on code by Chris Johnson
|
||||
class ulaw {
|
||||
public:
|
||||
ulaw() {
|
||||
fpd_l = 1.0; while (fpd_l < 16386) fpd_l = rand()*UINT32_MAX;
|
||||
fpd_r = 1.0; while (fpd_r < 16386) fpd_r = rand()*UINT32_MAX;
|
||||
ulaw()
|
||||
{
|
||||
fpd_l = 1.0;
|
||||
while (fpd_l < 16386) fpd_l = rand() * UINT32_MAX;
|
||||
fpd_r = 1.0;
|
||||
while (fpd_r < 16386) fpd_r = rand() * UINT32_MAX;
|
||||
}
|
||||
|
||||
void encode_samples(double& input_sample_l, double& input_sample_r) {
|
||||
void encode_samples(double& input_sample_l, double& input_sample_r)
|
||||
{
|
||||
|
||||
// ulaw encoding
|
||||
static int noisesource_l = 0;
|
||||
@@ -20,35 +24,41 @@ public:
|
||||
int residue;
|
||||
double applyresidue;
|
||||
|
||||
noisesource_l = noisesource_l % 1700021; noisesource_l++;
|
||||
noisesource_l = noisesource_l % 1700021;
|
||||
noisesource_l++;
|
||||
residue = noisesource_l * noisesource_l;
|
||||
residue = residue % 170003; residue *= residue;
|
||||
residue = residue % 17011; residue *= residue;
|
||||
residue = residue % 1709; residue *= residue;
|
||||
residue = residue % 173; residue *= residue;
|
||||
residue = residue % 170003;
|
||||
residue *= residue;
|
||||
residue = residue % 17011;
|
||||
residue *= residue;
|
||||
residue = residue % 1709;
|
||||
residue *= residue;
|
||||
residue = residue % 173;
|
||||
residue *= residue;
|
||||
residue = residue % 17;
|
||||
applyresidue = residue;
|
||||
applyresidue *= 0.00000001;
|
||||
applyresidue *= 0.00000001;
|
||||
input_sample_l += applyresidue;
|
||||
if (input_sample_l<1.2e-38 && -input_sample_l<1.2e-38) {
|
||||
input_sample_l -= applyresidue;
|
||||
}
|
||||
if (input_sample_l < 1.2e-38 && -input_sample_l < 1.2e-38) { input_sample_l -= applyresidue; }
|
||||
|
||||
noisesource_r = noisesource_r % 1700021; noisesource_r++;
|
||||
noisesource_r = noisesource_r % 1700021;
|
||||
noisesource_r++;
|
||||
residue = noisesource_r * noisesource_r;
|
||||
residue = residue % 170003; residue *= residue;
|
||||
residue = residue % 17011; residue *= residue;
|
||||
residue = residue % 1709; residue *= residue;
|
||||
residue = residue % 173; residue *= residue;
|
||||
residue = residue % 170003;
|
||||
residue *= residue;
|
||||
residue = residue % 17011;
|
||||
residue *= residue;
|
||||
residue = residue % 1709;
|
||||
residue *= residue;
|
||||
residue = residue % 173;
|
||||
residue *= residue;
|
||||
residue = residue % 17;
|
||||
applyresidue = residue;
|
||||
applyresidue *= 0.00000001;
|
||||
applyresidue *= 0.00000001;
|
||||
input_sample_r += applyresidue;
|
||||
if (input_sample_r<1.2e-38 && -input_sample_r<1.2e-38) {
|
||||
input_sample_r -= applyresidue;
|
||||
}
|
||||
if (input_sample_r < 1.2e-38 && -input_sample_r < 1.2e-38) { input_sample_r -= applyresidue; }
|
||||
|
||||
if (input_sample_l > 1.0) input_sample_l = 1.0;
|
||||
if (input_sample_l < -1.0) input_sample_l = -1.0;
|
||||
@@ -56,18 +66,19 @@ public:
|
||||
if (input_sample_r > 1.0) input_sample_r = 1.0;
|
||||
if (input_sample_r < -1.0) input_sample_r = -1.0;
|
||||
|
||||
if (input_sample_l > 0) input_sample_l = log(1.0+(255*fabs(input_sample_l))) / log(256);
|
||||
if (input_sample_l < 0) input_sample_l = -log(1.0+(255*fabs(input_sample_l))) / log(256);
|
||||
if (input_sample_l > 0) input_sample_l = log(1.0 + (255 * fabs(input_sample_l))) / log(256);
|
||||
if (input_sample_l < 0) input_sample_l = -log(1.0 + (255 * fabs(input_sample_l))) / log(256);
|
||||
|
||||
if (input_sample_r > 0) input_sample_r = log(1.0+(255*fabs(input_sample_r))) / log(256);
|
||||
if (input_sample_r < 0) input_sample_r = -log(1.0+(255*fabs(input_sample_r))) / log(256);
|
||||
if (input_sample_r > 0) input_sample_r = log(1.0 + (255 * fabs(input_sample_r))) / log(256);
|
||||
if (input_sample_r < 0) input_sample_r = -log(1.0 + (255 * fabs(input_sample_r))) / log(256);
|
||||
}
|
||||
|
||||
void decode_samples(double& input_sample_l, double& input_sample_r) {
|
||||
void decode_samples(double& input_sample_l, double& input_sample_r)
|
||||
{
|
||||
|
||||
// ulaw decoding
|
||||
if (fabs(input_sample_l)<1.18e-23) input_sample_l = fpd_l * 1.18e-17;
|
||||
if (fabs(input_sample_r)<1.18e-23) input_sample_r = fpd_r * 1.18e-17;
|
||||
if (fabs(input_sample_l) < 1.18e-23) input_sample_l = fpd_l * 1.18e-17;
|
||||
if (fabs(input_sample_r) < 1.18e-23) input_sample_r = fpd_r * 1.18e-17;
|
||||
|
||||
if (input_sample_l > 1.0) input_sample_l = 1.0;
|
||||
if (input_sample_l < -1.0) input_sample_l = -1.0;
|
||||
@@ -75,19 +86,23 @@ public:
|
||||
if (input_sample_r > 1.0) input_sample_r = 1.0;
|
||||
if (input_sample_r < -1.0) input_sample_r = -1.0;
|
||||
|
||||
if (input_sample_l > 0) input_sample_l = (pow(256,fabs(input_sample_l))-1.0) / 255;
|
||||
if (input_sample_l < 0) input_sample_l = -(pow(256,fabs(input_sample_l))-1.0) / 255;
|
||||
if (input_sample_l > 0) input_sample_l = (pow(256, fabs(input_sample_l)) - 1.0) / 255;
|
||||
if (input_sample_l < 0) input_sample_l = -(pow(256, fabs(input_sample_l)) - 1.0) / 255;
|
||||
|
||||
if (input_sample_r > 0) input_sample_r = (pow(256,fabs(input_sample_r))-1.0) / 255;
|
||||
if (input_sample_r < 0) input_sample_r = -(pow(256,fabs(input_sample_r))-1.0) / 255;
|
||||
if (input_sample_r > 0) input_sample_r = (pow(256, fabs(input_sample_r)) - 1.0) / 255;
|
||||
if (input_sample_r < 0) input_sample_r = -(pow(256, fabs(input_sample_r)) - 1.0) / 255;
|
||||
|
||||
// 64 bit stereo floating point dither
|
||||
fpd_l ^= fpd_l << 13; fpd_l ^= fpd_l >> 17; fpd_l ^= fpd_l << 5;
|
||||
fpd_r ^= fpd_r << 13; fpd_r ^= fpd_r >> 17; fpd_r ^= fpd_r << 5;
|
||||
fpd_l ^= fpd_l << 13;
|
||||
fpd_l ^= fpd_l >> 17;
|
||||
fpd_l ^= fpd_l << 5;
|
||||
fpd_r ^= fpd_r << 13;
|
||||
fpd_r ^= fpd_r >> 17;
|
||||
fpd_r ^= fpd_r << 5;
|
||||
}
|
||||
|
||||
private:
|
||||
uint32_t fpd_l;
|
||||
uint32_t fpd_r;
|
||||
};
|
||||
}
|
||||
} // namespace trnr
|
||||
@@ -6,7 +6,8 @@ namespace trnr {
|
||||
// compressor based on pop2 by Chris Johnson
|
||||
class aw_pop2 {
|
||||
public:
|
||||
aw_pop2() {
|
||||
aw_pop2()
|
||||
{
|
||||
samplerate = 44100;
|
||||
|
||||
A = 0.5;
|
||||
@@ -14,8 +15,10 @@ public:
|
||||
C = 0.5;
|
||||
D = 0.5;
|
||||
E = 1.0;
|
||||
fpdL = 1.0; while (fpdL < 16386) fpdL = rand()*UINT32_MAX;
|
||||
fpdR = 1.0; while (fpdR < 16386) fpdR = rand()*UINT32_MAX;
|
||||
fpdL = 1.0;
|
||||
while (fpdL < 16386) fpdL = rand() * UINT32_MAX;
|
||||
fpdR = 1.0;
|
||||
while (fpdR < 16386) fpdR = rand() * UINT32_MAX;
|
||||
|
||||
lastSampleL = 0.0;
|
||||
wasPosClipL = false;
|
||||
@@ -23,7 +26,10 @@ public:
|
||||
lastSampleR = 0.0;
|
||||
wasPosClipR = false;
|
||||
wasNegClipR = false;
|
||||
for (int x = 0; x < 16; x++) {intermediateL[x] = 0.0; intermediateR[x] = 0.0;}
|
||||
for (int x = 0; x < 16; x++) {
|
||||
intermediateL[x] = 0.0;
|
||||
intermediateR[x] = 0.0;
|
||||
}
|
||||
|
||||
muVaryL = 0.0;
|
||||
muAttackL = 0.0;
|
||||
@@ -42,34 +48,23 @@ public:
|
||||
muCoefficientBR = 1.0;
|
||||
|
||||
flip = false;
|
||||
//this is reset: values being initialized only once. Startup values, whatever they are.
|
||||
// this is reset: values being initialized only once. Startup values, whatever they are.
|
||||
}
|
||||
|
||||
void set_compression(double value) {
|
||||
A = clamp(value);
|
||||
}
|
||||
void set_compression(double value) { A = clamp(value); }
|
||||
|
||||
void set_attack(double value) {
|
||||
B = clamp(value);
|
||||
}
|
||||
void set_attack(double value) { B = clamp(value); }
|
||||
|
||||
void set_release(double value) {
|
||||
C = clamp(value);
|
||||
}
|
||||
void set_release(double value) { C = clamp(value); }
|
||||
|
||||
void set_drive(double value) {
|
||||
D = clamp(value);
|
||||
}
|
||||
void set_drive(double value) { D = clamp(value); }
|
||||
|
||||
void set_drywet(double value) {
|
||||
E = clamp(value);
|
||||
}
|
||||
void set_drywet(double value) { E = clamp(value); }
|
||||
|
||||
void set_samplerate(double _samplerate) {
|
||||
samplerate = _samplerate;
|
||||
}
|
||||
void set_samplerate(double _samplerate) { samplerate = _samplerate; }
|
||||
|
||||
void process_block(double **inputs, double **outputs, long sampleframes) {
|
||||
void process_block(double** inputs, double** outputs, long sampleframes)
|
||||
{
|
||||
double* in1 = inputs[0];
|
||||
double* in2 = inputs[1];
|
||||
double* out1 = outputs[0];
|
||||
@@ -79,91 +74,92 @@ public:
|
||||
overallscale /= 44100.0;
|
||||
overallscale *= samplerate;
|
||||
|
||||
int spacing = floor(overallscale); //should give us working basic scaling, usually 2 or 4
|
||||
if (spacing < 1) spacing = 1; if (spacing > 16) spacing = 16;
|
||||
int spacing = floor(overallscale); // should give us working basic scaling, usually 2 or 4
|
||||
if (spacing < 1) spacing = 1;
|
||||
if (spacing > 16) spacing = 16;
|
||||
|
||||
double threshold = 1.0 - ((1.0-pow(1.0-A,2))*0.9);
|
||||
double attack = ((pow(B,4)*100000.0)+10.0)*overallscale;
|
||||
double release = ((pow(C,5)*2000000.0)+20.0)*overallscale;
|
||||
double threshold = 1.0 - ((1.0 - pow(1.0 - A, 2)) * 0.9);
|
||||
double attack = ((pow(B, 4) * 100000.0) + 10.0) * overallscale;
|
||||
double release = ((pow(C, 5) * 2000000.0) + 20.0) * overallscale;
|
||||
double maxRelease = release * 4.0;
|
||||
double muPreGain = 1.0/threshold;
|
||||
double muMakeupGain = sqrt(1.0 / threshold)*D;
|
||||
double muPreGain = 1.0 / threshold;
|
||||
double muMakeupGain = sqrt(1.0 / threshold) * D;
|
||||
double wet = E;
|
||||
//compressor section
|
||||
// compressor section
|
||||
|
||||
while (--sampleframes >= 0)
|
||||
{
|
||||
while (--sampleframes >= 0) {
|
||||
double inputSampleL = *in1;
|
||||
double inputSampleR = *in2;
|
||||
if (fabs(inputSampleL)<1.18e-23) inputSampleL = fpdL * 1.18e-17;
|
||||
if (fabs(inputSampleR)<1.18e-23) inputSampleR = fpdR * 1.18e-17;
|
||||
if (fabs(inputSampleL) < 1.18e-23) inputSampleL = fpdL * 1.18e-17;
|
||||
if (fabs(inputSampleR) < 1.18e-23) inputSampleR = fpdR * 1.18e-17;
|
||||
double drySampleL = inputSampleL;
|
||||
double drySampleR = inputSampleR;
|
||||
|
||||
//begin compressor section
|
||||
// begin compressor section
|
||||
inputSampleL *= muPreGain;
|
||||
inputSampleR *= muPreGain;
|
||||
//adjust coefficients for L
|
||||
// adjust coefficients for L
|
||||
if (flip) {
|
||||
if (fabs(inputSampleL) > threshold) {
|
||||
muVaryL = threshold / fabs(inputSampleL);
|
||||
muAttackL = sqrt(fabs(muSpeedAL));
|
||||
muCoefficientAL = muCoefficientAL * (muAttackL-1.0);
|
||||
muCoefficientAL = muCoefficientAL * (muAttackL - 1.0);
|
||||
if (muVaryL < threshold) muCoefficientAL = muCoefficientAL + threshold;
|
||||
else muCoefficientAL = muCoefficientAL + muVaryL;
|
||||
muCoefficientAL = muCoefficientAL / muAttackL;
|
||||
muNewSpeedL = muSpeedAL * (muSpeedAL-1.0);
|
||||
muNewSpeedL = muSpeedAL * (muSpeedAL - 1.0);
|
||||
muNewSpeedL = muNewSpeedL + release;
|
||||
muSpeedAL = muNewSpeedL / muSpeedAL;
|
||||
if (muSpeedAL > maxRelease) muSpeedAL = maxRelease;
|
||||
} else {
|
||||
muCoefficientAL = muCoefficientAL * ((muSpeedAL * muSpeedAL)-1.0);
|
||||
muCoefficientAL = muCoefficientAL * ((muSpeedAL * muSpeedAL) - 1.0);
|
||||
muCoefficientAL = muCoefficientAL + 1.0;
|
||||
muCoefficientAL = muCoefficientAL / (muSpeedAL * muSpeedAL);
|
||||
muNewSpeedL = muSpeedAL * (muSpeedAL-1.0);
|
||||
muNewSpeedL = muSpeedAL * (muSpeedAL - 1.0);
|
||||
muNewSpeedL = muNewSpeedL + attack;
|
||||
muSpeedAL = muNewSpeedL / muSpeedAL;}
|
||||
muSpeedAL = muNewSpeedL / muSpeedAL;
|
||||
}
|
||||
} else {
|
||||
if (fabs(inputSampleL) > threshold) {
|
||||
muVaryL = threshold / fabs(inputSampleL);
|
||||
muAttackL = sqrt(fabs(muSpeedBL));
|
||||
muCoefficientBL = muCoefficientBL * (muAttackL-1);
|
||||
muCoefficientBL = muCoefficientBL * (muAttackL - 1);
|
||||
if (muVaryL < threshold) muCoefficientBL = muCoefficientBL + threshold;
|
||||
else muCoefficientBL = muCoefficientBL + muVaryL;
|
||||
muCoefficientBL = muCoefficientBL / muAttackL;
|
||||
muNewSpeedL = muSpeedBL * (muSpeedBL-1.0);
|
||||
muNewSpeedL = muSpeedBL * (muSpeedBL - 1.0);
|
||||
muNewSpeedL = muNewSpeedL + release;
|
||||
muSpeedBL = muNewSpeedL / muSpeedBL;
|
||||
if (muSpeedBL > maxRelease) muSpeedBL = maxRelease;
|
||||
} else {
|
||||
muCoefficientBL = muCoefficientBL * ((muSpeedBL * muSpeedBL)-1.0);
|
||||
muCoefficientBL = muCoefficientBL * ((muSpeedBL * muSpeedBL) - 1.0);
|
||||
muCoefficientBL = muCoefficientBL + 1.0;
|
||||
muCoefficientBL = muCoefficientBL / (muSpeedBL * muSpeedBL);
|
||||
muNewSpeedL = muSpeedBL * (muSpeedBL-1.0);
|
||||
muNewSpeedL = muSpeedBL * (muSpeedBL - 1.0);
|
||||
muNewSpeedL = muNewSpeedL + attack;
|
||||
muSpeedBL = muNewSpeedL / muSpeedBL;
|
||||
}
|
||||
}
|
||||
//got coefficients, adjusted speeds for L
|
||||
// got coefficients, adjusted speeds for L
|
||||
|
||||
//adjust coefficients for R
|
||||
// adjust coefficients for R
|
||||
if (flip) {
|
||||
if (fabs(inputSampleR) > threshold) {
|
||||
muVaryR = threshold / fabs(inputSampleR);
|
||||
muAttackR = sqrt(fabs(muSpeedAR));
|
||||
muCoefficientAR = muCoefficientAR * (muAttackR-1.0);
|
||||
muCoefficientAR = muCoefficientAR * (muAttackR - 1.0);
|
||||
if (muVaryR < threshold) muCoefficientAR = muCoefficientAR + threshold;
|
||||
else muCoefficientAR = muCoefficientAR + muVaryR;
|
||||
muCoefficientAR = muCoefficientAR / muAttackR;
|
||||
muNewSpeedR = muSpeedAR * (muSpeedAR-1.0);
|
||||
muNewSpeedR = muSpeedAR * (muSpeedAR - 1.0);
|
||||
muNewSpeedR = muNewSpeedR + release;
|
||||
muSpeedAR = muNewSpeedR / muSpeedAR;
|
||||
if (muSpeedAR > maxRelease) muSpeedAR = maxRelease;
|
||||
} else {
|
||||
muCoefficientAR = muCoefficientAR * ((muSpeedAR * muSpeedAR)-1.0);
|
||||
muCoefficientAR = muCoefficientAR * ((muSpeedAR * muSpeedAR) - 1.0);
|
||||
muCoefficientAR = muCoefficientAR + 1.0;
|
||||
muCoefficientAR = muCoefficientAR / (muSpeedAR * muSpeedAR);
|
||||
muNewSpeedR = muSpeedAR * (muSpeedAR-1.0);
|
||||
muNewSpeedR = muSpeedAR * (muSpeedAR - 1.0);
|
||||
muNewSpeedR = muNewSpeedR + attack;
|
||||
muSpeedAR = muNewSpeedR / muSpeedAR;
|
||||
}
|
||||
@@ -171,84 +167,106 @@ public:
|
||||
if (fabs(inputSampleR) > threshold) {
|
||||
muVaryR = threshold / fabs(inputSampleR);
|
||||
muAttackR = sqrt(fabs(muSpeedBR));
|
||||
muCoefficientBR = muCoefficientBR * (muAttackR-1);
|
||||
muCoefficientBR = muCoefficientBR * (muAttackR - 1);
|
||||
if (muVaryR < threshold) muCoefficientBR = muCoefficientBR + threshold;
|
||||
else muCoefficientBR = muCoefficientBR + muVaryR;
|
||||
muCoefficientBR = muCoefficientBR / muAttackR;
|
||||
muNewSpeedR = muSpeedBR * (muSpeedBR-1.0);
|
||||
muNewSpeedR = muSpeedBR * (muSpeedBR - 1.0);
|
||||
muNewSpeedR = muNewSpeedR + release;
|
||||
muSpeedBR = muNewSpeedR / muSpeedBR;
|
||||
if (muSpeedBR > maxRelease) muSpeedBR = maxRelease;
|
||||
} else {
|
||||
muCoefficientBR = muCoefficientBR * ((muSpeedBR * muSpeedBR)-1.0);
|
||||
muCoefficientBR = muCoefficientBR * ((muSpeedBR * muSpeedBR) - 1.0);
|
||||
muCoefficientBR = muCoefficientBR + 1.0;
|
||||
muCoefficientBR = muCoefficientBR / (muSpeedBR * muSpeedBR);
|
||||
muNewSpeedR = muSpeedBR * (muSpeedBR-1.0);
|
||||
muNewSpeedR = muSpeedBR * (muSpeedBR - 1.0);
|
||||
muNewSpeedR = muNewSpeedR + attack;
|
||||
muSpeedBR = muNewSpeedR / muSpeedBR;
|
||||
}
|
||||
}
|
||||
//got coefficients, adjusted speeds for R
|
||||
// got coefficients, adjusted speeds for R
|
||||
|
||||
if (flip) {
|
||||
inputSampleL *= pow(muCoefficientAL,2);
|
||||
inputSampleR *= pow(muCoefficientAR,2);
|
||||
inputSampleL *= pow(muCoefficientAL, 2);
|
||||
inputSampleR *= pow(muCoefficientAR, 2);
|
||||
} else {
|
||||
inputSampleL *= pow(muCoefficientBL,2);
|
||||
inputSampleR *= pow(muCoefficientBR,2);
|
||||
inputSampleL *= pow(muCoefficientBL, 2);
|
||||
inputSampleR *= pow(muCoefficientBR, 2);
|
||||
}
|
||||
inputSampleL *= muMakeupGain;
|
||||
inputSampleR *= muMakeupGain;
|
||||
flip = !flip;
|
||||
//end compressor section
|
||||
// end compressor section
|
||||
|
||||
//begin ClipOnly2 stereo as a little, compressed chunk that can be dropped into code
|
||||
if (inputSampleL > 4.0) inputSampleL = 4.0; if (inputSampleL < -4.0) inputSampleL = -4.0;
|
||||
if (wasPosClipL == true) { //current will be over
|
||||
if (inputSampleL<lastSampleL) lastSampleL=0.7058208+(inputSampleL*0.2609148);
|
||||
else lastSampleL = 0.2491717+(lastSampleL*0.7390851);
|
||||
} wasPosClipL = false;
|
||||
if (inputSampleL>0.9549925859) {wasPosClipL=true;inputSampleL=0.7058208+(lastSampleL*0.2609148);}
|
||||
if (wasNegClipL == true) { //current will be -over
|
||||
if (inputSampleL > lastSampleL) lastSampleL=-0.7058208+(inputSampleL*0.2609148);
|
||||
else lastSampleL=-0.2491717+(lastSampleL*0.7390851);
|
||||
} wasNegClipL = false;
|
||||
if (inputSampleL<-0.9549925859) {wasNegClipL=true;inputSampleL=-0.7058208+(lastSampleL*0.2609148);}
|
||||
// begin ClipOnly2 stereo as a little, compressed chunk that can be dropped into code
|
||||
if (inputSampleL > 4.0) inputSampleL = 4.0;
|
||||
if (inputSampleL < -4.0) inputSampleL = -4.0;
|
||||
if (wasPosClipL == true) { // current will be over
|
||||
if (inputSampleL < lastSampleL) lastSampleL = 0.7058208 + (inputSampleL * 0.2609148);
|
||||
else lastSampleL = 0.2491717 + (lastSampleL * 0.7390851);
|
||||
}
|
||||
wasPosClipL = false;
|
||||
if (inputSampleL > 0.9549925859) {
|
||||
wasPosClipL = true;
|
||||
inputSampleL = 0.7058208 + (lastSampleL * 0.2609148);
|
||||
}
|
||||
if (wasNegClipL == true) { // current will be -over
|
||||
if (inputSampleL > lastSampleL) lastSampleL = -0.7058208 + (inputSampleL * 0.2609148);
|
||||
else lastSampleL = -0.2491717 + (lastSampleL * 0.7390851);
|
||||
}
|
||||
wasNegClipL = false;
|
||||
if (inputSampleL < -0.9549925859) {
|
||||
wasNegClipL = true;
|
||||
inputSampleL = -0.7058208 + (lastSampleL * 0.2609148);
|
||||
}
|
||||
intermediateL[spacing] = inputSampleL;
|
||||
inputSampleL = lastSampleL; //Latency is however many samples equals one 44.1k sample
|
||||
for (int x = spacing; x > 0; x--) intermediateL[x-1] = intermediateL[x];
|
||||
lastSampleL = intermediateL[0]; //run a little buffer to handle this
|
||||
inputSampleL = lastSampleL; // Latency is however many samples equals one 44.1k sample
|
||||
for (int x = spacing; x > 0; x--) intermediateL[x - 1] = intermediateL[x];
|
||||
lastSampleL = intermediateL[0]; // run a little buffer to handle this
|
||||
|
||||
if (inputSampleR > 4.0) inputSampleR = 4.0; if (inputSampleR < -4.0) inputSampleR = -4.0;
|
||||
if (wasPosClipR == true) { //current will be over
|
||||
if (inputSampleR<lastSampleR) lastSampleR=0.7058208+(inputSampleR*0.2609148);
|
||||
else lastSampleR = 0.2491717+(lastSampleR*0.7390851);
|
||||
} wasPosClipR = false;
|
||||
if (inputSampleR>0.9549925859) {wasPosClipR=true;inputSampleR=0.7058208+(lastSampleR*0.2609148);}
|
||||
if (wasNegClipR == true) { //current will be -over
|
||||
if (inputSampleR > lastSampleR) lastSampleR=-0.7058208+(inputSampleR*0.2609148);
|
||||
else lastSampleR=-0.2491717+(lastSampleR*0.7390851);
|
||||
} wasNegClipR = false;
|
||||
if (inputSampleR<-0.9549925859) {wasNegClipR=true;inputSampleR=-0.7058208+(lastSampleR*0.2609148);}
|
||||
if (inputSampleR > 4.0) inputSampleR = 4.0;
|
||||
if (inputSampleR < -4.0) inputSampleR = -4.0;
|
||||
if (wasPosClipR == true) { // current will be over
|
||||
if (inputSampleR < lastSampleR) lastSampleR = 0.7058208 + (inputSampleR * 0.2609148);
|
||||
else lastSampleR = 0.2491717 + (lastSampleR * 0.7390851);
|
||||
}
|
||||
wasPosClipR = false;
|
||||
if (inputSampleR > 0.9549925859) {
|
||||
wasPosClipR = true;
|
||||
inputSampleR = 0.7058208 + (lastSampleR * 0.2609148);
|
||||
}
|
||||
if (wasNegClipR == true) { // current will be -over
|
||||
if (inputSampleR > lastSampleR) lastSampleR = -0.7058208 + (inputSampleR * 0.2609148);
|
||||
else lastSampleR = -0.2491717 + (lastSampleR * 0.7390851);
|
||||
}
|
||||
wasNegClipR = false;
|
||||
if (inputSampleR < -0.9549925859) {
|
||||
wasNegClipR = true;
|
||||
inputSampleR = -0.7058208 + (lastSampleR * 0.2609148);
|
||||
}
|
||||
intermediateR[spacing] = inputSampleR;
|
||||
inputSampleR = lastSampleR; //Latency is however many samples equals one 44.1k sample
|
||||
for (int x = spacing; x > 0; x--) intermediateR[x-1] = intermediateR[x];
|
||||
lastSampleR = intermediateR[0]; //run a little buffer to handle this
|
||||
//end ClipOnly2 stereo as a little, compressed chunk that can be dropped into code
|
||||
inputSampleR = lastSampleR; // Latency is however many samples equals one 44.1k sample
|
||||
for (int x = spacing; x > 0; x--) intermediateR[x - 1] = intermediateR[x];
|
||||
lastSampleR = intermediateR[0]; // run a little buffer to handle this
|
||||
// end ClipOnly2 stereo as a little, compressed chunk that can be dropped into code
|
||||
|
||||
if (wet<1.0) {
|
||||
inputSampleL = (drySampleL*(1.0-wet))+(inputSampleL*wet);
|
||||
inputSampleR = (drySampleR*(1.0-wet))+(inputSampleR*wet);
|
||||
if (wet < 1.0) {
|
||||
inputSampleL = (drySampleL * (1.0 - wet)) + (inputSampleL * wet);
|
||||
inputSampleR = (drySampleR * (1.0 - wet)) + (inputSampleR * wet);
|
||||
}
|
||||
|
||||
//begin 64 bit stereo floating point dither
|
||||
//int expon; frexp((double)inputSampleL, &expon);
|
||||
fpdL ^= fpdL << 13; fpdL ^= fpdL >> 17; fpdL ^= fpdL << 5;
|
||||
//inputSampleL += ((double(fpdL)-uint32_t(0x7fffffff)) * 1.1e-44l * pow(2,expon+62));
|
||||
//frexp((double)inputSampleR, &expon);
|
||||
fpdR ^= fpdR << 13; fpdR ^= fpdR >> 17; fpdR ^= fpdR << 5;
|
||||
//inputSampleR += ((double(fpdR)-uint32_t(0x7fffffff)) * 1.1e-44l * pow(2,expon+62));
|
||||
//end 64 bit stereo floating point dither
|
||||
// begin 64 bit stereo floating point dither
|
||||
// int expon; frexp((double)inputSampleL, &expon);
|
||||
fpdL ^= fpdL << 13;
|
||||
fpdL ^= fpdL >> 17;
|
||||
fpdL ^= fpdL << 5;
|
||||
// inputSampleL += ((double(fpdL)-uint32_t(0x7fffffff)) * 1.1e-44l * pow(2,expon+62));
|
||||
// frexp((double)inputSampleR, &expon);
|
||||
fpdR ^= fpdR << 13;
|
||||
fpdR ^= fpdR >> 17;
|
||||
fpdR ^= fpdR << 5;
|
||||
// inputSampleR += ((double(fpdR)-uint32_t(0x7fffffff)) * 1.1e-44l * pow(2,expon+62));
|
||||
// end 64 bit stereo floating point dither
|
||||
|
||||
*out1 = inputSampleL;
|
||||
*out2 = inputSampleR;
|
||||
@@ -265,7 +283,7 @@ private:
|
||||
|
||||
uint32_t fpdL;
|
||||
uint32_t fpdR;
|
||||
//default stuff
|
||||
// default stuff
|
||||
|
||||
double muVaryL;
|
||||
double muAttackL;
|
||||
@@ -292,15 +310,16 @@ private:
|
||||
double lastSampleR;
|
||||
double intermediateR[16];
|
||||
bool wasPosClipR;
|
||||
bool wasNegClipR; //Stereo ClipOnly2
|
||||
bool wasNegClipR; // Stereo ClipOnly2
|
||||
|
||||
float A;
|
||||
float B;
|
||||
float C;
|
||||
float D;
|
||||
float E; //parameters. Always 0-1, and we scale/alter them elsewhere.
|
||||
float E; // parameters. Always 0-1, and we scale/alter them elsewhere.
|
||||
|
||||
double clamp(double& value) {
|
||||
double clamp(double& value)
|
||||
{
|
||||
if (value > 1) {
|
||||
value = 1;
|
||||
} else if (value < 0) {
|
||||
@@ -309,4 +328,4 @@ private:
|
||||
return value;
|
||||
}
|
||||
};
|
||||
}
|
||||
} // namespace trnr
|
||||
302
filter/aw_eq.h
302
filter/aw_eq.h
@@ -6,17 +6,18 @@ namespace trnr {
|
||||
// 3 band equalizer with high/lowpass filters based on EQ by Chris Johnson.
|
||||
class aw_eq {
|
||||
public:
|
||||
aw_eq() {
|
||||
aw_eq()
|
||||
{
|
||||
samplerate = 44100;
|
||||
|
||||
A = 0.5; //Treble -12 to 12
|
||||
B = 0.5; //Mid -12 to 12
|
||||
C = 0.5; //Bass -12 to 12
|
||||
D = 1.0; //Lowpass 16.0K log 1 to 16 defaulting to 16K
|
||||
E = 0.4; //TrebFrq 6.0 log 1 to 16 defaulting to 6K
|
||||
F = 0.4; //BassFrq 100.0 log 30 to 1600 defaulting to 100 hz
|
||||
G = 0.0; //Hipass 30.0 log 30 to 1600 defaulting to 30
|
||||
H = 0.5; //OutGain -18 to 18
|
||||
A = 0.5; // Treble -12 to 12
|
||||
B = 0.5; // Mid -12 to 12
|
||||
C = 0.5; // Bass -12 to 12
|
||||
D = 1.0; // Lowpass 16.0K log 1 to 16 defaulting to 16K
|
||||
E = 0.4; // TrebFrq 6.0 log 1 to 16 defaulting to 6K
|
||||
F = 0.4; // BassFrq 100.0 log 30 to 1600 defaulting to 100 hz
|
||||
G = 0.0; // Hipass 30.0 log 30 to 1600 defaulting to 30
|
||||
H = 0.5; // OutGain -18 to 18
|
||||
|
||||
lastSampleL = 0.0;
|
||||
last2SampleL = 0.0;
|
||||
@@ -108,48 +109,33 @@ public:
|
||||
flip = false;
|
||||
flipthree = 0;
|
||||
|
||||
fpdL = 1.0; while (fpdL < 16386) fpdL = rand()*UINT32_MAX;
|
||||
fpdR = 1.0; while (fpdR < 16386) fpdR = rand()*UINT32_MAX;
|
||||
//this is reset: values being initialized only once. Startup values, whatever they are.
|
||||
fpdL = 1.0;
|
||||
while (fpdL < 16386) fpdL = rand() * UINT32_MAX;
|
||||
fpdR = 1.0;
|
||||
while (fpdR < 16386) fpdR = rand() * UINT32_MAX;
|
||||
// this is reset: values being initialized only once. Startup values, whatever they are.
|
||||
}
|
||||
|
||||
void set_treble(double value) {
|
||||
A = clamp(value);
|
||||
}
|
||||
void set_treble(double value) { A = clamp(value); }
|
||||
|
||||
void set_mid(double value) {
|
||||
B = clamp(value);
|
||||
}
|
||||
void set_mid(double value) { B = clamp(value); }
|
||||
|
||||
void set_bass(double value) {
|
||||
C = clamp(value);
|
||||
}
|
||||
void set_bass(double value) { C = clamp(value); }
|
||||
|
||||
void set_lowpass(double value) {
|
||||
D = clamp(value);
|
||||
}
|
||||
void set_lowpass(double value) { D = clamp(value); }
|
||||
|
||||
void set_treble_frq(double value) {
|
||||
E = clamp(value);
|
||||
}
|
||||
void set_treble_frq(double value) { E = clamp(value); }
|
||||
|
||||
void set_bass_frq(double value) {
|
||||
F = clamp(value);
|
||||
}
|
||||
void set_bass_frq(double value) { F = clamp(value); }
|
||||
|
||||
void set_hipass(double value) {
|
||||
G = clamp(value);
|
||||
}
|
||||
void set_hipass(double value) { G = clamp(value); }
|
||||
|
||||
void set_out_gain(double value) {
|
||||
H = clamp(value);
|
||||
}
|
||||
void set_out_gain(double value) { H = clamp(value); }
|
||||
|
||||
void set_samplerate(double _samplerate) {
|
||||
samplerate = _samplerate;
|
||||
}
|
||||
void set_samplerate(double _samplerate) { samplerate = _samplerate; }
|
||||
|
||||
void process_block(double **inputs, double **outputs, long sampleframes) {
|
||||
void process_block(double** inputs, double** outputs, long sampleframes)
|
||||
{
|
||||
|
||||
double* in1 = inputs[0];
|
||||
double* in2 = inputs[1];
|
||||
@@ -161,7 +147,7 @@ public:
|
||||
double compscale = overallscale;
|
||||
overallscale = samplerate;
|
||||
compscale = compscale * overallscale;
|
||||
//compscale is the one that's 1 or something like 2.2 for 96K rates
|
||||
// compscale is the one that's 1 or something like 2.2 for 96K rates
|
||||
|
||||
double inputSampleL;
|
||||
double inputSampleR;
|
||||
@@ -174,45 +160,44 @@ public:
|
||||
double midSampleR = 0.0;
|
||||
double bassSampleR = 0.0;
|
||||
|
||||
double densityA = (A*12.0)-6.0;
|
||||
double densityB = (B*12.0)-6.0;
|
||||
double densityC = (C*12.0)-6.0;
|
||||
double densityA = (A * 12.0) - 6.0;
|
||||
double densityB = (B * 12.0) - 6.0;
|
||||
double densityC = (C * 12.0) - 6.0;
|
||||
bool engageEQ = true;
|
||||
if ( (0.0 == densityA) && (0.0 == densityB) && (0.0 == densityC) ) engageEQ = false;
|
||||
if ((0.0 == densityA) && (0.0 == densityB) && (0.0 == densityC)) engageEQ = false;
|
||||
|
||||
densityA = pow(10.0,densityA/20.0)-1.0;
|
||||
densityB = pow(10.0,densityB/20.0)-1.0;
|
||||
densityC = pow(10.0,densityC/20.0)-1.0;
|
||||
//convert to 0 to X multiplier with 1.0 being O db
|
||||
//minus one gives nearly -1 to ? (should top out at 1)
|
||||
//calibrate so that X db roughly equals X db with maximum topping out at 1 internally
|
||||
densityA = pow(10.0, densityA / 20.0) - 1.0;
|
||||
densityB = pow(10.0, densityB / 20.0) - 1.0;
|
||||
densityC = pow(10.0, densityC / 20.0) - 1.0;
|
||||
// convert to 0 to X multiplier with 1.0 being O db
|
||||
// minus one gives nearly -1 to ? (should top out at 1)
|
||||
// calibrate so that X db roughly equals X db with maximum topping out at 1 internally
|
||||
|
||||
double tripletIntensity = -densityA;
|
||||
|
||||
double iirAmountC = (((D*D*15.0)+1.0)*0.0188) + 0.7;
|
||||
double iirAmountC = (((D * D * 15.0) + 1.0) * 0.0188) + 0.7;
|
||||
if (iirAmountC > 1.0) iirAmountC = 1.0;
|
||||
bool engageLowpass = false;
|
||||
if (((D*D*15.0)+1.0) < 15.99) engageLowpass = true;
|
||||
if (((D * D * 15.0) + 1.0) < 15.99) engageLowpass = true;
|
||||
|
||||
double iirAmountA = (((E*E*15.0)+1.0)*1000)/overallscale;
|
||||
double iirAmountB = (((F*F*1570.0)+30.0)*10)/overallscale;
|
||||
double iirAmountD = (((G*G*1570.0)+30.0)*1.0)/overallscale;
|
||||
double iirAmountA = (((E * E * 15.0) + 1.0) * 1000) / overallscale;
|
||||
double iirAmountB = (((F * F * 1570.0) + 30.0) * 10) / overallscale;
|
||||
double iirAmountD = (((G * G * 1570.0) + 30.0) * 1.0) / overallscale;
|
||||
bool engageHighpass = false;
|
||||
if (((G*G*1570.0)+30.0) > 30.01) engageHighpass = true;
|
||||
//bypass the highpass and lowpass if set to extremes
|
||||
if (((G * G * 1570.0) + 30.0) > 30.01) engageHighpass = true;
|
||||
// bypass the highpass and lowpass if set to extremes
|
||||
double bridgerectifier;
|
||||
double outA = fabs(densityA);
|
||||
double outB = fabs(densityB);
|
||||
double outC = fabs(densityC);
|
||||
//end EQ
|
||||
double outputgain = pow(10.0,((H*36.0)-18.0)/20.0);
|
||||
// end EQ
|
||||
double outputgain = pow(10.0, ((H * 36.0) - 18.0) / 20.0);
|
||||
|
||||
while (--sampleframes >= 0)
|
||||
{
|
||||
while (--sampleframes >= 0) {
|
||||
inputSampleL = *in1;
|
||||
inputSampleR = *in2;
|
||||
if (fabs(inputSampleL)<1.18e-23) inputSampleL = fpdL * 1.18e-17;
|
||||
if (fabs(inputSampleR)<1.18e-23) inputSampleR = fpdR * 1.18e-17;
|
||||
if (fabs(inputSampleL) < 1.18e-23) inputSampleL = fpdL * 1.18e-17;
|
||||
if (fabs(inputSampleR) < 1.18e-23) inputSampleR = fpdR * 1.18e-17;
|
||||
|
||||
last2SampleL = lastSampleL;
|
||||
lastSampleL = inputSampleL;
|
||||
@@ -223,13 +208,11 @@ public:
|
||||
flip = !flip;
|
||||
flipthree++;
|
||||
if (flipthree < 1 || flipthree > 3) flipthree = 1;
|
||||
//counters
|
||||
// counters
|
||||
|
||||
//begin highpass
|
||||
if (engageHighpass)
|
||||
{
|
||||
if (flip)
|
||||
{
|
||||
// begin highpass
|
||||
if (engageHighpass) {
|
||||
if (flip) {
|
||||
highpassSampleLAA = (highpassSampleLAA * (1.0 - iirAmountD)) + (inputSampleL * iirAmountD);
|
||||
inputSampleL -= highpassSampleLAA;
|
||||
highpassSampleLBA = (highpassSampleLBA * (1.0 - iirAmountD)) + (inputSampleL * iirAmountD);
|
||||
@@ -238,9 +221,7 @@ public:
|
||||
inputSampleL -= highpassSampleLCA;
|
||||
highpassSampleLDA = (highpassSampleLDA * (1.0 - iirAmountD)) + (inputSampleL * iirAmountD);
|
||||
inputSampleL -= highpassSampleLDA;
|
||||
}
|
||||
else
|
||||
{
|
||||
} else {
|
||||
highpassSampleLAB = (highpassSampleLAB * (1.0 - iirAmountD)) + (inputSampleL * iirAmountD);
|
||||
inputSampleL -= highpassSampleLAB;
|
||||
highpassSampleLBB = (highpassSampleLBB * (1.0 - iirAmountD)) + (inputSampleL * iirAmountD);
|
||||
@@ -255,8 +236,7 @@ public:
|
||||
highpassSampleLF = (highpassSampleLF * (1.0 - iirAmountD)) + (inputSampleL * iirAmountD);
|
||||
inputSampleL -= highpassSampleLF;
|
||||
|
||||
if (flip)
|
||||
{
|
||||
if (flip) {
|
||||
highpassSampleRAA = (highpassSampleRAA * (1.0 - iirAmountD)) + (inputSampleR * iirAmountD);
|
||||
inputSampleR -= highpassSampleRAA;
|
||||
highpassSampleRBA = (highpassSampleRBA * (1.0 - iirAmountD)) + (inputSampleR * iirAmountD);
|
||||
@@ -265,9 +245,7 @@ public:
|
||||
inputSampleR -= highpassSampleRCA;
|
||||
highpassSampleRDA = (highpassSampleRDA * (1.0 - iirAmountD)) + (inputSampleR * iirAmountD);
|
||||
inputSampleR -= highpassSampleRDA;
|
||||
}
|
||||
else
|
||||
{
|
||||
} else {
|
||||
highpassSampleRAB = (highpassSampleRAB * (1.0 - iirAmountD)) + (inputSampleR * iirAmountD);
|
||||
inputSampleR -= highpassSampleRAB;
|
||||
highpassSampleRBB = (highpassSampleRBB * (1.0 - iirAmountD)) + (inputSampleR * iirAmountD);
|
||||
@@ -281,15 +259,12 @@ public:
|
||||
inputSampleR -= highpassSampleRE;
|
||||
highpassSampleRF = (highpassSampleRF * (1 - iirAmountD)) + (inputSampleR * iirAmountD);
|
||||
inputSampleR -= highpassSampleRF;
|
||||
|
||||
}
|
||||
//end highpass
|
||||
// end highpass
|
||||
|
||||
//begin EQ
|
||||
if (engageEQ)
|
||||
{
|
||||
switch (flipthree)
|
||||
{
|
||||
// begin EQ
|
||||
if (engageEQ) {
|
||||
switch (flipthree) {
|
||||
case 1:
|
||||
tripletFactorL = last2SampleL - inputSampleL;
|
||||
tripletLA += tripletFactorL;
|
||||
@@ -358,8 +333,7 @@ public:
|
||||
tripletRC /= 2.0;
|
||||
highSampleR = highSampleR + tripletFactorR;
|
||||
|
||||
if (flip)
|
||||
{
|
||||
if (flip) {
|
||||
iirHighSampleLA = (iirHighSampleLA * (1.0 - iirAmountA)) + (highSampleL * iirAmountA);
|
||||
highSampleL -= iirHighSampleLA;
|
||||
iirLowSampleLA = (iirLowSampleLA * (1.0 - iirAmountB)) + (bassSampleL * iirAmountB);
|
||||
@@ -369,9 +343,7 @@ public:
|
||||
highSampleR -= iirHighSampleRA;
|
||||
iirLowSampleRA = (iirLowSampleRA * (1.0 - iirAmountB)) + (bassSampleR * iirAmountB);
|
||||
bassSampleR = iirLowSampleRA;
|
||||
}
|
||||
else
|
||||
{
|
||||
} else {
|
||||
iirHighSampleLB = (iirHighSampleLB * (1.0 - iirAmountA)) + (highSampleL * iirAmountA);
|
||||
highSampleL -= iirHighSampleLB;
|
||||
iirLowSampleLB = (iirLowSampleLB * (1.0 - iirAmountB)) + (bassSampleL * iirAmountB);
|
||||
@@ -393,75 +365,75 @@ public:
|
||||
iirLowSampleR = (iirLowSampleR * (1.0 - iirAmountB)) + (bassSampleR * iirAmountB);
|
||||
bassSampleR = iirLowSampleR;
|
||||
|
||||
midSampleL = (inputSampleL-bassSampleL)-highSampleL;
|
||||
midSampleR = (inputSampleR-bassSampleR)-highSampleR;
|
||||
midSampleL = (inputSampleL - bassSampleL) - highSampleL;
|
||||
midSampleR = (inputSampleR - bassSampleR) - highSampleR;
|
||||
|
||||
//drive section
|
||||
highSampleL *= (densityA+1.0);
|
||||
bridgerectifier = fabs(highSampleL)*1.57079633;
|
||||
// drive section
|
||||
highSampleL *= (densityA + 1.0);
|
||||
bridgerectifier = fabs(highSampleL) * 1.57079633;
|
||||
if (bridgerectifier > 1.57079633) bridgerectifier = 1.57079633;
|
||||
//max value for sine function
|
||||
// max value for sine function
|
||||
if (densityA > 0) bridgerectifier = sin(bridgerectifier);
|
||||
else bridgerectifier = 1-cos(bridgerectifier);
|
||||
//produce either boosted or starved version
|
||||
if (highSampleL > 0) highSampleL = (highSampleL*(1-outA))+(bridgerectifier*outA);
|
||||
else highSampleL = (highSampleL*(1-outA))-(bridgerectifier*outA);
|
||||
//blend according to densityA control
|
||||
else bridgerectifier = 1 - cos(bridgerectifier);
|
||||
// produce either boosted or starved version
|
||||
if (highSampleL > 0) highSampleL = (highSampleL * (1 - outA)) + (bridgerectifier * outA);
|
||||
else highSampleL = (highSampleL * (1 - outA)) - (bridgerectifier * outA);
|
||||
// blend according to densityA control
|
||||
|
||||
highSampleR *= (densityA+1.0);
|
||||
bridgerectifier = fabs(highSampleR)*1.57079633;
|
||||
highSampleR *= (densityA + 1.0);
|
||||
bridgerectifier = fabs(highSampleR) * 1.57079633;
|
||||
if (bridgerectifier > 1.57079633) bridgerectifier = 1.57079633;
|
||||
//max value for sine function
|
||||
// max value for sine function
|
||||
if (densityA > 0) bridgerectifier = sin(bridgerectifier);
|
||||
else bridgerectifier = 1-cos(bridgerectifier);
|
||||
//produce either boosted or starved version
|
||||
if (highSampleR > 0) highSampleR = (highSampleR*(1-outA))+(bridgerectifier*outA);
|
||||
else highSampleR = (highSampleR*(1-outA))-(bridgerectifier*outA);
|
||||
//blend according to densityA control
|
||||
else bridgerectifier = 1 - cos(bridgerectifier);
|
||||
// produce either boosted or starved version
|
||||
if (highSampleR > 0) highSampleR = (highSampleR * (1 - outA)) + (bridgerectifier * outA);
|
||||
else highSampleR = (highSampleR * (1 - outA)) - (bridgerectifier * outA);
|
||||
// blend according to densityA control
|
||||
|
||||
midSampleL *= (densityB+1.0);
|
||||
bridgerectifier = fabs(midSampleL)*1.57079633;
|
||||
midSampleL *= (densityB + 1.0);
|
||||
bridgerectifier = fabs(midSampleL) * 1.57079633;
|
||||
if (bridgerectifier > 1.57079633) bridgerectifier = 1.57079633;
|
||||
//max value for sine function
|
||||
// max value for sine function
|
||||
if (densityB > 0) bridgerectifier = sin(bridgerectifier);
|
||||
else bridgerectifier = 1-cos(bridgerectifier);
|
||||
//produce either boosted or starved version
|
||||
if (midSampleL > 0) midSampleL = (midSampleL*(1-outB))+(bridgerectifier*outB);
|
||||
else midSampleL = (midSampleL*(1-outB))-(bridgerectifier*outB);
|
||||
//blend according to densityB control
|
||||
else bridgerectifier = 1 - cos(bridgerectifier);
|
||||
// produce either boosted or starved version
|
||||
if (midSampleL > 0) midSampleL = (midSampleL * (1 - outB)) + (bridgerectifier * outB);
|
||||
else midSampleL = (midSampleL * (1 - outB)) - (bridgerectifier * outB);
|
||||
// blend according to densityB control
|
||||
|
||||
midSampleR *= (densityB+1.0);
|
||||
bridgerectifier = fabs(midSampleR)*1.57079633;
|
||||
midSampleR *= (densityB + 1.0);
|
||||
bridgerectifier = fabs(midSampleR) * 1.57079633;
|
||||
if (bridgerectifier > 1.57079633) bridgerectifier = 1.57079633;
|
||||
//max value for sine function
|
||||
// max value for sine function
|
||||
if (densityB > 0) bridgerectifier = sin(bridgerectifier);
|
||||
else bridgerectifier = 1-cos(bridgerectifier);
|
||||
//produce either boosted or starved version
|
||||
if (midSampleR > 0) midSampleR = (midSampleR*(1-outB))+(bridgerectifier*outB);
|
||||
else midSampleR = (midSampleR*(1-outB))-(bridgerectifier*outB);
|
||||
//blend according to densityB control
|
||||
else bridgerectifier = 1 - cos(bridgerectifier);
|
||||
// produce either boosted or starved version
|
||||
if (midSampleR > 0) midSampleR = (midSampleR * (1 - outB)) + (bridgerectifier * outB);
|
||||
else midSampleR = (midSampleR * (1 - outB)) - (bridgerectifier * outB);
|
||||
// blend according to densityB control
|
||||
|
||||
bassSampleL *= (densityC+1.0);
|
||||
bridgerectifier = fabs(bassSampleL)*1.57079633;
|
||||
bassSampleL *= (densityC + 1.0);
|
||||
bridgerectifier = fabs(bassSampleL) * 1.57079633;
|
||||
if (bridgerectifier > 1.57079633) bridgerectifier = 1.57079633;
|
||||
//max value for sine function
|
||||
// max value for sine function
|
||||
if (densityC > 0) bridgerectifier = sin(bridgerectifier);
|
||||
else bridgerectifier = 1-cos(bridgerectifier);
|
||||
//produce either boosted or starved version
|
||||
if (bassSampleL > 0) bassSampleL = (bassSampleL*(1-outC))+(bridgerectifier*outC);
|
||||
else bassSampleL = (bassSampleL*(1-outC))-(bridgerectifier*outC);
|
||||
//blend according to densityC control
|
||||
else bridgerectifier = 1 - cos(bridgerectifier);
|
||||
// produce either boosted or starved version
|
||||
if (bassSampleL > 0) bassSampleL = (bassSampleL * (1 - outC)) + (bridgerectifier * outC);
|
||||
else bassSampleL = (bassSampleL * (1 - outC)) - (bridgerectifier * outC);
|
||||
// blend according to densityC control
|
||||
|
||||
bassSampleR *= (densityC+1.0);
|
||||
bridgerectifier = fabs(bassSampleR)*1.57079633;
|
||||
bassSampleR *= (densityC + 1.0);
|
||||
bridgerectifier = fabs(bassSampleR) * 1.57079633;
|
||||
if (bridgerectifier > 1.57079633) bridgerectifier = 1.57079633;
|
||||
//max value for sine function
|
||||
// max value for sine function
|
||||
if (densityC > 0) bridgerectifier = sin(bridgerectifier);
|
||||
else bridgerectifier = 1-cos(bridgerectifier);
|
||||
//produce either boosted or starved version
|
||||
if (bassSampleR > 0) bassSampleR = (bassSampleR*(1-outC))+(bridgerectifier*outC);
|
||||
else bassSampleR = (bassSampleR*(1-outC))-(bridgerectifier*outC);
|
||||
//blend according to densityC control
|
||||
else bridgerectifier = 1 - cos(bridgerectifier);
|
||||
// produce either boosted or starved version
|
||||
if (bassSampleR > 0) bassSampleR = (bassSampleR * (1 - outC)) + (bridgerectifier * outC);
|
||||
else bassSampleR = (bassSampleR * (1 - outC)) - (bridgerectifier * outC);
|
||||
// blend according to densityC control
|
||||
|
||||
inputSampleL = midSampleL;
|
||||
inputSampleL += highSampleL;
|
||||
@@ -471,13 +443,11 @@ public:
|
||||
inputSampleR += highSampleR;
|
||||
inputSampleR += bassSampleR;
|
||||
}
|
||||
//end EQ
|
||||
// end EQ
|
||||
|
||||
//EQ lowpass is after all processing like the compressor that might produce hash
|
||||
if (engageLowpass)
|
||||
{
|
||||
if (flip)
|
||||
{
|
||||
// EQ lowpass is after all processing like the compressor that might produce hash
|
||||
if (engageLowpass) {
|
||||
if (flip) {
|
||||
lowpassSampleLAA = (lowpassSampleLAA * (1.0 - iirAmountC)) + (inputSampleL * iirAmountC);
|
||||
inputSampleL = lowpassSampleLAA;
|
||||
lowpassSampleLBA = (lowpassSampleLBA * (1.0 - iirAmountC)) + (inputSampleL * iirAmountC);
|
||||
@@ -499,9 +469,7 @@ public:
|
||||
inputSampleR = lowpassSampleRDA;
|
||||
lowpassSampleRE = (lowpassSampleRE * (1.0 - iirAmountC)) + (inputSampleR * iirAmountC);
|
||||
inputSampleR = lowpassSampleRE;
|
||||
}
|
||||
else
|
||||
{
|
||||
} else {
|
||||
lowpassSampleLAB = (lowpassSampleLAB * (1.0 - iirAmountC)) + (inputSampleL * iirAmountC);
|
||||
inputSampleL = lowpassSampleLAB;
|
||||
lowpassSampleLBB = (lowpassSampleLBB * (1.0 - iirAmountC)) + (inputSampleL * iirAmountC);
|
||||
@@ -531,20 +499,24 @@ public:
|
||||
inputSampleR = (lowpassSampleRG * (1.0 - iirAmountC)) + (inputSampleR * iirAmountC);
|
||||
}
|
||||
|
||||
//built in output trim and dry/wet if desired
|
||||
// built in output trim and dry/wet if desired
|
||||
if (outputgain != 1.0) {
|
||||
inputSampleL *= outputgain;
|
||||
inputSampleR *= outputgain;
|
||||
}
|
||||
|
||||
//begin 64 bit stereo floating point dither
|
||||
//int expon; frexp((double)inputSampleL, &expon);
|
||||
fpdL ^= fpdL << 13; fpdL ^= fpdL >> 17; fpdL ^= fpdL << 5;
|
||||
//inputSampleL += ((double(fpdL)-uint32_t(0x7fffffff)) * 1.1e-44l * pow(2,expon+62));
|
||||
//frexp((double)inputSampleR, &expon);
|
||||
fpdR ^= fpdR << 13; fpdR ^= fpdR >> 17; fpdR ^= fpdR << 5;
|
||||
//inputSampleR += ((double(fpdR)-uint32_t(0x7fffffff)) * 1.1e-44l * pow(2,expon+62));
|
||||
//end 64 bit stereo floating point dither
|
||||
// begin 64 bit stereo floating point dither
|
||||
// int expon; frexp((double)inputSampleL, &expon);
|
||||
fpdL ^= fpdL << 13;
|
||||
fpdL ^= fpdL >> 17;
|
||||
fpdL ^= fpdL << 5;
|
||||
// inputSampleL += ((double(fpdL)-uint32_t(0x7fffffff)) * 1.1e-44l * pow(2,expon+62));
|
||||
// frexp((double)inputSampleR, &expon);
|
||||
fpdR ^= fpdR << 13;
|
||||
fpdR ^= fpdR >> 17;
|
||||
fpdR ^= fpdR << 5;
|
||||
// inputSampleR += ((double(fpdR)-uint32_t(0x7fffffff)) * 1.1e-44l * pow(2,expon+62));
|
||||
// end 64 bit stereo floating point dither
|
||||
|
||||
*out1 = inputSampleL;
|
||||
*out2 = inputSampleR;
|
||||
@@ -561,14 +533,14 @@ private:
|
||||
|
||||
uint32_t fpdL;
|
||||
uint32_t fpdR;
|
||||
//default stuff
|
||||
// default stuff
|
||||
|
||||
double lastSampleL;
|
||||
double last2SampleL;
|
||||
double lastSampleR;
|
||||
double last2SampleR;
|
||||
|
||||
//begin EQ
|
||||
// begin EQ
|
||||
double iirHighSampleLA;
|
||||
double iirHighSampleLB;
|
||||
double iirHighSampleLC;
|
||||
@@ -653,8 +625,7 @@ private:
|
||||
|
||||
bool flip;
|
||||
int flipthree;
|
||||
//end EQ
|
||||
|
||||
// end EQ
|
||||
|
||||
float A;
|
||||
float B;
|
||||
@@ -665,7 +636,8 @@ private:
|
||||
float G;
|
||||
float H;
|
||||
|
||||
double clamp(double& value) {
|
||||
double clamp(double& value)
|
||||
{
|
||||
if (value > 1) {
|
||||
value = 1;
|
||||
} else if (value < 0) {
|
||||
@@ -674,4 +646,4 @@ private:
|
||||
return value;
|
||||
}
|
||||
};
|
||||
}
|
||||
} // namespace trnr
|
||||
@@ -1,20 +1,17 @@
|
||||
#pragma once
|
||||
#define _USE_MATH_DEFINES
|
||||
#include <math.h>
|
||||
#include <array>
|
||||
#include <math.h>
|
||||
|
||||
namespace trnr {
|
||||
class chebyshev {
|
||||
public:
|
||||
void set_samplerate(double _samplerate) {
|
||||
samplerate = _samplerate;
|
||||
}
|
||||
void set_samplerate(double _samplerate) { samplerate = _samplerate; }
|
||||
|
||||
void process_sample(double& input, double frequency) {
|
||||
void process_sample(double& input, double frequency)
|
||||
{
|
||||
|
||||
if (frequency >= 20000.f) {
|
||||
frequency = 20000.f;
|
||||
}
|
||||
if (frequency >= 20000.f) { frequency = 20000.f; }
|
||||
|
||||
// First calculate the prewarped digital frequency :
|
||||
auto K = tanf(M_PI * frequency / samplerate);
|
||||
@@ -77,4 +74,4 @@ private:
|
||||
double state3 = 0;
|
||||
double passband_ripple = 1;
|
||||
};
|
||||
}
|
||||
} // namespace trnr
|
||||
@@ -1,7 +1,7 @@
|
||||
#pragma once
|
||||
#define _USE_MATH_DEFINES
|
||||
#include <math.h>
|
||||
#include <array>
|
||||
#include <math.h>
|
||||
#include <vector>
|
||||
|
||||
namespace trnr {
|
||||
@@ -10,20 +10,18 @@ template <typename t_sample>
|
||||
class ybandpass {
|
||||
public:
|
||||
ybandpass(double _samplerate)
|
||||
: samplerate { _samplerate }
|
||||
, A { 0.1f }
|
||||
, B { 1.0f }
|
||||
, C { 0.0f }
|
||||
, D { 0.1f }
|
||||
, E { 0.9f }
|
||||
, F { 1.0f }
|
||||
, fpdL { 0 }
|
||||
, fpdR { 0 }
|
||||
, biquad { 0 }
|
||||
: samplerate {_samplerate}
|
||||
, A {0.1f}
|
||||
, B {1.0f}
|
||||
, C {0.0f}
|
||||
, D {0.1f}
|
||||
, E {0.9f}
|
||||
, F {1.0f}
|
||||
, fpdL {0}
|
||||
, fpdR {0}
|
||||
, biquad {0}
|
||||
{
|
||||
for (int x = 0; x < biq_total; x++) {
|
||||
biquad[x] = 0.0;
|
||||
}
|
||||
for (int x = 0; x < biq_total; x++) { biquad[x] = 0.0; }
|
||||
powFactorA = 1.0;
|
||||
powFactorB = 1.0;
|
||||
inTrimA = 0.1;
|
||||
@@ -36,41 +34,25 @@ public:
|
||||
}
|
||||
|
||||
fpdL = 1.0;
|
||||
while (fpdL < 16386)
|
||||
fpdL = rand() * UINT32_MAX;
|
||||
while (fpdL < 16386) fpdL = rand() * UINT32_MAX;
|
||||
fpdR = 1.0;
|
||||
while (fpdR < 16386)
|
||||
fpdR = rand() * UINT32_MAX;
|
||||
while (fpdR < 16386) fpdR = rand() * UINT32_MAX;
|
||||
}
|
||||
|
||||
void set_samplerate(double _samplerate) {
|
||||
samplerate = _samplerate;
|
||||
}
|
||||
void set_samplerate(double _samplerate) { samplerate = _samplerate; }
|
||||
|
||||
void set_drive(float value) { A = value * 0.9 + 0.1; }
|
||||
|
||||
void set_frequency(float value) { B = value; }
|
||||
|
||||
void set_resonance(float value) { C = value; }
|
||||
|
||||
void set_edge(float value) { D = value; }
|
||||
|
||||
void set_output(float value) { E = value; }
|
||||
|
||||
void set_mix(float value) { F = value; }
|
||||
|
||||
void set_drive(float value)
|
||||
{
|
||||
A = value * 0.9 + 0.1;
|
||||
}
|
||||
void set_frequency(float value)
|
||||
{
|
||||
B = value;
|
||||
}
|
||||
void set_resonance(float value)
|
||||
{
|
||||
C = value;
|
||||
}
|
||||
void set_edge(float value)
|
||||
{
|
||||
D = value;
|
||||
}
|
||||
void set_output(float value)
|
||||
{
|
||||
E = value;
|
||||
}
|
||||
void set_mix(float value)
|
||||
{
|
||||
F = value;
|
||||
}
|
||||
void processblock(t_sample** inputs, t_sample** outputs, int blockSize)
|
||||
{
|
||||
t_sample* in1 = inputs[0];
|
||||
@@ -87,8 +69,7 @@ public:
|
||||
inTrimB = A * 10.0;
|
||||
|
||||
biquad[biq_freq] = pow(B, 3) * 20000.0;
|
||||
if (biquad[biq_freq] < 15.0)
|
||||
biquad[biq_freq] = 15.0;
|
||||
if (biquad[biq_freq] < 15.0) biquad[biq_freq] = 15.0;
|
||||
biquad[biq_freq] /= samplerate;
|
||||
biquad[biq_reso] = (pow(C, 2) * 15.0) + 0.5571;
|
||||
biquad[biq_aA0] = biquad[biq_aB0];
|
||||
@@ -132,10 +113,8 @@ public:
|
||||
for (int s = 0; s < blockSize; s++) {
|
||||
double inputSampleL = *in1;
|
||||
double inputSampleR = *in2;
|
||||
if (fabs(inputSampleL) < 1.18e-23)
|
||||
inputSampleL = fpdL * 1.18e-17;
|
||||
if (fabs(inputSampleR) < 1.18e-23)
|
||||
inputSampleR = fpdR * 1.18e-17;
|
||||
if (fabs(inputSampleL) < 1.18e-23) inputSampleL = fpdL * 1.18e-17;
|
||||
if (fabs(inputSampleR) < 1.18e-23) inputSampleR = fpdR * 1.18e-17;
|
||||
double drySampleL = inputSampleL;
|
||||
double drySampleR = inputSampleR;
|
||||
|
||||
@@ -163,22 +142,14 @@ public:
|
||||
inputSampleR = temp; // fixed biquad filtering ultrasonics
|
||||
|
||||
// encode/decode courtesy of torridgristle under the MIT license
|
||||
if (inputSampleL > 1.0)
|
||||
inputSampleL = 1.0;
|
||||
else if (inputSampleL > 0.0)
|
||||
inputSampleL = 1.0 - pow(1.0 - inputSampleL, powFactor);
|
||||
if (inputSampleL < -1.0)
|
||||
inputSampleL = -1.0;
|
||||
else if (inputSampleL < 0.0)
|
||||
inputSampleL = -1.0 + pow(1.0 + inputSampleL, powFactor);
|
||||
if (inputSampleR > 1.0)
|
||||
inputSampleR = 1.0;
|
||||
else if (inputSampleR > 0.0)
|
||||
inputSampleR = 1.0 - pow(1.0 - inputSampleR, powFactor);
|
||||
if (inputSampleR < -1.0)
|
||||
inputSampleR = -1.0;
|
||||
else if (inputSampleR < 0.0)
|
||||
inputSampleR = -1.0 + pow(1.0 + inputSampleR, powFactor);
|
||||
if (inputSampleL > 1.0) inputSampleL = 1.0;
|
||||
else if (inputSampleL > 0.0) inputSampleL = 1.0 - pow(1.0 - inputSampleL, powFactor);
|
||||
if (inputSampleL < -1.0) inputSampleL = -1.0;
|
||||
else if (inputSampleL < 0.0) inputSampleL = -1.0 + pow(1.0 + inputSampleL, powFactor);
|
||||
if (inputSampleR > 1.0) inputSampleR = 1.0;
|
||||
else if (inputSampleR > 0.0) inputSampleR = 1.0 - pow(1.0 - inputSampleR, powFactor);
|
||||
if (inputSampleR < -1.0) inputSampleR = -1.0;
|
||||
else if (inputSampleR < 0.0) inputSampleR = -1.0 + pow(1.0 + inputSampleR, powFactor);
|
||||
|
||||
temp = (inputSampleL * biquad[biq_a0]) + biquad[biq_sL1];
|
||||
biquad[biq_sL1] = -(temp * biquad[biq_b1]) + biquad[biq_sL2];
|
||||
@@ -190,22 +161,14 @@ public:
|
||||
inputSampleR = temp; // coefficient interpolating biquad filter
|
||||
|
||||
// encode/decode courtesy of torridgristle under the MIT license
|
||||
if (inputSampleL > 1.0)
|
||||
inputSampleL = 1.0;
|
||||
else if (inputSampleL > 0.0)
|
||||
inputSampleL = 1.0 - pow(1.0 - inputSampleL, (1.0 / powFactor));
|
||||
if (inputSampleL < -1.0)
|
||||
inputSampleL = -1.0;
|
||||
else if (inputSampleL < 0.0)
|
||||
inputSampleL = -1.0 + pow(1.0 + inputSampleL, (1.0 / powFactor));
|
||||
if (inputSampleR > 1.0)
|
||||
inputSampleR = 1.0;
|
||||
else if (inputSampleR > 0.0)
|
||||
inputSampleR = 1.0 - pow(1.0 - inputSampleR, (1.0 / powFactor));
|
||||
if (inputSampleR < -1.0)
|
||||
inputSampleR = -1.0;
|
||||
else if (inputSampleR < 0.0)
|
||||
inputSampleR = -1.0 + pow(1.0 + inputSampleR, (1.0 / powFactor));
|
||||
if (inputSampleL > 1.0) inputSampleL = 1.0;
|
||||
else if (inputSampleL > 0.0) inputSampleL = 1.0 - pow(1.0 - inputSampleL, (1.0 / powFactor));
|
||||
if (inputSampleL < -1.0) inputSampleL = -1.0;
|
||||
else if (inputSampleL < 0.0) inputSampleL = -1.0 + pow(1.0 + inputSampleL, (1.0 / powFactor));
|
||||
if (inputSampleR > 1.0) inputSampleR = 1.0;
|
||||
else if (inputSampleR > 0.0) inputSampleR = 1.0 - pow(1.0 - inputSampleR, (1.0 / powFactor));
|
||||
if (inputSampleR < -1.0) inputSampleR = -1.0;
|
||||
else if (inputSampleR < 0.0) inputSampleR = -1.0 + pow(1.0 + inputSampleR, (1.0 / powFactor));
|
||||
|
||||
inputSampleL *= outTrim;
|
||||
inputSampleR *= outTrim;
|
||||
@@ -250,6 +213,7 @@ public:
|
||||
|
||||
private:
|
||||
double samplerate;
|
||||
|
||||
enum {
|
||||
biq_freq,
|
||||
biq_reso,
|
||||
@@ -274,6 +238,7 @@ private:
|
||||
biq_sR2,
|
||||
biq_total
|
||||
}; // coefficient interpolating biquad filter, stereo
|
||||
|
||||
std::array<double, biq_total> biquad;
|
||||
|
||||
double powFactorA;
|
||||
@@ -297,6 +262,7 @@ private:
|
||||
fix_sR2,
|
||||
fix_total
|
||||
}; // fixed frequency biquad filter for ultrasonics, stereo
|
||||
|
||||
std::array<double, fix_total> fixA;
|
||||
std::array<double, fix_total> fixB;
|
||||
|
||||
@@ -311,4 +277,4 @@ private:
|
||||
float E;
|
||||
float F; // parameters. Always 0-1, and we scale/alter them elsewhere.
|
||||
};
|
||||
}
|
||||
} // namespace trnr
|
||||
@@ -1,7 +1,7 @@
|
||||
#pragma once
|
||||
#define _USE_MATH_DEFINES
|
||||
#include <math.h>
|
||||
#include <array>
|
||||
#include <math.h>
|
||||
#include <vector>
|
||||
|
||||
namespace trnr {
|
||||
@@ -10,20 +10,18 @@ template <typename t_sample>
|
||||
class yhighpass {
|
||||
public:
|
||||
yhighpass(double _samplerate)
|
||||
: samplerate { _samplerate }
|
||||
, A { 0.1f }
|
||||
, B { 1.0f }
|
||||
, C { 0.0f }
|
||||
, D { 0.1f }
|
||||
, E { 0.9f }
|
||||
, F { 1.0f }
|
||||
, fpdL { 0 }
|
||||
, fpdR { 0 }
|
||||
, biquad { 0 }
|
||||
: samplerate {_samplerate}
|
||||
, A {0.1f}
|
||||
, B {1.0f}
|
||||
, C {0.0f}
|
||||
, D {0.1f}
|
||||
, E {0.9f}
|
||||
, F {1.0f}
|
||||
, fpdL {0}
|
||||
, fpdR {0}
|
||||
, biquad {0}
|
||||
{
|
||||
for (int x = 0; x < biq_total; x++) {
|
||||
biquad[x] = 0.0;
|
||||
}
|
||||
for (int x = 0; x < biq_total; x++) { biquad[x] = 0.0; }
|
||||
powFactorA = 1.0;
|
||||
powFactorB = 1.0;
|
||||
inTrimA = 0.1;
|
||||
@@ -36,41 +34,25 @@ public:
|
||||
}
|
||||
|
||||
fpdL = 1.0;
|
||||
while (fpdL < 16386)
|
||||
fpdL = rand() * UINT32_MAX;
|
||||
while (fpdL < 16386) fpdL = rand() * UINT32_MAX;
|
||||
fpdR = 1.0;
|
||||
while (fpdR < 16386)
|
||||
fpdR = rand() * UINT32_MAX;
|
||||
while (fpdR < 16386) fpdR = rand() * UINT32_MAX;
|
||||
}
|
||||
|
||||
void set_samplerate(double _samplerate) {
|
||||
samplerate = _samplerate;
|
||||
}
|
||||
void set_samplerate(double _samplerate) { samplerate = _samplerate; }
|
||||
|
||||
void set_drive(float value) { A = value * 0.9 + 0.1; }
|
||||
|
||||
void set_frequency(float value) { B = value; }
|
||||
|
||||
void set_resonance(float value) { C = value; }
|
||||
|
||||
void set_edge(float value) { D = value; }
|
||||
|
||||
void set_output(float value) { E = value; }
|
||||
|
||||
void set_mix(float value) { F = value; }
|
||||
|
||||
void set_drive(float value)
|
||||
{
|
||||
A = value * 0.9 + 0.1;
|
||||
}
|
||||
void set_frequency(float value)
|
||||
{
|
||||
B = value;
|
||||
}
|
||||
void set_resonance(float value)
|
||||
{
|
||||
C = value;
|
||||
}
|
||||
void set_edge(float value)
|
||||
{
|
||||
D = value;
|
||||
}
|
||||
void set_output(float value)
|
||||
{
|
||||
E = value;
|
||||
}
|
||||
void set_mix(float value)
|
||||
{
|
||||
F = value;
|
||||
}
|
||||
void processblock(t_sample** inputs, t_sample** outputs, int blockSize)
|
||||
{
|
||||
t_sample* in1 = inputs[0];
|
||||
@@ -87,8 +69,7 @@ public:
|
||||
inTrimB = A * 10.0;
|
||||
|
||||
biquad[biq_freq] = pow(B, 3) * 20000.0;
|
||||
if (biquad[biq_freq] < 15.0)
|
||||
biquad[biq_freq] = 15.0;
|
||||
if (biquad[biq_freq] < 15.0) biquad[biq_freq] = 15.0;
|
||||
biquad[biq_freq] /= samplerate;
|
||||
biquad[biq_reso] = (pow(C, 2) * 15.0) + 0.5571;
|
||||
biquad[biq_aA0] = biquad[biq_aB0];
|
||||
@@ -132,10 +113,8 @@ public:
|
||||
for (int s = 0; s < blockSize; s++) {
|
||||
double inputSampleL = *in1;
|
||||
double inputSampleR = *in2;
|
||||
if (fabs(inputSampleL) < 1.18e-23)
|
||||
inputSampleL = fpdL * 1.18e-17;
|
||||
if (fabs(inputSampleR) < 1.18e-23)
|
||||
inputSampleR = fpdR * 1.18e-17;
|
||||
if (fabs(inputSampleL) < 1.18e-23) inputSampleL = fpdL * 1.18e-17;
|
||||
if (fabs(inputSampleR) < 1.18e-23) inputSampleR = fpdR * 1.18e-17;
|
||||
double drySampleL = inputSampleL;
|
||||
double drySampleR = inputSampleR;
|
||||
|
||||
@@ -163,22 +142,14 @@ public:
|
||||
inputSampleR = temp; // fixed biquad filtering ultrasonics
|
||||
|
||||
// encode/decode courtesy of torridgristle under the MIT license
|
||||
if (inputSampleL > 1.0)
|
||||
inputSampleL = 1.0;
|
||||
else if (inputSampleL > 0.0)
|
||||
inputSampleL = 1.0 - pow(1.0 - inputSampleL, powFactor);
|
||||
if (inputSampleL < -1.0)
|
||||
inputSampleL = -1.0;
|
||||
else if (inputSampleL < 0.0)
|
||||
inputSampleL = -1.0 + pow(1.0 + inputSampleL, powFactor);
|
||||
if (inputSampleR > 1.0)
|
||||
inputSampleR = 1.0;
|
||||
else if (inputSampleR > 0.0)
|
||||
inputSampleR = 1.0 - pow(1.0 - inputSampleR, powFactor);
|
||||
if (inputSampleR < -1.0)
|
||||
inputSampleR = -1.0;
|
||||
else if (inputSampleR < 0.0)
|
||||
inputSampleR = -1.0 + pow(1.0 + inputSampleR, powFactor);
|
||||
if (inputSampleL > 1.0) inputSampleL = 1.0;
|
||||
else if (inputSampleL > 0.0) inputSampleL = 1.0 - pow(1.0 - inputSampleL, powFactor);
|
||||
if (inputSampleL < -1.0) inputSampleL = -1.0;
|
||||
else if (inputSampleL < 0.0) inputSampleL = -1.0 + pow(1.0 + inputSampleL, powFactor);
|
||||
if (inputSampleR > 1.0) inputSampleR = 1.0;
|
||||
else if (inputSampleR > 0.0) inputSampleR = 1.0 - pow(1.0 - inputSampleR, powFactor);
|
||||
if (inputSampleR < -1.0) inputSampleR = -1.0;
|
||||
else if (inputSampleR < 0.0) inputSampleR = -1.0 + pow(1.0 + inputSampleR, powFactor);
|
||||
|
||||
temp = (inputSampleL * biquad[biq_a0]) + biquad[biq_sL1];
|
||||
biquad[biq_sL1] = (inputSampleL * biquad[biq_a1]) - (temp * biquad[biq_b1]) + biquad[biq_sL2];
|
||||
@@ -190,22 +161,14 @@ public:
|
||||
inputSampleR = temp; // coefficient interpolating biquad filter
|
||||
|
||||
// encode/decode courtesy of torridgristle under the MIT license
|
||||
if (inputSampleL > 1.0)
|
||||
inputSampleL = 1.0;
|
||||
else if (inputSampleL > 0.0)
|
||||
inputSampleL = 1.0 - pow(1.0 - inputSampleL, (1.0 / powFactor));
|
||||
if (inputSampleL < -1.0)
|
||||
inputSampleL = -1.0;
|
||||
else if (inputSampleL < 0.0)
|
||||
inputSampleL = -1.0 + pow(1.0 + inputSampleL, (1.0 / powFactor));
|
||||
if (inputSampleR > 1.0)
|
||||
inputSampleR = 1.0;
|
||||
else if (inputSampleR > 0.0)
|
||||
inputSampleR = 1.0 - pow(1.0 - inputSampleR, (1.0 / powFactor));
|
||||
if (inputSampleR < -1.0)
|
||||
inputSampleR = -1.0;
|
||||
else if (inputSampleR < 0.0)
|
||||
inputSampleR = -1.0 + pow(1.0 + inputSampleR, (1.0 / powFactor));
|
||||
if (inputSampleL > 1.0) inputSampleL = 1.0;
|
||||
else if (inputSampleL > 0.0) inputSampleL = 1.0 - pow(1.0 - inputSampleL, (1.0 / powFactor));
|
||||
if (inputSampleL < -1.0) inputSampleL = -1.0;
|
||||
else if (inputSampleL < 0.0) inputSampleL = -1.0 + pow(1.0 + inputSampleL, (1.0 / powFactor));
|
||||
if (inputSampleR > 1.0) inputSampleR = 1.0;
|
||||
else if (inputSampleR > 0.0) inputSampleR = 1.0 - pow(1.0 - inputSampleR, (1.0 / powFactor));
|
||||
if (inputSampleR < -1.0) inputSampleR = -1.0;
|
||||
else if (inputSampleR < 0.0) inputSampleR = -1.0 + pow(1.0 + inputSampleR, (1.0 / powFactor));
|
||||
|
||||
inputSampleL *= outTrim;
|
||||
inputSampleR *= outTrim;
|
||||
@@ -250,6 +213,7 @@ public:
|
||||
|
||||
private:
|
||||
double samplerate;
|
||||
|
||||
enum {
|
||||
biq_freq,
|
||||
biq_reso,
|
||||
@@ -274,6 +238,7 @@ private:
|
||||
biq_sR2,
|
||||
biq_total
|
||||
}; // coefficient interpolating biquad filter, stereo
|
||||
|
||||
std::array<double, biq_total> biquad;
|
||||
|
||||
double powFactorA;
|
||||
@@ -297,6 +262,7 @@ private:
|
||||
fix_sR2,
|
||||
fix_total
|
||||
}; // fixed frequency biquad filter for ultrasonics, stereo
|
||||
|
||||
std::array<double, fix_total> fixA;
|
||||
std::array<double, fix_total> fixB;
|
||||
|
||||
@@ -311,4 +277,4 @@ private:
|
||||
float E;
|
||||
float F; // parameters. Always 0-1, and we scale/alter them elsewhere.
|
||||
};
|
||||
}
|
||||
} // namespace trnr
|
||||
@@ -1,7 +1,7 @@
|
||||
#pragma once
|
||||
#define _USE_MATH_DEFINES
|
||||
#include <math.h>
|
||||
#include <array>
|
||||
#include <math.h>
|
||||
#include <vector>
|
||||
|
||||
namespace trnr {
|
||||
@@ -10,20 +10,18 @@ template <typename t_sample>
|
||||
class ylowpass {
|
||||
public:
|
||||
ylowpass(double _samplerate)
|
||||
: samplerate { _samplerate }
|
||||
, A { 0.1f }
|
||||
, B { 1.0f }
|
||||
, C { 0.0f }
|
||||
, D { 0.1f }
|
||||
, E { 0.9f }
|
||||
, F { 1.0f }
|
||||
, fpdL { 0 }
|
||||
, fpdR { 0 }
|
||||
, biquad { 0 }
|
||||
: samplerate {_samplerate}
|
||||
, A {0.1f}
|
||||
, B {1.0f}
|
||||
, C {0.0f}
|
||||
, D {0.1f}
|
||||
, E {0.9f}
|
||||
, F {1.0f}
|
||||
, fpdL {0}
|
||||
, fpdR {0}
|
||||
, biquad {0}
|
||||
{
|
||||
for (int x = 0; x < biq_total; x++) {
|
||||
biquad[x] = 0.0;
|
||||
}
|
||||
for (int x = 0; x < biq_total; x++) { biquad[x] = 0.0; }
|
||||
powFactorA = 1.0;
|
||||
powFactorB = 1.0;
|
||||
inTrimA = 0.1;
|
||||
@@ -36,41 +34,25 @@ public:
|
||||
}
|
||||
|
||||
fpdL = 1.0;
|
||||
while (fpdL < 16386)
|
||||
fpdL = rand() * UINT32_MAX;
|
||||
while (fpdL < 16386) fpdL = rand() * UINT32_MAX;
|
||||
fpdR = 1.0;
|
||||
while (fpdR < 16386)
|
||||
fpdR = rand() * UINT32_MAX;
|
||||
while (fpdR < 16386) fpdR = rand() * UINT32_MAX;
|
||||
}
|
||||
|
||||
void set_samplerate(double _samplerate) {
|
||||
samplerate = _samplerate;
|
||||
}
|
||||
void set_samplerate(double _samplerate) { samplerate = _samplerate; }
|
||||
|
||||
void set_drive(float value) { A = value * 0.9 + 0.1; }
|
||||
|
||||
void set_frequency(float value) { B = value; }
|
||||
|
||||
void set_resonance(float value) { C = value; }
|
||||
|
||||
void set_edge(float value) { D = value; }
|
||||
|
||||
void set_output(float value) { E = value; }
|
||||
|
||||
void set_mix(float value) { F = value; }
|
||||
|
||||
void set_drive(float value)
|
||||
{
|
||||
A = value * 0.9 + 0.1;
|
||||
}
|
||||
void set_frequency(float value)
|
||||
{
|
||||
B = value;
|
||||
}
|
||||
void set_resonance(float value)
|
||||
{
|
||||
C = value;
|
||||
}
|
||||
void set_edge(float value)
|
||||
{
|
||||
D = value;
|
||||
}
|
||||
void set_output(float value)
|
||||
{
|
||||
E = value;
|
||||
}
|
||||
void set_mix(float value)
|
||||
{
|
||||
F = value;
|
||||
}
|
||||
void processblock(t_sample** inputs, t_sample** outputs, int blockSize)
|
||||
{
|
||||
t_sample* in1 = inputs[0];
|
||||
@@ -87,8 +69,7 @@ public:
|
||||
inTrimB = A * 10.0;
|
||||
|
||||
biquad[biq_freq] = pow(B, 3) * 20000.0;
|
||||
if (biquad[biq_freq] < 15.0)
|
||||
biquad[biq_freq] = 15.0;
|
||||
if (biquad[biq_freq] < 15.0) biquad[biq_freq] = 15.0;
|
||||
biquad[biq_freq] /= samplerate;
|
||||
biquad[biq_reso] = (pow(C, 2) * 15.0) + 0.5571;
|
||||
biquad[biq_aA0] = biquad[biq_aB0];
|
||||
@@ -132,10 +113,8 @@ public:
|
||||
for (int s = 0; s < blockSize; s++) {
|
||||
double inputSampleL = *in1;
|
||||
double inputSampleR = *in2;
|
||||
if (fabs(inputSampleL) < 1.18e-23)
|
||||
inputSampleL = fpdL * 1.18e-17;
|
||||
if (fabs(inputSampleR) < 1.18e-23)
|
||||
inputSampleR = fpdR * 1.18e-17;
|
||||
if (fabs(inputSampleL) < 1.18e-23) inputSampleL = fpdL * 1.18e-17;
|
||||
if (fabs(inputSampleR) < 1.18e-23) inputSampleR = fpdR * 1.18e-17;
|
||||
double drySampleL = inputSampleL;
|
||||
double drySampleR = inputSampleR;
|
||||
|
||||
@@ -163,22 +142,14 @@ public:
|
||||
inputSampleR = temp; // fixed biquad filtering ultrasonics
|
||||
|
||||
// encode/decode courtesy of torridgristle under the MIT license
|
||||
if (inputSampleL > 1.0)
|
||||
inputSampleL = 1.0;
|
||||
else if (inputSampleL > 0.0)
|
||||
inputSampleL = 1.0 - pow(1.0 - inputSampleL, powFactor);
|
||||
if (inputSampleL < -1.0)
|
||||
inputSampleL = -1.0;
|
||||
else if (inputSampleL < 0.0)
|
||||
inputSampleL = -1.0 + pow(1.0 + inputSampleL, powFactor);
|
||||
if (inputSampleR > 1.0)
|
||||
inputSampleR = 1.0;
|
||||
else if (inputSampleR > 0.0)
|
||||
inputSampleR = 1.0 - pow(1.0 - inputSampleR, powFactor);
|
||||
if (inputSampleR < -1.0)
|
||||
inputSampleR = -1.0;
|
||||
else if (inputSampleR < 0.0)
|
||||
inputSampleR = -1.0 + pow(1.0 + inputSampleR, powFactor);
|
||||
if (inputSampleL > 1.0) inputSampleL = 1.0;
|
||||
else if (inputSampleL > 0.0) inputSampleL = 1.0 - pow(1.0 - inputSampleL, powFactor);
|
||||
if (inputSampleL < -1.0) inputSampleL = -1.0;
|
||||
else if (inputSampleL < 0.0) inputSampleL = -1.0 + pow(1.0 + inputSampleL, powFactor);
|
||||
if (inputSampleR > 1.0) inputSampleR = 1.0;
|
||||
else if (inputSampleR > 0.0) inputSampleR = 1.0 - pow(1.0 - inputSampleR, powFactor);
|
||||
if (inputSampleR < -1.0) inputSampleR = -1.0;
|
||||
else if (inputSampleR < 0.0) inputSampleR = -1.0 + pow(1.0 + inputSampleR, powFactor);
|
||||
|
||||
temp = (inputSampleL * biquad[biq_a0]) + biquad[biq_sL1];
|
||||
biquad[biq_sL1] = (inputSampleL * biquad[biq_a1]) - (temp * biquad[biq_b1]) + biquad[biq_sL2];
|
||||
@@ -190,22 +161,14 @@ public:
|
||||
inputSampleR = temp; // coefficient interpolating biquad filter
|
||||
|
||||
// encode/decode courtesy of torridgristle under the MIT license
|
||||
if (inputSampleL > 1.0)
|
||||
inputSampleL = 1.0;
|
||||
else if (inputSampleL > 0.0)
|
||||
inputSampleL = 1.0 - pow(1.0 - inputSampleL, (1.0 / powFactor));
|
||||
if (inputSampleL < -1.0)
|
||||
inputSampleL = -1.0;
|
||||
else if (inputSampleL < 0.0)
|
||||
inputSampleL = -1.0 + pow(1.0 + inputSampleL, (1.0 / powFactor));
|
||||
if (inputSampleR > 1.0)
|
||||
inputSampleR = 1.0;
|
||||
else if (inputSampleR > 0.0)
|
||||
inputSampleR = 1.0 - pow(1.0 - inputSampleR, (1.0 / powFactor));
|
||||
if (inputSampleR < -1.0)
|
||||
inputSampleR = -1.0;
|
||||
else if (inputSampleR < 0.0)
|
||||
inputSampleR = -1.0 + pow(1.0 + inputSampleR, (1.0 / powFactor));
|
||||
if (inputSampleL > 1.0) inputSampleL = 1.0;
|
||||
else if (inputSampleL > 0.0) inputSampleL = 1.0 - pow(1.0 - inputSampleL, (1.0 / powFactor));
|
||||
if (inputSampleL < -1.0) inputSampleL = -1.0;
|
||||
else if (inputSampleL < 0.0) inputSampleL = -1.0 + pow(1.0 + inputSampleL, (1.0 / powFactor));
|
||||
if (inputSampleR > 1.0) inputSampleR = 1.0;
|
||||
else if (inputSampleR > 0.0) inputSampleR = 1.0 - pow(1.0 - inputSampleR, (1.0 / powFactor));
|
||||
if (inputSampleR < -1.0) inputSampleR = -1.0;
|
||||
else if (inputSampleR < 0.0) inputSampleR = -1.0 + pow(1.0 + inputSampleR, (1.0 / powFactor));
|
||||
|
||||
inputSampleL *= outTrim;
|
||||
inputSampleR *= outTrim;
|
||||
@@ -250,6 +213,7 @@ public:
|
||||
|
||||
private:
|
||||
double samplerate;
|
||||
|
||||
enum {
|
||||
biq_freq,
|
||||
biq_reso,
|
||||
@@ -274,6 +238,7 @@ private:
|
||||
biq_sR2,
|
||||
biq_total
|
||||
}; // coefficient interpolating biquad filter, stereo
|
||||
|
||||
std::array<double, biq_total> biquad;
|
||||
|
||||
double powFactorA;
|
||||
@@ -297,6 +262,7 @@ private:
|
||||
fix_sR2,
|
||||
fix_total
|
||||
}; // fixed frequency biquad filter for ultrasonics, stereo
|
||||
|
||||
std::array<double, fix_total> fixA;
|
||||
std::array<double, fix_total> fixB;
|
||||
|
||||
@@ -311,4 +277,4 @@ private:
|
||||
float E;
|
||||
float F; // parameters. Always 0-1, and we scale/alter them elsewhere.
|
||||
};
|
||||
}
|
||||
} // namespace trnr
|
||||
134
filter/ynotch.h
134
filter/ynotch.h
@@ -1,7 +1,7 @@
|
||||
#pragma once
|
||||
#define _USE_MATH_DEFINES
|
||||
#include <math.h>
|
||||
#include <array>
|
||||
#include <math.h>
|
||||
#include <vector>
|
||||
|
||||
namespace trnr {
|
||||
@@ -10,20 +10,18 @@ template <typename t_sample>
|
||||
class ynotch {
|
||||
public:
|
||||
ynotch(double _samplerate)
|
||||
: samplerate { _samplerate }
|
||||
, A { 0.1f }
|
||||
, B { 1.0f }
|
||||
, C { 0.0f }
|
||||
, D { 0.1f }
|
||||
, E { 0.9f }
|
||||
, F { 1.0f }
|
||||
, fpdL { 0 }
|
||||
, fpdR { 0 }
|
||||
, biquad { 0 }
|
||||
: samplerate {_samplerate}
|
||||
, A {0.1f}
|
||||
, B {1.0f}
|
||||
, C {0.0f}
|
||||
, D {0.1f}
|
||||
, E {0.9f}
|
||||
, F {1.0f}
|
||||
, fpdL {0}
|
||||
, fpdR {0}
|
||||
, biquad {0}
|
||||
{
|
||||
for (int x = 0; x < biq_total; x++) {
|
||||
biquad[x] = 0.0;
|
||||
}
|
||||
for (int x = 0; x < biq_total; x++) { biquad[x] = 0.0; }
|
||||
powFactorA = 1.0;
|
||||
powFactorB = 1.0;
|
||||
inTrimA = 0.1;
|
||||
@@ -36,41 +34,25 @@ public:
|
||||
}
|
||||
|
||||
fpdL = 1.0;
|
||||
while (fpdL < 16386)
|
||||
fpdL = rand() * UINT32_MAX;
|
||||
while (fpdL < 16386) fpdL = rand() * UINT32_MAX;
|
||||
fpdR = 1.0;
|
||||
while (fpdR < 16386)
|
||||
fpdR = rand() * UINT32_MAX;
|
||||
while (fpdR < 16386) fpdR = rand() * UINT32_MAX;
|
||||
}
|
||||
|
||||
void set_samplerate(double _samplerate) {
|
||||
samplerate = _samplerate;
|
||||
}
|
||||
void set_samplerate(double _samplerate) { samplerate = _samplerate; }
|
||||
|
||||
void set_drive(float value) { A = value * 0.9 + 0.1; }
|
||||
|
||||
void set_frequency(float value) { B = value; }
|
||||
|
||||
void set_resonance(float value) { C = value; }
|
||||
|
||||
void set_edge(float value) { D = value; }
|
||||
|
||||
void set_output(float value) { E = value; }
|
||||
|
||||
void set_mix(float value) { F = value; }
|
||||
|
||||
void set_drive(float value)
|
||||
{
|
||||
A = value * 0.9 + 0.1;
|
||||
}
|
||||
void set_frequency(float value)
|
||||
{
|
||||
B = value;
|
||||
}
|
||||
void set_resonance(float value)
|
||||
{
|
||||
C = value;
|
||||
}
|
||||
void set_edge(float value)
|
||||
{
|
||||
D = value;
|
||||
}
|
||||
void set_output(float value)
|
||||
{
|
||||
E = value;
|
||||
}
|
||||
void set_mix(float value)
|
||||
{
|
||||
F = value;
|
||||
}
|
||||
void processblock(t_sample** inputs, t_sample** outputs, int blockSize)
|
||||
{
|
||||
t_sample* in1 = inputs[0];
|
||||
@@ -87,8 +69,7 @@ public:
|
||||
inTrimB = A * 10.0;
|
||||
|
||||
biquad[biq_freq] = pow(B, 3) * 20000.0;
|
||||
if (biquad[biq_freq] < 15.0)
|
||||
biquad[biq_freq] = 15.0;
|
||||
if (biquad[biq_freq] < 15.0) biquad[biq_freq] = 15.0;
|
||||
biquad[biq_freq] /= samplerate;
|
||||
biquad[biq_reso] = (pow(C, 2) * 15.0) + 0.0001;
|
||||
biquad[biq_aA0] = biquad[biq_aB0];
|
||||
@@ -132,10 +113,8 @@ public:
|
||||
for (int s = 0; s < blockSize; s++) {
|
||||
double inputSampleL = *in1;
|
||||
double inputSampleR = *in2;
|
||||
if (fabs(inputSampleL) < 1.18e-23)
|
||||
inputSampleL = fpdL * 1.18e-17;
|
||||
if (fabs(inputSampleR) < 1.18e-23)
|
||||
inputSampleR = fpdR * 1.18e-17;
|
||||
if (fabs(inputSampleL) < 1.18e-23) inputSampleL = fpdL * 1.18e-17;
|
||||
if (fabs(inputSampleR) < 1.18e-23) inputSampleR = fpdR * 1.18e-17;
|
||||
double drySampleL = inputSampleL;
|
||||
double drySampleR = inputSampleR;
|
||||
|
||||
@@ -163,22 +142,14 @@ public:
|
||||
inputSampleR = temp; // fixed biquad filtering ultrasonics
|
||||
|
||||
// encode/decode courtesy of torridgristle under the MIT license
|
||||
if (inputSampleL > 1.0)
|
||||
inputSampleL = 1.0;
|
||||
else if (inputSampleL > 0.0)
|
||||
inputSampleL = 1.0 - pow(1.0 - inputSampleL, powFactor);
|
||||
if (inputSampleL < -1.0)
|
||||
inputSampleL = -1.0;
|
||||
else if (inputSampleL < 0.0)
|
||||
inputSampleL = -1.0 + pow(1.0 + inputSampleL, powFactor);
|
||||
if (inputSampleR > 1.0)
|
||||
inputSampleR = 1.0;
|
||||
else if (inputSampleR > 0.0)
|
||||
inputSampleR = 1.0 - pow(1.0 - inputSampleR, powFactor);
|
||||
if (inputSampleR < -1.0)
|
||||
inputSampleR = -1.0;
|
||||
else if (inputSampleR < 0.0)
|
||||
inputSampleR = -1.0 + pow(1.0 + inputSampleR, powFactor);
|
||||
if (inputSampleL > 1.0) inputSampleL = 1.0;
|
||||
else if (inputSampleL > 0.0) inputSampleL = 1.0 - pow(1.0 - inputSampleL, powFactor);
|
||||
if (inputSampleL < -1.0) inputSampleL = -1.0;
|
||||
else if (inputSampleL < 0.0) inputSampleL = -1.0 + pow(1.0 + inputSampleL, powFactor);
|
||||
if (inputSampleR > 1.0) inputSampleR = 1.0;
|
||||
else if (inputSampleR > 0.0) inputSampleR = 1.0 - pow(1.0 - inputSampleR, powFactor);
|
||||
if (inputSampleR < -1.0) inputSampleR = -1.0;
|
||||
else if (inputSampleR < 0.0) inputSampleR = -1.0 + pow(1.0 + inputSampleR, powFactor);
|
||||
|
||||
temp = (inputSampleL * biquad[biq_a0]) + biquad[biq_sL1];
|
||||
biquad[biq_sL1] = (inputSampleL * biquad[biq_a1]) - (temp * biquad[biq_b1]) + biquad[biq_sL2];
|
||||
@@ -190,22 +161,14 @@ public:
|
||||
inputSampleR = temp; // coefficient interpolating biquad filter
|
||||
|
||||
// encode/decode courtesy of torridgristle under the MIT license
|
||||
if (inputSampleL > 1.0)
|
||||
inputSampleL = 1.0;
|
||||
else if (inputSampleL > 0.0)
|
||||
inputSampleL = 1.0 - pow(1.0 - inputSampleL, (1.0 / powFactor));
|
||||
if (inputSampleL < -1.0)
|
||||
inputSampleL = -1.0;
|
||||
else if (inputSampleL < 0.0)
|
||||
inputSampleL = -1.0 + pow(1.0 + inputSampleL, (1.0 / powFactor));
|
||||
if (inputSampleR > 1.0)
|
||||
inputSampleR = 1.0;
|
||||
else if (inputSampleR > 0.0)
|
||||
inputSampleR = 1.0 - pow(1.0 - inputSampleR, (1.0 / powFactor));
|
||||
if (inputSampleR < -1.0)
|
||||
inputSampleR = -1.0;
|
||||
else if (inputSampleR < 0.0)
|
||||
inputSampleR = -1.0 + pow(1.0 + inputSampleR, (1.0 / powFactor));
|
||||
if (inputSampleL > 1.0) inputSampleL = 1.0;
|
||||
else if (inputSampleL > 0.0) inputSampleL = 1.0 - pow(1.0 - inputSampleL, (1.0 / powFactor));
|
||||
if (inputSampleL < -1.0) inputSampleL = -1.0;
|
||||
else if (inputSampleL < 0.0) inputSampleL = -1.0 + pow(1.0 + inputSampleL, (1.0 / powFactor));
|
||||
if (inputSampleR > 1.0) inputSampleR = 1.0;
|
||||
else if (inputSampleR > 0.0) inputSampleR = 1.0 - pow(1.0 - inputSampleR, (1.0 / powFactor));
|
||||
if (inputSampleR < -1.0) inputSampleR = -1.0;
|
||||
else if (inputSampleR < 0.0) inputSampleR = -1.0 + pow(1.0 + inputSampleR, (1.0 / powFactor));
|
||||
|
||||
inputSampleL *= outTrim;
|
||||
inputSampleR *= outTrim;
|
||||
@@ -250,6 +213,7 @@ public:
|
||||
|
||||
private:
|
||||
double samplerate;
|
||||
|
||||
enum {
|
||||
biq_freq,
|
||||
biq_reso,
|
||||
@@ -274,6 +238,7 @@ private:
|
||||
biq_sR2,
|
||||
biq_total
|
||||
}; // coefficient interpolating biquad filter, stereo
|
||||
|
||||
std::array<double, biq_total> biquad;
|
||||
|
||||
double powFactorA;
|
||||
@@ -297,6 +262,7 @@ private:
|
||||
fix_sR2,
|
||||
fix_total
|
||||
}; // fixed frequency biquad filter for ultrasonics, stereo
|
||||
|
||||
std::array<double, fix_total> fixA;
|
||||
std::array<double, fix_total> fixB;
|
||||
|
||||
@@ -311,4 +277,4 @@ private:
|
||||
float E;
|
||||
float F; // parameters. Always 0-1, and we scale/alter them elsewhere.
|
||||
};
|
||||
}
|
||||
} // namespace trnr
|
||||
@@ -1,7 +1,7 @@
|
||||
#pragma once
|
||||
#include "ylowpass.h"
|
||||
#include "yhighpass.h"
|
||||
#include "ybandpass.h"
|
||||
#include "yhighpass.h"
|
||||
#include "ylowpass.h"
|
||||
#include "ynotch.h"
|
||||
|
||||
namespace trnr {
|
||||
@@ -17,66 +17,73 @@ template <typename t_sample>
|
||||
class ysvf {
|
||||
public:
|
||||
ysvf(double _samplerate = 44100)
|
||||
: lowpass { _samplerate }
|
||||
, highpass { _samplerate }
|
||||
, bandpass { _samplerate }
|
||||
, notch { _samplerate }
|
||||
{}
|
||||
: lowpass {_samplerate}
|
||||
, highpass {_samplerate}
|
||||
, bandpass {_samplerate}
|
||||
, notch {_samplerate}
|
||||
{
|
||||
}
|
||||
|
||||
void set_samplerate(double _samplerate) {
|
||||
void set_samplerate(double _samplerate)
|
||||
{
|
||||
lowpass.set_samplerate(_samplerate);
|
||||
highpass.set_samplerate(_samplerate);
|
||||
bandpass.set_samplerate(_samplerate);
|
||||
notch.set_samplerate(_samplerate);
|
||||
}
|
||||
|
||||
void set_filter_type(filter_types type) {
|
||||
filter_type = type;
|
||||
}
|
||||
void set_filter_type(filter_types type) { filter_type = type; }
|
||||
|
||||
void set_drive(float value) {
|
||||
void set_drive(float value)
|
||||
{
|
||||
lowpass.set_drive(value);
|
||||
highpass.set_drive(value);
|
||||
bandpass.set_drive(value);
|
||||
notch.set_drive(value);
|
||||
}
|
||||
|
||||
void set_frequency(float value) {
|
||||
void set_frequency(float value)
|
||||
{
|
||||
lowpass.set_frequency(value);
|
||||
highpass.set_frequency(value);
|
||||
bandpass.set_frequency(value);
|
||||
notch.set_frequency(value);
|
||||
}
|
||||
|
||||
void set_resonance(float value) {
|
||||
void set_resonance(float value)
|
||||
{
|
||||
lowpass.set_resonance(value);
|
||||
highpass.set_resonance(value);
|
||||
bandpass.set_resonance(value);
|
||||
notch.set_resonance(value);
|
||||
}
|
||||
|
||||
void set_edge(float value) {
|
||||
void set_edge(float value)
|
||||
{
|
||||
lowpass.set_edge(value);
|
||||
highpass.set_edge(value);
|
||||
bandpass.set_edge(value);
|
||||
notch.set_edge(value);
|
||||
}
|
||||
|
||||
void set_output(float value) {
|
||||
void set_output(float value)
|
||||
{
|
||||
lowpass.set_output(value);
|
||||
highpass.set_output(value);
|
||||
bandpass.set_output(value);
|
||||
notch.set_output(value);
|
||||
}
|
||||
|
||||
void set_mix(float value) {
|
||||
void set_mix(float value)
|
||||
{
|
||||
lowpass.set_mix(value);
|
||||
highpass.set_mix(value);
|
||||
bandpass.set_mix(value);
|
||||
notch.set_mix(value);
|
||||
}
|
||||
|
||||
void process_block(t_sample** inputs, t_sample** outputs, int block_size) {
|
||||
void process_block(t_sample** inputs, t_sample** outputs, int block_size)
|
||||
{
|
||||
|
||||
switch (filter_type) {
|
||||
case filter_types::lowpass:
|
||||
@@ -101,7 +108,8 @@ private:
|
||||
ybandpass<t_sample> bandpass;
|
||||
ynotch<t_sample> notch;
|
||||
|
||||
double clamp(double& value, double min, double max) {
|
||||
double clamp(double& value, double min, double max)
|
||||
{
|
||||
if (value < min) {
|
||||
value = min;
|
||||
} else if (value > max) {
|
||||
@@ -110,4 +118,4 @@ private:
|
||||
return value;
|
||||
}
|
||||
};
|
||||
}
|
||||
} // namespace trnr
|
||||
@@ -22,4 +22,4 @@ struct is_convertible {
|
||||
|
||||
static const bool value = sizeof(test<ivoice>(static_cast<derived*>(0))) == 1;
|
||||
};
|
||||
}
|
||||
} // namespace trnr
|
||||
@@ -45,4 +45,4 @@ public:
|
||||
data = _mod;
|
||||
}
|
||||
};
|
||||
}
|
||||
} // namespace trnr
|
||||
|
||||
@@ -13,7 +13,7 @@ template <typename t_voice, typename t_sample>
|
||||
class midi_synth : public voice_allocator<t_voice, t_sample> {
|
||||
public:
|
||||
midi_synth(int _n_voices)
|
||||
: m_voices_active { false }
|
||||
: m_voices_active {false}
|
||||
{
|
||||
// checks whether template derives from ivoice
|
||||
typedef t_voice assert_at_compile_time[is_convertible<t_voice>::value ? 1 : -1];
|
||||
@@ -35,15 +35,14 @@ public:
|
||||
|
||||
while (samples_remaining > 0) {
|
||||
|
||||
if (samples_remaining < block_size)
|
||||
block_size = samples_remaining;
|
||||
if (samples_remaining < block_size) block_size = samples_remaining;
|
||||
|
||||
while (!m_event_queue.empty()) {
|
||||
midi_event event = m_event_queue.front();
|
||||
|
||||
// we assume the messages are in chronological order. If we find one later than the current block we are done.
|
||||
if (event.offset > start_index + block_size)
|
||||
break;
|
||||
// we assume the messages are in chronological order. If we find one later than the current block we
|
||||
// are done.
|
||||
if (event.offset > start_index + block_size) break;
|
||||
|
||||
// send performance messages to the voice allocator
|
||||
// message offset is relative to the start of this process_samples() block
|
||||
@@ -72,17 +71,14 @@ public:
|
||||
|
||||
void add_event(midi_event event)
|
||||
{
|
||||
if (event.type == midi_event_type::note_on)
|
||||
m_voices_active = true;
|
||||
if (event.type == midi_event_type::note_on) m_voices_active = true;
|
||||
|
||||
m_event_queue.push_back(event);
|
||||
}
|
||||
|
||||
void flush_event_queue(int frames)
|
||||
{
|
||||
for (int i = 0; i < m_event_queue.size(); i++) {
|
||||
m_event_queue.at(i).offset -= frames;
|
||||
}
|
||||
for (int i = 0; i < m_event_queue.size(); i++) { m_event_queue.at(i).offset -= frames; }
|
||||
}
|
||||
|
||||
private:
|
||||
@@ -90,4 +86,4 @@ private:
|
||||
int m_block_size;
|
||||
bool m_voices_active;
|
||||
};
|
||||
}
|
||||
} // namespace trnr
|
||||
|
||||
@@ -31,17 +31,15 @@ public:
|
||||
float release2_rate = 0;
|
||||
|
||||
tx_envelope(bool _retrigger = false)
|
||||
: retrigger { _retrigger }
|
||||
: retrigger {_retrigger}
|
||||
{
|
||||
}
|
||||
|
||||
float process_sample(bool gate, bool trigger) {
|
||||
|
||||
return process_sample<float>(gate, trigger, 0, 0);
|
||||
}
|
||||
float process_sample(bool gate, bool trigger) { return process_sample<float>(gate, trigger, 0, 0); }
|
||||
|
||||
template <typename t_sample>
|
||||
float process_sample(bool gate, bool trigger, t_sample _attack_mod, t_sample _decay_mod) {
|
||||
float process_sample(bool gate, bool trigger, t_sample _attack_mod, t_sample _decay_mod)
|
||||
{
|
||||
|
||||
size_t attack_mid_x1 = ms_to_samples(attack1_rate + (float)_attack_mod);
|
||||
size_t attack_mid_x2 = ms_to_samples(attack2_rate + (float)_attack_mod);
|
||||
@@ -53,10 +51,8 @@ public:
|
||||
|
||||
// if note on is triggered, transition to attack phase
|
||||
if (trigger) {
|
||||
if (retrigger)
|
||||
start_level = 0.f;
|
||||
else
|
||||
start_level = level;
|
||||
if (retrigger) start_level = 0.f;
|
||||
else start_level = level;
|
||||
phase = 0;
|
||||
state = attack1;
|
||||
}
|
||||
@@ -68,9 +64,7 @@ public:
|
||||
phase += 1;
|
||||
}
|
||||
// reset phase if parameter was changed
|
||||
if (phase > attack_mid_x1) {
|
||||
phase = attack_mid_x1;
|
||||
}
|
||||
if (phase > attack_mid_x1) { phase = attack_mid_x1; }
|
||||
// if attack phase is done, transition to decay phase
|
||||
if (phase == attack_mid_x1) {
|
||||
state = attack2;
|
||||
@@ -85,9 +79,7 @@ public:
|
||||
phase += 1;
|
||||
}
|
||||
// reset phase if parameter was changed
|
||||
if (phase > attack_mid_x2) {
|
||||
phase = attack_mid_x2;
|
||||
}
|
||||
if (phase > attack_mid_x2) { phase = attack_mid_x2; }
|
||||
// if attack phase is done, transition to decay phase
|
||||
if (phase == attack_mid_x2) {
|
||||
state = hold;
|
||||
@@ -100,9 +92,7 @@ public:
|
||||
level = 1.0;
|
||||
phase += 1;
|
||||
}
|
||||
if (phase > hold_samp) {
|
||||
phase = hold_samp;
|
||||
}
|
||||
if (phase > hold_samp) { phase = hold_samp; }
|
||||
if (phase == hold_samp) {
|
||||
state = decay1;
|
||||
phase = 0;
|
||||
@@ -116,9 +106,7 @@ public:
|
||||
phase += 1;
|
||||
}
|
||||
// reset phase if parameter was changed
|
||||
if (phase > decay_mid_x1) {
|
||||
phase = decay_mid_x1;
|
||||
}
|
||||
if (phase > decay_mid_x1) { phase = decay_mid_x1; }
|
||||
// if decay phase is done, transition to sustain phase
|
||||
if (phase == decay_mid_x1) {
|
||||
state = decay2;
|
||||
@@ -133,9 +121,7 @@ public:
|
||||
phase += 1;
|
||||
}
|
||||
// reset phase if parameter was changed
|
||||
if (phase > decay_mid_x2) {
|
||||
phase = decay_mid_x2;
|
||||
}
|
||||
if (phase > decay_mid_x2) { phase = decay_mid_x2; }
|
||||
// if decay phase is done, transition to sustain phase
|
||||
if (phase == decay_mid_x2) {
|
||||
state = sustain;
|
||||
@@ -156,9 +142,7 @@ public:
|
||||
phase += 1;
|
||||
}
|
||||
// reset phase if parameter was changed
|
||||
if (phase > release_mid_x1) {
|
||||
phase = release_mid_x1;
|
||||
}
|
||||
if (phase > release_mid_x1) { phase = release_mid_x1; }
|
||||
// transition to 2nd release half
|
||||
if (phase == release_mid_x1) {
|
||||
phase = 0;
|
||||
@@ -173,9 +157,7 @@ public:
|
||||
phase += 1;
|
||||
}
|
||||
// reset phase if parameter was changed
|
||||
if (phase > release_mid_x2) {
|
||||
phase = release_mid_x2;
|
||||
}
|
||||
if (phase > release_mid_x2) { phase = release_mid_x2; }
|
||||
// reset
|
||||
if (phase == release_mid_x2) {
|
||||
phase = 0;
|
||||
@@ -189,16 +171,13 @@ public:
|
||||
|
||||
bool is_busy() { return state != 0; }
|
||||
|
||||
void set_samplerate(double sampleRate) {
|
||||
this->samplerate = sampleRate;
|
||||
}
|
||||
void set_samplerate(double sampleRate) { this->samplerate = sampleRate; }
|
||||
|
||||
// converts the x/y coordinates of the envelope points as a list for graphical representation.
|
||||
std::array<float, 18> calc_coordinates(float _max_attack, float _max_decay, float _max_release) {
|
||||
std::array<float, 18> calc_coordinates(float _max_attack, float _max_decay, float _max_release)
|
||||
{
|
||||
|
||||
auto scale = [](float _value, float _max) {
|
||||
return powf(_value / _max, 0.25) * _max;
|
||||
};
|
||||
auto scale = [](float _value, float _max) { return powf(_value / _max, 0.25) * _max; };
|
||||
|
||||
float a_x = 0;
|
||||
float a_y = 0;
|
||||
@@ -229,26 +208,8 @@ public:
|
||||
|
||||
float total = _max_attack + _max_decay + _max_release;
|
||||
|
||||
return {
|
||||
a_x,
|
||||
a_y,
|
||||
b_x / total,
|
||||
b_y,
|
||||
c_x / total,
|
||||
c_y,
|
||||
d_x / total,
|
||||
d_y,
|
||||
e_x / total,
|
||||
e_y,
|
||||
f_x / total,
|
||||
f_y,
|
||||
g_x / total,
|
||||
g_y,
|
||||
h_x / total,
|
||||
h_y,
|
||||
i_x / total,
|
||||
i_y
|
||||
};
|
||||
return {a_x, a_y, b_x / total, b_y, c_x / total, c_y, d_x / total, d_y, e_x / total, e_y,
|
||||
f_x / total, f_y, g_x / total, g_y, h_x / total, h_y, i_x / total, i_y};
|
||||
}
|
||||
|
||||
private:
|
||||
@@ -263,7 +224,8 @@ private:
|
||||
|
||||
float lerp(float x1, float y1, float x2, float y2, float x) { return y1 + (((x - x1) * (y2 - y1)) / (x2 - x1)); }
|
||||
|
||||
float smooth(float sample) {
|
||||
float smooth(float sample)
|
||||
{
|
||||
h3 = h2;
|
||||
h2 = h1;
|
||||
h1 = sample;
|
||||
@@ -271,8 +233,6 @@ private:
|
||||
return (h1 + h2 + h3) / 3.f;
|
||||
}
|
||||
|
||||
size_t ms_to_samples(float ms) {
|
||||
return static_cast<size_t>(ms * samplerate / 1000.f);
|
||||
}
|
||||
size_t ms_to_samples(float ms) { return static_cast<size_t>(ms * samplerate / 1000.f); }
|
||||
};
|
||||
}
|
||||
} // namespace trnr
|
||||
@@ -1,13 +1,13 @@
|
||||
#pragma once
|
||||
#include "tx_sineosc.h"
|
||||
#include "tx_envelope.h"
|
||||
#include "tx_sineosc.h"
|
||||
|
||||
namespace trnr {
|
||||
class tx_operator {
|
||||
public:
|
||||
tx_operator()
|
||||
: ratio { 1 }
|
||||
, amplitude { 1.0f }
|
||||
: ratio {1}
|
||||
, amplitude {1.0f}
|
||||
{
|
||||
}
|
||||
|
||||
@@ -16,7 +16,9 @@ public:
|
||||
float ratio;
|
||||
float amplitude;
|
||||
|
||||
float process_sample(const bool& gate, const bool& trigger, const float& frequency, const float& velocity, const float& pm = 0) {
|
||||
float process_sample(const bool& gate, const bool& trigger, const float& frequency, const float& velocity,
|
||||
const float& pm = 0)
|
||||
{
|
||||
|
||||
float env = envelope.process_sample(gate, trigger);
|
||||
|
||||
@@ -29,9 +31,10 @@ public:
|
||||
}
|
||||
}
|
||||
|
||||
void set_samplerate(double samplerate) {
|
||||
void set_samplerate(double samplerate)
|
||||
{
|
||||
this->envelope.set_samplerate(samplerate);
|
||||
this->oscillator.set_samplerate(samplerate);
|
||||
}
|
||||
};
|
||||
}
|
||||
} // namespace trnr
|
||||
|
||||
@@ -8,22 +8,19 @@ public:
|
||||
bool phase_reset;
|
||||
|
||||
tx_sineosc()
|
||||
: samplerate { 44100 }
|
||||
, phase_resolution { 16.f }
|
||||
, phase { 0. }
|
||||
, history { 0. }
|
||||
, phase_reset { false }
|
||||
: samplerate {44100}
|
||||
, phase_resolution {16.f}
|
||||
, phase {0.}
|
||||
, history {0.}
|
||||
, phase_reset {false}
|
||||
{
|
||||
}
|
||||
|
||||
void set_phase_resolution(float res) {
|
||||
phase_resolution = powf(2, res);
|
||||
}
|
||||
void set_phase_resolution(float res) { phase_resolution = powf(2, res); }
|
||||
|
||||
float process_sample(bool trigger, float frequency, float phase_modulation = 0.f) {
|
||||
if (trigger && phase_reset) {
|
||||
phase = 0.0;
|
||||
}
|
||||
float process_sample(bool trigger, float frequency, float phase_modulation = 0.f)
|
||||
{
|
||||
if (trigger && phase_reset) { phase = 0.0; }
|
||||
|
||||
float lookup_phase = phase + phase_modulation;
|
||||
wrap(lookup_phase);
|
||||
@@ -38,9 +35,7 @@ public:
|
||||
return output;
|
||||
}
|
||||
|
||||
void set_samplerate(double _samplerate) {
|
||||
this->samplerate = _samplerate;
|
||||
}
|
||||
void set_samplerate(double _samplerate) { this->samplerate = _samplerate; }
|
||||
|
||||
private:
|
||||
double samplerate;
|
||||
@@ -48,7 +43,8 @@ private:
|
||||
float phase;
|
||||
float history;
|
||||
|
||||
float sine(float x) {
|
||||
float sine(float x)
|
||||
{
|
||||
// x is scaled 0<=x<4096
|
||||
const float a = -0.40319426317E-08;
|
||||
const float b = 0.21683205691E+03;
|
||||
@@ -61,26 +57,23 @@ private:
|
||||
negate = true;
|
||||
x -= 2048;
|
||||
}
|
||||
if (x > 1024)
|
||||
x = 2048 - x;
|
||||
if (x > 1024) x = 2048 - x;
|
||||
y = (a + x) / (b + c * x * x) + d * x;
|
||||
if (negate)
|
||||
return (float)(-y);
|
||||
else
|
||||
return (float)y;
|
||||
if (negate) return (float)(-y);
|
||||
else return (float)y;
|
||||
}
|
||||
|
||||
float wrap(float& phase) {
|
||||
while (phase < 0.)
|
||||
phase += 1.;
|
||||
float wrap(float& phase)
|
||||
{
|
||||
while (phase < 0.) phase += 1.;
|
||||
|
||||
while (phase >= 1.)
|
||||
phase -= 1.;
|
||||
while (phase >= 1.) phase -= 1.;
|
||||
|
||||
return phase;
|
||||
}
|
||||
|
||||
float filter(float& value) {
|
||||
float filter(float& value)
|
||||
{
|
||||
value = 0.5 * (value + history);
|
||||
history = value;
|
||||
return value;
|
||||
@@ -92,4 +85,4 @@ private:
|
||||
return value;
|
||||
}
|
||||
};
|
||||
}
|
||||
} // namespace trnr
|
||||
@@ -10,9 +10,9 @@ namespace trnr {
|
||||
class tx_voice : public ivoice {
|
||||
public:
|
||||
tx_voice()
|
||||
: algorithm { 0 }
|
||||
, pitch_env_amt { 0.f }
|
||||
, feedback_amt { 0.f }
|
||||
: algorithm {0}
|
||||
, pitch_env_amt {0.f}
|
||||
, feedback_amt {0.f}
|
||||
, bit_resolution(12.f)
|
||||
{
|
||||
}
|
||||
@@ -41,16 +41,10 @@ public:
|
||||
velocity = _velocity;
|
||||
}
|
||||
|
||||
void note_off() override
|
||||
{
|
||||
this->gate = false;
|
||||
}
|
||||
void note_off() override { this->gate = false; }
|
||||
|
||||
// modulates the pitch in semitones
|
||||
void modulate_pitch(float _pitch) override
|
||||
{
|
||||
this->pitch_mod = _pitch;
|
||||
}
|
||||
void modulate_pitch(float _pitch) override { this->pitch_mod = _pitch; }
|
||||
|
||||
float process_sample() override
|
||||
{
|
||||
@@ -84,7 +78,10 @@ public:
|
||||
return redux(output, bit_resolution);
|
||||
}
|
||||
|
||||
bool is_busy() override { return gate || op1.envelope.is_busy() || op2.envelope.is_busy() || op3.envelope.is_busy(); }
|
||||
bool is_busy() override
|
||||
{
|
||||
return gate || op1.envelope.is_busy() || op2.envelope.is_busy() || op3.envelope.is_busy();
|
||||
}
|
||||
|
||||
void set_samplerate(double samplerate) override
|
||||
{
|
||||
@@ -188,4 +185,4 @@ private:
|
||||
return value;
|
||||
}
|
||||
};
|
||||
}
|
||||
} // namespace trnr
|
||||
@@ -17,37 +17,25 @@ public:
|
||||
typedef t_voice assert_at_compile_time[is_convertible<t_voice>::value ? 1 : -1];
|
||||
}
|
||||
|
||||
void set_voice_count(const int& voice_count)
|
||||
{
|
||||
voices.resize(voice_count, voices.at(0));
|
||||
}
|
||||
void set_voice_count(const int& voice_count) { voices.resize(voice_count, voices.at(0)); }
|
||||
|
||||
void note_on(const midi_event& event)
|
||||
{
|
||||
t_voice* voice = get_free_voice(event.midi_note);
|
||||
|
||||
if (voice == nullptr) {
|
||||
voice = steal_voice();
|
||||
}
|
||||
if (voice == nullptr) { voice = steal_voice(); }
|
||||
|
||||
if (voice != nullptr) {
|
||||
voice->note_on(event.midi_note, event.velocity);
|
||||
}
|
||||
if (voice != nullptr) { voice->note_on(event.midi_note, event.velocity); }
|
||||
}
|
||||
|
||||
void note_off(const midi_event& event)
|
||||
{
|
||||
for (auto it = voices.begin(); it != voices.end(); it++) {
|
||||
if ((*it).midi_note == event.midi_note) {
|
||||
(*it).note_off();
|
||||
}
|
||||
if ((*it).midi_note == event.midi_note) { (*it).note_off(); }
|
||||
}
|
||||
}
|
||||
|
||||
void access(std::function<void(t_voice&)> f)
|
||||
{
|
||||
std::for_each(voices.begin(), voices.end(), f);
|
||||
}
|
||||
void access(std::function<void(t_voice&)> f) { std::for_each(voices.begin(), voices.end(), f); }
|
||||
|
||||
void process_samples(t_sample** _outputs, int _start_index, int _block_size)
|
||||
{
|
||||
@@ -57,19 +45,15 @@ public:
|
||||
|
||||
float voices_signal = 0.;
|
||||
|
||||
std::for_each(voices.begin(), voices.end(), [&voices_signal](t_voice& voice) {
|
||||
voices_signal += (voice.process_sample() / 3.);
|
||||
});
|
||||
std::for_each(voices.begin(), voices.end(),
|
||||
[&voices_signal](t_voice& voice) { voices_signal += (voice.process_sample() / 3.); });
|
||||
|
||||
_outputs[0][s] = voices_signal;
|
||||
_outputs[1][s] = voices_signal;
|
||||
}
|
||||
}
|
||||
|
||||
void add_event(midi_event event)
|
||||
{
|
||||
input_queue.push_back(event);
|
||||
}
|
||||
void add_event(midi_event event) { input_queue.push_back(event); }
|
||||
|
||||
bool voices_active()
|
||||
{
|
||||
@@ -85,9 +69,7 @@ public:
|
||||
|
||||
void set_samplerate(double _samplerate)
|
||||
{
|
||||
for (int i = 0; i < voices.size(); i++) {
|
||||
voices.at(i).set_samplerate(_samplerate);
|
||||
}
|
||||
for (int i = 0; i < voices.size(); i++) { voices.at(i).set_samplerate(_samplerate); }
|
||||
}
|
||||
|
||||
private:
|
||||
@@ -99,9 +81,7 @@ private:
|
||||
t_voice* voice = nullptr;
|
||||
|
||||
for (auto it = voices.begin(); it != voices.end(); it++) {
|
||||
if (!(*it).is_busy()) {
|
||||
voice = &*it;
|
||||
}
|
||||
if (!(*it).is_busy()) { voice = &*it; }
|
||||
}
|
||||
|
||||
return voice;
|
||||
@@ -160,4 +140,4 @@ private:
|
||||
}
|
||||
}
|
||||
};
|
||||
}
|
||||
} // namespace trnr
|
||||
|
||||
Reference in New Issue
Block a user