36
36
#include "shared-bindings/synthio/__init__.h"
37
37
#include "supervisor/shared/translate/translate.h"
38
38
39
- //| class Synth :
39
+ //| class Synthesizer :
40
40
//| def __init__(self, *, sample_rate: int = 11025, waveform: ReadableBuffer = None) -> None:
41
- //| """Create a synthesizer object."""
41
+ //| """Create a synthesizer object.
42
+ //|
43
+ //| This API is experimental.
44
+ //|
45
+ //| At least 2 simultaneous notes are supported. mimxrt10xx and rp2040 platforms support up to
46
+ //| 12 notes.
47
+ //|
48
+ //| Notes use MIDI note numbering, with 60 being C4 or Middle C, approximately 262Hz.
49
+ //|
50
+ //| :param int sample_rate: The desired playback sample rate; higher sample rate requires more memory
51
+ //| :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.
52
+ //| """
42
53
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 ) {
43
54
enum { ARG_sample_rate , ARG_waveform };
44
55
static const mp_arg_t allowed_args [] = {
@@ -69,7 +80,11 @@ STATIC void check_for_deinit(synthio_synthesizer_obj_t *self) {
69
80
}
70
81
71
82
//| def press(self, /, press: Sequence[int] = ()) -> None:
72
- //| """Turn some notes on. Notes use MIDI numbering, with 60 being middle C."""
83
+ //| """Turn some notes on. Notes use MIDI numbering, with 60 being middle C, approximately 262Hz.
84
+ //|
85
+ //| Pressing a note that was already pressed has no effect.
86
+ //|
87
+ //| :param Sequence[int] press: Any sequence of integer notes."""
73
88
STATIC mp_obj_t synthio_synthesizer_press (mp_obj_t self_in , mp_obj_t press ) {
74
89
synthio_synthesizer_obj_t * self = MP_OBJ_TO_PTR (self_in );
75
90
check_for_deinit (self );
@@ -81,7 +96,17 @@ STATIC MP_DEFINE_CONST_FUN_OBJ_2(synthio_synthesizer_press_obj, synthio_synthesi
81
96
//| def release_then_press(
82
97
//| self, release: Sequence[int] = (), press: Sequence[int] = ()
83
98
//| ) -> None:
84
- //| """Turn some notes on and/or off. Notes use MIDI numbering, with 60 being middle C."""
99
+ //| """Turn some notes on and/or off. Notes use MIDI numbering, with 60 being middle C.
100
+ //|
101
+ //| It is OK to release note that was not actually turned on.
102
+ //|
103
+ //| Pressing a note that was already pressed has no effect.
104
+ //|
105
+ //| Releasing and pressing the note again has little effect, but does reset the phase
106
+ //| of the note, which may be perceptible as a small glitch.
107
+ //|
108
+ //| :param Sequence[int] release: Any sequence of integer notes.
109
+ //| :param Sequence[int] press: Any sequence of integer notes."""
85
110
STATIC mp_obj_t synthio_synthesizer_release_then_press (mp_uint_t n_args , const mp_obj_t * pos_args , mp_map_t * kw_args ) {
86
111
enum { ARG_release , ARG_press };
87
112
static const mp_arg_t allowed_args [] = {
@@ -102,7 +127,12 @@ STATIC MP_DEFINE_CONST_FUN_OBJ_KW(synthio_synthesizer_release_then_press_obj, 1,
102
127
103
128
//
104
129
//| def release_all_then_press(self, /, press: Sequence[int]) -> None:
105
- //| """Turn any currently-playing notes off, then turn on the given notes"""
130
+ //| """Turn any currently-playing notes off, then turn on the given notes
131
+ //|
132
+ //| Releasing and pressing the note again has little effect, but does reset the phase
133
+ //| of the note, which may be perceptible as a small glitch.
134
+ //|
135
+ //| :param Sequence[int] press: Any sequence of integer notes."""
106
136
STATIC mp_obj_t synthio_synthesizer_release_all_then_press (mp_obj_t self_in , mp_obj_t press ) {
107
137
synthio_synthesizer_obj_t * self = MP_OBJ_TO_PTR (self_in );
108
138
check_for_deinit (self );
@@ -173,6 +203,10 @@ MP_DEFINE_CONST_FUN_OBJ_1(synthio_synthesizer_get_pressed_obj, synthio_synthesiz
173
203
MP_PROPERTY_GETTER (synthio_synthesizer_pressed_obj ,
174
204
(mp_obj_t )& synthio_synthesizer_get_pressed_obj );
175
205
206
+ //| max_polyphony: int
207
+ //| """Maximum polyphony of the synthesizer (read-only class property)"""
208
+ //|
209
+
176
210
STATIC const mp_rom_map_elem_t synthio_synthesizer_locals_dict_table [] = {
177
211
// Methods
178
212
{ MP_ROM_QSTR (MP_QSTR_press ), MP_ROM_PTR (& synthio_synthesizer_press_obj ) },
@@ -185,6 +219,7 @@ STATIC const mp_rom_map_elem_t synthio_synthesizer_locals_dict_table[] = {
185
219
186
220
// Properties
187
221
{ MP_ROM_QSTR (MP_QSTR_sample_rate ), MP_ROM_PTR (& synthio_synthesizer_sample_rate_obj ) },
222
+ { MP_ROM_QSTR (MP_QSTR_max_polyphony ), MP_ROM_INT (CIRCUITPY_SYNTHIO_MAX_CHANNELS ) },
188
223
{ MP_ROM_QSTR (MP_QSTR_pressed ), MP_ROM_PTR (& synthio_synthesizer_pressed_obj ) },
189
224
};
190
225
STATIC MP_DEFINE_CONST_DICT (synthio_synthesizer_locals_dict , synthio_synthesizer_locals_dict_table );
0 commit comments