Skip to content

Commit 1847c2b

Browse files
committed
synthio: fix, rename voct_to_hz
todbot discovered that this function wasn't working right, and wasn't well-named.
1 parent bb74be3 commit 1847c2b

File tree

3 files changed

+11
-11
lines changed

3 files changed

+11
-11
lines changed

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/__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)