diff --git a/Source/synth/lfo.c b/Source/synth/lfo.c index f73aa4e..d0e60e1 100644 --- a/Source/synth/lfo.c +++ b/Source/synth/lfo.c @@ -129,7 +129,6 @@ void LFO_Init(lfo_t *pObj, synth_float_t fs) pObj->out = 0; pObj->sqr = 0; pObj->tri = 0; - pObj->gain = 1; pObj->offset = 0.5; LFO_Reset(pObj, 0); @@ -173,7 +172,6 @@ void LFO_SetFS(lfo_t *pObj, synth_float_t fs) void LFO_Reset(lfo_t *pObj, synth_float_t initial_phase) { - pObj->a = 0.5; pObj->out = 0; pObj->sqr = 0; pObj->tri = 0; @@ -222,8 +220,7 @@ void LFO_Param2Set(lfo_t *pObj, UINT32 type, synth_float_t value) case LFO_PARAM2_SYMMETRY: pObj->param[type] = value; - pObj->gain = 1; - pObj->offset = 0.5 *(1 + value) - 1; + pObj->offset = 0.5 *value; break; default: @@ -268,8 +265,9 @@ synth_float_t* LFO_ProcessDataV(lfo_t *pObj, UINT32 len) for (i=i0; i< len; i++) { sync_result_t sync_result = Sync_process(&pObj->sync, pObj->omega); + synth_float_t y = 2*sync_result.phase - 1.0; - in = sync_result.phase + pObj->offset; + in = 0.5*y + pObj->offset; pObj->out = pObj->smooth_a*pObj->out + pObj->smooth_b*in; out = pObj->out; if (pObj->smooth_is_negative) @@ -292,8 +290,9 @@ synth_float_t* LFO_ProcessDataV(lfo_t *pObj, UINT32 len) for (i=i0; i< len; i++) { sync_result_t sync_result = Sync_process(&pObj->sync, pObj->omega); - - in = (1-sync_result.phase) + pObj->offset; + synth_float_t y = 2*sync_result.phase - 1.0; + + in = -0.5*y + pObj->offset; pObj->out = pObj->smooth_a*pObj->out + pObj->smooth_b*in; out = pObj->out; if (pObj->smooth_is_negative) @@ -377,7 +376,7 @@ synth_float_t* LFO_ProcessDataV(lfo_t *pObj, UINT32 len) sync_result_t sync_result = Sync_process(&pObj->sync, pObj->omega); synth_float_t y = sin(2*M_PI*sync_result.phase); - in = y + pObj->a + pObj->offset; + in = 0.5*y + pObj->offset; pObj->out = pObj->smooth_a*pObj->out + pObj->smooth_b*in; out = pObj->out; if (pObj->smooth_is_negative) @@ -401,7 +400,7 @@ synth_float_t* LFO_ProcessDataV(lfo_t *pObj, UINT32 len) sync_result_t sync_result = Sync_process(&pObj->sync, pObj->omega); synth_float_t y = sin(2*M_PI*sync_result.phase); - in = (1-(y+pObj->a)) + pObj->offset; + in = -0.5*y + pObj->offset; pObj->out = pObj->smooth_a*pObj->out + pObj->smooth_b*in; out = pObj->out; if (pObj->smooth_is_negative) @@ -425,7 +424,7 @@ synth_float_t* LFO_ProcessDataV(lfo_t *pObj, UINT32 len) sync_result_t sync_result = Sync_process(&pObj->sync, pObj->omega); synth_float_t y = cos(2*M_PI*sync_result.phase); - in = y+pObj->a + pObj->offset; + in = 0.5*y + pObj->offset; pObj->out = pObj->smooth_a*pObj->out + pObj->smooth_b*in; out = pObj->out; if (pObj->smooth_is_negative) @@ -449,7 +448,7 @@ synth_float_t* LFO_ProcessDataV(lfo_t *pObj, UINT32 len) sync_result_t sync_result = Sync_process(&pObj->sync, pObj->omega); synth_float_t y = cos(2*M_PI*sync_result.phase); - in = (1-(y+pObj->a)) + pObj->offset; + in = -0.5*y + pObj->offset; pObj->out = pObj->smooth_a*pObj->out + pObj->smooth_b*in; out = pObj->out; if (pObj->smooth_is_negative) @@ -472,9 +471,9 @@ synth_float_t* LFO_ProcessDataV(lfo_t *pObj, UINT32 len) for (i=i0; i< len; i++) { sync_result_t sync_result = Sync_process(&pObj->sync, pObj->omega); - pObj->sqr = (int)(sync_result.phase < 0.5); + synth_float_t y = 2*(synth_float_t)(sync_result.phase < 0.5) - 1.0; - in = (synth_float_t)pObj->sqr + pObj->offset; + in = 0.5*y + pObj->offset; pObj->out = pObj->smooth_a*pObj->out + pObj->smooth_b*in; out = pObj->out; if (pObj->smooth_is_negative) @@ -497,9 +496,9 @@ synth_float_t* LFO_ProcessDataV(lfo_t *pObj, UINT32 len) for (i=i0; i< len; i++) { sync_result_t sync_result = Sync_process(&pObj->sync, pObj->omega); - pObj->sqr = (int)(sync_result.phase < 0.5); + synth_float_t y = 2*(synth_float_t)(sync_result.phase < 0.5) - 1.0; - in = (1-((synth_float_t)pObj->sqr)) + pObj->offset; + in = -0.5*y + pObj->offset; pObj->out = pObj->smooth_a*pObj->out + pObj->smooth_b*in; out = pObj->out; if (pObj->smooth_is_negative) @@ -522,12 +521,13 @@ synth_float_t* LFO_ProcessDataV(lfo_t *pObj, UINT32 len) for (i=i0; i< len; i++) { sync_result_t sync_result = Sync_process(&pObj->sync, pObj->omega); + synth_float_t y = 2*(1-sync_result.phase) - 1.0; if (sync_result.phase < 0.5) - pObj->tri = 2*sync_result.phase; - else - pObj->tri = 2*(1-sync_result.phase); - - in = (synth_float_t)pObj->tri + pObj->offset; + { + y = 2*sync_result.phase - 1.0; + } + + in = 0.5*y + pObj->offset; pObj->out = pObj->smooth_a*pObj->out + pObj->smooth_b*in; out = pObj->out; if (pObj->smooth_is_negative) @@ -550,12 +550,13 @@ synth_float_t* LFO_ProcessDataV(lfo_t *pObj, UINT32 len) for (i=i0; i< len; i++) { sync_result_t sync_result = Sync_process(&pObj->sync, pObj->omega); + synth_float_t y = 2*(1-sync_result.phase) - 0.5; if (sync_result.phase < 0.5) - pObj->tri = 2*sync_result.phase; - else - pObj->tri = 2*(1-sync_result.phase); - - in = (1-((synth_float_t)pObj->tri)) + pObj->offset; + { + y = 2*sync_result.phase - 0.5; + } + + in = -0.5*y + pObj->offset; pObj->out = pObj->smooth_a*pObj->out + pObj->smooth_b*in; out = pObj->out; if (pObj->smooth_is_negative) diff --git a/Source/synth/lfo.h b/Source/synth/lfo.h index 74d0430..c8359a5 100644 --- a/Source/synth/lfo.h +++ b/Source/synth/lfo.h @@ -83,7 +83,7 @@ typedef struct _slfo_t { synth_float_t param[LFO_NUM_PARAMS]; synth_float_t omega, fs; - synth_float_t a, b, out, sh_sample, tri; + synth_float_t out, sh_sample, tri; int freq_update_req, sqr; synth_float_t *pOut; UINT32 bufsize; @@ -91,7 +91,7 @@ typedef struct _slfo_t synth_float_t smooth_a, smooth_b; UINT32 smooth_is_negative; synth_float_t delay_x, delay_dx, attack_y, attack_a; - synth_float_t gain, offset; + synth_float_t offset; sync_t sync; } lfo_t;