@@ -192,7 +192,7 @@ static void synth_note_into_buffer(synthio_synth_t *synth, int chan, int32_t *ou
192
192
193
193
uint32_t dds_rate ;
194
194
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 ;
196
196
197
197
uint32_t ring_dds_rate = 0 ;
198
198
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
213
213
int32_t frequency_scaled = synthio_note_step (note , sample_rate , dur , loudness );
214
214
if (note -> waveform_buf .buf ) {
215
215
waveform = note -> waveform_buf .buf ;
216
- waveform_length = note -> waveform_buf .len / sizeof ( int16_t ) ;
216
+ waveform_length = note -> waveform_buf .len ;
217
217
}
218
218
dds_rate = synthio_frequency_convert_scaled_to_dds ((uint64_t )frequency_scaled * waveform_length , sample_rate );
219
219
if (note -> ring_frequency_scaled != 0 && note -> ring_waveform_buf .buf ) {
220
220
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 ;
222
222
ring_dds_rate = synthio_frequency_convert_scaled_to_dds ((uint64_t )note -> ring_frequency_bent * ring_waveform_length , sample_rate );
223
223
uint32_t lim = ring_waveform_length << SYNTHIO_FREQUENCY_SHIFT ;
224
224
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
311
311
312
312
STATIC void run_fir (synthio_synth_t * synth , int32_t * out_buffer32 , uint16_t dur ) {
313
313
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 ;
315
315
int32_t * in_buf = synth -> filter_buffer ;
316
316
317
317
@@ -362,7 +362,7 @@ void synthio_synth_synthesize(synthio_synth_t *synth, uint8_t **bufptr, uint32_t
362
362
int32_t out_buffer32 [dur * synth -> channel_count ];
363
363
364
364
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 ];
366
366
memset (filter_start , 0 , dur * synth -> channel_count * sizeof (int32_t ));
367
367
368
368
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
441
441
synth -> buffers [0 ] = m_malloc (synth -> buffer_length , false);
442
442
synth -> buffers [1 ] = m_malloc (synth -> buffer_length , false);
443
443
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 );
445
445
synth -> filter_buffer = m_malloc (synth -> filter_buffer_length , false);
446
446
}
447
447
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
473
473
if (bufinfo -> typecode != 'h' ) {
474
474
mp_raise_ValueError_varg (translate ("%q must be array of type 'h'" ), what );
475
475
}
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 );
477
478
}
478
479
}
479
480
480
481
void 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 });
482
483
parse_common (bufinfo_waveform , waveform_obj , MP_QSTR_waveform , 16384 );
483
484
}
484
485
0 commit comments