synthio: Finish ading SWEEP_IN

This commit is contained in:
Jeff Epler 2023-05-11 16:53:40 -05:00
parent 17df238145
commit 53e13f15a3
No known key found for this signature in database
GPG Key ID: D5BF15AB975AB4DE
4 changed files with 22 additions and 9 deletions

View File

@ -30,7 +30,7 @@
#include "py/enum.h"
typedef enum synthio_bend_mode_e {
SYNTHIO_BEND_MODE_STATIC, SYNTHIO_BEND_MODE_VIBRATO, SYNTHIO_BEND_MODE_SWEEP
SYNTHIO_BEND_MODE_STATIC, SYNTHIO_BEND_MODE_VIBRATO, SYNTHIO_BEND_MODE_SWEEP, SYNTHIO_BEND_MODE_SWEEP_IN
} synthio_bend_mode_t;
extern const cp_enum_obj_t bend_mode_VIBRATO_obj;

View File

@ -224,6 +224,8 @@ STATIC int synthio_bend_value(synthio_note_obj_t *self, int16_t dur) {
return synthio_lfo_step(&self->bend_state, dur);
case SYNTHIO_BEND_MODE_SWEEP:
return synthio_sweep_step(&self->bend_state, dur);
case SYNTHIO_BEND_MODE_SWEEP_IN:
return synthio_sweep_in_step(&self->bend_state, dur);
default:
return 32768;
}

View File

@ -480,25 +480,35 @@ void synthio_lfo_set(synthio_lfo_state_t *state, const synthio_lfo_descr_t *desc
state->dds = synthio_frequency_convert_float_to_dds(descr->frequency * 65536, sample_rate);
}
int synthio_sweep_step(synthio_lfo_state_t *state, uint16_t dur) {
STATIC int synthio_lfo_step_common(synthio_lfo_state_t *state, uint16_t dur) {
uint32_t phase = state->phase;
uint16_t whole_phase = phase >> 16;
// advance the phase accumulator
state->phase = phase + state->dds * dur;
if (state->phase < phase) {
return whole_phase;
}
STATIC int synthio_lfo_sweep_common(synthio_lfo_state_t *state, uint16_t dur) {
uint16_t whole_phase = synthio_lfo_step_common(state, dur);
if (state->phase < state->dds) {
state->phase = 0xffffffff;
}
return whole_phase;
}
int synthio_sweep_step(synthio_lfo_state_t *state, uint16_t dur) {
uint16_t whole_phase = synthio_lfo_sweep_common(state, dur);
return (state->amplitude_scaled * whole_phase) / 65536 + state->offset_scaled;
}
int synthio_sweep_in_step(synthio_lfo_state_t *state, uint16_t dur) {
uint16_t whole_phase = 65535 - synthio_lfo_sweep_common(state, dur);
return (state->amplitude_scaled * whole_phase) / 65536 + state->offset_scaled;
}
int synthio_lfo_step(synthio_lfo_state_t *state, uint16_t dur) {
uint32_t phase = state->phase;
uint16_t whole_phase = phase >> 16;
// advance the phase accumulator
state->phase = phase + state->dds * dur;
uint16_t whole_phase = synthio_lfo_step_common(state, dur);
// create a triangle wave, it's quick and easy
int v;
if (whole_phase < 16384) { // ramp from 0 to amplitude

View File

@ -111,3 +111,4 @@ uint32_t synthio_frequency_convert_scaled_to_dds(uint64_t frequency_scaled, int3
void synthio_lfo_set(synthio_lfo_state_t *state, const synthio_lfo_descr_t *descr, uint32_t sample_rate);
int synthio_lfo_step(synthio_lfo_state_t *state, uint16_t dur);
int synthio_sweep_step(synthio_lfo_state_t *state, uint16_t dur);
int synthio_sweep_in_step(synthio_lfo_state_t *state, uint16_t dur);