diff options
author | Chris Robinson <[email protected]> | 2016-11-22 02:28:18 -0800 |
---|---|---|
committer | Chris Robinson <[email protected]> | 2016-11-22 02:59:54 -0800 |
commit | 01babb69d25fd23bde0fdf5ed525bb82934ce6fd (patch) | |
tree | 4532d0fb9439add22c860ec59b1f1dbfef29d0b2 /OpenAL32 | |
parent | 616adea4cc0629c7ce20a2c7e713342cadc26435 (diff) |
Clean up finding a source's voice
Diffstat (limited to 'OpenAL32')
-rw-r--r-- | OpenAL32/Include/alSource.h | 2 | ||||
-rw-r--r-- | OpenAL32/alSource.c | 55 |
2 files changed, 30 insertions, 27 deletions
diff --git a/OpenAL32/Include/alSource.h b/OpenAL32/Include/alSource.h index b288937a..d5eb3c50 100644 --- a/OpenAL32/Include/alSource.h +++ b/OpenAL32/Include/alSource.h @@ -78,7 +78,7 @@ struct ALsourceProps { typedef struct ALvoice { struct ALsourceProps Props; - struct ALsource *volatile Source; + struct ALsource *Source; /** Current target parameters used for mixing. */ ALint Step; diff --git a/OpenAL32/alSource.c b/OpenAL32/alSource.c index 78aaf61d..b65c2c18 100644 --- a/OpenAL32/alSource.c +++ b/OpenAL32/alSource.c @@ -125,6 +125,18 @@ 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) +{ + ALvoice *voice = context->Voices; + ALvoice *voice_end = voice + context->VoiceCount; + while(voice != voice_end) + { + if(voice->Source == source) + return voice; + } + return NULL; +} + static inline bool SourceShouldUpdate(const ALsource *source, const ALCcontext *context) { return (source->state == AL_PLAYING || source->state == AL_PAUSED) && @@ -1584,22 +1596,15 @@ AL_API ALvoid AL_APIENTRY alDeleteSources(ALsizei n, const ALuint *sources) } for(i = 0;i < n;i++) { - ALvoice *voice, *voice_end; + ALvoice *voice; if((Source=RemoveSource(context, sources[i])) == NULL) continue; FreeThunkEntry(Source->id); LockContext(context); - voice = context->Voices; - voice_end = voice + context->VoiceCount; - while(voice != voice_end) - { - ALsource *old = Source; - if(COMPARE_EXCHANGE(&voice->Source, &old, NULL)) - break; - voice++; - } + voice = GetSourceVoice(Source, context); + if(voice) voice->Source = NULL; UnlockContext(context); DeinitSource(Source); @@ -2977,29 +2982,27 @@ ALvoid SetSourceState(ALsource *Source, ALCcontext *Context, ALenum state) if(!BufferList || !device->Connected) goto do_stop; - /* Make sure this source isn't already active, while looking for an - * unused active source slot to put it in. */ - for(i = 0;i < Context->VoiceCount;i++) + /* Make sure this source isn't already active, and if not, look for an + * unused voice to put it in. + */ + voice = GetSourceVoice(Source, Context); + if(voice == NULL) { - if(Context->Voices[i].Source == Source) + for(i = 0;i < Context->VoiceCount;i++) { - if(voice != NULL) - Context->Voices[i].Source = NULL; - else + if(Context->Voices[i].Source == NULL) + { voice = &Context->Voices[i]; - break; + voice->Source = Source; + break; + } } - - if(!voice && !Context->Voices[i].Source) + if(voice == NULL) { - voice = &Context->Voices[i]; + voice = &Context->Voices[Context->VoiceCount++]; voice->Source = Source; } - } - if(voice == NULL) - { - voice = &Context->Voices[Context->VoiceCount++]; - voice->Source = Source; + discontinuity = AL_TRUE; } if(discontinuity) |