Skip to content

Commit

Permalink
Rename param to envelope_sustain_index
Browse files Browse the repository at this point in the history
  • Loading branch information
jepler committed Apr 15, 2023
1 parent d0c0ac2 commit 2f208b5
Show file tree
Hide file tree
Showing 5 changed files with 18 additions and 18 deletions.
14 changes: 7 additions & 7 deletions shared-bindings/synthio/MidiTrack.c
Original file line number Diff line number Diff line change
Expand Up @@ -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::
//|
Expand All @@ -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);
Expand All @@ -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,
Expand All @@ -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);
Expand Down
2 changes: 1 addition & 1 deletion shared-bindings/synthio/MidiTrack.h
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down
14 changes: 7 additions & 7 deletions shared-bindings/synthio/Synthesizer.c
Original file line number Diff line number Diff line change
Expand Up @@ -49,26 +49,26 @@
//|
//| :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);

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;
Expand All @@ -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);
Expand Down
2 changes: 1 addition & 1 deletion shared-bindings/synthio/Synthesizer.h
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down
4 changes: 2 additions & 2 deletions shared-bindings/synthio/__init__.c
Original file line number Diff line number Diff line change
Expand Up @@ -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::
Expand Down

0 comments on commit 2f208b5

Please sign in to comment.