summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorDamien Zammit <damien@zamaudio.com>2019-07-07 22:51:38 +1000
committerDamien Zammit <damien@zamaudio.com>2019-07-09 21:04:01 +1000
commitaed0bea3a817c9b0433f7205af328b9817a02df7 (patch)
tree90402ceea133b8103714c048c940cea75a9cbf09
parent1fa7b123380e8dea288d6f5be3c580c30ff46c65 (diff)
-rw-r--r--plugins/ZaMultiCompX2/ZaMultiCompX2Plugin.cpp109
-rw-r--r--plugins/ZaMultiCompX2/ZaMultiCompX2Plugin.hpp6
2 files changed, 56 insertions, 59 deletions
diff --git a/plugins/ZaMultiCompX2/ZaMultiCompX2Plugin.cpp b/plugins/ZaMultiCompX2/ZaMultiCompX2Plugin.cpp
index 079cfc6..50c54ba 100644
--- a/plugins/ZaMultiCompX2/ZaMultiCompX2Plugin.cpp
+++ b/plugins/ZaMultiCompX2/ZaMultiCompX2Plugin.cpp
@@ -19,6 +19,13 @@
START_NAMESPACE_DISTRHO
+#define FILT_LOW 0
+#define FILT_HIGH 1
+#define FILT_ALLPASS 2
+#define FILT_BAND 3
+#define FILT_NOTCH 4
+#define FILT_PEAK 5
+
// -----------------------------------------------------------------------
ZaMultiCompX2Plugin::ZaMultiCompX2Plugin()
@@ -722,9 +729,9 @@ void ZaMultiCompX2Plugin::activate()
for (j = 0; j < 2; j++)
old_ll[j]=old_l1[j]=0.f;
- for (type = 0; type < 3; type++) {
+ for (type = 0; type < 2; type++) {
for (i = 0; i < MAX_FILT; i++) {
- for (layer = 0; layer < 2; layer++) {
+ for (layer = 0; layer < 4; layer++) {
simper[type][i][layer].k = 0.f;
simper[type][i][layer].g = 0.f;
simper[type][i][layer].m0 = 0.f;
@@ -749,31 +756,13 @@ void ZaMultiCompX2Plugin::activate()
* https://cytomic.com/files/dsp/SvfInputMixing.pdf
*/
-void ZaMultiCompX2Plugin::linear_svf_set_xover(struct linear_svf *self, float sample_rate, float cutoff, float resonance, int hp)
+void ZaMultiCompX2Plugin::linear_svf_set_xover(struct linear_svf *self, float sample_rate, float cutoff, float resonance)
{
- double w;
-
self->k = 1. / resonance;
- w = M_PI * cutoff / sample_rate;
- self->g = tan(w);
- switch (hp) {
- case 0:
- self->m0 = 1.;
- self->m1 = 0.;
- self->m2 = 0.;
- break;
- case 1:
- self->m0 = 0.;
- self->m1 = 0.;
- self->m2 = 1.;
- break;
- default:
- case 2:
- self->m0 = 1.;
- self->m1 = -self->k;
- self->m2 = 1.;
- break;
- }
+ self->g = tan(M_PI * cutoff / sample_rate);
+ self->m0 = 1./(1. + self->g*(self->g+self->k));
+ self->m1 = self->g*self->m0;
+ self->m2 = self->g*self->m1;
}
@@ -783,41 +772,49 @@ void ZaMultiCompX2Plugin::linear_svf_reset(struct linear_svf *self)
self->s[0] = self->s[1] = 0.f;
}
-float ZaMultiCompX2Plugin::run_linear_svf_xover(struct linear_svf *self, float in)
+float ZaMultiCompX2Plugin::run_linear_svf_xover(struct linear_svf *self, float in, int type)
{
- double v[2];
- double g = self->g;
- double k = self->k;
- double s0 = self->s[0];
- double s1 = self->s[1];
- double g2 = g*g;
- double vhigh = in * self->m2;
- double vband = in * self->m1;
- double vlow = in * self->m0;
-
- v[0] = -1. / (1. + g2 + g*k) * (-s0 + g*s1 - g*k*s0 + g2*vband + g*vhigh - g*vlow - g2*k*vlow);
- v[1] = -1. / (1. + g2 + g*k) * (-g*s0 - s1 - g*vband + g2*vhigh + g*k*vhigh - g2*vlow);
- self->s[0] = 2. * v[0] - s0;
- self->s[1] = 2. * v[1] - s1;
-
- return (float)(vhigh + v[1]);
+ double v[3];
+ v[2] = in - self->s[1];
+ v[0] = self->m0 * self->s[0] + self->m1 * v[2];
+ v[1] = self->s[1] + self->m1 * self->s[0] + self->m2 * v[2];
+ self->s[0] = 2. * v[0] - self->s[0];
+ self->s[1] = 2. * v[1] - self->s[1];
+
+ switch(type) {
+ case FILT_LOW:
+ return (float)v[1];
+ case FILT_HIGH:
+ return (float)(in - self->k * v[0] - v[1]);
+ case FILT_ALLPASS:
+ return (float)(in - v[0] * (self->k + 1.));
+ case FILT_BAND:
+ return (float)v[0];
+ case FILT_NOTCH:
+ return (float)(in - self->k * v[0]);
+ case FILT_PEAK:
+ return (float)(in - self->k * v[0] - 2. * v[1]);
+ default:
+ return 0.f;
+ }
}
void ZaMultiCompX2Plugin::calc_lr4(float f, int i)
{
float srate = getSampleRate();
-
- linear_svf_set_xover(&simper[0][i][0], srate, f, 0.7071068, 0); // lp layer0
- linear_svf_set_xover(&simper[0][i][1], srate, f, 0.7071068, 0); // lp layer1
- linear_svf_set_xover(&simper[1][i][0], srate, f, 0.7071068, 1); // hp layer0
- linear_svf_set_xover(&simper[1][i][1], srate, f, 0.7071068, 1); // hp layer1
- linear_svf_set_xover(&simper[2][i][0], srate, f, 0.7071068, 2); // bp layer0
- linear_svf_set_xover(&simper[2][i][1], srate, f, 0.7071068, 2); // bp layer1
+ float q = 0.7071068;
+
+ linear_svf_set_xover(&simper[0][i][0], srate, f, q); // lp layer0
+ linear_svf_set_xover(&simper[0][i][1], srate, f, q); // ap
+ linear_svf_set_xover(&simper[0][i][2], srate, f, q); // lp layer1
+ linear_svf_set_xover(&simper[1][i][0], srate, f, q); // hp layer0
+ linear_svf_set_xover(&simper[1][i][1], srate, f, q); // ap
+ linear_svf_set_xover(&simper[1][i][2], srate, f, q); // hp layer1
}
void ZaMultiCompX2Plugin::run_lr4(int i, float in, float *outlo, float *outhi)
{
- float lo, hi, ap;
+ float tmp0, tmp1;
/*
lo = run_linear_svf_xover(&simper[0][i][0], in);
ap = run_linear_svf_xover(&simper[2][i][0], lo);
@@ -827,13 +824,13 @@ void ZaMultiCompX2Plugin::run_lr4(int i, float in, float *outlo, float *outhi)
ap = run_linear_svf_xover(&simper[2][i][1], hi);
*outhi = run_linear_svf_xover(&simper[1][i][1], ap);
*/
- ap = run_linear_svf_xover(&simper[2][i][0], in);
- lo = run_linear_svf_xover(&simper[0][i][0], ap);
- *outlo = run_linear_svf_xover(&simper[0][i][1], lo);
+ tmp0 = run_linear_svf_xover(&simper[0][i][0], in, FILT_LOW);
+ tmp1 = run_linear_svf_xover(&simper[0][i][1], tmp0, FILT_ALLPASS);
+ *outlo = run_linear_svf_xover(&simper[0][i][2], tmp1, FILT_LOW);
- ap = run_linear_svf_xover(&simper[2][i][1], in);
- hi = run_linear_svf_xover(&simper[1][i][0], ap);
- *outhi = run_linear_svf_xover(&simper[1][i][1], hi);
+ tmp0 = run_linear_svf_xover(&simper[1][i][0], in, FILT_HIGH);
+ tmp1 = run_linear_svf_xover(&simper[1][i][1], tmp0, FILT_ALLPASS);
+ *outhi = run_linear_svf_xover(&simper[1][i][2], tmp1, FILT_HIGH);
}
void ZaMultiCompX2Plugin::run_comp(int k, float inL, float inR, float *outL, float *outR)
diff --git a/plugins/ZaMultiCompX2/ZaMultiCompX2Plugin.hpp b/plugins/ZaMultiCompX2/ZaMultiCompX2Plugin.hpp
index f775e0c..e6228ab 100644
--- a/plugins/ZaMultiCompX2/ZaMultiCompX2Plugin.hpp
+++ b/plugins/ZaMultiCompX2/ZaMultiCompX2Plugin.hpp
@@ -180,10 +180,10 @@ Stereo version of ZaMultiComp, with individual threshold controls for each band
double s[2];
};
- struct linear_svf simper[3][MAX_FILT][2];
- void linear_svf_set_xover(struct linear_svf *self, float sample_rate, float cutoff, float resonance, int hi);
+ struct linear_svf simper[2][MAX_FILT][4];
+ void linear_svf_set_xover(struct linear_svf *self, float sample_rate, float cutoff, float resonance);
void linear_svf_reset(struct linear_svf *self);
- float run_linear_svf_xover(struct linear_svf *self, float in);
+ float run_linear_svf_xover(struct linear_svf *self, float in, int type);
// -------------------------------------------------------------------
private: