@@ -314,19 +314,21 @@ STATIC void run_fir(synthio_synth_t *synth, int32_t *out_buffer32, uint16_t dur)
314314 size_t fir_len = synth -> filter_bufinfo .len / sizeof (int16_t );
315315 int32_t * in_buf = synth -> filter_buffer ;
316316
317+
318+ int synth_chan = synth -> channel_count ;
317319 // 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 ++ ) {
319321 int32_t acc = 0 ;
320322 for (size_t j = 0 ; j < fir_len ; j ++ ) {
321323 // 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 ));
323325 }
324326 * out_buffer32 ++ = acc >> 10 ;
325327 in_buf ++ ;
326328 }
327329
328330 // 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 );
330332}
331333
332334STATIC 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
359361
360362 if (synth -> filter_buffer ) {
361363 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 ));
363365
364366 for (int chan = 0 ; chan < CIRCUITPY_SYNTHIO_MAX_CHANNELS ; chan ++ ) {
365367 mp_obj_t note_obj = synth -> span .note_obj [chan ];
0 commit comments