diff options
-rw-r--r-- | Alc/ALc.c | 13 | ||||
-rw-r--r-- | Alc/ALu.c | 29 | ||||
-rw-r--r-- | OpenAL32/Include/alMain.h | 6 | ||||
-rw-r--r-- | OpenAL32/Include/alSource.h | 9 | ||||
-rw-r--r-- | OpenAL32/alSource.c | 26 | ||||
-rw-r--r-- | OpenAL32/alState.c | 16 |
6 files changed, 65 insertions, 34 deletions
@@ -2137,6 +2137,8 @@ static ALvoid InitContext(ALCcontext *Context) */ static ALCvoid FreeContext(ALCcontext *context) { + ALsizei i; + TRACE("%p\n", context); if(context->SourceMap.size > 0) @@ -2153,9 +2155,14 @@ static ALCvoid FreeContext(ALCcontext *context) } ResetUIntMap(&context->EffectSlotMap); - context->ActiveSourceCount = 0; + for(i = 0;i < context->MaxActiveSources;i++) + { + al_free(context->ActiveSources[i]); + context->ActiveSources[i] = NULL; + } free(context->ActiveSources); context->ActiveSources = NULL; + context->ActiveSourceCount = 0; context->MaxActiveSources = 0; context->ActiveEffectSlotCount = 0; @@ -2877,8 +2884,8 @@ ALC_API ALCcontext* ALC_APIENTRY alcCreateContext(ALCdevice *device, const ALCin ALContext->Listener = (ALlistener*)(((ALintptrEXT)(ALContext+1)+15)&~15); ALContext->MaxActiveSources = 256; - ALContext->ActiveSources = malloc(sizeof(ALContext->ActiveSources[0]) * - ALContext->MaxActiveSources); + ALContext->ActiveSources = calloc(ALContext->MaxActiveSources, + sizeof(ALContext->ActiveSources[0])); } if(!ALContext || !ALContext->ActiveSources) { @@ -1025,7 +1025,7 @@ ALvoid aluMixData(ALCdevice *device, ALvoid *buffer, ALsizei size) { ALuint SamplesToDo; ALeffectslot **slot, **slot_end; - ALsource **src, **src_end; + ALactivesource **src, **src_end; ALCcontext *ctx; FPUCtl oldMode; ALuint i, c; @@ -1058,18 +1058,22 @@ ALvoid aluMixData(ALCdevice *device, ALvoid *buffer, ALsizei size) src_end = src + ctx->ActiveSourceCount; while(src != src_end) { - if((*src)->state != AL_PLAYING) + ALsource *source = (*src)->Source; + + if(source->state != AL_PLAYING) { + ALactivesource *temp = *(--src_end); + *src_end = *src; + *src = temp; --(ctx->ActiveSourceCount); - *src = *(--src_end); continue; } - if(!DeferUpdates && (ExchangeInt(&(*src)->NeedsUpdate, AL_FALSE) || + if(!DeferUpdates && (ExchangeInt(&source->NeedsUpdate, AL_FALSE) || UpdateSources)) - ALsource_Update(*src, ctx); + ALsource_Update(source, ctx); - MixSource(*src, device, SamplesToDo); + MixSource(source, device, SamplesToDo); src++; } @@ -1233,18 +1237,19 @@ ALvoid aluHandleDisconnect(ALCdevice *device) Context = device->ContextList; while(Context) { - ALsource **src, **src_end; + ALactivesource **src, **src_end; src = Context->ActiveSources; src_end = src + Context->ActiveSourceCount; while(src != src_end) { - if((*src)->state == AL_PLAYING) + ALsource *source = (*src)->Source; + if(source->state == AL_PLAYING) { - (*src)->state = AL_STOPPED; - (*src)->BuffersPlayed = (*src)->BuffersInQueue; - (*src)->position = 0; - (*src)->position_fraction = 0; + source->state = AL_STOPPED; + source->BuffersPlayed = source->BuffersInQueue; + source->position = 0; + source->position_fraction = 0; } src++; } diff --git a/OpenAL32/Include/alMain.h b/OpenAL32/Include/alMain.h index bb7d9367..1d5eb888 100644 --- a/OpenAL32/Include/alMain.h +++ b/OpenAL32/Include/alMain.h @@ -733,9 +733,9 @@ struct ALCcontext_struct volatile ALfloat SpeedOfSound; volatile ALenum DeferUpdates; - struct ALsource **ActiveSources; - ALsizei ActiveSourceCount; - ALsizei MaxActiveSources; + struct ALactivesource **ActiveSources; + ALsizei ActiveSourceCount; + ALsizei MaxActiveSources; struct ALeffectslot **ActiveEffectSlots; ALsizei ActiveEffectSlotCount; diff --git a/OpenAL32/Include/alSource.h b/OpenAL32/Include/alSource.h index 0432cb32..ecc62a37 100644 --- a/OpenAL32/Include/alSource.h +++ b/OpenAL32/Include/alSource.h @@ -29,6 +29,12 @@ typedef struct ALbufferlistitem { struct ALbufferlistitem *prev; } ALbufferlistitem; + +typedef struct ALactivesource { + struct ALsource *Source; +} ALactivesource; + + typedef struct HrtfState { ALboolean Moving; ALuint Counter; @@ -78,8 +84,7 @@ typedef struct SendParams { } SendParams; -typedef struct ALsource -{ +typedef struct ALsource { /** Source properties. */ volatile ALfloat Pitch; volatile ALfloat Gain; diff --git a/OpenAL32/alSource.c b/OpenAL32/alSource.c index e0ae9768..b2a314ee 100644 --- a/OpenAL32/alSource.c +++ b/OpenAL32/alSource.c @@ -1272,7 +1272,7 @@ AL_API ALvoid AL_APIENTRY alDeleteSources(ALsizei n, const ALuint *sources) } for(i = 0;i < n;i++) { - ALsource **srclist, **srclistend; + ALactivesource **srclist, **srclistend; if((Source=RemoveSource(context, sources[i])) == NULL) continue; @@ -1283,10 +1283,12 @@ AL_API ALvoid AL_APIENTRY alDeleteSources(ALsizei n, const ALuint *sources) srclistend = srclist + context->ActiveSourceCount; while(srclist != srclistend) { - if(*srclist == Source) + if((*srclist)->Source == Source) { - context->ActiveSourceCount--; - *srclist = *(--srclistend); + ALactivesource *temp = *(--srclistend); + *srclistend = *srclist; + *srclist = temp; + --(context->ActiveSourceCount); break; } srclist++; @@ -1903,18 +1905,20 @@ AL_API ALvoid AL_APIENTRY alSourcePlayv(ALsizei n, const ALuint *sources) LockContext(context); while(n > context->MaxActiveSources-context->ActiveSourceCount) { - void *temp = NULL; + ALactivesource **temp = NULL; ALsizei newcount; newcount = context->MaxActiveSources << 1; if(newcount > 0) temp = realloc(context->ActiveSources, - sizeof(*context->ActiveSources) * newcount); + newcount * sizeof(context->ActiveSources[0])); if(!temp) { UnlockContext(context); SET_ERROR_AND_GOTO(context, AL_OUT_OF_MEMORY, done); } + for(i = context->MaxActiveSources;i < newcount;i++) + temp[i] = NULL; context->ActiveSources = temp; context->MaxActiveSources = newcount; @@ -2337,11 +2341,17 @@ ALvoid SetSourceState(ALsource *Source, ALCcontext *Context, ALenum state) for(j = 0;j < Context->ActiveSourceCount;j++) { - if(Context->ActiveSources[j] == Source) + if(Context->ActiveSources[j]->Source == Source) break; } if(j == Context->ActiveSourceCount) - Context->ActiveSources[Context->ActiveSourceCount++] = Source; + { + ALsizei idx = Context->ActiveSourceCount; + if(!Context->ActiveSources[idx]) + Context->ActiveSources[idx] = al_malloc(16, sizeof(Context->ActiveSources[0])); + Context->ActiveSources[idx]->Source = Source; + Context->ActiveSourceCount++; + } } else if(state == AL_PAUSED) { diff --git a/OpenAL32/alState.c b/OpenAL32/alState.c index 280dd896..aebee3e7 100644 --- a/OpenAL32/alState.c +++ b/OpenAL32/alState.c @@ -715,7 +715,7 @@ AL_API ALvoid AL_APIENTRY alDeferUpdatesSOFT(void) if(!context->DeferUpdates) { ALboolean UpdateSources; - ALsource **src, **src_end; + ALactivesource **src, **src_end; ALeffectslot **slot, **slot_end; FPUCtl oldMode; @@ -731,15 +731,19 @@ AL_API ALvoid AL_APIENTRY alDeferUpdatesSOFT(void) src_end = src + context->ActiveSourceCount; while(src != src_end) { - if((*src)->state != AL_PLAYING) + ALsource *source = (*src)->Source; + + if(source->state != AL_PLAYING) { - context->ActiveSourceCount--; - *src = *(--src_end); + ALactivesource *temp = *(--src_end); + *src_end = *src; + *src = temp; + --(context->ActiveSourceCount); continue; } - if(ExchangeInt(&(*src)->NeedsUpdate, AL_FALSE) || UpdateSources) - ALsource_Update(*src, context); + if(ExchangeInt(&source->NeedsUpdate, AL_FALSE) || UpdateSources) + ALsource_Update(source, context); src++; } |