Skip to content

Commit 1d1907b

Browse files
committed
synthio: Generalize vibrato into bend
bend can be static, sweep, or vibrato
1 parent c48d385 commit 1d1907b

File tree

10 files changed

+153
-69
lines changed

10 files changed

+153
-69
lines changed

shared-bindings/synthio/Note.c

Lines changed: 55 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,7 @@
3030
#include "py/objproperty.h"
3131
#include "py/runtime.h"
3232
#include "shared-bindings/util.h"
33+
#include "shared-bindings/synthio/__init__.h"
3334
#include "shared-bindings/synthio/Note.h"
3435
#include "shared-module/synthio/Note.h"
3536

@@ -38,8 +39,9 @@ static const mp_arg_t note_properties[] = {
3839
{ MP_QSTR_amplitude, MP_ARG_OBJ | MP_ARG_KW_ONLY, {.u_obj = MP_ROM_INT(1) } },
3940
{ MP_QSTR_tremolo_rate, MP_ARG_OBJ | MP_ARG_KW_ONLY, {.u_obj = NULL } },
4041
{ MP_QSTR_tremolo_depth, MP_ARG_OBJ | MP_ARG_KW_ONLY, {.u_obj = NULL } },
41-
{ MP_QSTR_vibrato_rate, MP_ARG_OBJ | MP_ARG_KW_ONLY, {.u_obj = NULL } },
42-
{ MP_QSTR_vibrato_depth, MP_ARG_OBJ | MP_ARG_KW_ONLY, {.u_obj = NULL } },
42+
{ MP_QSTR_bend_rate, MP_ARG_OBJ | MP_ARG_KW_ONLY, {.u_obj = NULL } },
43+
{ MP_QSTR_bend_depth, MP_ARG_OBJ | MP_ARG_KW_ONLY, {.u_obj = NULL } },
44+
{ MP_QSTR_bend_mode, MP_ARG_OBJ | MP_ARG_KW_ONLY, {.u_obj = (mp_obj_t)MP_ROM_PTR(&bend_mode_VIBRATO_obj) } },
4345
{ MP_QSTR_waveform, MP_ARG_OBJ | MP_ARG_KW_ONLY, {.u_obj = MP_ROM_NONE } },
4446
{ MP_QSTR_envelope, MP_ARG_OBJ | MP_ARG_KW_ONLY, {.u_obj = MP_ROM_NONE } },
4547
};
@@ -53,17 +55,16 @@ static const mp_arg_t note_properties[] = {
5355
//| envelope: Optional[Envelope] = None,
5456
//| tremolo_depth: float = 0.0,
5557
//| tremolo_rate: float = 0.0,
56-
//| vibrato_depth: float = 0.0,
57-
//| vibrato_rate: float = 0.0,
58+
//| bend_depth: float = 0.0,
59+
//| bend_rate: float = 0.0,
5860
//| ) -> None:
59-
//| """Construct a Note object, with a frequency in Hz, and optional amplitude (volume), waveform, envelope, tremolo (volume change) and vibrato (frequency change).
61+
//| """Construct a Note object, with a frequency in Hz, and optional amplitude (volume), waveform, envelope, tremolo (volume change) and bend (frequency change).
6062
//|
6163
//| If waveform or envelope are `None` the synthesizer object's default waveform or envelope are used.
6264
//|
6365
//| If the same Note object is played on multiple Synthesizer objects, the result is undefined.
6466
//| """
6567
STATIC mp_obj_t synthio_note_make_new(const mp_obj_type_t *type_in, size_t n_args, size_t n_kw, const mp_obj_t *all_args) {
66-
enum { ARG_frequency, ARG_amplitude, ARG_waveform, ARG_envelope, ARG_tremolo_rate, ARG_tremolo_depth, ARG_vibrato_rate, ARG_vibrato_depth };
6768
mp_arg_val_t args[MP_ARRAY_SIZE(note_properties)];
6869
mp_arg_parse_all_kw_array(n_args, n_kw, all_args, MP_ARRAY_SIZE(note_properties), note_properties, args);
6970

@@ -158,46 +159,67 @@ MP_PROPERTY_GETSET(synthio_note_tremolo_rate_obj,
158159
(mp_obj_t)&synthio_note_get_tremolo_rate_obj,
159160
(mp_obj_t)&synthio_note_set_tremolo_rate_obj);
160161

161-
//| vibrato_depth: float
162-
//| """The vibrato depth of the note, from 0 to 1
163162
//|
164-
//| A depth of 0 disables vibrato. A depth of 1 corresponds to a vibrato of ±1
165-
//| octave. A depth of (1/12) = 0.833 corresponds to a vibrato of ±1 semitone,
163+
//| bend_mode: BendMode
164+
//| """The type of bend operation"""
165+
STATIC mp_obj_t synthio_note_get_bend_mode(mp_obj_t self_in) {
166+
synthio_note_obj_t *self = MP_OBJ_TO_PTR(self_in);
167+
return cp_enum_find(&synthio_bend_mode_type, common_hal_synthio_note_get_bend_mode(self));
168+
}
169+
MP_DEFINE_CONST_FUN_OBJ_1(synthio_note_get_bend_mode_obj, synthio_note_get_bend_mode);
170+
171+
STATIC mp_obj_t synthio_note_set_bend_mode(mp_obj_t self_in, mp_obj_t arg) {
172+
synthio_note_obj_t *self = MP_OBJ_TO_PTR(self_in);
173+
common_hal_synthio_note_set_bend_mode(self, cp_enum_value(&synthio_bend_mode_type, arg, MP_QSTR_bend_mode));
174+
return mp_const_none;
175+
}
176+
MP_DEFINE_CONST_FUN_OBJ_2(synthio_note_set_bend_mode_obj, synthio_note_set_bend_mode);
177+
MP_PROPERTY_GETSET(synthio_note_bend_mode_obj,
178+
(mp_obj_t)&synthio_note_get_bend_mode_obj,
179+
(mp_obj_t)&synthio_note_set_bend_mode_obj);
180+
181+
//
182+
//|
183+
//| bend_depth: float
184+
//| """The bend depth of the note, from -1 to +1
185+
//|
186+
//| A depth of 0 disables bend. A depth of 1 corresponds to a bend of 1
187+
//| octave. A depth of (1/12) = 0.833 corresponds to a bend of 1 semitone,
166188
//| and a depth of .00833 corresponds to one musical cent.
167189
//| """
168-
STATIC mp_obj_t synthio_note_get_vibrato_depth(mp_obj_t self_in) {
190+
STATIC mp_obj_t synthio_note_get_bend_depth(mp_obj_t self_in) {
169191
synthio_note_obj_t *self = MP_OBJ_TO_PTR(self_in);
170-
return mp_obj_new_float(common_hal_synthio_note_get_vibrato_depth(self));
192+
return mp_obj_new_float(common_hal_synthio_note_get_bend_depth(self));
171193
}
172-
MP_DEFINE_CONST_FUN_OBJ_1(synthio_note_get_vibrato_depth_obj, synthio_note_get_vibrato_depth);
194+
MP_DEFINE_CONST_FUN_OBJ_1(synthio_note_get_bend_depth_obj, synthio_note_get_bend_depth);
173195

174-
STATIC mp_obj_t synthio_note_set_vibrato_depth(mp_obj_t self_in, mp_obj_t arg) {
196+
STATIC mp_obj_t synthio_note_set_bend_depth(mp_obj_t self_in, mp_obj_t arg) {
175197
synthio_note_obj_t *self = MP_OBJ_TO_PTR(self_in);
176-
common_hal_synthio_note_set_vibrato_depth(self, mp_obj_get_float(arg));
198+
common_hal_synthio_note_set_bend_depth(self, mp_obj_get_float(arg));
177199
return mp_const_none;
178200
}
179-
MP_DEFINE_CONST_FUN_OBJ_2(synthio_note_set_vibrato_depth_obj, synthio_note_set_vibrato_depth);
180-
MP_PROPERTY_GETSET(synthio_note_vibrato_depth_obj,
181-
(mp_obj_t)&synthio_note_get_vibrato_depth_obj,
182-
(mp_obj_t)&synthio_note_set_vibrato_depth_obj);
201+
MP_DEFINE_CONST_FUN_OBJ_2(synthio_note_set_bend_depth_obj, synthio_note_set_bend_depth);
202+
MP_PROPERTY_GETSET(synthio_note_bend_depth_obj,
203+
(mp_obj_t)&synthio_note_get_bend_depth_obj,
204+
(mp_obj_t)&synthio_note_set_bend_depth_obj);
183205

184-
//| vibrato_rate: float
185-
//| """The vibrato rate of the note, in Hz."""
186-
STATIC mp_obj_t synthio_note_get_vibrato_rate(mp_obj_t self_in) {
206+
//| bend_rate: float
207+
//| """The bend rate of the note, in Hz."""
208+
STATIC mp_obj_t synthio_note_get_bend_rate(mp_obj_t self_in) {
187209
synthio_note_obj_t *self = MP_OBJ_TO_PTR(self_in);
188-
return mp_obj_new_float(common_hal_synthio_note_get_vibrato_rate(self));
210+
return mp_obj_new_float(common_hal_synthio_note_get_bend_rate(self));
189211
}
190-
MP_DEFINE_CONST_FUN_OBJ_1(synthio_note_get_vibrato_rate_obj, synthio_note_get_vibrato_rate);
212+
MP_DEFINE_CONST_FUN_OBJ_1(synthio_note_get_bend_rate_obj, synthio_note_get_bend_rate);
191213

192-
STATIC mp_obj_t synthio_note_set_vibrato_rate(mp_obj_t self_in, mp_obj_t arg) {
214+
STATIC mp_obj_t synthio_note_set_bend_rate(mp_obj_t self_in, mp_obj_t arg) {
193215
synthio_note_obj_t *self = MP_OBJ_TO_PTR(self_in);
194-
common_hal_synthio_note_set_vibrato_rate(self, mp_obj_get_float(arg));
216+
common_hal_synthio_note_set_bend_rate(self, mp_obj_get_float(arg));
195217
return mp_const_none;
196218
}
197-
MP_DEFINE_CONST_FUN_OBJ_2(synthio_note_set_vibrato_rate_obj, synthio_note_set_vibrato_rate);
198-
MP_PROPERTY_GETSET(synthio_note_vibrato_rate_obj,
199-
(mp_obj_t)&synthio_note_get_vibrato_rate_obj,
200-
(mp_obj_t)&synthio_note_set_vibrato_rate_obj);
219+
MP_DEFINE_CONST_FUN_OBJ_2(synthio_note_set_bend_rate_obj, synthio_note_set_bend_rate);
220+
MP_PROPERTY_GETSET(synthio_note_bend_rate_obj,
221+
(mp_obj_t)&synthio_note_get_bend_rate_obj,
222+
(mp_obj_t)&synthio_note_set_bend_rate_obj);
201223

202224
//| waveform: Optional[ReadableBuffer]
203225
//| """The waveform of this note. Setting the waveform to a buffer of a different size resets the note's phase."""
@@ -249,8 +271,9 @@ STATIC const mp_rom_map_elem_t synthio_note_locals_dict_table[] = {
249271
{ MP_ROM_QSTR(MP_QSTR_envelope), MP_ROM_PTR(&synthio_note_envelope_obj) },
250272
{ MP_ROM_QSTR(MP_QSTR_tremolo_depth), MP_ROM_PTR(&synthio_note_tremolo_depth_obj) },
251273
{ MP_ROM_QSTR(MP_QSTR_tremolo_rate), MP_ROM_PTR(&synthio_note_tremolo_rate_obj) },
252-
{ MP_ROM_QSTR(MP_QSTR_vibrato_depth), MP_ROM_PTR(&synthio_note_vibrato_depth_obj) },
253-
{ MP_ROM_QSTR(MP_QSTR_vibrato_rate), MP_ROM_PTR(&synthio_note_vibrato_rate_obj) },
274+
{ MP_ROM_QSTR(MP_QSTR_bend_depth), MP_ROM_PTR(&synthio_note_bend_depth_obj) },
275+
{ MP_ROM_QSTR(MP_QSTR_bend_rate), MP_ROM_PTR(&synthio_note_bend_rate_obj) },
276+
{ MP_ROM_QSTR(MP_QSTR_bend_mode), MP_ROM_PTR(&synthio_note_bend_mode_obj) },
254277
};
255278
STATIC MP_DEFINE_CONST_DICT(synthio_note_locals_dict, synthio_note_locals_dict_table);
256279

shared-bindings/synthio/Note.h

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44

55
typedef struct synthio_note_obj synthio_note_obj_t;
66
extern const mp_obj_type_t synthio_note_type;
7+
typedef enum synthio_bend_mode_e synthio_bend_mode_t;
78

89
mp_float_t common_hal_synthio_note_get_frequency(synthio_note_obj_t *self);
910
void common_hal_synthio_note_set_frequency(synthio_note_obj_t *self, mp_float_t value);
@@ -17,11 +18,14 @@ void common_hal_synthio_note_set_tremolo_rate(synthio_note_obj_t *self, mp_float
1718
mp_float_t common_hal_synthio_note_get_tremolo_depth(synthio_note_obj_t *self);
1819
void common_hal_synthio_note_set_tremolo_depth(synthio_note_obj_t *self, mp_float_t value);
1920

20-
mp_float_t common_hal_synthio_note_get_vibrato_rate(synthio_note_obj_t *self);
21-
void common_hal_synthio_note_set_vibrato_rate(synthio_note_obj_t *self, mp_float_t value);
21+
synthio_bend_mode_t common_hal_synthio_note_get_bend_mode(synthio_note_obj_t *self);
22+
void common_hal_synthio_note_set_bend_mode(synthio_note_obj_t *self, synthio_bend_mode_t value);
2223

23-
mp_float_t common_hal_synthio_note_get_vibrato_depth(synthio_note_obj_t *self);
24-
void common_hal_synthio_note_set_vibrato_depth(synthio_note_obj_t *self, mp_float_t value);
24+
mp_float_t common_hal_synthio_note_get_bend_rate(synthio_note_obj_t *self);
25+
void common_hal_synthio_note_set_bend_rate(synthio_note_obj_t *self, mp_float_t value);
26+
27+
mp_float_t common_hal_synthio_note_get_bend_depth(synthio_note_obj_t *self);
28+
void common_hal_synthio_note_set_bend_depth(synthio_note_obj_t *self, mp_float_t value);
2529

2630
mp_obj_t common_hal_synthio_note_get_waveform_obj(synthio_note_obj_t *self);
2731
void common_hal_synthio_note_set_waveform(synthio_note_obj_t *self, mp_obj_t value);

shared-bindings/synthio/__init__.c

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -287,7 +287,7 @@ STATIC mp_obj_t onevo_to_hz(mp_obj_t arg) {
287287
MP_DEFINE_CONST_FUN_OBJ_1(synthio_onevo_to_hz_obj, onevo_to_hz);
288288

289289
MAKE_ENUM_VALUE(synthio_bend_mode_type, bend_mode, STATIC, SYNTHIO_BEND_MODE_STATIC);
290-
MAKE_ENUM_VALUE(synthio_bend_mode_type, bend_mode, TREMOLO, SYNTHIO_BEND_MODE_TREMOLO);
290+
MAKE_ENUM_VALUE(synthio_bend_mode_type, bend_mode, VIBRATO, SYNTHIO_BEND_MODE_VIBRATO);
291291
MAKE_ENUM_VALUE(synthio_bend_mode_type, bend_mode, SWEEP, SYNTHIO_BEND_MODE_SWEEP);
292292

293293
//|
@@ -297,15 +297,15 @@ MAKE_ENUM_VALUE(synthio_bend_mode_type, bend_mode, SWEEP, SYNTHIO_BEND_MODE_SWEE
297297
//| STATIC: object
298298
//| """The Note's pitch is modified by its ``pitch_bend_depth``. ``pitch_bend_rate`` is ignored."""
299299
//|
300-
//| TREMOLO: object
300+
//| VIBRATO: object
301301
//| """The Note's pitch varies by ``±pitch_bend_depth` at a rate of ``pitch_bend_rate``Hz."""
302302
//|
303303
//| SWEEP: object
304304
//| """The Note's pitch starts at ``Note.frequency`` then sweeps up or down by ``pitch_bend_depth`` over ``1/pitch_bend_rate`` seconds."""
305305
//|
306306
MAKE_ENUM_MAP(synthio_bend_mode) {
307307
MAKE_ENUM_MAP_ENTRY(bend_mode, STATIC),
308-
MAKE_ENUM_MAP_ENTRY(bend_mode, TREMOLO),
308+
MAKE_ENUM_MAP_ENTRY(bend_mode, VIBRATO),
309309
MAKE_ENUM_MAP_ENTRY(bend_mode, SWEEP),
310310
};
311311

shared-bindings/synthio/__init__.h

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -27,11 +27,13 @@
2727
#pragma once
2828

2929
#include "py/objnamedtuple.h"
30+
#include "py/enum.h"
3031

31-
typedef enum {
32-
SYNTHIO_BEND_MODE_STATIC, SYNTHIO_BEND_MODE_TREMOLO, SYNTHIO_BEND_MODE_SWEEP
32+
typedef enum synthio_bend_mode_e {
33+
SYNTHIO_BEND_MODE_STATIC, SYNTHIO_BEND_MODE_VIBRATO, SYNTHIO_BEND_MODE_SWEEP
3334
} synthio_bend_mode_t;
3435

36+
extern const cp_enum_obj_t bend_mode_VIBRATO_obj;
3537
extern const mp_obj_type_t synthio_bend_mode_type;
3638
typedef struct synthio_synth synthio_synth_t;
3739
extern int16_t shared_bindings_synthio_square_wave[];

shared-module/synthio/Note.c

Lines changed: 38 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -76,25 +76,34 @@ void common_hal_synthio_note_set_tremolo_rate(synthio_note_obj_t *self, mp_float
7676
}
7777
}
7878

79-
mp_float_t common_hal_synthio_note_get_vibrato_depth(synthio_note_obj_t *self) {
80-
return self->vibrato_descr.amplitude;
79+
mp_float_t common_hal_synthio_note_get_bend_depth(synthio_note_obj_t *self) {
80+
return self->bend_descr.amplitude;
8181
}
8282

83-
void common_hal_synthio_note_set_vibrato_depth(synthio_note_obj_t *self, mp_float_t value_in) {
84-
mp_float_t val = mp_arg_validate_float_range(value_in, 0, 1, MP_QSTR_vibrato_depth);
85-
self->vibrato_descr.amplitude = val;
86-
self->vibrato_state.amplitude_scaled = round_float_to_int(val * 32767);
83+
void common_hal_synthio_note_set_bend_depth(synthio_note_obj_t *self, mp_float_t value_in) {
84+
mp_float_t val = mp_arg_validate_float_range(value_in, -1, 1, MP_QSTR_bend_depth);
85+
self->bend_descr.amplitude = val;
86+
self->bend_state.amplitude_scaled = round_float_to_int(val * 32767);
8787
}
8888

89-
mp_float_t common_hal_synthio_note_get_vibrato_rate(synthio_note_obj_t *self) {
90-
return self->vibrato_descr.frequency;
89+
mp_float_t common_hal_synthio_note_get_bend_rate(synthio_note_obj_t *self) {
90+
return self->bend_descr.frequency;
9191
}
9292

93-
void common_hal_synthio_note_set_vibrato_rate(synthio_note_obj_t *self, mp_float_t value_in) {
94-
mp_float_t val = mp_arg_validate_float_range(value_in, 0, 60, MP_QSTR_vibrato_rate);
95-
self->vibrato_descr.frequency = val;
93+
synthio_bend_mode_t common_hal_synthio_note_get_bend_mode(synthio_note_obj_t *self) {
94+
return self->bend_mode;
95+
}
96+
97+
void common_hal_synthio_note_set_bend_mode(synthio_note_obj_t *self, synthio_bend_mode_t value) {
98+
self->bend_mode = value;
99+
}
100+
101+
102+
void common_hal_synthio_note_set_bend_rate(synthio_note_obj_t *self, mp_float_t value_in) {
103+
mp_float_t val = mp_arg_validate_float_range(value_in, 0, 60, MP_QSTR_bend_rate);
104+
self->bend_descr.frequency = val;
96105
if (self->sample_rate != 0) {
97-
self->vibrato_state.dds = synthio_frequency_convert_float_to_dds(val, self->sample_rate);
106+
self->bend_state.dds = synthio_frequency_convert_float_to_dds(val, self->sample_rate);
98107
}
99108
}
100109

@@ -139,8 +148,8 @@ void synthio_note_recalculate(synthio_note_obj_t *self, int32_t sample_rate) {
139148

140149
synthio_lfo_set(&self->tremolo_state, &self->tremolo_descr, sample_rate);
141150
self->tremolo_state.offset_scaled = 32768 - self->tremolo_state.amplitude_scaled;
142-
synthio_lfo_set(&self->vibrato_state, &self->vibrato_descr, sample_rate);
143-
self->vibrato_state.offset_scaled = 32768;
151+
synthio_lfo_set(&self->bend_state, &self->bend_descr, sample_rate);
152+
self->bend_state.offset_scaled = 32768;
144153
}
145154

146155
void synthio_note_start(synthio_note_obj_t *self, int32_t sample_rate) {
@@ -176,10 +185,23 @@ STATIC uint32_t pitch_bend(uint32_t frequency_scaled, uint16_t bend_value) {
176185
return (frequency_scaled * (uint64_t)f) >> (15 + down);
177186
}
178187

188+
STATIC int synthio_bend_value(synthio_note_obj_t *self, int16_t dur) {
189+
switch (self->bend_mode) {
190+
case SYNTHIO_BEND_MODE_STATIC:
191+
return self->bend_state.amplitude_scaled + self->bend_state.offset_scaled;
192+
case SYNTHIO_BEND_MODE_VIBRATO:
193+
return synthio_lfo_step(&self->bend_state, dur);
194+
case SYNTHIO_BEND_MODE_SWEEP:
195+
return synthio_sweep_step(&self->bend_state, dur);
196+
default:
197+
return 32768;
198+
}
199+
}
200+
179201
uint32_t synthio_note_step(synthio_note_obj_t *self, int32_t sample_rate, int16_t dur, uint16_t *loudness) {
180202
int tremolo_value = synthio_lfo_step(&self->tremolo_state, dur);
181-
int vibrato_value = synthio_lfo_step(&self->vibrato_state, dur);
182203
*loudness = (*loudness * tremolo_value) >> 15;
183-
uint32_t frequency_scaled = pitch_bend(self->frequency_scaled, vibrato_value);
204+
int bend_value = synthio_bend_value(self, dur);
205+
uint32_t frequency_scaled = pitch_bend(self->frequency_scaled, bend_value);
184206
return frequency_scaled;
185207
}

shared-module/synthio/Note.h

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,7 @@
2727
#pragma once
2828

2929
#include "shared-module/synthio/__init__.h"
30+
#include "shared-bindings/synthio/__init__.h"
3031

3132
typedef struct synthio_note_obj {
3233
mp_obj_base_t base;
@@ -39,8 +40,9 @@ typedef struct synthio_note_obj {
3940

4041
int32_t frequency_scaled;
4142
int32_t amplitude_scaled;
42-
synthio_lfo_descr_t tremolo_descr, vibrato_descr;
43-
synthio_lfo_state_t tremolo_state, vibrato_state;
43+
synthio_bend_mode_t bend_mode;
44+
synthio_lfo_descr_t tremolo_descr, bend_descr;
45+
synthio_lfo_state_t tremolo_state, bend_state;
4446

4547
mp_buffer_info_t waveform_buf;
4648
synthio_envelope_definition_t envelope_def;

shared-module/synthio/__init__.c

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -402,6 +402,18 @@ void synthio_lfo_set(synthio_lfo_state_t *state, const synthio_lfo_descr_t *desc
402402
state->dds = synthio_frequency_convert_float_to_dds(descr->frequency * 65536, sample_rate);
403403
}
404404

405+
int synthio_sweep_step(synthio_lfo_state_t *state, uint16_t dur) {
406+
uint32_t phase = state->phase;
407+
uint16_t whole_phase = phase >> 16;
408+
409+
// advance the phase accumulator
410+
state->phase = phase + state->dds * dur;
411+
if (state->phase < phase) {
412+
state->phase = 0xffffffff;
413+
}
414+
return (state->amplitude_scaled * whole_phase) / 65536 + state->offset_scaled;
415+
}
416+
405417
int synthio_lfo_step(synthio_lfo_state_t *state, uint16_t dur) {
406418
uint32_t phase = state->phase;
407419
uint16_t whole_phase = phase >> 16;

shared-module/synthio/__init__.h

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -81,7 +81,8 @@ typedef struct {
8181
} synthio_lfo_descr_t;
8282

8383
typedef struct {
84-
uint32_t amplitude_scaled, offset_scaled, dds, phase;
84+
int32_t amplitude_scaled;
85+
uint32_t offset_scaled, dds, phase;
8586
} synthio_lfo_state_t;
8687

8788

@@ -107,3 +108,4 @@ uint32_t synthio_frequency_convert_scaled_to_dds(uint64_t frequency_scaled, int3
107108

108109
void synthio_lfo_set(synthio_lfo_state_t *state, const synthio_lfo_descr_t *descr, uint32_t sample_rate);
109110
int synthio_lfo_step(synthio_lfo_state_t *state, uint16_t dur);
111+
int synthio_sweep_step(synthio_lfo_state_t *state, uint16_t dur);

0 commit comments

Comments
 (0)