Skip to content

Instantly share code, notes, and snippets.

@fundamental
Created April 11, 2018 21:54
Show Gist options
  • Save fundamental/40ce0e9369673dff3f2c0594ffb4a669 to your computer and use it in GitHub Desktop.
Save fundamental/40ce0e9369673dff3f2c0594ffb4a669 to your computer and use it in GitHub Desktop.
Patch
--- a/src/DSP/SVFilter.cpp
+++ b/src/DSP/SVFilter.cpp
@@ -102,6 +102,7 @@ SVFilter::response SVFilter::computeResponse(int type,
void SVFilter::computefiltercoefs(void)
{
+ //printf("compute coeff (%f, %f, %d)\n", freq, q, stages);
par.f = freq / samplerate_f * 4.0f;
if(par.f > 0.99999f)
par.f = 0.99999f;
@@ -125,7 +126,7 @@ void SVFilter::setfreq(float frequency)
bool nyquistthresh = (abovenq ^ oldabovenq);
//if the frequency is changed fast, it needs interpolation
- if((rap > 3.0f) || nyquistthresh) { //(now, filter and coefficients backup)
+ if(true || (rap > 3.0f) || nyquistthresh) { //(now, filter and coefficients backup)
if(!firsttime)
needsinterpolation = true;
ipar = par;
@@ -168,7 +169,7 @@ void SVFilter::setstages(int stages_)
computefiltercoefs();
}
-void SVFilter::singlefilterout(float *smp, fstage &x, parameters &par)
+void SVFilter::singlefilterout(float *smp, fstage &x, parameters &par, parameters &par2)
{
float *out = NULL;
switch(type) {
@@ -189,10 +190,16 @@ void SVFilter::singlefilterout(float *smp, fstage &x, parameters &par)
warnx("Impossible SVFilter type encountered [%d]", type);
}
+ //printf("delta q = %f\n", (par.q-par2.q)/buffersize_f);
+ //printf("delta f = %f\n", (par.f-par2.f)/buffersize_f);
for(int i = 0; i < buffersize; ++i) {
- x.low = x.low + par.f * x.band;
- x.high = par.q_sqrt * smp[i] - x.low - par.q * x.band;
- x.band = par.f * x.high + x.band;
+ const float t = i/buffersize_f;
+ const float par_f = (1-t)*par.f + t*par2.f;
+ const float par_q = (1-t)*par.q + t*par2.q;
+ const float par_q_sqrt = sqrtf(par_q);
+ x.low = x.low + par_f * x.band;
+ x.high = par_q_sqrt * smp[i] - x.low - par_q * x.band;
+ x.band = par_f * x.high + x.band;
x.notch = x.high + x.low;
smp[i] = *out;
}
@@ -211,6 +218,8 @@ void SVFilter::singlefilterout(float *smp, fstage &x, parameters &par)
void SVFilter::filterout(float *smp)
{
+ //printf("SVFilter::filterout\n");
+#if 0
for(int i = 0; i < stages + 1; ++i)
singlefilterout(smp, st[i], par);
@@ -227,6 +236,15 @@ void SVFilter::filterout(float *smp)
}
needsinterpolation = false;
}
+#endif
+ if(needsinterpolation) {
+ //printf("interpolating...\n");
+ for(int i = 0; i < stages + 1; ++i)
+ singlefilterout(smp, st[i], ipar, par);
+ needsinterpolation = false;
+ } else
+ for(int i = 0; i < stages + 1; ++i)
+ singlefilterout(smp, st[i], par, par);
for(int i = 0; i < buffersize; ++i)
smp[i] *= outgain;
diff --git a/src/DSP/SVFilter.h b/src/DSP/SVFilter.h
index 7cb7e989..57e82494 100644
--- a/src/DSP/SVFilter.h
+++ b/src/DSP/SVFilter.h
@@ -56,7 +56,7 @@ class SVFilter:public Filter
float f, q, q_sqrt;
} par, ipar;
- void singlefilterout(float *smp, fstage &x, parameters &par);
+ void singlefilterout(float *smp, fstage &x, parameters &par, parameters &);
void computefiltercoefs(void);
int type; // The type of the filter (LPF1,HPF1,LPF2,HPF2...)
int stages; // how many times the filter is applied (0->1,1->2,etc.)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment