Skip to content
Merged
Show file tree
Hide file tree
Changes from 3 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions shared-bindings/audiodelays/Echo.c
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@
#include "shared-module/synthio/block.h"

#define DECAY_DEFAULT 0.7f
#define MIX_DEFAULT 0.5f
#define MIX_DEFAULT 0.25f

//| class Echo:
//| """An Echo effect"""
Expand All @@ -27,7 +27,7 @@
//| max_delay_ms: int = 500,
//| delay_ms: synthio.BlockInput = 250.0,
//| decay: synthio.BlockInput = 0.7,
//| mix: synthio.BlockInput = 0.5,
//| mix: synthio.BlockInput = 0.25,
//| buffer_size: int = 512,
//| sample_rate: int = 8000,
//| bits_per_sample: int = 16,
Expand Down
11 changes: 6 additions & 5 deletions shared-module/audiodelays/Echo.c
Original file line number Diff line number Diff line change
Expand Up @@ -306,7 +306,7 @@ audioio_get_buffer_result_t audiodelays_echo_get_buffer(audiodelays_echo_obj_t *

// get the effect values we need from the BlockInput. These may change at run time so you need to do bounds checking if required
shared_bindings_synthio_lfo_tick(self->sample_rate, n / self->channel_count);
mp_float_t mix = synthio_block_slot_get_limited(&self->mix, MICROPY_FLOAT_CONST(0.0), MICROPY_FLOAT_CONST(1.0));
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);
mp_float_t decay = synthio_block_slot_get_limited(&self->decay, MICROPY_FLOAT_CONST(0.0), MICROPY_FLOAT_CONST(1.0));

mp_float_t f_delay_ms = synthio_block_slot_get(&self->delay_ms);
Expand Down Expand Up @@ -361,7 +361,7 @@ audioio_get_buffer_result_t audiodelays_echo_get_buffer(audiodelays_echo_obj_t *
echo_buffer[self->echo_buffer_write_pos++] = word;
}

word = (int16_t)(echo * mix);
word = (int16_t)(echo * MIN(mix, MICROPY_FLOAT_CONST(1.0)));

if (MP_LIKELY(self->bits_per_sample == 16)) {
word_buffer[i] = word;
Expand Down Expand Up @@ -452,16 +452,17 @@ audioio_get_buffer_result_t audiodelays_echo_get_buffer(audiodelays_echo_obj_t *
}
}

word = echo + sample_word;
word = (int32_t)((sample_word * MIN(MICROPY_FLOAT_CONST(2.0) - mix, MICROPY_FLOAT_CONST(1.0)))
+ (echo * MIN(mix, MICROPY_FLOAT_CONST(1.0))));
word = synthio_mix_down_sample(word, SYNTHIO_MIX_DOWN_SCALE(2));

if (MP_LIKELY(self->bits_per_sample == 16)) {
word_buffer[i] = (int16_t)((sample_word * (MICROPY_FLOAT_CONST(1.0) - mix)) + (word * mix));
word_buffer[i] = (int16_t)word;
if (!self->samples_signed) {
word_buffer[i] ^= 0x8000;
}
} else {
int8_t mixed = (int16_t)((sample_word * (MICROPY_FLOAT_CONST(1.0) - mix)) + (word * mix));
int8_t mixed = (int16_t)word;
if (self->samples_signed) {
hword_buffer[i] = mixed;
} else {
Expand Down