aboutsummaryrefslogtreecommitdiffstats
path: root/OpenAL32/alAuxEffectSlot.c
diff options
context:
space:
mode:
authorChris Robinson <[email protected]>2011-08-30 20:13:42 -0700
committerChris Robinson <[email protected]>2011-08-30 20:13:42 -0700
commit189add1d5a5b1f9f55fba63937f3d92cddc0cea2 (patch)
tree202a765e0355e2702d9eb9d17ee9200814bf4c21 /OpenAL32/alAuxEffectSlot.c
parent755062fb76148d740681eb33046f8f2a7729eab3 (diff)
Use a separate array for the auxiliary slots in the mixer
Diffstat (limited to 'OpenAL32/alAuxEffectSlot.c')
-rw-r--r--OpenAL32/alAuxEffectSlot.c85
1 files changed, 69 insertions, 16 deletions
diff --git a/OpenAL32/alAuxEffectSlot.c b/OpenAL32/alAuxEffectSlot.c
index 4645ed2b..27d92949 100644
--- a/OpenAL32/alAuxEffectSlot.c
+++ b/OpenAL32/alAuxEffectSlot.c
@@ -33,6 +33,8 @@
static ALvoid InitializeEffect(ALCcontext *Context, ALeffectslot *EffectSlot, ALeffect *effect);
+static ALenum ResizeEffectSlotArray(ALCcontext *Context, ALsizei count);
+static ALvoid RemoveEffectSlotArray(ALCcontext *Context, ALeffectslot *val);
#define LookupEffectSlot(m, k) ((ALeffectslot*)LookupUIntMapKey(&(m), (k)))
#define LookupEffect(m, k) ((ALeffect*)LookupUIntMapKey(&(m), (k)))
@@ -55,8 +57,14 @@ AL_API ALvoid AL_APIENTRY alGenAuxiliaryEffectSlots(ALsizei n, ALuint *effectslo
ALenum err;
ALsizei i, j;
- i = 0;
- while(i < n)
+ err = ResizeEffectSlotArray(Context, n);
+ if(err != AL_NO_ERROR)
+ {
+ alSetError(Context, err);
+ n = 0;
+ }
+
+ for(i = 0;i < n;i++)
{
ALeffectslot *slot = calloc(1, sizeof(ALeffectslot));
if(!slot || !(slot->EffectState=NoneCreate()))
@@ -68,11 +76,29 @@ AL_API ALvoid AL_APIENTRY alGenAuxiliaryEffectSlots(ALsizei n, ALuint *effectslo
break;
}
- err = NewThunkEntry(&slot->effectslot);
+ slot->Gain = 1.0;
+ slot->AuxSendAuto = AL_TRUE;
+ slot->NeedsUpdate = AL_FALSE;
+ for(j = 0;j < BUFFERSIZE;j++)
+ slot->WetBuffer[j] = 0.0f;
+ for(j = 0;j < 1;j++)
+ {
+ slot->ClickRemoval[j] = 0.0f;
+ slot->PendingClicks[j] = 0.0f;
+ }
+ slot->ref = 0;
+
+ err = ResizeEffectSlotArray(Context, 1);
+ if(err == AL_NO_ERROR)
+ {
+ Context->ActiveEffectSlots[Context->ActiveEffectSlotCount++] = slot;
+ err = NewThunkEntry(&slot->effectslot);
+ }
if(err == AL_NO_ERROR)
err = InsertUIntMapEntry(&Context->EffectSlotMap, slot->effectslot, slot);
if(err != AL_NO_ERROR)
{
+ RemoveEffectSlotArray(Context, slot);
FreeThunkEntry(slot->effectslot);
ALEffect_Destroy(slot->EffectState);
free(slot);
@@ -82,19 +108,7 @@ AL_API ALvoid AL_APIENTRY alGenAuxiliaryEffectSlots(ALsizei n, ALuint *effectslo
break;
}
- effectslots[i++] = slot->effectslot;
-
- slot->Gain = 1.0;
- slot->AuxSendAuto = AL_TRUE;
- slot->NeedsUpdate = AL_FALSE;
- for(j = 0;j < BUFFERSIZE;j++)
- slot->WetBuffer[j] = 0.0f;
- for(j = 0;j < 1;j++)
- {
- slot->ClickRemoval[j] = 0.0f;
- slot->PendingClicks[j] = 0.0f;
- }
- slot->ref = 0;
+ effectslots[i] = slot->effectslot;
}
}
@@ -143,6 +157,7 @@ AL_API ALvoid AL_APIENTRY alDeleteAuxiliaryEffectSlots(ALsizei n, ALuint *effect
if((EffectSlot=LookupEffectSlot(Context->EffectSlotMap, effectslots[i])) == NULL)
continue;
+ RemoveEffectSlotArray(Context, EffectSlot);
ALEffect_Destroy(EffectSlot->EffectState);
RemoveUIntMapKey(&Context->EffectSlotMap, EffectSlot->effectslot);
@@ -468,6 +483,44 @@ ALeffectState *NoneCreate(void)
return state;
}
+
+static ALvoid RemoveEffectSlotArray(ALCcontext *Context, ALeffectslot *slot)
+{
+ ALeffectslot **slotlist, **slotlistend;
+
+ slotlist = Context->ActiveEffectSlots;
+ slotlistend = slotlist + Context->ActiveEffectSlotCount;
+ while(slotlist != slotlistend)
+ {
+ if(*slotlist == slot)
+ {
+ *slotlist = *(--slotlistend);
+ Context->ActiveEffectSlotCount--;
+ break;
+ }
+ }
+}
+
+static ALenum ResizeEffectSlotArray(ALCcontext *Context, ALsizei count)
+{
+ ALsizei newcount;
+ void *temp;
+
+ if(count <= Context->MaxActiveEffectSlots-Context->ActiveEffectSlotCount)
+ return AL_NO_ERROR;
+
+ newcount = Context->MaxActiveEffectSlots ?
+ (Context->MaxActiveEffectSlots<<1) : 1;
+ if(newcount <= Context->MaxActiveEffectSlots ||
+ !(temp=realloc(Context->ActiveEffectSlots, newcount *
+ sizeof(*Context->ActiveEffectSlots))))
+ return AL_OUT_OF_MEMORY;
+
+ Context->ActiveEffectSlots = temp;
+ Context->MaxActiveEffectSlots = newcount;
+ return AL_NO_ERROR;
+}
+
static ALvoid InitializeEffect(ALCcontext *Context, ALeffectslot *EffectSlot, ALeffect *effect)
{
if(EffectSlot->effect.type != (effect?effect->type:AL_EFFECT_NULL))