Skip to content

Commit 9359d81

Browse files
authored
Merge pull request #8024 from jepler/synthio-todbot-feedback
synthio: improvements based on feedback
2 parents ff20031 + 9f138dc commit 9359d81

File tree

8 files changed

+28
-27
lines changed

8 files changed

+28
-27
lines changed

shared-bindings/synthio/Note.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -79,7 +79,7 @@ STATIC mp_obj_t synthio_note_make_new(const mp_obj_type_t *type_in, size_t n_arg
7979
return result;
8080
};
8181

82-
//| frequency: BlockInput
82+
//| frequency: float
8383
//| """The base frequency of the note, in Hz."""
8484
STATIC mp_obj_t synthio_note_get_frequency(mp_obj_t self_in) {
8585
synthio_note_obj_t *self = MP_OBJ_TO_PTR(self_in);

shared-bindings/synthio/Synthesizer.c

Lines changed: 10 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -52,6 +52,7 @@
5252
//| channel_count: int = 1,
5353
//| waveform: Optional[ReadableBuffer] = None,
5454
//| envelope: Optional[Envelope] = None,
55+
//| filter: Optional[ReadableBuffer] = None,
5556
//| ) -> None:
5657
//| """Create a synthesizer object.
5758
//|
@@ -270,22 +271,22 @@ MP_DEFINE_CONST_FUN_OBJ_1(synthio_synthesizer_get_pressed_obj, synthio_synthesiz
270271
MP_PROPERTY_GETTER(synthio_synthesizer_pressed_obj,
271272
(mp_obj_t)&synthio_synthesizer_get_pressed_obj);
272273

273-
//| lfos: List[LFO]
274-
//| """A list of LFOs to advance whether or not they are associated with a playing note.
274+
//| blocks: List[BlockInput]
275+
//| """A list of blocks to advance whether or not they are associated with a playing note.
275276
//|
276277
//| This can be used to implement 'free-running' LFOs. LFOs associated with playing notes are advanced whether or not they are in this list.
277278
//|
278-
//| This property is read-only but its contents may be modified by e.g., calling ``synth.lfos.append()`` or ``synth.lfos.remove()``. It is initially an empty list."""
279+
//| This property is read-only but its contents may be modified by e.g., calling ``synth.blocks.append()`` or ``synth.blocks.remove()``. It is initially an empty list."""
279280
//|
280-
STATIC mp_obj_t synthio_synthesizer_obj_get_lfos(mp_obj_t self_in) {
281+
STATIC mp_obj_t synthio_synthesizer_obj_get_blocks(mp_obj_t self_in) {
281282
synthio_synthesizer_obj_t *self = MP_OBJ_TO_PTR(self_in);
282283
check_for_deinit(self);
283-
return common_hal_synthio_synthesizer_get_lfos(self);
284+
return common_hal_synthio_synthesizer_get_blocks(self);
284285
}
285-
MP_DEFINE_CONST_FUN_OBJ_1(synthio_synthesizer_get_lfos_obj, synthio_synthesizer_obj_get_lfos);
286+
MP_DEFINE_CONST_FUN_OBJ_1(synthio_synthesizer_get_blocks_obj, synthio_synthesizer_obj_get_blocks);
286287

287-
MP_PROPERTY_GETTER(synthio_synthesizer_lfos_obj,
288-
(mp_obj_t)&synthio_synthesizer_get_lfos_obj);
288+
MP_PROPERTY_GETTER(synthio_synthesizer_blocks_obj,
289+
(mp_obj_t)&synthio_synthesizer_get_blocks_obj);
289290

290291
//| max_polyphony: int
291292
//| """Maximum polyphony of the synthesizer (read-only class property)"""
@@ -308,7 +309,7 @@ STATIC const mp_rom_map_elem_t synthio_synthesizer_locals_dict_table[] = {
308309
{ MP_ROM_QSTR(MP_QSTR_sample_rate), MP_ROM_PTR(&synthio_synthesizer_sample_rate_obj) },
309310
{ MP_ROM_QSTR(MP_QSTR_max_polyphony), MP_ROM_INT(CIRCUITPY_SYNTHIO_MAX_CHANNELS) },
310311
{ MP_ROM_QSTR(MP_QSTR_pressed), MP_ROM_PTR(&synthio_synthesizer_pressed_obj) },
311-
{ MP_ROM_QSTR(MP_QSTR_lfos), MP_ROM_PTR(&synthio_synthesizer_lfos_obj) },
312+
{ MP_ROM_QSTR(MP_QSTR_blocks), MP_ROM_PTR(&synthio_synthesizer_blocks_obj) },
312313
};
313314
STATIC MP_DEFINE_CONST_DICT(synthio_synthesizer_locals_dict, synthio_synthesizer_locals_dict_table);
314315

shared-bindings/synthio/Synthesizer.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -44,4 +44,4 @@ void common_hal_synthio_synthesizer_press(synthio_synthesizer_obj_t *self, mp_ob
4444
void common_hal_synthio_synthesizer_retrigger(synthio_synthesizer_obj_t *self, mp_obj_t to_retrigger);
4545
void common_hal_synthio_synthesizer_release_all(synthio_synthesizer_obj_t *self);
4646
mp_obj_t common_hal_synthio_synthesizer_get_pressed_notes(synthio_synthesizer_obj_t *self);
47-
mp_obj_t common_hal_synthio_synthesizer_get_lfos(synthio_synthesizer_obj_t *self);
47+
mp_obj_t common_hal_synthio_synthesizer_get_blocks(synthio_synthesizer_obj_t *self);

shared-bindings/synthio/__init__.c

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -281,17 +281,17 @@ STATIC mp_obj_t midi_to_hz(mp_obj_t arg) {
281281
}
282282
MP_DEFINE_CONST_FUN_OBJ_1(synthio_midi_to_hz_obj, midi_to_hz);
283283

284-
//| def onevo_to_hz(ctrl: float) -> float:
284+
//| def voct_to_hz(ctrl: float) -> float:
285285
//| """Converts a 1v/octave signal to Hz.
286286
//|
287-
//| 60/12 (5.0) corresponds to middle C, 69/12 is concert A."""
287+
//| 24/12 (2.0) corresponds to middle C, 33/12 (2.75) is concert A."""
288288
//|
289289

290-
STATIC mp_obj_t onevo_to_hz(mp_obj_t arg) {
291-
mp_float_t note = mp_arg_validate_obj_float_range(arg, 0, 11, MP_QSTR_ctrl);
292-
return mp_obj_new_float(common_hal_synthio_onevo_to_hz_float(note));
290+
STATIC mp_obj_t voct_to_hz(mp_obj_t arg) {
291+
mp_float_t note = mp_arg_validate_obj_float_range(arg, -11, 11, MP_QSTR_ctrl);
292+
return mp_obj_new_float(common_hal_synthio_voct_to_hz_float(note));
293293
}
294-
MP_DEFINE_CONST_FUN_OBJ_1(synthio_onevo_to_hz_obj, onevo_to_hz);
294+
MP_DEFINE_CONST_FUN_OBJ_1(synthio_voct_to_hz_obj, voct_to_hz);
295295

296296
#if CIRCUITPY_AUDIOCORE_DEBUG
297297
STATIC mp_obj_t synthio_lfo_tick(size_t n, const mp_obj_t *args) {
@@ -319,7 +319,7 @@ STATIC const mp_rom_map_elem_t synthio_module_globals_table[] = {
319319
{ MP_ROM_QSTR(MP_QSTR_from_file), MP_ROM_PTR(&synthio_from_file_obj) },
320320
{ MP_ROM_QSTR(MP_QSTR_Envelope), MP_ROM_PTR(&synthio_envelope_type_obj) },
321321
{ MP_ROM_QSTR(MP_QSTR_midi_to_hz), MP_ROM_PTR(&synthio_midi_to_hz_obj) },
322-
{ MP_ROM_QSTR(MP_QSTR_onevo_to_hz), MP_ROM_PTR(&synthio_midi_to_hz_obj) },
322+
{ MP_ROM_QSTR(MP_QSTR_voct_to_hz), MP_ROM_PTR(&synthio_voct_to_hz_obj) },
323323
#if CIRCUITPY_AUDIOCORE_DEBUG
324324
{ MP_ROM_QSTR(MP_QSTR_lfo_tick), MP_ROM_PTR(&synthio_lfo_tick_obj) },
325325
#endif

shared-bindings/synthio/__init__.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -41,4 +41,4 @@ extern const mp_obj_namedtuple_type_t synthio_envelope_type_obj;
4141
void synthio_synth_envelope_set(synthio_synth_t *synth, mp_obj_t envelope_obj);
4242
mp_obj_t synthio_synth_envelope_get(synthio_synth_t *synth);
4343
mp_float_t common_hal_synthio_midi_to_hz_float(mp_float_t note);
44-
mp_float_t common_hal_synthio_onevo_to_hz_float(mp_float_t note);
44+
mp_float_t common_hal_synthio_voct_to_hz_float(mp_float_t note);

shared-module/synthio/Synthesizer.c

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,7 @@ void common_hal_synthio_synthesizer_construct(synthio_synthesizer_obj_t *self,
3737
mp_obj_t envelope_obj) {
3838

3939
synthio_synth_init(&self->synth, sample_rate, channel_count, waveform_obj, filter_obj, envelope_obj);
40-
self->lfos = mp_obj_new_list(0, NULL);
40+
self->blocks = mp_obj_new_list(0, NULL);
4141
}
4242

4343
void common_hal_synthio_synthesizer_deinit(synthio_synthesizer_obj_t *self) {
@@ -75,7 +75,7 @@ audioio_get_buffer_result_t synthio_synthesizer_get_buffer(synthio_synthesizer_o
7575

7676
// free-running LFOs
7777
mp_obj_iter_buf_t iter_buf;
78-
mp_obj_t iterable = mp_getiter(self->lfos, &iter_buf);
78+
mp_obj_t iterable = mp_getiter(self->blocks, &iter_buf);
7979
mp_obj_t item;
8080
while ((item = mp_iternext(iterable)) != MP_OBJ_STOP_ITERATION) {
8181
if (!synthio_obj_is_block(item)) {
@@ -185,6 +185,6 @@ mp_obj_t common_hal_synthio_synthesizer_get_pressed_notes(synthio_synthesizer_ob
185185
return MP_OBJ_FROM_PTR(result);
186186
}
187187

188-
mp_obj_t common_hal_synthio_synthesizer_get_lfos(synthio_synthesizer_obj_t *self) {
189-
return self->lfos;
188+
mp_obj_t common_hal_synthio_synthesizer_get_blocks(synthio_synthesizer_obj_t *self) {
189+
return self->blocks;
190190
}

shared-module/synthio/Synthesizer.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,7 @@
3434
typedef struct {
3535
mp_obj_base_t base;
3636
synthio_synth_t synth;
37-
mp_obj_t lfos;
37+
mp_obj_t blocks;
3838
} synthio_synthesizer_obj_t;
3939

4040

shared-module/synthio/__init__.c

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -46,11 +46,11 @@ STATIC int64_t round_float_to_int64(mp_float_t f) {
4646
}
4747

4848
mp_float_t common_hal_synthio_midi_to_hz_float(mp_float_t arg) {
49-
return common_hal_synthio_onevo_to_hz_float(arg / 12.);
49+
return common_hal_synthio_voct_to_hz_float(arg / 12. - 3);
5050
}
5151

52-
mp_float_t common_hal_synthio_onevo_to_hz_float(mp_float_t octave) {
53-
return notes[0] * MICROPY_FLOAT_C_FUN(pow)(2., octave - 10);
52+
mp_float_t common_hal_synthio_voct_to_hz_float(mp_float_t octave) {
53+
return notes[0] * MICROPY_FLOAT_C_FUN(pow)(2., octave - 7);
5454
}
5555

5656
STATIC int16_t convert_time_to_rate(uint32_t sample_rate, mp_obj_t time_in, int16_t difference) {

0 commit comments

Comments
 (0)