diff --git a/shared-bindings/synthio/MidiTrack.c b/shared-bindings/synthio/MidiTrack.c index cb8be34cdc322..59507bf08340e 100644 --- a/shared-bindings/synthio/MidiTrack.c +++ b/shared-bindings/synthio/MidiTrack.c @@ -54,8 +54,8 @@ //| :param int tempo: Tempo of the streamed events, in MIDI ticks per second //| :param int sample_rate: The desired playback sample rate; higher sample rate requires more memory //| :param ReadableBuffer waveform: A single-cycle waveform. Default is a 50% duty cycle square wave. If specified, must be a ReadableBuffer of type 'h' (signed 16 bit) -//| :param ReadableBuffer envelope: A buffer that controls how the loudness of the note evolves over time. Values from the start to the ``envelope_hold_index`` are used for the attack and decay; the value at ``envelope_hold_index`` is the sustain volume, and following values are the release. The envelope value is updated once per audio frame, or 256 samples; This ranges from e.g., 5.3ms at 48kHz to 23ms at 11kHz. The default envelope provides no ramping. -//| :param Optional[int] envelope_hold_index: The index within the envelope array which is the 'hold' value. Must be specified if ``envelope`` is. +//| :param ReadableBuffer envelope: A buffer that controls how the loudness of the note evolves over time. Values from the start to the ``envelope_sustain_index`` are used for the attack and decay; the value at ``envelope_sustain_index`` is the sustain volume, and following values are the release. The envelope value is updated once per audio frame, or 256 samples; This ranges from e.g., 5.3ms at 48kHz to 23ms at 11kHz. The default envelope provides no ramping. +//| :param Optional[int] envelope_sustain_index: The index within the envelope array which is the 'hold' value. Must be specified if ``envelope`` is. //| //| Simple melody:: //| @@ -74,14 +74,14 @@ //| print("stopped")""" //| ... STATIC mp_obj_t synthio_miditrack_make_new(const mp_obj_type_t *type, size_t n_args, size_t n_kw, const mp_obj_t *all_args) { - enum { ARG_buffer, ARG_tempo, ARG_sample_rate, ARG_waveform, ARG_envelope, ARG_envelope_hold_index }; + enum { ARG_buffer, ARG_tempo, ARG_sample_rate, ARG_waveform, ARG_envelope, ARG_envelope_sustain_index }; static const mp_arg_t allowed_args[] = { { MP_QSTR_buffer, MP_ARG_OBJ | MP_ARG_REQUIRED }, { MP_QSTR_tempo, MP_ARG_INT | MP_ARG_REQUIRED }, { MP_QSTR_sample_rate, MP_ARG_INT | MP_ARG_KW_ONLY, {.u_int = 11025} }, { MP_QSTR_waveform, MP_ARG_OBJ | MP_ARG_KW_ONLY, {.u_obj = mp_const_none } }, { MP_QSTR_envelope, MP_ARG_OBJ | MP_ARG_KW_ONLY, {.u_obj = mp_const_none } }, - { MP_QSTR_envelope_hold_index, MP_ARG_OBJ | MP_ARG_KW_ONLY, {.u_obj = mp_const_none } }, + { MP_QSTR_envelope_sustain_index, MP_ARG_OBJ | MP_ARG_KW_ONLY, {.u_obj = mp_const_none } }, }; mp_arg_val_t args[MP_ARRAY_SIZE(allowed_args)]; mp_arg_parse_all_kw_array(n_args, n_kw, all_args, MP_ARRAY_SIZE(allowed_args), allowed_args, args); @@ -95,9 +95,9 @@ STATIC mp_obj_t synthio_miditrack_make_new(const mp_obj_type_t *type, size_t n_a synthio_miditrack_obj_t *self = m_new_obj(synthio_miditrack_obj_t); self->base.type = &synthio_miditrack_type; - uint16_t envelope_hold_index; + uint16_t envelope_sustain_index; mp_buffer_info_t bufinfo_envelope; - synthio_synth_parse_envelope(&envelope_hold_index, &bufinfo_envelope, args[ARG_envelope].u_obj, args[ARG_envelope_hold_index].u_obj); + synthio_synth_parse_envelope(&envelope_sustain_index, &bufinfo_envelope, args[ARG_envelope].u_obj, args[ARG_envelope_sustain_index].u_obj); common_hal_synthio_miditrack_construct(self, (uint8_t *)bufinfo.buf, bufinfo.len, @@ -107,7 +107,7 @@ STATIC mp_obj_t synthio_miditrack_make_new(const mp_obj_type_t *type, size_t n_a bufinfo_waveform.len / 2, bufinfo_envelope.buf, bufinfo_envelope.len / 2, - envelope_hold_index + envelope_sustain_index ); return MP_OBJ_FROM_PTR(self); diff --git a/shared-bindings/synthio/MidiTrack.h b/shared-bindings/synthio/MidiTrack.h index b671764886b77..a5e855824a13f 100644 --- a/shared-bindings/synthio/MidiTrack.h +++ b/shared-bindings/synthio/MidiTrack.h @@ -32,7 +32,7 @@ extern const mp_obj_type_t synthio_miditrack_type; void common_hal_synthio_miditrack_construct(synthio_miditrack_obj_t *self, const uint8_t *buffer, uint32_t len, uint32_t tempo, uint32_t sample_rate, const int16_t *waveform, uint16_t waveform_len, - const int16_t *envelope, uint16_t envelope_length, uint16_t envelope_hold_index); + const int16_t *envelope, uint16_t envelope_length, uint16_t envelope_sustain_index); void common_hal_synthio_miditrack_deinit(synthio_miditrack_obj_t *self); bool common_hal_synthio_miditrack_deinited(synthio_miditrack_obj_t *self); diff --git a/shared-bindings/synthio/Synthesizer.c b/shared-bindings/synthio/Synthesizer.c index 5bc276ee6d658..29685bb256607 100644 --- a/shared-bindings/synthio/Synthesizer.c +++ b/shared-bindings/synthio/Synthesizer.c @@ -49,16 +49,16 @@ //| //| :param int sample_rate: The desired playback sample rate; higher sample rate requires more memory //| :param ReadableBuffer waveform: A single-cycle waveform. Default is a 50% duty cycle square wave. If specified, must be a ReadableBuffer of type 'h' (signed 16 bit). It is permitted to modify this buffer during synthesis. This can be used, for instance, to control the overall volume or timbre of the notes. -//| :param ReadableBuffer envelope: A buffer that controls how the loudness of the note evolves over time. Values from the start to the ``envelope_hold_index`` are used for the attack and decay; the value at ``envelope_hold_index`` is the sustain volume, and following values are the release. The envelope value is updated once per audio frame, or 256 samples; This ranges from e.g., 5.3ms at 48kHz to 23ms at 11kHz. The default envelope provides no ramping. -//| :param Optional[int] envelope_hold_index: The index within the envelope array which is the 'hold' value. Must be specified if ``envelope`` is. +//| :param ReadableBuffer envelope: A buffer that controls how the loudness of the note evolves over time. Values from the start to the ``envelope_sustain_index`` are used for the attack and decay; the value at ``envelope_sustain_index`` is the sustain volume, and following values are the release. The envelope value is updated once per audio frame, or 256 samples; This ranges from e.g., 5.3ms at 48kHz to 23ms at 11kHz. The default envelope provides no ramping. +//| :param Optional[int] envelope_sustain_index: The index within the envelope array which is the 'hold' value. Must be specified if ``envelope`` is. //| """ STATIC mp_obj_t synthio_synthesizer_make_new(const mp_obj_type_t *type, size_t n_args, size_t n_kw, const mp_obj_t *all_args) { - enum { ARG_sample_rate, ARG_waveform, ARG_envelope, ARG_envelope_hold_index }; + enum { ARG_sample_rate, ARG_waveform, ARG_envelope, ARG_envelope_sustain_index }; static const mp_arg_t allowed_args[] = { { MP_QSTR_sample_rate, MP_ARG_INT | MP_ARG_KW_ONLY, {.u_int = 11025} }, { MP_QSTR_waveform, MP_ARG_OBJ | MP_ARG_KW_ONLY, {.u_obj = mp_const_none } }, { MP_QSTR_envelope, MP_ARG_OBJ | MP_ARG_KW_ONLY, {.u_obj = mp_const_none } }, - { MP_QSTR_envelope_hold_index, MP_ARG_OBJ | MP_ARG_KW_ONLY, {.u_obj = mp_const_none } }, + { MP_QSTR_envelope_sustain_index, MP_ARG_OBJ | MP_ARG_KW_ONLY, {.u_obj = mp_const_none } }, }; mp_arg_val_t args[MP_ARRAY_SIZE(allowed_args)]; mp_arg_parse_all_kw_array(n_args, n_kw, all_args, MP_ARRAY_SIZE(allowed_args), allowed_args, args); @@ -66,9 +66,9 @@ STATIC mp_obj_t synthio_synthesizer_make_new(const mp_obj_type_t *type, size_t n mp_buffer_info_t bufinfo_waveform; synthio_synth_parse_waveform(&bufinfo_waveform, args[ARG_waveform].u_obj); - uint16_t envelope_hold_index; + uint16_t envelope_sustain_index; mp_buffer_info_t bufinfo_envelope; - synthio_synth_parse_envelope(&envelope_hold_index, &bufinfo_envelope, args[ARG_envelope].u_obj, args[ARG_envelope_hold_index].u_obj); + synthio_synth_parse_envelope(&envelope_sustain_index, &bufinfo_envelope, args[ARG_envelope].u_obj, args[ARG_envelope_sustain_index].u_obj); synthio_synthesizer_obj_t *self = m_new_obj(synthio_synthesizer_obj_t); self->base.type = &synthio_synthesizer_type; @@ -79,7 +79,7 @@ STATIC mp_obj_t synthio_synthesizer_make_new(const mp_obj_type_t *type, size_t n bufinfo_waveform.len / 2, bufinfo_envelope.buf, bufinfo_envelope.len / 2, - envelope_hold_index); + envelope_sustain_index); return MP_OBJ_FROM_PTR(self); diff --git a/shared-bindings/synthio/Synthesizer.h b/shared-bindings/synthio/Synthesizer.h index b109b3e1a1852..6cd13d5a54d78 100644 --- a/shared-bindings/synthio/Synthesizer.h +++ b/shared-bindings/synthio/Synthesizer.h @@ -33,7 +33,7 @@ extern const mp_obj_type_t synthio_synthesizer_type; void common_hal_synthio_synthesizer_construct(synthio_synthesizer_obj_t *self, uint32_t sample_rate, const int16_t *waveform, uint16_t waveform_len, - const int16_t *envelope, uint16_t envelope_size, uint16_t envelope_hold_index); + const int16_t *envelope, uint16_t envelope_size, uint16_t envelope_sustain_index); void common_hal_synthio_synthesizer_deinit(synthio_synthesizer_obj_t *self); bool common_hal_synthio_synthesizer_deinited(synthio_synthesizer_obj_t *self); diff --git a/shared-bindings/synthio/__init__.c b/shared-bindings/synthio/__init__.c index e8ae6ae926d7d..308f712cb39b3 100644 --- a/shared-bindings/synthio/__init__.c +++ b/shared-bindings/synthio/__init__.c @@ -45,8 +45,8 @@ //| :param typing.BinaryIO file: Already opened MIDI file //| :param int sample_rate: The desired playback sample rate; higher sample rate requires more memory //| :param ReadableBuffer waveform: A single-cycle waveform. Default is a 50% duty cycle square wave. If specified, must be a ReadableBuffer of type 'h' (signed 16 bit) -//| :param ReadableBuffer envelope: A buffer that controls how the loudness of the note evolves over time. Values from the start to the ``envelope_hold_index`` are used for the attack and decay; the value at ``envelope_hold_index`` is the sustain volume, and following values are the release. The envelope value is updated once per audio frame, or 256 samples; This ranges from e.g., 5.3ms at 48kHz to 23ms at 11kHz. The default envelope provides no ramping. -//| :param Optional[int] envelope_hold_index: The index within the envelope array which is the 'hold' value. Must be specified if ``envelope`` is. +//| :param ReadableBuffer envelope: A buffer that controls how the loudness of the note evolves over time. Values from the start to the ``envelope_sustain_index`` are used for the attack and decay; the value at ``envelope_sustain_index`` is the sustain volume, and following values are the release. The envelope value is updated once per audio frame, or 256 samples; This ranges from e.g., 5.3ms at 48kHz to 23ms at 11kHz. The default envelope provides no ramping. +//| :param Optional[int] envelope_sustain_index: The index within the envelope array which is the 'hold' value. Must be specified if ``envelope`` is. //| //| //| Playing a MIDI file from flash::