Skip to content

Commit 68afc15

Browse files
committed
Change mix calculation on audiodelays.Echo to allow full range.
1 parent e03798b commit 68afc15

File tree

1 file changed

+6
-5
lines changed
  • shared-module/audiodelays

1 file changed

+6
-5
lines changed

shared-module/audiodelays/Echo.c

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -306,7 +306,7 @@ audioio_get_buffer_result_t audiodelays_echo_get_buffer(audiodelays_echo_obj_t *
306306

307307
// get the effect values we need from the BlockInput. These may change at run time so you need to do bounds checking if required
308308
shared_bindings_synthio_lfo_tick(self->sample_rate, n / self->channel_count);
309-
mp_float_t mix = synthio_block_slot_get_limited(&self->mix, MICROPY_FLOAT_CONST(0.0), MICROPY_FLOAT_CONST(1.0));
309+
mp_float_t mix = synthio_block_slot_get_limited(&self->mix, MICROPY_FLOAT_CONST(0.0), MICROPY_FLOAT_CONST(1.0)) * MICROPY_FLOAT_CONST(2.0);
310310
mp_float_t decay = synthio_block_slot_get_limited(&self->decay, MICROPY_FLOAT_CONST(0.0), MICROPY_FLOAT_CONST(1.0));
311311

312312
mp_float_t f_delay_ms = synthio_block_slot_get(&self->delay_ms);
@@ -361,7 +361,7 @@ audioio_get_buffer_result_t audiodelays_echo_get_buffer(audiodelays_echo_obj_t *
361361
echo_buffer[self->echo_buffer_write_pos++] = word;
362362
}
363363

364-
word = (int16_t)(echo * mix);
364+
word = (int16_t)(echo * MIN(mix, MICROPY_FLOAT_CONST(1.0)));
365365

366366
if (MP_LIKELY(self->bits_per_sample == 16)) {
367367
word_buffer[i] = word;
@@ -452,16 +452,17 @@ audioio_get_buffer_result_t audiodelays_echo_get_buffer(audiodelays_echo_obj_t *
452452
}
453453
}
454454

455-
word = echo + sample_word;
455+
word = (sample_word * MIN(MICROPY_FLOAT_CONST(2.0) - mix, MICROPY_FLOAT_CONST(1.0)))
456+
+ (echo * MIN(mix, MICROPY_FLOAT_CONST(1.0)));
456457
word = synthio_mix_down_sample(word, SYNTHIO_MIX_DOWN_SCALE(2));
457458

458459
if (MP_LIKELY(self->bits_per_sample == 16)) {
459-
word_buffer[i] = (int16_t)((sample_word * (MICROPY_FLOAT_CONST(1.0) - mix)) + (word * mix));
460+
word_buffer[i] = (int16_t)word;
460461
if (!self->samples_signed) {
461462
word_buffer[i] ^= 0x8000;
462463
}
463464
} else {
464-
int8_t mixed = (int16_t)((sample_word * (MICROPY_FLOAT_CONST(1.0) - mix)) + (word * mix));
465+
int8_t mixed = (int16_t)word;
465466
if (self->samples_signed) {
466467
hword_buffer[i] = mixed;
467468
} else {

0 commit comments

Comments
 (0)