From 2d348affa1ca4dc4ca287421aaba98cebafc4898 Mon Sep 17 00:00:00 2001 From: Holger Wirtz Date: Thu, 22 Aug 2019 11:26:57 +0200 Subject: [PATCH] Simple 1st-order filter test, as BlackAddr sugested: https://forum.pjrc.com/threads/56532-Modulated-Delay-Chorus-Flanger?highlight=Chorus --- effect_modulated_delay.cpp | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) diff --git a/effect_modulated_delay.cpp b/effect_modulated_delay.cpp index 79e32f9..a203e0e 100644 --- a/effect_modulated_delay.cpp +++ b/effect_modulated_delay.cpp @@ -65,6 +65,8 @@ 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; @@ -92,8 +94,12 @@ 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 = *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_fraction = modff(mod_index, &mod_number); // split float of mod_index into integer (= mod_number) and fraction part // calculate modulation index into circular buffer @@ -102,7 +108,7 @@ void AudioEffectModulatedDelay::update(void) cb_mod_index += _delay_length; *bp = round(float(_delayline[cb_mod_index]) * mod_fraction + float(_delayline[cb_mod_index + 1]) * (1.0 - mod_fraction)); - + // push the pointers forward bp++; // next audio data mp++; // next modulation data