aboutsummaryrefslogtreecommitdiffstats
path: root/Alc/alcEcho.c
diff options
context:
space:
mode:
authorChris Robinson <[email protected]>2009-10-20 08:31:44 -0700
committerChris Robinson <[email protected]>2009-10-20 08:31:44 -0700
commitf14cf8289eae832b090c4067ae66a19be08b7029 (patch)
tree72429089a328f49f494f9234bad41cf23d99a534 /Alc/alcEcho.c
parent790aa686214559377c4ec398762c1e7cd655f8a5 (diff)
Add a method to update device-dependant effect parameters.
The effect state's update method will be called afterwards
Diffstat (limited to 'Alc/alcEcho.c')
-rw-r--r--Alc/alcEcho.c51
1 files changed, 23 insertions, 28 deletions
diff --git a/Alc/alcEcho.c b/Alc/alcEcho.c
index 8aa4d2ce..6601051d 100644
--- a/Alc/alcEcho.c
+++ b/Alc/alcEcho.c
@@ -85,32 +85,41 @@ ALvoid EchoDestroy(ALeffectState *effect)
}
}
-ALvoid EchoUpdate(ALeffectState *effect, ALCcontext *Context, const ALeffect *Effect)
+ALboolean EchoDeviceUpdate(ALeffectState *effect, ALCdevice *Device)
{
ALechoState *state = (ALechoState*)effect;
- ALfloat lrpan, cw, a, g;
ALuint maxlen;
- maxlen = (ALuint)(AL_ECHO_MAX_DELAY * Context->Frequency);
- maxlen += (ALuint)(AL_ECHO_MAX_LRDELAY * Context->Frequency);
+ // Use the next power of 2 for the buffer length, so the tap offsets can be
+ // wrapped using a mask instead of a modulo
+ maxlen = (ALuint)(AL_ECHO_MAX_DELAY * Device->Frequency);
+ maxlen += (ALuint)(AL_ECHO_MAX_LRDELAY * Device->Frequency);
maxlen = NextPowerOf2(maxlen+1);
- if(maxlen > state->BufferLength)
+ if(maxlen != state->BufferLength)
{
void *temp;
ALuint i;
- state->BufferLength = maxlen;
- temp = realloc(state->SampleBuffer, state->BufferLength * sizeof(ALfloat));
+ temp = realloc(state->SampleBuffer, maxlen * sizeof(ALfloat));
if(!temp)
{
- AL_PRINT("Failed reallocation!");
- abort();
+ alSetError(AL_OUT_OF_MEMORY);
+ return AL_FALSE;
}
+ state->BufferLength = maxlen;
for(i = 0;i < state->BufferLength;i++)
state->SampleBuffer[i] = 0.0f;
}
+ return AL_TRUE;
+}
+
+ALvoid EchoUpdate(ALeffectState *effect, ALCcontext *Context, const ALeffect *Effect)
+{
+ ALechoState *state = (ALechoState*)effect;
+ ALfloat lrpan, cw, a, g;
+
state->Tap[0].delay = (ALuint)(Effect->Echo.Delay * Context->Frequency);
state->Tap[1].delay = (ALuint)(Effect->Echo.LRDelay * Context->Frequency);
state->Tap[1].delay += state->Tap[0].delay;
@@ -173,7 +182,6 @@ ALvoid EchoProcess(ALeffectState *effect, const ALeffectslot *Slot, ALuint Sampl
ALeffectState *EchoCreate(void)
{
ALechoState *state;
- ALuint i, maxlen;
state = malloc(sizeof(*state));
if(!state)
@@ -183,25 +191,12 @@ ALeffectState *EchoCreate(void)
}
state->state.Destroy = EchoDestroy;
+ state->state.DeviceUpdate = EchoDeviceUpdate;
state->state.Update = EchoUpdate;
state->state.Process = EchoProcess;
- maxlen = (ALuint)(AL_ECHO_MAX_DELAY * MAX_ECHO_FREQ);
- maxlen += (ALuint)(AL_ECHO_MAX_LRDELAY * MAX_ECHO_FREQ);
-
- // Use the next power of 2 for the buffer length, so the tap offsets can be
- // wrapped using a mask instead of a modulo
- state->BufferLength = NextPowerOf2(maxlen+1);
- state->SampleBuffer = malloc(state->BufferLength * sizeof(ALfloat));
- if(!state->SampleBuffer)
- {
- free(state);
- alSetError(AL_OUT_OF_MEMORY);
- return NULL;
- }
-
- for(i = 0;i < state->BufferLength;i++)
- state->SampleBuffer[i] = 0.0f;
+ state->BufferLength = 0;
+ state->SampleBuffer = NULL;
state->Tap[0].delay = 0;
state->Tap[1].delay = 0;
@@ -209,9 +204,9 @@ ALeffectState *EchoCreate(void)
state->GainL = 0.0f;
state->GainR = 0.0f;
- for(i = 0;i < 2;i++)
- state->iirFilter.history[i] = 0.0f;
state->iirFilter.coeff = 0.0f;
+ state->iirFilter.history[0] = 0.0f;
+ state->iirFilter.history[1] = 0.0f;
return &state->state;
}