@ -46,7 +46,7 @@ boolean AudioEffectModulatedDelay::begin(short *delayline, int d_length)
_delayline = NULL ;
_delay_length = 0 ;
_delay_offset = 0.0 ;
_circ_id x = 0 ;
_cb_inde x = 0 ;
if ( delayline = = NULL ) {
return ( false ) ;
@ -58,17 +58,6 @@ boolean AudioEffectModulatedDelay::begin(short *delayline, int d_length)
_delayline = delayline ;
_delay_length = d_length ;
# ifdef CHORUS_MODULATOR_BIQUAD
filter_lp_mod . numStages = 1 ;
filter_lp_mod . pState = filter_lp_state ;
filter_lp_mod . pCoeffs = filter_lp_coeffs ;
filter_lp_coeffs [ 0 ] = 0.072959657268266670 ;
filter_lp_coeffs [ 1 ] = 0.072959657268266670 ;
filter_lp_coeffs [ 2 ] = 0.0 ;
filter_lp_coeffs [ 3 ] = 0.854080685463466605 ;
filter_lp_coeffs [ 4 ] = 0.0 ;
# endif
return ( true ) ;
}
@ -87,7 +76,7 @@ void AudioEffectModulatedDelay::update(void)
{
int16_t * bp ;
float * mp ;
float mod_idx ;
float mod_in de x ;
float mod_number ;
float mod_fraction ;
float modulation_f32 [ AUDIO_BLOCK_SAMPLES ] ;
@ -95,51 +84,29 @@ void AudioEffectModulatedDelay::update(void)
bp = block - > data ;
arm_q15_to_float ( modulation - > data , modulation_f32 , AUDIO_BLOCK_SAMPLES ) ;
mp = modulation_f32 ;
# ifdef CHORUS_MODULATOR_BIQUAD
arm_biquad_cascade_df1_f32 ( & filter_lp_mod , modulation_f32 , modulation_f32 , AUDIO_BLOCK_SAMPLES ) ;
# endif
for ( uint16_t i = 0 ; i < AUDIO_BLOCK_SAMPLES ; i + + )
{
// write data into circular buffer (delayline)
if ( _circ_id x > = _delay_length )
_circ_id x = 0 ;
_delayline [ _circ_id x ] = * bp ;
if ( _cb_inde x > = _delay_length )
_cb_inde x = 0 ;
_delayline [ _cb_inde x ] = * bp ;
// Calculate the modulation-index as a floating point number for interpolation
mod_idx = * mp * ( 1 - MODULATION_MAX_FACTOR ) * _delay_length ;
mod_fraction = modff ( mod_idx , & mod_number ) ;
mod_in de x = * 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_in de x , & mod_number ) ; // split float of mod_index into integer (= mod_number) and fraction part
// calculate modulation index into circular buffer
c_mod_idx = ( _circ_idx - _delay_offset - int ( mod_number ) ) % _delay_length ;
if ( c_mod_idx < 0 ) // check for negative offsets and correct them
c_mod_idx + = _delay_length ;
// linear interpolation
if ( c_mod_idx = = 0 )
{
idx [ 0 ] = _delay_length - 1 ;
idx [ 1 ] = 0 ;
}
else if ( c_mod_idx = = _delay_length - 1 )
{
idx [ 0 ] = 0 ;
idx [ 1 ] = _delay_length - 1 ;
}
else
{
idx [ 0 ] = c_mod_idx ;
idx [ 1 ] = c_mod_idx + 1 ;
}
if ( mod_idx < 0.0 )
* bp = round ( float ( _delayline [ idx [ 0 ] ] ) * fabs ( mod_fraction ) + float ( _delayline [ idx [ 1 ] ] ) * ( 1.0 - fabs ( mod_fraction ) ) ) ;
else
* bp = round ( float ( _delayline [ idx [ 0 ] ] ) * ( 1.0 - mod_fraction ) + float ( _delayline [ idx [ 1 ] ] ) * mod_fraction ) ;
cb_mod_index = ( _cb_index - ( _delay_offset + int ( 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 ) ) ;
// push the pointers forward
bp + + ; // next audio data
mp + + ; // next modulation data
_circ_id x + + ; // next circular buffer index
_cb_index + + ; // next circular buffer index
}
}