@ -23,7 +23,7 @@
# include <Arduino.h>
# include <Audio.h>
# include "limits .h"
# include "arm_math .h"
# include "effect_modulated_delay.h"
# include "config.h"
@ -73,50 +73,54 @@ void AudioEffectModulatedDelay::update(void)
block = receiveWritable ( 0 ) ;
modulation = receiveReadOnly ( 1 ) ;
if ( block & & modulation )
if ( block & & modulation & & _modulation_intensity > 0.1 )
{
int16_t * bp ;
int16_ t * mp ;
floa t * mp ;
float mod_idx ;
float mod_number ;
float mod_fraction ;
float mod_float [ AUDIO_BLOCK_SAMPLES ] ;
bp = block - > data ;
mp = modulation - > data ;
arm_q15_to_float ( modulation - > data , mod_float , AUDIO_BLOCK_SAMPLES ) ;
mp = mod_float ;
for ( uint16_t i = 0 ; i < AUDIO_BLOCK_SAMPLES ; i + + )
{
// write data into circular buffer
// write data into circular buffer (delayline)
if ( _circ_idx > = _delay_length )
_circ_idx = 0 ;
_delayline [ _circ_idx ] = * bp ;
// Calculate the modulation-index as a floating point number fo late r interpolation
mod_idx = _delay_offset + ( ( float ( * mp ) / SHRT_MAX ) * _modulation_intensity ) ;
// Calculate the modulation-index as a floating point number for interpolation
mod_idx = _delay_offset + ( * mp * _modulation_intensity ) ;
mod_fraction = modff ( mod_idx , & mod_number ) ;
// linear interpolation
c_mod_idx = _circ_idx - round ( mod_idx ) ;
c_mod_idx % = _delay_length ;
// calculate modulation index into circular buffer
c_mod_idx = ( _circ_idx - int ( mod_number ) ) % _delay_length ;
if ( c_mod_idx < 0 ) // check for negative offsets and correct them
c_mod_idx + = _delay_length ;
if ( c_mod_idx - 1 < 0 )
// linear interpolation
if ( c_mod_idx < 1 )
{
idx [ 0 ] = 0 ;
idx [ 1 ] = _delay_length - 1 ;
idx [ 0 ] = _delay_length - 1 ;
idx [ 1 ] = 0 ;
}
else if ( c_mod_idx + 1 > = _delay_length )
{
idx [ 0 ] = c_mod_idx ;
idx [ 1 ] = 0 ;
idx [ 0 ] = 0 ;
idx [ 1 ] = c_mod_idx ;
}
else
{
idx [ 0 ] = c_mod_idx ;
idx [ 1 ] = c_mod_idx + 1 ;
idx [ 0 ] = c_mod_idx + 1 ;
idx [ 1 ] = c_mod_idx ;
}
* bp = round ( float ( _delayline [ idx [ 0 ] ] ) * mod_fraction + float ( _delayline [ idx [ 1 ] ] ) * ( 1.0 - mod_fraction ) ) ;
* bp = round ( float ( _delayline [ idx [ 0 ] ] ) * ( mod_fraction ) + float ( _delayline [ idx [ 1 ] ] ) * ( 1.0 - mod_fraction ) ) ;
// push the pointers forward
bp + + ; // next audio data
mp + + ; // next modulation data
_circ_idx + + ; // next circular buffer index
@ -133,7 +137,7 @@ void AudioEffectModulatedDelay::update(void)
}
}
float AudioEffectModulatedDelay : : offset ( float offset_value )
float AudioEffectModulatedDelay : : offset ( float offset_value ) // in ms
{
uint16_t offset_frames = ( offset_value / 1000 ) * AUDIO_SAMPLE_RATE ;
if ( offset_frames > _delay_length * MODULATION_MAX_FACTOR )