diff options
author | Chris Robinson <[email protected]> | 2010-05-18 17:54:45 -0700 |
---|---|---|
committer | Chris Robinson <[email protected]> | 2010-05-18 17:54:45 -0700 |
commit | 2d46a1001e5ff81276666cb7eec292396710122d (patch) | |
tree | 7cedecfb8dc9b258b42a87c9f7ba457033e43ee4 | |
parent | 4edd7fe6476dc83fae162ab694984b17924968c3 (diff) |
Use a map for the filter list
-rw-r--r-- | Alc/ALc.c | 7 | ||||
-rw-r--r-- | OpenAL32/Include/alFilter.h | 2 | ||||
-rw-r--r-- | OpenAL32/Include/alMain.h | 5 | ||||
-rw-r--r-- | OpenAL32/alFilter.c | 89 | ||||
-rw-r--r-- | OpenAL32/alSource.c | 7 |
5 files changed, 47 insertions, 63 deletions
@@ -1933,6 +1933,7 @@ ALC_API ALCdevice* ALC_APIENTRY alcOpenDevice(const ALCchar *deviceName) InitUIntMap(&device->BufferMap); InitUIntMap(&device->EffectMap); + InitUIntMap(&device->FilterMap); //Set output format device->Frequency = GetConfigValueInt(NULL, "frequency", SWMIXER_OUTPUT_RATE); @@ -2062,13 +2063,15 @@ ALC_API ALCboolean ALC_APIENTRY alcCloseDevice(ALCdevice *pDevice) } ResetUIntMap(&pDevice->EffectMap); - if(pDevice->FilterCount > 0) + if(pDevice->FilterMap.size > 0) { #ifdef _DEBUG - AL_PRINT("alcCloseDevice(): deleting %d Filter(s)\n", pDevice->FilterCount); + AL_PRINT("alcCloseDevice(): deleting %d Filter(s)\n", pDevice->FilterMap.size); #endif ReleaseALFilters(pDevice); } + ResetUIntMap(&pDevice->FilterMap); + if(pDevice->DatabufferCount > 0) { #ifdef _DEBUG diff --git a/OpenAL32/Include/alFilter.h b/OpenAL32/Include/alFilter.h index 2b5d3e94..9f420d35 100644 --- a/OpenAL32/Include/alFilter.h +++ b/OpenAL32/Include/alFilter.h @@ -89,8 +89,6 @@ typedef struct ALfilter // Index to itself ALuint filter; - - struct ALfilter *next; } ALfilter; diff --git a/OpenAL32/Include/alMain.h b/OpenAL32/Include/alMain.h index 9b1bcca9..aad409dc 100644 --- a/OpenAL32/Include/alMain.h +++ b/OpenAL32/Include/alMain.h @@ -361,9 +361,8 @@ struct ALCdevice_struct // Map of Effects for this device UIntMap EffectMap; - // Linked List of Filters for this device - struct ALfilter *FilterList; - ALuint FilterCount; + // Map of Filters for this device + UIntMap FilterMap; // Linked List of Databuffers for this device struct ALdatabuffer *DatabufferList; diff --git a/OpenAL32/alFilter.c b/OpenAL32/alFilter.c index 319b24d9..35a58c7a 100644 --- a/OpenAL32/alFilter.c +++ b/OpenAL32/alFilter.c @@ -32,7 +32,7 @@ static void InitFilterParams(ALfilter *filter, ALenum type); -DECL_VERIFIER(Filter, ALfilter, filter) +#define LookupFilter(m, k) ((ALfilter*)LookupUIntMapKey(&(m), (k))) AL_API ALvoid AL_APIENTRY alGenFilters(ALsizei n, ALuint *filters) { @@ -49,38 +49,34 @@ AL_API ALvoid AL_APIENTRY alGenFilters(ALsizei n, ALuint *filters) // Check that enough memory has been allocted in the 'filters' array for n Filters if (!IsBadWritePtr((void*)filters, n * sizeof(ALuint))) { - ALfilter *end; - ALfilter **list = &device->FilterList; - while(*list) - list = &(*list)->next; + ALenum err; - end = *list; while(i < n) { - *list = calloc(1, sizeof(ALfilter)); - if(!(*list)) + ALfilter *filter = calloc(1, sizeof(ALfilter)); + if(!filter) { - while(end->next) - { - ALfilter *temp = end->next; - end->next = temp->next; - - ALTHUNK_REMOVEENTRY(temp->filter); - device->FilterCount--; - free(temp); - } alSetError(Context, AL_OUT_OF_MEMORY); + alDeleteFilters(i, filters); break; } - filters[i] = (ALuint)ALTHUNK_ADDENTRY(*list); - (*list)->filter = filters[i]; + filter->filter = ALTHUNK_ADDENTRY(filter); + err = InsertUIntMapEntry(&device->FilterMap, filter->filter, + filter); + if(err != AL_NO_ERROR) + { + ALTHUNK_REMOVEENTRY(filter->filter); + memset(filter, 0, sizeof(ALfilter)); + free(filter); - InitFilterParams(*list, AL_FILTER_NULL); - device->FilterCount++; - i++; + alSetError(Context, err); + alDeleteFilters(i, filters); + break; + } - list = &(*list)->next; + filters[i++] = filter->filter; + InitFilterParams(filter, AL_FILTER_NULL); } } } @@ -107,7 +103,7 @@ AL_API ALvoid AL_APIENTRY alDeleteFilters(ALsizei n, ALuint *filters) if(!filters[i]) continue; - if(!VerifyFilter(device->FilterList, filters[i])) + if(!LookupFilter(device->FilterMap, filters[i])) { alSetError(Context, AL_INVALID_NAME); break; @@ -120,23 +116,13 @@ AL_API ALvoid AL_APIENTRY alDeleteFilters(ALsizei n, ALuint *filters) for (i = 0; i < n; i++) { // Recheck that the filter is valid, because there could be duplicated names - if((ALFilter=VerifyFilter(device->FilterList, filters[i])) != NULL) + if((ALFilter=LookupFilter(device->FilterMap, filters[i])) != NULL) { - ALfilter **list; - - // Remove Source from list of Sources - list = &device->FilterList; - while(*list && *list != ALFilter) - list = &(*list)->next; - - if(*list) - *list = (*list)->next; + RemoveUIntMapKey(&device->FilterMap, ALFilter->filter); ALTHUNK_REMOVEENTRY(ALFilter->filter); memset(ALFilter, 0, sizeof(ALfilter)); free(ALFilter); - - device->FilterCount--; } } } @@ -150,14 +136,13 @@ AL_API ALvoid AL_APIENTRY alDeleteFilters(ALsizei n, ALuint *filters) AL_API ALboolean AL_APIENTRY alIsFilter(ALuint filter) { ALCcontext *Context; - ALboolean result = AL_TRUE; + ALboolean result; Context = GetContextSuspended(); if(!Context) return AL_FALSE; - if(filter) - result = (VerifyFilter(Context->Device->FilterList, filter) ? - AL_TRUE : AL_FALSE); + result = ((!filter || LookupFilter(Context->Device->FilterMap, filter)) ? + AL_TRUE : AL_FALSE); ProcessContext(Context); @@ -174,7 +159,7 @@ AL_API ALvoid AL_APIENTRY alFilteri(ALuint filter, ALenum param, ALint iValue) if(!Context) return; Device = Context->Device; - if((ALFilter=VerifyFilter(Device->FilterList, filter)) != NULL) + if((ALFilter=LookupFilter(Device->FilterMap, filter)) != NULL) { switch(param) { @@ -206,7 +191,7 @@ AL_API ALvoid AL_APIENTRY alFilteriv(ALuint filter, ALenum param, ALint *piValue if(!Context) return; Device = Context->Device; - if(VerifyFilter(Device->FilterList, filter) != NULL) + if(LookupFilter(Device->FilterMap, filter) != NULL) { switch(param) { @@ -235,7 +220,7 @@ AL_API ALvoid AL_APIENTRY alFilterf(ALuint filter, ALenum param, ALfloat flValue if(!Context) return; Device = Context->Device; - if((ALFilter=VerifyFilter(Device->FilterList, filter)) != NULL) + if((ALFilter=LookupFilter(Device->FilterMap, filter)) != NULL) { switch(ALFilter->type) { @@ -282,7 +267,7 @@ AL_API ALvoid AL_APIENTRY alFilterfv(ALuint filter, ALenum param, ALfloat *pflVa if(!Context) return; Device = Context->Device; - if(VerifyFilter(Device->FilterList, filter) != NULL) + if(LookupFilter(Device->FilterMap, filter) != NULL) { switch(param) { @@ -307,7 +292,7 @@ AL_API ALvoid AL_APIENTRY alGetFilteri(ALuint filter, ALenum param, ALint *piVal if(!Context) return; Device = Context->Device; - if((ALFilter=VerifyFilter(Device->FilterList, filter)) != NULL) + if((ALFilter=LookupFilter(Device->FilterMap, filter)) != NULL) { switch(param) { @@ -335,7 +320,7 @@ AL_API ALvoid AL_APIENTRY alGetFilteriv(ALuint filter, ALenum param, ALint *piVa if(!Context) return; Device = Context->Device; - if(VerifyFilter(Device->FilterList, filter) != NULL) + if(LookupFilter(Device->FilterMap, filter) != NULL) { switch(param) { @@ -364,7 +349,7 @@ AL_API ALvoid AL_APIENTRY alGetFilterf(ALuint filter, ALenum param, ALfloat *pfl if(!Context) return; Device = Context->Device; - if((ALFilter=VerifyFilter(Device->FilterList, filter)) != NULL) + if((ALFilter=LookupFilter(Device->FilterMap, filter)) != NULL) { switch(ALFilter->type) { @@ -405,7 +390,7 @@ AL_API ALvoid AL_APIENTRY alGetFilterfv(ALuint filter, ALenum param, ALfloat *pf if(!Context) return; Device = Context->Device; - if(VerifyFilter(Device->FilterList, filter) != NULL) + if(LookupFilter(Device->FilterMap, filter) != NULL) { switch(param) { @@ -423,17 +408,17 @@ AL_API ALvoid AL_APIENTRY alGetFilterfv(ALuint filter, ALenum param, ALfloat *pf ALvoid ReleaseALFilters(ALCdevice *device) { - while(device->FilterList) + ALsizei i; + for(i = 0;i < device->FilterMap.size;i++) { - ALfilter *temp = device->FilterList; - device->FilterList = temp->next; + ALfilter *temp = device->FilterMap.array[i].value; + device->FilterMap.array[i].value = NULL; // Release filter structure ALTHUNK_REMOVEENTRY(temp->filter); memset(temp, 0, sizeof(ALfilter)); free(temp); } - device->FilterCount = 0; } diff --git a/OpenAL32/alSource.c b/OpenAL32/alSource.c index df7abbcc..078b5623 100644 --- a/OpenAL32/alSource.c +++ b/OpenAL32/alSource.c @@ -38,10 +38,9 @@ static ALboolean ApplyOffset(ALsource *Source); static ALint GetByteOffset(ALsource *Source); static ALint FramesFromBytes(ALint offset, ALenum format, ALint channels); -DECL_VERIFIER(Filter, ALfilter, filter) - #define LookupSource(m, k) ((ALsource*)LookupUIntMapKey(&(m), (k))) #define LookupBuffer(m, k) ((ALbuffer*)LookupUIntMapKey(&(m), (k))) +#define LookupFilter(m, k) ((ALfilter*)LookupUIntMapKey(&(m), (k))) #define LookupEffectSlot(m, k) ((ALeffectslot*)LookupUIntMapKey(&(m), (k))) AL_API ALvoid AL_APIENTRY alGenSources(ALsizei n,ALuint *sources) @@ -628,7 +627,7 @@ AL_API ALvoid AL_APIENTRY alSourcei(ALuint source,ALenum eParam,ALint lValue) ALfilter *filter = NULL; if(lValue == 0 || - (filter=VerifyFilter(pContext->Device->FilterList, lValue)) != NULL) + (filter=LookupFilter(pContext->Device->FilterMap, lValue)) != NULL) { if(!filter) { @@ -730,7 +729,7 @@ AL_API void AL_APIENTRY alSource3i(ALuint source, ALenum eParam, ALint lValue1, (lValue1 == 0 || (ALEffectSlot=LookupEffectSlot(pContext->EffectSlotMap, lValue1)) != NULL) && (lValue3 == 0 || - (ALFilter=VerifyFilter(device->FilterList, lValue3)) != NULL)) + (ALFilter=LookupFilter(device->FilterMap, lValue3)) != NULL)) { /* Release refcount on the previous slot, and add one for * the new slot */ |