@@ -314,19 +314,21 @@ STATIC void run_fir(synthio_synth_t *synth, int32_t *out_buffer32, uint16_t dur)
314
314
size_t fir_len = synth -> filter_bufinfo .len / sizeof (int16_t );
315
315
int32_t * in_buf = synth -> filter_buffer ;
316
316
317
+
318
+ int synth_chan = synth -> channel_count ;
317
319
// FIR and copy values to output buffer
318
- for (int16_t i = 0 ; i < dur ; i ++ ) {
320
+ for (int16_t i = 0 ; i < dur * synth_chan ; i ++ ) {
319
321
int32_t acc = 0 ;
320
322
for (size_t j = 0 ; j < fir_len ; j ++ ) {
321
323
// shift 5 here is good for up to 32 filtered voices, else might wrap
322
- acc = acc + (in_buf [j ] * (coeff [j ] >> 5 ));
324
+ acc = acc + (in_buf [j * synth_chan ] * (coeff [j ] >> 5 ));
323
325
}
324
326
* out_buffer32 ++ = acc >> 10 ;
325
327
in_buf ++ ;
326
328
}
327
329
328
330
// Move values down so that they get filtered next time
329
- memmove (synth -> filter_buffer , & synth -> filter_buffer [dur ], fir_len * sizeof (int32_t ));
331
+ memmove (synth -> filter_buffer , & synth -> filter_buffer [dur * synth_chan ], fir_len * sizeof (int32_t ) * synth_chan );
330
332
}
331
333
332
334
STATIC bool synthio_synth_get_note_filtered (mp_obj_t note_obj ) {
@@ -359,7 +361,7 @@ void synthio_synth_synthesize(synthio_synth_t *synth, uint8_t **bufptr, uint32_t
359
361
360
362
if (synth -> filter_buffer ) {
361
363
int32_t * filter_start = & synth -> filter_buffer [synth -> filter_bufinfo .len * synth -> channel_count / sizeof (int16_t )];
362
- memset (filter_start , 0 , dur * sizeof (int32_t ));
364
+ memset (filter_start , 0 , dur * synth -> channel_count * sizeof (int32_t ));
363
365
364
366
for (int chan = 0 ; chan < CIRCUITPY_SYNTHIO_MAX_CHANNELS ; chan ++ ) {
365
367
mp_obj_t note_obj = synth -> span .note_obj [chan ];
0 commit comments