@@ -221,10 +221,10 @@ audioio_get_buffer_result_t audiofilters_phaser_get_buffer(audiofilters_phaser_o
221
221
// get the effect values we need from the BlockInput. These may change at run time so you need to do bounds checking if required
222
222
shared_bindings_synthio_lfo_tick (self -> base .sample_rate , n / self -> base .channel_count );
223
223
mp_float_t frequency = synthio_block_slot_get_limited (& self -> frequency , MICROPY_FLOAT_CONST (0.0 ), self -> nyquist );
224
- mp_float_t feedback = synthio_block_slot_get_limited (& self -> feedback , MICROPY_FLOAT_CONST (0.1 ), MICROPY_FLOAT_CONST (0.9 ));
225
- mp_float_t mix = synthio_block_slot_get_limited (& self -> mix , MICROPY_FLOAT_CONST (0.0 ), MICROPY_FLOAT_CONST (1.0 ));
224
+ int16_t feedback = ( int16_t )( synthio_block_slot_get_limited (& self -> feedback , MICROPY_FLOAT_CONST (0.1 ), MICROPY_FLOAT_CONST (0.9 )) * 32767 );
225
+ int16_t mix = ( int16_t )( synthio_block_slot_get_limited (& self -> mix , MICROPY_FLOAT_CONST (0.0 ), MICROPY_FLOAT_CONST (1.0 )) * 32767 );
226
226
227
- if (mix <= MICROPY_FLOAT_CONST ( 0.01 )) { // if mix is zero pure sample only
227
+ if (mix <= 328 ) { // if mix is zero (0.01 in fixed point), pure sample only
228
228
for (uint32_t i = 0 ; i < n ; i ++ ) {
229
229
if (MP_LIKELY (self -> base .bits_per_sample == 16 )) {
230
230
word_buffer [i ] = sample_src [i ];
@@ -233,10 +233,9 @@ audioio_get_buffer_result_t audiofilters_phaser_get_buffer(audiofilters_phaser_o
233
233
}
234
234
}
235
235
} else {
236
-
237
236
// Update all-pass filter coefficient
238
- mp_float_t allpasscoef = frequency / self -> nyquist ;
239
- allpasscoef = (MICROPY_FLOAT_CONST (1.0 ) - allpasscoef ) / (MICROPY_FLOAT_CONST (1.0 ) + allpasscoef );
237
+ frequency /= self -> nyquist ; // scale relative to frequency range
238
+ int16_t allpasscoef = (int16_t )(( MICROPY_FLOAT_CONST (1.0 ) - frequency ) / (MICROPY_FLOAT_CONST (1.0 ) + frequency ) * 32767 );
240
239
241
240
for (uint32_t i = 0 ; i < n ; i ++ ) {
242
241
bool right_channel = (single_channel_output && channel == 1 ) || (!single_channel_output && (i % self -> base .channel_count ) == 1 );
@@ -254,19 +253,19 @@ audioio_get_buffer_result_t audiofilters_phaser_get_buffer(audiofilters_phaser_o
254
253
}
255
254
}
256
255
257
- int32_t word = sample_word + self -> word_buffer [right_channel ] * feedback ;
256
+ int32_t word = synthio_sat16 ( sample_word + synthio_sat16 ( self -> word_buffer [right_channel ] * feedback , 15 ), 0 ) ;
258
257
int32_t allpass_word = 0 ;
259
258
260
259
// Update all-pass filters
261
260
for (uint32_t j = 0 ; j < self -> stages ; j ++ ) {
262
- allpass_word = word * - allpasscoef + self -> allpass_buffer [j + allpass_buffer_offset ];
263
- self -> allpass_buffer [j + allpass_buffer_offset ] = allpass_word * allpasscoef + word ;
261
+ allpass_word = synthio_sat16 ( synthio_sat16 ( word * - allpasscoef , 15 ) + self -> allpass_buffer [j + allpass_buffer_offset ], 0 ) ;
262
+ self -> allpass_buffer [j + allpass_buffer_offset ] = synthio_sat16 ( synthio_sat16 ( allpass_word * allpasscoef , 15 ) + word , 0 ) ;
264
263
word = allpass_word ;
265
264
}
266
265
self -> word_buffer [(bool )allpass_buffer_offset ] = word ;
267
266
268
267
// Add original sample + effect
269
- word = sample_word + (int32_t )(word * mix );
268
+ word = sample_word + (int32_t )(synthio_sat16 ( word * mix , 15 ) );
270
269
word = synthio_mix_down_sample (word , 2 );
271
270
272
271
if (MP_LIKELY (self -> base .bits_per_sample == 16 )) {
0 commit comments