33
33
#include "shared-bindings/synthio/LFO.h"
34
34
#include "shared-module/synthio/LFO.h"
35
35
36
+ STATIC const uint16_t triangle [] = {0 , 32767 , 0 , -32767 };
37
+
36
38
//| class LFO:
37
39
//| """A low-frequency oscillator block
38
40
//|
39
41
//| Every `rate` seconds, the output of the LFO cycles through its `waveform`.
40
42
//| The output at any particular moment is ``waveform[idx] * scale + offset``.
41
43
//|
42
- //| `rate`, `offset`, `scale`, and `once` can be changed at run-time. `waveform` may be mutated.
44
+ //| If `waveform` is None, a triangle waveform is used.
45
+ //|
46
+ //| `rate`, `phase_offset`, `offset`, `scale`, and `once` can be changed at run-time. `waveform` may be mutated.
43
47
//|
44
48
//| `waveform` must be a ``ReadableBuffer`` with elements of type ``'h'``
45
49
//| (16-bit signed integer). Internally, the elements of `waveform` are scaled
58
62
//|
59
63
//| def __init__(
60
64
//| self,
61
- //| waveform: ReadableBuffer,
65
+ //| waveform: ReadableBuffer = None ,
62
66
//| *,
63
67
//| rate: BlockInput = 1.0,
64
68
//| scale: BlockInput = 1.0,
65
- //| offset: BlockInput = 0,
66
- //| phase_offset: BlockInput = 0,
69
+ //| offset: BlockInput = 0.0 ,
70
+ //| phase_offset: BlockInput = 0.0 ,
67
71
//| once=False,
68
72
//| interpolate=True
69
73
//| ):
70
74
//| pass
71
75
static const mp_arg_t lfo_properties [] = {
72
- { MP_QSTR_waveform , MP_ARG_OBJ | MP_ARG_REQUIRED , {.u_obj = NULL } },
76
+ { MP_QSTR_waveform , MP_ARG_OBJ , {.u_obj = MP_ROM_NONE } },
73
77
{ MP_QSTR_rate , MP_ARG_OBJ | MP_ARG_KW_ONLY , {.u_obj = MP_ROM_INT (1 ) } },
74
78
{ MP_QSTR_scale , MP_ARG_OBJ | MP_ARG_KW_ONLY , {.u_obj = MP_ROM_INT (1 ) } },
75
79
{ MP_QSTR_offset , MP_ARG_OBJ | MP_ARG_KW_ONLY , {.u_obj = MP_ROM_INT (0 ) } },
@@ -87,7 +91,10 @@ STATIC mp_obj_t synthio_lfo_make_new(const mp_obj_type_t *type_in, size_t n_args
87
91
synthio_lfo_obj_t * self = m_new_obj (synthio_lfo_obj_t );
88
92
self -> base .base .type = & synthio_lfo_type ;
89
93
90
- synthio_synth_parse_waveform (& self -> waveform_bufinfo , args [ARG_waveform ].u_obj );
94
+ self -> waveform_bufinfo = ((mp_buffer_info_t ) {.buf = triangle , .len = MP_ARRAY_SIZE (triangle )});
95
+ if (args [ARG_waveform ].u_obj != mp_const_none ) {
96
+ synthio_synth_parse_waveform (& self -> waveform_bufinfo , args [ARG_waveform ].u_obj );
97
+ }
91
98
self -> waveform_obj = args [ARG_waveform ].u_obj ;
92
99
self -> base .last_tick = synthio_global_tick ;
93
100
0 commit comments