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++) {
|
||||||
|
intermediateL[x] = 0.0;
|
||||||
|
intermediateR[x] = 0.0;
|
||||||
|
}
|
||||||
// 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_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];
|
||||||
@@ -33,41 +36,59 @@ public:
|
|||||||
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 (inputSampleL < -4.0) inputSampleL = -4.0;
|
||||||
if (wasPosClipL == true) { // current will be over
|
if (wasPosClipL == true) { // current will be over
|
||||||
if (inputSampleL < lastSampleL) lastSampleL = 0.7058208 + (inputSampleL * 0.2609148);
|
if (inputSampleL < lastSampleL) lastSampleL = 0.7058208 + (inputSampleL * 0.2609148);
|
||||||
else lastSampleL = 0.2491717 + (lastSampleL * 0.7390851);
|
else lastSampleL = 0.2491717 + (lastSampleL * 0.7390851);
|
||||||
} wasPosClipL = false;
|
}
|
||||||
if (inputSampleL>0.9549925859) {wasPosClipL=true;inputSampleL=0.7058208+(lastSampleL*0.2609148);}
|
wasPosClipL = false;
|
||||||
|
if (inputSampleL > 0.9549925859) {
|
||||||
|
wasPosClipL = true;
|
||||||
|
inputSampleL = 0.7058208 + (lastSampleL * 0.2609148);
|
||||||
|
}
|
||||||
if (wasNegClipL == true) { // current will be -over
|
if (wasNegClipL == true) { // current will be -over
|
||||||
if (inputSampleL > lastSampleL) lastSampleL = -0.7058208 + (inputSampleL * 0.2609148);
|
if (inputSampleL > lastSampleL) lastSampleL = -0.7058208 + (inputSampleL * 0.2609148);
|
||||||
else lastSampleL = -0.2491717 + (lastSampleL * 0.7390851);
|
else lastSampleL = -0.2491717 + (lastSampleL * 0.7390851);
|
||||||
} wasNegClipL = false;
|
}
|
||||||
if (inputSampleL<-0.9549925859) {wasNegClipL=true;inputSampleL=-0.7058208+(lastSampleL*0.2609148);}
|
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 (inputSampleR < -4.0) inputSampleR = -4.0;
|
||||||
if (wasPosClipR == true) { // current will be over
|
if (wasPosClipR == true) { // current will be over
|
||||||
if (inputSampleR < lastSampleR) lastSampleR = 0.7058208 + (inputSampleR * 0.2609148);
|
if (inputSampleR < lastSampleR) lastSampleR = 0.7058208 + (inputSampleR * 0.2609148);
|
||||||
else lastSampleR = 0.2491717 + (lastSampleR * 0.7390851);
|
else lastSampleR = 0.2491717 + (lastSampleR * 0.7390851);
|
||||||
} wasPosClipR = false;
|
}
|
||||||
if (inputSampleR>0.9549925859) {wasPosClipR=true;inputSampleR=0.7058208+(lastSampleR*0.2609148);}
|
wasPosClipR = false;
|
||||||
|
if (inputSampleR > 0.9549925859) {
|
||||||
|
wasPosClipR = true;
|
||||||
|
inputSampleR = 0.7058208 + (lastSampleR * 0.2609148);
|
||||||
|
}
|
||||||
if (wasNegClipR == true) { // current will be -over
|
if (wasNegClipR == true) { // current will be -over
|
||||||
if (inputSampleR > lastSampleR) lastSampleR = -0.7058208 + (inputSampleR * 0.2609148);
|
if (inputSampleR > lastSampleR) lastSampleR = -0.7058208 + (inputSampleR * 0.2609148);
|
||||||
else lastSampleR = -0.2491717 + (lastSampleR * 0.7390851);
|
else lastSampleR = -0.2491717 + (lastSampleR * 0.7390851);
|
||||||
} wasNegClipR = false;
|
}
|
||||||
if (inputSampleR<-0.9549925859) {wasNegClipR=true;inputSampleR=-0.7058208+(lastSampleR*0.2609148);}
|
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];
|
||||||
@@ -97,4 +118,4 @@ private:
|
|||||||
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;
|
||||||
|
}
|
||||||
|
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.
|
// 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];
|
||||||
@@ -31,24 +36,26 @@ 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;
|
||||||
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
|
||||||
@@ -66,10 +73,14 @@ public:
|
|||||||
|
|
||||||
// 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;
|
||||||
|
fpdL ^= fpdL >> 17;
|
||||||
|
fpdL ^= fpdL << 5;
|
||||||
// inputSampleL += ((double(fpdL)-uint32_t(0x7fffffff)) * 1.1e-44l * pow(2,expon+62));
|
// inputSampleL += ((double(fpdL)-uint32_t(0x7fffffff)) * 1.1e-44l * pow(2,expon+62));
|
||||||
// frexp((double)inputSampleR, &expon);
|
// frexp((double)inputSampleR, &expon);
|
||||||
fpdR ^= fpdR << 13; fpdR ^= fpdR >> 17; fpdR ^= fpdR << 5;
|
fpdR ^= fpdR << 13;
|
||||||
|
fpdR ^= fpdR >> 17;
|
||||||
|
fpdR ^= fpdR << 5;
|
||||||
// inputSampleR += ((double(fpdR)-uint32_t(0x7fffffff)) * 1.1e-44l * pow(2,expon+62));
|
// inputSampleR += ((double(fpdR)-uint32_t(0x7fffffff)) * 1.1e-44l * pow(2,expon+62));
|
||||||
// end 64 bit stereo floating point dither
|
// end 64 bit stereo floating point dither
|
||||||
|
|
||||||
@@ -94,4 +105,4 @@ private:
|
|||||||
uint32_t fpdR;
|
uint32_t fpdR;
|
||||||
// default stuff
|
// default stuff
|
||||||
};
|
};
|
||||||
}
|
} // namespace trnr
|
||||||
@@ -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;
|
||||||
|
fpdR = 1.0;
|
||||||
|
while (fpdR < 16386) fpdR = rand() * UINT32_MAX;
|
||||||
// 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_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];
|
||||||
@@ -51,8 +49,7 @@ public:
|
|||||||
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;
|
||||||
@@ -65,9 +62,13 @@ 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;
|
||||||
|
previousSampleB = stored;
|
||||||
|
inputSampleR *= 0.5;
|
||||||
} // for high sample rates on this plugin we are going to do a simple average
|
} // 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;
|
||||||
@@ -111,9 +112,13 @@ public:
|
|||||||
|
|
||||||
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;
|
||||||
|
previousSampleD = stored;
|
||||||
|
inputSampleR *= 0.5;
|
||||||
} // for high sample rates on this plugin we are going to do a simple average
|
} // 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
|
// end original Tube. Now we have a boosted fat sound peaking at 0dB exactly
|
||||||
|
|
||||||
@@ -121,7 +126,9 @@ public:
|
|||||||
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;
|
||||||
|
previousSampleE = stored;
|
||||||
|
inputSampleL *= 0.5;
|
||||||
} else previousSampleE = inputSampleL; // for this, need previousSampleC always
|
} else previousSampleE = inputSampleL; // for this, need previousSampleC always
|
||||||
if (slew > 0.0) slew = 1.0 + (sqrt(slew) * 0.5);
|
if (slew > 0.0) slew = 1.0 + (sqrt(slew) * 0.5);
|
||||||
else slew = 1.0 - (sqrt(-slew) * 0.5);
|
else slew = 1.0 - (sqrt(-slew) * 0.5);
|
||||||
@@ -134,7 +141,9 @@ public:
|
|||||||
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;
|
||||||
|
previousSampleF = stored;
|
||||||
|
inputSampleR *= 0.5;
|
||||||
} else previousSampleF = inputSampleR; // for this, need previousSampleC always
|
} else previousSampleF = inputSampleR; // for this, need previousSampleC always
|
||||||
if (slew > 0.0) slew = 1.0 + (sqrt(slew) * 0.5);
|
if (slew > 0.0) slew = 1.0 + (sqrt(slew) * 0.5);
|
||||||
else slew = 1.0 - (sqrt(-slew) * 0.5);
|
else slew = 1.0 - (sqrt(-slew) * 0.5);
|
||||||
@@ -147,10 +156,14 @@ public:
|
|||||||
|
|
||||||
// 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;
|
||||||
|
fpdL ^= fpdL >> 17;
|
||||||
|
fpdL ^= fpdL << 5;
|
||||||
// inputSampleL += ((double(fpdL)-uint32_t(0x7fffffff)) * 1.1e-44l * pow(2,expon+62));
|
// inputSampleL += ((double(fpdL)-uint32_t(0x7fffffff)) * 1.1e-44l * pow(2,expon+62));
|
||||||
// frexp((double)inputSampleR, &expon);
|
// frexp((double)inputSampleR, &expon);
|
||||||
fpdR ^= fpdR << 13; fpdR ^= fpdR >> 17; fpdR ^= fpdR << 5;
|
fpdR ^= fpdR << 13;
|
||||||
|
fpdR ^= fpdR >> 17;
|
||||||
|
fpdR ^= fpdR << 5;
|
||||||
// inputSampleR += ((double(fpdR)-uint32_t(0x7fffffff)) * 1.1e-44l * pow(2,expon+62));
|
// inputSampleR += ((double(fpdR)-uint32_t(0x7fffffff)) * 1.1e-44l * pow(2,expon+62));
|
||||||
// end 64 bit stereo floating point dither
|
// end 64 bit stereo floating point dither
|
||||||
|
|
||||||
@@ -181,7 +194,8 @@ private:
|
|||||||
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;
|
||||||
@@ -63,7 +73,8 @@ public:
|
|||||||
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;
|
||||||
@@ -82,12 +93,16 @@ public:
|
|||||||
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;
|
||||||
@@ -45,31 +51,20 @@ public:
|
|||||||
// 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];
|
||||||
@@ -80,7 +75,8 @@ public:
|
|||||||
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;
|
||||||
@@ -91,8 +87,7 @@ public:
|
|||||||
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;
|
||||||
@@ -122,7 +117,8 @@ public:
|
|||||||
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);
|
||||||
@@ -203,33 +199,51 @@ public:
|
|||||||
// 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 (inputSampleL < -4.0) inputSampleL = -4.0;
|
||||||
if (wasPosClipL == true) { // current will be over
|
if (wasPosClipL == true) { // current will be over
|
||||||
if (inputSampleL < lastSampleL) lastSampleL = 0.7058208 + (inputSampleL * 0.2609148);
|
if (inputSampleL < lastSampleL) lastSampleL = 0.7058208 + (inputSampleL * 0.2609148);
|
||||||
else lastSampleL = 0.2491717 + (lastSampleL * 0.7390851);
|
else lastSampleL = 0.2491717 + (lastSampleL * 0.7390851);
|
||||||
} wasPosClipL = false;
|
}
|
||||||
if (inputSampleL>0.9549925859) {wasPosClipL=true;inputSampleL=0.7058208+(lastSampleL*0.2609148);}
|
wasPosClipL = false;
|
||||||
|
if (inputSampleL > 0.9549925859) {
|
||||||
|
wasPosClipL = true;
|
||||||
|
inputSampleL = 0.7058208 + (lastSampleL * 0.2609148);
|
||||||
|
}
|
||||||
if (wasNegClipL == true) { // current will be -over
|
if (wasNegClipL == true) { // current will be -over
|
||||||
if (inputSampleL > lastSampleL) lastSampleL = -0.7058208 + (inputSampleL * 0.2609148);
|
if (inputSampleL > lastSampleL) lastSampleL = -0.7058208 + (inputSampleL * 0.2609148);
|
||||||
else lastSampleL = -0.2491717 + (lastSampleL * 0.7390851);
|
else lastSampleL = -0.2491717 + (lastSampleL * 0.7390851);
|
||||||
} wasNegClipL = false;
|
}
|
||||||
if (inputSampleL<-0.9549925859) {wasNegClipL=true;inputSampleL=-0.7058208+(lastSampleL*0.2609148);}
|
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 (inputSampleR < -4.0) inputSampleR = -4.0;
|
||||||
if (wasPosClipR == true) { // current will be over
|
if (wasPosClipR == true) { // current will be over
|
||||||
if (inputSampleR < lastSampleR) lastSampleR = 0.7058208 + (inputSampleR * 0.2609148);
|
if (inputSampleR < lastSampleR) lastSampleR = 0.7058208 + (inputSampleR * 0.2609148);
|
||||||
else lastSampleR = 0.2491717 + (lastSampleR * 0.7390851);
|
else lastSampleR = 0.2491717 + (lastSampleR * 0.7390851);
|
||||||
} wasPosClipR = false;
|
}
|
||||||
if (inputSampleR>0.9549925859) {wasPosClipR=true;inputSampleR=0.7058208+(lastSampleR*0.2609148);}
|
wasPosClipR = false;
|
||||||
|
if (inputSampleR > 0.9549925859) {
|
||||||
|
wasPosClipR = true;
|
||||||
|
inputSampleR = 0.7058208 + (lastSampleR * 0.2609148);
|
||||||
|
}
|
||||||
if (wasNegClipR == true) { // current will be -over
|
if (wasNegClipR == true) { // current will be -over
|
||||||
if (inputSampleR > lastSampleR) lastSampleR = -0.7058208 + (inputSampleR * 0.2609148);
|
if (inputSampleR > lastSampleR) lastSampleR = -0.7058208 + (inputSampleR * 0.2609148);
|
||||||
else lastSampleR = -0.2491717 + (lastSampleR * 0.7390851);
|
else lastSampleR = -0.2491717 + (lastSampleR * 0.7390851);
|
||||||
} wasNegClipR = false;
|
}
|
||||||
if (inputSampleR<-0.9549925859) {wasNegClipR=true;inputSampleR=-0.7058208+(lastSampleR*0.2609148);}
|
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];
|
||||||
@@ -243,10 +257,14 @@ public:
|
|||||||
|
|
||||||
// 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;
|
||||||
|
fpdL ^= fpdL >> 17;
|
||||||
|
fpdL ^= fpdL << 5;
|
||||||
// inputSampleL += ((double(fpdL)-uint32_t(0x7fffffff)) * 1.1e-44l * pow(2,expon+62));
|
// inputSampleL += ((double(fpdL)-uint32_t(0x7fffffff)) * 1.1e-44l * pow(2,expon+62));
|
||||||
// frexp((double)inputSampleR, &expon);
|
// frexp((double)inputSampleR, &expon);
|
||||||
fpdR ^= fpdR << 13; fpdR ^= fpdR >> 17; fpdR ^= fpdR << 5;
|
fpdR ^= fpdR << 13;
|
||||||
|
fpdR ^= fpdR >> 17;
|
||||||
|
fpdR ^= fpdR << 5;
|
||||||
// inputSampleR += ((double(fpdR)-uint32_t(0x7fffffff)) * 1.1e-44l * pow(2,expon+62));
|
// inputSampleR += ((double(fpdR)-uint32_t(0x7fffffff)) * 1.1e-44l * pow(2,expon+62));
|
||||||
// end 64 bit stereo floating point dither
|
// end 64 bit stereo floating point dither
|
||||||
|
|
||||||
@@ -300,7 +318,8 @@ private:
|
|||||||
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
|
||||||
106
filter/aw_eq.h
106
filter/aw_eq.h
@@ -6,7 +6,8 @@ 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
|
||||||
@@ -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;
|
||||||
|
fpdR = 1.0;
|
||||||
|
while (fpdR < 16386) fpdR = rand() * UINT32_MAX;
|
||||||
// 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_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];
|
||||||
@@ -207,8 +193,7 @@ public:
|
|||||||
// 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;
|
||||||
@@ -226,10 +211,8 @@ public:
|
|||||||
// 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);
|
||||||
@@ -474,10 +446,8 @@ public:
|
|||||||
// 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);
|
||||||
@@ -539,10 +507,14 @@ public:
|
|||||||
|
|
||||||
// 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;
|
||||||
|
fpdL ^= fpdL >> 17;
|
||||||
|
fpdL ^= fpdL << 5;
|
||||||
// inputSampleL += ((double(fpdL)-uint32_t(0x7fffffff)) * 1.1e-44l * pow(2,expon+62));
|
// inputSampleL += ((double(fpdL)-uint32_t(0x7fffffff)) * 1.1e-44l * pow(2,expon+62));
|
||||||
// frexp((double)inputSampleR, &expon);
|
// frexp((double)inputSampleR, &expon);
|
||||||
fpdR ^= fpdR << 13; fpdR ^= fpdR >> 17; fpdR ^= fpdR << 5;
|
fpdR ^= fpdR << 13;
|
||||||
|
fpdR ^= fpdR >> 17;
|
||||||
|
fpdR ^= fpdR << 5;
|
||||||
// inputSampleR += ((double(fpdR)-uint32_t(0x7fffffff)) * 1.1e-44l * pow(2,expon+62));
|
// inputSampleR += ((double(fpdR)-uint32_t(0x7fffffff)) * 1.1e-44l * pow(2,expon+62));
|
||||||
// end 64 bit stereo floating point dither
|
// end 64 bit stereo floating point dither
|
||||||
|
|
||||||
@@ -655,7 +627,6 @@ private:
|
|||||||
int flipthree;
|
int flipthree;
|
||||||
// end EQ
|
// end EQ
|
||||||
|
|
||||||
|
|
||||||
float A;
|
float A;
|
||||||
float B;
|
float B;
|
||||||
float C;
|
float C;
|
||||||
@@ -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 {
|
||||||
@@ -21,9 +21,7 @@ public:
|
|||||||
, 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 {
|
||||||
@@ -21,9 +21,7 @@ public:
|
|||||||
, 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 {
|
||||||
@@ -21,9 +21,7 @@ public:
|
|||||||
, 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
|
||||||
114
filter/ynotch.h
114
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 {
|
||||||
@@ -21,9 +21,7 @@ public:
|
|||||||
, 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 {
|
||||||
@@ -21,62 +21,69 @@ public:
|
|||||||
, 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
|
||||||
|
|||||||
@@ -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
|
||||||
|
|||||||
@@ -35,13 +35,11 @@ public:
|
|||||||
{
|
{
|
||||||
}
|
}
|
||||||
|
|
||||||
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,6 +1,6 @@
|
|||||||
#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 {
|
||||||
@@ -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
|
||||||
|
|||||||
@@ -16,14 +16,11 @@ public:
|
|||||||
{
|
{
|
||||||
}
|
}
|
||||||
|
|
||||||
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
|
||||||
@@ -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