clang format
This commit is contained in:
@@ -1,2 +1,25 @@
|
||||
---
|
||||
BasedOnStyle: LLVM
|
||||
ColumnLimit: 140
|
||||
ColumnLimit: "120"
|
||||
ConstructorInitializerIndentWidth: "0"
|
||||
IndentWidth: "4"
|
||||
TabWidth: "4"
|
||||
UseTab: Always
|
||||
AccessModifierOffset: "-4"
|
||||
AllowShortIfStatementsOnASingleLine: AllIfsAndElse
|
||||
AllowShortBlocksOnASingleLine: Always
|
||||
AllowShortLoopsOnASingleLine: true
|
||||
AllowShortEnumsOnASingleLine: false
|
||||
AlwaysBreakTemplateDeclarations: Yes
|
||||
PackConstructorInitializers: Never
|
||||
BreakConstructorInitializers: BeforeComma
|
||||
PointerAlignment: Left
|
||||
ReferenceAlignment: Left
|
||||
ConstructorInitializerIndentWidth: 4
|
||||
SpaceBeforeCpp11BracedList: true
|
||||
SeparateDefinitionBlocks: Always
|
||||
|
||||
BreakBeforeBraces: WebKit
|
||||
|
||||
EmptyLineBeforeAccessModifier: LogicalBlock
|
||||
Cpp11BracedListStyle: true
|
||||
|
||||
@@ -5,7 +5,8 @@ namespace trnr {
|
||||
// Clipper based on ClipOnly2 by Chris Johnson
|
||||
class aw_cliponly2 {
|
||||
public:
|
||||
aw_cliponly2() {
|
||||
aw_cliponly2()
|
||||
{
|
||||
samplerate = 44100;
|
||||
|
||||
lastSampleL = 0.0;
|
||||
@@ -14,15 +15,17 @@ public:
|
||||
lastSampleR = 0.0;
|
||||
wasPosClipR = false;
|
||||
wasNegClipR = false;
|
||||
for (int x = 0; x < 16; x++) {intermediateL[x] = 0.0; intermediateR[x] = 0.0;}
|
||||
for (int x = 0; x < 16; x++) {
|
||||
intermediateL[x] = 0.0;
|
||||
intermediateR[x] = 0.0;
|
||||
}
|
||||
// this is reset: values being initialized only once. Startup values, whatever they are.
|
||||
}
|
||||
|
||||
void set_samplerate(double _samplerate) {
|
||||
samplerate = _samplerate;
|
||||
}
|
||||
void set_samplerate(double _samplerate) { samplerate = _samplerate; }
|
||||
|
||||
void process_block(double** inputs, double** outputs, long sample_frames) {
|
||||
void process_block(double** inputs, double** outputs, long sample_frames)
|
||||
{
|
||||
double* in1 = inputs[0];
|
||||
double* in2 = inputs[1];
|
||||
double* out1 = outputs[0];
|
||||
@@ -33,41 +36,59 @@ public:
|
||||
overallscale *= samplerate;
|
||||
|
||||
int spacing = floor(overallscale); // should give us working basic scaling, usually 2 or 4
|
||||
if (spacing < 1) spacing = 1; if (spacing > 16) spacing = 16;
|
||||
if (spacing < 1) spacing = 1;
|
||||
if (spacing > 16) spacing = 16;
|
||||
|
||||
while (--sample_frames >= 0)
|
||||
{
|
||||
while (--sample_frames >= 0) {
|
||||
double inputSampleL = *in1;
|
||||
double inputSampleR = *in2;
|
||||
|
||||
// begin ClipOnly2 stereo as a little, compressed chunk that can be dropped into code
|
||||
if (inputSampleL > 4.0) inputSampleL = 4.0; if (inputSampleL < -4.0) inputSampleL = -4.0;
|
||||
if (inputSampleL > 4.0) inputSampleL = 4.0;
|
||||
if (inputSampleL < -4.0) inputSampleL = -4.0;
|
||||
if (wasPosClipL == true) { // current will be over
|
||||
if (inputSampleL < lastSampleL) lastSampleL = 0.7058208 + (inputSampleL * 0.2609148);
|
||||
else lastSampleL = 0.2491717 + (lastSampleL * 0.7390851);
|
||||
} wasPosClipL = false;
|
||||
if (inputSampleL>0.9549925859) {wasPosClipL=true;inputSampleL=0.7058208+(lastSampleL*0.2609148);}
|
||||
}
|
||||
wasPosClipL = false;
|
||||
if (inputSampleL > 0.9549925859) {
|
||||
wasPosClipL = true;
|
||||
inputSampleL = 0.7058208 + (lastSampleL * 0.2609148);
|
||||
}
|
||||
if (wasNegClipL == true) { // current will be -over
|
||||
if (inputSampleL > lastSampleL) lastSampleL = -0.7058208 + (inputSampleL * 0.2609148);
|
||||
else lastSampleL = -0.2491717 + (lastSampleL * 0.7390851);
|
||||
} wasNegClipL = false;
|
||||
if (inputSampleL<-0.9549925859) {wasNegClipL=true;inputSampleL=-0.7058208+(lastSampleL*0.2609148);}
|
||||
}
|
||||
wasNegClipL = false;
|
||||
if (inputSampleL < -0.9549925859) {
|
||||
wasNegClipL = true;
|
||||
inputSampleL = -0.7058208 + (lastSampleL * 0.2609148);
|
||||
}
|
||||
intermediateL[spacing] = inputSampleL;
|
||||
inputSampleL = lastSampleL; // Latency is however many samples equals one 44.1k sample
|
||||
for (int x = spacing; x > 0; x--) intermediateL[x - 1] = intermediateL[x];
|
||||
lastSampleL = intermediateL[0]; // run a little buffer to handle this
|
||||
|
||||
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 (inputSampleR < lastSampleR) lastSampleR = 0.7058208 + (inputSampleR * 0.2609148);
|
||||
else lastSampleR = 0.2491717 + (lastSampleR * 0.7390851);
|
||||
} wasPosClipR = false;
|
||||
if (inputSampleR>0.9549925859) {wasPosClipR=true;inputSampleR=0.7058208+(lastSampleR*0.2609148);}
|
||||
}
|
||||
wasPosClipR = false;
|
||||
if (inputSampleR > 0.9549925859) {
|
||||
wasPosClipR = true;
|
||||
inputSampleR = 0.7058208 + (lastSampleR * 0.2609148);
|
||||
}
|
||||
if (wasNegClipR == true) { // current will be -over
|
||||
if (inputSampleR > lastSampleR) lastSampleR = -0.7058208 + (inputSampleR * 0.2609148);
|
||||
else lastSampleR = -0.2491717 + (lastSampleR * 0.7390851);
|
||||
} wasNegClipR = false;
|
||||
if (inputSampleR<-0.9549925859) {wasNegClipR=true;inputSampleR=-0.7058208+(lastSampleR*0.2609148);}
|
||||
}
|
||||
wasNegClipR = false;
|
||||
if (inputSampleR < -0.9549925859) {
|
||||
wasNegClipR = true;
|
||||
inputSampleR = -0.7058208 + (lastSampleR * 0.2609148);
|
||||
}
|
||||
intermediateR[spacing] = inputSampleR;
|
||||
inputSampleR = lastSampleR; // Latency is however many samples equals one 44.1k sample
|
||||
for (int x = spacing; x > 0; x--) intermediateR[x - 1] = intermediateR[x];
|
||||
@@ -97,4 +118,4 @@ private:
|
||||
bool wasNegClipR; // Stereo ClipOnly2
|
||||
// default stuff
|
||||
};
|
||||
}
|
||||
} // namespace trnr
|
||||
@@ -6,22 +6,27 @@ namespace trnr {
|
||||
// soft clipper based on ClipSoftly by Chris Johnson
|
||||
class aw_clipsoftly {
|
||||
public:
|
||||
aw_clipsoftly() {
|
||||
aw_clipsoftly()
|
||||
{
|
||||
samplerate = 44100;
|
||||
|
||||
lastSampleL = 0.0;
|
||||
lastSampleR = 0.0;
|
||||
for (int x = 0; x < 16; x++) {intermediateL[x] = 0.0; intermediateR[x] = 0.0;}
|
||||
fpdL = 1.0; while (fpdL < 16386) fpdL = rand()*UINT32_MAX;
|
||||
fpdR = 1.0; while (fpdR < 16386) fpdR = rand()*UINT32_MAX;
|
||||
for (int x = 0; x < 16; x++) {
|
||||
intermediateL[x] = 0.0;
|
||||
intermediateR[x] = 0.0;
|
||||
}
|
||||
fpdL = 1.0;
|
||||
while (fpdL < 16386) fpdL = rand() * UINT32_MAX;
|
||||
fpdR = 1.0;
|
||||
while (fpdR < 16386) fpdR = rand() * UINT32_MAX;
|
||||
// this is reset: values being initialized only once. Startup values, whatever they are.
|
||||
}
|
||||
|
||||
void set_samplerate(double _samplerate) {
|
||||
samplerate = _samplerate;
|
||||
}
|
||||
void set_samplerate(double _samplerate) { samplerate = _samplerate; }
|
||||
|
||||
void process_block(double** inputs, double** outputs, long sample_frames) {
|
||||
void process_block(double** inputs, double** outputs, long sample_frames)
|
||||
{
|
||||
double* in1 = inputs[0];
|
||||
double* in2 = inputs[1];
|
||||
double* out1 = outputs[0];
|
||||
@@ -31,24 +36,26 @@ public:
|
||||
overallscale /= 44100.0;
|
||||
overallscale *= samplerate;
|
||||
int spacing = floor(overallscale); // should give us working basic scaling, usually 2 or 4
|
||||
if (spacing < 1) spacing = 1; if (spacing > 16) spacing = 16;
|
||||
if (spacing < 1) spacing = 1;
|
||||
if (spacing > 16) spacing = 16;
|
||||
|
||||
while (--sample_frames >= 0)
|
||||
{
|
||||
while (--sample_frames >= 0) {
|
||||
double inputSampleL = *in1;
|
||||
double inputSampleR = *in2;
|
||||
if (fabs(inputSampleL) < 1.18e-23) inputSampleL = fpdL * 1.18e-17;
|
||||
if (fabs(inputSampleR) < 1.18e-23) inputSampleR = fpdR * 1.18e-17;
|
||||
|
||||
double softSpeed = fabs(inputSampleL);
|
||||
if (softSpeed < 1.0) softSpeed = 1.0; else softSpeed = 1.0/softSpeed;
|
||||
if (softSpeed < 1.0) softSpeed = 1.0;
|
||||
else softSpeed = 1.0 / softSpeed;
|
||||
if (inputSampleL > 1.57079633) inputSampleL = 1.57079633;
|
||||
if (inputSampleL < -1.57079633) inputSampleL = -1.57079633;
|
||||
inputSampleL = sin(inputSampleL) * 0.9549925859; // scale to what cliponly uses
|
||||
inputSampleL = (inputSampleL * softSpeed) + (lastSampleL * (1.0 - softSpeed));
|
||||
|
||||
softSpeed = fabs(inputSampleR);
|
||||
if (softSpeed < 1.0) softSpeed = 1.0; else softSpeed = 1.0/softSpeed;
|
||||
if (softSpeed < 1.0) softSpeed = 1.0;
|
||||
else softSpeed = 1.0 / softSpeed;
|
||||
if (inputSampleR > 1.57079633) inputSampleR = 1.57079633;
|
||||
if (inputSampleR < -1.57079633) inputSampleR = -1.57079633;
|
||||
inputSampleR = sin(inputSampleR) * 0.9549925859; // scale to what cliponly uses
|
||||
@@ -66,10 +73,14 @@ public:
|
||||
|
||||
// begin 64 bit stereo floating point dither
|
||||
// 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));
|
||||
// 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));
|
||||
// end 64 bit stereo floating point dither
|
||||
|
||||
@@ -94,4 +105,4 @@ private:
|
||||
uint32_t fpdR;
|
||||
// default stuff
|
||||
};
|
||||
}
|
||||
} // namespace trnr
|
||||
@@ -6,7 +6,8 @@ namespace trnr {
|
||||
// modeled tube preamp based on tube2 by Chris Johnson
|
||||
class aw_tube2 {
|
||||
public:
|
||||
aw_tube2() {
|
||||
aw_tube2()
|
||||
{
|
||||
samplerate = 44100;
|
||||
|
||||
A = 0.5;
|
||||
@@ -17,24 +18,21 @@ public:
|
||||
previousSampleD = 0.0;
|
||||
previousSampleE = 0.0;
|
||||
previousSampleF = 0.0;
|
||||
fpdL = 1.0; while (fpdL < 16386) fpdL = rand()*UINT32_MAX;
|
||||
fpdR = 1.0; while (fpdR < 16386) fpdR = rand()*UINT32_MAX;
|
||||
fpdL = 1.0;
|
||||
while (fpdL < 16386) fpdL = rand() * UINT32_MAX;
|
||||
fpdR = 1.0;
|
||||
while (fpdR < 16386) fpdR = rand() * UINT32_MAX;
|
||||
// this is reset: values being initialized only once. Startup values, whatever they are.
|
||||
}
|
||||
|
||||
void set_input(double value) {
|
||||
A = clamp(value);
|
||||
}
|
||||
void set_input(double value) { A = clamp(value); }
|
||||
|
||||
void set_tube(double value) {
|
||||
B = clamp(value);
|
||||
}
|
||||
void set_tube(double value) { B = clamp(value); }
|
||||
|
||||
void set_samplerate(double _samplerate) {
|
||||
samplerate = _samplerate;
|
||||
}
|
||||
void set_samplerate(double _samplerate) { samplerate = _samplerate; }
|
||||
|
||||
void process_block(double **inputs, double **outputs, long sampleframes) {
|
||||
void process_block(double** inputs, double** outputs, long sampleframes)
|
||||
{
|
||||
double* in1 = inputs[0];
|
||||
double* in2 = inputs[1];
|
||||
double* out1 = outputs[0];
|
||||
@@ -51,8 +49,7 @@ public:
|
||||
double gainscaling = 1.0 / (double)(powerfactor + 1);
|
||||
double outputscaling = 1.0 + (1.0 / (double)(powerfactor));
|
||||
|
||||
while (--sampleframes >= 0)
|
||||
{
|
||||
while (--sampleframes >= 0) {
|
||||
double inputSampleL = *in1;
|
||||
double inputSampleR = *in2;
|
||||
if (fabs(inputSampleL) < 1.18e-23) inputSampleL = fpdL * 1.18e-17;
|
||||
@@ -65,9 +62,13 @@ public:
|
||||
|
||||
if (overallscale > 1.9) {
|
||||
double stored = inputSampleL;
|
||||
inputSampleL += previousSampleA; previousSampleA = stored; inputSampleL *= 0.5;
|
||||
inputSampleL += previousSampleA;
|
||||
previousSampleA = stored;
|
||||
inputSampleL *= 0.5;
|
||||
stored = inputSampleR;
|
||||
inputSampleR += previousSampleB; previousSampleB = stored; inputSampleR *= 0.5;
|
||||
inputSampleR += previousSampleB;
|
||||
previousSampleB = stored;
|
||||
inputSampleR *= 0.5;
|
||||
} // for high sample rates on this plugin we are going to do a simple average
|
||||
|
||||
if (inputSampleL > 1.0) inputSampleL = 1.0;
|
||||
@@ -111,9 +112,13 @@ public:
|
||||
|
||||
if (overallscale > 1.9) {
|
||||
double stored = inputSampleL;
|
||||
inputSampleL += previousSampleC; previousSampleC = stored; inputSampleL *= 0.5;
|
||||
inputSampleL += previousSampleC;
|
||||
previousSampleC = stored;
|
||||
inputSampleL *= 0.5;
|
||||
stored = inputSampleR;
|
||||
inputSampleR += previousSampleD; previousSampleD = stored; inputSampleR *= 0.5;
|
||||
inputSampleR += previousSampleD;
|
||||
previousSampleD = stored;
|
||||
inputSampleR *= 0.5;
|
||||
} // for high sample rates on this plugin we are going to do a simple average
|
||||
// end original Tube. Now we have a boosted fat sound peaking at 0dB exactly
|
||||
|
||||
@@ -121,7 +126,9 @@ public:
|
||||
double slew = previousSampleE - inputSampleL;
|
||||
if (overallscale > 1.9) {
|
||||
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
|
||||
if (slew > 0.0) slew = 1.0 + (sqrt(slew) * 0.5);
|
||||
else slew = 1.0 - (sqrt(-slew) * 0.5);
|
||||
@@ -134,7 +141,9 @@ public:
|
||||
slew = previousSampleF - inputSampleR;
|
||||
if (overallscale > 1.9) {
|
||||
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
|
||||
if (slew > 0.0) 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
|
||||
// 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));
|
||||
// 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));
|
||||
// end 64 bit stereo floating point dither
|
||||
|
||||
@@ -181,7 +194,8 @@ private:
|
||||
float A;
|
||||
float B;
|
||||
|
||||
double clamp(double& value) {
|
||||
double clamp(double& value)
|
||||
{
|
||||
if (value > 1) {
|
||||
value = 1;
|
||||
} else if (value < 0) {
|
||||
@@ -190,4 +204,4 @@ private:
|
||||
return value;
|
||||
}
|
||||
};
|
||||
}
|
||||
} // namespace trnr
|
||||
@@ -5,7 +5,8 @@ namespace trnr {
|
||||
// mulaw companding based on code by Emilie Gillet / Mutable Instruments
|
||||
class mulaw {
|
||||
public:
|
||||
int8_t encode_samples(int16_t pcm_val) {
|
||||
int8_t encode_samples(int16_t pcm_val)
|
||||
{
|
||||
int16_t mask;
|
||||
int16_t seg;
|
||||
uint8_t uval;
|
||||
@@ -28,15 +29,15 @@ public:
|
||||
else if (pcm_val <= 0xfff) seg = 6;
|
||||
else if (pcm_val <= 0x1fff) seg = 7;
|
||||
else seg = 8;
|
||||
if (seg >= 8)
|
||||
return static_cast<uint8_t>(0x7f ^ mask);
|
||||
if (seg >= 8) return static_cast<uint8_t>(0x7f ^ mask);
|
||||
else {
|
||||
uval = static_cast<uint8_t>((seg << 4) | ((pcm_val >> (seg + 1)) & 0x0f));
|
||||
return (uval ^ mask);
|
||||
}
|
||||
}
|
||||
|
||||
int16_t decode_samples(uint8_t u_val) {
|
||||
int16_t decode_samples(uint8_t u_val)
|
||||
{
|
||||
int16_t t;
|
||||
u_val = ~u_val;
|
||||
t = ((u_val & 0xf) << 3) + 0x84;
|
||||
@@ -44,4 +45,4 @@ public:
|
||||
return ((u_val & 0x80) ? (0x84 - t) : (t - 0x84));
|
||||
}
|
||||
};
|
||||
}
|
||||
} // namespace trnr
|
||||
@@ -1,18 +1,22 @@
|
||||
#pragma once
|
||||
#include <stdlib.h>
|
||||
#include <cstdint>
|
||||
#include <cmath>
|
||||
#include <cstdint>
|
||||
#include <stdlib.h>
|
||||
|
||||
namespace trnr {
|
||||
// ulaw compansion based on code by Chris Johnson
|
||||
class ulaw {
|
||||
public:
|
||||
ulaw() {
|
||||
fpd_l = 1.0; while (fpd_l < 16386) fpd_l = rand()*UINT32_MAX;
|
||||
fpd_r = 1.0; while (fpd_r < 16386) fpd_r = rand()*UINT32_MAX;
|
||||
ulaw()
|
||||
{
|
||||
fpd_l = 1.0;
|
||||
while (fpd_l < 16386) fpd_l = rand() * UINT32_MAX;
|
||||
fpd_r = 1.0;
|
||||
while (fpd_r < 16386) fpd_r = rand() * UINT32_MAX;
|
||||
}
|
||||
|
||||
void encode_samples(double& input_sample_l, double& input_sample_r) {
|
||||
void encode_samples(double& input_sample_l, double& input_sample_r)
|
||||
{
|
||||
|
||||
// ulaw encoding
|
||||
static int noisesource_l = 0;
|
||||
@@ -20,35 +24,41 @@ public:
|
||||
int residue;
|
||||
double applyresidue;
|
||||
|
||||
noisesource_l = noisesource_l % 1700021; noisesource_l++;
|
||||
noisesource_l = noisesource_l % 1700021;
|
||||
noisesource_l++;
|
||||
residue = noisesource_l * noisesource_l;
|
||||
residue = residue % 170003; residue *= residue;
|
||||
residue = residue % 17011; residue *= residue;
|
||||
residue = residue % 1709; residue *= residue;
|
||||
residue = residue % 173; residue *= residue;
|
||||
residue = residue % 170003;
|
||||
residue *= residue;
|
||||
residue = residue % 17011;
|
||||
residue *= residue;
|
||||
residue = residue % 1709;
|
||||
residue *= residue;
|
||||
residue = residue % 173;
|
||||
residue *= residue;
|
||||
residue = residue % 17;
|
||||
applyresidue = residue;
|
||||
applyresidue *= 0.00000001;
|
||||
applyresidue *= 0.00000001;
|
||||
input_sample_l += applyresidue;
|
||||
if (input_sample_l<1.2e-38 && -input_sample_l<1.2e-38) {
|
||||
input_sample_l -= applyresidue;
|
||||
}
|
||||
if (input_sample_l < 1.2e-38 && -input_sample_l < 1.2e-38) { input_sample_l -= applyresidue; }
|
||||
|
||||
noisesource_r = noisesource_r % 1700021; noisesource_r++;
|
||||
noisesource_r = noisesource_r % 1700021;
|
||||
noisesource_r++;
|
||||
residue = noisesource_r * noisesource_r;
|
||||
residue = residue % 170003; residue *= residue;
|
||||
residue = residue % 17011; residue *= residue;
|
||||
residue = residue % 1709; residue *= residue;
|
||||
residue = residue % 173; residue *= residue;
|
||||
residue = residue % 170003;
|
||||
residue *= residue;
|
||||
residue = residue % 17011;
|
||||
residue *= residue;
|
||||
residue = residue % 1709;
|
||||
residue *= residue;
|
||||
residue = residue % 173;
|
||||
residue *= residue;
|
||||
residue = residue % 17;
|
||||
applyresidue = residue;
|
||||
applyresidue *= 0.00000001;
|
||||
applyresidue *= 0.00000001;
|
||||
input_sample_r += applyresidue;
|
||||
if (input_sample_r<1.2e-38 && -input_sample_r<1.2e-38) {
|
||||
input_sample_r -= applyresidue;
|
||||
}
|
||||
if (input_sample_r < 1.2e-38 && -input_sample_r < 1.2e-38) { input_sample_r -= applyresidue; }
|
||||
|
||||
if (input_sample_l > 1.0) input_sample_l = 1.0;
|
||||
if (input_sample_l < -1.0) input_sample_l = -1.0;
|
||||
@@ -63,7 +73,8 @@ public:
|
||||
if (input_sample_r < 0) input_sample_r = -log(1.0 + (255 * fabs(input_sample_r))) / log(256);
|
||||
}
|
||||
|
||||
void decode_samples(double& input_sample_l, double& input_sample_r) {
|
||||
void decode_samples(double& input_sample_l, double& input_sample_r)
|
||||
{
|
||||
|
||||
// ulaw decoding
|
||||
if (fabs(input_sample_l) < 1.18e-23) input_sample_l = fpd_l * 1.18e-17;
|
||||
@@ -82,12 +93,16 @@ public:
|
||||
if (input_sample_r < 0) input_sample_r = -(pow(256, fabs(input_sample_r)) - 1.0) / 255;
|
||||
|
||||
// 64 bit stereo floating point dither
|
||||
fpd_l ^= fpd_l << 13; fpd_l ^= fpd_l >> 17; fpd_l ^= fpd_l << 5;
|
||||
fpd_r ^= fpd_r << 13; fpd_r ^= fpd_r >> 17; fpd_r ^= fpd_r << 5;
|
||||
fpd_l ^= fpd_l << 13;
|
||||
fpd_l ^= fpd_l >> 17;
|
||||
fpd_l ^= fpd_l << 5;
|
||||
fpd_r ^= fpd_r << 13;
|
||||
fpd_r ^= fpd_r >> 17;
|
||||
fpd_r ^= fpd_r << 5;
|
||||
}
|
||||
|
||||
private:
|
||||
uint32_t fpd_l;
|
||||
uint32_t fpd_r;
|
||||
};
|
||||
}
|
||||
} // namespace trnr
|
||||
@@ -6,7 +6,8 @@ namespace trnr {
|
||||
// compressor based on pop2 by Chris Johnson
|
||||
class aw_pop2 {
|
||||
public:
|
||||
aw_pop2() {
|
||||
aw_pop2()
|
||||
{
|
||||
samplerate = 44100;
|
||||
|
||||
A = 0.5;
|
||||
@@ -14,8 +15,10 @@ public:
|
||||
C = 0.5;
|
||||
D = 0.5;
|
||||
E = 1.0;
|
||||
fpdL = 1.0; while (fpdL < 16386) fpdL = rand()*UINT32_MAX;
|
||||
fpdR = 1.0; while (fpdR < 16386) fpdR = rand()*UINT32_MAX;
|
||||
fpdL = 1.0;
|
||||
while (fpdL < 16386) fpdL = rand() * UINT32_MAX;
|
||||
fpdR = 1.0;
|
||||
while (fpdR < 16386) fpdR = rand() * UINT32_MAX;
|
||||
|
||||
lastSampleL = 0.0;
|
||||
wasPosClipL = false;
|
||||
@@ -23,7 +26,10 @@ public:
|
||||
lastSampleR = 0.0;
|
||||
wasPosClipR = false;
|
||||
wasNegClipR = false;
|
||||
for (int x = 0; x < 16; x++) {intermediateL[x] = 0.0; intermediateR[x] = 0.0;}
|
||||
for (int x = 0; x < 16; x++) {
|
||||
intermediateL[x] = 0.0;
|
||||
intermediateR[x] = 0.0;
|
||||
}
|
||||
|
||||
muVaryL = 0.0;
|
||||
muAttackL = 0.0;
|
||||
@@ -45,31 +51,20 @@ public:
|
||||
// this is reset: values being initialized only once. Startup values, whatever they are.
|
||||
}
|
||||
|
||||
void set_compression(double value) {
|
||||
A = clamp(value);
|
||||
}
|
||||
void set_compression(double value) { A = clamp(value); }
|
||||
|
||||
void set_attack(double value) {
|
||||
B = clamp(value);
|
||||
}
|
||||
void set_attack(double value) { B = clamp(value); }
|
||||
|
||||
void set_release(double value) {
|
||||
C = clamp(value);
|
||||
}
|
||||
void set_release(double value) { C = clamp(value); }
|
||||
|
||||
void set_drive(double value) {
|
||||
D = clamp(value);
|
||||
}
|
||||
void set_drive(double value) { D = clamp(value); }
|
||||
|
||||
void set_drywet(double value) {
|
||||
E = clamp(value);
|
||||
}
|
||||
void set_drywet(double value) { E = clamp(value); }
|
||||
|
||||
void set_samplerate(double _samplerate) {
|
||||
samplerate = _samplerate;
|
||||
}
|
||||
void set_samplerate(double _samplerate) { samplerate = _samplerate; }
|
||||
|
||||
void process_block(double **inputs, double **outputs, long sampleframes) {
|
||||
void process_block(double** inputs, double** outputs, long sampleframes)
|
||||
{
|
||||
double* in1 = inputs[0];
|
||||
double* in2 = inputs[1];
|
||||
double* out1 = outputs[0];
|
||||
@@ -80,7 +75,8 @@ public:
|
||||
overallscale *= samplerate;
|
||||
|
||||
int spacing = floor(overallscale); // should give us working basic scaling, usually 2 or 4
|
||||
if (spacing < 1) spacing = 1; if (spacing > 16) spacing = 16;
|
||||
if (spacing < 1) spacing = 1;
|
||||
if (spacing > 16) spacing = 16;
|
||||
|
||||
double threshold = 1.0 - ((1.0 - pow(1.0 - A, 2)) * 0.9);
|
||||
double attack = ((pow(B, 4) * 100000.0) + 10.0) * overallscale;
|
||||
@@ -91,8 +87,7 @@ public:
|
||||
double wet = E;
|
||||
// compressor section
|
||||
|
||||
while (--sampleframes >= 0)
|
||||
{
|
||||
while (--sampleframes >= 0) {
|
||||
double inputSampleL = *in1;
|
||||
double inputSampleR = *in2;
|
||||
if (fabs(inputSampleL) < 1.18e-23) inputSampleL = fpdL * 1.18e-17;
|
||||
@@ -122,7 +117,8 @@ public:
|
||||
muCoefficientAL = muCoefficientAL / (muSpeedAL * muSpeedAL);
|
||||
muNewSpeedL = muSpeedAL * (muSpeedAL - 1.0);
|
||||
muNewSpeedL = muNewSpeedL + attack;
|
||||
muSpeedAL = muNewSpeedL / muSpeedAL;}
|
||||
muSpeedAL = muNewSpeedL / muSpeedAL;
|
||||
}
|
||||
} else {
|
||||
if (fabs(inputSampleL) > threshold) {
|
||||
muVaryL = threshold / fabs(inputSampleL);
|
||||
@@ -203,33 +199,51 @@ public:
|
||||
// end compressor section
|
||||
|
||||
// begin ClipOnly2 stereo as a little, compressed chunk that can be dropped into code
|
||||
if (inputSampleL > 4.0) inputSampleL = 4.0; if (inputSampleL < -4.0) inputSampleL = -4.0;
|
||||
if (inputSampleL > 4.0) inputSampleL = 4.0;
|
||||
if (inputSampleL < -4.0) inputSampleL = -4.0;
|
||||
if (wasPosClipL == true) { // current will be over
|
||||
if (inputSampleL < lastSampleL) lastSampleL = 0.7058208 + (inputSampleL * 0.2609148);
|
||||
else lastSampleL = 0.2491717 + (lastSampleL * 0.7390851);
|
||||
} wasPosClipL = false;
|
||||
if (inputSampleL>0.9549925859) {wasPosClipL=true;inputSampleL=0.7058208+(lastSampleL*0.2609148);}
|
||||
}
|
||||
wasPosClipL = false;
|
||||
if (inputSampleL > 0.9549925859) {
|
||||
wasPosClipL = true;
|
||||
inputSampleL = 0.7058208 + (lastSampleL * 0.2609148);
|
||||
}
|
||||
if (wasNegClipL == true) { // current will be -over
|
||||
if (inputSampleL > lastSampleL) lastSampleL = -0.7058208 + (inputSampleL * 0.2609148);
|
||||
else lastSampleL = -0.2491717 + (lastSampleL * 0.7390851);
|
||||
} wasNegClipL = false;
|
||||
if (inputSampleL<-0.9549925859) {wasNegClipL=true;inputSampleL=-0.7058208+(lastSampleL*0.2609148);}
|
||||
}
|
||||
wasNegClipL = false;
|
||||
if (inputSampleL < -0.9549925859) {
|
||||
wasNegClipL = true;
|
||||
inputSampleL = -0.7058208 + (lastSampleL * 0.2609148);
|
||||
}
|
||||
intermediateL[spacing] = inputSampleL;
|
||||
inputSampleL = lastSampleL; // Latency is however many samples equals one 44.1k sample
|
||||
for (int x = spacing; x > 0; x--) intermediateL[x - 1] = intermediateL[x];
|
||||
lastSampleL = intermediateL[0]; // run a little buffer to handle this
|
||||
|
||||
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 (inputSampleR < lastSampleR) lastSampleR = 0.7058208 + (inputSampleR * 0.2609148);
|
||||
else lastSampleR = 0.2491717 + (lastSampleR * 0.7390851);
|
||||
} wasPosClipR = false;
|
||||
if (inputSampleR>0.9549925859) {wasPosClipR=true;inputSampleR=0.7058208+(lastSampleR*0.2609148);}
|
||||
}
|
||||
wasPosClipR = false;
|
||||
if (inputSampleR > 0.9549925859) {
|
||||
wasPosClipR = true;
|
||||
inputSampleR = 0.7058208 + (lastSampleR * 0.2609148);
|
||||
}
|
||||
if (wasNegClipR == true) { // current will be -over
|
||||
if (inputSampleR > lastSampleR) lastSampleR = -0.7058208 + (inputSampleR * 0.2609148);
|
||||
else lastSampleR = -0.2491717 + (lastSampleR * 0.7390851);
|
||||
} wasNegClipR = false;
|
||||
if (inputSampleR<-0.9549925859) {wasNegClipR=true;inputSampleR=-0.7058208+(lastSampleR*0.2609148);}
|
||||
}
|
||||
wasNegClipR = false;
|
||||
if (inputSampleR < -0.9549925859) {
|
||||
wasNegClipR = true;
|
||||
inputSampleR = -0.7058208 + (lastSampleR * 0.2609148);
|
||||
}
|
||||
intermediateR[spacing] = inputSampleR;
|
||||
inputSampleR = lastSampleR; // Latency is however many samples equals one 44.1k sample
|
||||
for (int x = spacing; x > 0; x--) intermediateR[x - 1] = intermediateR[x];
|
||||
@@ -243,10 +257,14 @@ public:
|
||||
|
||||
// begin 64 bit stereo floating point dither
|
||||
// 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));
|
||||
// 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));
|
||||
// end 64 bit stereo floating point dither
|
||||
|
||||
@@ -300,7 +318,8 @@ private:
|
||||
float D;
|
||||
float E; // parameters. Always 0-1, and we scale/alter them elsewhere.
|
||||
|
||||
double clamp(double& value) {
|
||||
double clamp(double& value)
|
||||
{
|
||||
if (value > 1) {
|
||||
value = 1;
|
||||
} else if (value < 0) {
|
||||
@@ -309,4 +328,4 @@ private:
|
||||
return value;
|
||||
}
|
||||
};
|
||||
}
|
||||
} // namespace trnr
|
||||
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.
|
||||
class aw_eq {
|
||||
public:
|
||||
aw_eq() {
|
||||
aw_eq()
|
||||
{
|
||||
samplerate = 44100;
|
||||
|
||||
A = 0.5; // Treble -12 to 12
|
||||
@@ -108,48 +109,33 @@ public:
|
||||
flip = false;
|
||||
flipthree = 0;
|
||||
|
||||
fpdL = 1.0; while (fpdL < 16386) fpdL = rand()*UINT32_MAX;
|
||||
fpdR = 1.0; while (fpdR < 16386) fpdR = rand()*UINT32_MAX;
|
||||
fpdL = 1.0;
|
||||
while (fpdL < 16386) fpdL = rand() * UINT32_MAX;
|
||||
fpdR = 1.0;
|
||||
while (fpdR < 16386) fpdR = rand() * UINT32_MAX;
|
||||
// this is reset: values being initialized only once. Startup values, whatever they are.
|
||||
}
|
||||
|
||||
void set_treble(double value) {
|
||||
A = clamp(value);
|
||||
}
|
||||
void set_treble(double value) { A = clamp(value); }
|
||||
|
||||
void set_mid(double value) {
|
||||
B = clamp(value);
|
||||
}
|
||||
void set_mid(double value) { B = clamp(value); }
|
||||
|
||||
void set_bass(double value) {
|
||||
C = clamp(value);
|
||||
}
|
||||
void set_bass(double value) { C = clamp(value); }
|
||||
|
||||
void set_lowpass(double value) {
|
||||
D = clamp(value);
|
||||
}
|
||||
void set_lowpass(double value) { D = clamp(value); }
|
||||
|
||||
void set_treble_frq(double value) {
|
||||
E = clamp(value);
|
||||
}
|
||||
void set_treble_frq(double value) { E = clamp(value); }
|
||||
|
||||
void set_bass_frq(double value) {
|
||||
F = clamp(value);
|
||||
}
|
||||
void set_bass_frq(double value) { F = clamp(value); }
|
||||
|
||||
void set_hipass(double value) {
|
||||
G = clamp(value);
|
||||
}
|
||||
void set_hipass(double value) { G = clamp(value); }
|
||||
|
||||
void set_out_gain(double value) {
|
||||
H = clamp(value);
|
||||
}
|
||||
void set_out_gain(double value) { H = clamp(value); }
|
||||
|
||||
void set_samplerate(double _samplerate) {
|
||||
samplerate = _samplerate;
|
||||
}
|
||||
void set_samplerate(double _samplerate) { samplerate = _samplerate; }
|
||||
|
||||
void process_block(double **inputs, double **outputs, long sampleframes) {
|
||||
void process_block(double** inputs, double** outputs, long sampleframes)
|
||||
{
|
||||
|
||||
double* in1 = inputs[0];
|
||||
double* in2 = inputs[1];
|
||||
@@ -207,8 +193,7 @@ public:
|
||||
// end EQ
|
||||
double outputgain = pow(10.0, ((H * 36.0) - 18.0) / 20.0);
|
||||
|
||||
while (--sampleframes >= 0)
|
||||
{
|
||||
while (--sampleframes >= 0) {
|
||||
inputSampleL = *in1;
|
||||
inputSampleR = *in2;
|
||||
if (fabs(inputSampleL) < 1.18e-23) inputSampleL = fpdL * 1.18e-17;
|
||||
@@ -226,10 +211,8 @@ public:
|
||||
// counters
|
||||
|
||||
// begin highpass
|
||||
if (engageHighpass)
|
||||
{
|
||||
if (flip)
|
||||
{
|
||||
if (engageHighpass) {
|
||||
if (flip) {
|
||||
highpassSampleLAA = (highpassSampleLAA * (1.0 - iirAmountD)) + (inputSampleL * iirAmountD);
|
||||
inputSampleL -= highpassSampleLAA;
|
||||
highpassSampleLBA = (highpassSampleLBA * (1.0 - iirAmountD)) + (inputSampleL * iirAmountD);
|
||||
@@ -238,9 +221,7 @@ public:
|
||||
inputSampleL -= highpassSampleLCA;
|
||||
highpassSampleLDA = (highpassSampleLDA * (1.0 - iirAmountD)) + (inputSampleL * iirAmountD);
|
||||
inputSampleL -= highpassSampleLDA;
|
||||
}
|
||||
else
|
||||
{
|
||||
} else {
|
||||
highpassSampleLAB = (highpassSampleLAB * (1.0 - iirAmountD)) + (inputSampleL * iirAmountD);
|
||||
inputSampleL -= highpassSampleLAB;
|
||||
highpassSampleLBB = (highpassSampleLBB * (1.0 - iirAmountD)) + (inputSampleL * iirAmountD);
|
||||
@@ -255,8 +236,7 @@ public:
|
||||
highpassSampleLF = (highpassSampleLF * (1.0 - iirAmountD)) + (inputSampleL * iirAmountD);
|
||||
inputSampleL -= highpassSampleLF;
|
||||
|
||||
if (flip)
|
||||
{
|
||||
if (flip) {
|
||||
highpassSampleRAA = (highpassSampleRAA * (1.0 - iirAmountD)) + (inputSampleR * iirAmountD);
|
||||
inputSampleR -= highpassSampleRAA;
|
||||
highpassSampleRBA = (highpassSampleRBA * (1.0 - iirAmountD)) + (inputSampleR * iirAmountD);
|
||||
@@ -265,9 +245,7 @@ public:
|
||||
inputSampleR -= highpassSampleRCA;
|
||||
highpassSampleRDA = (highpassSampleRDA * (1.0 - iirAmountD)) + (inputSampleR * iirAmountD);
|
||||
inputSampleR -= highpassSampleRDA;
|
||||
}
|
||||
else
|
||||
{
|
||||
} else {
|
||||
highpassSampleRAB = (highpassSampleRAB * (1.0 - iirAmountD)) + (inputSampleR * iirAmountD);
|
||||
inputSampleR -= highpassSampleRAB;
|
||||
highpassSampleRBB = (highpassSampleRBB * (1.0 - iirAmountD)) + (inputSampleR * iirAmountD);
|
||||
@@ -281,15 +259,12 @@ public:
|
||||
inputSampleR -= highpassSampleRE;
|
||||
highpassSampleRF = (highpassSampleRF * (1 - iirAmountD)) + (inputSampleR * iirAmountD);
|
||||
inputSampleR -= highpassSampleRF;
|
||||
|
||||
}
|
||||
// end highpass
|
||||
|
||||
// begin EQ
|
||||
if (engageEQ)
|
||||
{
|
||||
switch (flipthree)
|
||||
{
|
||||
if (engageEQ) {
|
||||
switch (flipthree) {
|
||||
case 1:
|
||||
tripletFactorL = last2SampleL - inputSampleL;
|
||||
tripletLA += tripletFactorL;
|
||||
@@ -358,8 +333,7 @@ public:
|
||||
tripletRC /= 2.0;
|
||||
highSampleR = highSampleR + tripletFactorR;
|
||||
|
||||
if (flip)
|
||||
{
|
||||
if (flip) {
|
||||
iirHighSampleLA = (iirHighSampleLA * (1.0 - iirAmountA)) + (highSampleL * iirAmountA);
|
||||
highSampleL -= iirHighSampleLA;
|
||||
iirLowSampleLA = (iirLowSampleLA * (1.0 - iirAmountB)) + (bassSampleL * iirAmountB);
|
||||
@@ -369,9 +343,7 @@ public:
|
||||
highSampleR -= iirHighSampleRA;
|
||||
iirLowSampleRA = (iirLowSampleRA * (1.0 - iirAmountB)) + (bassSampleR * iirAmountB);
|
||||
bassSampleR = iirLowSampleRA;
|
||||
}
|
||||
else
|
||||
{
|
||||
} else {
|
||||
iirHighSampleLB = (iirHighSampleLB * (1.0 - iirAmountA)) + (highSampleL * iirAmountA);
|
||||
highSampleL -= iirHighSampleLB;
|
||||
iirLowSampleLB = (iirLowSampleLB * (1.0 - iirAmountB)) + (bassSampleL * iirAmountB);
|
||||
@@ -474,10 +446,8 @@ public:
|
||||
// end EQ
|
||||
|
||||
// EQ lowpass is after all processing like the compressor that might produce hash
|
||||
if (engageLowpass)
|
||||
{
|
||||
if (flip)
|
||||
{
|
||||
if (engageLowpass) {
|
||||
if (flip) {
|
||||
lowpassSampleLAA = (lowpassSampleLAA * (1.0 - iirAmountC)) + (inputSampleL * iirAmountC);
|
||||
inputSampleL = lowpassSampleLAA;
|
||||
lowpassSampleLBA = (lowpassSampleLBA * (1.0 - iirAmountC)) + (inputSampleL * iirAmountC);
|
||||
@@ -499,9 +469,7 @@ public:
|
||||
inputSampleR = lowpassSampleRDA;
|
||||
lowpassSampleRE = (lowpassSampleRE * (1.0 - iirAmountC)) + (inputSampleR * iirAmountC);
|
||||
inputSampleR = lowpassSampleRE;
|
||||
}
|
||||
else
|
||||
{
|
||||
} else {
|
||||
lowpassSampleLAB = (lowpassSampleLAB * (1.0 - iirAmountC)) + (inputSampleL * iirAmountC);
|
||||
inputSampleL = lowpassSampleLAB;
|
||||
lowpassSampleLBB = (lowpassSampleLBB * (1.0 - iirAmountC)) + (inputSampleL * iirAmountC);
|
||||
@@ -539,10 +507,14 @@ public:
|
||||
|
||||
// begin 64 bit stereo floating point dither
|
||||
// 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));
|
||||
// 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));
|
||||
// end 64 bit stereo floating point dither
|
||||
|
||||
@@ -655,7 +627,6 @@ private:
|
||||
int flipthree;
|
||||
// end EQ
|
||||
|
||||
|
||||
float A;
|
||||
float B;
|
||||
float C;
|
||||
@@ -665,7 +636,8 @@ private:
|
||||
float G;
|
||||
float H;
|
||||
|
||||
double clamp(double& value) {
|
||||
double clamp(double& value)
|
||||
{
|
||||
if (value > 1) {
|
||||
value = 1;
|
||||
} else if (value < 0) {
|
||||
@@ -674,4 +646,4 @@ private:
|
||||
return value;
|
||||
}
|
||||
};
|
||||
}
|
||||
} // namespace trnr
|
||||
@@ -1,20 +1,17 @@
|
||||
#pragma once
|
||||
#define _USE_MATH_DEFINES
|
||||
#include <math.h>
|
||||
#include <array>
|
||||
#include <math.h>
|
||||
|
||||
namespace trnr {
|
||||
class chebyshev {
|
||||
public:
|
||||
void set_samplerate(double _samplerate) {
|
||||
samplerate = _samplerate;
|
||||
}
|
||||
void set_samplerate(double _samplerate) { samplerate = _samplerate; }
|
||||
|
||||
void process_sample(double& input, double frequency) {
|
||||
void process_sample(double& input, double frequency)
|
||||
{
|
||||
|
||||
if (frequency >= 20000.f) {
|
||||
frequency = 20000.f;
|
||||
}
|
||||
if (frequency >= 20000.f) { frequency = 20000.f; }
|
||||
|
||||
// First calculate the prewarped digital frequency :
|
||||
auto K = tanf(M_PI * frequency / samplerate);
|
||||
@@ -77,4 +74,4 @@ private:
|
||||
double state3 = 0;
|
||||
double passband_ripple = 1;
|
||||
};
|
||||
}
|
||||
} // namespace trnr
|
||||
@@ -1,7 +1,7 @@
|
||||
#pragma once
|
||||
#define _USE_MATH_DEFINES
|
||||
#include <math.h>
|
||||
#include <array>
|
||||
#include <math.h>
|
||||
#include <vector>
|
||||
|
||||
namespace trnr {
|
||||
@@ -21,9 +21,7 @@ public:
|
||||
, fpdR {0}
|
||||
, biquad {0}
|
||||
{
|
||||
for (int x = 0; x < biq_total; x++) {
|
||||
biquad[x] = 0.0;
|
||||
}
|
||||
for (int x = 0; x < biq_total; x++) { biquad[x] = 0.0; }
|
||||
powFactorA = 1.0;
|
||||
powFactorB = 1.0;
|
||||
inTrimA = 0.1;
|
||||
@@ -36,41 +34,25 @@ public:
|
||||
}
|
||||
|
||||
fpdL = 1.0;
|
||||
while (fpdL < 16386)
|
||||
fpdL = rand() * UINT32_MAX;
|
||||
while (fpdL < 16386) fpdL = rand() * UINT32_MAX;
|
||||
fpdR = 1.0;
|
||||
while (fpdR < 16386)
|
||||
fpdR = rand() * UINT32_MAX;
|
||||
while (fpdR < 16386) fpdR = rand() * UINT32_MAX;
|
||||
}
|
||||
|
||||
void set_samplerate(double _samplerate) {
|
||||
samplerate = _samplerate;
|
||||
}
|
||||
void set_samplerate(double _samplerate) { samplerate = _samplerate; }
|
||||
|
||||
void set_drive(float value) { A = value * 0.9 + 0.1; }
|
||||
|
||||
void set_frequency(float value) { B = value; }
|
||||
|
||||
void set_resonance(float value) { C = value; }
|
||||
|
||||
void set_edge(float value) { D = value; }
|
||||
|
||||
void set_output(float value) { E = value; }
|
||||
|
||||
void set_mix(float value) { F = value; }
|
||||
|
||||
void set_drive(float value)
|
||||
{
|
||||
A = value * 0.9 + 0.1;
|
||||
}
|
||||
void set_frequency(float value)
|
||||
{
|
||||
B = value;
|
||||
}
|
||||
void set_resonance(float value)
|
||||
{
|
||||
C = value;
|
||||
}
|
||||
void set_edge(float value)
|
||||
{
|
||||
D = value;
|
||||
}
|
||||
void set_output(float value)
|
||||
{
|
||||
E = value;
|
||||
}
|
||||
void set_mix(float value)
|
||||
{
|
||||
F = value;
|
||||
}
|
||||
void processblock(t_sample** inputs, t_sample** outputs, int blockSize)
|
||||
{
|
||||
t_sample* in1 = inputs[0];
|
||||
@@ -87,8 +69,7 @@ public:
|
||||
inTrimB = A * 10.0;
|
||||
|
||||
biquad[biq_freq] = pow(B, 3) * 20000.0;
|
||||
if (biquad[biq_freq] < 15.0)
|
||||
biquad[biq_freq] = 15.0;
|
||||
if (biquad[biq_freq] < 15.0) biquad[biq_freq] = 15.0;
|
||||
biquad[biq_freq] /= samplerate;
|
||||
biquad[biq_reso] = (pow(C, 2) * 15.0) + 0.5571;
|
||||
biquad[biq_aA0] = biquad[biq_aB0];
|
||||
@@ -132,10 +113,8 @@ public:
|
||||
for (int s = 0; s < blockSize; s++) {
|
||||
double inputSampleL = *in1;
|
||||
double inputSampleR = *in2;
|
||||
if (fabs(inputSampleL) < 1.18e-23)
|
||||
inputSampleL = fpdL * 1.18e-17;
|
||||
if (fabs(inputSampleR) < 1.18e-23)
|
||||
inputSampleR = fpdR * 1.18e-17;
|
||||
if (fabs(inputSampleL) < 1.18e-23) inputSampleL = fpdL * 1.18e-17;
|
||||
if (fabs(inputSampleR) < 1.18e-23) inputSampleR = fpdR * 1.18e-17;
|
||||
double drySampleL = inputSampleL;
|
||||
double drySampleR = inputSampleR;
|
||||
|
||||
@@ -163,22 +142,14 @@ public:
|
||||
inputSampleR = temp; // fixed biquad filtering ultrasonics
|
||||
|
||||
// encode/decode courtesy of torridgristle under the MIT license
|
||||
if (inputSampleL > 1.0)
|
||||
inputSampleL = 1.0;
|
||||
else if (inputSampleL > 0.0)
|
||||
inputSampleL = 1.0 - pow(1.0 - inputSampleL, powFactor);
|
||||
if (inputSampleL < -1.0)
|
||||
inputSampleL = -1.0;
|
||||
else if (inputSampleL < 0.0)
|
||||
inputSampleL = -1.0 + pow(1.0 + inputSampleL, powFactor);
|
||||
if (inputSampleR > 1.0)
|
||||
inputSampleR = 1.0;
|
||||
else if (inputSampleR > 0.0)
|
||||
inputSampleR = 1.0 - pow(1.0 - inputSampleR, powFactor);
|
||||
if (inputSampleR < -1.0)
|
||||
inputSampleR = -1.0;
|
||||
else if (inputSampleR < 0.0)
|
||||
inputSampleR = -1.0 + pow(1.0 + inputSampleR, powFactor);
|
||||
if (inputSampleL > 1.0) inputSampleL = 1.0;
|
||||
else if (inputSampleL > 0.0) inputSampleL = 1.0 - pow(1.0 - inputSampleL, powFactor);
|
||||
if (inputSampleL < -1.0) inputSampleL = -1.0;
|
||||
else if (inputSampleL < 0.0) inputSampleL = -1.0 + pow(1.0 + inputSampleL, powFactor);
|
||||
if (inputSampleR > 1.0) inputSampleR = 1.0;
|
||||
else if (inputSampleR > 0.0) inputSampleR = 1.0 - pow(1.0 - inputSampleR, powFactor);
|
||||
if (inputSampleR < -1.0) inputSampleR = -1.0;
|
||||
else if (inputSampleR < 0.0) inputSampleR = -1.0 + pow(1.0 + inputSampleR, powFactor);
|
||||
|
||||
temp = (inputSampleL * biquad[biq_a0]) + biquad[biq_sL1];
|
||||
biquad[biq_sL1] = -(temp * biquad[biq_b1]) + biquad[biq_sL2];
|
||||
@@ -190,22 +161,14 @@ public:
|
||||
inputSampleR = temp; // coefficient interpolating biquad filter
|
||||
|
||||
// encode/decode courtesy of torridgristle under the MIT license
|
||||
if (inputSampleL > 1.0)
|
||||
inputSampleL = 1.0;
|
||||
else if (inputSampleL > 0.0)
|
||||
inputSampleL = 1.0 - pow(1.0 - inputSampleL, (1.0 / powFactor));
|
||||
if (inputSampleL < -1.0)
|
||||
inputSampleL = -1.0;
|
||||
else if (inputSampleL < 0.0)
|
||||
inputSampleL = -1.0 + pow(1.0 + inputSampleL, (1.0 / powFactor));
|
||||
if (inputSampleR > 1.0)
|
||||
inputSampleR = 1.0;
|
||||
else if (inputSampleR > 0.0)
|
||||
inputSampleR = 1.0 - pow(1.0 - inputSampleR, (1.0 / powFactor));
|
||||
if (inputSampleR < -1.0)
|
||||
inputSampleR = -1.0;
|
||||
else if (inputSampleR < 0.0)
|
||||
inputSampleR = -1.0 + pow(1.0 + inputSampleR, (1.0 / powFactor));
|
||||
if (inputSampleL > 1.0) inputSampleL = 1.0;
|
||||
else if (inputSampleL > 0.0) inputSampleL = 1.0 - pow(1.0 - inputSampleL, (1.0 / powFactor));
|
||||
if (inputSampleL < -1.0) inputSampleL = -1.0;
|
||||
else if (inputSampleL < 0.0) inputSampleL = -1.0 + pow(1.0 + inputSampleL, (1.0 / powFactor));
|
||||
if (inputSampleR > 1.0) inputSampleR = 1.0;
|
||||
else if (inputSampleR > 0.0) inputSampleR = 1.0 - pow(1.0 - inputSampleR, (1.0 / powFactor));
|
||||
if (inputSampleR < -1.0) inputSampleR = -1.0;
|
||||
else if (inputSampleR < 0.0) inputSampleR = -1.0 + pow(1.0 + inputSampleR, (1.0 / powFactor));
|
||||
|
||||
inputSampleL *= outTrim;
|
||||
inputSampleR *= outTrim;
|
||||
@@ -250,6 +213,7 @@ public:
|
||||
|
||||
private:
|
||||
double samplerate;
|
||||
|
||||
enum {
|
||||
biq_freq,
|
||||
biq_reso,
|
||||
@@ -274,6 +238,7 @@ private:
|
||||
biq_sR2,
|
||||
biq_total
|
||||
}; // coefficient interpolating biquad filter, stereo
|
||||
|
||||
std::array<double, biq_total> biquad;
|
||||
|
||||
double powFactorA;
|
||||
@@ -297,6 +262,7 @@ private:
|
||||
fix_sR2,
|
||||
fix_total
|
||||
}; // fixed frequency biquad filter for ultrasonics, stereo
|
||||
|
||||
std::array<double, fix_total> fixA;
|
||||
std::array<double, fix_total> fixB;
|
||||
|
||||
@@ -311,4 +277,4 @@ private:
|
||||
float E;
|
||||
float F; // parameters. Always 0-1, and we scale/alter them elsewhere.
|
||||
};
|
||||
}
|
||||
} // namespace trnr
|
||||
@@ -1,7 +1,7 @@
|
||||
#pragma once
|
||||
#define _USE_MATH_DEFINES
|
||||
#include <math.h>
|
||||
#include <array>
|
||||
#include <math.h>
|
||||
#include <vector>
|
||||
|
||||
namespace trnr {
|
||||
@@ -21,9 +21,7 @@ public:
|
||||
, fpdR {0}
|
||||
, biquad {0}
|
||||
{
|
||||
for (int x = 0; x < biq_total; x++) {
|
||||
biquad[x] = 0.0;
|
||||
}
|
||||
for (int x = 0; x < biq_total; x++) { biquad[x] = 0.0; }
|
||||
powFactorA = 1.0;
|
||||
powFactorB = 1.0;
|
||||
inTrimA = 0.1;
|
||||
@@ -36,41 +34,25 @@ public:
|
||||
}
|
||||
|
||||
fpdL = 1.0;
|
||||
while (fpdL < 16386)
|
||||
fpdL = rand() * UINT32_MAX;
|
||||
while (fpdL < 16386) fpdL = rand() * UINT32_MAX;
|
||||
fpdR = 1.0;
|
||||
while (fpdR < 16386)
|
||||
fpdR = rand() * UINT32_MAX;
|
||||
while (fpdR < 16386) fpdR = rand() * UINT32_MAX;
|
||||
}
|
||||
|
||||
void set_samplerate(double _samplerate) {
|
||||
samplerate = _samplerate;
|
||||
}
|
||||
void set_samplerate(double _samplerate) { samplerate = _samplerate; }
|
||||
|
||||
void set_drive(float value) { A = value * 0.9 + 0.1; }
|
||||
|
||||
void set_frequency(float value) { B = value; }
|
||||
|
||||
void set_resonance(float value) { C = value; }
|
||||
|
||||
void set_edge(float value) { D = value; }
|
||||
|
||||
void set_output(float value) { E = value; }
|
||||
|
||||
void set_mix(float value) { F = value; }
|
||||
|
||||
void set_drive(float value)
|
||||
{
|
||||
A = value * 0.9 + 0.1;
|
||||
}
|
||||
void set_frequency(float value)
|
||||
{
|
||||
B = value;
|
||||
}
|
||||
void set_resonance(float value)
|
||||
{
|
||||
C = value;
|
||||
}
|
||||
void set_edge(float value)
|
||||
{
|
||||
D = value;
|
||||
}
|
||||
void set_output(float value)
|
||||
{
|
||||
E = value;
|
||||
}
|
||||
void set_mix(float value)
|
||||
{
|
||||
F = value;
|
||||
}
|
||||
void processblock(t_sample** inputs, t_sample** outputs, int blockSize)
|
||||
{
|
||||
t_sample* in1 = inputs[0];
|
||||
@@ -87,8 +69,7 @@ public:
|
||||
inTrimB = A * 10.0;
|
||||
|
||||
biquad[biq_freq] = pow(B, 3) * 20000.0;
|
||||
if (biquad[biq_freq] < 15.0)
|
||||
biquad[biq_freq] = 15.0;
|
||||
if (biquad[biq_freq] < 15.0) biquad[biq_freq] = 15.0;
|
||||
biquad[biq_freq] /= samplerate;
|
||||
biquad[biq_reso] = (pow(C, 2) * 15.0) + 0.5571;
|
||||
biquad[biq_aA0] = biquad[biq_aB0];
|
||||
@@ -132,10 +113,8 @@ public:
|
||||
for (int s = 0; s < blockSize; s++) {
|
||||
double inputSampleL = *in1;
|
||||
double inputSampleR = *in2;
|
||||
if (fabs(inputSampleL) < 1.18e-23)
|
||||
inputSampleL = fpdL * 1.18e-17;
|
||||
if (fabs(inputSampleR) < 1.18e-23)
|
||||
inputSampleR = fpdR * 1.18e-17;
|
||||
if (fabs(inputSampleL) < 1.18e-23) inputSampleL = fpdL * 1.18e-17;
|
||||
if (fabs(inputSampleR) < 1.18e-23) inputSampleR = fpdR * 1.18e-17;
|
||||
double drySampleL = inputSampleL;
|
||||
double drySampleR = inputSampleR;
|
||||
|
||||
@@ -163,22 +142,14 @@ public:
|
||||
inputSampleR = temp; // fixed biquad filtering ultrasonics
|
||||
|
||||
// encode/decode courtesy of torridgristle under the MIT license
|
||||
if (inputSampleL > 1.0)
|
||||
inputSampleL = 1.0;
|
||||
else if (inputSampleL > 0.0)
|
||||
inputSampleL = 1.0 - pow(1.0 - inputSampleL, powFactor);
|
||||
if (inputSampleL < -1.0)
|
||||
inputSampleL = -1.0;
|
||||
else if (inputSampleL < 0.0)
|
||||
inputSampleL = -1.0 + pow(1.0 + inputSampleL, powFactor);
|
||||
if (inputSampleR > 1.0)
|
||||
inputSampleR = 1.0;
|
||||
else if (inputSampleR > 0.0)
|
||||
inputSampleR = 1.0 - pow(1.0 - inputSampleR, powFactor);
|
||||
if (inputSampleR < -1.0)
|
||||
inputSampleR = -1.0;
|
||||
else if (inputSampleR < 0.0)
|
||||
inputSampleR = -1.0 + pow(1.0 + inputSampleR, powFactor);
|
||||
if (inputSampleL > 1.0) inputSampleL = 1.0;
|
||||
else if (inputSampleL > 0.0) inputSampleL = 1.0 - pow(1.0 - inputSampleL, powFactor);
|
||||
if (inputSampleL < -1.0) inputSampleL = -1.0;
|
||||
else if (inputSampleL < 0.0) inputSampleL = -1.0 + pow(1.0 + inputSampleL, powFactor);
|
||||
if (inputSampleR > 1.0) inputSampleR = 1.0;
|
||||
else if (inputSampleR > 0.0) inputSampleR = 1.0 - pow(1.0 - inputSampleR, powFactor);
|
||||
if (inputSampleR < -1.0) inputSampleR = -1.0;
|
||||
else if (inputSampleR < 0.0) inputSampleR = -1.0 + pow(1.0 + inputSampleR, powFactor);
|
||||
|
||||
temp = (inputSampleL * biquad[biq_a0]) + biquad[biq_sL1];
|
||||
biquad[biq_sL1] = (inputSampleL * biquad[biq_a1]) - (temp * biquad[biq_b1]) + biquad[biq_sL2];
|
||||
@@ -190,22 +161,14 @@ public:
|
||||
inputSampleR = temp; // coefficient interpolating biquad filter
|
||||
|
||||
// encode/decode courtesy of torridgristle under the MIT license
|
||||
if (inputSampleL > 1.0)
|
||||
inputSampleL = 1.0;
|
||||
else if (inputSampleL > 0.0)
|
||||
inputSampleL = 1.0 - pow(1.0 - inputSampleL, (1.0 / powFactor));
|
||||
if (inputSampleL < -1.0)
|
||||
inputSampleL = -1.0;
|
||||
else if (inputSampleL < 0.0)
|
||||
inputSampleL = -1.0 + pow(1.0 + inputSampleL, (1.0 / powFactor));
|
||||
if (inputSampleR > 1.0)
|
||||
inputSampleR = 1.0;
|
||||
else if (inputSampleR > 0.0)
|
||||
inputSampleR = 1.0 - pow(1.0 - inputSampleR, (1.0 / powFactor));
|
||||
if (inputSampleR < -1.0)
|
||||
inputSampleR = -1.0;
|
||||
else if (inputSampleR < 0.0)
|
||||
inputSampleR = -1.0 + pow(1.0 + inputSampleR, (1.0 / powFactor));
|
||||
if (inputSampleL > 1.0) inputSampleL = 1.0;
|
||||
else if (inputSampleL > 0.0) inputSampleL = 1.0 - pow(1.0 - inputSampleL, (1.0 / powFactor));
|
||||
if (inputSampleL < -1.0) inputSampleL = -1.0;
|
||||
else if (inputSampleL < 0.0) inputSampleL = -1.0 + pow(1.0 + inputSampleL, (1.0 / powFactor));
|
||||
if (inputSampleR > 1.0) inputSampleR = 1.0;
|
||||
else if (inputSampleR > 0.0) inputSampleR = 1.0 - pow(1.0 - inputSampleR, (1.0 / powFactor));
|
||||
if (inputSampleR < -1.0) inputSampleR = -1.0;
|
||||
else if (inputSampleR < 0.0) inputSampleR = -1.0 + pow(1.0 + inputSampleR, (1.0 / powFactor));
|
||||
|
||||
inputSampleL *= outTrim;
|
||||
inputSampleR *= outTrim;
|
||||
@@ -250,6 +213,7 @@ public:
|
||||
|
||||
private:
|
||||
double samplerate;
|
||||
|
||||
enum {
|
||||
biq_freq,
|
||||
biq_reso,
|
||||
@@ -274,6 +238,7 @@ private:
|
||||
biq_sR2,
|
||||
biq_total
|
||||
}; // coefficient interpolating biquad filter, stereo
|
||||
|
||||
std::array<double, biq_total> biquad;
|
||||
|
||||
double powFactorA;
|
||||
@@ -297,6 +262,7 @@ private:
|
||||
fix_sR2,
|
||||
fix_total
|
||||
}; // fixed frequency biquad filter for ultrasonics, stereo
|
||||
|
||||
std::array<double, fix_total> fixA;
|
||||
std::array<double, fix_total> fixB;
|
||||
|
||||
@@ -311,4 +277,4 @@ private:
|
||||
float E;
|
||||
float F; // parameters. Always 0-1, and we scale/alter them elsewhere.
|
||||
};
|
||||
}
|
||||
} // namespace trnr
|
||||
@@ -1,7 +1,7 @@
|
||||
#pragma once
|
||||
#define _USE_MATH_DEFINES
|
||||
#include <math.h>
|
||||
#include <array>
|
||||
#include <math.h>
|
||||
#include <vector>
|
||||
|
||||
namespace trnr {
|
||||
@@ -21,9 +21,7 @@ public:
|
||||
, fpdR {0}
|
||||
, biquad {0}
|
||||
{
|
||||
for (int x = 0; x < biq_total; x++) {
|
||||
biquad[x] = 0.0;
|
||||
}
|
||||
for (int x = 0; x < biq_total; x++) { biquad[x] = 0.0; }
|
||||
powFactorA = 1.0;
|
||||
powFactorB = 1.0;
|
||||
inTrimA = 0.1;
|
||||
@@ -36,41 +34,25 @@ public:
|
||||
}
|
||||
|
||||
fpdL = 1.0;
|
||||
while (fpdL < 16386)
|
||||
fpdL = rand() * UINT32_MAX;
|
||||
while (fpdL < 16386) fpdL = rand() * UINT32_MAX;
|
||||
fpdR = 1.0;
|
||||
while (fpdR < 16386)
|
||||
fpdR = rand() * UINT32_MAX;
|
||||
while (fpdR < 16386) fpdR = rand() * UINT32_MAX;
|
||||
}
|
||||
|
||||
void set_samplerate(double _samplerate) {
|
||||
samplerate = _samplerate;
|
||||
}
|
||||
void set_samplerate(double _samplerate) { samplerate = _samplerate; }
|
||||
|
||||
void set_drive(float value) { A = value * 0.9 + 0.1; }
|
||||
|
||||
void set_frequency(float value) { B = value; }
|
||||
|
||||
void set_resonance(float value) { C = value; }
|
||||
|
||||
void set_edge(float value) { D = value; }
|
||||
|
||||
void set_output(float value) { E = value; }
|
||||
|
||||
void set_mix(float value) { F = value; }
|
||||
|
||||
void set_drive(float value)
|
||||
{
|
||||
A = value * 0.9 + 0.1;
|
||||
}
|
||||
void set_frequency(float value)
|
||||
{
|
||||
B = value;
|
||||
}
|
||||
void set_resonance(float value)
|
||||
{
|
||||
C = value;
|
||||
}
|
||||
void set_edge(float value)
|
||||
{
|
||||
D = value;
|
||||
}
|
||||
void set_output(float value)
|
||||
{
|
||||
E = value;
|
||||
}
|
||||
void set_mix(float value)
|
||||
{
|
||||
F = value;
|
||||
}
|
||||
void processblock(t_sample** inputs, t_sample** outputs, int blockSize)
|
||||
{
|
||||
t_sample* in1 = inputs[0];
|
||||
@@ -87,8 +69,7 @@ public:
|
||||
inTrimB = A * 10.0;
|
||||
|
||||
biquad[biq_freq] = pow(B, 3) * 20000.0;
|
||||
if (biquad[biq_freq] < 15.0)
|
||||
biquad[biq_freq] = 15.0;
|
||||
if (biquad[biq_freq] < 15.0) biquad[biq_freq] = 15.0;
|
||||
biquad[biq_freq] /= samplerate;
|
||||
biquad[biq_reso] = (pow(C, 2) * 15.0) + 0.5571;
|
||||
biquad[biq_aA0] = biquad[biq_aB0];
|
||||
@@ -132,10 +113,8 @@ public:
|
||||
for (int s = 0; s < blockSize; s++) {
|
||||
double inputSampleL = *in1;
|
||||
double inputSampleR = *in2;
|
||||
if (fabs(inputSampleL) < 1.18e-23)
|
||||
inputSampleL = fpdL * 1.18e-17;
|
||||
if (fabs(inputSampleR) < 1.18e-23)
|
||||
inputSampleR = fpdR * 1.18e-17;
|
||||
if (fabs(inputSampleL) < 1.18e-23) inputSampleL = fpdL * 1.18e-17;
|
||||
if (fabs(inputSampleR) < 1.18e-23) inputSampleR = fpdR * 1.18e-17;
|
||||
double drySampleL = inputSampleL;
|
||||
double drySampleR = inputSampleR;
|
||||
|
||||
@@ -163,22 +142,14 @@ public:
|
||||
inputSampleR = temp; // fixed biquad filtering ultrasonics
|
||||
|
||||
// encode/decode courtesy of torridgristle under the MIT license
|
||||
if (inputSampleL > 1.0)
|
||||
inputSampleL = 1.0;
|
||||
else if (inputSampleL > 0.0)
|
||||
inputSampleL = 1.0 - pow(1.0 - inputSampleL, powFactor);
|
||||
if (inputSampleL < -1.0)
|
||||
inputSampleL = -1.0;
|
||||
else if (inputSampleL < 0.0)
|
||||
inputSampleL = -1.0 + pow(1.0 + inputSampleL, powFactor);
|
||||
if (inputSampleR > 1.0)
|
||||
inputSampleR = 1.0;
|
||||
else if (inputSampleR > 0.0)
|
||||
inputSampleR = 1.0 - pow(1.0 - inputSampleR, powFactor);
|
||||
if (inputSampleR < -1.0)
|
||||
inputSampleR = -1.0;
|
||||
else if (inputSampleR < 0.0)
|
||||
inputSampleR = -1.0 + pow(1.0 + inputSampleR, powFactor);
|
||||
if (inputSampleL > 1.0) inputSampleL = 1.0;
|
||||
else if (inputSampleL > 0.0) inputSampleL = 1.0 - pow(1.0 - inputSampleL, powFactor);
|
||||
if (inputSampleL < -1.0) inputSampleL = -1.0;
|
||||
else if (inputSampleL < 0.0) inputSampleL = -1.0 + pow(1.0 + inputSampleL, powFactor);
|
||||
if (inputSampleR > 1.0) inputSampleR = 1.0;
|
||||
else if (inputSampleR > 0.0) inputSampleR = 1.0 - pow(1.0 - inputSampleR, powFactor);
|
||||
if (inputSampleR < -1.0) inputSampleR = -1.0;
|
||||
else if (inputSampleR < 0.0) inputSampleR = -1.0 + pow(1.0 + inputSampleR, powFactor);
|
||||
|
||||
temp = (inputSampleL * biquad[biq_a0]) + biquad[biq_sL1];
|
||||
biquad[biq_sL1] = (inputSampleL * biquad[biq_a1]) - (temp * biquad[biq_b1]) + biquad[biq_sL2];
|
||||
@@ -190,22 +161,14 @@ public:
|
||||
inputSampleR = temp; // coefficient interpolating biquad filter
|
||||
|
||||
// encode/decode courtesy of torridgristle under the MIT license
|
||||
if (inputSampleL > 1.0)
|
||||
inputSampleL = 1.0;
|
||||
else if (inputSampleL > 0.0)
|
||||
inputSampleL = 1.0 - pow(1.0 - inputSampleL, (1.0 / powFactor));
|
||||
if (inputSampleL < -1.0)
|
||||
inputSampleL = -1.0;
|
||||
else if (inputSampleL < 0.0)
|
||||
inputSampleL = -1.0 + pow(1.0 + inputSampleL, (1.0 / powFactor));
|
||||
if (inputSampleR > 1.0)
|
||||
inputSampleR = 1.0;
|
||||
else if (inputSampleR > 0.0)
|
||||
inputSampleR = 1.0 - pow(1.0 - inputSampleR, (1.0 / powFactor));
|
||||
if (inputSampleR < -1.0)
|
||||
inputSampleR = -1.0;
|
||||
else if (inputSampleR < 0.0)
|
||||
inputSampleR = -1.0 + pow(1.0 + inputSampleR, (1.0 / powFactor));
|
||||
if (inputSampleL > 1.0) inputSampleL = 1.0;
|
||||
else if (inputSampleL > 0.0) inputSampleL = 1.0 - pow(1.0 - inputSampleL, (1.0 / powFactor));
|
||||
if (inputSampleL < -1.0) inputSampleL = -1.0;
|
||||
else if (inputSampleL < 0.0) inputSampleL = -1.0 + pow(1.0 + inputSampleL, (1.0 / powFactor));
|
||||
if (inputSampleR > 1.0) inputSampleR = 1.0;
|
||||
else if (inputSampleR > 0.0) inputSampleR = 1.0 - pow(1.0 - inputSampleR, (1.0 / powFactor));
|
||||
if (inputSampleR < -1.0) inputSampleR = -1.0;
|
||||
else if (inputSampleR < 0.0) inputSampleR = -1.0 + pow(1.0 + inputSampleR, (1.0 / powFactor));
|
||||
|
||||
inputSampleL *= outTrim;
|
||||
inputSampleR *= outTrim;
|
||||
@@ -250,6 +213,7 @@ public:
|
||||
|
||||
private:
|
||||
double samplerate;
|
||||
|
||||
enum {
|
||||
biq_freq,
|
||||
biq_reso,
|
||||
@@ -274,6 +238,7 @@ private:
|
||||
biq_sR2,
|
||||
biq_total
|
||||
}; // coefficient interpolating biquad filter, stereo
|
||||
|
||||
std::array<double, biq_total> biquad;
|
||||
|
||||
double powFactorA;
|
||||
@@ -297,6 +262,7 @@ private:
|
||||
fix_sR2,
|
||||
fix_total
|
||||
}; // fixed frequency biquad filter for ultrasonics, stereo
|
||||
|
||||
std::array<double, fix_total> fixA;
|
||||
std::array<double, fix_total> fixB;
|
||||
|
||||
@@ -311,4 +277,4 @@ private:
|
||||
float E;
|
||||
float F; // parameters. Always 0-1, and we scale/alter them elsewhere.
|
||||
};
|
||||
}
|
||||
} // namespace trnr
|
||||
114
filter/ynotch.h
114
filter/ynotch.h
@@ -1,7 +1,7 @@
|
||||
#pragma once
|
||||
#define _USE_MATH_DEFINES
|
||||
#include <math.h>
|
||||
#include <array>
|
||||
#include <math.h>
|
||||
#include <vector>
|
||||
|
||||
namespace trnr {
|
||||
@@ -21,9 +21,7 @@ public:
|
||||
, fpdR {0}
|
||||
, biquad {0}
|
||||
{
|
||||
for (int x = 0; x < biq_total; x++) {
|
||||
biquad[x] = 0.0;
|
||||
}
|
||||
for (int x = 0; x < biq_total; x++) { biquad[x] = 0.0; }
|
||||
powFactorA = 1.0;
|
||||
powFactorB = 1.0;
|
||||
inTrimA = 0.1;
|
||||
@@ -36,41 +34,25 @@ public:
|
||||
}
|
||||
|
||||
fpdL = 1.0;
|
||||
while (fpdL < 16386)
|
||||
fpdL = rand() * UINT32_MAX;
|
||||
while (fpdL < 16386) fpdL = rand() * UINT32_MAX;
|
||||
fpdR = 1.0;
|
||||
while (fpdR < 16386)
|
||||
fpdR = rand() * UINT32_MAX;
|
||||
while (fpdR < 16386) fpdR = rand() * UINT32_MAX;
|
||||
}
|
||||
|
||||
void set_samplerate(double _samplerate) {
|
||||
samplerate = _samplerate;
|
||||
}
|
||||
void set_samplerate(double _samplerate) { samplerate = _samplerate; }
|
||||
|
||||
void set_drive(float value) { A = value * 0.9 + 0.1; }
|
||||
|
||||
void set_frequency(float value) { B = value; }
|
||||
|
||||
void set_resonance(float value) { C = value; }
|
||||
|
||||
void set_edge(float value) { D = value; }
|
||||
|
||||
void set_output(float value) { E = value; }
|
||||
|
||||
void set_mix(float value) { F = value; }
|
||||
|
||||
void set_drive(float value)
|
||||
{
|
||||
A = value * 0.9 + 0.1;
|
||||
}
|
||||
void set_frequency(float value)
|
||||
{
|
||||
B = value;
|
||||
}
|
||||
void set_resonance(float value)
|
||||
{
|
||||
C = value;
|
||||
}
|
||||
void set_edge(float value)
|
||||
{
|
||||
D = value;
|
||||
}
|
||||
void set_output(float value)
|
||||
{
|
||||
E = value;
|
||||
}
|
||||
void set_mix(float value)
|
||||
{
|
||||
F = value;
|
||||
}
|
||||
void processblock(t_sample** inputs, t_sample** outputs, int blockSize)
|
||||
{
|
||||
t_sample* in1 = inputs[0];
|
||||
@@ -87,8 +69,7 @@ public:
|
||||
inTrimB = A * 10.0;
|
||||
|
||||
biquad[biq_freq] = pow(B, 3) * 20000.0;
|
||||
if (biquad[biq_freq] < 15.0)
|
||||
biquad[biq_freq] = 15.0;
|
||||
if (biquad[biq_freq] < 15.0) biquad[biq_freq] = 15.0;
|
||||
biquad[biq_freq] /= samplerate;
|
||||
biquad[biq_reso] = (pow(C, 2) * 15.0) + 0.0001;
|
||||
biquad[biq_aA0] = biquad[biq_aB0];
|
||||
@@ -132,10 +113,8 @@ public:
|
||||
for (int s = 0; s < blockSize; s++) {
|
||||
double inputSampleL = *in1;
|
||||
double inputSampleR = *in2;
|
||||
if (fabs(inputSampleL) < 1.18e-23)
|
||||
inputSampleL = fpdL * 1.18e-17;
|
||||
if (fabs(inputSampleR) < 1.18e-23)
|
||||
inputSampleR = fpdR * 1.18e-17;
|
||||
if (fabs(inputSampleL) < 1.18e-23) inputSampleL = fpdL * 1.18e-17;
|
||||
if (fabs(inputSampleR) < 1.18e-23) inputSampleR = fpdR * 1.18e-17;
|
||||
double drySampleL = inputSampleL;
|
||||
double drySampleR = inputSampleR;
|
||||
|
||||
@@ -163,22 +142,14 @@ public:
|
||||
inputSampleR = temp; // fixed biquad filtering ultrasonics
|
||||
|
||||
// encode/decode courtesy of torridgristle under the MIT license
|
||||
if (inputSampleL > 1.0)
|
||||
inputSampleL = 1.0;
|
||||
else if (inputSampleL > 0.0)
|
||||
inputSampleL = 1.0 - pow(1.0 - inputSampleL, powFactor);
|
||||
if (inputSampleL < -1.0)
|
||||
inputSampleL = -1.0;
|
||||
else if (inputSampleL < 0.0)
|
||||
inputSampleL = -1.0 + pow(1.0 + inputSampleL, powFactor);
|
||||
if (inputSampleR > 1.0)
|
||||
inputSampleR = 1.0;
|
||||
else if (inputSampleR > 0.0)
|
||||
inputSampleR = 1.0 - pow(1.0 - inputSampleR, powFactor);
|
||||
if (inputSampleR < -1.0)
|
||||
inputSampleR = -1.0;
|
||||
else if (inputSampleR < 0.0)
|
||||
inputSampleR = -1.0 + pow(1.0 + inputSampleR, powFactor);
|
||||
if (inputSampleL > 1.0) inputSampleL = 1.0;
|
||||
else if (inputSampleL > 0.0) inputSampleL = 1.0 - pow(1.0 - inputSampleL, powFactor);
|
||||
if (inputSampleL < -1.0) inputSampleL = -1.0;
|
||||
else if (inputSampleL < 0.0) inputSampleL = -1.0 + pow(1.0 + inputSampleL, powFactor);
|
||||
if (inputSampleR > 1.0) inputSampleR = 1.0;
|
||||
else if (inputSampleR > 0.0) inputSampleR = 1.0 - pow(1.0 - inputSampleR, powFactor);
|
||||
if (inputSampleR < -1.0) inputSampleR = -1.0;
|
||||
else if (inputSampleR < 0.0) inputSampleR = -1.0 + pow(1.0 + inputSampleR, powFactor);
|
||||
|
||||
temp = (inputSampleL * biquad[biq_a0]) + biquad[biq_sL1];
|
||||
biquad[biq_sL1] = (inputSampleL * biquad[biq_a1]) - (temp * biquad[biq_b1]) + biquad[biq_sL2];
|
||||
@@ -190,22 +161,14 @@ public:
|
||||
inputSampleR = temp; // coefficient interpolating biquad filter
|
||||
|
||||
// encode/decode courtesy of torridgristle under the MIT license
|
||||
if (inputSampleL > 1.0)
|
||||
inputSampleL = 1.0;
|
||||
else if (inputSampleL > 0.0)
|
||||
inputSampleL = 1.0 - pow(1.0 - inputSampleL, (1.0 / powFactor));
|
||||
if (inputSampleL < -1.0)
|
||||
inputSampleL = -1.0;
|
||||
else if (inputSampleL < 0.0)
|
||||
inputSampleL = -1.0 + pow(1.0 + inputSampleL, (1.0 / powFactor));
|
||||
if (inputSampleR > 1.0)
|
||||
inputSampleR = 1.0;
|
||||
else if (inputSampleR > 0.0)
|
||||
inputSampleR = 1.0 - pow(1.0 - inputSampleR, (1.0 / powFactor));
|
||||
if (inputSampleR < -1.0)
|
||||
inputSampleR = -1.0;
|
||||
else if (inputSampleR < 0.0)
|
||||
inputSampleR = -1.0 + pow(1.0 + inputSampleR, (1.0 / powFactor));
|
||||
if (inputSampleL > 1.0) inputSampleL = 1.0;
|
||||
else if (inputSampleL > 0.0) inputSampleL = 1.0 - pow(1.0 - inputSampleL, (1.0 / powFactor));
|
||||
if (inputSampleL < -1.0) inputSampleL = -1.0;
|
||||
else if (inputSampleL < 0.0) inputSampleL = -1.0 + pow(1.0 + inputSampleL, (1.0 / powFactor));
|
||||
if (inputSampleR > 1.0) inputSampleR = 1.0;
|
||||
else if (inputSampleR > 0.0) inputSampleR = 1.0 - pow(1.0 - inputSampleR, (1.0 / powFactor));
|
||||
if (inputSampleR < -1.0) inputSampleR = -1.0;
|
||||
else if (inputSampleR < 0.0) inputSampleR = -1.0 + pow(1.0 + inputSampleR, (1.0 / powFactor));
|
||||
|
||||
inputSampleL *= outTrim;
|
||||
inputSampleR *= outTrim;
|
||||
@@ -250,6 +213,7 @@ public:
|
||||
|
||||
private:
|
||||
double samplerate;
|
||||
|
||||
enum {
|
||||
biq_freq,
|
||||
biq_reso,
|
||||
@@ -274,6 +238,7 @@ private:
|
||||
biq_sR2,
|
||||
biq_total
|
||||
}; // coefficient interpolating biquad filter, stereo
|
||||
|
||||
std::array<double, biq_total> biquad;
|
||||
|
||||
double powFactorA;
|
||||
@@ -297,6 +262,7 @@ private:
|
||||
fix_sR2,
|
||||
fix_total
|
||||
}; // fixed frequency biquad filter for ultrasonics, stereo
|
||||
|
||||
std::array<double, fix_total> fixA;
|
||||
std::array<double, fix_total> fixB;
|
||||
|
||||
@@ -311,4 +277,4 @@ private:
|
||||
float E;
|
||||
float F; // parameters. Always 0-1, and we scale/alter them elsewhere.
|
||||
};
|
||||
}
|
||||
} // namespace trnr
|
||||
@@ -1,7 +1,7 @@
|
||||
#pragma once
|
||||
#include "ylowpass.h"
|
||||
#include "yhighpass.h"
|
||||
#include "ybandpass.h"
|
||||
#include "yhighpass.h"
|
||||
#include "ylowpass.h"
|
||||
#include "ynotch.h"
|
||||
|
||||
namespace trnr {
|
||||
@@ -21,62 +21,69 @@ public:
|
||||
, highpass {_samplerate}
|
||||
, bandpass {_samplerate}
|
||||
, notch {_samplerate}
|
||||
{}
|
||||
{
|
||||
}
|
||||
|
||||
void set_samplerate(double _samplerate) {
|
||||
void set_samplerate(double _samplerate)
|
||||
{
|
||||
lowpass.set_samplerate(_samplerate);
|
||||
highpass.set_samplerate(_samplerate);
|
||||
bandpass.set_samplerate(_samplerate);
|
||||
notch.set_samplerate(_samplerate);
|
||||
}
|
||||
|
||||
void set_filter_type(filter_types type) {
|
||||
filter_type = type;
|
||||
}
|
||||
void set_filter_type(filter_types type) { filter_type = type; }
|
||||
|
||||
void set_drive(float value) {
|
||||
void set_drive(float value)
|
||||
{
|
||||
lowpass.set_drive(value);
|
||||
highpass.set_drive(value);
|
||||
bandpass.set_drive(value);
|
||||
notch.set_drive(value);
|
||||
}
|
||||
|
||||
void set_frequency(float value) {
|
||||
void set_frequency(float value)
|
||||
{
|
||||
lowpass.set_frequency(value);
|
||||
highpass.set_frequency(value);
|
||||
bandpass.set_frequency(value);
|
||||
notch.set_frequency(value);
|
||||
}
|
||||
|
||||
void set_resonance(float value) {
|
||||
void set_resonance(float value)
|
||||
{
|
||||
lowpass.set_resonance(value);
|
||||
highpass.set_resonance(value);
|
||||
bandpass.set_resonance(value);
|
||||
notch.set_resonance(value);
|
||||
}
|
||||
|
||||
void set_edge(float value) {
|
||||
void set_edge(float value)
|
||||
{
|
||||
lowpass.set_edge(value);
|
||||
highpass.set_edge(value);
|
||||
bandpass.set_edge(value);
|
||||
notch.set_edge(value);
|
||||
}
|
||||
|
||||
void set_output(float value) {
|
||||
void set_output(float value)
|
||||
{
|
||||
lowpass.set_output(value);
|
||||
highpass.set_output(value);
|
||||
bandpass.set_output(value);
|
||||
notch.set_output(value);
|
||||
}
|
||||
|
||||
void set_mix(float value) {
|
||||
void set_mix(float value)
|
||||
{
|
||||
lowpass.set_mix(value);
|
||||
highpass.set_mix(value);
|
||||
bandpass.set_mix(value);
|
||||
notch.set_mix(value);
|
||||
}
|
||||
|
||||
void process_block(t_sample** inputs, t_sample** outputs, int block_size) {
|
||||
void process_block(t_sample** inputs, t_sample** outputs, int block_size)
|
||||
{
|
||||
|
||||
switch (filter_type) {
|
||||
case filter_types::lowpass:
|
||||
@@ -101,7 +108,8 @@ private:
|
||||
ybandpass<t_sample> bandpass;
|
||||
ynotch<t_sample> notch;
|
||||
|
||||
double clamp(double& value, double min, double max) {
|
||||
double clamp(double& value, double min, double max)
|
||||
{
|
||||
if (value < min) {
|
||||
value = min;
|
||||
} else if (value > max) {
|
||||
@@ -110,4 +118,4 @@ private:
|
||||
return value;
|
||||
}
|
||||
};
|
||||
}
|
||||
} // namespace trnr
|
||||
@@ -22,4 +22,4 @@ struct is_convertible {
|
||||
|
||||
static const bool value = sizeof(test<ivoice>(static_cast<derived*>(0))) == 1;
|
||||
};
|
||||
}
|
||||
} // namespace trnr
|
||||
@@ -45,4 +45,4 @@ public:
|
||||
data = _mod;
|
||||
}
|
||||
};
|
||||
}
|
||||
} // namespace trnr
|
||||
|
||||
@@ -35,15 +35,14 @@ public:
|
||||
|
||||
while (samples_remaining > 0) {
|
||||
|
||||
if (samples_remaining < block_size)
|
||||
block_size = samples_remaining;
|
||||
if (samples_remaining < block_size) block_size = samples_remaining;
|
||||
|
||||
while (!m_event_queue.empty()) {
|
||||
midi_event event = m_event_queue.front();
|
||||
|
||||
// we assume the messages are in chronological order. If we find one later than the current block we are done.
|
||||
if (event.offset > start_index + block_size)
|
||||
break;
|
||||
// we assume the messages are in chronological order. If we find one later than the current block we
|
||||
// are done.
|
||||
if (event.offset > start_index + block_size) break;
|
||||
|
||||
// send performance messages to the voice allocator
|
||||
// message offset is relative to the start of this process_samples() block
|
||||
@@ -72,17 +71,14 @@ public:
|
||||
|
||||
void add_event(midi_event event)
|
||||
{
|
||||
if (event.type == midi_event_type::note_on)
|
||||
m_voices_active = true;
|
||||
if (event.type == midi_event_type::note_on) m_voices_active = true;
|
||||
|
||||
m_event_queue.push_back(event);
|
||||
}
|
||||
|
||||
void flush_event_queue(int frames)
|
||||
{
|
||||
for (int i = 0; i < m_event_queue.size(); i++) {
|
||||
m_event_queue.at(i).offset -= frames;
|
||||
}
|
||||
for (int i = 0; i < m_event_queue.size(); i++) { m_event_queue.at(i).offset -= frames; }
|
||||
}
|
||||
|
||||
private:
|
||||
@@ -90,4 +86,4 @@ private:
|
||||
int m_block_size;
|
||||
bool m_voices_active;
|
||||
};
|
||||
}
|
||||
} // namespace trnr
|
||||
|
||||
@@ -35,13 +35,11 @@ public:
|
||||
{
|
||||
}
|
||||
|
||||
float process_sample(bool gate, bool trigger) {
|
||||
|
||||
return process_sample<float>(gate, trigger, 0, 0);
|
||||
}
|
||||
float process_sample(bool gate, bool trigger) { return process_sample<float>(gate, trigger, 0, 0); }
|
||||
|
||||
template <typename t_sample>
|
||||
float process_sample(bool gate, bool trigger, t_sample _attack_mod, t_sample _decay_mod) {
|
||||
float process_sample(bool gate, bool trigger, t_sample _attack_mod, t_sample _decay_mod)
|
||||
{
|
||||
|
||||
size_t attack_mid_x1 = ms_to_samples(attack1_rate + (float)_attack_mod);
|
||||
size_t attack_mid_x2 = ms_to_samples(attack2_rate + (float)_attack_mod);
|
||||
@@ -53,10 +51,8 @@ public:
|
||||
|
||||
// if note on is triggered, transition to attack phase
|
||||
if (trigger) {
|
||||
if (retrigger)
|
||||
start_level = 0.f;
|
||||
else
|
||||
start_level = level;
|
||||
if (retrigger) start_level = 0.f;
|
||||
else start_level = level;
|
||||
phase = 0;
|
||||
state = attack1;
|
||||
}
|
||||
@@ -68,9 +64,7 @@ public:
|
||||
phase += 1;
|
||||
}
|
||||
// reset phase if parameter was changed
|
||||
if (phase > attack_mid_x1) {
|
||||
phase = attack_mid_x1;
|
||||
}
|
||||
if (phase > attack_mid_x1) { phase = attack_mid_x1; }
|
||||
// if attack phase is done, transition to decay phase
|
||||
if (phase == attack_mid_x1) {
|
||||
state = attack2;
|
||||
@@ -85,9 +79,7 @@ public:
|
||||
phase += 1;
|
||||
}
|
||||
// reset phase if parameter was changed
|
||||
if (phase > attack_mid_x2) {
|
||||
phase = attack_mid_x2;
|
||||
}
|
||||
if (phase > attack_mid_x2) { phase = attack_mid_x2; }
|
||||
// if attack phase is done, transition to decay phase
|
||||
if (phase == attack_mid_x2) {
|
||||
state = hold;
|
||||
@@ -100,9 +92,7 @@ public:
|
||||
level = 1.0;
|
||||
phase += 1;
|
||||
}
|
||||
if (phase > hold_samp) {
|
||||
phase = hold_samp;
|
||||
}
|
||||
if (phase > hold_samp) { phase = hold_samp; }
|
||||
if (phase == hold_samp) {
|
||||
state = decay1;
|
||||
phase = 0;
|
||||
@@ -116,9 +106,7 @@ public:
|
||||
phase += 1;
|
||||
}
|
||||
// reset phase if parameter was changed
|
||||
if (phase > decay_mid_x1) {
|
||||
phase = decay_mid_x1;
|
||||
}
|
||||
if (phase > decay_mid_x1) { phase = decay_mid_x1; }
|
||||
// if decay phase is done, transition to sustain phase
|
||||
if (phase == decay_mid_x1) {
|
||||
state = decay2;
|
||||
@@ -133,9 +121,7 @@ public:
|
||||
phase += 1;
|
||||
}
|
||||
// reset phase if parameter was changed
|
||||
if (phase > decay_mid_x2) {
|
||||
phase = decay_mid_x2;
|
||||
}
|
||||
if (phase > decay_mid_x2) { phase = decay_mid_x2; }
|
||||
// if decay phase is done, transition to sustain phase
|
||||
if (phase == decay_mid_x2) {
|
||||
state = sustain;
|
||||
@@ -156,9 +142,7 @@ public:
|
||||
phase += 1;
|
||||
}
|
||||
// reset phase if parameter was changed
|
||||
if (phase > release_mid_x1) {
|
||||
phase = release_mid_x1;
|
||||
}
|
||||
if (phase > release_mid_x1) { phase = release_mid_x1; }
|
||||
// transition to 2nd release half
|
||||
if (phase == release_mid_x1) {
|
||||
phase = 0;
|
||||
@@ -173,9 +157,7 @@ public:
|
||||
phase += 1;
|
||||
}
|
||||
// reset phase if parameter was changed
|
||||
if (phase > release_mid_x2) {
|
||||
phase = release_mid_x2;
|
||||
}
|
||||
if (phase > release_mid_x2) { phase = release_mid_x2; }
|
||||
// reset
|
||||
if (phase == release_mid_x2) {
|
||||
phase = 0;
|
||||
@@ -189,16 +171,13 @@ public:
|
||||
|
||||
bool is_busy() { return state != 0; }
|
||||
|
||||
void set_samplerate(double sampleRate) {
|
||||
this->samplerate = sampleRate;
|
||||
}
|
||||
void set_samplerate(double sampleRate) { this->samplerate = sampleRate; }
|
||||
|
||||
// converts the x/y coordinates of the envelope points as a list for graphical representation.
|
||||
std::array<float, 18> calc_coordinates(float _max_attack, float _max_decay, float _max_release) {
|
||||
std::array<float, 18> calc_coordinates(float _max_attack, float _max_decay, float _max_release)
|
||||
{
|
||||
|
||||
auto scale = [](float _value, float _max) {
|
||||
return powf(_value / _max, 0.25) * _max;
|
||||
};
|
||||
auto scale = [](float _value, float _max) { return powf(_value / _max, 0.25) * _max; };
|
||||
|
||||
float a_x = 0;
|
||||
float a_y = 0;
|
||||
@@ -229,26 +208,8 @@ public:
|
||||
|
||||
float total = _max_attack + _max_decay + _max_release;
|
||||
|
||||
return {
|
||||
a_x,
|
||||
a_y,
|
||||
b_x / total,
|
||||
b_y,
|
||||
c_x / total,
|
||||
c_y,
|
||||
d_x / total,
|
||||
d_y,
|
||||
e_x / total,
|
||||
e_y,
|
||||
f_x / total,
|
||||
f_y,
|
||||
g_x / total,
|
||||
g_y,
|
||||
h_x / total,
|
||||
h_y,
|
||||
i_x / total,
|
||||
i_y
|
||||
};
|
||||
return {a_x, a_y, b_x / total, b_y, c_x / total, c_y, d_x / total, d_y, e_x / total, e_y,
|
||||
f_x / total, f_y, g_x / total, g_y, h_x / total, h_y, i_x / total, i_y};
|
||||
}
|
||||
|
||||
private:
|
||||
@@ -263,7 +224,8 @@ private:
|
||||
|
||||
float lerp(float x1, float y1, float x2, float y2, float x) { return y1 + (((x - x1) * (y2 - y1)) / (x2 - x1)); }
|
||||
|
||||
float smooth(float sample) {
|
||||
float smooth(float sample)
|
||||
{
|
||||
h3 = h2;
|
||||
h2 = h1;
|
||||
h1 = sample;
|
||||
@@ -271,8 +233,6 @@ private:
|
||||
return (h1 + h2 + h3) / 3.f;
|
||||
}
|
||||
|
||||
size_t ms_to_samples(float ms) {
|
||||
return static_cast<size_t>(ms * samplerate / 1000.f);
|
||||
}
|
||||
size_t ms_to_samples(float ms) { return static_cast<size_t>(ms * samplerate / 1000.f); }
|
||||
};
|
||||
}
|
||||
} // namespace trnr
|
||||
@@ -1,6 +1,6 @@
|
||||
#pragma once
|
||||
#include "tx_sineosc.h"
|
||||
#include "tx_envelope.h"
|
||||
#include "tx_sineosc.h"
|
||||
|
||||
namespace trnr {
|
||||
class tx_operator {
|
||||
@@ -16,7 +16,9 @@ public:
|
||||
float ratio;
|
||||
float amplitude;
|
||||
|
||||
float process_sample(const bool& gate, const bool& trigger, const float& frequency, const float& velocity, const float& pm = 0) {
|
||||
float process_sample(const bool& gate, const bool& trigger, const float& frequency, const float& velocity,
|
||||
const float& pm = 0)
|
||||
{
|
||||
|
||||
float env = envelope.process_sample(gate, trigger);
|
||||
|
||||
@@ -29,9 +31,10 @@ public:
|
||||
}
|
||||
}
|
||||
|
||||
void set_samplerate(double samplerate) {
|
||||
void set_samplerate(double samplerate)
|
||||
{
|
||||
this->envelope.set_samplerate(samplerate);
|
||||
this->oscillator.set_samplerate(samplerate);
|
||||
}
|
||||
};
|
||||
}
|
||||
} // namespace trnr
|
||||
|
||||
@@ -16,14 +16,11 @@ public:
|
||||
{
|
||||
}
|
||||
|
||||
void set_phase_resolution(float res) {
|
||||
phase_resolution = powf(2, res);
|
||||
}
|
||||
void set_phase_resolution(float res) { phase_resolution = powf(2, res); }
|
||||
|
||||
float process_sample(bool trigger, float frequency, float phase_modulation = 0.f) {
|
||||
if (trigger && phase_reset) {
|
||||
phase = 0.0;
|
||||
}
|
||||
float process_sample(bool trigger, float frequency, float phase_modulation = 0.f)
|
||||
{
|
||||
if (trigger && phase_reset) { phase = 0.0; }
|
||||
|
||||
float lookup_phase = phase + phase_modulation;
|
||||
wrap(lookup_phase);
|
||||
@@ -38,9 +35,7 @@ public:
|
||||
return output;
|
||||
}
|
||||
|
||||
void set_samplerate(double _samplerate) {
|
||||
this->samplerate = _samplerate;
|
||||
}
|
||||
void set_samplerate(double _samplerate) { this->samplerate = _samplerate; }
|
||||
|
||||
private:
|
||||
double samplerate;
|
||||
@@ -48,7 +43,8 @@ private:
|
||||
float phase;
|
||||
float history;
|
||||
|
||||
float sine(float x) {
|
||||
float sine(float x)
|
||||
{
|
||||
// x is scaled 0<=x<4096
|
||||
const float a = -0.40319426317E-08;
|
||||
const float b = 0.21683205691E+03;
|
||||
@@ -61,26 +57,23 @@ private:
|
||||
negate = true;
|
||||
x -= 2048;
|
||||
}
|
||||
if (x > 1024)
|
||||
x = 2048 - x;
|
||||
if (x > 1024) x = 2048 - x;
|
||||
y = (a + x) / (b + c * x * x) + d * x;
|
||||
if (negate)
|
||||
return (float)(-y);
|
||||
else
|
||||
return (float)y;
|
||||
if (negate) return (float)(-y);
|
||||
else return (float)y;
|
||||
}
|
||||
|
||||
float wrap(float& phase) {
|
||||
while (phase < 0.)
|
||||
phase += 1.;
|
||||
float wrap(float& phase)
|
||||
{
|
||||
while (phase < 0.) phase += 1.;
|
||||
|
||||
while (phase >= 1.)
|
||||
phase -= 1.;
|
||||
while (phase >= 1.) phase -= 1.;
|
||||
|
||||
return phase;
|
||||
}
|
||||
|
||||
float filter(float& value) {
|
||||
float filter(float& value)
|
||||
{
|
||||
value = 0.5 * (value + history);
|
||||
history = value;
|
||||
return value;
|
||||
@@ -92,4 +85,4 @@ private:
|
||||
return value;
|
||||
}
|
||||
};
|
||||
}
|
||||
} // namespace trnr
|
||||
@@ -41,16 +41,10 @@ public:
|
||||
velocity = _velocity;
|
||||
}
|
||||
|
||||
void note_off() override
|
||||
{
|
||||
this->gate = false;
|
||||
}
|
||||
void note_off() override { this->gate = false; }
|
||||
|
||||
// modulates the pitch in semitones
|
||||
void modulate_pitch(float _pitch) override
|
||||
{
|
||||
this->pitch_mod = _pitch;
|
||||
}
|
||||
void modulate_pitch(float _pitch) override { this->pitch_mod = _pitch; }
|
||||
|
||||
float process_sample() override
|
||||
{
|
||||
@@ -84,7 +78,10 @@ public:
|
||||
return redux(output, bit_resolution);
|
||||
}
|
||||
|
||||
bool is_busy() override { return gate || op1.envelope.is_busy() || op2.envelope.is_busy() || op3.envelope.is_busy(); }
|
||||
bool is_busy() override
|
||||
{
|
||||
return gate || op1.envelope.is_busy() || op2.envelope.is_busy() || op3.envelope.is_busy();
|
||||
}
|
||||
|
||||
void set_samplerate(double samplerate) override
|
||||
{
|
||||
@@ -188,4 +185,4 @@ private:
|
||||
return value;
|
||||
}
|
||||
};
|
||||
}
|
||||
} // namespace trnr
|
||||
@@ -17,37 +17,25 @@ public:
|
||||
typedef t_voice assert_at_compile_time[is_convertible<t_voice>::value ? 1 : -1];
|
||||
}
|
||||
|
||||
void set_voice_count(const int& voice_count)
|
||||
{
|
||||
voices.resize(voice_count, voices.at(0));
|
||||
}
|
||||
void set_voice_count(const int& voice_count) { voices.resize(voice_count, voices.at(0)); }
|
||||
|
||||
void note_on(const midi_event& event)
|
||||
{
|
||||
t_voice* voice = get_free_voice(event.midi_note);
|
||||
|
||||
if (voice == nullptr) {
|
||||
voice = steal_voice();
|
||||
}
|
||||
if (voice == nullptr) { voice = steal_voice(); }
|
||||
|
||||
if (voice != nullptr) {
|
||||
voice->note_on(event.midi_note, event.velocity);
|
||||
}
|
||||
if (voice != nullptr) { voice->note_on(event.midi_note, event.velocity); }
|
||||
}
|
||||
|
||||
void note_off(const midi_event& event)
|
||||
{
|
||||
for (auto it = voices.begin(); it != voices.end(); it++) {
|
||||
if ((*it).midi_note == event.midi_note) {
|
||||
(*it).note_off();
|
||||
}
|
||||
if ((*it).midi_note == event.midi_note) { (*it).note_off(); }
|
||||
}
|
||||
}
|
||||
|
||||
void access(std::function<void(t_voice&)> f)
|
||||
{
|
||||
std::for_each(voices.begin(), voices.end(), f);
|
||||
}
|
||||
void access(std::function<void(t_voice&)> f) { std::for_each(voices.begin(), voices.end(), f); }
|
||||
|
||||
void process_samples(t_sample** _outputs, int _start_index, int _block_size)
|
||||
{
|
||||
@@ -57,19 +45,15 @@ public:
|
||||
|
||||
float voices_signal = 0.;
|
||||
|
||||
std::for_each(voices.begin(), voices.end(), [&voices_signal](t_voice& voice) {
|
||||
voices_signal += (voice.process_sample() / 3.);
|
||||
});
|
||||
std::for_each(voices.begin(), voices.end(),
|
||||
[&voices_signal](t_voice& voice) { voices_signal += (voice.process_sample() / 3.); });
|
||||
|
||||
_outputs[0][s] = voices_signal;
|
||||
_outputs[1][s] = voices_signal;
|
||||
}
|
||||
}
|
||||
|
||||
void add_event(midi_event event)
|
||||
{
|
||||
input_queue.push_back(event);
|
||||
}
|
||||
void add_event(midi_event event) { input_queue.push_back(event); }
|
||||
|
||||
bool voices_active()
|
||||
{
|
||||
@@ -85,9 +69,7 @@ public:
|
||||
|
||||
void set_samplerate(double _samplerate)
|
||||
{
|
||||
for (int i = 0; i < voices.size(); i++) {
|
||||
voices.at(i).set_samplerate(_samplerate);
|
||||
}
|
||||
for (int i = 0; i < voices.size(); i++) { voices.at(i).set_samplerate(_samplerate); }
|
||||
}
|
||||
|
||||
private:
|
||||
@@ -99,9 +81,7 @@ private:
|
||||
t_voice* voice = nullptr;
|
||||
|
||||
for (auto it = voices.begin(); it != voices.end(); it++) {
|
||||
if (!(*it).is_busy()) {
|
||||
voice = &*it;
|
||||
}
|
||||
if (!(*it).is_busy()) { voice = &*it; }
|
||||
}
|
||||
|
||||
return voice;
|
||||
@@ -160,4 +140,4 @@ private:
|
||||
}
|
||||
}
|
||||
};
|
||||
}
|
||||
} // namespace trnr
|
||||
|
||||
Reference in New Issue
Block a user