Added function for coeff-calculation.

master
Holger Wirtz 5 years ago
parent 23c4ac1a53
commit 8833124c4f
  1. 37
      effect_modulated_delay.cpp
  2. 1
      effect_modulated_delay.h

@ -27,6 +27,8 @@
#include "effect_modulated_delay.h"
#include "config.h"
extern config_t configuration;
/******************************************************************/
// Based on; A u d i o E f f e c t D e l a y
@ -58,18 +60,37 @@ boolean AudioEffectModulatedDelay::begin(short *delayline, int d_length)
_delayline = delayline;
_delay_length = d_length;
set_modulator_filter_coeffs(1.0, configuration.chorus_frequency / 10, 1.0); // gain, center frerquency
modulator_filter_data = {1, &modulator_filter_state, modulator_filter_coeffs};
return (true);
}
void AudioEffectModulatedDelay::set_modulator_filter_coeffs(float gain, float fc, float width)
{
// modulator filter
// coefficients calculated with "IOWA Hills IIR Filter Designer 6.5", http://www.iowahills.com/8DownloadPage.html
// OmegaC = 0.5, SR = 44117.64706, Fc = 11 kHz, N=2
// Example: https://web.fhnw.ch/technik/projekte/eit/Fruehling2016/MuelZum/html/parametric_equalizer_example_8c-example.html
modulator_filter_coeffs[0] = 0.291938819295525787; // b0
modulator_filter_coeffs[1] = 0.582700575839973478; // b1
modulator_filter_coeffs[2] = 0.291938819295525787; // b2
modulator_filter_coeffs[3] = 0.005242268129729576; // -a1
modulator_filter_coeffs[4] = -0.171820482560754689; // -a2
modulator_filter_data = {1, &modulator_filter_state, modulator_filter_coeffs};
return (true);
float32_t A = sqrt(powf(10, gain / 20.0f));
float32_t w0 = 2.0f * PI * fc / ((float32_t)AUDIO_SAMPLE_RATE_EXACT);
float32_t cosw0 = cosf(w0);
float32_t sinw0 = sinf(w0);
float32_t alpha = sinw0 / (2.0f * width);
float32_t a0 = 1.0f + alpha / A;
modulator_filter_coeffs[0] = (1.0f + alpha * A) / a0; // b0
modulator_filter_coeffs[1] = (-2.0f * cosw0) / a0; // b1
modulator_filter_coeffs[2] = (1.0f - alpha * A) / a0; // b2
modulator_filter_coeffs[3] = -(2.0f * cosw0) / -a0; // -a1
modulator_filter_coeffs[4] = (1.0f - alpha / A) / -a0; // -a2
// OmegaC = 0.5, SR = 44117.64706, Fc = 11 kHz, N=2
/* modulator_filter_coeffs[0] = 0.291938819295525787; // b0
modulator_filter_coeffs[1] = 0.582700575839973478; // b1
modulator_filter_coeffs[2] = 0.291938819295525787; // b2
modulator_filter_coeffs[3] = 0.005242268129729576; // -a1
modulator_filter_coeffs[4] = -0.171820482560754689; // -a2 */
}
void AudioEffectModulatedDelay::update(void)

@ -49,6 +49,7 @@ class AudioEffectModulatedDelay :
virtual float offset(float offset_value);
private:
void set_modulator_filter_coeffs(float gain, float fc, float width);
audio_block_t *inputQueueArray[2];
int16_t *_delayline; // pointer for the circular buffer
uint16_t _cb_index; // current write pointer of the circular buffer

Loading…
Cancel
Save