Slightly better simple interpolation code.

master
Holger Wirtz 6 years ago
parent 1b19fdb7f0
commit be62fba2e0
  1. 49
      effect_modulated_delay.cpp

@ -87,6 +87,8 @@ void AudioEffectModulatedDelay::update(void)
if (block && modulation) if (block && modulation)
{ {
float _tmp;
for (uint16_t i = 0; i < AUDIO_BLOCK_SAMPLES; i++) for (uint16_t i = 0; i < AUDIO_BLOCK_SAMPLES; i++)
{ {
// write data into circular buffer // write data into circular buffer
@ -100,9 +102,9 @@ void AudioEffectModulatedDelay::update(void)
#ifdef INTERPOLATE_MODE #ifdef INTERPOLATE_MODE
// Generate a an array with the size of INTERPOLATION_WINDOW_SIZE of x/y values around mod_idx for interpolation // Generate a an array with the size of INTERPOLATION_WINDOW_SIZE of x/y values around mod_idx for interpolation
uint8_t c = 0; uint8_t c;
int16_t c_mod_idx = _circ_idx - int(mod_idx + 0.5); // This is the pointer to the value in the circular buffer at the current modulation index int16_t c_mod_idx = _circ_idx - int(mod_idx + 0.5); // This is the pointer to the value in the circular buffer at the current modulation index
for (j = ~(INTERPOLATION_WINDOW_SIZE >> 1) | 0x01; j <= INTERPOLATION_WINDOW_SIZE >> 1; j++) // only another way to say: from -INTERPOLATION_WINDOW_SIZE/2 to INTERPOLATION_WINDOW_SIZE/2 for (j = ~(INTERPOLATION_WINDOW_SIZE >> 1) | 0x01, c = 0; j <= INTERPOLATION_WINDOW_SIZE >> 1; j++, c++) // only another way to say: from -INTERPOLATION_WINDOW_SIZE/2 to INTERPOLATION_WINDOW_SIZE/2
{ {
int16_t jc_mod_idx = (c_mod_idx + j) % _delay_length; // The modulation index pointer plus the value of the current window pointer int16_t jc_mod_idx = (c_mod_idx + j) % _delay_length; // The modulation index pointer plus the value of the current window pointer
if (jc_mod_idx < 0) if (jc_mod_idx < 0)
@ -110,25 +112,40 @@ void AudioEffectModulatedDelay::update(void)
else else
y[c] = float(_delayline[jc_mod_idx]); y[c] = float(_delayline[jc_mod_idx]);
x[c] = float(j); x[c] = float(j);
c++; // because 42 is the answer! ;-)
} }
*bp = int(s.value(modff(mod_idx, NULL)) + 0.5); *bp = int(s.value(modff(mod_idx, &_tmp)) + 0.5);
#else #else
// No interpolation - should sound really bad... // Simple interpolation
int16_t c_mod_idx = (_circ_idx - int(mod_idx + 0.5)) % _delay_length; int16_t c_mod_idx = (_circ_idx - int(mod_idx + 0.5)) % _delay_length;
float fraction = modff(mod_idx, &_tmp);
float value1, value2;
if (c_mod_idx < 0) if (c_mod_idx < 0)
*bp = _delayline[_delay_length + c_mod_idx]; {
if (fraction < 0.5)
{
value1 = _delayline[_delay_length + c_mod_idx - 1];
value2 = _delayline[_delay_length + c_mod_idx];
}
else
{
value1 = _delayline[_delay_length + c_mod_idx];
value2 = _delayline[_delay_length + c_mod_idx + 1];
}
}
else else
*bp = _delayline[c_mod_idx]; {
/* Serial.print("mod_idx="); if (fraction < 0.5)
Serial.print(mod_idx, 3); {
Serial.print(" c_mod_idx="); value1 = _delayline[c_mod_idx - 1];
Serial.print(c_mod_idx, DEC); value2 = _delayline[c_mod_idx];
Serial.print(" MODULATION="); }
Serial.print(*mp, DEC); else
Serial.print(" DATA="); {
Serial.print(*bp, DEC); value1 = _delayline[c_mod_idx];
Serial.println();*/ value2 = _delayline[c_mod_idx + 1];
}
}
*bp = int ((fraction * value1) + ((1.0 - fraction) * value2) + 0.5);
#endif #endif
bp++; // next audio data bp++; // next audio data

Loading…
Cancel
Save