@@ -77,7 +77,7 @@ void common_hal_audiodelays_echo_construct(audiodelays_echo_obj_t *self, uint32_
77
77
78
78
// Allocate the echo buffer for the max possible delay, echo is always 16-bit
79
79
self -> max_delay_ms = max_delay_ms ;
80
- self -> max_echo_buffer_len = self -> sample_rate / 1000.0f * max_delay_ms * (self -> channel_count * sizeof (uint16_t )); // bytes
80
+ self -> max_echo_buffer_len = ( uint32_t )( self -> sample_rate / 1000.0f * max_delay_ms ) * (self -> channel_count * sizeof (uint16_t )); // bytes
81
81
self -> echo_buffer = m_malloc (self -> max_echo_buffer_len );
82
82
if (self -> echo_buffer == NULL ) {
83
83
common_hal_audiodelays_echo_deinit (self );
@@ -129,11 +129,11 @@ void common_hal_audiodelays_echo_set_delay_ms(audiodelays_echo_obj_t *self, mp_o
129
129
void recalculate_delay (audiodelays_echo_obj_t * self , mp_float_t f_delay_ms ) {
130
130
if (self -> freq_shift ) {
131
131
// Calculate the rate of iteration over the echo buffer with 8 sub-bits
132
- self -> echo_buffer_rate = MAX (self -> max_delay_ms / f_delay_ms * 256.0f , 1.0 );
132
+ self -> echo_buffer_rate = ( uint32_t ) MAX (self -> max_delay_ms / f_delay_ms * MICROPY_FLOAT_CONST ( 256.0 ), MICROPY_FLOAT_CONST ( 1.0 ) );
133
133
self -> echo_buffer_len = self -> max_echo_buffer_len ;
134
134
} else {
135
135
// Calculate the current echo buffer length in bytes
136
- uint32_t new_echo_buffer_len = self -> sample_rate / 1000.0f * f_delay_ms * (self -> channel_count * sizeof (uint16_t ));
136
+ uint32_t new_echo_buffer_len = ( uint32_t )( self -> sample_rate / MICROPY_FLOAT_CONST ( 1000.0 ) * f_delay_ms ) * (self -> channel_count * sizeof (uint16_t ));
137
137
138
138
// Check if our new echo is too long for our maximum buffer
139
139
if (new_echo_buffer_len > self -> max_echo_buffer_len ) {
@@ -153,7 +153,7 @@ void recalculate_delay(audiodelays_echo_obj_t *self, mp_float_t f_delay_ms) {
153
153
memset (self -> echo_buffer + self -> echo_buffer_len , 0 , self -> max_echo_buffer_len - self -> echo_buffer_len );
154
154
}
155
155
156
- self -> current_delay_ms = f_delay_ms ;
156
+ self -> current_delay_ms = ( uint32_t ) f_delay_ms ;
157
157
}
158
158
159
159
mp_obj_t common_hal_audiodelays_echo_get_decay (audiodelays_echo_obj_t * self ) {
@@ -360,17 +360,17 @@ audioio_get_buffer_result_t audiodelays_echo_get_buffer(audiodelays_echo_obj_t *
360
360
echo = echo_buffer [echo_buffer_pos >> 8 ];
361
361
next_buffer_pos = echo_buffer_pos + self -> echo_buffer_rate ;
362
362
363
- word = echo * decay ;
363
+ word = ( int16_t )( echo * decay ) ;
364
364
for (uint32_t j = echo_buffer_pos >> 8 ; j < next_buffer_pos >> 8 ; j ++ ) {
365
365
echo_buffer [j % echo_buf_len ] = word ;
366
366
}
367
367
} else {
368
368
echo = echo_buffer [self -> echo_buffer_read_pos ++ ];
369
- word = echo * decay ;
369
+ word = ( int16_t )( echo * decay ) ;
370
370
echo_buffer [self -> echo_buffer_write_pos ++ ] = word ;
371
371
}
372
372
373
- word = echo * mix ;
373
+ word = ( int16_t )( echo * mix ) ;
374
374
375
375
if (MP_LIKELY (self -> bits_per_sample == 16 )) {
376
376
word_buffer [i ] = word ;
@@ -433,10 +433,10 @@ audioio_get_buffer_result_t audiodelays_echo_get_buffer(audiodelays_echo_obj_t *
433
433
if (self -> freq_shift ) {
434
434
echo = echo_buffer [echo_buffer_pos >> 8 ];
435
435
next_buffer_pos = echo_buffer_pos + self -> echo_buffer_rate ;
436
- word = echo * decay + sample_word ;
436
+ word = ( int32_t )( echo * decay + sample_word ) ;
437
437
} else {
438
438
echo = echo_buffer [self -> echo_buffer_read_pos ++ ];
439
- word = echo * decay + sample_word ;
439
+ word = ( int32_t )( echo * decay + sample_word ) ;
440
440
}
441
441
442
442
if (MP_LIKELY (self -> bits_per_sample == 16 )) {
@@ -467,12 +467,12 @@ audioio_get_buffer_result_t audiodelays_echo_get_buffer(audiodelays_echo_obj_t *
467
467
word = echo + sample_word ;
468
468
469
469
if (MP_LIKELY (self -> bits_per_sample == 16 )) {
470
- word_buffer [i ] = (sample_word * (1.0 - mix )) + (word * mix );
470
+ word_buffer [i ] = (int16_t )(( sample_word * (1.0 - mix )) + (word * mix ) );
471
471
if (!self -> samples_signed ) {
472
472
word_buffer [i ] ^= 0x8000 ;
473
473
}
474
474
} else {
475
- int8_t mixed = (sample_word * (1.0 - mix )) + (word * mix );
475
+ int8_t mixed = (int16_t )(( sample_word * (1.0 - mix )) + (word * mix ) );
476
476
if (self -> samples_signed ) {
477
477
hword_buffer [i ] = mixed ;
478
478
} else {
0 commit comments