diff --git a/shared-bindings/audiodelays/Echo.c b/shared-bindings/audiodelays/Echo.c index 32a7061745a82..87cd9b3d9ff96 100644 --- a/shared-bindings/audiodelays/Echo.c +++ b/shared-bindings/audiodelays/Echo.c @@ -16,9 +16,6 @@ #include "shared-bindings/util.h" #include "shared-module/synthio/block.h" -#define DECAY_DEFAULT 0.7f -#define MIX_DEFAULT 0.5f - //| class Echo: //| """An Echo effect""" //| @@ -27,7 +24,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, @@ -165,7 +162,7 @@ MP_PROPERTY_GETSET(audiodelays_echo_delay_ms_obj, (mp_obj_t)&audiodelays_echo_set_delay_ms_obj); //| decay: synthio.BlockInput -//| """The rate the echo decays between 0 and 1 where 1 is forever and 0 is no echo.""" +//| """The rate the echo fades between 0 and 1 where 0 is instant and 1 is never.""" static mp_obj_t audiodelays_echo_obj_get_decay(mp_obj_t self_in) { return common_hal_audiodelays_echo_get_decay(self_in); } @@ -183,7 +180,7 @@ MP_PROPERTY_GETSET(audiodelays_echo_decay_obj, (mp_obj_t)&audiodelays_echo_set_decay_obj); //| mix: synthio.BlockInput -//| """The rate the echo mix between 0 and 1 where 0 is only sample and 1 is all effect.""" +//| """The rate the echo mix between 0 and 1 where 0 is only sample, 0.5 is an equal mix of the sample and the effect and 1 is all effect.""" static mp_obj_t audiodelays_echo_obj_get_mix(mp_obj_t self_in) { return common_hal_audiodelays_echo_get_mix(self_in); } diff --git a/shared-bindings/audiofilters/Filter.c b/shared-bindings/audiofilters/Filter.c index 07a5739dcb273..4e66b1c3757be 100644 --- a/shared-bindings/audiofilters/Filter.c +++ b/shared-bindings/audiofilters/Filter.c @@ -16,8 +16,6 @@ #include "shared-bindings/util.h" #include "shared-module/synthio/block.h" -#define MIX_DEFAULT 1.0f - //| class Filter: //| """A Filter effect""" //| diff --git a/shared-module/audiodelays/Echo.c b/shared-module/audiodelays/Echo.c index c1a21d8981171..4ce97079267a4 100644 --- a/shared-module/audiodelays/Echo.c +++ b/shared-module/audiodelays/Echo.c @@ -68,7 +68,7 @@ void common_hal_audiodelays_echo_construct(audiodelays_echo_obj_t *self, uint32_ synthio_block_assign_slot(delay_ms, &self->delay_ms, MP_QSTR_delay_ms); if (mix == MP_OBJ_NULL) { - mix = mp_obj_new_float(MICROPY_FLOAT_CONST(0.5)); + mix = mp_obj_new_float(MICROPY_FLOAT_CONST(0.25)); } synthio_block_assign_slot(mix, &self->mix, MP_QSTR_mix); @@ -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); @@ -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; @@ -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 {