/* LadderFilterProcess *************************************************/ Error_t LadderFilterProcess(LadderFilter *filter, float *outBuffer, float *inBuffer, unsigned n_samples) { // Pre-calculate Scalars float TWO_VT_INV = 1.0 / (2 * filter->Vt); float TWO_VT_G = 2 * filter->Vt * (1 - exp(-TWO_PI * filter->cutoff / filter->sample_rate)); // Filter audio for (unsigned i = 0; i < n_samples; ++i) { // Stage 1 output filter->y[0] = filter->y[0] + TWO_VT_G * (f_tanh(inBuffer[i] - 4 * \ f_tanh(2 * filter->resonance * filter->y[3]) * \ TWO_VT_INV) - filter->w[0]); filter->w[0] = f_tanh(filter->y[0] * TWO_VT_INV); // Stage 2 output filter->y[1] = filter->y[1] + TWO_VT_G * (filter->w[0]- filter->w[1]); filter->w[1] = f_tanh(filter->y[1] * TWO_VT_INV); // Stage 3 output filter->y[2] = filter->y[2] + TWO_VT_G * (filter->w[1]- filter->w[2]); filter->w[2] = f_tanh(filter->y[2] * TWO_VT_INV); // Stage 4 output filter->y[3] = filter->y[3] + TWO_VT_G * (filter->w[2]- filter->w[3]); filter->w[3] = f_tanh(filter->y[3] * TWO_VT_INV); // Write output outBuffer[i] = filter->y[3]; } return NOERR; }
bool TestExtMath::test_tanh() { VC(f_tanh(1.23), 0.84257932565893); return Count(true); }