diff options
author | Chris Robinson <[email protected]> | 2010-06-06 00:17:50 -0700 |
---|---|---|
committer | Chris Robinson <[email protected]> | 2010-06-06 00:17:50 -0700 |
commit | 7f6df7695c9c8cd957339f85e57233f5d3308e49 (patch) | |
tree | 19d67ce16718276dceb3509c30d192c6dc518826 /OpenAL32 | |
parent | ed585710790c35a2624586d9f387c261cf1bff48 (diff) |
Use an array of active sources when mixing
Prevents iterating over all allocated sources during mixing updates
Diffstat (limited to 'OpenAL32')
-rw-r--r-- | OpenAL32/Include/alMain.h | 4 | ||||
-rw-r--r-- | OpenAL32/alSource.c | 45 |
2 files changed, 49 insertions, 0 deletions
diff --git a/OpenAL32/Include/alMain.h b/OpenAL32/Include/alMain.h index afc94da2..4d963563 100644 --- a/OpenAL32/Include/alMain.h +++ b/OpenAL32/Include/alMain.h @@ -433,6 +433,10 @@ struct ALCcontext_struct ALfloat DopplerVelocity; ALfloat flSpeedOfSound; + struct ALsource **ActiveSources; + ALsizei ActiveSourceCount; + ALsizei MaxActiveSources; + ALCdevice *Device; const ALCchar *ExtensionList; diff --git a/OpenAL32/alSource.c b/OpenAL32/alSource.c index d470f027..5d7ceced 100644 --- a/OpenAL32/alSource.c +++ b/OpenAL32/alSource.c @@ -145,6 +145,16 @@ AL_API ALvoid AL_APIENTRY alDeleteSources(ALsizei n, const ALuint *sources) // Recheck that the Source is valid, because there could be duplicated Source names if((Source=LookupSource(Context->SourceMap, sources[i])) != NULL) { + for(j = 0;j < Context->ActiveSourceCount;j++) + { + if(Context->ActiveSources[j] == Source) + { + ALsizei end = --(Context->ActiveSourceCount); + Context->ActiveSources[j] = Context->ActiveSources[end]; + break; + } + } + // For each buffer in the source's queue, decrement its reference counter and remove it while(Source->queue != NULL) { @@ -1310,6 +1320,31 @@ AL_API ALvoid AL_APIENTRY alSourcePlayv(ALsizei n, const ALuint *sources) } } + if(Context->ActiveSourceCount+n < n) + { + alSetError(Context, AL_OUT_OF_MEMORY); + goto done; + } + + while(Context->MaxActiveSources < Context->ActiveSourceCount+n) + { + void *temp = NULL; + ALsizei newcount; + + newcount = Context->MaxActiveSources << 1; + if(newcount > 0) + temp = realloc(Context->ActiveSources, + sizeof(*Context->ActiveSources) * newcount); + if(!temp) + { + alSetError(Context, AL_OUT_OF_MEMORY); + goto done; + } + + Context->ActiveSources = temp; + Context->MaxActiveSources = newcount; + } + for(i = 0;i < n;i++) { Source = (ALsource*)ALTHUNK_LOOKUPENTRY(sources[i]); @@ -1364,6 +1399,16 @@ AL_API ALvoid AL_APIENTRY alSourcePlayv(ALsizei n, const ALuint *sources) Source->position = 0; Source->position_fraction = 0; } + else + { + for(j = 0;j < Context->ActiveSourceCount;j++) + { + if(Context->ActiveSources[j] == Source) + break; + } + if(j == Context->ActiveSourceCount) + Context->ActiveSources[Context->ActiveSourceCount++] = Source; + } } done: |