@@ -480,25 +480,35 @@ void synthio_lfo_set(synthio_lfo_state_t *state, const synthio_lfo_descr_t *desc
480
480
state -> dds = synthio_frequency_convert_float_to_dds (descr -> frequency * 65536 , sample_rate );
481
481
}
482
482
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 ) {
484
484
uint32_t phase = state -> phase ;
485
485
uint16_t whole_phase = phase >> 16 ;
486
486
487
487
// advance the phase accumulator
488
488
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 ) {
490
495
state -> phase = 0xffffffff ;
491
496
}
492
- return ( state -> amplitude_scaled * whole_phase ) / 65536 + state -> offset_scaled ;
497
+ return whole_phase ;
493
498
}
494
499
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
+ }
498
504
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
+ }
501
509
510
+ int synthio_lfo_step (synthio_lfo_state_t * state , uint16_t dur ) {
511
+ uint16_t whole_phase = synthio_lfo_step_common (state , dur );
502
512
// create a triangle wave, it's quick and easy
503
513
int v ;
504
514
if (whole_phase < 16384 ) { // ramp from 0 to amplitude
0 commit comments