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