Store the effect and filter lists in the device

This commit is contained in:
Chris Robinson 2009-08-15 09:39:18 -07:00
parent 43067ed2b8
commit 510ccc7f17
6 changed files with 68 additions and 53 deletions

View File

@ -216,8 +216,6 @@ BOOL APIENTRY DllMain(HANDLE hModule,DWORD ul_reason_for_call,LPVOID lpReserved)
if(!init_done) if(!init_done)
break; break;
ReleaseALC(); ReleaseALC();
ReleaseALEffects();
ReleaseALFilters();
FreeALConfig(); FreeALConfig();
ALTHUNK_EXIT(); ALTHUNK_EXIT();
DeleteCriticalSection(&g_csMutex); DeleteCriticalSection(&g_csMutex);
@ -235,8 +233,6 @@ static void my_deinit()
once = AL_TRUE; once = AL_TRUE;
ReleaseALC(); ReleaseALC();
ReleaseALEffects();
ReleaseALFilters();
FreeALConfig(); FreeALConfig();
ALTHUNK_EXIT(); ALTHUNK_EXIT();
DeleteCriticalSection(&g_csMutex); DeleteCriticalSection(&g_csMutex);
@ -1376,6 +1372,20 @@ ALCAPI ALCboolean ALCAPIENTRY alcCloseDevice(ALCdevice *pDevice)
#endif #endif
ReleaseALBuffers(pDevice); ReleaseALBuffers(pDevice);
} }
if(pDevice->EffectCount > 0)
{
#ifdef _DEBUG
AL_PRINT("alcCloseDevice(): deleting %d Effect(s)\n", pDevice->EffectCount);
#endif
ReleaseALEffects(pDevice);
}
if(pDevice->FilterCount > 0)
{
#ifdef _DEBUG
AL_PRINT("alcCloseDevice(): deleting %d Filter(s)\n", pDevice->FilterCount);
#endif
ReleaseALFilters(pDevice);
}
//Release device structure //Release device structure
memset(pDevice, 0, sizeof(ALCdevice)); memset(pDevice, 0, sizeof(ALCdevice));

View File

@ -201,7 +201,7 @@ enum {
}; };
extern ALboolean DisabledEffects[MAX_EFFECTS]; extern ALboolean DisabledEffects[MAX_EFFECTS];
typedef struct ALeffect_struct typedef struct ALeffect
{ {
// Effect type (AL_EFFECT_NULL, ...) // Effect type (AL_EFFECT_NULL, ...)
ALenum type; ALenum type;
@ -248,7 +248,7 @@ typedef struct ALeffect_struct
// Index to itself // Index to itself
ALuint effect; ALuint effect;
struct ALeffect_struct *next; struct ALeffect *next;
} ALeffect; } ALeffect;
ALvoid AL_APIENTRY alGenEffects(ALsizei n, ALuint *effects); ALvoid AL_APIENTRY alGenEffects(ALsizei n, ALuint *effects);
@ -265,7 +265,7 @@ ALvoid AL_APIENTRY alGetEffectiv(ALuint effect, ALenum param, ALint *piValues);
ALvoid AL_APIENTRY alGetEffectf(ALuint effect, ALenum param, ALfloat *pflValue); ALvoid AL_APIENTRY alGetEffectf(ALuint effect, ALenum param, ALfloat *pflValue);
ALvoid AL_APIENTRY alGetEffectfv(ALuint effect, ALenum param, ALfloat *pflValues); ALvoid AL_APIENTRY alGetEffectfv(ALuint effect, ALenum param, ALfloat *pflValues);
ALvoid ReleaseALEffects(ALvoid); ALvoid ReleaseALEffects(ALCdevice *device);
#ifdef __cplusplus #ifdef __cplusplus
} }

View File

