diff options
Diffstat (limited to 'OpenAL32/alAuxEffectSlot.c')
-rw-r--r-- | OpenAL32/alAuxEffectSlot.c | 443 |
1 files changed, 209 insertions, 234 deletions
diff --git a/OpenAL32/alAuxEffectSlot.c b/OpenAL32/alAuxEffectSlot.c index 5fde2d3d..ae706231 100644 --- a/OpenAL32/alAuxEffectSlot.c +++ b/OpenAL32/alAuxEffectSlot.c @@ -48,404 +48,379 @@ static inline ALeffectStateFactory *getFactoryByType(ALenum type) 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); - alDeleteAuxiliaryEffectSlots(cur, effectslots); - 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); - DELETE_OBJ(slot->EffectState); - al_free(slot); - - alDeleteAuxiliaryEffectSlots(cur, effectslots); - 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) { + FreeThunkEntry(slot->id); + DELETE_OBJ(slot->EffectState); + al_free(slot); + alDeleteAuxiliaryEffectSlots(cur, effectslots); - al_throwerr(Context, err); + SET_ERROR_AND_GOTO(context, err, done); } + + effectslots[cur] = slot->id; + } + err = AddEffectSlotArray(context, n, effectslots); + if(err != AL_NO_ERROR) + { + 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); - DELETE_OBJ(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_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); +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; } |