Pre-scale the chorus and flanger delays to be in samples
This commit is contained in:
+12
-19
@@ -45,10 +45,9 @@ typedef struct ALchorusState {
|
||||
|
||||
/* effect parameters */
|
||||
ALint waveform;
|
||||
ALint delay;
|
||||
ALfloat depth;
|
||||
ALfloat feedback;
|
||||
ALfloat delay;
|
||||
ALfloat frequency;
|
||||
} ALchorusState;
|
||||
|
||||
static ALvoid ChorusDestroy(ALeffectState *effect)
|
||||
@@ -75,7 +74,7 @@ static ALboolean ChorusDeviceUpdate(ALeffectState *effect, ALCdevice *Device)
|
||||
maxlen = fastf2u(AL_CHORUS_MAX_DELAY * 3.0f * Device->Frequency) + 1;
|
||||
maxlen = NextPowerOf2(maxlen);
|
||||
|
||||
if (maxlen != state->BufferLength)
|
||||
if(maxlen != state->BufferLength)
|
||||
{
|
||||
void *temp;
|
||||
|
||||
@@ -90,20 +89,19 @@ static ALboolean ChorusDeviceUpdate(ALeffectState *effect, ALCdevice *Device)
|
||||
state->BufferLength = maxlen;
|
||||
}
|
||||
|
||||
for (it = 0; it < state->BufferLength; it++)
|
||||
for(it = 0;it < state->BufferLength;it++)
|
||||
{
|
||||
state->SampleBufferLeft[it] = 0.0f;
|
||||
state->SampleBufferRight[it] = 0.0f;
|
||||
}
|
||||
|
||||
state->frequency=(ALfloat)Device->Frequency;
|
||||
|
||||
return AL_TRUE;
|
||||
}
|
||||
|
||||
static ALvoid ChorusUpdate(ALeffectState *effect, ALCdevice *Device, const ALeffectslot *Slot)
|
||||
{
|
||||
ALchorusState *state = GET_PARENT_TYPE(ALchorusState, ALeffectState, effect);
|
||||
ALfloat frequency = Device->Frequency;
|
||||
ALfloat rate;
|
||||
ALint phase;
|
||||
ALuint it;
|
||||
@@ -117,8 +115,7 @@ static ALvoid ChorusUpdate(ALeffectState *effect, ALCdevice *Device, const ALeff
|
||||
state->waveform = Slot->effect.Chorus.Waveform;
|
||||
state->depth = Slot->effect.Chorus.Depth;
|
||||
state->feedback = Slot->effect.Chorus.Feedback;
|
||||
state->delay = Slot->effect.Chorus.Delay;
|
||||
state->frequency=(ALfloat)Device->Frequency;
|
||||
state->delay = fastf2i(Slot->effect.Chorus.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 ChorusUpdate(ALeffectState *effect, ALCdevice *Device, const ALeff
|
||||
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_CHORUS_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 ChorusUpdate(ALeffectState *effect, ALCdevice *Device, const ALeff
|
||||
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 ALchorusState *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 ALchorusState *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) \
|
||||
|
||||
+10
-17
@@ -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) \
|
||||
|
||||
Reference in New Issue
Block a user