diff --git a/effect_modulated_delay.cpp b/effect_modulated_delay.cpp index 578d77f..4e4df89 100644 --- a/effect_modulated_delay.cpp +++ b/effect_modulated_delay.cpp @@ -167,19 +167,43 @@ void AudioEffectModulatedDelay::setDelay(float milliseconds) void AudioEffectModulatedDelay::calcModFilterCoeff(float32_t cFrq, float32_t gain, float32_t width) { /* Calculate intermediate values */ - float32_t A = sqrt(pow(10, gain / 20.0f)); - float32_t w0 = 2.0f * PI * cFrq / ((float32_t)AUDIO_SAMPLE_RATE_EXACT); - float32_t cosw0 = cos(w0); - float32_t sinw0 = sin(w0); - float32_t alpha = sinw0 / (2.0f * width); + // float32_t A = sqrt(pow(10, gain / 20.0f)); + // float32_t w0 = 2.0f * PI * cFrq / ((float32_t)AUDIO_SAMPLE_RATE_EXACT); + // float32_t cosw0 = cos(w0); + // float32_t sinw0 = sin(w0); + // float32_t alpha = sinw0 / (2.0f * width); /* Calculate coefficients */ - float32_t b0 = 1.0f + alpha * A; - float32_t b1 = -2.0f * cosw0; - float32_t b2 = 1.0f - alpha * A; - float32_t a0 = 1.0f + alpha / A; - float32_t a1 = -2.0f * cosw0; - float32_t a2 = 1.0f - alpha / A; + // float32_t b0 = 1.0f + alpha * A; + // float32_t b1 = -2.0f * cosw0; + // float32_t b2 = 1.0f - alpha * A; + // float32_t a0 = 1.0f + alpha / A; + // float32_t a1 = -2.0f * cosw0; + // float32_t a2 = 1.0f - alpha / A; + +/* https://stackoverflow.com/questions/20924868/calculate-coefficients-of-2nd-order-butterworth-low-pass-filter/20932062 + ff=cutoff_frq/sample_rate=AUDIO_SAMPLE_RATE_EXACT/1000 + const double ita =1.0/ tan(M_PI*ff); + const double q=sqrt(2.0); + b0 = 1.0 / (1.0 + q*ita + ita*ita); + b1= 2*b0; + b2= b0; + a1 = 2.0 * (ita*ita - 1.0) * b0; + a2 = -(1.0 - q*ita + ita*ita) * b0; + + ff=1000/44117.64706=0.02266666666 + ita=804.60898525 + q=1.414213 + + */ + // 1kHz 2nd order Butterworth lowpass filter coefficients + // calculated with Iowa IIR FIlter Designer 6.5 + float32_t b0 = 0.124589380980617656; + float32_t b1 = 0.124589380980617656; + float32_t b2 = 0.0; + float32_t a0 = 1.000000000000000000; + float32_t a1 = -0.750821238038764660; + float32_t a2 = 0.0; /* Normalize so a0 = 1 */ filter_coeffs[0] = b0 / a0;