From aa7d619d55294a7fe0703820b5d56d278c2a0192 Mon Sep 17 00:00:00 2001 From: dcooperdalrymple Date: Sun, 3 Nov 2024 19:57:02 -0600 Subject: [PATCH 1/7] Fix `ring_waveform_loop_start` typo in frequency calculation. --- shared-module/synthio/__init__.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/shared-module/synthio/__init__.c b/shared-module/synthio/__init__.c index 630c3de86988c..f2c05cd5f74aa 100644 --- a/shared-module/synthio/__init__.c +++ b/shared-module/synthio/__init__.c @@ -196,7 +196,7 @@ static bool synth_note_into_buffer(synthio_synth_t *synth, int chan, int32_t *ou ring_waveform = note->ring_waveform_buf.buf; ring_waveform_length = note->ring_waveform_buf.len; if (note->ring_waveform_loop_start > 0 && note->ring_waveform_loop_start < ring_waveform_length) { - ring_waveform_start = note->waveform_loop_start; + ring_waveform_start = note->ring_waveform_loop_start; } if (note->ring_waveform_loop_end > ring_waveform_start && note->ring_waveform_loop_end < ring_waveform_length) { ring_waveform_length = note->ring_waveform_loop_end; From ce12d90160f01c9be36ecd2facff40efd8404f96 Mon Sep 17 00:00:00 2001 From: dcooperdalrymple Date: Sun, 3 Nov 2024 20:00:35 -0600 Subject: [PATCH 2/7] Fix default value of `synthio.Note.amplitude` in documentation. --- shared-bindings/synthio/Note.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/shared-bindings/synthio/Note.c b/shared-bindings/synthio/Note.c index c886f106a4cfd..f7f6f54986e76 100644 --- a/shared-bindings/synthio/Note.c +++ b/shared-bindings/synthio/Note.c @@ -40,7 +40,7 @@ static const mp_arg_t note_properties[] = { //| waveform_loop_start: int = 0, //| waveform_loop_end: int = waveform_max_length, //| envelope: Optional[Envelope] = None, -//| amplitude: BlockInput = 0.0, +//| amplitude: BlockInput = 1.0, //| bend: BlockInput = 0.0, //| filter: Optional[Biquad] = None, //| ring_frequency: float = 0.0, From e2a52afa9323853766cf556ef7ae0bc323e22054 Mon Sep 17 00:00:00 2001 From: dcooperdalrymple Date: Sun, 3 Nov 2024 20:30:06 -0600 Subject: [PATCH 3/7] Add support for `synthio.BlockInput` on `synthio.Note.waveform_loop_start`, `synthio.Note.waveform_loop_end`, `synthio.Note.ring_waveform_loop_start`, and `synthio.Note.ring_waveform_loop_end`. --- shared-bindings/synthio/Note.c | 42 +++++++++++++++++--------------- shared-bindings/synthio/Note.h | 16 ++++++------ shared-module/synthio/Note.c | 36 ++++++++++++--------------- shared-module/synthio/Note.h | 4 +-- shared-module/synthio/__init__.c | 16 +++--------- 5 files changed, 52 insertions(+), 62 deletions(-) diff --git a/shared-bindings/synthio/Note.c b/shared-bindings/synthio/Note.c index f7f6f54986e76..60ebbff3a2ae9 100644 --- a/shared-bindings/synthio/Note.c +++ b/shared-bindings/synthio/Note.c @@ -20,15 +20,15 @@ static const mp_arg_t note_properties[] = { { MP_QSTR_amplitude, MP_ARG_OBJ | MP_ARG_KW_ONLY, {.u_obj = MP_ROM_INT(1) } }, { MP_QSTR_bend, MP_ARG_OBJ | MP_ARG_KW_ONLY, {.u_obj = MP_ROM_INT(0) } }, { MP_QSTR_waveform, MP_ARG_OBJ | MP_ARG_KW_ONLY, {.u_obj = MP_ROM_NONE } }, - { MP_QSTR_waveform_loop_start, MP_ARG_OBJ, {.u_obj = MP_ROM_INT(0) } }, - { MP_QSTR_waveform_loop_end, MP_ARG_OBJ, {.u_obj = MP_ROM_INT(SYNTHIO_WAVEFORM_SIZE) } }, + { MP_QSTR_waveform_loop_start, MP_ARG_OBJ | MP_ARG_KW_ONLY, {.u_obj = MP_ROM_INT(0) } }, + { MP_QSTR_waveform_loop_end, MP_ARG_OBJ | MP_ARG_KW_ONLY, {.u_obj = MP_ROM_INT(SYNTHIO_WAVEFORM_SIZE) } }, { MP_QSTR_envelope, MP_ARG_OBJ | MP_ARG_KW_ONLY, {.u_obj = MP_ROM_NONE } }, { MP_QSTR_filter, MP_ARG_OBJ | MP_ARG_KW_ONLY, {.u_obj = MP_ROM_NONE } }, { MP_QSTR_ring_frequency, MP_ARG_OBJ, {.u_obj = MP_ROM_INT(0) } }, { MP_QSTR_ring_bend, MP_ARG_OBJ, {.u_obj = MP_ROM_INT(0) } }, { MP_QSTR_ring_waveform, MP_ARG_OBJ | MP_ARG_KW_ONLY, {.u_obj = MP_ROM_NONE } }, - { MP_QSTR_ring_waveform_loop_start, MP_ARG_OBJ, {.u_obj = MP_ROM_INT(0) } }, - { MP_QSTR_ring_waveform_loop_end, MP_ARG_OBJ, {.u_obj = MP_ROM_INT(SYNTHIO_WAVEFORM_SIZE) } }, + { MP_QSTR_ring_waveform_loop_start, MP_ARG_OBJ | MP_ARG_KW_ONLY, {.u_obj = MP_ROM_INT(0) } }, + { MP_QSTR_ring_waveform_loop_end, MP_ARG_OBJ | MP_ARG_KW_ONLY, {.u_obj = MP_ROM_INT(SYNTHIO_WAVEFORM_SIZE) } }, }; //| class Note: //| def __init__( @@ -37,8 +37,8 @@ static const mp_arg_t note_properties[] = { //| frequency: float, //| panning: BlockInput = 0.0, //| waveform: Optional[ReadableBuffer] = None, -//| waveform_loop_start: int = 0, -//| waveform_loop_end: int = waveform_max_length, +//| waveform_loop_start: BlockInput = 0, +//| waveform_loop_end: BlockInput = waveform_max_length, //| envelope: Optional[Envelope] = None, //| amplitude: BlockInput = 1.0, //| bend: BlockInput = 0.0, @@ -46,8 +46,8 @@ static const mp_arg_t note_properties[] = { //| ring_frequency: float = 0.0, //| ring_bend: float = 0.0, //| ring_waveform: Optional[ReadableBuffer] = None, -//| ring_waveform_loop_start: int = 0, -//| ring_waveform_loop_end: int = waveform_max_length, +//| ring_waveform_loop_start: BlockInput = 0, +//| ring_waveform_loop_end: BlockInput = waveform_max_length, //| ) -> None: //| """Construct a Note object, with a frequency in Hz, and optional panning, waveform, envelope, tremolo (volume change) and bend (frequency change). //| @@ -198,7 +198,9 @@ MP_PROPERTY_GETSET(synthio_note_waveform_obj, (mp_obj_t)&synthio_note_get_waveform_obj, (mp_obj_t)&synthio_note_set_waveform_obj); -//| waveform_loop_start: int + + +//| waveform_loop_start: BlockInput //| """The sample index of where to begin looping waveform data. //| //| Values outside the range ``0`` to ``waveform_max_length-1`` (inclusive) are rejected with a `ValueError`. @@ -206,13 +208,13 @@ MP_PROPERTY_GETSET(synthio_note_waveform_obj, //| Values greater than or equal to the actual waveform length are treated as 0.""" static mp_obj_t synthio_note_get_waveform_loop_start(mp_obj_t self_in) { synthio_note_obj_t *self = MP_OBJ_TO_PTR(self_in); - return mp_obj_new_int(common_hal_synthio_note_get_waveform_loop_start(self)); + return common_hal_synthio_note_get_waveform_loop_start(self); } MP_DEFINE_CONST_FUN_OBJ_1(synthio_note_get_waveform_loop_start_obj, synthio_note_get_waveform_loop_start); static mp_obj_t synthio_note_set_waveform_loop_start(mp_obj_t self_in, mp_obj_t arg) { synthio_note_obj_t *self = MP_OBJ_TO_PTR(self_in); - common_hal_synthio_note_set_waveform_loop_start(self, mp_obj_get_int(arg)); + common_hal_synthio_note_set_waveform_loop_start(self, arg); return mp_const_none; } MP_DEFINE_CONST_FUN_OBJ_2(synthio_note_set_waveform_loop_start_obj, synthio_note_set_waveform_loop_start); @@ -220,7 +222,7 @@ MP_PROPERTY_GETSET(synthio_note_waveform_loop_start_obj, (mp_obj_t)&synthio_note_get_waveform_loop_start_obj, (mp_obj_t)&synthio_note_set_waveform_loop_start_obj); -//| waveform_loop_end: int +//| waveform_loop_end: BlockInput //| """The sample index of where to end looping waveform data. //| //| Values outside the range ``1`` to ``waveform_max_length`` (inclusive) are rejected with a `ValueError`. @@ -231,13 +233,13 @@ MP_PROPERTY_GETSET(synthio_note_waveform_loop_start_obj, //| static mp_obj_t synthio_note_get_waveform_loop_end(mp_obj_t self_in) { synthio_note_obj_t *self = MP_OBJ_TO_PTR(self_in); - return mp_obj_new_int(common_hal_synthio_note_get_waveform_loop_end(self)); + return common_hal_synthio_note_get_waveform_loop_end(self); } MP_DEFINE_CONST_FUN_OBJ_1(synthio_note_get_waveform_loop_end_obj, synthio_note_get_waveform_loop_end); static mp_obj_t synthio_note_set_waveform_loop_end(mp_obj_t self_in, mp_obj_t arg) { synthio_note_obj_t *self = MP_OBJ_TO_PTR(self_in); - common_hal_synthio_note_set_waveform_loop_end(self, mp_obj_get_int(arg)); + common_hal_synthio_note_set_waveform_loop_end(self, arg); return mp_const_none; } MP_DEFINE_CONST_FUN_OBJ_2(synthio_note_set_waveform_loop_end_obj, synthio_note_set_waveform_loop_end); @@ -331,7 +333,7 @@ MP_PROPERTY_GETSET(synthio_note_ring_waveform_obj, (mp_obj_t)&synthio_note_get_ring_waveform_obj, (mp_obj_t)&synthio_note_set_ring_waveform_obj); -//| ring_waveform_loop_start: int +//| ring_waveform_loop_start: BlockInput //| """The sample index of where to begin looping waveform data. //| //| Values outside the range ``0`` to ``waveform_max_length-1`` (inclusive) are rejected with a `ValueError`. @@ -339,13 +341,13 @@ MP_PROPERTY_GETSET(synthio_note_ring_waveform_obj, //| Values greater than or equal to the actual waveform length are treated as 0.""" static mp_obj_t synthio_note_get_ring_waveform_loop_start(mp_obj_t self_in) { synthio_note_obj_t *self = MP_OBJ_TO_PTR(self_in); - return mp_obj_new_int(common_hal_synthio_note_get_ring_waveform_loop_start(self)); + return common_hal_synthio_note_get_ring_waveform_loop_start(self); } MP_DEFINE_CONST_FUN_OBJ_1(synthio_note_get_ring_waveform_loop_start_obj, synthio_note_get_ring_waveform_loop_start); static mp_obj_t synthio_note_set_ring_waveform_loop_start(mp_obj_t self_in, mp_obj_t arg) { synthio_note_obj_t *self = MP_OBJ_TO_PTR(self_in); - common_hal_synthio_note_set_ring_waveform_loop_start(self, mp_obj_get_int(arg)); + common_hal_synthio_note_set_ring_waveform_loop_start(self, arg); return mp_const_none; } MP_DEFINE_CONST_FUN_OBJ_2(synthio_note_set_ring_waveform_loop_start_obj, synthio_note_set_ring_waveform_loop_start); @@ -353,7 +355,7 @@ MP_PROPERTY_GETSET(synthio_note_ring_waveform_loop_start_obj, (mp_obj_t)&synthio_note_get_ring_waveform_loop_start_obj, (mp_obj_t)&synthio_note_set_ring_waveform_loop_start_obj); -//| ring_waveform_loop_end: int +//| ring_waveform_loop_end: BlockInput //| """The sample index of where to end looping waveform data. //| //| Values outside the range ``1`` to ``waveform_max_length`` (inclusive) are rejected with a `ValueError`. @@ -364,13 +366,13 @@ MP_PROPERTY_GETSET(synthio_note_ring_waveform_loop_start_obj, //| static mp_obj_t synthio_note_get_ring_waveform_loop_end(mp_obj_t self_in) { synthio_note_obj_t *self = MP_OBJ_TO_PTR(self_in); - return mp_obj_new_int(common_hal_synthio_note_get_ring_waveform_loop_end(self)); + return common_hal_synthio_note_get_ring_waveform_loop_end(self); } MP_DEFINE_CONST_FUN_OBJ_1(synthio_note_get_ring_waveform_loop_end_obj, synthio_note_get_ring_waveform_loop_end); static mp_obj_t synthio_note_set_ring_waveform_loop_end(mp_obj_t self_in, mp_obj_t arg) { synthio_note_obj_t *self = MP_OBJ_TO_PTR(self_in); - common_hal_synthio_note_set_ring_waveform_loop_end(self, mp_obj_get_int(arg)); + common_hal_synthio_note_set_ring_waveform_loop_end(self, arg); return mp_const_none; } MP_DEFINE_CONST_FUN_OBJ_2(synthio_note_set_ring_waveform_loop_end_obj, synthio_note_set_ring_waveform_loop_end); diff --git a/shared-bindings/synthio/Note.h b/shared-bindings/synthio/Note.h index 0ee450acfe467..707b9f2e10463 100644 --- a/shared-bindings/synthio/Note.h +++ b/shared-bindings/synthio/Note.h @@ -31,11 +31,11 @@ void common_hal_synthio_note_set_bend(synthio_note_obj_t *self, mp_obj_t value); mp_obj_t common_hal_synthio_note_get_waveform_obj(synthio_note_obj_t *self); void common_hal_synthio_note_set_waveform(synthio_note_obj_t *self, mp_obj_t value); -mp_int_t common_hal_synthio_note_get_waveform_loop_start(synthio_note_obj_t *self); -void common_hal_synthio_note_set_waveform_loop_start(synthio_note_obj_t *self, mp_int_t value_in); +mp_obj_t common_hal_synthio_note_get_waveform_loop_start(synthio_note_obj_t *self); +void common_hal_synthio_note_set_waveform_loop_start(synthio_note_obj_t *self, mp_obj_t value); -mp_int_t common_hal_synthio_note_get_waveform_loop_end(synthio_note_obj_t *self); -void common_hal_synthio_note_set_waveform_loop_end(synthio_note_obj_t *self, mp_int_t value_in); +mp_obj_t common_hal_synthio_note_get_waveform_loop_end(synthio_note_obj_t *self); +void common_hal_synthio_note_set_waveform_loop_end(synthio_note_obj_t *self, mp_obj_t value); mp_float_t common_hal_synthio_note_get_ring_frequency(synthio_note_obj_t *self); void common_hal_synthio_note_set_ring_frequency(synthio_note_obj_t *self, mp_float_t value); @@ -46,11 +46,11 @@ void common_hal_synthio_note_set_ring_bend(synthio_note_obj_t *self, mp_obj_t va mp_obj_t common_hal_synthio_note_get_ring_waveform_obj(synthio_note_obj_t *self); void common_hal_synthio_note_set_ring_waveform(synthio_note_obj_t *self, mp_obj_t value); -mp_int_t common_hal_synthio_note_get_ring_waveform_loop_start(synthio_note_obj_t *self); -void common_hal_synthio_note_set_ring_waveform_loop_start(synthio_note_obj_t *self, mp_int_t value_in); +mp_obj_t common_hal_synthio_note_get_ring_waveform_loop_start(synthio_note_obj_t *self); +void common_hal_synthio_note_set_ring_waveform_loop_start(synthio_note_obj_t *self, mp_obj_t value); -mp_int_t common_hal_synthio_note_get_ring_waveform_loop_end(synthio_note_obj_t *self); -void common_hal_synthio_note_set_ring_waveform_loop_end(synthio_note_obj_t *self, mp_int_t value_in); +mp_obj_t common_hal_synthio_note_get_ring_waveform_loop_end(synthio_note_obj_t *self); +void common_hal_synthio_note_set_ring_waveform_loop_end(synthio_note_obj_t *self, mp_obj_t value); mp_obj_t common_hal_synthio_note_get_envelope_obj(synthio_note_obj_t *self); void common_hal_synthio_note_set_envelope(synthio_note_obj_t *self, mp_obj_t value); diff --git a/shared-module/synthio/Note.c b/shared-module/synthio/Note.c index 49dfbb7f429d3..0e612914ec700 100644 --- a/shared-module/synthio/Note.c +++ b/shared-module/synthio/Note.c @@ -100,22 +100,20 @@ void common_hal_synthio_note_set_waveform(synthio_note_obj_t *self, mp_obj_t wav self->waveform_obj = waveform_in; } -mp_int_t common_hal_synthio_note_get_waveform_loop_start(synthio_note_obj_t *self) { - return self->waveform_loop_start; +mp_obj_t common_hal_synthio_note_get_waveform_loop_start(synthio_note_obj_t *self) { + return self->waveform_loop_start.obj; } -void common_hal_synthio_note_set_waveform_loop_start(synthio_note_obj_t *self, mp_int_t value_in) { - mp_int_t val = mp_arg_validate_int_range(value_in, 0, SYNTHIO_WAVEFORM_SIZE - 1, MP_QSTR_waveform_loop_start); - self->waveform_loop_start = val; +void common_hal_synthio_note_set_waveform_loop_start(synthio_note_obj_t *self, mp_obj_t value_in) { + synthio_block_assign_slot(value_in, &self->waveform_loop_start, MP_QSTR_waveform_loop_start); } -mp_int_t common_hal_synthio_note_get_waveform_loop_end(synthio_note_obj_t *self) { - return self->waveform_loop_end; +mp_obj_t common_hal_synthio_note_get_waveform_loop_end(synthio_note_obj_t *self) { + return self->waveform_loop_end.obj; } -void common_hal_synthio_note_set_waveform_loop_end(synthio_note_obj_t *self, mp_int_t value_in) { - mp_int_t val = mp_arg_validate_int_range(value_in, 1, SYNTHIO_WAVEFORM_SIZE, MP_QSTR_waveform_loop_end); - self->waveform_loop_end = val; +void common_hal_synthio_note_set_waveform_loop_end(synthio_note_obj_t *self, mp_obj_t value_in) { + synthio_block_assign_slot(value_in, &self->waveform_loop_end, MP_QSTR_waveform_loop_end); } mp_obj_t common_hal_synthio_note_get_ring_waveform_obj(synthio_note_obj_t *self) { @@ -133,22 +131,20 @@ void common_hal_synthio_note_set_ring_waveform(synthio_note_obj_t *self, mp_obj_ self->ring_waveform_obj = ring_waveform_in; } -mp_int_t common_hal_synthio_note_get_ring_waveform_loop_start(synthio_note_obj_t *self) { - return self->ring_waveform_loop_start; +mp_obj_t common_hal_synthio_note_get_ring_waveform_loop_start(synthio_note_obj_t *self) { + return self->ring_waveform_loop_start.obj; } -void common_hal_synthio_note_set_ring_waveform_loop_start(synthio_note_obj_t *self, mp_int_t value_in) { - mp_int_t val = mp_arg_validate_int_range(value_in, 0, SYNTHIO_WAVEFORM_SIZE - 1, MP_QSTR_ring_waveform_loop_start); - self->ring_waveform_loop_start = val; +void common_hal_synthio_note_set_ring_waveform_loop_start(synthio_note_obj_t *self, mp_obj_t value_in) { + synthio_block_assign_slot(value_in, &self->ring_waveform_loop_start, MP_QSTR_ring_waveform_loop_start); } -mp_int_t common_hal_synthio_note_get_ring_waveform_loop_end(synthio_note_obj_t *self) { - return self->ring_waveform_loop_end; +mp_obj_t common_hal_synthio_note_get_ring_waveform_loop_end(synthio_note_obj_t *self) { + return self->ring_waveform_loop_end.obj; } -void common_hal_synthio_note_set_ring_waveform_loop_end(synthio_note_obj_t *self, mp_int_t value_in) { - mp_int_t val = mp_arg_validate_int_range(value_in, 1, SYNTHIO_WAVEFORM_SIZE, MP_QSTR_ring_waveform_loop_end); - self->ring_waveform_loop_end = val; +void common_hal_synthio_note_set_ring_waveform_loop_end(synthio_note_obj_t *self, mp_obj_t value_in) { + synthio_block_assign_slot(value_in, &self->ring_waveform_loop_end, MP_QSTR_ring_waveform_loop_end); } void synthio_note_recalculate(synthio_note_obj_t *self, int32_t sample_rate) { diff --git a/shared-module/synthio/Note.h b/shared-module/synthio/Note.h index dc4e5557fd3c9..9d9deb42ac8f3 100644 --- a/shared-module/synthio/Note.h +++ b/shared-module/synthio/Note.h @@ -28,9 +28,9 @@ typedef struct synthio_note_obj { int32_t ring_frequency_scaled, ring_frequency_bent; mp_buffer_info_t waveform_buf; - uint32_t waveform_loop_start, waveform_loop_end; + synthio_block_slot_t waveform_loop_start, waveform_loop_end; mp_buffer_info_t ring_waveform_buf; - uint32_t ring_waveform_loop_start, ring_waveform_loop_end; + synthio_block_slot_t ring_waveform_loop_start, ring_waveform_loop_end; synthio_envelope_definition_t envelope_def; } synthio_note_obj_t; diff --git a/shared-module/synthio/__init__.c b/shared-module/synthio/__init__.c index f2c05cd5f74aa..8173da3f0ce35 100644 --- a/shared-module/synthio/__init__.c +++ b/shared-module/synthio/__init__.c @@ -184,23 +184,15 @@ static bool synth_note_into_buffer(synthio_synth_t *synth, int chan, int32_t *ou if (note->waveform_buf.buf) { waveform = note->waveform_buf.buf; waveform_length = note->waveform_buf.len; - if (note->waveform_loop_start > 0 && note->waveform_loop_start < waveform_length) { - waveform_start = note->waveform_loop_start; - } - if (note->waveform_loop_end > waveform_start && note->waveform_loop_end < waveform_length) { - waveform_length = note->waveform_loop_end; - } + waveform_start = synthio_block_slot_get_limited(¬e->waveform_loop_start, 0, waveform_length - 1); + waveform_length = synthio_block_slot_get_limited(¬e->waveform_loop_end, waveform_start + 1, waveform_length); } dds_rate = synthio_frequency_convert_scaled_to_dds((uint64_t)frequency_scaled * (waveform_length - waveform_start), sample_rate); if (note->ring_frequency_scaled != 0 && note->ring_waveform_buf.buf) { ring_waveform = note->ring_waveform_buf.buf; ring_waveform_length = note->ring_waveform_buf.len; - if (note->ring_waveform_loop_start > 0 && note->ring_waveform_loop_start < ring_waveform_length) { - ring_waveform_start = note->ring_waveform_loop_start; - } - if (note->ring_waveform_loop_end > ring_waveform_start && note->ring_waveform_loop_end < ring_waveform_length) { - ring_waveform_length = note->ring_waveform_loop_end; - } + ring_waveform_start = synthio_block_slot_get_limited(¬e->ring_waveform_loop_start, 0, ring_waveform_length - 1); + ring_waveform_length = synthio_block_slot_get_limited(¬e->ring_waveform_loop_end, ring_waveform_start + 1, ring_waveform_length); ring_dds_rate = synthio_frequency_convert_scaled_to_dds((uint64_t)note->ring_frequency_bent * (ring_waveform_length - ring_waveform_start), sample_rate); uint32_t lim = ring_waveform_length << SYNTHIO_FREQUENCY_SHIFT; if (ring_dds_rate > lim / sizeof(int16_t)) { From e7382c2fc444f934b510d37033cdb3f01a74f507 Mon Sep 17 00:00:00 2001 From: dcooperdalrymple Date: Mon, 4 Nov 2024 08:13:17 -0600 Subject: [PATCH 4/7] Make conversion of `mp_float_t` to `uint32_t` for waveform_loop values explicit. --- shared-module/synthio/__init__.c | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/shared-module/synthio/__init__.c b/shared-module/synthio/__init__.c index 8173da3f0ce35..be7e036660a84 100644 --- a/shared-module/synthio/__init__.c +++ b/shared-module/synthio/__init__.c @@ -184,15 +184,15 @@ static bool synth_note_into_buffer(synthio_synth_t *synth, int chan, int32_t *ou if (note->waveform_buf.buf) { waveform = note->waveform_buf.buf; waveform_length = note->waveform_buf.len; - waveform_start = synthio_block_slot_get_limited(¬e->waveform_loop_start, 0, waveform_length - 1); - waveform_length = synthio_block_slot_get_limited(¬e->waveform_loop_end, waveform_start + 1, waveform_length); + waveform_start = (uint32_t)synthio_block_slot_get_limited(¬e->waveform_loop_start, 0, waveform_length - 1); + waveform_length = (uint32_t)synthio_block_slot_get_limited(¬e->waveform_loop_end, waveform_start + 1, waveform_length); } dds_rate = synthio_frequency_convert_scaled_to_dds((uint64_t)frequency_scaled * (waveform_length - waveform_start), sample_rate); if (note->ring_frequency_scaled != 0 && note->ring_waveform_buf.buf) { ring_waveform = note->ring_waveform_buf.buf; ring_waveform_length = note->ring_waveform_buf.len; - ring_waveform_start = synthio_block_slot_get_limited(¬e->ring_waveform_loop_start, 0, ring_waveform_length - 1); - ring_waveform_length = synthio_block_slot_get_limited(¬e->ring_waveform_loop_end, ring_waveform_start + 1, ring_waveform_length); + ring_waveform_start = (uint32_t)synthio_block_slot_get_limited(¬e->ring_waveform_loop_start, 0, ring_waveform_length - 1); + ring_waveform_length = (uint32_t)synthio_block_slot_get_limited(¬e->ring_waveform_loop_end, ring_waveform_start + 1, ring_waveform_length); ring_dds_rate = synthio_frequency_convert_scaled_to_dds((uint64_t)note->ring_frequency_bent * (ring_waveform_length - ring_waveform_start), sample_rate); uint32_t lim = ring_waveform_length << SYNTHIO_FREQUENCY_SHIFT; if (ring_dds_rate > lim / sizeof(int16_t)) { From ce3e83d47448e22bd04da2224c079cd3d57814ac Mon Sep 17 00:00:00 2001 From: Cooper Dalrymple Date: Mon, 4 Nov 2024 11:13:04 -0600 Subject: [PATCH 5/7] Update `ring_frequency` and `ring_bend` with `MP_ARG_KW_ONLY`. --- shared-bindings/synthio/Note.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/shared-bindings/synthio/Note.c b/shared-bindings/synthio/Note.c index 60ebbff3a2ae9..f46bef9f510a2 100644 --- a/shared-bindings/synthio/Note.c +++ b/shared-bindings/synthio/Note.c @@ -24,8 +24,8 @@ static const mp_arg_t note_properties[] = { { MP_QSTR_waveform_loop_end, MP_ARG_OBJ | MP_ARG_KW_ONLY, {.u_obj = MP_ROM_INT(SYNTHIO_WAVEFORM_SIZE) } }, { MP_QSTR_envelope, MP_ARG_OBJ | MP_ARG_KW_ONLY, {.u_obj = MP_ROM_NONE } }, { MP_QSTR_filter, MP_ARG_OBJ | MP_ARG_KW_ONLY, {.u_obj = MP_ROM_NONE } }, - { MP_QSTR_ring_frequency, MP_ARG_OBJ, {.u_obj = MP_ROM_INT(0) } }, - { MP_QSTR_ring_bend, MP_ARG_OBJ, {.u_obj = MP_ROM_INT(0) } }, + { MP_QSTR_ring_frequency, MP_ARG_OBJ | MP_ARG_KW_ONLY, {.u_obj = MP_ROM_INT(0) } }, + { MP_QSTR_ring_bend, MP_ARG_OBJ | MP_ARG_KW_ONLY, {.u_obj = MP_ROM_INT(0) } }, { MP_QSTR_ring_waveform, MP_ARG_OBJ | MP_ARG_KW_ONLY, {.u_obj = MP_ROM_NONE } }, { MP_QSTR_ring_waveform_loop_start, MP_ARG_OBJ | MP_ARG_KW_ONLY, {.u_obj = MP_ROM_INT(0) } }, { MP_QSTR_ring_waveform_loop_end, MP_ARG_OBJ | MP_ARG_KW_ONLY, {.u_obj = MP_ROM_INT(SYNTHIO_WAVEFORM_SIZE) } }, From dfe9836e352e745c561dfbafddf9dcad962fd63e Mon Sep 17 00:00:00 2001 From: Cooper Dalrymple Date: Mon, 4 Nov 2024 11:25:51 -0600 Subject: [PATCH 6/7] Update loop docstrings to demonstrate `BlockInput` implementation. --- shared-bindings/synthio/Note.c | 16 ++++------------ 1 file changed, 4 insertions(+), 12 deletions(-) diff --git a/shared-bindings/synthio/Note.c b/shared-bindings/synthio/Note.c index f46bef9f510a2..9e588edefd1a9 100644 --- a/shared-bindings/synthio/Note.c +++ b/shared-bindings/synthio/Note.c @@ -203,9 +203,7 @@ MP_PROPERTY_GETSET(synthio_note_waveform_obj, //| waveform_loop_start: BlockInput //| """The sample index of where to begin looping waveform data. //| -//| Values outside the range ``0`` to ``waveform_max_length-1`` (inclusive) are rejected with a `ValueError`. -//| -//| Values greater than or equal to the actual waveform length are treated as 0.""" +//| The value is limited to the range ``0`` to ``len(waveform)-1`` (inclusive).""" static mp_obj_t synthio_note_get_waveform_loop_start(mp_obj_t self_in) { synthio_note_obj_t *self = MP_OBJ_TO_PTR(self_in); return common_hal_synthio_note_get_waveform_loop_start(self); @@ -225,9 +223,7 @@ MP_PROPERTY_GETSET(synthio_note_waveform_loop_start_obj, //| waveform_loop_end: BlockInput //| """The sample index of where to end looping waveform data. //| -//| Values outside the range ``1`` to ``waveform_max_length`` (inclusive) are rejected with a `ValueError`. -//| -//| If the value is greater than the actual waveform length, or less than or equal to the loop start, the loop will occur at the end of the waveform. +//| The value is limited to the range ``waveform_loop_start+1`` to ``len(waveform)`` (inclusive). //| //| Use the `synthio.waveform_max_length` constant to set the loop point at the end of the wave form, no matter its length.""" //| @@ -336,9 +332,7 @@ MP_PROPERTY_GETSET(synthio_note_ring_waveform_obj, //| ring_waveform_loop_start: BlockInput //| """The sample index of where to begin looping waveform data. //| -//| Values outside the range ``0`` to ``waveform_max_length-1`` (inclusive) are rejected with a `ValueError`. -//| -//| Values greater than or equal to the actual waveform length are treated as 0.""" +//| The value is limited to the range ``0`` to ``len(ring_waveform)-1`` (inclusive).""" static mp_obj_t synthio_note_get_ring_waveform_loop_start(mp_obj_t self_in) { synthio_note_obj_t *self = MP_OBJ_TO_PTR(self_in); return common_hal_synthio_note_get_ring_waveform_loop_start(self); @@ -358,9 +352,7 @@ MP_PROPERTY_GETSET(synthio_note_ring_waveform_loop_start_obj, //| ring_waveform_loop_end: BlockInput //| """The sample index of where to end looping waveform data. //| -//| Values outside the range ``1`` to ``waveform_max_length`` (inclusive) are rejected with a `ValueError`. -//| -//| If the value is greater than the actual waveform length, or less than or equal to the loop start, the loop will occur at the end of the waveform. +//| The value is limited to the range ``ring_waveform_loop_start+1`` to ``len(ring_waveform)`` (inclusive). //| //| Use the `synthio.waveform_max_length` constant to set the loop point at the end of the wave form, no matter its length.""" //| From fd24006901c06236f1e7771cc9e6aaf772a4bb18 Mon Sep 17 00:00:00 2001 From: dcooperdalrymple Date: Mon, 4 Nov 2024 13:33:16 -0600 Subject: [PATCH 7/7] Updated expected results for synthesizer_note test. --- tests/circuitpython/synthesizer_note.py.exp | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/tests/circuitpython/synthesizer_note.py.exp b/tests/circuitpython/synthesizer_note.py.exp index 43d07e5e7da9c..7417a4c8a19fb 100644 --- a/tests/circuitpython/synthesizer_note.py.exp +++ b/tests/circuitpython/synthesizer_note.py.exp @@ -1,10 +1,10 @@ () [0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0] -(Note(frequency=830.6076004423605, panning=0.0, amplitude=1.0, bend=0.0, waveform=None, waveform_loop_start=0, waveform_loop_end=16384, envelope=None, filter=None, ring_frequency=0.0, ring_bend=0.0, ring_waveform=None, ring_waveform_loop_start=0, ring_waveform_loop_end=16384),) +(Note(frequency=830.6076004423605, panning=0.0, amplitude=1.0, bend=0.0, waveform=None, waveform_loop_start=0.0, waveform_loop_end=16384.0, envelope=None, filter=None, ring_frequency=0.0, ring_bend=0.0, ring_waveform=None, ring_waveform_loop_start=0.0, ring_waveform_loop_end=16384.0),) [-16383, -16383, -16383, -16383, 16382, 16382, 16382, 16382, 16382, -16383, -16383, -16383, -16383, -16383, 16382, 16382, 16382, 16382, 16382, -16383, -16383, -16383, -16383, -16383] -(Note(frequency=830.6076004423605, panning=0.0, amplitude=1.0, bend=0.0, waveform=None, waveform_loop_start=0, waveform_loop_end=16384, envelope=None, filter=None, ring_frequency=0.0, ring_bend=0.0, ring_waveform=None, ring_waveform_loop_start=0, ring_waveform_loop_end=16384), Note(frequency=830.6076004423605, panning=0.0, amplitude=1.0, bend=0.0, waveform=None, waveform_loop_start=0, waveform_loop_end=16384, envelope=None, filter=None, ring_frequency=0.0, ring_bend=0.0, ring_waveform=None, ring_waveform_loop_start=0, ring_waveform_loop_end=16384)) +(Note(frequency=830.6076004423605, panning=0.0, amplitude=1.0, bend=0.0, waveform=None, waveform_loop_start=0.0, waveform_loop_end=16384.0, envelope=None, filter=None, ring_frequency=0.0, ring_bend=0.0, ring_waveform=None, ring_waveform_loop_start=0.0, ring_waveform_loop_end=16384.0), Note(frequency=830.6076004423605, panning=0.0, amplitude=1.0, bend=0.0, waveform=None, waveform_loop_start=0.0, waveform_loop_end=16384.0, envelope=None, filter=None, ring_frequency=0.0, ring_bend=0.0, ring_waveform=None, ring_waveform_loop_start=0.0, ring_waveform_loop_end=16384.0)) [-1, -1, -1, -1, -1, -1, -1, -1, 28045, -1, -1, -1, -1, -28046, -1, -1, -1, -1, 28045, -1, -1, -1, -1, -28046] -(Note(frequency=830.6076004423605, panning=0.0, amplitude=1.0, bend=0.0, waveform=None, waveform_loop_start=0, waveform_loop_end=16384, envelope=None, filter=None, ring_frequency=0.0, ring_bend=0.0, ring_waveform=None, ring_waveform_loop_start=0, ring_waveform_loop_end=16384),) +(Note(frequency=830.6076004423605, panning=0.0, amplitude=1.0, bend=0.0, waveform=None, waveform_loop_start=0.0, waveform_loop_end=16384.0, envelope=None, filter=None, ring_frequency=0.0, ring_bend=0.0, ring_waveform=None, ring_waveform_loop_start=0.0, ring_waveform_loop_end=16384.0),) [-1, -1, -1, 28045, -1, -1, -1, -1, -1, -1, -1, -1, 28045, -1, -1, -1, -1, -28046, -1, -1, -1, -1, 28045, -1] (-5242, 5241) (-10485, 10484)