|
|
|
|
|
|
|
|
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; |
|
|
} |
|
|
} |