aboutsummaryrefslogtreecommitdiffstats
path: root/OpenAL32
diff options
context:
space:
mode:
authorChris Robinson <[email protected]>2014-03-18 19:56:25 -0700
committerChris Robinson <[email protected]>2014-03-18 19:56:25 -0700
commitd6f7aac1bbc2c51dbe53e30a50275d550a020df6 (patch)
treeeff721968bc56422bca8e565c3842d1c1422bcc8 /OpenAL32
parent71b177918d2e5864edf45088bf1e5f59d2cd8871 (diff)
Use a separate struct for tracking active sources
Diffstat (limited to 'OpenAL32')
-rw-r--r--OpenAL32/Include/alMain.h6
-rw-r--r--OpenAL32/Include/alSource.h9
-rw-r--r--OpenAL32/alSource.c26
-rw-r--r--OpenAL32/alState.c16
4 files changed, 38 insertions, 19 deletions
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++;
}