Browse Source

Detect when ladder filter is no longer resonating

dds
PaulStoffregen 3 years ago
parent
commit
570c7165f0
2 changed files with 16 additions and 6 deletions
  1. +15
    -6
      filter_ladder.cpp
  2. +1
    -0
      filter_ladder.h

+ 15
- 6
filter_ladder.cpp View File

alpha = 0.9892f * wc - 0.4324f * wc2 + 0.1381f * wc * wc2 - 0.0202f * wc2 * wc2; alpha = 0.9892f * wc - 0.4324f * wc2 + 0.1381f * wc * wc2 - 0.0202f * wc2 * wc2;
} }


bool AudioFilterLadder::resonating()
{
for (int i=0; i < 4; i++) {
if (fabsf(z0[i]) > 0.0001f) return true;
if (fabsf(z1[i]) > 0.0001f) return true;
}
return false;
}

static inline float fast_tanh(float x) static inline float fast_tanh(float x)
{ {
float x2 = x * x; float x2 = x * x;
blockb = receiveReadOnly(1); blockb = receiveReadOnly(1);
blockc = receiveReadOnly(2); blockc = receiveReadOnly(2);
if (!blocka) { if (!blocka) {
blocka = allocate();
if (resonating()) {
// When no data arrives but the filter is still
// resonating, we must continue computing the filter
// with zero input to sustain the resonance
blocka = allocate();
}
if (!blocka) { if (!blocka) {
if (blockb) release(blockb); if (blockb) release(blockb);
if (blockc) release(blockc); if (blockc) release(blockc);
return; return;
} }
// When no data arrives, we must treat it as if zeros had
// arrived. Because of resonance, we need to keep computing
// output. Perhaps we could examine the filter state here
// and just return without any work when it's below some
// threshold we know produces no more sound/resonance?
for (int i=0; i < AUDIO_BLOCK_SAMPLES; i++) { for (int i=0; i < AUDIO_BLOCK_SAMPLES; i++) {
blocka->data[i] = 0; blocka->data[i] = 0;
} }

+ 1
- 0
filter_ladder.h View File

private: private:
float LPF(float s, int i); float LPF(float s, int i);
void compute_coeffs(float fc); void compute_coeffs(float fc);
bool resonating();
float alpha = 1.0; float alpha = 1.0;
float beta[4] = {0.0, 0.0, 0.0, 0.0}; float beta[4] = {0.0, 0.0, 0.0, 0.0};
float z0[4] = {0.0, 0.0, 0.0, 0.0}; float z0[4] = {0.0, 0.0, 0.0, 0.0};

Loading…
Cancel
Save