diff options
author | Chris Robinson <[email protected]> | 2020-02-28 20:07:43 -0800 |
---|---|---|
committer | Chris Robinson <[email protected]> | 2020-02-28 20:07:43 -0800 |
commit | a01617904c222578b71d6912cc5e5410b137c626 (patch) | |
tree | 5444998a93f808b3e19a0767a604e8abd13be1e9 | |
parent | b42d241da58eb4dbe949c8b6ba5c0fd80ee021a9 (diff) |
Simplify getting a voice for a new source offset
-rw-r--r-- | al/source.cpp | 38 |
1 files changed, 21 insertions, 17 deletions
diff --git a/al/source.cpp b/al/source.cpp index 8085b429..b0613068 100644 --- a/al/source.cpp +++ b/al/source.cpp @@ -601,23 +601,6 @@ bool SetVoiceOffset(ALvoice *oldvoice, const VoicePos &vpos, ALsource *source, A { /* First, get a free voice to start at the new offset. */ auto voicelist = context->getVoicesSpan(); - bool free_voices{false}; - for(const ALvoice *voice : voicelist) - { - free_voices |= (voice->mPlayState.load(std::memory_order_acquire) == ALvoice::Stopped - && voice->mSourceID.load(std::memory_order_relaxed) == 0u - && voice->mPendingChange.load(std::memory_order_relaxed) == false); - if(free_voices) break; - } - if UNLIKELY(!free_voices) - { - auto &allvoices = *context->mVoices.load(std::memory_order_relaxed); - if(allvoices.size() == voicelist.size()) - context->allocVoices(1); - context->mActiveVoiceCount.fetch_add(1, std::memory_order_release); - voicelist = context->getVoicesSpan(); - } - ALvoice *newvoice{}; ALuint vidx{0}; for(ALvoice *voice : voicelist) @@ -631,6 +614,27 @@ bool SetVoiceOffset(ALvoice *oldvoice, const VoicePos &vpos, ALsource *source, A } ++vidx; } + if UNLIKELY(!newvoice) + { + auto &allvoices = *context->mVoices.load(std::memory_order_relaxed); + if(allvoices.size() == voicelist.size()) + context->allocVoices(1); + context->mActiveVoiceCount.fetch_add(1, std::memory_order_release); + voicelist = context->getVoicesSpan(); + + vidx = 0; + for(ALvoice *voice : voicelist) + { + if(voice->mPlayState.load(std::memory_order_acquire) == ALvoice::Stopped + && voice->mSourceID.load(std::memory_order_relaxed) == 0u + && voice->mPendingChange.load(std::memory_order_relaxed) == false) + { + newvoice = voice; + break; + } + ++vidx; + } + } /* Initialize the new voice and set its starting offset. * TODO: It might be better to have the VoiceChange processing copy the old |