aboutsummaryrefslogtreecommitdiffstats
path: root/alc/alc.cpp
diff options
context:
space:
mode:
authorChris Robinson <[email protected]>2020-11-02 05:08:23 -0800
committerChris Robinson <[email protected]>2020-11-02 05:19:17 -0800
commit03389f390c2b9979563b0901bdb73b2e0cd0e8fb (patch)
treeba1bba4782d69ad346d0a472219d83a177c5fc36 /alc/alc.cpp
parent52d58a40234b8829801f0a587375eca91694c30f (diff)
Avoid a full wipe and reallocation of wet buffers
Diffstat (limited to 'alc/alc.cpp')
-rw-r--r--alc/alc.cpp28
1 files changed, 6 insertions, 22 deletions
diff --git a/alc/alc.cpp b/alc/alc.cpp
index b3da9209..c94a9d53 100644
--- a/alc/alc.cpp
+++ b/alc/alc.cpp
@@ -2102,29 +2102,13 @@ static ALCenum UpdateDeviceParams(ALCdevice *device, const int *attrList)
{
std::unique_lock<std::mutex> proplock{context->mPropLock};
std::unique_lock<std::mutex> slotlock{context->mEffectSlotLock};
- /* HACK: Clear the effect slots' wet buffer references, and clear the wet
- * buffer array so they're reallocated (with potentially a new channel
- * count) when reinitialized.
- */
- if(ALeffectslot *slot{context->mDefaultSlot.get()})
- {
- slot->mWetBuffer = nullptr;
- slot->Wet.Buffer = {};
- }
- for(auto &sublist : context->mEffectSlotList)
- {
- uint64_t usemask{~sublist.FreeMask};
- while(usemask)
- {
- const ALsizei idx{CountTrailingZeros(usemask)};
- ALeffectslot *slot{sublist.EffectSlots + idx};
- usemask &= ~(1_u64 << idx);
- slot->mWetBuffer = nullptr;
- slot->Wet.Buffer = {};
- }
- }
- decltype(context->mWetBuffers){}.swap(context->mWetBuffers);
+ /* Clear out unused wet buffers. */
+ auto buffer_not_in_use = [](WetBufferPtr &wetbuffer) noexcept -> bool
+ { return !wetbuffer->mInUse; };
+ auto wetbuffer_iter = std::remove_if(context->mWetBuffers.begin(),
+ context->mWetBuffers.end(), buffer_not_in_use);
+ context->mWetBuffers.erase(wetbuffer_iter, context->mWetBuffers.end());
if(ALeffectslot *slot{context->mDefaultSlot.get()})
{