@ -61,7 +61,7 @@ static __inline ALfloat lpFilter2P(FILTER *iir, ALuint offset, ALfloat input)
#define AL_LOWPASS_GAINHF 0x0002 #define AL_LOWPASS_GAINHF 0x0002
typedef struct ALfilter_struct typedef struct ALfilter
{ {
// Filter type (AL_FILTER_NULL, ...) // Filter type (AL_FILTER_NULL, ...)
ALenum type; ALenum type;
@ -72,7 +72,7 @@ typedef struct ALfilter_struct
// Index to itself // Index to itself
ALuint filter; ALuint filter;
struct ALfilter_struct *next; struct ALfilter *next;
} ALfilter; } ALfilter;
ALvoid AL_APIENTRY alGenFilters(ALsizei n, ALuint *filters); ALvoid AL_APIENTRY alGenFilters(ALsizei n, ALuint *filters);
@ -89,7 +89,7 @@ ALvoid AL_APIENTRY alGetFilteriv(ALuint filter, ALenum param, ALint *piValues);
ALvoid AL_APIENTRY alGetFilterf(ALuint filter, ALenum param, ALfloat *pflValue); ALvoid AL_APIENTRY alGetFilterf(ALuint filter, ALenum param, ALfloat *pflValue);
ALvoid AL_APIENTRY alGetFilterfv(ALuint filter, ALenum param, ALfloat *pflValues); ALvoid AL_APIENTRY alGetFilterfv(ALuint filter, ALenum param, ALfloat *pflValues);
ALvoid ReleaseALFilters(ALvoid); ALvoid ReleaseALFilters(ALCdevice *device);
#ifdef __cplusplus #ifdef __cplusplus
} }

View File

@ -193,6 +193,14 @@ struct ALCdevice_struct
struct ALbuffer *Buffers; struct ALbuffer *Buffers;
ALuint BufferCount; ALuint BufferCount;
// Linked List of Effects for this device
struct ALeffect *EffectList;
ALuint EffectCount;
// Linked List of Filters for this device
struct ALfilter *FilterList;
ALuint FilterCount;
// Context created on this device // Context created on this device
ALCcontext *Context; ALCcontext *Context;

View File

