@@ -292,28 +292,8 @@ audioio_get_buffer_result_t audiodelays_echo_get_buffer(audiodelays_echo_obj_t *
292
292
int8_t * hword_buffer = self -> buffer [self -> last_buf_idx ];
293
293
uint32_t length = self -> buffer_len / (self -> bits_per_sample / 8 );
294
294
295
- // get the effect values we need from the BlockInput. These may change at run time so you need to do bounds checking if required
296
- shared_bindings_synthio_lfo_tick (self -> sample_rate , length / self -> channel_count );
297
- mp_float_t mix = synthio_block_slot_get_limited (& self -> mix , MICROPY_FLOAT_CONST (0.0 ), MICROPY_FLOAT_CONST (1.0 ));
298
- mp_float_t decay = synthio_block_slot_get_limited (& self -> decay , MICROPY_FLOAT_CONST (0.0 ), MICROPY_FLOAT_CONST (1.0 ));
299
-
300
- uint32_t delay_ms = (uint32_t )synthio_block_slot_get (& self -> delay_ms );
301
- if (self -> current_delay_ms != delay_ms ) {
302
- recalculate_delay (self , delay_ms );
303
- }
304
-
305
295
// The echo buffer is always stored as a 16-bit value internally
306
296
int16_t * echo_buffer = (int16_t * )self -> echo_buffer ;
307
- uint32_t echo_buf_len = self -> echo_buffer_len / sizeof (uint16_t );
308
-
309
- // Set our echo buffer position accounting for stereo
310
- uint32_t echo_buffer_pos = 0 ;
311
- if (self -> freq_shift ) {
312
- echo_buffer_pos = self -> echo_buffer_left_pos ;
313
- if (channel == 1 ) {
314
- echo_buffer_pos = self -> echo_buffer_right_pos ;
315
- }
316
- }
317
297
318
298
// Loop over the entire length of our buffer to fill it, this may require several calls to get data from the sample
319
299
while (length != 0 ) {
@@ -335,6 +315,35 @@ audioio_get_buffer_result_t audiodelays_echo_get_buffer(audiodelays_echo_obj_t *
335
315
}
336
316
}
337
317
318
+ // Determine how many bytes we can process to our buffer, the less of the sample we have left and our buffer remaining
319
+ uint32_t n ;
320
+ if (self -> sample == NULL ) {
321
+ n = MIN (length , SYNTHIO_MAX_DUR * self -> channel_count );
322
+ } else {
323
+ n = MIN (MIN (self -> sample_buffer_length , length ), SYNTHIO_MAX_DUR * self -> channel_count );
324
+ }
325
+
326
+ // get the effect values we need from the BlockInput. These may change at run time so you need to do bounds checking if required
327
+ shared_bindings_synthio_lfo_tick (self -> sample_rate , n / self -> channel_count );
328
+ mp_float_t mix = synthio_block_slot_get_limited (& self -> mix , MICROPY_FLOAT_CONST (0.0 ), MICROPY_FLOAT_CONST (1.0 ));
329
+ mp_float_t decay = synthio_block_slot_get_limited (& self -> decay , MICROPY_FLOAT_CONST (0.0 ), MICROPY_FLOAT_CONST (1.0 ));
330
+
331
+ uint32_t delay_ms = (uint32_t )synthio_block_slot_get (& self -> delay_ms );
332
+ if (self -> current_delay_ms != delay_ms ) {
333
+ recalculate_delay (self , delay_ms );
334
+ }
335
+
336
+ uint32_t echo_buf_len = self -> echo_buffer_len / sizeof (uint16_t );
337
+
338
+ // Set our echo buffer position accounting for stereo
339
+ uint32_t echo_buffer_pos = 0 ;
340
+ if (self -> freq_shift ) {
341
+ echo_buffer_pos = self -> echo_buffer_left_pos ;
342
+ if (channel == 1 ) {
343
+ echo_buffer_pos = self -> echo_buffer_right_pos ;
344
+ }
345
+ }
346
+
338
347
// If we have no sample keep the echo echoing
339
348
if (self -> sample == NULL ) {
340
349
if (mix <= MICROPY_FLOAT_CONST (0.01 )) { // Mix of 0 is pure sample sound. We have no sample so no sound
@@ -401,9 +410,6 @@ audioio_get_buffer_result_t audiodelays_echo_get_buffer(audiodelays_echo_obj_t *
401
410
length = 0 ;
402
411
} else {
403
412
// we have a sample to play and echo
404
- // Determine how many bytes we can process to our buffer, the less of the sample we have left and our buffer remaining
405
- uint32_t n = MIN (self -> sample_buffer_length , length );
406
-
407
413
int16_t * sample_src = (int16_t * )self -> sample_remaining_buffer ; // for 16-bit samples
408
414
int8_t * sample_hsrc = (int8_t * )self -> sample_remaining_buffer ; // for 8-bit samples
409
415
@@ -501,13 +507,13 @@ audioio_get_buffer_result_t audiodelays_echo_get_buffer(audiodelays_echo_obj_t *
501
507
self -> sample_remaining_buffer += (n * (self -> bits_per_sample / 8 ));
502
508
self -> sample_buffer_length -= n ;
503
509
}
504
- }
505
510
506
- if (self -> freq_shift ) {
507
- if (channel == 0 ) {
508
- self -> echo_buffer_left_pos = echo_buffer_pos ;
509
- } else if (channel == 1 ) {
510
- self -> echo_buffer_right_pos = echo_buffer_pos ;
511
+ if (self -> freq_shift ) {
512
+ if (channel == 0 ) {
513
+ self -> echo_buffer_left_pos = echo_buffer_pos ;
514
+ } else if (channel == 1 ) {
515
+ self -> echo_buffer_right_pos = echo_buffer_pos ;
516
+ }
511
517
}
512
518
}
513
519
0 commit comments