From 68afc156e47f0abfe45eee26d4aece847dce2e84 Mon Sep 17 00:00:00 2001 From: dcooperdalrymple Date: Fri, 24 Jan 2025 16:34:08 -0600 Subject: [PATCH 1/5] Change mix calculation on `audiodelays.Echo` to allow full range. --- shared-module/audiodelays/Echo.c | 11 ++++++----- 1 file changed, 6 insertions(+), 5 deletions(-) diff --git a/shared-module/audiodelays/Echo.c b/shared-module/audiodelays/Echo.c index c1a21d8981171..1ee701898c827 100644 --- a/shared-module/audiodelays/Echo.c +++ b/shared-module/audiodelays/Echo.c @@ -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 = (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 { From e3e90de59995745e2a8770faee28ac88dfae0007 Mon Sep 17 00:00:00 2001 From: dcooperdalrymple Date: Sun, 26 Jan 2025 09:27:26 -0600 Subject: [PATCH 2/5] Update default mix. --- shared-bindings/audiodelays/Echo.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/shared-bindings/audiodelays/Echo.c b/shared-bindings/audiodelays/Echo.c index 32a7061745a82..70895a5ae7a1b 100644 --- a/shared-bindings/audiodelays/Echo.c +++ b/shared-bindings/audiodelays/Echo.c @@ -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""" @@ -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, From fd8567b7a5bfbd1fdd183511b84c7eb40c73f3c5 Mon Sep 17 00:00:00 2001 From: dcooperdalrymple Date: Mon, 27 Jan 2025 14:33:05 -0600 Subject: [PATCH 3/5] Fix explicit cast. --- shared-module/audiodelays/Echo.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/shared-module/audiodelays/Echo.c b/shared-module/audiodelays/Echo.c index 1ee701898c827..c85b0e1f10704 100644 --- a/shared-module/audiodelays/Echo.c +++ b/shared-module/audiodelays/Echo.c @@ -452,8 +452,8 @@ audioio_get_buffer_result_t audiodelays_echo_get_buffer(audiodelays_echo_obj_t * } } - word = (sample_word * MIN(MICROPY_FLOAT_CONST(2.0) - mix, MICROPY_FLOAT_CONST(1.0))) - + (echo * MIN(mix, MICROPY_FLOAT_CONST(1.0))); + 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)) { From 7ffb2d3a2ccef7901a003e89f698c09a0f55fefd Mon Sep 17 00:00:00 2001 From: Cooper Dalrymple Date: Wed, 29 Jan 2025 19:10:07 -0600 Subject: [PATCH 4/5] Remove unnecessary defines and update echo mix default. --- shared-bindings/audiodelays/Echo.c | 3 --- shared-bindings/audiofilters/Filter.c | 2 -- shared-module/audiodelays/Echo.c | 2 +- 3 files changed, 1 insertion(+), 6 deletions(-) diff --git a/shared-bindings/audiodelays/Echo.c b/shared-bindings/audiodelays/Echo.c index 70895a5ae7a1b..970cc6e145d04 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.25f - //| class Echo: //| """An Echo effect""" //| 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 c85b0e1f10704..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); From 8d5219fbfbc9106d04422c8bf3c47569766f3580 Mon Sep 17 00:00:00 2001 From: Cooper Dalrymple Date: Wed, 29 Jan 2025 19:14:30 -0600 Subject: [PATCH 5/5] Update echo mix and decay docstrings. --- shared-bindings/audiodelays/Echo.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/shared-bindings/audiodelays/Echo.c b/shared-bindings/audiodelays/Echo.c index 970cc6e145d04..87cd9b3d9ff96 100644 --- a/shared-bindings/audiodelays/Echo.c +++ b/shared-bindings/audiodelays/Echo.c @@ -162,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); } @@ -180,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); }