diff --git a/Alc/alcChorus.c b/Alc/alcChorus.c index 5a25d4d1..6a56cf68 100644 --- a/Alc/alcChorus.c +++ b/Alc/alcChorus.c @@ -31,8 +31,7 @@ typedef struct ALchorusState { - // Must be first in all effects! - ALeffectState state; + DERIVE_FROM_TYPE(ALeffectState); ALfloat *SampleBufferLeft; ALfloat *SampleBufferRight; @@ -56,8 +55,7 @@ typedef struct ALchorusState { static ALvoid ChorusDestroy(ALeffectState *effect) { - ALchorusState *state = (ALchorusState*)effect; - + ALchorusState *state = GET_PARENT_TYPE(ALchorusState, ALeffectState, effect); if(state) { free(state->SampleBufferLeft); @@ -72,7 +70,7 @@ static ALvoid ChorusDestroy(ALeffectState *effect) static ALboolean ChorusDeviceUpdate(ALeffectState *effect, ALCdevice *Device) { - ALchorusState *state = (ALchorusState*)effect; + ALchorusState *state = GET_PARENT_TYPE(ALchorusState, ALeffectState, effect); ALuint maxlen; ALuint it; @@ -113,7 +111,7 @@ static ALboolean ChorusDeviceUpdate(ALeffectState *effect, ALCdevice *Device) static ALvoid ChorusUpdate(ALeffectState *effect, ALCdevice *Device, const ALeffectslot *Slot) { - ALchorusState *state = (ALchorusState*)effect; + ALchorusState *state = GET_PARENT_TYPE(ALchorusState, ALeffectState, effect); ALuint it; for (it = 0; it < MaxChannels; it++) @@ -173,7 +171,7 @@ static ALvoid ChorusUpdate(ALeffectState *effect, ALCdevice *Device, const ALeff static ALvoid ChorusProcess(ALeffectState *effect, ALuint SamplesToDo, const ALfloat *RESTRICT SamplesIn, ALfloat (*RESTRICT SamplesOut)[BUFFERSIZE]) { - ALchorusState *state = (ALchorusState*)effect; + ALchorusState *state = GET_PARENT_TYPE(ALchorusState, ALeffectState, effect); const ALuint mask = state->BufferLength-1; ALuint it; ALuint kt; @@ -257,17 +255,17 @@ ALeffectState *ChorusCreate(void) if(!state) return NULL; - state->state.Destroy = ChorusDestroy; - state->state.DeviceUpdate = ChorusDeviceUpdate; - state->state.Update = ChorusUpdate; - state->state.Process = ChorusProcess; + GET_DERIVED_TYPE(ALeffectState, state)->Destroy = ChorusDestroy; + GET_DERIVED_TYPE(ALeffectState, state)->DeviceUpdate = ChorusDeviceUpdate; + GET_DERIVED_TYPE(ALeffectState, state)->Update = ChorusUpdate; + GET_DERIVED_TYPE(ALeffectState, state)->Process = ChorusProcess; state->BufferLength = 0; state->SampleBufferLeft = NULL; state->SampleBufferRight = NULL; state->offset = 0; - return &state->state; + return GET_DERIVED_TYPE(ALeffectState, state); } void chorus_SetParami(ALeffect *effect, ALCcontext *context, ALenum param, ALint val) diff --git a/Alc/alcDedicated.c b/Alc/alcDedicated.c index d73d8959..e10ad9e9 100644 --- a/Alc/alcDedicated.c +++ b/Alc/alcDedicated.c @@ -30,8 +30,7 @@ typedef struct ALdedicatedState { - // Must be first in all effects! - ALeffectState state; + DERIVE_FROM_TYPE(ALeffectState); ALfloat gains[MaxChannels]; } ALdedicatedState; @@ -39,7 +38,7 @@ typedef struct ALdedicatedState { static ALvoid DedicatedDestroy(ALeffectState *effect) { - ALdedicatedState *state = (ALdedicatedState*)effect; + ALdedicatedState *state = GET_PARENT_TYPE(ALdedicatedState, ALeffectState, effect); free(state); } @@ -52,7 +51,7 @@ static ALboolean DedicatedDeviceUpdate(ALeffectState *effect, ALCdevice *Device) static ALvoid DedicatedUpdate(ALeffectState *effect, ALCdevice *device, const ALeffectslot *Slot) { - ALdedicatedState *state = (ALdedicatedState*)effect; + ALdedicatedState *state = GET_PARENT_TYPE(ALdedicatedState, ALeffectState, effect); ALfloat Gain; ALsizei s; @@ -68,7 +67,7 @@ static ALvoid DedicatedUpdate(ALeffectState *effect, ALCdevice *device, const AL static ALvoid DedicatedProcess(ALeffectState *effect, ALuint SamplesToDo, const ALfloat *RESTRICT SamplesIn, ALfloat (*RESTRICT SamplesOut)[BUFFERSIZE]) { - ALdedicatedState *state = (ALdedicatedState*)effect; + ALdedicatedState *state = GET_PARENT_TYPE(ALdedicatedState, ALeffectState, effect); const ALfloat *gains = state->gains; ALuint i, c; @@ -88,15 +87,15 @@ ALeffectState *DedicatedCreate(void) if(!state) return NULL; - state->state.Destroy = DedicatedDestroy; - state->state.DeviceUpdate = DedicatedDeviceUpdate; - state->state.Update = DedicatedUpdate; - state->state.Process = DedicatedProcess; + GET_DERIVED_TYPE(ALeffectState, state)->Destroy = DedicatedDestroy; + GET_DERIVED_TYPE(ALeffectState, state)->DeviceUpdate = DedicatedDeviceUpdate; + GET_DERIVED_TYPE(ALeffectState, state)->Update = DedicatedUpdate; + GET_DERIVED_TYPE(ALeffectState, state)->Process = DedicatedProcess; for(s = 0;s < MaxChannels;s++) state->gains[s] = 0.0f; - return &state->state; + return GET_DERIVED_TYPE(ALeffectState, state); } void ded_SetParami(ALeffect *effect, ALCcontext *context, ALenum param, ALint val) diff --git a/Alc/alcDistortion.c b/Alc/alcDistortion.c index 59ccca73..05833680 100644 --- a/Alc/alcDistortion.c +++ b/Alc/alcDistortion.c @@ -47,8 +47,7 @@ typedef struct ALEQFilter { } ALEQFilter; typedef struct ALdistortionState { - /* Must be first in all effects! */ - ALeffectState state; + DERIVE_FROM_TYPE(ALeffectState); /* Effect gains for each channel */ ALfloat Gain[MaxChannels]; @@ -66,14 +65,13 @@ typedef struct ALdistortionState { static ALvoid DistortionDestroy(ALeffectState *effect) { - ALdistortionState *state = (ALdistortionState*)effect; - + ALdistortionState *state = GET_PARENT_TYPE(ALdistortionState, ALeffectState, effect); free(state); } static ALboolean DistortionDeviceUpdate(ALeffectState *effect, ALCdevice *Device) { - ALdistortionState *state = (ALdistortionState*)effect; + ALdistortionState *state = GET_PARENT_TYPE(ALdistortionState, ALeffectState, effect); state->frequency = (ALfloat)Device->Frequency; @@ -82,7 +80,7 @@ static ALboolean DistortionDeviceUpdate(ALeffectState *effect, ALCdevice *Device static ALvoid DistortionUpdate(ALeffectState *effect, ALCdevice *Device, const ALeffectslot *Slot) { - ALdistortionState *state = (ALdistortionState*)effect; + ALdistortionState *state = GET_PARENT_TYPE(ALdistortionState, ALeffectState, effect); ALfloat gain = sqrtf(1.0f / Device->NumChan) * Slot->Gain; ALuint it; ALfloat w0; @@ -135,7 +133,7 @@ static ALvoid DistortionUpdate(ALeffectState *effect, ALCdevice *Device, const A static ALvoid DistortionProcess(ALeffectState *effect, ALuint SamplesToDo, const ALfloat *RESTRICT SamplesIn, ALfloat (*RESTRICT SamplesOut)[BUFFERSIZE]) { - ALdistortionState *state = (ALdistortionState*)effect; + ALdistortionState *state = GET_PARENT_TYPE(ALdistortionState, ALeffectState, effect); float *RESTRICT oversample_buffer = &state->oversample_buffer[0][0]; ALfloat tempsmp; ALuint it; @@ -222,10 +220,10 @@ ALeffectState *DistortionCreate(void) if(!state) return NULL; - state->state.Destroy = DistortionDestroy; - state->state.DeviceUpdate = DistortionDeviceUpdate; - state->state.Update = DistortionUpdate; - state->state.Process = DistortionProcess; + GET_DERIVED_TYPE(ALeffectState, state)->Destroy = DistortionDestroy; + GET_DERIVED_TYPE(ALeffectState, state)->DeviceUpdate = DistortionDeviceUpdate; + GET_DERIVED_TYPE(ALeffectState, state)->Update = DistortionUpdate; + GET_DERIVED_TYPE(ALeffectState, state)->Process = DistortionProcess; state->bandpass.type = BANDPASS; state->lowpass.type = LOWPASS; @@ -237,7 +235,7 @@ ALeffectState *DistortionCreate(void) state->lowpass.y[0] = 0.0f; state->lowpass.y[1] = 0.0f; - return &state->state; + return GET_DERIVED_TYPE(ALeffectState, state); } void distortion_SetParami(ALeffect *effect, ALCcontext *context, ALenum param, ALint val) diff --git a/Alc/alcEcho.c b/Alc/alcEcho.c index 55a5b599..1d06e68a 100644 --- a/Alc/alcEcho.c +++ b/Alc/alcEcho.c @@ -31,8 +31,7 @@ typedef struct ALechoState { - // Must be first in all effects! - ALeffectState state; + DERIVE_FROM_TYPE(ALeffectState); ALfloat *SampleBuffer; ALuint BufferLength; @@ -54,7 +53,7 @@ typedef struct ALechoState { static ALvoid EchoDestroy(ALeffectState *effect) { - ALechoState *state = (ALechoState*)effect; + ALechoState *state = GET_PARENT_TYPE(ALechoState, ALeffectState, effect); if(state) { free(state->SampleBuffer); @@ -65,7 +64,7 @@ static ALvoid EchoDestroy(ALeffectState *effect) static ALboolean EchoDeviceUpdate(ALeffectState *effect, ALCdevice *Device) { - ALechoState *state = (ALechoState*)effect; + ALechoState *state = GET_PARENT_TYPE(ALechoState, ALeffectState, effect); ALuint maxlen, i; // Use the next power of 2 for the buffer length, so the tap offsets can be @@ -92,7 +91,7 @@ static ALboolean EchoDeviceUpdate(ALeffectState *effect, ALCdevice *Device) static ALvoid EchoUpdate(ALeffectState *effect, ALCdevice *Device, const ALeffectslot *Slot) { - ALechoState *state = (ALechoState*)effect; + ALechoState *state = GET_PARENT_TYPE(ALechoState, ALeffectState, effect); ALuint frequency = Device->Frequency; ALfloat lrpan, cw, g, gain; ALfloat dirGain; @@ -128,7 +127,7 @@ static ALvoid EchoUpdate(ALeffectState *effect, ALCdevice *Device, const ALeffec static ALvoid EchoProcess(ALeffectState *effect, ALuint SamplesToDo, const ALfloat *RESTRICT SamplesIn, ALfloat (*RESTRICT SamplesOut)[BUFFERSIZE]) { - ALechoState *state = (ALechoState*)effect; + ALechoState *state = GET_PARENT_TYPE(ALechoState, ALeffectState, effect); const ALuint mask = state->BufferLength-1; const ALuint tap1 = state->Tap[0].delay; const ALuint tap2 = state->Tap[1].delay; @@ -164,10 +163,10 @@ ALeffectState *EchoCreate(void) if(!state) return NULL; - state->state.Destroy = EchoDestroy; - state->state.DeviceUpdate = EchoDeviceUpdate; - state->state.Update = EchoUpdate; - state->state.Process = EchoProcess; + GET_DERIVED_TYPE(ALeffectState, state)->Destroy = EchoDestroy; + GET_DERIVED_TYPE(ALeffectState, state)->DeviceUpdate = EchoDeviceUpdate; + GET_DERIVED_TYPE(ALeffectState, state)->Update = EchoUpdate; + GET_DERIVED_TYPE(ALeffectState, state)->Process = EchoProcess; state->BufferLength = 0; state->SampleBuffer = NULL; @@ -180,7 +179,7 @@ ALeffectState *EchoCreate(void) state->iirFilter.history[0] = 0.0f; state->iirFilter.history[1] = 0.0f; - return &state->state; + return GET_DERIVED_TYPE(ALeffectState, state); } void echo_SetParami(ALeffect *effect, ALCcontext *context, ALenum param, ALint val) diff --git a/Alc/alcEqualizer.c b/Alc/alcEqualizer.c index dffc431a..c10eba2a 100644 --- a/Alc/alcEqualizer.c +++ b/Alc/alcEqualizer.c @@ -85,8 +85,7 @@ typedef struct ALEQFilter { } ALEQFilter; typedef struct ALequalizerState { - /* Must be first in all effects! */ - ALeffectState state; + DERIVE_FROM_TYPE(ALeffectState); /* Effect gains for each channel */ ALfloat Gain[MaxChannels]; @@ -98,14 +97,13 @@ typedef struct ALequalizerState { static ALvoid EqualizerDestroy(ALeffectState *effect) { - ALequalizerState *state = (ALequalizerState*)effect; - + ALequalizerState *state = GET_PARENT_TYPE(ALequalizerState, ALeffectState, effect); free(state); } static ALboolean EqualizerDeviceUpdate(ALeffectState *effect, ALCdevice *Device) { - ALequalizerState *state = (ALequalizerState*)effect; + ALequalizerState *state = GET_PARENT_TYPE(ALequalizerState, ALeffectState, effect); state->frequency = (ALfloat)Device->Frequency; @@ -114,7 +112,7 @@ static ALboolean EqualizerDeviceUpdate(ALeffectState *effect, ALCdevice *Device) static ALvoid EqualizerUpdate(ALeffectState *effect, ALCdevice *Device, const ALeffectslot *Slot) { - ALequalizerState *state = (ALequalizerState*)effect; + ALequalizerState *state = GET_PARENT_TYPE(ALequalizerState, ALeffectState, effect); ALfloat gain = sqrtf(1.0f / Device->NumChan) * Slot->Gain; ALuint it; @@ -215,7 +213,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]) { - ALequalizerState *state = (ALequalizerState*)effect; + ALequalizerState *state = GET_PARENT_TYPE(ALequalizerState, ALeffectState, effect); ALuint it; ALuint kt; ALuint ft; @@ -254,10 +252,10 @@ ALeffectState *EqualizerCreate(void) if(!state) return NULL; - state->state.Destroy = EqualizerDestroy; - state->state.DeviceUpdate = EqualizerDeviceUpdate; - state->state.Update = EqualizerUpdate; - state->state.Process = EqualizerProcess; + GET_DERIVED_TYPE(ALeffectState, state)->Destroy = EqualizerDestroy; + GET_DERIVED_TYPE(ALeffectState, state)->DeviceUpdate = EqualizerDeviceUpdate; + GET_DERIVED_TYPE(ALeffectState, state)->Update = EqualizerUpdate; + GET_DERIVED_TYPE(ALeffectState, state)->Process = EqualizerProcess; state->bandfilter[0].type = LOW_SHELF; state->bandfilter[1].type = PEAKING; @@ -274,7 +272,7 @@ ALeffectState *EqualizerCreate(void) state->bandfilter[it].y[1] = 0.0f; } - return &state->state; + return GET_DERIVED_TYPE(ALeffectState, state); } void equalizer_SetParami(ALeffect *effect, ALCcontext *context, ALenum param, ALint val) diff --git a/Alc/alcFlanger.c b/Alc/alcFlanger.c index d5764706..5b643a46 100644 --- a/Alc/alcFlanger.c +++ b/Alc/alcFlanger.c @@ -31,8 +31,7 @@ typedef struct ALflangerState { - // Must be first in all effects! - ALeffectState state; + DERIVE_FROM_TYPE(ALeffectState); ALfloat *SampleBufferLeft; ALfloat *SampleBufferRight; @@ -56,8 +55,7 @@ typedef struct ALflangerState { static ALvoid FlangerDestroy(ALeffectState *effect) { - ALflangerState *state = (ALflangerState*)effect; - + ALflangerState *state = GET_PARENT_TYPE(ALflangerState, ALeffectState, effect); if(state) { free(state->SampleBufferLeft); @@ -72,7 +70,7 @@ static ALvoid FlangerDestroy(ALeffectState *effect) static ALboolean FlangerDeviceUpdate(ALeffectState *effect, ALCdevice *Device) { - ALflangerState *state = (ALflangerState*)effect; + ALflangerState *state = GET_PARENT_TYPE(ALflangerState, ALeffectState, effect); ALuint maxlen; ALuint it; @@ -113,7 +111,7 @@ static ALboolean FlangerDeviceUpdate(ALeffectState *effect, ALCdevice *Device) static ALvoid FlangerUpdate(ALeffectState *effect, ALCdevice *Device, const ALeffectslot *Slot) { - ALflangerState *state = (ALflangerState*)effect; + ALflangerState *state = GET_PARENT_TYPE(ALflangerState, ALeffectState, effect); ALuint it; for (it = 0; it < MaxChannels; it++) @@ -173,7 +171,7 @@ static ALvoid FlangerUpdate(ALeffectState *effect, ALCdevice *Device, const ALef static ALvoid FlangerProcess(ALeffectState *effect, ALuint SamplesToDo, const ALfloat *RESTRICT SamplesIn, ALfloat (*RESTRICT SamplesOut)[BUFFERSIZE]) { - ALflangerState *state = (ALflangerState*)effect; + ALflangerState *state = GET_PARENT_TYPE(ALflangerState, ALeffectState, effect); const ALuint mask = state->BufferLength-1; ALuint it; ALuint kt; @@ -257,17 +255,17 @@ ALeffectState *FlangerCreate(void) if(!state) return NULL; - state->state.Destroy = FlangerDestroy; - state->state.DeviceUpdate = FlangerDeviceUpdate; - state->state.Update = FlangerUpdate; - state->state.Process = FlangerProcess; + GET_DERIVED_TYPE(ALeffectState, state)->Destroy = FlangerDestroy; + GET_DERIVED_TYPE(ALeffectState, state)->DeviceUpdate = FlangerDeviceUpdate; + GET_DERIVED_TYPE(ALeffectState, state)->Update = FlangerUpdate; + GET_DERIVED_TYPE(ALeffectState, state)->Process = FlangerProcess; state->BufferLength = 0; state->SampleBufferLeft = NULL; state->SampleBufferRight = NULL; state->offset = 0; - return &state->state; + return GET_DERIVED_TYPE(ALeffectState, state); } void flanger_SetParami(ALeffect *effect, ALCcontext *context, ALenum param, ALint val) diff --git a/Alc/alcModulator.c b/Alc/alcModulator.c index f1f8dadd..d33811ba 100644 --- a/Alc/alcModulator.c +++ b/Alc/alcModulator.c @@ -31,8 +31,7 @@ typedef struct ALmodulatorState { - // Must be first in all effects! - ALeffectState state; + DERIVE_FROM_TYPE(ALeffectState); enum { SINUSOID, @@ -116,7 +115,7 @@ DECL_TEMPLATE(Square) static ALvoid ModulatorDestroy(ALeffectState *effect) { - ALmodulatorState *state = (ALmodulatorState*)effect; + ALmodulatorState *state = GET_PARENT_TYPE(ALmodulatorState, ALeffectState, effect); free(state); } @@ -129,7 +128,7 @@ static ALboolean ModulatorDeviceUpdate(ALeffectState *effect, ALCdevice *Device) static ALvoid ModulatorUpdate(ALeffectState *effect, ALCdevice *Device, const ALeffectslot *Slot) { - ALmodulatorState *state = (ALmodulatorState*)effect; + ALmodulatorState *state = GET_PARENT_TYPE(ALmodulatorState, ALeffectState, effect); ALfloat gain, cw, a = 0.0f; ALuint index; @@ -162,7 +161,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]) { - ALmodulatorState *state = (ALmodulatorState*)effect; + ALmodulatorState *state = GET_PARENT_TYPE(ALmodulatorState, ALeffectState, effect); switch(state->Waveform) { @@ -188,10 +187,10 @@ ALeffectState *ModulatorCreate(void) if(!state) return NULL; - state->state.Destroy = ModulatorDestroy; - state->state.DeviceUpdate = ModulatorDeviceUpdate; - state->state.Update = ModulatorUpdate; - state->state.Process = ModulatorProcess; + GET_DERIVED_TYPE(ALeffectState, state)->Destroy = ModulatorDestroy; + GET_DERIVED_TYPE(ALeffectState, state)->DeviceUpdate = ModulatorDeviceUpdate; + GET_DERIVED_TYPE(ALeffectState, state)->Update = ModulatorUpdate; + GET_DERIVED_TYPE(ALeffectState, state)->Process = ModulatorProcess; state->index = 0; state->step = 1; @@ -199,7 +198,7 @@ ALeffectState *ModulatorCreate(void) state->iirFilter.coeff = 0.0f; state->iirFilter.history[0] = 0.0f; - return &state->state; + return GET_DERIVED_TYPE(ALeffectState, state); } void mod_SetParamf(ALeffect *effect, ALCcontext *context, ALenum param, ALfloat val) diff --git a/Alc/alcReverb.c b/Alc/alcReverb.c index ab52ae77..ac9af905 100644 --- a/Alc/alcReverb.c +++ b/Alc/alcReverb.c @@ -40,8 +40,7 @@ typedef struct DelayLine } DelayLine; typedef struct ALverbState { - // Must be first in all effects! - ALeffectState state; + DERIVE_FROM_TYPE(ALeffectState); // All delay lines are allocated as a single buffer to reduce memory // fragmentation and management code. @@ -557,7 +556,7 @@ static __inline ALvoid EAXVerbPass(ALverbState *State, ALfloat in, ALfloat *REST // buffer. static ALvoid VerbProcess(ALeffectState *effect, ALuint SamplesToDo, const ALfloat *RESTRICT SamplesIn, ALfloat (*RESTRICT SamplesOut)[BUFFERSIZE]) { - ALverbState *State = (ALverbState*)effect; + ALverbState *State = GET_PARENT_TYPE(ALverbState, ALeffectState, effect); ALfloat (*RESTRICT out)[4] = State->ReverbSamples; ALuint index, c; @@ -580,7 +579,7 @@ static ALvoid VerbProcess(ALeffectState *effect, ALuint SamplesToDo, const ALflo // buffer. static ALvoid EAXVerbProcess(ALeffectState *effect, ALuint SamplesToDo, const ALfloat *RESTRICT SamplesIn, ALfloat (*RESTRICT SamplesOut)[BUFFERSIZE]) { - ALverbState *State = (ALverbState*)effect; + ALverbState *State = GET_PARENT_TYPE(ALverbState, ALeffectState, effect); ALfloat (*RESTRICT early)[4] = State->EarlySamples; ALfloat (*RESTRICT late)[4] = State->ReverbSamples; ALuint index, c; @@ -727,7 +726,7 @@ static ALboolean AllocLines(ALuint frequency, ALverbState *State) // format) have been changed. static ALboolean ReverbDeviceUpdate(ALeffectState *effect, ALCdevice *Device) { - ALverbState *State = (ALverbState*)effect; + ALverbState *State = GET_PARENT_TYPE(ALverbState, ALeffectState, effect); ALuint frequency = Device->Frequency, index; // Allocate the delay lines. @@ -1079,19 +1078,19 @@ static ALvoid Update3DPanning(const ALCdevice *Device, const ALfloat *Reflection // effect is loaded into a slot. static ALvoid ReverbUpdate(ALeffectState *effect, ALCdevice *Device, const ALeffectslot *Slot) { - ALverbState *State = (ALverbState*)effect; + ALverbState *State = GET_PARENT_TYPE(ALverbState, ALeffectState, effect); ALuint frequency = Device->Frequency; ALboolean isEAX = AL_FALSE; ALfloat cw, x, y, hfRatio; if(Slot->effect.type == AL_EFFECT_EAXREVERB && !EmulateEAXReverb) { - State->state.Process = EAXVerbProcess; + GET_DERIVED_TYPE(ALeffectState, State)->Process = EAXVerbProcess; isEAX = AL_TRUE; } else if(Slot->effect.type == AL_EFFECT_REVERB || EmulateEAXReverb) { - State->state.Process = VerbProcess; + GET_DERIVED_TYPE(ALeffectState, State)->Process = VerbProcess; isEAX = AL_FALSE; } @@ -1174,7 +1173,7 @@ static ALvoid ReverbUpdate(ALeffectState *effect, ALCdevice *Device, const ALeff // slot has a different (or no) effect loaded over the reverb effect. static ALvoid ReverbDestroy(ALeffectState *effect) { - ALverbState *State = (ALverbState*)effect; + ALverbState *State = GET_PARENT_TYPE(ALverbState, ALeffectState, effect); if(State) { free(State->SampleBuffer); @@ -1194,10 +1193,10 @@ ALeffectState *ReverbCreate(void) if(!State) return NULL; - State->state.Destroy = ReverbDestroy; - State->state.DeviceUpdate = ReverbDeviceUpdate; - State->state.Update = ReverbUpdate; - State->state.Process = VerbProcess; + GET_DERIVED_TYPE(ALeffectState, State)->Destroy = ReverbDestroy; + GET_DERIVED_TYPE(ALeffectState, State)->DeviceUpdate = ReverbDeviceUpdate; + GET_DERIVED_TYPE(ALeffectState, State)->Update = ReverbUpdate; + GET_DERIVED_TYPE(ALeffectState, State)->Process = VerbProcess; State->TotalSamples = 0; State->SampleBuffer = NULL; @@ -1279,7 +1278,7 @@ ALeffectState *ReverbCreate(void) State->Gain = State->Late.PanGain; - return &State->state; + return GET_DERIVED_TYPE(ALeffectState, State); } void eaxreverb_SetParami(ALeffect *effect, ALCcontext *context, ALenum param, ALint val) diff --git a/OpenAL32/Include/alMain.h b/OpenAL32/Include/alMain.h index d234ae13..a1a90b2f 100644 --- a/OpenAL32/Include/alMain.h +++ b/OpenAL32/Include/alMain.h @@ -62,6 +62,10 @@ static const union { #define COUNTOF(x) (sizeof((x))/sizeof((x)[0])) +#define DERIVE_FROM_TYPE(t) t t##_parent +#define GET_DERIVED_TYPE(t, o) (&(o)->t##_parent) +#define GET_PARENT_TYPE(t1, t2, o) ((t1*)((char*)(o) - offsetof(t1, t2##_parent))) + #ifdef _WIN32 #define WIN32_LEAN_AND_MEAN