@ -34,9 +34,6 @@
ALboolean DisabledEffects[MAX_EFFECTS]; ALboolean DisabledEffects[MAX_EFFECTS];
static ALeffect *g_EffectList;
static ALuint g_EffectCount;
static void InitEffectParams(ALeffect *effect, ALenum type); static void InitEffectParams(ALeffect *effect, ALenum type);
@ -50,10 +47,12 @@ ALvoid AL_APIENTRY alGenEffects(ALsizei n, ALuint *effects)
if (n > 0) if (n > 0)
{ {
ALCdevice *device = Context->Device;
// Check that enough memory has been allocted in the 'effects' array for n Effects // Check that enough memory has been allocted in the 'effects' array for n Effects
if (!IsBadWritePtr((void*)effects, n * sizeof(ALuint))) if (!IsBadWritePtr((void*)effects, n * sizeof(ALuint)))
{ {
ALeffect **list = &g_EffectList; ALeffect **list = &device->EffectList;
while(*list) while(*list)
list = &(*list)->next; list = &(*list)->next;
@ -73,7 +72,7 @@ ALvoid AL_APIENTRY alGenEffects(ALsizei n, ALuint *effects)
(*list)->effect = effects[i]; (*list)->effect = effects[i];
InitEffectParams(*list, AL_EFFECT_NULL); InitEffectParams(*list, AL_EFFECT_NULL);
g_EffectCount++; device->EffectCount++;
i++; i++;
list = &(*list)->next; list = &(*list)->next;
@ -95,6 +94,8 @@ ALvoid AL_APIENTRY alDeleteEffects(ALsizei n, ALuint *effects)
if (n >= 0) if (n >= 0)
{ {
ALCdevice *device = Context->Device;
// Check that all effects are valid // Check that all effects are valid
for (i = 0; i < n; i++) for (i = 0; i < n; i++)
{ {
@ -118,7 +119,7 @@ ALvoid AL_APIENTRY alDeleteEffects(ALsizei n, ALuint *effects)
ALEffect = ((ALeffect*)ALTHUNK_LOOKUPENTRY(effects[i])); ALEffect = ((ALeffect*)ALTHUNK_LOOKUPENTRY(effects[i]));
// Remove Source from list of Sources // Remove Source from list of Sources
list = &g_EffectList; list = &device->EffectList;
while(*list && *list != ALEffect) while(*list && *list != ALEffect)
list = &(*list)->next; list = &(*list)->next;
@ -129,7 +130,7 @@ ALvoid AL_APIENTRY alDeleteEffects(ALsizei n, ALuint *effects)
memset(ALEffect, 0, sizeof(ALeffect)); memset(ALEffect, 0, sizeof(ALeffect));
free(ALEffect); free(ALEffect);
g_EffectCount--; device->EffectCount--;
} }
} }
} }
@ -143,18 +144,18 @@ ALvoid AL_APIENTRY alDeleteEffects(ALsizei n, ALuint *effects)
ALboolean AL_APIENTRY alIsEffect(ALuint effect) ALboolean AL_APIENTRY alIsEffect(ALuint effect)
{ {
ALCcontext *Context; ALCcontext *Context;
ALeffect **list; ALeffect *list;
Context = alcGetCurrentContext(); Context = alcGetCurrentContext();
SuspendContext(Context); SuspendContext(Context);
list = &g_EffectList; list = Context->Device->EffectList;
while(*list && (*list)->effect != effect) while(list && list->effect != effect)
list = &(*list)->next; list = list->next;
ProcessContext(Context); ProcessContext(Context);
return ((*list || !effect) ? AL_TRUE : AL_FALSE); return ((list || !effect) ? AL_TRUE : AL_FALSE);
} }
ALvoid AL_APIENTRY alEffecti(ALuint effect, ALenum param, ALint iValue) ALvoid AL_APIENTRY alEffecti(ALuint effect, ALenum param, ALint iValue)
@ -1160,23 +1161,20 @@ ALvoid AL_APIENTRY alGetEffectfv(ALuint effect, ALenum param, ALfloat *pflValues
} }
ALvoid ReleaseALEffects(ALvoid) ALvoid ReleaseALEffects(ALCdevice *device)
{ {
#ifdef _DEBUG ALeffect *list = device->EffectList;
if(g_EffectCount > 0) while(list)
AL_PRINT("exit(): deleting %d Effect(s)\n", g_EffectCount);
#endif
while(g_EffectList)
{ {
ALeffect *temp = g_EffectList; ALeffect *temp = list;
g_EffectList = g_EffectList->next; list = list->next;
// Release effect structure // Release effect structure
memset(temp, 0, sizeof(ALeffect)); memset(temp, 0, sizeof(ALeffect));
free(temp); free(temp);
} }
g_EffectCount = 0; device->EffectList = NULL;
device->EffectCount = 0;
} }

View File

@ -29,8 +29,6 @@
#include "alThunk.h" #include "alThunk.h"
#include "alError.h" #include "alError.h"
static ALfilter *g_FilterList;
static ALuint g_FilterCount;
static void InitFilterParams(ALfilter *filter, ALenum type); static void InitFilterParams(ALfilter *filter, ALenum type);
@ -45,10 +43,12 @@ ALvoid AL_APIENTRY alGenFilters(ALsizei n, ALuint *filters)
if (n > 0) if (n > 0)
{ {
ALCdevice *device = Context->Device;
// Check that enough memory has been allocted in the 'filters' array for n Filters // Check that enough memory has been allocted in the 'filters' array for n Filters
if (!IsBadWritePtr((void*)filters, n * sizeof(ALuint))) if (!IsBadWritePtr((void*)filters, n * sizeof(ALuint)))
{ {
ALfilter **list = &g_FilterList; ALfilter **list = &device->FilterList;
while(*list) while(*list)
list = &(*list)->next; list = &(*list)->next;
@ -68,7 +68,7 @@ ALvoid AL_APIENTRY alGenFilters(ALsizei n, ALuint *filters)
(*list)->filter = filters[i]; (*list)->filter = filters[i];
InitFilterParams(*list, AL_FILTER_NULL); InitFilterParams(*list, AL_FILTER_NULL);
g_FilterCount++; device->FilterCount++;
i++; i++;
list = &(*list)->next; list = &(*list)->next;
@ -90,6 +90,8 @@ ALvoid AL_APIENTRY alDeleteFilters(ALsizei n, ALuint *filters)
if (n >= 0) if (n >= 0)
{ {
ALCdevice *device = Context->Device;
// Check that all filters are valid // Check that all filters are valid
for (i = 0; i < n; i++) for (i = 0; i < n; i++)
{ {
@ -113,7 +115,7 @@ ALvoid AL_APIENTRY alDeleteFilters(ALsizei n, ALuint *filters)
ALFilter = ((ALfilter*)ALTHUNK_LOOKUPENTRY(filters[i])); ALFilter = ((ALfilter*)ALTHUNK_LOOKUPENTRY(filters[i]));
// Remove Source from list of Sources // Remove Source from list of Sources
list = &g_FilterList; list = &device->FilterList;
while(*list && *list != ALFilter) while(*list && *list != ALFilter)
list = &(*list)->next; list = &(*list)->next;
@ -124,7 +126,7 @@ ALvoid AL_APIENTRY alDeleteFilters(ALsizei n, ALuint *filters)
memset(ALFilter, 0, sizeof(ALfilter)); memset(ALFilter, 0, sizeof(ALfilter));
free(ALFilter); free(ALFilter);
g_FilterCount--; device->FilterCount--;
} }
} }
} }
@ -138,18 +140,18 @@ ALvoid AL_APIENTRY alDeleteFilters(ALsizei n, ALuint *filters)
ALboolean AL_APIENTRY alIsFilter(ALuint filter) ALboolean AL_APIENTRY alIsFilter(ALuint filter)
{ {
ALCcontext *Context; ALCcontext *Context;
ALfilter **list; ALfilter *list;
Context = alcGetCurrentContext(); Context = alcGetCurrentContext();
SuspendContext(Context); SuspendContext(Context);
list = &g_FilterList; list = Context->Device->FilterList;
while(*list && (*list)->filter != filter) while(list && list->filter != filter)
list = &(*list)->next; list = list->next;
ProcessContext(Context); ProcessContext(Context);
return ((*list || !filter) ? AL_TRUE : AL_FALSE); return ((list || !filter) ? AL_TRUE : AL_FALSE);
} }
ALvoid AL_APIENTRY alFilteri(ALuint filter, ALenum param, ALint iValue) ALvoid AL_APIENTRY alFilteri(ALuint filter, ALenum param, ALint iValue)
@ -397,23 +399,20 @@ ALvoid AL_APIENTRY alGetFilterfv(ALuint filter, ALenum param, ALfloat *pflValues
} }
ALvoid ReleaseALFilters(ALvoid) ALvoid ReleaseALFilters(ALCdevice *device)
{ {
#ifdef _DEBUG ALfilter *list = device->FilterList;
if(g_FilterCount > 0) while(list)
AL_PRINT("exit(): deleting %d Filter(s)\n", g_FilterCount);
#endif
while(g_FilterList)
{ {
ALfilter *temp = g_FilterList; ALfilter *temp = list;
g_FilterList = g_FilterList->next; list = list->next;
// Release filter structure // Release filter structure
memset(temp, 0, sizeof(ALfilter)); memset(temp, 0, sizeof(ALfilter));
free(temp); free(temp);
} }
g_FilterCount = 0; device->FilterList = NULL;
device->FilterCount = 0;
} }