3333#include "shared-bindings/synthio/LFO.h"
3434#include "shared-module/synthio/LFO.h"
3535
36+ STATIC const uint16_t triangle [] = {0 , 32767 , 0 , -32767 };
37+
3638//| class LFO:
3739//| """A low-frequency oscillator block
3840//|
3941//| Every `rate` seconds, the output of the LFO cycles through its `waveform`.
4042//| The output at any particular moment is ``waveform[idx] * scale + offset``.
4143//|
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.
4347//|
4448//| `waveform` must be a ``ReadableBuffer`` with elements of type ``'h'``
4549//| (16-bit signed integer). Internally, the elements of `waveform` are scaled
5862//|
5963//| def __init__(
6064//| self,
61- //| waveform: ReadableBuffer,
65+ //| waveform: ReadableBuffer = None ,
6266//| *,
6367//| rate: BlockInput = 1.0,
6468//| scale: BlockInput = 1.0,
65- //| offset: BlockInput = 0,
66- //| phase_offset: BlockInput = 0,
69+ //| offset: BlockInput = 0.0 ,
70+ //| phase_offset: BlockInput = 0.0 ,
6771//| once=False,
6872//| interpolate=True
6973//| ):
7074//| pass
7175static 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 } },
7377 { MP_QSTR_rate , MP_ARG_OBJ | MP_ARG_KW_ONLY , {.u_obj = MP_ROM_INT (1 ) } },
7478 { MP_QSTR_scale , MP_ARG_OBJ | MP_ARG_KW_ONLY , {.u_obj = MP_ROM_INT (1 ) } },
7579 { 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
8791 synthio_lfo_obj_t * self = m_new_obj (synthio_lfo_obj_t );
8892 self -> base .base .type = & synthio_lfo_type ;
8993
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+ }
9198 self -> waveform_obj = args [ARG_waveform ].u_obj ;
9299 self -> base .last_tick = synthio_global_tick ;
93100
0 commit comments