From 1847c2b72a96d4c6158897f718376baad1f717ff Mon Sep 17 00:00:00 2001 From: Jeff Epler Date: Tue, 23 May 2023 18:41:15 -0500 Subject: [PATCH] synthio: fix, rename voct_to_hz todbot discovered that this function wasn't working right, and wasn't well-named. --- shared-bindings/synthio/__init__.c | 14 +++++++------- shared-bindings/synthio/__init__.h | 2 +- shared-module/synthio/__init__.c | 6 +++--- 3 files changed, 11 insertions(+), 11 deletions(-) diff --git a/shared-bindings/synthio/__init__.c b/shared-bindings/synthio/__init__.c index e1dfc111f9..b6185051fc 100644 --- a/shared-bindings/synthio/__init__.c +++ b/shared-bindings/synthio/__init__.c @@ -281,17 +281,17 @@ STATIC mp_obj_t midi_to_hz(mp_obj_t arg) { } MP_DEFINE_CONST_FUN_OBJ_1(synthio_midi_to_hz_obj, midi_to_hz); -//| def onevo_to_hz(ctrl: float) -> float: +//| def voct_to_hz(ctrl: float) -> float: //| """Converts a 1v/octave signal to Hz. //| -//| 60/12 (5.0) corresponds to middle C, 69/12 is concert A.""" +//| 24/12 (2.0) corresponds to middle C, 33/12 (2.75) is concert A.""" //| -STATIC mp_obj_t onevo_to_hz(mp_obj_t arg) { - mp_float_t note = mp_arg_validate_obj_float_range(arg, 0, 11, MP_QSTR_ctrl); - return mp_obj_new_float(common_hal_synthio_onevo_to_hz_float(note)); +STATIC mp_obj_t voct_to_hz(mp_obj_t arg) { + mp_float_t note = mp_arg_validate_obj_float_range(arg, -11, 11, MP_QSTR_ctrl); + return mp_obj_new_float(common_hal_synthio_voct_to_hz_float(note)); } -MP_DEFINE_CONST_FUN_OBJ_1(synthio_onevo_to_hz_obj, onevo_to_hz); +MP_DEFINE_CONST_FUN_OBJ_1(synthio_voct_to_hz_obj, voct_to_hz); #if CIRCUITPY_AUDIOCORE_DEBUG 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[] = { { MP_ROM_QSTR(MP_QSTR_from_file), MP_ROM_PTR(&synthio_from_file_obj) }, { MP_ROM_QSTR(MP_QSTR_Envelope), MP_ROM_PTR(&synthio_envelope_type_obj) }, { MP_ROM_QSTR(MP_QSTR_midi_to_hz), MP_ROM_PTR(&synthio_midi_to_hz_obj) }, - { MP_ROM_QSTR(MP_QSTR_onevo_to_hz), MP_ROM_PTR(&synthio_midi_to_hz_obj) }, + { MP_ROM_QSTR(MP_QSTR_voct_to_hz), MP_ROM_PTR(&synthio_voct_to_hz_obj) }, #if CIRCUITPY_AUDIOCORE_DEBUG { MP_ROM_QSTR(MP_QSTR_lfo_tick), MP_ROM_PTR(&synthio_lfo_tick_obj) }, #endif diff --git a/shared-bindings/synthio/__init__.h b/shared-bindings/synthio/__init__.h index 6f3aed0124..2315d92e58 100644 --- a/shared-bindings/synthio/__init__.h +++ b/shared-bindings/synthio/__init__.h @@ -41,4 +41,4 @@ extern const mp_obj_namedtuple_type_t synthio_envelope_type_obj; void synthio_synth_envelope_set(synthio_synth_t *synth, mp_obj_t envelope_obj); mp_obj_t synthio_synth_envelope_get(synthio_synth_t *synth); mp_float_t common_hal_synthio_midi_to_hz_float(mp_float_t note); -mp_float_t common_hal_synthio_onevo_to_hz_float(mp_float_t note); +mp_float_t common_hal_synthio_voct_to_hz_float(mp_float_t note); diff --git a/shared-module/synthio/__init__.c b/shared-module/synthio/__init__.c index 85e98329fd..7c8e627404 100644 --- a/shared-module/synthio/__init__.c +++ b/shared-module/synthio/__init__.c @@ -46,11 +46,11 @@ STATIC int64_t round_float_to_int64(mp_float_t f) { } mp_float_t common_hal_synthio_midi_to_hz_float(mp_float_t arg) { - return common_hal_synthio_onevo_to_hz_float(arg / 12.); + return common_hal_synthio_voct_to_hz_float(arg / 12. - 3); } -mp_float_t common_hal_synthio_onevo_to_hz_float(mp_float_t octave) { - return notes[0] * MICROPY_FLOAT_C_FUN(pow)(2., octave - 10); +mp_float_t common_hal_synthio_voct_to_hz_float(mp_float_t octave) { + return notes[0] * MICROPY_FLOAT_C_FUN(pow)(2., octave - 7); } STATIC int16_t convert_time_to_rate(uint32_t sample_rate, mp_obj_t time_in, int16_t difference) {