diff options
author | Sven Gothel <[email protected]> | 2014-01-26 07:06:02 +0100 |
---|---|---|
committer | Sven Gothel <[email protected]> | 2014-01-26 07:06:02 +0100 |
commit | e6f4251945c228a775649b5ccd7f11dd4519c28d (patch) | |
tree | 8454b34363358cf9bb502021a68c6985c97daac4 /OpenAL32/alAuxEffectSlot.c | |
parent | 389ae1f767bfad6116e21306fc3cdf89a4cbcc0a (diff) | |
parent | 49baa9128dd98e986639def4f24c7522d9ec6b56 (diff) |
Merge branch 'UPSTREAM'
Diffstat (limited to 'OpenAL32/alAuxEffectSlot.c')
-rw-r--r-- | OpenAL32/alAuxEffectSlot.c | 625 |
1 files changed, 291 insertions, 334 deletions
diff --git a/OpenAL32/alAuxEffectSlot.c b/OpenAL32/alAuxEffectSlot.c index 230fe5fc..aa071de2 100644 --- a/OpenAL32/alAuxEffectSlot.c +++ b/OpenAL32/alAuxEffectSlot.c @@ -32,538 +32,491 @@ #include "alSource.h" +extern inline struct ALeffectslot *LookupEffectSlot(ALCcontext *context, ALuint id); +extern inline struct ALeffectslot *RemoveEffectSlot(ALCcontext *context, ALuint id); + static ALenum AddEffectSlotArray(ALCcontext *Context, ALsizei count, const ALuint *slots); static ALvoid RemoveEffectSlotArray(ALCcontext *Context, ALeffectslot *slot); +static UIntMap EffectStateFactoryMap; +static inline ALeffectStateFactory *getFactoryByType(ALenum type) +{ + ALeffectStateFactory* (*getFactory)(void) = LookupUIntMapKey(&EffectStateFactoryMap, type); + if(getFactory != NULL) + return getFactory(); + return NULL; +} + + AL_API ALvoid AL_APIENTRY alGenAuxiliaryEffectSlots(ALsizei n, ALuint *effectslots) { - ALCcontext *Context; - ALsizei cur = 0; + ALCcontext *context; + ALsizei cur; + ALenum err; - Context = GetContextRef(); - if(!Context) return; + context = GetContextRef(); + if(!context) return; - al_try + if(!(n >= 0)) + SET_ERROR_AND_GOTO(context, AL_INVALID_VALUE, done); + for(cur = 0;cur < n;cur++) { - ALenum err; - - CHECK_VALUE(Context, n >= 0); - for(cur = 0;cur < n;cur++) + ALeffectslot *slot = al_calloc(16, sizeof(ALeffectslot)); + err = AL_OUT_OF_MEMORY; + if(!slot || (err=InitEffectSlot(slot)) != AL_NO_ERROR) { - ALeffectslot *slot = al_calloc(16, sizeof(ALeffectslot)); - err = AL_OUT_OF_MEMORY; - if(!slot || (err=InitEffectSlot(slot)) != AL_NO_ERROR) - { - al_free(slot); - al_throwerr(Context, err); - break; - } - - err = NewThunkEntry(&slot->id); - if(err == AL_NO_ERROR) - err = InsertUIntMapEntry(&Context->EffectSlotMap, slot->id, slot); - if(err != AL_NO_ERROR) - { - FreeThunkEntry(slot->id); - ALeffectState_Destroy(slot->EffectState); - al_free(slot); - - al_throwerr(Context, err); - } - - effectslots[cur] = slot->id; + al_free(slot); + alDeleteAuxiliaryEffectSlots(cur, effectslots); + SET_ERROR_AND_GOTO(context, err, done); } - err = AddEffectSlotArray(Context, n, effectslots); + + err = NewThunkEntry(&slot->id); + if(err == AL_NO_ERROR) + err = InsertUIntMapEntry(&context->EffectSlotMap, slot->id, slot); if(err != AL_NO_ERROR) - al_throwerr(Context, err); + { + FreeThunkEntry(slot->id); + DELETE_OBJ(slot->EffectState); + al_free(slot); + + alDeleteAuxiliaryEffectSlots(cur, effectslots); + SET_ERROR_AND_GOTO(context, err, done); + } + + effectslots[cur] = slot->id; } - al_catchany() + err = AddEffectSlotArray(context, n, effectslots); + if(err != AL_NO_ERROR) { - if(cur > 0) - alDeleteAuxiliaryEffectSlots(cur, effectslots); + alDeleteAuxiliaryEffectSlots(cur, effectslots); + SET_ERROR_AND_GOTO(context, err, done); } - al_endtry; - ALCcontext_DecRef(Context); +done: + ALCcontext_DecRef(context); } AL_API ALvoid AL_APIENTRY alDeleteAuxiliaryEffectSlots(ALsizei n, const ALuint *effectslots) { - ALCcontext *Context; + ALCcontext *context; ALeffectslot *slot; ALsizei i; - Context = GetContextRef(); - if(!Context) return; + context = GetContextRef(); + if(!context) return; - al_try + if(!(n >= 0)) + SET_ERROR_AND_GOTO(context, AL_INVALID_VALUE, done); + for(i = 0;i < n;i++) { - CHECK_VALUE(Context, n >= 0); - for(i = 0;i < n;i++) - { - if((slot=LookupEffectSlot(Context, effectslots[i])) == NULL) - al_throwerr(Context, AL_INVALID_NAME); - if(slot->ref != 0) - al_throwerr(Context, AL_INVALID_OPERATION); - } + if((slot=LookupEffectSlot(context, effectslots[i])) == NULL) + SET_ERROR_AND_GOTO(context, AL_INVALID_NAME, done); + if(slot->ref != 0) + SET_ERROR_AND_GOTO(context, AL_INVALID_OPERATION, done); + } - // All effectslots are valid - for(i = 0;i < n;i++) - { - if((slot=RemoveEffectSlot(Context, effectslots[i])) == NULL) - continue; - FreeThunkEntry(slot->id); + // All effectslots are valid + for(i = 0;i < n;i++) + { + if((slot=RemoveEffectSlot(context, effectslots[i])) == NULL) + continue; + FreeThunkEntry(slot->id); - RemoveEffectSlotArray(Context, slot); - ALeffectState_Destroy(slot->EffectState); + RemoveEffectSlotArray(context, slot); + DELETE_OBJ(slot->EffectState); - memset(slot, 0, sizeof(*slot)); - al_free(slot); - } + memset(slot, 0, sizeof(*slot)); + al_free(slot); } - al_endtry; - ALCcontext_DecRef(Context); +done: + ALCcontext_DecRef(context); } AL_API ALboolean AL_APIENTRY alIsAuxiliaryEffectSlot(ALuint effectslot) { - ALCcontext *Context; - ALboolean result; + ALCcontext *context; + ALboolean ret; - Context = GetContextRef(); - if(!Context) return AL_FALSE; + context = GetContextRef(); + if(!context) return AL_FALSE; - result = (LookupEffectSlot(Context, effectslot) ? AL_TRUE : AL_FALSE); + ret = (LookupEffectSlot(context, effectslot) ? AL_TRUE : AL_FALSE); - ALCcontext_DecRef(Context); + ALCcontext_DecRef(context); - return result; + return ret; } AL_API ALvoid AL_APIENTRY alAuxiliaryEffectSloti(ALuint effectslot, ALenum param, ALint value) { - ALCcontext *Context; - ALeffectslot *Slot; + ALCdevice *device; + ALCcontext *context; + ALeffectslot *slot; ALeffect *effect = NULL; ALenum err; - Context = GetContextRef(); - if(!Context) return; + context = GetContextRef(); + if(!context) return; - al_try + device = context->Device; + if((slot=LookupEffectSlot(context, effectslot)) == NULL) + SET_ERROR_AND_GOTO(context, AL_INVALID_NAME, done); + switch(param) { - ALCdevice *device = Context->Device; - if((Slot=LookupEffectSlot(Context, effectslot)) == NULL) - al_throwerr(Context, AL_INVALID_NAME); - switch(param) - { - case AL_EFFECTSLOT_EFFECT: - CHECK_VALUE(Context, value == 0 || (effect=LookupEffect(device, value)) != NULL); + case AL_EFFECTSLOT_EFFECT: + effect = (value ? LookupEffect(device, value) : NULL); + if(!(value == 0 || effect != NULL)) + SET_ERROR_AND_GOTO(context, AL_INVALID_VALUE, done); - err = InitializeEffect(device, Slot, effect); - if(err != AL_NO_ERROR) - al_throwerr(Context, err); - Context->UpdateSources = AL_TRUE; - break; + err = InitializeEffect(device, slot, effect); + if(err != AL_NO_ERROR) + SET_ERROR_AND_GOTO(context, err, done); + context->UpdateSources = AL_TRUE; + break; - case AL_EFFECTSLOT_AUXILIARY_SEND_AUTO: - CHECK_VALUE(Context, value == AL_TRUE || value == AL_FALSE); + case AL_EFFECTSLOT_AUXILIARY_SEND_AUTO: + if(!(value == AL_TRUE || value == AL_FALSE)) + SET_ERROR_AND_GOTO(context, AL_INVALID_VALUE, done); - Slot->AuxSendAuto = value; - Context->UpdateSources = AL_TRUE; - break; + slot->AuxSendAuto = value; + context->UpdateSources = AL_TRUE; + break; - default: - al_throwerr(Context, AL_INVALID_ENUM); - } + default: + SET_ERROR_AND_GOTO(context, AL_INVALID_ENUM, done); } - al_endtry; - ALCcontext_DecRef(Context); +done: + ALCcontext_DecRef(context); } AL_API ALvoid AL_APIENTRY alAuxiliaryEffectSlotiv(ALuint effectslot, ALenum param, const ALint *values) { - ALCcontext *Context; + ALCcontext *context; switch(param) { - case AL_EFFECTSLOT_EFFECT: - case AL_EFFECTSLOT_AUXILIARY_SEND_AUTO: - alAuxiliaryEffectSloti(effectslot, param, values[0]); - return; + case AL_EFFECTSLOT_EFFECT: + case AL_EFFECTSLOT_AUXILIARY_SEND_AUTO: + alAuxiliaryEffectSloti(effectslot, param, values[0]); + return; } - Context = GetContextRef(); - if(!Context) return; + context = GetContextRef(); + if(!context) return; - al_try + if(LookupEffectSlot(context, effectslot) == NULL) + SET_ERROR_AND_GOTO(context, AL_INVALID_NAME, done); + switch(param) { - if(LookupEffectSlot(Context, effectslot) == NULL) - al_throwerr(Context, AL_INVALID_NAME); - switch(param) - { - default: - al_throwerr(Context, AL_INVALID_ENUM); - } + default: + SET_ERROR_AND_GOTO(context, AL_INVALID_ENUM, done); } - al_endtry; - ALCcontext_DecRef(Context); +done: + ALCcontext_DecRef(context); } AL_API ALvoid AL_APIENTRY alAuxiliaryEffectSlotf(ALuint effectslot, ALenum param, ALfloat value) { - ALCcontext *Context; - ALeffectslot *Slot; + ALCcontext *context; + ALeffectslot *slot; - Context = GetContextRef(); - if(!Context) return; + context = GetContextRef(); + if(!context) return; - al_try + if((slot=LookupEffectSlot(context, effectslot)) == NULL) + SET_ERROR_AND_GOTO(context, AL_INVALID_NAME, done); + switch(param) { - if((Slot=LookupEffectSlot(Context, effectslot)) == NULL) - al_throwerr(Context, AL_INVALID_NAME); - switch(param) - { - case AL_EFFECTSLOT_GAIN: - CHECK_VALUE(Context, value >= 0.0f && value <= 1.0f); + case AL_EFFECTSLOT_GAIN: + if(!(value >= 0.0f && value <= 1.0f)) + SET_ERROR_AND_GOTO(context, AL_INVALID_VALUE, done); - Slot->Gain = value; - Slot->NeedsUpdate = AL_TRUE; - break; + slot->Gain = value; + slot->NeedsUpdate = AL_TRUE; + break; - default: - al_throwerr(Context, AL_INVALID_ENUM); - } + default: + SET_ERROR_AND_GOTO(context, AL_INVALID_ENUM, done); } - al_endtry; - ALCcontext_DecRef(Context); +done: + ALCcontext_DecRef(context); } AL_API ALvoid AL_APIENTRY alAuxiliaryEffectSlotfv(ALuint effectslot, ALenum param, const ALfloat *values) { - ALCcontext *Context; + ALCcontext *context; switch(param) { - case AL_EFFECTSLOT_GAIN: - alAuxiliaryEffectSlotf(effectslot, param, values[0]); - return; + case AL_EFFECTSLOT_GAIN: + alAuxiliaryEffectSlotf(effectslot, param, values[0]); + return; } - Context = GetContextRef(); - if(!Context) return; + context = GetContextRef(); + if(!context) return; - al_try + if(LookupEffectSlot(context, effectslot) == NULL) + SET_ERROR_AND_GOTO(context, AL_INVALID_NAME, done); + switch(param) { - if(LookupEffectSlot(Context, effectslot) == NULL) - al_throwerr(Context, AL_INVALID_NAME); - switch(param) - { - default: - al_throwerr(Context, AL_INVALID_ENUM); - } + default: + SET_ERROR_AND_GOTO(context, AL_INVALID_ENUM, done); } - al_endtry; - ALCcontext_DecRef(Context); +done: + ALCcontext_DecRef(context); } AL_API ALvoid AL_APIENTRY alGetAuxiliaryEffectSloti(ALuint effectslot, ALenum param, ALint *value) { - ALCcontext *Context; - ALeffectslot *Slot; + ALCcontext *context; + ALeffectslot *slot; - Context = GetContextRef(); - if(!Context) return; + context = GetContextRef(); + if(!context) return; - al_try + if((slot=LookupEffectSlot(context, effectslot)) == NULL) + SET_ERROR_AND_GOTO(context, AL_INVALID_NAME, done); + switch(param) { - if((Slot=LookupEffectSlot(Context, effectslot)) == NULL) - al_throwerr(Context, AL_INVALID_NAME); - switch(param) - { - case AL_EFFECTSLOT_EFFECT: - *value = Slot->effect.id; - break; - - case AL_EFFECTSLOT_AUXILIARY_SEND_AUTO: - *value = Slot->AuxSendAuto; - break; + case AL_EFFECTSLOT_AUXILIARY_SEND_AUTO: + *value = slot->AuxSendAuto; + break; - default: - al_throwerr(Context, AL_INVALID_ENUM); - } + default: + SET_ERROR_AND_GOTO(context, AL_INVALID_ENUM, done); } - al_endtry; - ALCcontext_DecRef(Context); +done: + ALCcontext_DecRef(context); } AL_API ALvoid AL_APIENTRY alGetAuxiliaryEffectSlotiv(ALuint effectslot, ALenum param, ALint *values) { - ALCcontext *Context; + ALCcontext *context; switch(param) { - case AL_EFFECTSLOT_EFFECT: - case AL_EFFECTSLOT_AUXILIARY_SEND_AUTO: - alGetAuxiliaryEffectSloti(effectslot, param, values); - return; + case AL_EFFECTSLOT_EFFECT: + case AL_EFFECTSLOT_AUXILIARY_SEND_AUTO: + alGetAuxiliaryEffectSloti(effectslot, param, values); + return; } - Context = GetContextRef(); - if(!Context) return; + context = GetContextRef(); + if(!context) return; - al_try + if(LookupEffectSlot(context, effectslot) == NULL) + SET_ERROR_AND_GOTO(context, AL_INVALID_NAME, done); + switch(param) { - if(LookupEffectSlot(Context, effectslot) == NULL) - al_throwerr(Context, AL_INVALID_NAME); - switch(param) - { - default: - al_throwerr(Context, AL_INVALID_ENUM); - } + default: + SET_ERROR_AND_GOTO(context, AL_INVALID_ENUM, done); } - al_endtry; - ALCcontext_DecRef(Context); +done: + ALCcontext_DecRef(context); } AL_API ALvoid AL_APIENTRY alGetAuxiliaryEffectSlotf(ALuint effectslot, ALenum param, ALfloat *value) { - ALCcontext *Context; - ALeffectslot *Slot; + ALCcontext *context; + ALeffectslot *slot; - Context = GetContextRef(); - if(!Context) return; + context = GetContextRef(); + if(!context) return; - al_try + if((slot=LookupEffectSlot(context, effectslot)) == NULL) + SET_ERROR_AND_GOTO(context, AL_INVALID_NAME, done); + switch(param) { - if((Slot=LookupEffectSlot(Context, effectslot)) == NULL) - al_throwerr(Context, AL_INVALID_NAME); - switch(param) - { - case AL_EFFECTSLOT_GAIN: - *value = Slot->Gain; - break; + case AL_EFFECTSLOT_GAIN: + *value = slot->Gain; + break; - default: - al_throwerr(Context, AL_INVALID_ENUM); - } + default: + SET_ERROR_AND_GOTO(context, AL_INVALID_ENUM, done); } - al_endtry; - ALCcontext_DecRef(Context); +done: + ALCcontext_DecRef(context); } AL_API ALvoid AL_APIENTRY alGetAuxiliaryEffectSlotfv(ALuint effectslot, ALenum param, ALfloat *values) { - ALCcontext *Context; + ALCcontext *context; switch(param) { - case AL_EFFECTSLOT_GAIN: - alGetAuxiliaryEffectSlotf(effectslot, param, values); - return; + case AL_EFFECTSLOT_GAIN: + alGetAuxiliaryEffectSlotf(effectslot, param, values); + return; } - Context = GetContextRef(); - if(!Context) return; + context = GetContextRef(); + if(!context) return; - al_try + if(LookupEffectSlot(context, effectslot) == NULL) + SET_ERROR_AND_GOTO(context, AL_INVALID_NAME, done); + switch(param) { - if(LookupEffectSlot(Context, effectslot) == NULL) - al_throwerr(Context, AL_INVALID_NAME); - switch(param) - { - default: - al_throwerr(Context, AL_INVALID_ENUM); - } + default: + SET_ERROR_AND_GOTO(context, AL_INVALID_ENUM, done); } - al_endtry; - - ALCcontext_DecRef(Context); -} - - -static ALvoid NoneDestroy(ALeffectState *State) -{ free(State); } -static ALboolean NoneDeviceUpdate(ALeffectState *State, ALCdevice *Device) -{ - return AL_TRUE; - (void)State; - (void)Device; -} -static ALvoid NoneUpdate(ALeffectState *State, ALCdevice *Device, const ALeffectslot *Slot) -{ - (void)State; - (void)Device; - (void)Slot; -} -static ALvoid NoneProcess(ALeffectState *State, ALuint SamplesToDo, const ALfloat *RESTRICT SamplesIn, ALfloat (*RESTRICT SamplesOut)[BUFFERSIZE]) -{ - (void)State; - (void)SamplesToDo; - (void)SamplesIn; - (void)SamplesOut; -} -ALeffectState *NoneCreate(void) -{ - ALeffectState *state; - - state = calloc(1, sizeof(*state)); - if(!state) - return NULL; - - state->Destroy = NoneDestroy; - state->DeviceUpdate = NoneDeviceUpdate; - state->Update = NoneUpdate; - state->Process = NoneProcess; - return state; +done: + ALCcontext_DecRef(context); } -static ALvoid RemoveEffectSlotArray(ALCcontext *Context, ALeffectslot *slot) +static ALvoid RemoveEffectSlotArray(ALCcontext *context, ALeffectslot *slot) { ALeffectslot **slotlist, **slotlistend; - LockContext(Context); - slotlist = Context->ActiveEffectSlots; - slotlistend = slotlist + Context->ActiveEffectSlotCount; + LockContext(context); + slotlist = context->ActiveEffectSlots; + slotlistend = slotlist + context->ActiveEffectSlotCount; while(slotlist != slotlistend) { if(*slotlist == slot) { *slotlist = *(--slotlistend); - Context->ActiveEffectSlotCount--; + context->ActiveEffectSlotCount--; break; } slotlist++; } - UnlockContext(Context); + UnlockContext(context); } -static ALenum AddEffectSlotArray(ALCcontext *Context, ALsizei count, const ALuint *slots) +static ALenum AddEffectSlotArray(ALCcontext *context, ALsizei count, const ALuint *slots) { ALsizei i; - LockContext(Context); - if(count > Context->MaxActiveEffectSlots-Context->ActiveEffectSlotCount) + LockContext(context); + if(count > context->MaxActiveEffectSlots-context->ActiveEffectSlotCount) { ALsizei newcount; void *temp = NULL; - newcount = Context->MaxActiveEffectSlots ? (Context->MaxActiveEffectSlots<<1) : 1; - if(newcount > Context->MaxActiveEffectSlots) - temp = realloc(Context->ActiveEffectSlots, - newcount * sizeof(*Context->ActiveEffectSlots)); + newcount = context->MaxActiveEffectSlots ? (context->MaxActiveEffectSlots<<1) : 1; + if(newcount > context->MaxActiveEffectSlots) + temp = realloc(context->ActiveEffectSlots, + newcount * sizeof(*context->ActiveEffectSlots)); if(!temp) { - UnlockContext(Context); + UnlockContext(context); return AL_OUT_OF_MEMORY; } - Context->ActiveEffectSlots = temp; - Context->MaxActiveEffectSlots = newcount; + context->ActiveEffectSlots = temp; + context->MaxActiveEffectSlots = newcount; } for(i = 0;i < count;i++) { - ALeffectslot *slot = LookupEffectSlot(Context, slots[i]); + ALeffectslot *slot = LookupEffectSlot(context, slots[i]); assert(slot != NULL); - Context->ActiveEffectSlots[Context->ActiveEffectSlotCount++] = slot; + context->ActiveEffectSlots[context->ActiveEffectSlotCount++] = slot; } - UnlockContext(Context); + UnlockContext(context); return AL_NO_ERROR; } + +void InitEffectFactoryMap(void) +{ + InitUIntMap(&EffectStateFactoryMap, ~0); + + InsertUIntMapEntry(&EffectStateFactoryMap, AL_EFFECT_NULL, ALnullStateFactory_getFactory); + InsertUIntMapEntry(&EffectStateFactoryMap, AL_EFFECT_EAXREVERB, ALreverbStateFactory_getFactory); + InsertUIntMapEntry(&EffectStateFactoryMap, AL_EFFECT_REVERB, ALreverbStateFactory_getFactory); + InsertUIntMapEntry(&EffectStateFactoryMap, AL_EFFECT_AUTOWAH, ALautowahStateFactory_getFactory); + InsertUIntMapEntry(&EffectStateFactoryMap, AL_EFFECT_CHORUS, ALchorusStateFactory_getFactory); + InsertUIntMapEntry(&EffectStateFactoryMap, AL_EFFECT_COMPRESSOR, ALcompressorStateFactory_getFactory); + InsertUIntMapEntry(&EffectStateFactoryMap, AL_EFFECT_DISTORTION, ALdistortionStateFactory_getFactory); + InsertUIntMapEntry(&EffectStateFactoryMap, AL_EFFECT_ECHO, ALechoStateFactory_getFactory); + InsertUIntMapEntry(&EffectStateFactoryMap, AL_EFFECT_EQUALIZER, ALequalizerStateFactory_getFactory); + InsertUIntMapEntry(&EffectStateFactoryMap, AL_EFFECT_FLANGER, ALflangerStateFactory_getFactory); + InsertUIntMapEntry(&EffectStateFactoryMap, AL_EFFECT_RING_MODULATOR, ALmodulatorStateFactory_getFactory); + InsertUIntMapEntry(&EffectStateFactoryMap, AL_EFFECT_DEDICATED_DIALOGUE, ALdedicatedStateFactory_getFactory); + InsertUIntMapEntry(&EffectStateFactoryMap, AL_EFFECT_DEDICATED_LOW_FREQUENCY_EFFECT, ALdedicatedStateFactory_getFactory); +} + +void DeinitEffectFactoryMap(void) +{ + ResetUIntMap(&EffectStateFactoryMap); +} + + ALenum InitializeEffect(ALCdevice *Device, ALeffectslot *EffectSlot, ALeffect *effect) { ALenum newtype = (effect ? effect->type : AL_EFFECT_NULL); - ALeffectState *State = NULL; - ALenum err = AL_NO_ERROR; + ALeffectStateFactory *factory; - ALCdevice_Lock(Device); - if(newtype == AL_EFFECT_NULL && EffectSlot->effect.type != AL_EFFECT_NULL) - { - State = NoneCreate(); - if(!State) err = AL_OUT_OF_MEMORY; - } - else if(newtype == AL_EFFECT_EAXREVERB || newtype == AL_EFFECT_REVERB) - { - if(EffectSlot->effect.type != AL_EFFECT_EAXREVERB && EffectSlot->effect.type != AL_EFFECT_REVERB) - { - State = ReverbCreate(); - if(!State) err = AL_OUT_OF_MEMORY; - } - } - else if(newtype == AL_EFFECT_ECHO && EffectSlot->effect.type != AL_EFFECT_ECHO) - { - State = EchoCreate(); - if(!State) err = AL_OUT_OF_MEMORY; - } - else if(newtype == AL_EFFECT_RING_MODULATOR && EffectSlot->effect.type != AL_EFFECT_RING_MODULATOR) - { - State = ModulatorCreate(); - if(!State) err = AL_OUT_OF_MEMORY; - } - else if(newtype == AL_EFFECT_DEDICATED_DIALOGUE || newtype == AL_EFFECT_DEDICATED_LOW_FREQUENCY_EFFECT) + if(newtype != EffectSlot->EffectType) { - if(EffectSlot->effect.type != AL_EFFECT_DEDICATED_DIALOGUE && EffectSlot->effect.type != AL_EFFECT_DEDICATED_LOW_FREQUENCY_EFFECT) + ALeffectState *State; + FPUCtl oldMode; + + factory = getFactoryByType(newtype); + if(!factory) { - State = DedicatedCreate(); - if(!State) err = AL_OUT_OF_MEMORY; + ERR("Failed to find factory for effect type 0x%04x\n", newtype); + return AL_INVALID_ENUM; } - } - - if(err != AL_NO_ERROR) - { - ALCdevice_Unlock(Device); - return err; - } + State = V0(factory,create)(); + if(!State) + return AL_OUT_OF_MEMORY; - if(State) - { - FPUCtl oldMode; SetMixerFPUMode(&oldMode); - if(ALeffectState_DeviceUpdate(State, Device) == AL_FALSE) + ALCdevice_Lock(Device); + if(V(State,deviceUpdate)(Device) == AL_FALSE) { - RestoreFPUMode(&oldMode); ALCdevice_Unlock(Device); - ALeffectState_Destroy(State); + RestoreFPUMode(&oldMode); + DELETE_OBJ(State); return AL_OUT_OF_MEMORY; } - State = ExchangePtr((XchgPtr*)&EffectSlot->EffectState, State); + State = ExchangePtr((XchgPtr*)&EffectSlot->EffectState, State); if(!effect) - memset(&EffectSlot->effect, 0, sizeof(EffectSlot->effect)); + { + memset(&EffectSlot->EffectProps, 0, sizeof(EffectSlot->EffectProps)); + EffectSlot->EffectType = AL_EFFECT_NULL; + } else - memcpy(&EffectSlot->effect, effect, sizeof(*effect)); + { + memcpy(&EffectSlot->EffectProps, &effect->Props, sizeof(effect->Props)); + EffectSlot->EffectType = effect->type; + } + /* FIXME: This should be done asynchronously, but since the EffectState * object was changed, it needs an update before its Process method can * be called. */ EffectSlot->NeedsUpdate = AL_FALSE; - ALeffectState_Update(EffectSlot->EffectState, Device, EffectSlot); + V(EffectSlot->EffectState,update)(Device, EffectSlot); ALCdevice_Unlock(Device); RestoreFPUMode(&oldMode); - ALeffectState_Destroy(State); + DELETE_OBJ(State); State = NULL; } else { - if(!effect) - memset(&EffectSlot->effect, 0, sizeof(EffectSlot->effect)); - else - memcpy(&EffectSlot->effect, effect, sizeof(*effect)); - ALCdevice_Unlock(Device); - EffectSlot->NeedsUpdate = AL_TRUE; + if(effect) + { + ALCdevice_Lock(Device); + memcpy(&EffectSlot->EffectProps, &effect->Props, sizeof(effect->Props)); + ALCdevice_Unlock(Device); + EffectSlot->NeedsUpdate = AL_TRUE; + } } return AL_NO_ERROR; @@ -572,9 +525,13 @@ ALenum InitializeEffect(ALCdevice *Device, ALeffectslot *EffectSlot, ALeffect *e ALenum InitEffectSlot(ALeffectslot *slot) { - ALint i, c; + ALeffectStateFactory *factory; + ALuint i, c; + + slot->EffectType = AL_EFFECT_NULL; - if(!(slot->EffectState=NoneCreate())) + factory = getFactoryByType(AL_EFFECT_NULL); + if(!(slot->EffectState=V0(factory,create)())) return AL_OUT_OF_MEMORY; slot->Gain = 1.0; @@ -600,7 +557,7 @@ ALvoid ReleaseALAuxiliaryEffectSlots(ALCcontext *Context) ALeffectslot *temp = Context->EffectSlotMap.array[pos].value; Context->EffectSlotMap.array[pos].value = NULL; - ALeffectState_Destroy(temp->EffectState); + DELETE_OBJ(temp->EffectState); FreeThunkEntry(temp->id); memset(temp, 0, sizeof(ALeffectslot)); |