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)
break;
ReleaseALC();
ReleaseALEffects();
ReleaseALFilters();
FreeALConfig();
ALTHUNK_EXIT();
DeleteCriticalSection(&g_csMutex);
@ -235,8 +233,6 @@ static void my_deinit()
once = AL_TRUE;
ReleaseALC();
ReleaseALEffects();
ReleaseALFilters();
FreeALConfig();
ALTHUNK_EXIT();
DeleteCriticalSection(&g_csMutex);
@ -1376,6 +1372,20 @@ ALCAPI ALCboolean ALCAPIENTRY alcCloseDevice(ALCdevice *pDevice)
#endif
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
memset(pDevice, 0, sizeof(ALCdevice));

View File

@ -201,7 +201,7 @@ enum {
};
extern ALboolean DisabledEffects[MAX_EFFECTS];
typedef struct ALeffect_struct
typedef struct ALeffect
{
// Effect type (AL_EFFECT_NULL, ...)
ALenum type;
@ -248,7 +248,7 @@ typedef struct ALeffect_struct
// Index to itself
ALuint effect;
struct ALeffect_struct *next;
struct ALeffect *next;
} ALeffect;
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 alGetEffectfv(ALuint effect, ALenum param, ALfloat *pflValues);
ALvoid ReleaseALEffects(ALvoid);
ALvoid ReleaseALEffects(ALCdevice *device);
#ifdef __cplusplus
}

View File

@ -61,7 +61,7 @@ static __inline ALfloat lpFilter2P(FILTER *iir, ALuint offset, ALfloat input)
#define AL_LOWPASS_GAINHF 0x0002
typedef struct ALfilter_struct
typedef struct ALfilter
{
// Filter type (AL_FILTER_NULL, ...)
ALenum type;
@ -72,7 +72,7 @@ typedef struct ALfilter_struct
// Index to itself
ALuint filter;
struct ALfilter_struct *next;
struct ALfilter *next;
} ALfilter;
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 alGetFilterfv(ALuint filter, ALenum param, ALfloat *pflValues);
ALvoid ReleaseALFilters(ALvoid);
ALvoid ReleaseALFilters(ALCdevice *device);
#ifdef __cplusplus
}

View File

@ -193,6 +193,14 @@ struct ALCdevice_struct
struct ALbuffer *Buffers;
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
ALCcontext *Context;

View File

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

View File

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