@@ -192,7 +192,7 @@ static void synth_note_into_buffer(synthio_synth_t *synth, int chan, int32_t *ou
192192
193193 uint32_t dds_rate ;
194194 const int16_t * waveform = synth -> waveform_bufinfo .buf ;
195- uint32_t waveform_length = synth -> waveform_bufinfo .len / sizeof ( int16_t ) ;
195+ uint32_t waveform_length = synth -> waveform_bufinfo .len ;
196196
197197 uint32_t ring_dds_rate = 0 ;
198198 const int16_t * ring_waveform = NULL ;
@@ -213,12 +213,12 @@ static void synth_note_into_buffer(synthio_synth_t *synth, int chan, int32_t *ou
213213 int32_t frequency_scaled = synthio_note_step (note , sample_rate , dur , loudness );
214214 if (note -> waveform_buf .buf ) {
215215 waveform = note -> waveform_buf .buf ;
216- waveform_length = note -> waveform_buf .len / sizeof ( int16_t ) ;
216+ waveform_length = note -> waveform_buf .len ;
217217 }
218218 dds_rate = synthio_frequency_convert_scaled_to_dds ((uint64_t )frequency_scaled * waveform_length , sample_rate );
219219 if (note -> ring_frequency_scaled != 0 && note -> ring_waveform_buf .buf ) {
220220 ring_waveform = note -> ring_waveform_buf .buf ;
221- ring_waveform_length = note -> ring_waveform_buf .len / sizeof ( int16_t ) ;
221+ ring_waveform_length = note -> ring_waveform_buf .len ;
222222 ring_dds_rate = synthio_frequency_convert_scaled_to_dds ((uint64_t )note -> ring_frequency_bent * ring_waveform_length , sample_rate );
223223 uint32_t lim = ring_waveform_length << SYNTHIO_FREQUENCY_SHIFT ;
224224 if (ring_dds_rate > lim / sizeof (int16_t )) {
@@ -311,7 +311,7 @@ static void synth_note_into_buffer(synthio_synth_t *synth, int chan, int32_t *ou
311311
312312STATIC void run_fir (synthio_synth_t * synth , int32_t * out_buffer32 , uint16_t dur ) {
313313 int16_t * coeff = (int16_t * )synth -> filter_bufinfo .buf ;
314- size_t fir_len = synth -> filter_bufinfo .len / sizeof ( int16_t ) ;
314+ size_t fir_len = synth -> filter_bufinfo .len ;
315315 int32_t * in_buf = synth -> filter_buffer ;
316316
317317
@@ -362,7 +362,7 @@ void synthio_synth_synthesize(synthio_synth_t *synth, uint8_t **bufptr, uint32_t
362362 int32_t out_buffer32 [dur * synth -> channel_count ];
363363
364364 if (synth -> filter_buffer ) {
365- int32_t * filter_start = & synth -> filter_buffer [synth -> filter_bufinfo .len * synth -> channel_count / sizeof ( int16_t ) ];
365+ int32_t * filter_start = & synth -> filter_buffer [synth -> filter_bufinfo .len * synth -> channel_count ];
366366 memset (filter_start , 0 , dur * synth -> channel_count * sizeof (int32_t ));
367367
368368 for (int chan = 0 ; chan < CIRCUITPY_SYNTHIO_MAX_CHANNELS ; chan ++ ) {
@@ -441,7 +441,7 @@ void synthio_synth_init(synthio_synth_t *synth, uint32_t sample_rate, int channe
441441 synth -> buffers [0 ] = m_malloc (synth -> buffer_length , false);
442442 synth -> buffers [1 ] = m_malloc (synth -> buffer_length , false);
443443 if (synth -> filter_bufinfo .len ) {
444- synth -> filter_buffer_length = (synth -> filter_bufinfo .len / 2 + SYNTHIO_MAX_DUR ) * channel_count * sizeof (int32_t );
444+ synth -> filter_buffer_length = (synth -> filter_bufinfo .len + SYNTHIO_MAX_DUR ) * channel_count * sizeof (int32_t );
445445 synth -> filter_buffer = m_malloc (synth -> filter_buffer_length , false);
446446 }
447447 synth -> channel_count = channel_count ;
@@ -473,12 +473,13 @@ STATIC void parse_common(mp_buffer_info_t *bufinfo, mp_obj_t o, int16_t what, mp
473473 if (bufinfo -> typecode != 'h' ) {
474474 mp_raise_ValueError_varg (translate ("%q must be array of type 'h'" ), what );
475475 }
476- mp_arg_validate_length_range (bufinfo -> len / sizeof (int16_t ), 2 , max_len , what );
476+ bufinfo -> len /= 2 ;
477+ mp_arg_validate_length_range (bufinfo -> len , 2 , max_len , what );
477478 }
478479}
479480
480481void synthio_synth_parse_waveform (mp_buffer_info_t * bufinfo_waveform , mp_obj_t waveform_obj ) {
481- * bufinfo_waveform = ((mp_buffer_info_t ) { .buf = (void * )square_wave , .len = 4 });
482+ * bufinfo_waveform = ((mp_buffer_info_t ) { .buf = (void * )square_wave , .len = 2 });
482483 parse_common (bufinfo_waveform , waveform_obj , MP_QSTR_waveform , 16384 );
483484}
484485
0 commit comments