From 4d04f28815e5e0f7cccba5fde53398fb34d837d1 Mon Sep 17 00:00:00 2001 From: Holger Wirtz Date: Mon, 26 Aug 2019 14:58:41 +0200 Subject: [PATCH] Next test. --- effect_modulated_delay.cpp | 25 +++++++++++++++++++++++-- 1 file changed, 23 insertions(+), 2 deletions(-) diff --git a/effect_modulated_delay.cpp b/effect_modulated_delay.cpp index 9395811..cdd509d 100644 --- a/effect_modulated_delay.cpp +++ b/effect_modulated_delay.cpp @@ -107,6 +107,7 @@ void AudioEffectModulatedDelay::update(void) if (block && modulation) { int16_t *bp; + int16_t cb_mod_index_neighbor; float *mp; float mod_index; float mod_number; @@ -130,11 +131,31 @@ void AudioEffectModulatedDelay::update(void) 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 - cb_mod_index = (_cb_index - (_delay_offset + int(mod_index))) % _delay_length; + cb_mod_index = (_cb_index - (_delay_offset + int(mod_index))); + if (cb_mod_index >= _delay_length) + cb_mod_index -= _delay_length; if (cb_mod_index < 0) // check for negative offsets and correct them cb_mod_index += _delay_length; - *bp = round(float(_delayline[cb_mod_index]) * mod_fraction + float(_delayline[cb_mod_index + 1]) * (1.0 - mod_fraction)); + if (*mp < 0.0) + { + if (cb_mod_index == 0) + cb_mod_index_neighbor = _delay_length; + else + cb_mod_index_neighbor = cb_mod_index - 1; + } + else + { + if (cb_mod_index == _delay_length) + cb_mod_index_neighbor = 0; + else + cb_mod_index_neighbor = cb_mod_index + 1; + } + + if (*mp < 0.0) + *bp = round(float(_delayline[cb_mod_index]) * mod_fraction + float(_delayline[cb_mod_index_neighbor]) * (1.0 - mod_fraction)); + else + *bp = round(float(_delayline[cb_mod_index_neighbor]) * mod_fraction + float(_delayline[cb_mod_index]) * (1.0 - mod_fraction)); // push the pointers forward bp++; // next audio data