From 3393c60ed686229a0f5ca661bcf30f42e43799ce Mon Sep 17 00:00:00 2001 From: Holger Wirtz Date: Thu, 22 Aug 2019 14:51:35 +0200 Subject: [PATCH] Filter for modulator implemented again (just testing). --- effect_modulated_delay.cpp | 19 ++++++++++++------- effect_modulated_delay.h | 5 ++++- 2 files changed, 16 insertions(+), 8 deletions(-) diff --git a/effect_modulated_delay.cpp b/effect_modulated_delay.cpp index a203e0e..f3ad4df 100644 --- a/effect_modulated_delay.cpp +++ b/effect_modulated_delay.cpp @@ -58,6 +58,16 @@ boolean AudioEffectModulatedDelay::begin(short *delayline, int d_length) _delayline = delayline; _delay_length = d_length; + // modulator filter + // coefficients calculated with "IOWA Hills IIR Filter Designer 6.5" + // 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 + modulator_filter_data = {1, &modulator_filter_state, modulator_filter_coeffs}; + return (true); } @@ -65,8 +75,6 @@ void AudioEffectModulatedDelay::update(void) { audio_block_t *block; audio_block_t *modulation; - float alpha = 0.9f; // 90% new value, 10% feedback - static float filteredOutput; if (_delayline == NULL) return; @@ -85,6 +93,7 @@ void AudioEffectModulatedDelay::update(void) bp = block->data; arm_q15_to_float(modulation->data, modulation_f32, AUDIO_BLOCK_SAMPLES); + arm_biquad_cascade_df1_f32(&modulator_filter_data, modulation_f32, modulation_f32, AUDIO_BLOCK_SAMPLES); mp = modulation_f32; for (uint16_t i = 0; i < AUDIO_BLOCK_SAMPLES; i++) @@ -94,12 +103,8 @@ void AudioEffectModulatedDelay::update(void) _cb_index = 0; _delayline[_cb_index] = *bp; - // Simple 1st order IIR, mix the new value with the old value (for modulation to get a band-limited signal) - filteredOutput = (*mp * alpha) + filteredOutput * (1 - alpha); - // Calculate the modulation-index as a floating point number for interpolation - //mod_index = *mp * (1 - MODULATION_MAX_FACTOR) * _delay_length; // "(1 - MODULATION_MAX_FACTOR) * _delay_length" means: maximum bytes of modulation allowed by given delay length - mod_index = filteredOutput * (1 - MODULATION_MAX_FACTOR) * _delay_length; // "(1 - MODULATION_MAX_FACTOR) * _delay_length" means: maximum bytes of modulation allowed by given delay length + mod_index = *mp * (1 - MODULATION_MAX_FACTOR) * _delay_length; // "(1 - MODULATION_MAX_FACTOR) * _delay_length" means: maximum bytes of modulation allowed by given delay length mod_fraction = modff(mod_index, &mod_number); // split float of mod_index into integer (= mod_number) and fraction part // calculate modulation index into circular buffer diff --git a/effect_modulated_delay.h b/effect_modulated_delay.h index 41d689b..2c9d04b 100644 --- a/effect_modulated_delay.h +++ b/effect_modulated_delay.h @@ -54,7 +54,10 @@ class AudioEffectModulatedDelay : uint16_t _cb_index; // current write pointer of the circular buffer uint16_t _delay_offset; // number of samples for the read offset of the modulation inside the circular buffer uint16_t _delay_length; // calculated number of samples of the delay - int16_t cb_mod_index; // current read pointer with modulation for the circular buffer + int16_t cb_mod_index; // current read pointer with modulation for the circular buffer + arm_biquad_casd_df1_inst_f32 modulator_filter_data; + float32_t modulator_filter_state; + float32_t modulator_filter_coeffs[5]; }; #endif