From fd0ed9f33fe552c7a3ba0c049c1369a31b056c47 Mon Sep 17 00:00:00 2001 From: Chris Robinson Date: Mon, 24 Feb 2020 21:40:54 -0800 Subject: Improve searching for the next voice when playing multiple sources Instead of searching from the beginning of the voice list for each source, just continue searching from the last source's voice. --- al/source.cpp | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) (limited to 'al/source.cpp') diff --git a/al/source.cpp b/al/source.cpp index 229a6d66..aa850e5e 100644 --- a/al/source.cpp +++ b/al/source.cpp @@ -2712,6 +2712,8 @@ START_API_FUNC voicelist = context->getVoicesSpan(); } + auto voiceiter = voicelist.begin(); + ALuint vidx{0}; VoiceChange *tail{}, *cur{}; for(ALsource *source : srchandles) { @@ -2777,10 +2779,10 @@ START_API_FUNC break; } - /* Look for an unused voice to play this source with. */ - ALuint vidx{0}; - for(ALvoice *v : voicelist) + /* Find the next unused voice to play this source with. */ + for(;voiceiter != voicelist.end();++voiceiter,++vidx) { + ALvoice *v{*voiceiter}; if(v->mPlayState.load(std::memory_order_acquire) == ALvoice::Stopped && v->mSourceID.load(std::memory_order_relaxed) == 0u && v->mPendingStop.load(std::memory_order_relaxed) == false) @@ -2788,7 +2790,6 @@ START_API_FUNC voice = v; break; } - ++vidx; }; /* A source that's not playing or paused has any offset applied when it -- cgit v1.2.3