Generate dsp class of EQ filter, expose the variable fBandwidth
This commit is contained in:
parent
a7e6ae14ce
commit
1f21916c73
4 changed files with 383 additions and 2 deletions
|
|
@ -21,6 +21,7 @@ faustgen() {
|
|||
local cutoffVar=`echo "$code" | $SED -r 's%.*\("Cutoff", &[ \t]*([a-zA-Z0-9_]+).*%\1%;t;d'`
|
||||
local resoVar=`echo "$code" | $SED -r 's%.*\("Resonance", &[ \t]*([a-zA-Z0-9_]+).*%\1%;t;d'`
|
||||
local pkshVar=`echo "$code" | $SED -r 's%.*\("Peak/shelf gain", &[ \t]*([a-zA-Z0-9_]+).*%\1%;t;d'`
|
||||
local bwVar=`echo "$code" | $SED -r 's%.*\("Bandwidth", &[ \t]*([a-zA-Z0-9_]+).*%\1%;t;d'`
|
||||
|
||||
# suppress some faust-specific stuff we don't care
|
||||
echo "$code" \
|
||||
|
|
@ -47,6 +48,9 @@ faustgen() {
|
|||
if test ! -z "$pkshVar"; then
|
||||
$SED -r -i 's/\b'"$pkshVar"'\b/fPkShGain/' "$outfile"
|
||||
fi
|
||||
if test ! -z "$bwVar"; then
|
||||
$SED -r -i 's/\b'"$bwVar"'\b/fBandwidth/' "$outfile"
|
||||
fi
|
||||
}
|
||||
|
||||
for f in \
|
||||
|
|
@ -57,7 +61,8 @@ for f in \
|
|||
Brf1p Brf2p \
|
||||
Lsh Hsh Peq \
|
||||
Pink \
|
||||
Lpf2pSv Hpf2pSv Bpf2pSv Brf2pSv
|
||||
Lpf2pSv Hpf2pSv Bpf2pSv Brf2pSv \
|
||||
Eq
|
||||
do
|
||||
faustgen "$f"
|
||||
faustgen "2ch$f"
|
||||
|
|
|
|||
198
src/sfizz/gen/filters/sfz2chEq.cxx
Normal file
198
src/sfizz/gen/filters/sfz2chEq.cxx
Normal file
|
|
@ -0,0 +1,198 @@
|
|||
/* ------------------------------------------------------------
|
||||
author: "Jean Pierre Cimalando"
|
||||
license: "BSD-2-Clause"
|
||||
name: "sfz_filters"
|
||||
Code generated with Faust 2.20.2 (https://faust.grame.fr)
|
||||
Compilation options: -lang cpp -inpl -double -ftz 0
|
||||
------------------------------------------------------------ */
|
||||
|
||||
#ifndef __faust2chEq_H__
|
||||
#define __faust2chEq_H__
|
||||
|
||||
#ifndef FAUSTFLOAT
|
||||
#define FAUSTFLOAT float
|
||||
#endif
|
||||
|
||||
/* link with : "" */
|
||||
#include <algorithm>
|
||||
#include <cmath>
|
||||
#include <math.h>
|
||||
|
||||
|
||||
#ifndef FAUSTCLASS
|
||||
#define FAUSTCLASS faust2chEq
|
||||
#endif
|
||||
|
||||
#ifdef __APPLE__
|
||||
#define exp10f __exp10f
|
||||
#define exp10 __exp10
|
||||
#endif
|
||||
|
||||
class faust2chEq : public dsp {
|
||||
|
||||
public:
|
||||
|
||||
int fSampleRate;
|
||||
double fConst0;
|
||||
double fConst1;
|
||||
FAUSTFLOAT fCutoff;
|
||||
double fConst2;
|
||||
FAUSTFLOAT fBandwidth;
|
||||
FAUSTFLOAT fPkShGain;
|
||||
double fRec1[2];
|
||||
double fRec2[2];
|
||||
double fRec0[3];
|
||||
double fRec3[2];
|
||||
double fRec4[2];
|
||||
double fRec5[3];
|
||||
|
||||
public:
|
||||
|
||||
void metadata(Meta* m) {
|
||||
}
|
||||
|
||||
int getNumInputs() {
|
||||
return 2;
|
||||
}
|
||||
int getNumOutputs() {
|
||||
return 2;
|
||||
}
|
||||
int getInputRate(int channel) {
|
||||
int rate;
|
||||
switch ((channel)) {
|
||||
case 0: {
|
||||
rate = 1;
|
||||
break;
|
||||
}
|
||||
case 1: {
|
||||
rate = 1;
|
||||
break;
|
||||
}
|
||||
default: {
|
||||
rate = -1;
|
||||
break;
|
||||
}
|
||||
}
|
||||
return rate;
|
||||
}
|
||||
int getOutputRate(int channel) {
|
||||
int rate;
|
||||
switch ((channel)) {
|
||||
case 0: {
|
||||
rate = 1;
|
||||
break;
|
||||
}
|
||||
case 1: {
|
||||
rate = 1;
|
||||
break;
|
||||
}
|
||||
default: {
|
||||
rate = -1;
|
||||
break;
|
||||
}
|
||||
}
|
||||
return rate;
|
||||
}
|
||||
|
||||
static void classInit(int sample_rate) {
|
||||
}
|
||||
|
||||
void instanceConstants(int sample_rate) {
|
||||
fSampleRate = sample_rate;
|
||||
fConst0 = std::min<double>(192000.0, std::max<double>(1.0, double(fSampleRate)));
|
||||
fConst1 = (6.2831853071795862 / fConst0);
|
||||
fConst2 = (2.1775860903036022 / fConst0);
|
||||
}
|
||||
|
||||
void instanceResetUserInterface() {
|
||||
fCutoff = FAUSTFLOAT(440.0);
|
||||
fBandwidth = FAUSTFLOAT(1.0);
|
||||
fPkShGain = FAUSTFLOAT(0.0);
|
||||
}
|
||||
|
||||
void instanceClear() {
|
||||
for (int l0 = 0; (l0 < 2); l0 = (l0 + 1)) {
|
||||
fRec1[l0] = 0.0;
|
||||
}
|
||||
for (int l1 = 0; (l1 < 2); l1 = (l1 + 1)) {
|
||||
fRec2[l1] = 0.0;
|
||||
}
|
||||
for (int l2 = 0; (l2 < 3); l2 = (l2 + 1)) {
|
||||
fRec0[l2] = 0.0;
|
||||
}
|
||||
for (int l3 = 0; (l3 < 2); l3 = (l3 + 1)) {
|
||||
fRec3[l3] = 0.0;
|
||||
}
|
||||
for (int l4 = 0; (l4 < 2); l4 = (l4 + 1)) {
|
||||
fRec4[l4] = 0.0;
|
||||
}
|
||||
for (int l5 = 0; (l5 < 3); l5 = (l5 + 1)) {
|
||||
fRec5[l5] = 0.0;
|
||||
}
|
||||
}
|
||||
|
||||
void init(int sample_rate) {
|
||||
classInit(sample_rate);
|
||||
instanceInit(sample_rate);
|
||||
}
|
||||
void instanceInit(int sample_rate) {
|
||||
instanceConstants(sample_rate);
|
||||
instanceResetUserInterface();
|
||||
instanceClear();
|
||||
}
|
||||
|
||||
faust2chEq* clone() {
|
||||
return new faust2chEq();
|
||||
}
|
||||
|
||||
int getSampleRate() {
|
||||
return fSampleRate;
|
||||
}
|
||||
|
||||
void buildUserInterface(UI* ui_interface) {
|
||||
}
|
||||
|
||||
void compute(int count, FAUSTFLOAT** inputs, FAUSTFLOAT** outputs) {
|
||||
FAUSTFLOAT* input0 = inputs[0];
|
||||
FAUSTFLOAT* input1 = inputs[1];
|
||||
FAUSTFLOAT* output0 = outputs[0];
|
||||
FAUSTFLOAT* output1 = outputs[1];
|
||||
double fSlow0 = std::max<double>(0.0, double(fCutoff));
|
||||
double fSlow1 = (fConst1 * fSlow0);
|
||||
double fSlow2 = std::sin(fSlow1);
|
||||
double fSlow3 = std::max<double>(0.001, (0.5 / double(sinh(double((fConst2 * ((fSlow0 * double(fBandwidth)) / fSlow2)))))));
|
||||
double fSlow4 = std::pow(10.0, (0.025000000000000001 * double(fPkShGain)));
|
||||
double fSlow5 = (0.5 * (fSlow2 / (fSlow3 * fSlow4)));
|
||||
double fSlow6 = (fSlow5 + 1.0);
|
||||
double fSlow7 = (0.0010000000000000009 * ((0.0 - (2.0 * std::cos(fSlow1))) / fSlow6));
|
||||
double fSlow8 = (0.0010000000000000009 * ((1.0 - fSlow5) / fSlow6));
|
||||
double fSlow9 = (0.5 * ((fSlow2 * fSlow4) / fSlow3));
|
||||
double fSlow10 = (0.0010000000000000009 * ((fSlow9 + 1.0) / fSlow6));
|
||||
double fSlow11 = (0.0010000000000000009 * ((1.0 - fSlow9) / fSlow6));
|
||||
for (int i = 0; (i < count); i = (i + 1)) {
|
||||
double fTemp0 = double(input0[i]);
|
||||
double fTemp1 = double(input1[i]);
|
||||
fRec1[0] = (fSlow7 + (0.999 * fRec1[1]));
|
||||
double fTemp2 = (fRec1[0] * fRec0[1]);
|
||||
fRec2[0] = (fSlow8 + (0.999 * fRec2[1]));
|
||||
fRec0[0] = (fTemp0 - (fTemp2 + (fRec2[0] * fRec0[2])));
|
||||
fRec3[0] = (fSlow10 + (0.999 * fRec3[1]));
|
||||
fRec4[0] = (fSlow11 + (0.999 * fRec4[1]));
|
||||
output0[i] = FAUSTFLOAT((((fRec0[0] * fRec3[0]) + fTemp2) + (fRec4[0] * fRec0[2])));
|
||||
double fTemp3 = (fRec1[0] * fRec5[1]);
|
||||
fRec5[0] = (fTemp1 - (fTemp3 + (fRec2[0] * fRec5[2])));
|
||||
output1[i] = FAUSTFLOAT(((fTemp3 + (fRec3[0] * fRec5[0])) + (fRec4[0] * fRec5[2])));
|
||||
fRec1[1] = fRec1[0];
|
||||
fRec2[1] = fRec2[0];
|
||||
fRec0[2] = fRec0[1];
|
||||
fRec0[1] = fRec0[0];
|
||||
fRec3[1] = fRec3[0];
|
||||
fRec4[1] = fRec4[0];
|
||||
fRec5[2] = fRec5[1];
|
||||
fRec5[1] = fRec5[0];
|
||||
}
|
||||
}
|
||||
|
||||
};
|
||||
|
||||
#endif
|
||||
|
|
@ -175,7 +175,7 @@ class faust2chPeq : public dsp {
|
|||
output0[i] = FAUSTFLOAT((((fRec0[0] * fRec3[0]) + fTemp2) + (fRec4[0] * fRec0[2])));
|
||||
double fTemp3 = (fRec1[0] * fRec5[1]);
|
||||
fRec5[0] = (fTemp1 - (fTemp3 + (fRec2[0] * fRec5[2])));
|
||||
output1[i] = FAUSTFLOAT(((fRec3[0] * fRec5[0]) + (fTemp3 + (fRec4[0] * fRec5[2]))));
|
||||
output1[i] = FAUSTFLOAT(((fTemp3 + (fRec3[0] * fRec5[0])) + (fRec4[0] * fRec5[2])));
|
||||
fRec1[1] = fRec1[0];
|
||||
fRec2[1] = fRec2[0];
|
||||
fRec0[2] = fRec0[1];
|
||||
|
|
|
|||
178
src/sfizz/gen/filters/sfzEq.cxx
Normal file
178
src/sfizz/gen/filters/sfzEq.cxx
Normal file
|
|
@ -0,0 +1,178 @@
|
|||
/* ------------------------------------------------------------
|
||||
author: "Jean Pierre Cimalando"
|
||||
license: "BSD-2-Clause"
|
||||
name: "sfz_filters"
|
||||
Code generated with Faust 2.20.2 (https://faust.grame.fr)
|
||||
Compilation options: -lang cpp -inpl -double -ftz 0
|
||||
------------------------------------------------------------ */
|
||||
|
||||
#ifndef __faustEq_H__
|
||||
#define __faustEq_H__
|
||||
|
||||
#ifndef FAUSTFLOAT
|
||||
#define FAUSTFLOAT float
|
||||
#endif
|
||||
|
||||
/* link with : "" */
|
||||
#include <algorithm>
|
||||
#include <cmath>
|
||||
#include <math.h>
|
||||
|
||||
|
||||
#ifndef FAUSTCLASS
|
||||
#define FAUSTCLASS faustEq
|
||||
#endif
|
||||
|
||||
#ifdef __APPLE__
|
||||
#define exp10f __exp10f
|
||||
#define exp10 __exp10
|
||||
#endif
|
||||
|
||||
class faustEq : public dsp {
|
||||
|
||||
public:
|
||||
|
||||
int fSampleRate;
|
||||
double fConst0;
|
||||
double fConst1;
|
||||
FAUSTFLOAT fCutoff;
|
||||
double fConst2;
|
||||
FAUSTFLOAT fBandwidth;
|
||||
FAUSTFLOAT fPkShGain;
|
||||
double fRec1[2];
|
||||
double fRec2[2];
|
||||
double fRec0[3];
|
||||
double fRec3[2];
|
||||
double fRec4[2];
|
||||
|
||||
public:
|
||||
|
||||
void metadata(Meta* m) {
|
||||
}
|
||||
|
||||
int getNumInputs() {
|
||||
return 1;
|
||||
}
|
||||
int getNumOutputs() {
|
||||
return 1;
|
||||
}
|
||||
int getInputRate(int channel) {
|
||||
int rate;
|
||||
switch ((channel)) {
|
||||
case 0: {
|
||||
rate = 1;
|
||||
break;
|
||||
}
|
||||
default: {
|
||||
rate = -1;
|
||||
break;
|
||||
}
|
||||
}
|
||||
return rate;
|
||||
}
|
||||
int getOutputRate(int channel) {
|
||||
int rate;
|
||||
switch ((channel)) {
|
||||
case 0: {
|
||||
rate = 1;
|
||||
break;
|
||||
}
|
||||
default: {
|
||||
rate = -1;
|
||||
break;
|
||||
}
|
||||
}
|
||||
return rate;
|
||||
}
|
||||
|
||||
static void classInit(int sample_rate) {
|
||||
}
|
||||
|
||||
void instanceConstants(int sample_rate) {
|
||||
fSampleRate = sample_rate;
|
||||
fConst0 = std::min<double>(192000.0, std::max<double>(1.0, double(fSampleRate)));
|
||||
fConst1 = (6.2831853071795862 / fConst0);
|
||||
fConst2 = (2.1775860903036022 / fConst0);
|
||||
}
|
||||
|
||||
void instanceResetUserInterface() {
|
||||
fCutoff = FAUSTFLOAT(440.0);
|
||||
fBandwidth = FAUSTFLOAT(1.0);
|
||||
fPkShGain = FAUSTFLOAT(0.0);
|
||||
}
|
||||
|
||||
void instanceClear() {
|
||||
for (int l0 = 0; (l0 < 2); l0 = (l0 + 1)) {
|
||||
fRec1[l0] = 0.0;
|
||||
}
|
||||
for (int l1 = 0; (l1 < 2); l1 = (l1 + 1)) {
|
||||
fRec2[l1] = 0.0;
|
||||
}
|
||||
for (int l2 = 0; (l2 < 3); l2 = (l2 + 1)) {
|
||||
fRec0[l2] = 0.0;
|
||||
}
|
||||
for (int l3 = 0; (l3 < 2); l3 = (l3 + 1)) {
|
||||
fRec3[l3] = 0.0;
|
||||
}
|
||||
for (int l4 = 0; (l4 < 2); l4 = (l4 + 1)) {
|
||||
fRec4[l4] = 0.0;
|
||||
}
|
||||
}
|
||||
|
||||
void init(int sample_rate) {
|
||||
classInit(sample_rate);
|
||||
instanceInit(sample_rate);
|
||||
}
|
||||
void instanceInit(int sample_rate) {
|
||||
instanceConstants(sample_rate);
|
||||
instanceResetUserInterface();
|
||||
instanceClear();
|
||||
}
|
||||
|
||||
faustEq* clone() {
|
||||
return new faustEq();
|
||||
}
|
||||
|
||||
int getSampleRate() {
|
||||
return fSampleRate;
|
||||
}
|
||||
|
||||
void buildUserInterface(UI* ui_interface) {
|
||||
}
|
||||
|
||||
void compute(int count, FAUSTFLOAT** inputs, FAUSTFLOAT** outputs) {
|
||||
FAUSTFLOAT* input0 = inputs[0];
|
||||
FAUSTFLOAT* output0 = outputs[0];
|
||||
double fSlow0 = std::max<double>(0.0, double(fCutoff));
|
||||
double fSlow1 = (fConst1 * fSlow0);
|
||||
double fSlow2 = std::sin(fSlow1);
|
||||
double fSlow3 = std::max<double>(0.001, (0.5 / double(sinh(double((fConst2 * ((fSlow0 * double(fBandwidth)) / fSlow2)))))));
|
||||
double fSlow4 = std::pow(10.0, (0.025000000000000001 * double(fPkShGain)));
|
||||
double fSlow5 = (0.5 * (fSlow2 / (fSlow3 * fSlow4)));
|
||||
double fSlow6 = (fSlow5 + 1.0);
|
||||
double fSlow7 = (0.0010000000000000009 * ((0.0 - (2.0 * std::cos(fSlow1))) / fSlow6));
|
||||
double fSlow8 = (0.0010000000000000009 * ((1.0 - fSlow5) / fSlow6));
|
||||
double fSlow9 = (0.5 * ((fSlow2 * fSlow4) / fSlow3));
|
||||
double fSlow10 = (0.0010000000000000009 * ((fSlow9 + 1.0) / fSlow6));
|
||||
double fSlow11 = (0.0010000000000000009 * ((1.0 - fSlow9) / fSlow6));
|
||||
for (int i = 0; (i < count); i = (i + 1)) {
|
||||
double fTemp0 = double(input0[i]);
|
||||
fRec1[0] = (fSlow7 + (0.999 * fRec1[1]));
|
||||
double fTemp1 = (fRec1[0] * fRec0[1]);
|
||||
fRec2[0] = (fSlow8 + (0.999 * fRec2[1]));
|
||||
fRec0[0] = (fTemp0 - (fTemp1 + (fRec2[0] * fRec0[2])));
|
||||
fRec3[0] = (fSlow10 + (0.999 * fRec3[1]));
|
||||
fRec4[0] = (fSlow11 + (0.999 * fRec4[1]));
|
||||
output0[i] = FAUSTFLOAT((((fRec0[0] * fRec3[0]) + fTemp1) + (fRec4[0] * fRec0[2])));
|
||||
fRec1[1] = fRec1[0];
|
||||
fRec2[1] = fRec2[0];
|
||||
fRec0[2] = fRec0[1];
|
||||
fRec0[1] = fRec0[0];
|
||||
fRec3[1] = fRec3[0];
|
||||
fRec4[1] = fRec4[0];
|
||||
}
|
||||
}
|
||||
|
||||
};
|
||||
|
||||
#endif
|
||||
Loading…
Add table
Reference in a new issue