@@ -258,32 +258,6 @@ void common_hal_audiodelays_echo_stop(audiodelays_echo_obj_t *self) {
258258 return ;
259259}
260260
261- #define RANGE_LOW_16 (-28000)
262- #define RANGE_HIGH_16 (28000)
263- #define RANGE_SHIFT_16 (16)
264- #define RANGE_SCALE_16 (0xfffffff / (32768 * 2 - RANGE_HIGH_16)) // 2 for echo+sample
265-
266- // dynamic range compression via a downward compressor with hard knee
267- //
268- // When the output value is within the range +-28000 (about 85% of full scale),
269- // it is unchanged. Otherwise, it undergoes a gain reduction so that the
270- // largest possible values, (+32768,-32767) * 2 (2 for echo and sample),
271- // still fit within the output range
272- //
273- // This produces a much louder overall volume with multiple voices, without
274- // much additional processing.
275- //
276- // https://en.wikipedia.org/wiki/Dynamic_range_compression
277- static
278- int16_t mix_down_sample (int32_t sample ) {
279- if (sample < RANGE_LOW_16 ) {
280- sample = (((sample - RANGE_LOW_16 ) * RANGE_SCALE_16 ) >> RANGE_SHIFT_16 ) + RANGE_LOW_16 ;
281- } else if (sample > RANGE_HIGH_16 ) {
282- sample = (((sample - RANGE_HIGH_16 ) * RANGE_SCALE_16 ) >> RANGE_SHIFT_16 ) + RANGE_HIGH_16 ;
283- }
284- return sample ;
285- }
286-
287261audioio_get_buffer_result_t audiodelays_echo_get_buffer (audiodelays_echo_obj_t * self , bool single_channel_output , uint8_t channel ,
288262 uint8_t * * buffer , uint32_t * buffer_length ) {
289263
@@ -454,7 +428,7 @@ audioio_get_buffer_result_t audiodelays_echo_get_buffer(audiodelays_echo_obj_t *
454428 }
455429
456430 if (MP_LIKELY (self -> bits_per_sample == 16 )) {
457- word = mix_down_sample (word );
431+ word = synthio_mix_down_sample (word );
458432 if (self -> freq_shift ) {
459433 for (uint32_t j = echo_buffer_pos >> 8 ; j < next_buffer_pos >> 8 ; j ++ ) {
460434 echo_buffer [j % echo_buf_len ] = (int16_t )word ;
@@ -479,7 +453,7 @@ audioio_get_buffer_result_t audiodelays_echo_get_buffer(audiodelays_echo_obj_t *
479453 }
480454
481455 word = echo + sample_word ;
482- word = mix_down_sample (word );
456+ word = synthio_mix_down_sample (word );
483457
484458 if (MP_LIKELY (self -> bits_per_sample == 16 )) {
485459 word_buffer [i ] = (int16_t )((sample_word * (MICROPY_FLOAT_CONST (1.0 ) - mix )) + (word * mix ));
0 commit comments