aboutsummaryrefslogtreecommitdiffstats
path: root/Alc
diff options
context:
space:
mode:
authorChris Robinson <[email protected]>2013-05-21 01:38:43 -0700
committerChris Robinson <[email protected]>2013-05-21 01:38:43 -0700
commit7e9960f7f1bf54c1ac603c4871ce79f5d36b3b07 (patch)
tree6bf5c9e45857b94b678f5dcbb42f4782639367e0 /Alc
parentc6872d4d868dad5935f731b4aa7275f44b5f7597 (diff)
Avoid storing some chorus and flanger properties in the effect state
Diffstat (limited to 'Alc')
-rw-r--r--Alc/alcChorus.c52
-rw-r--r--Alc/alcFlanger.c32
2 files changed, 32 insertions, 52 deletions
diff --git a/Alc/alcChorus.c b/Alc/alcChorus.c
index 5b62c910..eb89dd8e 100644
--- a/Alc/alcChorus.c
+++ b/Alc/alcChorus.c
@@ -45,8 +45,6 @@ typedef struct ALchorusState {
/* effect parameters */
ALint waveform;
- ALint phase;
- ALfloat rate;
ALfloat depth;
ALfloat feedback;
ALfloat delay;
@@ -82,17 +80,11 @@ static ALboolean ChorusDeviceUpdate(ALeffectState *effect, ALCdevice *Device)
void *temp;
temp = realloc(state->SampleBufferLeft, maxlen * sizeof(ALfloat));
- if (!temp)
- {
- return AL_FALSE;
- }
+ if(!temp) return AL_FALSE;
state->SampleBufferLeft = temp;
temp = realloc(state->SampleBufferRight, maxlen * sizeof(ALfloat));
- if (!temp)
- {
- return AL_FALSE;
- }
+ if(!temp) return AL_FALSE;
state->SampleBufferRight = temp;
state->BufferLength = maxlen;
@@ -112,6 +104,8 @@ static ALboolean ChorusDeviceUpdate(ALeffectState *effect, ALCdevice *Device)
static ALvoid ChorusUpdate(ALeffectState *effect, ALCdevice *Device, const ALeffectslot *Slot)
{
ALchorusState *state = GET_PARENT_TYPE(ALchorusState, ALeffectState, effect);
+ ALfloat rate;
+ ALint phase;
ALuint it;
for (it = 0; it < MaxChannels; it++)
@@ -121,8 +115,6 @@ static ALvoid ChorusUpdate(ALeffectState *effect, ALCdevice *Device, const ALeff
}
state->waveform = Slot->effect.Chorus.Waveform;
- state->phase = Slot->effect.Chorus.Phase;
- state->rate = Slot->effect.Chorus.Rate;
state->depth = Slot->effect.Chorus.Depth;
state->feedback = Slot->effect.Chorus.Feedback;
state->delay = Slot->effect.Chorus.Delay;
@@ -132,41 +124,31 @@ static ALvoid ChorusUpdate(ALeffectState *effect, ALCdevice *Device, const ALeff
ComputeAngleGains(Device, atan2f(-1.0f, 0.0f), 0.0f, Slot->Gain, state->Gain[0]);
ComputeAngleGains(Device, atan2f(+1.0f, 0.0f), 0.0f, Slot->Gain, state->Gain[1]);
+ phase = Slot->effect.Chorus.Phase;
+ rate = Slot->effect.Chorus.Rate;
+
/* Calculate LFO coefficient */
switch (state->waveform)
{
case AL_CHORUS_WAVEFORM_TRIANGLE:
- if (state->rate == 0.0f)
- {
+ if(rate == 0.0f)
state->lfo_coeff = 0.0f;
- }
else
- {
- state->lfo_coeff = 1.0f / ((ALfloat)Device->Frequency / state->rate);
- }
+ state->lfo_coeff = 1.0f / (state->frequency / rate);
break;
case AL_CHORUS_WAVEFORM_SINUSOID:
- if (state->rate == 0.0f)
- {
+ if(rate == 0.0f)
state->lfo_coeff = 0.0f;
- }
else
- {
- state->lfo_coeff = F_PI * 2.0f / ((ALfloat)Device->Frequency / state->rate);
- }
+ state->lfo_coeff = F_PI*2.0f / (state->frequency / rate);
break;
}
/* Calculate lfo phase displacement */
- if ((state->phase == 0) || (state->rate == 0.0f))
- {
+ if(phase == 0 || rate == 0.0f)
state->lfo_disp = 0;
- }
else
- {
- state->lfo_disp = (ALint) ((ALfloat)Device->Frequency /
- state->rate / (360.0f / (ALfloat)state->phase));
- }
+ state->lfo_disp = fastf2i(state->frequency / rate / (360.0f/phase));
}
static __inline void Triangle(ALint *delay_left, ALint *delay_right, ALint offset, const ALchorusState *state)
@@ -176,14 +158,14 @@ 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 = (ALint)(lfo_value * state->frequency);
+ *delay_left = fastf2i(lfo_value * state->frequency);
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 = (ALint)(lfo_value * state->frequency);
+ *delay_right = fastf2i(lfo_value * state->frequency);
}
static __inline void Sinusoid(ALint *delay_left, ALint *delay_right, ALint offset, const ALchorusState *state)
@@ -193,13 +175,13 @@ 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 = (ALint)(lfo_value * state->frequency);
+ *delay_left = fastf2i(lfo_value * state->frequency);
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 = (ALint)(lfo_value * state->frequency);
+ *delay_right = fastf2i(lfo_value * state->frequency);
}
#define DECL_TEMPLATE(func) \
diff --git a/Alc/alcFlanger.c b/Alc/alcFlanger.c
index 4f9a4f22..91d98cac 100644
--- a/Alc/alcFlanger.c
+++ b/Alc/alcFlanger.c
@@ -45,8 +45,6 @@ typedef struct ALflangerState {
/* effect parameters */
ALint waveform;
- ALint phase;
- ALfloat rate;
ALfloat depth;
ALfloat feedback;
ALfloat delay;
@@ -106,6 +104,8 @@ static ALboolean FlangerDeviceUpdate(ALeffectState *effect, ALCdevice *Device)
static ALvoid FlangerUpdate(ALeffectState *effect, ALCdevice *Device, const ALeffectslot *Slot)
{
ALflangerState *state = GET_PARENT_TYPE(ALflangerState, ALeffectState, effect);
+ ALfloat rate;
+ ALint phase;
ALuint it;
for(it = 0;it < MaxChannels;it++)
@@ -115,8 +115,6 @@ static ALvoid FlangerUpdate(ALeffectState *effect, ALCdevice *Device, const ALef
}
state->waveform = Slot->effect.Flanger.Waveform;
- state->phase = Slot->effect.Flanger.Phase;
- state->rate = Slot->effect.Flanger.Rate;
state->depth = Slot->effect.Flanger.Depth;
state->feedback = Slot->effect.Flanger.Feedback;
state->delay = Slot->effect.Flanger.Delay;
@@ -126,31 +124,31 @@ static ALvoid FlangerUpdate(ALeffectState *effect, ALCdevice *Device, const ALef
ComputeAngleGains(Device, atan2f(-1.0f, 0.0f), 0.0f, Slot->Gain, state->Gain[0]);
ComputeAngleGains(Device, atan2f(+1.0f, 0.0f), 0.0f, Slot->Gain, state->Gain[1]);
+ phase = Slot->effect.Flanger.Phase;
+ rate = Slot->effect.Flanger.Rate;
+
/* Calculate LFO coefficient */
switch(state->waveform)
{
case AL_FLANGER_WAVEFORM_TRIANGLE:
- if(state->rate == 0.0f)
+ if(rate == 0.0f)
state->lfo_coeff = 0.0f;
else
- state->lfo_coeff = 1.0f / (state->frequency / state->rate);
+ state->lfo_coeff = 1.0f / (state->frequency / rate);
break;
case AL_FLANGER_WAVEFORM_SINUSOID:
- if (state->rate == 0.0f)
+ if(rate == 0.0f)
state->lfo_coeff = 0.0f;
else
- state->lfo_coeff = F_PI * 2.0f / (state->frequency / state->rate);
+ state->lfo_coeff = F_PI * 2.0f / (state->frequency / rate);
break;
}
/* Calculate lfo phase displacement */
- if(state->phase == 0 || state->rate == 0.0f)
+ if(phase == 0 || rate == 0.0f)
state->lfo_disp = 0;
else
- {
- state->lfo_disp = (ALint)(state->frequency / state->rate /
- (360.0f / (ALfloat)state->phase));
- }
+ state->lfo_disp = fastf2i(state->frequency / rate / (360.0f/phase));
}
static __inline void Triangle(ALint *delay_left, ALint *delay_right, ALint offset, const ALflangerState *state)
@@ -160,14 +158,14 @@ 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 = (ALint)(lfo_value * state->frequency);
+ *delay_left = fastf2i(lfo_value * state->frequency);
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 = (ALint)(lfo_value * state->frequency);
+ *delay_right = fastf2i(lfo_value * state->frequency);
}
static __inline void Sinusoid(ALint *delay_left, ALint *delay_right, ALint offset, const ALflangerState *state)
@@ -177,13 +175,13 @@ 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 = (ALint)(lfo_value * state->frequency);
+ *delay_left = fastf2i(lfo_value * state->frequency);
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 = (ALint)(lfo_value * state->frequency);
+ *delay_right = fastf2i(lfo_value * state->frequency);
}
#define DECL_TEMPLATE(func) \