aboutsummaryrefslogtreecommitdiffstats
path: root/OpenAL32
diff options
context:
space:
mode:
authorChris Robinson <[email protected]>2018-02-01 23:56:35 -0800
committerChris Robinson <[email protected]>2018-02-01 23:56:35 -0800
commit6a4a88f8f5c050b2a1e312984d072d806d7c387c (patch)
tree8d2b68be9d645486536b1acbf355b0bd484ec709 /OpenAL32
parenta114d6cbb56470db87c2b0bd7c76ce26bdaeb63c (diff)
Store an index to a given source's voice
For more efficient voice lookups when needed.
Diffstat (limited to 'OpenAL32')
-rw-r--r--OpenAL32/Include/alSource.h5
-rw-r--r--OpenAL32/alSource.c25
2 files changed, 20 insertions, 10 deletions
diff --git a/OpenAL32/Include/alSource.h b/OpenAL32/Include/alSource.h
index b346e619..2892a245 100644
--- a/OpenAL32/Include/alSource.h
+++ b/OpenAL32/Include/alSource.h
@@ -100,6 +100,11 @@ typedef struct ALsource {
ATOMIC_FLAG PropsClean;
+ /* Index into the context's Voices array. Lazily updated, only checked and
+ * reset when looking up the voice.
+ */
+ ALint VoiceIdx;
+
/** Self ID */
ALuint id;
} ALsource;
diff --git a/OpenAL32/alSource.c b/OpenAL32/alSource.c
index b3e98bc9..a7e5fc17 100644
--- a/OpenAL32/alSource.c
+++ b/OpenAL32/alSource.c
@@ -187,16 +187,16 @@ static ALboolean GetSourcedv(ALsource *Source, ALCcontext *Context, SourceProp p
static ALboolean GetSourceiv(ALsource *Source, ALCcontext *Context, SourceProp prop, ALint *values);
static ALboolean GetSourcei64v(ALsource *Source, ALCcontext *Context, SourceProp prop, ALint64 *values);
-static inline ALvoice *GetSourceVoice(const ALsource *source, const ALCcontext *context)
+static inline ALvoice *GetSourceVoice(ALsource *source, ALCcontext *context)
{
- ALvoice **voice = context->Voices;
- ALvoice **voice_end = voice + context->VoiceCount;
- while(voice != voice_end)
+ ALint idx = source->VoiceIdx;
+ if(idx >= 0 && idx < context->VoiceCount)
{
- if(ATOMIC_LOAD(&(*voice)->Source, almemory_order_acquire) == source)
- return *voice;
- ++voice;
+ ALvoice *voice = context->Voices[idx];
+ if(ATOMIC_LOAD(&voice->Source, almemory_order_acquire) == source)
+ return voice;
}
+ source->VoiceIdx = -1;
return NULL;
}
@@ -2567,6 +2567,7 @@ AL_API ALvoid AL_APIENTRY alSourcePlayv(ALsizei n, const ALuint *sources)
ALbufferlistitem *BufferList;
ALbuffer *buffer = NULL;
bool start_fading = false;
+ ALint vidx = -1;
ALsizei s;
source = LookupSource(context, sources[i]);
@@ -2630,12 +2631,13 @@ AL_API ALvoid AL_APIENTRY alSourcePlayv(ALsizei n, const ALuint *sources)
{
if(ATOMIC_LOAD(&context->Voices[j]->Source, almemory_order_acquire) == NULL)
{
- voice = context->Voices[j];
+ vidx = j;
break;
}
}
- if(voice == NULL)
- voice = context->Voices[context->VoiceCount++];
+ if(vidx == -1)
+ vidx = context->VoiceCount++;
+ voice = context->Voices[vidx];
ATOMIC_STORE(&voice->Playing, false, almemory_order_release);
ATOMIC_FLAG_TEST_AND_SET(&source->PropsClean, almemory_order_acquire);
@@ -2690,6 +2692,7 @@ AL_API ALvoid AL_APIENTRY alSourcePlayv(ALsizei n, const ALuint *sources)
ATOMIC_STORE(&voice->Source, source, almemory_order_relaxed);
ATOMIC_STORE(&voice->Playing, true, almemory_order_release);
ATOMIC_STORE(&source->state, AL_PLAYING, almemory_order_release);
+ source->VoiceIdx = vidx;
finish_play:
WriteUnlock(&source->queue_lock);
}
@@ -3163,6 +3166,8 @@ static void InitSourceParams(ALsource *Source, ALsizei num_sends)
* ignore the test.
*/
ATOMIC_FLAG_TEST_AND_SET(&Source->PropsClean, almemory_order_relaxed);
+
+ Source->VoiceIdx = -1;
}
static void DeinitSource(ALsource *source, ALsizei num_sends)