diff options
author | Chris Robinson <[email protected]> | 2017-12-24 19:13:48 -0800 |
---|---|---|
committer | Chris Robinson <[email protected]> | 2017-12-24 20:40:33 -0800 |
commit | dabb99de8d9130d543728fe022c7f2f8d4f83118 (patch) | |
tree | c55e3d29e7c724c599719d0805ae2e52e25d2f07 /Alc/effects/chorus.c | |
parent | 254ebe5f9649bf338a6f584c0924d54e4f413bff (diff) |
Don't offset the chorus/flanger delay and LFO
The delay being added to the scaled LFO will ensure a proper positive result
regardless.
Diffstat (limited to 'Alc/effects/chorus.c')
-rw-r--r-- | Alc/effects/chorus.c | 29 |
1 files changed, 11 insertions, 18 deletions
diff --git a/Alc/effects/chorus.c b/Alc/effects/chorus.c index 850108cf..b4b4ac5a 100644 --- a/Alc/effects/chorus.c +++ b/Alc/effects/chorus.c @@ -119,7 +119,6 @@ static ALvoid ALchorusState_update(ALchorusState *state, const ALCcontext *Conte const ALCdevice *device = Context->Device; ALfloat frequency = (ALfloat)device->Frequency; ALfloat coeffs[MAX_AMBI_COEFFS]; - ALfloat delay; ALfloat rate; ALint phase; @@ -134,13 +133,8 @@ static ALvoid ALchorusState_update(ALchorusState *state, const ALCcontext *Conte } /* The LFO depth is scaled to be relative to the sample delay. */ - delay = props->Chorus.Delay*frequency * FRACTIONONE; - state->depth = props->Chorus.Depth * delay; - - /* Offset the delay so that the center point remains the same with the LFO - * ranging from 0...2 instead of -1...+1. - */ - state->delay = fastf2i(delay-state->depth + 0.5f); + state->delay = fastf2i(props->Chorus.Delay*frequency*FRACTIONONE + 0.5f); + state->depth = props->Chorus.Depth * state->delay; state->feedback = props->Chorus.Feedback; @@ -192,7 +186,7 @@ static void GetTriangleDelays(ALint *restrict delays, ALsizei offset, const ALsi ALsizei i; for(i = 0;i < todo;i++) { - delays[i] = fastf2i((2.0f - fabsf(2.0f - lfo_scale*offset)) * depth) + delay; + delays[i] = fastf2i((1.0f - fabsf(2.0f - lfo_scale*offset)) * depth) + delay; offset = (offset+1)%lfo_range; } } @@ -204,7 +198,7 @@ static void GetSinusoidDelays(ALint *restrict delays, ALsizei offset, const ALsi ALsizei i; for(i = 0;i < todo;i++) { - delays[i] = fastf2i((sinf(lfo_scale*offset)+1.0f) * depth) + delay; + delays[i] = fastf2i(sinf(lfo_scale*offset) * depth) + delay; offset = (offset+1)%lfo_range; } } @@ -214,8 +208,7 @@ static ALvoid ALchorusState_process(ALchorusState *state, ALsizei SamplesToDo, c { const ALsizei bufmask = state->BufferLength-1; const ALfloat feedback = state->feedback; - const ALsizei avgdelay = (state->delay+fastf2i(state->depth) + (FRACTIONONE>>1)) >> - FRACTIONBITS; + const ALsizei avgdelay = (state->delay + (FRACTIONONE>>1)) >> FRACTIONBITS; ALfloat *restrict delaybuf = state->SampleBuffer; ALsizei offset = state->offset; ALsizei i, c; @@ -254,16 +247,16 @@ static ALvoid ALchorusState_process(ALchorusState *state, ALsizei SamplesToDo, c delaybuf[offset&bufmask] = SamplesIn[0][base+i]; // Tap for the left output. - delay = moddelays[0][i] >> FRACTIONBITS; + delay = offset - (moddelays[0][i]>>FRACTIONBITS); mu = (moddelays[0][i]&FRACTIONMASK) * (1.0f/FRACTIONONE); - temps[0][i] = delaybuf[(offset-delay) & bufmask]*(1.0f-mu) + - delaybuf[(offset-(delay+1)) & bufmask]*mu; + temps[0][i] = delaybuf[(delay ) & bufmask]*(1.0f-mu) + + delaybuf[(delay-1) & bufmask]*( mu); // Tap for the right output. - delay = moddelays[1][i] >> FRACTIONBITS; + delay = offset - (moddelays[1][i]>>FRACTIONBITS); mu = (moddelays[1][i]&FRACTIONMASK) * (1.0f/FRACTIONONE); - temps[1][i] = delaybuf[(offset-delay) & bufmask]*(1.0f-mu) + - delaybuf[(offset-(delay+1)) & bufmask]*mu; + temps[1][i] = delaybuf[(delay ) & bufmask]*(1.0f-mu) + + delaybuf[(delay-1) & bufmask]*( mu); // Accumulate feedback from the average delay of the taps. delaybuf[offset&bufmask] += delaybuf[(offset-avgdelay) & bufmask] * feedback; |