diff options
Diffstat (limited to 'Alc')
-rw-r--r-- | Alc/alcChorus.c | 19 | ||||
-rw-r--r-- | Alc/alcDedicated.c | 19 | ||||
-rw-r--r-- | Alc/alcDistortion.c | 19 | ||||
-rw-r--r-- | Alc/alcEcho.c | 19 | ||||
-rw-r--r-- | Alc/alcEqualizer.c | 19 | ||||
-rw-r--r-- | Alc/alcFlanger.c | 19 | ||||
-rw-r--r-- | Alc/alcModulator.c | 19 | ||||
-rw-r--r-- | Alc/alcReverb.c | 108 |
8 files changed, 110 insertions, 131 deletions
diff --git a/Alc/alcChorus.c b/Alc/alcChorus.c index f02544c4..c34396eb 100644 --- a/Alc/alcChorus.c +++ b/Alc/alcChorus.c @@ -50,7 +50,7 @@ typedef struct ALchorusState { ALfloat feedback; } ALchorusState; -static ALvoid ChorusDestroy(ALeffectState *effect) +static ALvoid ALchorusState_Destroy(ALeffectState *effect) { ALchorusState *state = STATIC_UPCAST(ALchorusState, ALeffectState, effect); @@ -63,7 +63,7 @@ static ALvoid ChorusDestroy(ALeffectState *effect) free(state); } -static ALboolean ChorusDeviceUpdate(ALeffectState *effect, ALCdevice *Device) +static ALboolean ALchorusState_DeviceUpdate(ALeffectState *effect, ALCdevice *Device) { ALchorusState *state = STATIC_UPCAST(ALchorusState, ALeffectState, effect); ALuint maxlen; @@ -96,7 +96,7 @@ static ALboolean ChorusDeviceUpdate(ALeffectState *effect, ALCdevice *Device) return AL_TRUE; } -static ALvoid ChorusUpdate(ALeffectState *effect, ALCdevice *Device, const ALeffectslot *Slot) +static ALvoid ALchorusState_Update(ALeffectState *effect, ALCdevice *Device, const ALeffectslot *Slot) { ALchorusState *state = STATIC_UPCAST(ALchorusState, ALeffectState, effect); ALfloat frequency = Device->Frequency; @@ -234,7 +234,7 @@ DECL_TEMPLATE(Sinusoid) #undef DECL_TEMPLATE -static ALvoid ChorusProcess(ALeffectState *effect, ALuint SamplesToDo, const ALfloat *RESTRICT SamplesIn, ALfloat (*RESTRICT SamplesOut)[BUFFERSIZE]) +static ALvoid ALchorusState_Process(ALeffectState *effect, ALuint SamplesToDo, const ALfloat *RESTRICT SamplesIn, ALfloat (*RESTRICT SamplesOut)[BUFFERSIZE]) { ALchorusState *state = STATIC_UPCAST(ALchorusState, ALeffectState, effect); @@ -244,18 +244,15 @@ static ALvoid ChorusProcess(ALeffectState *effect, ALuint SamplesToDo, const ALf ProcessSinusoid(state, SamplesToDo, SamplesIn, SamplesOut); } +DEFINE_ALEFFECTSTATE_VTABLE(ALchorusState); + ALeffectState *ChorusCreate(void) { ALchorusState *state; state = malloc(sizeof(*state)); - if(!state) - return NULL; - - STATIC_CAST(ALeffectState, state)->Destroy = ChorusDestroy; - STATIC_CAST(ALeffectState, state)->DeviceUpdate = ChorusDeviceUpdate; - STATIC_CAST(ALeffectState, state)->Update = ChorusUpdate; - STATIC_CAST(ALeffectState, state)->Process = ChorusProcess; + if(!state) return NULL; + SET_VTABLE2(ALchorusState, ALeffectState, state); state->BufferLength = 0; state->SampleBufferLeft = NULL; diff --git a/Alc/alcDedicated.c b/Alc/alcDedicated.c index 35de345f..a3267509 100644 --- a/Alc/alcDedicated.c +++ b/Alc/alcDedicated.c @@ -36,20 +36,20 @@ typedef struct ALdedicatedState { } ALdedicatedState; -static ALvoid DedicatedDestroy(ALeffectState *effect) +static ALvoid ALdedicatedState_Destroy(ALeffectState *effect) { ALdedicatedState *state = STATIC_UPCAST(ALdedicatedState, ALeffectState, effect); free(state); } -static ALboolean DedicatedDeviceUpdate(ALeffectState *effect, ALCdevice *Device) +static ALboolean ALdedicatedState_DeviceUpdate(ALeffectState *effect, ALCdevice *Device) { (void)effect; (void)Device; return AL_TRUE; } -static ALvoid DedicatedUpdate(ALeffectState *effect, ALCdevice *device, const ALeffectslot *Slot) +static ALvoid ALdedicatedState_Update(ALeffectState *effect, ALCdevice *device, const ALeffectslot *Slot) { ALdedicatedState *state = STATIC_UPCAST(ALdedicatedState, ALeffectState, effect); ALfloat Gain; @@ -65,7 +65,7 @@ static ALvoid DedicatedUpdate(ALeffectState *effect, ALCdevice *device, const AL state->gains[LFE] = Gain; } -static ALvoid DedicatedProcess(ALeffectState *effect, ALuint SamplesToDo, const ALfloat *RESTRICT SamplesIn, ALfloat (*RESTRICT SamplesOut)[BUFFERSIZE]) +static ALvoid ALdedicatedState_Process(ALeffectState *effect, ALuint SamplesToDo, const ALfloat *RESTRICT SamplesIn, ALfloat (*RESTRICT SamplesOut)[BUFFERSIZE]) { ALdedicatedState *state = STATIC_UPCAST(ALdedicatedState, ALeffectState, effect); const ALfloat *gains = state->gains; @@ -81,19 +81,16 @@ static ALvoid DedicatedProcess(ALeffectState *effect, ALuint SamplesToDo, const } } +DEFINE_ALEFFECTSTATE_VTABLE(ALdedicatedState); + ALeffectState *DedicatedCreate(void) { ALdedicatedState *state; ALsizei s; state = malloc(sizeof(*state)); - if(!state) - return NULL; - - STATIC_CAST(ALeffectState, state)->Destroy = DedicatedDestroy; - STATIC_CAST(ALeffectState, state)->DeviceUpdate = DedicatedDeviceUpdate; - STATIC_CAST(ALeffectState, state)->Update = DedicatedUpdate; - STATIC_CAST(ALeffectState, state)->Process = DedicatedProcess; + if(!state) return NULL; + SET_VTABLE2(ALdedicatedState, ALeffectState, state); for(s = 0;s < MaxChannels;s++) state->gains[s] = 0.0f; diff --git a/Alc/alcDistortion.c b/Alc/alcDistortion.c index 0b0c9c93..50627093 100644 --- a/Alc/alcDistortion.c +++ b/Alc/alcDistortion.c @@ -59,20 +59,20 @@ typedef struct ALdistortionState { ALfloat edge_coeff; } ALdistortionState; -static ALvoid DistortionDestroy(ALeffectState *effect) +static ALvoid ALdistortionState_Destroy(ALeffectState *effect) { ALdistortionState *state = STATIC_UPCAST(ALdistortionState, ALeffectState, effect); free(state); } -static ALboolean DistortionDeviceUpdate(ALeffectState *effect, ALCdevice *Device) +static ALboolean ALdistortionState_DeviceUpdate(ALeffectState *effect, ALCdevice *Device) { return AL_TRUE; (void)effect; (void)Device; } -static ALvoid DistortionUpdate(ALeffectState *effect, ALCdevice *Device, const ALeffectslot *Slot) +static ALvoid ALdistortionState_Update(ALeffectState *effect, ALCdevice *Device, const ALeffectslot *Slot) { ALdistortionState *state = STATIC_UPCAST(ALdistortionState, ALeffectState, effect); ALfloat gain = sqrtf(1.0f / Device->NumChan) * Slot->Gain; @@ -126,7 +126,7 @@ static ALvoid DistortionUpdate(ALeffectState *effect, ALCdevice *Device, const A state->bandpass.a[2] = 1.0f - alpha; } -static ALvoid DistortionProcess(ALeffectState *effect, ALuint SamplesToDo, const ALfloat *RESTRICT SamplesIn, ALfloat (*RESTRICT SamplesOut)[BUFFERSIZE]) +static ALvoid ALdistortionState_Process(ALeffectState *effect, ALuint SamplesToDo, const ALfloat *RESTRICT SamplesIn, ALfloat (*RESTRICT SamplesOut)[BUFFERSIZE]) { ALdistortionState *state = STATIC_UPCAST(ALdistortionState, ALeffectState, effect); const ALfloat fc = state->edge_coeff; @@ -229,18 +229,15 @@ static ALvoid DistortionProcess(ALeffectState *effect, ALuint SamplesToDo, const } } +DEFINE_ALEFFECTSTATE_VTABLE(ALdistortionState); + ALeffectState *DistortionCreate(void) { ALdistortionState *state; state = malloc(sizeof(*state)); - if(!state) - return NULL; - - STATIC_CAST(ALeffectState, state)->Destroy = DistortionDestroy; - STATIC_CAST(ALeffectState, state)->DeviceUpdate = DistortionDeviceUpdate; - STATIC_CAST(ALeffectState, state)->Update = DistortionUpdate; - STATIC_CAST(ALeffectState, state)->Process = DistortionProcess; + if(!state) return NULL; + SET_VTABLE2(ALdistortionState, ALeffectState, state); state->bandpass.type = BANDPASS; state->lowpass.type = LOWPASS; diff --git a/Alc/alcEcho.c b/Alc/alcEcho.c index b4663ade..3fbd5232 100644 --- a/Alc/alcEcho.c +++ b/Alc/alcEcho.c @@ -51,7 +51,7 @@ typedef struct ALechoState { ALfloat history[2]; } ALechoState; -static ALvoid EchoDestroy(ALeffectState *effect) +static ALvoid ALechoState_Destroy(ALeffectState *effect) { ALechoState *state = STATIC_UPCAST(ALechoState, ALeffectState, effect); @@ -61,7 +61,7 @@ static ALvoid EchoDestroy(ALeffectState *effect) free(state); } -static ALboolean EchoDeviceUpdate(ALeffectState *effect, ALCdevice *Device) +static ALboolean ALechoState_DeviceUpdate(ALeffectState *effect, ALCdevice *Device) { ALechoState *state = STATIC_UPCAST(ALechoState, ALeffectState, effect); ALuint maxlen, i; @@ -88,7 +88,7 @@ static ALboolean EchoDeviceUpdate(ALeffectState *effect, ALCdevice *Device) return AL_TRUE; } -static ALvoid EchoUpdate(ALeffectState *effect, ALCdevice *Device, const ALeffectslot *Slot) +static ALvoid ALechoState_Update(ALeffectState *effect, ALCdevice *Device, const ALeffectslot *Slot) { ALechoState *state = STATIC_UPCAST(ALechoState, ALeffectState, effect); ALuint frequency = Device->Frequency; @@ -124,7 +124,7 @@ static ALvoid EchoUpdate(ALeffectState *effect, ALCdevice *Device, const ALeffec ComputeAngleGains(Device, atan2f(+lrpan, 0.0f), (1.0f-dirGain)*F_PI, gain, state->Gain[1]); } -static ALvoid EchoProcess(ALeffectState *effect, ALuint SamplesToDo, const ALfloat *RESTRICT SamplesIn, ALfloat (*RESTRICT SamplesOut)[BUFFERSIZE]) +static ALvoid ALechoState_Process(ALeffectState *effect, ALuint SamplesToDo, const ALfloat *RESTRICT SamplesIn, ALfloat (*RESTRICT SamplesOut)[BUFFERSIZE]) { ALechoState *state = STATIC_UPCAST(ALechoState, ALeffectState, effect); const ALuint mask = state->BufferLength-1; @@ -176,18 +176,15 @@ static ALvoid EchoProcess(ALeffectState *effect, ALuint SamplesToDo, const ALflo state->Offset = offset; } +DEFINE_ALEFFECTSTATE_VTABLE(ALechoState); + ALeffectState *EchoCreate(void) { ALechoState *state; state = malloc(sizeof(*state)); - if(!state) - return NULL; - - STATIC_CAST(ALeffectState, state)->Destroy = EchoDestroy; - STATIC_CAST(ALeffectState, state)->DeviceUpdate = EchoDeviceUpdate; - STATIC_CAST(ALeffectState, state)->Update = EchoUpdate; - STATIC_CAST(ALeffectState, state)->Process = EchoProcess; + if(!state) return NULL; + SET_VTABLE2(ALechoState, ALeffectState, state); state->BufferLength = 0; state->SampleBuffer = NULL; diff --git a/Alc/alcEqualizer.c b/Alc/alcEqualizer.c index 62097cd5..50a83c9a 100644 --- a/Alc/alcEqualizer.c +++ b/Alc/alcEqualizer.c @@ -95,13 +95,13 @@ typedef struct ALequalizerState { ALfloat frequency; } ALequalizerState; -static ALvoid EqualizerDestroy(ALeffectState *effect) +static ALvoid ALequalizerState_Destroy(ALeffectState *effect) { ALequalizerState *state = STATIC_UPCAST(ALequalizerState, ALeffectState, effect); free(state); } -static ALboolean EqualizerDeviceUpdate(ALeffectState *effect, ALCdevice *Device) +static ALboolean ALequalizerState_DeviceUpdate(ALeffectState *effect, ALCdevice *Device) { ALequalizerState *state = STATIC_UPCAST(ALequalizerState, ALeffectState, effect); @@ -110,7 +110,7 @@ static ALboolean EqualizerDeviceUpdate(ALeffectState *effect, ALCdevice *Device) return AL_TRUE; } -static ALvoid EqualizerUpdate(ALeffectState *effect, ALCdevice *Device, const ALeffectslot *Slot) +static ALvoid ALequalizerState_Update(ALeffectState *effect, ALCdevice *Device, const ALeffectslot *Slot) { ALequalizerState *state = STATIC_UPCAST(ALequalizerState, ALeffectState, effect); ALfloat gain = sqrtf(1.0f / Device->NumChan) * Slot->Gain; @@ -215,7 +215,7 @@ static ALvoid EqualizerUpdate(ALeffectState *effect, ALCdevice *Device, const AL } } -static ALvoid EqualizerProcess(ALeffectState *effect, ALuint SamplesToDo, const ALfloat *RESTRICT SamplesIn, ALfloat (*RESTRICT SamplesOut)[BUFFERSIZE]) +static ALvoid ALequalizerState_Process(ALeffectState *effect, ALuint SamplesToDo, const ALfloat *RESTRICT SamplesIn, ALfloat (*RESTRICT SamplesOut)[BUFFERSIZE]) { ALequalizerState *state = STATIC_UPCAST(ALequalizerState, ALeffectState, effect); ALuint base; @@ -267,19 +267,16 @@ static ALvoid EqualizerProcess(ALeffectState *effect, ALuint SamplesToDo, const } } +DEFINE_ALEFFECTSTATE_VTABLE(ALequalizerState); + ALeffectState *EqualizerCreate(void) { ALequalizerState *state; int it; state = malloc(sizeof(*state)); - if(!state) - return NULL; - - STATIC_CAST(ALeffectState, state)->Destroy = EqualizerDestroy; - STATIC_CAST(ALeffectState, state)->DeviceUpdate = EqualizerDeviceUpdate; - STATIC_CAST(ALeffectState, state)->Update = EqualizerUpdate; - STATIC_CAST(ALeffectState, state)->Process = EqualizerProcess; + if(!state) return NULL; + SET_VTABLE2(ALequalizerState, ALeffectState, state); state->bandfilter[0].type = LOW_SHELF; state->bandfilter[1].type = PEAKING; diff --git a/Alc/alcFlanger.c b/Alc/alcFlanger.c index d7a59f3a..a69d7006 100644 --- a/Alc/alcFlanger.c +++ b/Alc/alcFlanger.c @@ -50,7 +50,7 @@ typedef struct ALflangerState { ALfloat feedback; } ALflangerState; -static ALvoid FlangerDestroy(ALeffectState *effect) +static ALvoid ALflangerState_Destroy(ALeffectState *effect) { ALflangerState *state = STATIC_UPCAST(ALflangerState, ALeffectState, effect); @@ -63,7 +63,7 @@ static ALvoid FlangerDestroy(ALeffectState *effect) free(state); } -static ALboolean FlangerDeviceUpdate(ALeffectState *effect, ALCdevice *Device) +static ALboolean ALflangerState_DeviceUpdate(ALeffectState *effect, ALCdevice *Device) { ALflangerState *state = STATIC_UPCAST(ALflangerState, ALeffectState, effect); ALuint maxlen; @@ -96,7 +96,7 @@ static ALboolean FlangerDeviceUpdate(ALeffectState *effect, ALCdevice *Device) return AL_TRUE; } -static ALvoid FlangerUpdate(ALeffectState *effect, ALCdevice *Device, const ALeffectslot *Slot) +static ALvoid ALflangerState_Update(ALeffectState *effect, ALCdevice *Device, const ALeffectslot *Slot) { ALflangerState *state = STATIC_UPCAST(ALflangerState, ALeffectState, effect); ALfloat frequency = Device->Frequency; @@ -234,7 +234,7 @@ DECL_TEMPLATE(Sinusoid) #undef DECL_TEMPLATE -static ALvoid FlangerProcess(ALeffectState *effect, ALuint SamplesToDo, const ALfloat *RESTRICT SamplesIn, ALfloat (*RESTRICT SamplesOut)[BUFFERSIZE]) +static ALvoid ALflangerState_Process(ALeffectState *effect, ALuint SamplesToDo, const ALfloat *RESTRICT SamplesIn, ALfloat (*RESTRICT SamplesOut)[BUFFERSIZE]) { ALflangerState *state = STATIC_UPCAST(ALflangerState, ALeffectState, effect); @@ -244,18 +244,15 @@ static ALvoid FlangerProcess(ALeffectState *effect, ALuint SamplesToDo, const AL ProcessSinusoid(state, SamplesToDo, SamplesIn, SamplesOut); } +DEFINE_ALEFFECTSTATE_VTABLE(ALflangerState); + ALeffectState *FlangerCreate(void) { ALflangerState *state; state = malloc(sizeof(*state)); - if(!state) - return NULL; - - STATIC_CAST(ALeffectState, state)->Destroy = FlangerDestroy; - STATIC_CAST(ALeffectState, state)->DeviceUpdate = FlangerDeviceUpdate; - STATIC_CAST(ALeffectState, state)->Update = FlangerUpdate; - STATIC_CAST(ALeffectState, state)->Process = FlangerProcess; + if(!state) return NULL; + SET_VTABLE2(ALflangerState, ALeffectState, state); state->BufferLength = 0; state->SampleBufferLeft = NULL; diff --git a/Alc/alcModulator.c b/Alc/alcModulator.c index daf5416c..b2ea6642 100644 --- a/Alc/alcModulator.c +++ b/Alc/alcModulator.c @@ -129,20 +129,20 @@ DECL_TEMPLATE(Square) #undef DECL_TEMPLATE -static ALvoid ModulatorDestroy(ALeffectState *effect) +static ALvoid ALmodulatorState_Destroy(ALeffectState *effect) { ALmodulatorState *state = STATIC_UPCAST(ALmodulatorState, ALeffectState, effect); free(state); } -static ALboolean ModulatorDeviceUpdate(ALeffectState *effect, ALCdevice *Device) +static ALboolean ALmodulatorState_DeviceUpdate(ALeffectState *effect, ALCdevice *Device) { return AL_TRUE; (void)effect; (void)Device; } -static ALvoid ModulatorUpdate(ALeffectState *effect, ALCdevice *Device, const ALeffectslot *Slot) +static ALvoid ALmodulatorState_Update(ALeffectState *effect, ALCdevice *Device, const ALeffectslot *Slot) { ALmodulatorState *state = STATIC_UPCAST(ALmodulatorState, ALeffectState, effect); ALfloat gain, cw, a = 0.0f; @@ -175,7 +175,7 @@ static ALvoid ModulatorUpdate(ALeffectState *effect, ALCdevice *Device, const AL } } -static ALvoid ModulatorProcess(ALeffectState *effect, ALuint SamplesToDo, const ALfloat *RESTRICT SamplesIn, ALfloat (*RESTRICT SamplesOut)[BUFFERSIZE]) +static ALvoid ALmodulatorState_Process(ALeffectState *effect, ALuint SamplesToDo, const ALfloat *RESTRICT SamplesIn, ALfloat (*RESTRICT SamplesOut)[BUFFERSIZE]) { ALmodulatorState *state = STATIC_UPCAST(ALmodulatorState, ALeffectState, effect); @@ -195,18 +195,15 @@ static ALvoid ModulatorProcess(ALeffectState *effect, ALuint SamplesToDo, const } } +DEFINE_ALEFFECTSTATE_VTABLE(ALmodulatorState); + ALeffectState *ModulatorCreate(void) { ALmodulatorState *state; state = malloc(sizeof(*state)); - if(!state) - return NULL; - - STATIC_CAST(ALeffectState, state)->Destroy = ModulatorDestroy; - STATIC_CAST(ALeffectState, state)->DeviceUpdate = ModulatorDeviceUpdate; - STATIC_CAST(ALeffectState, state)->Update = ModulatorUpdate; - STATIC_CAST(ALeffectState, state)->Process = ModulatorProcess; + if(!state) return NULL; + SET_VTABLE2(ALmodulatorState, ALeffectState, state); state->index = 0; state->step = 1; diff --git a/Alc/alcReverb.c b/Alc/alcReverb.c index 6de2c66f..b84dad96 100644 --- a/Alc/alcReverb.c +++ b/Alc/alcReverb.c @@ -39,9 +39,11 @@ typedef struct DelayLine ALfloat *Line; } DelayLine; -typedef struct ALverbState { +typedef struct ALreverbState { DERIVE_FROM_TYPE(ALeffectState); + ALboolean IsEax; + // All delay lines are allocated as a single buffer to reduce memory // fragmentation and management code. ALfloat *SampleBuffer; @@ -159,7 +161,7 @@ typedef struct ALverbState { /* Temporary storage used when processing, before deinterlacing. */ ALfloat ReverbSamples[BUFFERSIZE][4]; ALfloat EarlySamples[BUFFERSIZE][4]; -} ALverbState; +} ALreverbState; /* This is a user config option for modifying the overall output of the reverb * effect. @@ -254,7 +256,7 @@ static __inline ALfloat AllpassInOut(DelayLine *Delay, ALuint outOffset, ALuint // Given an input sample, this function produces modulation for the late // reverb. -static __inline ALfloat EAXModulation(ALverbState *State, ALfloat in) +static __inline ALfloat EAXModulation(ALreverbState *State, ALfloat in) { ALfloat sinus, frac; ALuint offset; @@ -291,7 +293,7 @@ static __inline ALfloat EAXModulation(ALverbState *State, ALfloat in) } // Delay line output routine for early reflections. -static __inline ALfloat EarlyDelayLineOut(ALverbState *State, ALuint index) +static __inline ALfloat EarlyDelayLineOut(ALreverbState *State, ALuint index) { return AttenuatedDelayLineOut(&State->Early.Delay[index], State->Offset - State->Early.Offset[index], @@ -300,7 +302,7 @@ static __inline ALfloat EarlyDelayLineOut(ALverbState *State, ALuint index) // Given an input sample, this function produces four-channel output for the // early reflections. -static __inline ALvoid EarlyReflection(ALverbState *State, ALfloat in, ALfloat *RESTRICT out) +static __inline ALvoid EarlyReflection(ALreverbState *State, ALfloat in, ALfloat *RESTRICT out) { ALfloat d[4], v, f[4]; @@ -345,7 +347,7 @@ static __inline ALvoid EarlyReflection(ALverbState *State, ALfloat in, ALfloat * } // All-pass input/output routine for late reverb. -static __inline ALfloat LateAllPassInOut(ALverbState *State, ALuint index, ALfloat in) +static __inline ALfloat LateAllPassInOut(ALreverbState *State, ALuint index, ALfloat in) { return AllpassInOut(&State->Late.ApDelay[index], State->Offset - State->Late.ApOffset[index], @@ -354,7 +356,7 @@ static __inline ALfloat LateAllPassInOut(ALverbState *State, ALuint index, ALflo } // Delay line output routine for late reverb. -static __inline ALfloat LateDelayLineOut(ALverbState *State, ALuint index) +static __inline ALfloat LateDelayLineOut(ALreverbState *State, ALuint index) { return AttenuatedDelayLineOut(&State->Late.Delay[index], State->Offset - State->Late.Offset[index], @@ -362,7 +364,7 @@ static __inline ALfloat LateDelayLineOut(ALverbState *State, ALuint index) } // Low-pass filter input/output routine for late reverb. -static __inline ALfloat LateLowPassInOut(ALverbState *State, ALuint index, ALfloat in) +static __inline ALfloat LateLowPassInOut(ALreverbState *State, ALuint index, ALfloat in) { in = lerp(in, State->Late.LpSample[index], State->Late.LpCoeff[index]); State->Late.LpSample[index] = in; @@ -371,7 +373,7 @@ static __inline ALfloat LateLowPassInOut(ALverbState *State, ALuint index, ALflo // Given four decorrelated input samples, this function produces four-channel // output for the late reverb. -static __inline ALvoid LateReverb(ALverbState *State, const ALfloat *RESTRICT in, ALfloat *RESTRICT out) +static __inline ALvoid LateReverb(ALreverbState *State, const ALfloat *RESTRICT in, ALfloat *RESTRICT out) { ALfloat d[4], f[4]; @@ -442,7 +444,7 @@ static __inline ALvoid LateReverb(ALverbState *State, const ALfloat *RESTRICT in // Given an input sample, this function mixes echo into the four-channel late // reverb. -static __inline ALvoid EAXEcho(ALverbState *State, ALfloat in, ALfloat *RESTRICT late) +static __inline ALvoid EAXEcho(ALreverbState *State, ALfloat in, ALfloat *RESTRICT late) { ALfloat out, feed; @@ -476,7 +478,7 @@ static __inline ALvoid EAXEcho(ALverbState *State, ALfloat in, ALfloat *RESTRICT // Perform the non-EAX reverb pass on a given input sample, resulting in // four-channel output. -static __inline ALvoid VerbPass(ALverbState *State, ALfloat in, ALfloat *RESTRICT out) +static __inline ALvoid VerbPass(ALreverbState *State, ALfloat in, ALfloat *RESTRICT out) { ALfloat feed, late[4], taps[4]; @@ -515,7 +517,7 @@ static __inline ALvoid VerbPass(ALverbState *State, ALfloat in, ALfloat *RESTRIC // Perform the EAX reverb pass on a given input sample, resulting in four- // channel output. -static __inline ALvoid EAXVerbPass(ALverbState *State, ALfloat in, ALfloat *RESTRICT early, ALfloat *RESTRICT late) +static __inline ALvoid EAXVerbPass(ALreverbState *State, ALfloat in, ALfloat *RESTRICT early, ALfloat *RESTRICT late) { ALfloat feed, taps[4]; @@ -552,11 +554,10 @@ static __inline ALvoid EAXVerbPass(ALverbState *State, ALfloat in, ALfloat *REST State->Offset++; } -// This processes the reverb state, given the input samples and an output -// buffer. -static ALvoid VerbProcess(ALeffectState *effect, ALuint SamplesToDo, const ALfloat *RESTRICT SamplesIn, ALfloat (*RESTRICT SamplesOut)[BUFFERSIZE]) +// This processes the standard reverb state, given the input samples and an +// output buffer. +static ALvoid ALreverbState_ProcessStandard(ALreverbState *State, ALuint SamplesToDo, const ALfloat *RESTRICT SamplesIn, ALfloat (*RESTRICT SamplesOut)[BUFFERSIZE]) { - ALverbState *State = STATIC_UPCAST(ALverbState, ALeffectState, effect); ALfloat (*RESTRICT out)[4] = State->ReverbSamples; ALuint index, c; @@ -577,9 +578,8 @@ static ALvoid VerbProcess(ALeffectState *effect, ALuint SamplesToDo, const ALflo // This processes the EAX reverb state, given the input samples and an output // buffer. -static ALvoid EAXVerbProcess(ALeffectState *effect, ALuint SamplesToDo, const ALfloat *RESTRICT SamplesIn, ALfloat (*RESTRICT SamplesOut)[BUFFERSIZE]) +static ALvoid ALreverbState_ProcessEax(ALreverbState *State, ALuint SamplesToDo, const ALfloat *RESTRICT SamplesIn, ALfloat (*RESTRICT SamplesOut)[BUFFERSIZE]) { - ALverbState *State = STATIC_UPCAST(ALverbState, ALeffectState, effect); ALfloat (*RESTRICT early)[4] = State->EarlySamples; ALfloat (*RESTRICT late)[4] = State->ReverbSamples; ALuint index, c; @@ -606,6 +606,14 @@ static ALvoid EAXVerbProcess(ALeffectState *effect, ALuint SamplesToDo, const AL } } +static ALvoid ALreverbState_Process(ALeffectState *effect, ALuint SamplesToDo, const ALfloat *RESTRICT SamplesIn, ALfloat (*RESTRICT SamplesOut)[BUFFERSIZE]) +{ + ALreverbState *State = STATIC_UPCAST(ALreverbState, ALeffectState, effect); + if(State->IsEax) + ALreverbState_ProcessEax(State, SamplesToDo, SamplesIn, SamplesOut); + else + ALreverbState_ProcessStandard(State, SamplesToDo, SamplesIn, SamplesOut); +} // Given the allocated sample buffer, this function updates each delay line // offset. @@ -633,7 +641,7 @@ static ALuint CalcLineLength(ALfloat length, ALintptrEXT offset, ALuint frequenc * for all lines given the sample rate (frequency). If an allocation failure * occurs, it returns AL_FALSE. */ -static ALboolean AllocLines(ALuint frequency, ALverbState *State) +static ALboolean AllocLines(ALuint frequency, ALreverbState *State) { ALuint totalSamples, index; ALfloat length; @@ -724,9 +732,9 @@ static ALboolean AllocLines(ALuint frequency, ALverbState *State) // This updates the device-dependant EAX reverb state. This is called on // initialization and any time the device parameters (eg. playback frequency, // format) have been changed. -static ALboolean ReverbDeviceUpdate(ALeffectState *effect, ALCdevice *Device) +static ALboolean ALreverbState_DeviceUpdate(ALeffectState *effect, ALCdevice *Device) { - ALverbState *State = STATIC_UPCAST(ALverbState, ALeffectState, effect); + ALreverbState *State = STATIC_UPCAST(ALreverbState, ALeffectState, effect); ALuint frequency = Device->Frequency, index; // Allocate the delay lines. @@ -861,7 +869,7 @@ static __inline ALfloat CalcDampingCoeff(ALfloat hfRatio, ALfloat length, ALfloa // Update the EAX modulation index, range, and depth. Keep in mind that this // kind of vibrato is additive and not multiplicative as one may expect. The // downswing will sound stronger than the upswing. -static ALvoid UpdateModulator(ALfloat modTime, ALfloat modDepth, ALuint frequency, ALverbState *State) +static ALvoid UpdateModulator(ALfloat modTime, ALfloat modDepth, ALuint frequency, ALreverbState *State) { ALuint range; @@ -891,7 +899,7 @@ static ALvoid UpdateModulator(ALfloat modTime, ALfloat modDepth, ALuint frequenc } // Update the offsets for the initial effect delay line. -static ALvoid UpdateDelayLine(ALfloat earlyDelay, ALfloat lateDelay, ALuint frequency, ALverbState *State) +static ALvoid UpdateDelayLine(ALfloat earlyDelay, ALfloat lateDelay, ALuint frequency, ALreverbState *State) { // Calculate the initial delay taps. State->DelayTap[0] = fastf2u(earlyDelay * frequency); @@ -899,7 +907,7 @@ static ALvoid UpdateDelayLine(ALfloat earlyDelay, ALfloat lateDelay, ALuint freq } // Update the early reflections gain and line coefficients. -static ALvoid UpdateEarlyLines(ALfloat reverbGain, ALfloat earlyGain, ALfloat lateDelay, ALverbState *State) +static ALvoid UpdateEarlyLines(ALfloat reverbGain, ALfloat earlyGain, ALfloat lateDelay, ALreverbState *State) { ALuint index; @@ -916,7 +924,7 @@ static ALvoid UpdateEarlyLines(ALfloat reverbGain, ALfloat earlyGain, ALfloat la } // Update the offsets for the decorrelator line. -static ALvoid UpdateDecorrelator(ALfloat density, ALuint frequency, ALverbState *State) +static ALvoid UpdateDecorrelator(ALfloat density, ALuint frequency, ALreverbState *State) { ALuint index; ALfloat length; @@ -937,7 +945,7 @@ static ALvoid UpdateDecorrelator(ALfloat density, ALuint frequency, ALverbState } // Update the late reverb gains, line lengths, and line coefficients. -static ALvoid UpdateLateLines(ALfloat reverbGain, ALfloat lateGain, ALfloat xMix, ALfloat density, ALfloat decayTime, ALfloat diffusion, ALfloat hfRatio, ALfloat cw, ALuint frequency, ALverbState *State) +static ALvoid UpdateLateLines(ALfloat reverbGain, ALfloat lateGain, ALfloat xMix, ALfloat density, ALfloat decayTime, ALfloat diffusion, ALfloat hfRatio, ALfloat cw, ALuint frequency, ALreverbState *State) { ALfloat length; ALuint index; @@ -995,7 +1003,7 @@ static ALvoid UpdateLateLines(ALfloat reverbGain, ALfloat lateGain, ALfloat xMix // Update the echo gain, line offset, line coefficients, and mixing // coefficients. -static ALvoid UpdateEchoLine(ALfloat reverbGain, ALfloat lateGain, ALfloat echoTime, ALfloat decayTime, ALfloat diffusion, ALfloat echoDepth, ALfloat hfRatio, ALfloat cw, ALuint frequency, ALverbState *State) +static ALvoid UpdateEchoLine(ALfloat reverbGain, ALfloat lateGain, ALfloat echoTime, ALfloat decayTime, ALfloat diffusion, ALfloat echoDepth, ALfloat hfRatio, ALfloat cw, ALuint frequency, ALreverbState *State) { // Update the offset and coefficient for the echo delay line. State->Echo.Offset = fastf2u(echoTime * frequency); @@ -1027,7 +1035,7 @@ static ALvoid UpdateEchoLine(ALfloat reverbGain, ALfloat lateGain, ALfloat echoT } // Update the early and late 3D panning gains. -static ALvoid Update3DPanning(const ALCdevice *Device, const ALfloat *ReflectionsPan, const ALfloat *LateReverbPan, ALfloat Gain, ALverbState *State) +static ALvoid Update3DPanning(const ALCdevice *Device, const ALfloat *ReflectionsPan, const ALfloat *LateReverbPan, ALfloat Gain, ALreverbState *State) { ALfloat earlyPan[3] = { ReflectionsPan[0], ReflectionsPan[1], ReflectionsPan[2] }; @@ -1076,31 +1084,26 @@ static ALvoid Update3DPanning(const ALCdevice *Device, const ALfloat *Reflection // This updates the EAX reverb state. This is called any time the EAX reverb // effect is loaded into a slot. -static ALvoid ReverbUpdate(ALeffectState *effect, ALCdevice *Device, const ALeffectslot *Slot) +static ALvoid ALreverbState_Update(ALeffectState *effect, ALCdevice *Device, const ALeffectslot *Slot) { - ALverbState *State = STATIC_UPCAST(ALverbState, ALeffectState, effect); + ALreverbState *State = STATIC_UPCAST(ALreverbState, ALeffectState, effect); ALuint frequency = Device->Frequency; - ALboolean isEAX = AL_FALSE; ALfloat cw, x, y, hfRatio; if(Slot->effect.type == AL_EFFECT_EAXREVERB && !EmulateEAXReverb) - { - STATIC_CAST(ALeffectState, State)->Process = EAXVerbProcess; - isEAX = AL_TRUE; - } + State->IsEax = AL_TRUE; else if(Slot->effect.type == AL_EFFECT_REVERB || EmulateEAXReverb) - { - STATIC_CAST(ALeffectState, State)->Process = VerbProcess; - isEAX = AL_FALSE; - } + State->IsEax = AL_FALSE; // Calculate the master low-pass filter (from the master effect HF gain). - if(isEAX) cw = CalcI3DL2HFreq(Slot->effect.Reverb.HFReference, frequency); - else cw = CalcI3DL2HFreq(LOWPASSFREQREF, frequency); + if(State->IsEax) + cw = CalcI3DL2HFreq(Slot->effect.Reverb.HFReference, frequency); + else + cw = CalcI3DL2HFreq(LOWPASSFREQREF, frequency); // This is done with 2 chained 1-pole filters, so no need to square g. State->LpFilter.coeff = lpCoeffCalc(Slot->effect.Reverb.GainHF, cw); - if(isEAX) + if(State->IsEax) { // Update the modulator line. UpdateModulator(Slot->effect.Reverb.ModulationTime, @@ -1140,7 +1143,7 @@ static ALvoid ReverbUpdate(ALeffectState *effect, ALCdevice *Device, const ALeff x, Slot->effect.Reverb.Density, Slot->effect.Reverb.DecayTime, Slot->effect.Reverb.Diffusion, hfRatio, cw, frequency, State); - if(isEAX) + if(State->IsEax) { // Update the echo line. UpdateEchoLine(Slot->effect.Reverb.Gain, Slot->effect.Reverb.LateReverbGain, @@ -1171,9 +1174,9 @@ static ALvoid ReverbUpdate(ALeffectState *effect, ALCdevice *Device, const ALeff // This destroys the reverb state. It should be called only when the effect // slot has a different (or no) effect loaded over the reverb effect. -static ALvoid ReverbDestroy(ALeffectState *effect) +static ALvoid ALreverbState_Destroy(ALeffectState *effect) { - ALverbState *State = STATIC_UPCAST(ALverbState, ALeffectState, effect); + ALreverbState *State = STATIC_UPCAST(ALreverbState, ALeffectState, effect); free(State->SampleBuffer); State->SampleBuffer = NULL; @@ -1181,21 +1184,18 @@ static ALvoid ReverbDestroy(ALeffectState *effect) free(State); } +DEFINE_ALEFFECTSTATE_VTABLE(ALreverbState); + // This creates the reverb state. It should be called only when the reverb // effect is loaded into a slot that doesn't already have a reverb effect. ALeffectState *ReverbCreate(void) { - ALverbState *State = NULL; + ALreverbState *State = NULL; ALuint index; - State = malloc(sizeof(ALverbState)); - if(!State) - return NULL; - - STATIC_CAST(ALeffectState, State)->Destroy = ReverbDestroy; - STATIC_CAST(ALeffectState, State)->DeviceUpdate = ReverbDeviceUpdate; - STATIC_CAST(ALeffectState, State)->Update = ReverbUpdate; - STATIC_CAST(ALeffectState, State)->Process = VerbProcess; + State = malloc(sizeof(ALreverbState)); + if(!State) return NULL; + SET_VTABLE2(ALreverbState, ALeffectState, State); State->TotalSamples = 0; State->SampleBuffer = NULL; |