Skip to content

Commit 53e13f1

Browse files
committed
synthio: Finish ading SWEEP_IN
1 parent 17df238 commit 53e13f1

File tree

4 files changed

+22
-9
lines changed

4 files changed

+22
-9
lines changed

shared-bindings/synthio/__init__.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@
3030
#include "py/enum.h"
3131

3232
typedef enum synthio_bend_mode_e {
33-
SYNTHIO_BEND_MODE_STATIC, SYNTHIO_BEND_MODE_VIBRATO, SYNTHIO_BEND_MODE_SWEEP
33+
SYNTHIO_BEND_MODE_STATIC, SYNTHIO_BEND_MODE_VIBRATO, SYNTHIO_BEND_MODE_SWEEP, SYNTHIO_BEND_MODE_SWEEP_IN
3434
} synthio_bend_mode_t;
3535

3636
extern const cp_enum_obj_t bend_mode_VIBRATO_obj;

shared-module/synthio/Note.c

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -224,6 +224,8 @@ STATIC int synthio_bend_value(synthio_note_obj_t *self, int16_t dur) {
224224
return synthio_lfo_step(&self->bend_state, dur);
225225
case SYNTHIO_BEND_MODE_SWEEP:
226226
return synthio_sweep_step(&self->bend_state, dur);
227+
case SYNTHIO_BEND_MODE_SWEEP_IN:
228+
return synthio_sweep_in_step(&self->bend_state, dur);
227229
default:
228230
return 32768;
229231
}

shared-module/synthio/__init__.c

Lines changed: 18 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -480,25 +480,35 @@ void synthio_lfo_set(synthio_lfo_state_t *state, const synthio_lfo_descr_t *desc
480480
state->dds = synthio_frequency_convert_float_to_dds(descr->frequency * 65536, sample_rate);
481481
}
482482

483-
int synthio_sweep_step(synthio_lfo_state_t *state, uint16_t dur) {
483+
STATIC int synthio_lfo_step_common(synthio_lfo_state_t *state, uint16_t dur) {
484484
uint32_t phase = state->phase;
485485
uint16_t whole_phase = phase >> 16;
486486

487487
// advance the phase accumulator
488488
state->phase = phase + state->dds * dur;
489-
if (state->phase < phase) {
489+
490+
return whole_phase;
491+
}
492+
STATIC int synthio_lfo_sweep_common(synthio_lfo_state_t *state, uint16_t dur) {
493+
uint16_t whole_phase = synthio_lfo_step_common(state, dur);
494+
if (state->phase < state->dds) {
490495
state->phase = 0xffffffff;
491496
}
492-
return (state->amplitude_scaled * whole_phase) / 65536 + state->offset_scaled;
497+
return whole_phase;
493498
}
494499

495-
int synthio_lfo_step(synthio_lfo_state_t *state, uint16_t dur) {
496-
uint32_t phase = state->phase;
497-
uint16_t whole_phase = phase >> 16;
500+
int synthio_sweep_step(synthio_lfo_state_t *state, uint16_t dur) {
501+
uint16_t whole_phase = synthio_lfo_sweep_common(state, dur);
502+
return (state->amplitude_scaled * whole_phase) / 65536 + state->offset_scaled;
503+
}
498504

499-
// advance the phase accumulator
500-
state->phase = phase + state->dds * dur;
505+
int synthio_sweep_in_step(synthio_lfo_state_t *state, uint16_t dur) {
506+
uint16_t whole_phase = 65535 - synthio_lfo_sweep_common(state, dur);
507+
return (state->amplitude_scaled * whole_phase) / 65536 + state->offset_scaled;
508+
}
501509

510+
int synthio_lfo_step(synthio_lfo_state_t *state, uint16_t dur) {
511+
uint16_t whole_phase = synthio_lfo_step_common(state, dur);
502512
// create a triangle wave, it's quick and easy
503513
int v;
504514
if (whole_phase < 16384) { // ramp from 0 to amplitude

shared-module/synthio/__init__.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -111,3 +111,4 @@ uint32_t synthio_frequency_convert_scaled_to_dds(uint64_t frequency_scaled, int3
111111
void synthio_lfo_set(synthio_lfo_state_t *state, const synthio_lfo_descr_t *descr, uint32_t sample_rate);
112112
int synthio_lfo_step(synthio_lfo_state_t *state, uint16_t dur);
113113
int synthio_sweep_step(synthio_lfo_state_t *state, uint16_t dur);
114+
int synthio_sweep_in_step(synthio_lfo_state_t *state, uint16_t dur);

0 commit comments

Comments
 (0)