From b6da74b6e2eb6ad72179e07bb7d50da4c2c95390 Mon Sep 17 00:00:00 2001 From: Chris Robinson Date: Tue, 21 May 2013 01:59:44 -0700 Subject: Pre-scale the chorus and flanger delays to be in samples --- Alc/alcFlanger.c | 27 ++++++++++----------------- 1 file changed, 10 insertions(+), 17 deletions(-) (limited to 'Alc/alcFlanger.c') diff --git a/Alc/alcFlanger.c b/Alc/alcFlanger.c index 91d98cac..7409a4c1 100644 --- a/Alc/alcFlanger.c +++ b/Alc/alcFlanger.c @@ -45,10 +45,9 @@ typedef struct ALflangerState { /* effect parameters */ ALint waveform; + ALint delay; ALfloat depth; ALfloat feedback; - ALfloat delay; - ALfloat frequency; } ALflangerState; static ALvoid FlangerDestroy(ALeffectState *effect) @@ -96,14 +95,13 @@ static ALboolean FlangerDeviceUpdate(ALeffectState *effect, ALCdevice *Device) state->SampleBufferRight[it] = 0.0f; } - state->frequency = (ALfloat)Device->Frequency; - return AL_TRUE; } static ALvoid FlangerUpdate(ALeffectState *effect, ALCdevice *Device, const ALeffectslot *Slot) { ALflangerState *state = GET_PARENT_TYPE(ALflangerState, ALeffectState, effect); + ALfloat frequency = Device->Frequency; ALfloat rate; ALint phase; ALuint it; @@ -117,8 +115,7 @@ static ALvoid FlangerUpdate(ALeffectState *effect, ALCdevice *Device, const ALef state->waveform = Slot->effect.Flanger.Waveform; state->depth = Slot->effect.Flanger.Depth; state->feedback = Slot->effect.Flanger.Feedback; - state->delay = Slot->effect.Flanger.Delay; - state->frequency = (ALfloat)Device->Frequency; + state->delay = fastf2i(Slot->effect.Flanger.Delay * frequency); /* Gains for left and right sides */ ComputeAngleGains(Device, atan2f(-1.0f, 0.0f), 0.0f, Slot->Gain, state->Gain[0]); @@ -134,13 +131,13 @@ static ALvoid FlangerUpdate(ALeffectState *effect, ALCdevice *Device, const ALef if(rate == 0.0f) state->lfo_coeff = 0.0f; else - state->lfo_coeff = 1.0f / (state->frequency / rate); + state->lfo_coeff = 1.0f / (frequency / rate); break; case AL_FLANGER_WAVEFORM_SINUSOID: if(rate == 0.0f) state->lfo_coeff = 0.0f; else - state->lfo_coeff = F_PI * 2.0f / (state->frequency / rate); + state->lfo_coeff = F_PI * 2.0f / (frequency / rate); break; } @@ -148,7 +145,7 @@ static ALvoid FlangerUpdate(ALeffectState *effect, ALCdevice *Device, const ALef if(phase == 0 || rate == 0.0f) state->lfo_disp = 0; else - state->lfo_disp = fastf2i(state->frequency / rate / (360.0f/phase)); + state->lfo_disp = fastf2i(frequency / rate / (360.0f/phase)); } static __inline void Triangle(ALint *delay_left, ALint *delay_right, ALint offset, const ALflangerState *state) @@ -157,15 +154,13 @@ static __inline void Triangle(ALint *delay_left, ALint *delay_right, ALint offse lfo_value = 2.0f - fabsf(2.0f - fmodf(state->lfo_coeff * offset * 4.0f, 4.0f)); lfo_value *= state->depth * state->delay; - lfo_value += state->delay; - *delay_left = fastf2i(lfo_value * state->frequency); + *delay_left = fastf2i(lfo_value) + state->delay; lfo_value = 2.0f - fabsf(2.0f - fmodf(state->lfo_coeff * (offset+state->lfo_disp) * 4.0f, 4.0f)); lfo_value *= state->depth * state->delay; - lfo_value += state->delay; - *delay_right = fastf2i(lfo_value * state->frequency); + *delay_right = fastf2i(lfo_value) + state->delay; } static __inline void Sinusoid(ALint *delay_left, ALint *delay_right, ALint offset, const ALflangerState *state) @@ -174,14 +169,12 @@ static __inline void Sinusoid(ALint *delay_left, ALint *delay_right, ALint offse lfo_value = 1.0f + sinf(fmodf(state->lfo_coeff * offset, 2.0f*F_PI)); lfo_value *= state->depth * state->delay; - lfo_value += state->delay; - *delay_left = fastf2i(lfo_value * state->frequency); + *delay_left = fastf2i(lfo_value) + state->delay; lfo_value = 1.0f + sinf(fmodf(state->lfo_coeff * (offset+state->lfo_disp), 2.0f*F_PI)); lfo_value *= state->depth * state->delay; - lfo_value += state->delay; - *delay_right = fastf2i(lfo_value * state->frequency); + *delay_right = fastf2i(lfo_value) + state->delay; } #define DECL_TEMPLATE(func) \ -- cgit v1.2.3