Skip to content
Merged
Show file tree
Hide file tree
Changes from 5 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
9 changes: 3 additions & 6 deletions shared-bindings/audiodelays/Echo.c
Original file line number Diff line number Diff line change
Expand Up @@ -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"""
//|
Expand All @@ -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,
Expand Down Expand Up @@ -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);
}
Expand All @@ -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);
}
Expand Down
2 changes: 0 additions & 2 deletions shared-bindings/audiofilters/Filter.c
Original file line number Diff line number Diff line change
Expand Up @@ -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"""
//|
Expand Down
13 changes: 7 additions & 6 deletions shared-module/audiodelays/Echo.c
Original file line number Diff line number Diff line change
Expand Up @@ -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);

Expand Down 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