diff options
author | Chris Robinson <[email protected]> | 2009-08-15 09:14:08 -0700 |
---|---|---|
committer | Chris Robinson <[email protected]> | 2009-08-15 09:14:08 -0700 |
commit | 43067ed2b8d4ab9c3f46b8ee002d6c3f6480cc4f (patch) | |
tree | c83c89f3a37a468f18d8aa533b97ca8027fa96f3 /OpenAL32 | |
parent | 4e4c9aef1581fbec81294f20e2466d9d63e26ad8 (diff) |
Store the buffer list in the device
Diffstat (limited to 'OpenAL32')
-rw-r--r-- | OpenAL32/Include/alBuffer.h | 6 | ||||
-rw-r--r-- | OpenAL32/Include/alMain.h | 4 | ||||
-rw-r--r-- | OpenAL32/alBuffer.c | 32 |
3 files changed, 22 insertions, 20 deletions
diff --git a/OpenAL32/Include/alBuffer.h b/OpenAL32/Include/alBuffer.h index 75e97d18..b25a35c6 100644 --- a/OpenAL32/Include/alBuffer.h +++ b/OpenAL32/Include/alBuffer.h @@ -11,7 +11,7 @@ extern "C" { #define PENDING 1 #define PROCESSED 2 -typedef struct ALbuffer_struct +typedef struct ALbuffer { ALenum format; ALenum eOriginalFormat; @@ -21,12 +21,12 @@ typedef struct ALbuffer_struct ALsizei padding; ALenum state; ALuint refcount; // Number of sources using this buffer (deletion can only occur when this is 0) - struct ALbuffer_struct *next; + struct ALbuffer *next; } ALbuffer; ALvoid ALAPIENTRY alBufferSubDataEXT(ALuint buffer,ALenum format,const ALvoid *data,ALsizei offset,ALsizei length); -ALvoid ReleaseALBuffers(ALvoid); +ALvoid ReleaseALBuffers(ALCdevice *device); #ifdef __cplusplus } diff --git a/OpenAL32/Include/alMain.h b/OpenAL32/Include/alMain.h index e3823364..ccfb94ac 100644 --- a/OpenAL32/Include/alMain.h +++ b/OpenAL32/Include/alMain.h @@ -189,6 +189,10 @@ struct ALCdevice_struct ALint lNumStereoSources; ALuint NumAuxSends; + // Linked List of Buffers for this device + struct ALbuffer *Buffers; + ALuint BufferCount; + // Context created on this device ALCcontext *Context; diff --git a/OpenAL32/alBuffer.c b/OpenAL32/alBuffer.c index 0dfe05ba..cfac55d7 100644 --- a/OpenAL32/alBuffer.c +++ b/OpenAL32/alBuffer.c @@ -49,9 +49,6 @@ static void ConvertDataIMA4(ALshort *dst, const ALvoid *src, ALint origChans, AL * Global Variables */ -static ALbuffer *g_pBuffers = NULL; // Linked List of Buffers -static ALuint g_uiBufferCount = 0; // Buffer Count - static const long g_IMAStep_size[89]={ // IMA ADPCM Stepsize table 7, 8, 9, 10, 11, 12, 13, 14, 16, 17, 19, 21, 23, 25, 28, 31, 34, 37, 41, 45, 50, 55, 60, 66, 73, 80, 88, 97, 107, 118, 130, 143, @@ -87,10 +84,12 @@ ALAPI ALvoid ALAPIENTRY alGenBuffers(ALsizei n,ALuint *puiBuffers) // Check that we are actually generation some Buffers if (n > 0) { + ALCdevice *device = Context->Device; + // Check the pointer is valid (and points to enough memory to store Buffer Names) if (!IsBadWritePtr((void*)puiBuffers, n * sizeof(ALuint))) { - ALbuffer **list = &g_pBuffers; + ALbuffer **list = &device->Buffers; while(*list) list = &(*list)->next; @@ -107,7 +106,7 @@ ALAPI ALvoid ALAPIENTRY alGenBuffers(ALsizei n,ALuint *puiBuffers) puiBuffers[i] = (ALuint)ALTHUNK_ADDENTRY(*list); (*list)->state = UNUSED; - g_uiBufferCount++; + device->BufferCount++; i++; list = &(*list)->next; @@ -143,6 +142,8 @@ ALAPI ALvoid ALAPIENTRY alDeleteBuffers(ALsizei n, const ALuint *puiBuffers) // Check we are actually Deleting some Buffers if (n >= 0) { + ALCdevice *device = Context->Device; + // Check that all the buffers are valid and can actually be deleted for (i = 0; i < n; i++) { @@ -176,7 +177,7 @@ ALAPI ALvoid ALAPIENTRY alDeleteBuffers(ALsizei n, const ALuint *puiBuffers) { if (puiBuffers[i] && alIsBuffer(puiBuffers[i])) { - ALbuffer **list = &g_pBuffers; + ALbuffer **list = &device->Buffers; ALBuf=((ALbuffer *)ALTHUNK_LOOKUPENTRY(puiBuffers[i])); while(*list && *list != ALBuf) @@ -191,7 +192,7 @@ ALAPI ALvoid ALAPIENTRY alDeleteBuffers(ALsizei n, const ALuint *puiBuffers) // Release buffer structure ALTHUNK_REMOVEENTRY(puiBuffers[i]); memset(ALBuf, 0, sizeof(ALbuffer)); - g_uiBufferCount--; + device->BufferCount--; free(ALBuf); } } @@ -223,10 +224,12 @@ ALAPI ALboolean ALAPIENTRY alIsBuffer(ALuint uiBuffer) if (uiBuffer) { + ALCdevice *device = Context->Device; + TgtALBuf = (ALbuffer *)ALTHUNK_LOOKUPENTRY(uiBuffer); // Check through list of generated buffers for uiBuffer - ALBuf = g_pBuffers; + ALBuf = device->Buffers; while (ALBuf) { if (ALBuf == TgtALBuf) @@ -1069,17 +1072,12 @@ static void ConvertDataIMA4(ALshort *dst, const ALvoid *src, ALint origChans, AL * * INTERNAL FN : Called by DLLMain on exit to destroy any buffers that still exist */ -ALvoid ReleaseALBuffers(ALvoid) +ALvoid ReleaseALBuffers(ALCdevice *device) { ALbuffer *ALBuffer; ALbuffer *ALBufferTemp; -#ifdef _DEBUG - if(g_uiBufferCount > 0) - AL_PRINT("exit(): deleting %d Buffer(s)\n", g_uiBufferCount); -#endif - - ALBuffer = g_pBuffers; + ALBuffer = device->Buffers; while(ALBuffer) { // Release sample data @@ -1091,6 +1089,6 @@ ALvoid ReleaseALBuffers(ALvoid) memset(ALBufferTemp, 0, sizeof(ALbuffer)); free(ALBufferTemp); } - g_pBuffers = NULL; - g_uiBufferCount = 0; + device->Buffers = NULL; + device->BufferCount = 0; } |