2007-12-17 17:43:19 -08:00
|
|
|
/**
|
|
|
|
* OpenAL cross platform audio library
|
|
|
|
* Copyright (C) 1999-2007 by authors.
|
|
|
|
* This library is free software; you can redistribute it and/or
|
|
|
|
* modify it under the terms of the GNU Library General Public
|
|
|
|
* License as published by the Free Software Foundation; either
|
|
|
|
* version 2 of the License, or (at your option) any later version.
|
|
|
|
*
|
|
|
|
* This library is distributed in the hope that it will be useful,
|
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
|
|
|
* Library General Public License for more details.
|
|
|
|
*
|
|
|
|
* You should have received a copy of the GNU Library General Public
|
|
|
|
* License along with this library; if not, write to the
|
2014-08-18 14:11:03 +02:00
|
|
|
* Free Software Foundation, Inc.,
|
|
|
|
* 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
|
2007-12-17 17:43:19 -08:00
|
|
|
* Or go to http://www.gnu.org/copyleft/lgpl.html
|
|
|
|
*/
|
|
|
|
|
|
|
|
#include "config.h"
|
|
|
|
|
2008-01-16 14:09:04 -08:00
|
|
|
#include <stdlib.h>
|
Implement AL_EFFECT_REVERB
Here is a quick description of how the reverb effect works:
+--->---+*(4)
| V new sample
+-----+---+---+ |
|extra|ltr|ref| <- +*(1)
+-----+---+---+
(3,5)*| |*(2)
+-->|
V
out sample
1) Apply master reverb gain to incoming sample and place it at the head of the
buffer. The master reverb gainhf was already applied when the source was
initially mixed.
2) Copy the delayed reflection sample to an output sample and apply the
reflection gain.
3) Apply the late reverb gain to the late reverb sample
4) Copy the end of the buffer, applying a decay gain and the decay hf ratio,
and add to the late reverb.
5) Copy the late reverb sample, adding to the output sample.
Then the head and sampling points are shifted forward, and done again for each
new sample. The extra buffer length is determined by the Reverb Density
property. A value of 0 gives a length of 0.1 seconds (long, with fairly
distinct echos) , and 1 gives 0.075 seconds (short, indistinct echos).
The decay gain is calculated such that after a number of loops to satisfy the
Decay Time, a sample will be 1/32768th as powerful (virtually insignificant to
the resulting output, and only getting further reduced). It is calculated as:
DecayGain = pow(1.0f/32768.0f, 1.0/(DecayTime/ExtraLength));
Things to note: Reverb Diffusion is not currently handled, nor is Decay HF
Limit. Decay HF Ratios above 1 probably give incorrect results. Also, this
method likely sucks, but it's the best I can come up with before release. :)
2008-01-18 21:25:40 -08:00
|
|
|
#include <math.h>
|
2008-01-16 14:09:04 -08:00
|
|
|
|
2018-11-26 23:06:49 -08:00
|
|
|
#include <thread>
|
2018-11-18 02:39:27 -08:00
|
|
|
#include <algorithm>
|
|
|
|
|
2007-12-17 17:43:19 -08:00
|
|
|
#include "AL/al.h"
|
|
|
|
#include "AL/alc.h"
|
2018-11-17 23:02:27 -08:00
|
|
|
|
2007-12-17 17:43:19 -08:00
|
|
|
#include "alMain.h"
|
2018-11-17 23:02:27 -08:00
|
|
|
#include "alcontext.h"
|
2007-12-17 17:43:19 -08:00
|
|
|
#include "alAuxEffectSlot.h"
|
2007-12-31 19:34:52 -08:00
|
|
|
#include "alError.h"
|
2016-05-11 18:40:17 -07:00
|
|
|
#include "alListener.h"
|
2009-11-25 16:21:47 -08:00
|
|
|
#include "alSource.h"
|
2007-12-17 17:43:19 -08:00
|
|
|
|
2018-01-11 08:44:52 -08:00
|
|
|
#include "fpu_modes.h"
|
2016-03-29 00:44:58 -07:00
|
|
|
#include "almalloc.h"
|
|
|
|
|
2007-12-17 17:43:19 -08:00
|
|
|
|
2018-11-20 09:47:49 -08:00
|
|
|
namespace {
|
2018-02-22 12:03:52 -08:00
|
|
|
|
2018-11-20 09:47:49 -08:00
|
|
|
inline ALeffectslot *LookupEffectSlot(ALCcontext *context, ALuint id) noexcept
|
|
|
|
{
|
|
|
|
--id;
|
|
|
|
if(UNLIKELY(id >= context->EffectSlotList.size()))
|
|
|
|
return nullptr;
|
2018-11-20 10:01:20 -08:00
|
|
|
return context->EffectSlotList[id].get();
|
2018-11-20 09:47:49 -08:00
|
|
|
}
|
|
|
|
|
|
|
|
inline ALeffect *LookupEffect(ALCdevice *device, ALuint id) noexcept
|
|
|
|
{
|
|
|
|
ALuint lidx = (id-1) >> 6;
|
|
|
|
ALsizei slidx = (id-1) & 0x3f;
|
|
|
|
|
|
|
|
if(UNLIKELY(lidx >= device->EffectList.size()))
|
|
|
|
return nullptr;
|
|
|
|
EffectSubList &sublist = device->EffectList[lidx];
|
|
|
|
if(UNLIKELY(sublist.FreeMask & (U64(1)<<slidx)))
|
|
|
|
return nullptr;
|
|
|
|
return sublist.Effects + slidx;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void AddActiveEffectSlots(const ALuint *slotids, ALsizei count, ALCcontext *context)
|
|
|
|
{
|
|
|
|
if(count < 1) return;
|
|
|
|
ALeffectslotArray *curarray{context->ActiveAuxSlots.load(std::memory_order_acquire)};
|
|
|
|
ALsizei newcount{curarray->count + count};
|
|
|
|
|
|
|
|
/* Insert the new effect slots into the head of the array, followed by the
|
|
|
|
* existing ones.
|
|
|
|
*/
|
|
|
|
auto newarray = static_cast<ALeffectslotArray*>(al_calloc(DEF_ALIGN,
|
|
|
|
FAM_SIZE(ALeffectslotArray, slot, newcount)));
|
|
|
|
newarray->count = newcount;
|
|
|
|
auto slotiter = std::transform(slotids, slotids+count, newarray->slot,
|
|
|
|
[context](ALuint id) noexcept -> ALeffectslot*
|
|
|
|
{ return LookupEffectSlot(context, id); }
|
|
|
|
);
|
|
|
|
std::copy_n(curarray->slot, curarray->count, slotiter);
|
|
|
|
|
|
|
|
/* Remove any duplicates (first instance of each will be kept). */
|
|
|
|
ALeffectslot **last = newarray->slot + newarray->count;
|
|
|
|
for(ALeffectslot **start=newarray->slot+1;;)
|
|
|
|
{
|
|
|
|
last = std::remove(start, last, *(start-1));
|
|
|
|
if(start == last) break;
|
|
|
|
++start;
|
|
|
|
}
|
|
|
|
newcount = std::distance(newarray->slot, last);
|
|
|
|
|
|
|
|
/* Reallocate newarray if the new size ended up smaller from duplicate
|
|
|
|
* removal.
|
|
|
|
*/
|
|
|
|
if(UNLIKELY(newcount < newarray->count))
|
|
|
|
{
|
|
|
|
curarray = newarray;
|
|
|
|
newarray = static_cast<ALeffectslotArray*>(al_calloc(DEF_ALIGN,
|
|
|
|
FAM_SIZE(ALeffectslotArray, slot, newcount)));
|
|
|
|
newarray->count = newcount;
|
|
|
|
std::copy_n(curarray->slot, newcount, newarray->slot);
|
|
|
|
al_free(curarray);
|
|
|
|
curarray = nullptr;
|
|
|
|
}
|
|
|
|
|
|
|
|
curarray = context->ActiveAuxSlots.exchange(newarray, std::memory_order_acq_rel);
|
|
|
|
ALCdevice *device{context->Device};
|
|
|
|
while((device->MixCount.load(std::memory_order_acquire)&1))
|
2018-11-26 23:06:49 -08:00
|
|
|
std::this_thread::yield();
|
2018-11-20 09:47:49 -08:00
|
|
|
al_free(curarray);
|
|
|
|
}
|
|
|
|
|
|
|
|
void RemoveActiveEffectSlots(const ALuint *slotids, ALsizei count, ALCcontext *context)
|
|
|
|
{
|
|
|
|
if(count < 1) return;
|
|
|
|
ALeffectslotArray *curarray{context->ActiveAuxSlots.load(std::memory_order_acquire)};
|
|
|
|
|
|
|
|
/* Don't shrink the allocated array size since we don't know how many (if
|
|
|
|
* any) of the effect slots to remove are in the array.
|
|
|
|
*/
|
|
|
|
auto newarray = static_cast<ALeffectslotArray*>(al_calloc(DEF_ALIGN,
|
|
|
|
FAM_SIZE(ALeffectslotArray, slot, curarray->count)));
|
|
|
|
|
|
|
|
/* Copy each element in curarray to newarray whose ID is not in slotids. */
|
|
|
|
const ALuint *slotids_end{slotids + count};
|
|
|
|
auto slotiter = std::copy_if(curarray->slot, curarray->slot+curarray->count, newarray->slot,
|
|
|
|
[slotids, slotids_end](const ALeffectslot *slot) -> bool
|
|
|
|
{ return std::find(slotids, slotids_end, slot->id) == slotids_end; }
|
|
|
|
);
|
|
|
|
newarray->count = std::distance(newarray->slot, slotiter);
|
|
|
|
|
|
|
|
/* TODO: Could reallocate newarray now that we know it's needed size. */
|
|
|
|
|
|
|
|
curarray = context->ActiveAuxSlots.exchange(newarray, std::memory_order_acq_rel);
|
|
|
|
ALCdevice *device{context->Device};
|
|
|
|
while((device->MixCount.load(std::memory_order_acquire)&1))
|
2018-11-26 23:06:49 -08:00
|
|
|
std::this_thread::yield();
|
2018-11-20 09:47:49 -08:00
|
|
|
al_free(curarray);
|
|
|
|
}
|
|
|
|
|
|
|
|
constexpr struct FactoryItem {
|
2018-01-28 00:10:12 -08:00
|
|
|
ALenum Type;
|
2018-11-20 09:47:49 -08:00
|
|
|
EffectStateFactory* (&GetFactory)(void);
|
2018-01-28 00:10:12 -08:00
|
|
|
} FactoryList[] = {
|
2018-02-28 19:37:12 -08:00
|
|
|
{ AL_EFFECT_NULL, NullStateFactory_getFactory },
|
|
|
|
{ AL_EFFECT_EAXREVERB, ReverbStateFactory_getFactory },
|
|
|
|
{ AL_EFFECT_REVERB, ReverbStateFactory_getFactory },
|
2018-07-22 00:48:54 +02:00
|
|
|
{ AL_EFFECT_AUTOWAH, AutowahStateFactory_getFactory },
|
2018-02-28 19:37:12 -08:00
|
|
|
{ AL_EFFECT_CHORUS, ChorusStateFactory_getFactory },
|
|
|
|
{ AL_EFFECT_COMPRESSOR, CompressorStateFactory_getFactory },
|
|
|
|
{ AL_EFFECT_DISTORTION, DistortionStateFactory_getFactory },
|
|
|
|
{ AL_EFFECT_ECHO, EchoStateFactory_getFactory },
|
|
|
|
{ AL_EFFECT_EQUALIZER, EqualizerStateFactory_getFactory },
|
|
|
|
{ AL_EFFECT_FLANGER, FlangerStateFactory_getFactory },
|
2018-05-20 17:23:03 +02:00
|
|
|
{ AL_EFFECT_FREQUENCY_SHIFTER, FshifterStateFactory_getFactory },
|
2018-02-28 19:37:12 -08:00
|
|
|
{ AL_EFFECT_RING_MODULATOR, ModulatorStateFactory_getFactory },
|
2018-03-18 17:47:17 +01:00
|
|
|
{ AL_EFFECT_PITCH_SHIFTER, PshifterStateFactory_getFactory},
|
2018-02-28 19:37:12 -08:00
|
|
|
{ AL_EFFECT_DEDICATED_DIALOGUE, DedicatedStateFactory_getFactory },
|
|
|
|
{ AL_EFFECT_DEDICATED_LOW_FREQUENCY_EFFECT, DedicatedStateFactory_getFactory }
|
2018-01-28 00:10:12 -08:00
|
|
|
};
|
|
|
|
|
2018-11-20 09:47:49 -08:00
|
|
|
inline EffectStateFactory *getFactoryByType(ALenum type)
|
2018-01-27 19:01:25 -08:00
|
|
|
{
|
2018-11-20 09:47:49 -08:00
|
|
|
auto iter = std::find_if(std::begin(FactoryList), std::end(FactoryList),
|
|
|
|
[type](const FactoryItem &item) noexcept -> bool
|
|
|
|
{ return item.Type == type; }
|
|
|
|
);
|
|
|
|
return (iter != std::end(FactoryList)) ? iter->GetFactory() : nullptr;
|
2018-01-27 19:01:25 -08:00
|
|
|
}
|
|
|
|
|
2018-01-27 17:24:18 -08:00
|
|
|
|
2016-08-25 06:17:36 -07:00
|
|
|
#define DO_UPDATEPROPS() do { \
|
2018-11-20 09:47:49 -08:00
|
|
|
if(!context->DeferUpdates.load(std::memory_order_acquire)) \
|
|
|
|
UpdateEffectSlotProps(slot, context.get()); \
|
2016-08-25 06:17:36 -07:00
|
|
|
else \
|
2018-11-20 10:45:01 -08:00
|
|
|
slot->PropsClean.clear(std::memory_order_release); \
|
2016-08-25 06:17:36 -07:00
|
|
|
} while(0)
|
|
|
|
|
2018-11-20 09:47:49 -08:00
|
|
|
} // namespace
|
2010-05-12 02:20:14 -07:00
|
|
|
|
2010-03-23 17:44:01 -07:00
|
|
|
AL_API ALvoid AL_APIENTRY alGenAuxiliaryEffectSlots(ALsizei n, ALuint *effectslots)
|
2007-12-17 17:43:19 -08:00
|
|
|
{
|
2018-11-20 09:47:49 -08:00
|
|
|
ContextRef context{GetContextRef()};
|
|
|
|
if(UNLIKELY(!context)) return;
|
2007-12-17 17:43:19 -08:00
|
|
|
|
2018-10-29 02:05:45 +01:00
|
|
|
if(n < 0)
|
2018-11-20 09:47:49 -08:00
|
|
|
SETERR_RETURN(context.get(), AL_INVALID_VALUE,, "Generating %d effect slots", n);
|
|
|
|
if(n == 0) return;
|
2014-04-10 20:49:01 -07:00
|
|
|
|
2018-11-26 21:50:48 -08:00
|
|
|
std::unique_lock<std::mutex> slotlock{context->EffectSlotLock};
|
2018-11-20 09:47:49 -08:00
|
|
|
ALCdevice *device{context->Device};
|
|
|
|
for(ALsizei cur{0};cur < n;cur++)
|
2007-12-17 17:43:19 -08:00
|
|
|
{
|
2018-11-18 02:39:27 -08:00
|
|
|
auto iter = std::find_if(context->EffectSlotList.begin(), context->EffectSlotList.end(),
|
|
|
|
[](const ALeffectslotPtr &entry) noexcept -> bool
|
|
|
|
{ return !entry; }
|
|
|
|
);
|
|
|
|
if(iter == context->EffectSlotList.end())
|
2018-01-27 17:24:18 -08:00
|
|
|
{
|
2018-11-20 09:47:49 -08:00
|
|
|
if(UNLIKELY(device->AuxiliaryEffectSlotMax == context->EffectSlotList.size()))
|
2018-09-14 14:53:35 -07:00
|
|
|
{
|
2018-11-20 09:47:49 -08:00
|
|
|
slotlock.unlock();
|
2018-09-14 14:53:35 -07:00
|
|
|
alDeleteAuxiliaryEffectSlots(cur, effectslots);
|
2018-11-20 09:47:49 -08:00
|
|
|
alSetError(context.get(), AL_OUT_OF_MEMORY,
|
2018-09-14 14:53:35 -07:00
|
|
|
"Exceeding %u auxiliary effect slot limit", device->AuxiliaryEffectSlotMax);
|
2018-11-20 09:47:49 -08:00
|
|
|
return;
|
2018-09-14 14:53:35 -07:00
|
|
|
}
|
2018-11-18 02:39:27 -08:00
|
|
|
context->EffectSlotList.emplace_back(nullptr);
|
|
|
|
iter = context->EffectSlotList.end() - 1;
|
2018-01-27 17:24:18 -08:00
|
|
|
}
|
2018-11-18 02:39:27 -08:00
|
|
|
|
2018-11-20 10:01:20 -08:00
|
|
|
*iter = std::unique_ptr<ALeffectslot>(new ALeffectslot{});
|
|
|
|
ALenum err{InitEffectSlot(iter->get())};
|
2018-11-18 02:52:46 -08:00
|
|
|
if(err != AL_NO_ERROR)
|
2013-03-24 13:55:41 -07:00
|
|
|
{
|
2018-11-20 10:01:20 -08:00
|
|
|
*iter = nullptr;
|
2018-11-20 09:47:49 -08:00
|
|
|
slotlock.unlock();
|
2013-10-07 11:30:11 -07:00
|
|
|
|
2012-04-24 22:57:23 -07:00
|
|
|
alDeleteAuxiliaryEffectSlots(cur, effectslots);
|
2018-11-20 09:47:49 -08:00
|
|
|
alSetError(context.get(), err, "Effect slot object allocation failed");
|
|
|
|
return;
|
2013-03-24 13:55:41 -07:00
|
|
|
}
|
2018-11-20 10:01:20 -08:00
|
|
|
aluInitEffectPanning(iter->get());
|
2016-01-28 00:02:46 -08:00
|
|
|
|
2018-11-20 10:01:20 -08:00
|
|
|
ALuint id = std::distance(context->EffectSlotList.begin(), iter) + 1;
|
|
|
|
(*iter)->id = id;
|
|
|
|
effectslots[cur] = id;
|
2013-10-07 11:30:11 -07:00
|
|
|
}
|
2018-11-20 09:47:49 -08:00
|
|
|
AddActiveEffectSlots(effectslots, n, context.get());
|
2007-12-17 17:43:19 -08:00
|
|
|
}
|
|
|
|
|
2011-09-22 00:31:42 -07:00
|
|
|
AL_API ALvoid AL_APIENTRY alDeleteAuxiliaryEffectSlots(ALsizei n, const ALuint *effectslots)
|
2007-12-17 17:43:19 -08:00
|
|
|
{
|
2018-11-20 09:47:49 -08:00
|
|
|
ContextRef context{GetContextRef()};
|
|
|
|
if(UNLIKELY(!context)) return;
|
2007-12-17 17:43:19 -08:00
|
|
|
|
2018-10-29 02:05:45 +01:00
|
|
|
if(n < 0)
|
2018-11-20 09:47:49 -08:00
|
|
|
SETERR_RETURN(context.get(), AL_INVALID_VALUE,, "Deleting %d effect slots", n);
|
|
|
|
if(n == 0) return;
|
2018-02-22 12:03:52 -08:00
|
|
|
|
2018-11-26 21:50:48 -08:00
|
|
|
std::lock_guard<std::mutex> _{context->EffectSlotLock};
|
2018-11-20 09:47:49 -08:00
|
|
|
auto effectslots_end = effectslots + n;
|
|
|
|
auto bad_slot = std::find_if(effectslots, effectslots_end,
|
|
|
|
[&context](ALuint id) -> bool
|
|
|
|
{
|
|
|
|
ALeffectslot *slot{LookupEffectSlot(context.get(), id)};
|
|
|
|
if(!slot)
|
|
|
|
{
|
|
|
|
alSetError(context.get(), AL_INVALID_NAME, "Invalid effect slot ID %u", id);
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
if(ReadRef(&slot->ref) != 0)
|
|
|
|
{
|
|
|
|
alSetError(context.get(), AL_INVALID_NAME, "Deleting in-use effect slot %u", id);
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
);
|
|
|
|
if(bad_slot != effectslots_end)
|
|
|
|
return;
|
2007-12-17 17:43:19 -08:00
|
|
|
|
2018-11-20 09:47:49 -08:00
|
|
|
// All effectslots are valid, remove and delete them
|
|
|
|
RemoveActiveEffectSlots(effectslots, n, context.get());
|
|
|
|
std::for_each(effectslots, effectslots_end,
|
2018-11-20 10:01:20 -08:00
|
|
|
[&context](ALuint id) noexcept -> void
|
|
|
|
{ context->EffectSlotList[id-1] = nullptr; }
|
2018-11-20 09:47:49 -08:00
|
|
|
);
|
2007-12-17 17:43:19 -08:00
|
|
|
}
|
|
|
|
|
2010-03-23 17:44:01 -07:00
|
|
|
AL_API ALboolean AL_APIENTRY alIsAuxiliaryEffectSlot(ALuint effectslot)
|
2007-12-17 17:43:19 -08:00
|
|
|
{
|
2018-11-20 09:47:49 -08:00
|
|
|
ContextRef context{GetContextRef()};
|
|
|
|
if(LIKELY(context))
|
|
|
|
{
|
2018-11-26 21:50:48 -08:00
|
|
|
std::lock_guard<std::mutex> _{context->EffectSlotLock};
|
2018-11-20 09:47:49 -08:00
|
|
|
if(LookupEffectSlot(context.get(), effectslot) != nullptr)
|
|
|
|
return AL_TRUE;
|
|
|
|
}
|
|
|
|
return AL_FALSE;
|
2007-12-17 17:43:19 -08:00
|
|
|
}
|
|
|
|
|
2012-04-19 22:40:40 -07:00
|
|
|
AL_API ALvoid AL_APIENTRY alAuxiliaryEffectSloti(ALuint effectslot, ALenum param, ALint value)
|
2007-12-17 17:43:19 -08:00
|
|
|
{
|
2018-11-20 09:47:49 -08:00
|
|
|
ContextRef context{GetContextRef()};
|
|
|
|
if(UNLIKELY(!context)) return;
|
|
|
|
|
2018-11-26 21:37:58 -08:00
|
|
|
std::lock_guard<std::mutex> _{context->PropLock};
|
2018-11-26 21:50:48 -08:00
|
|
|
std::lock_guard<std::mutex> __{context->EffectSlotLock};
|
2018-11-20 09:47:49 -08:00
|
|
|
ALeffectslot *slot = LookupEffectSlot(context.get(), effectslot);
|
|
|
|
if(UNLIKELY(!slot))
|
|
|
|
SETERR_RETURN(context.get(), AL_INVALID_NAME,, "Invalid effect slot ID %u", effectslot);
|
|
|
|
|
|
|
|
ALCdevice *device{};
|
|
|
|
ALenum err{};
|
2013-10-07 11:30:11 -07:00
|
|
|
switch(param)
|
2007-12-17 17:43:19 -08:00
|
|
|
{
|
2013-10-07 11:30:11 -07:00
|
|
|
case AL_EFFECTSLOT_EFFECT:
|
2016-05-12 18:26:33 -07:00
|
|
|
device = context->Device;
|
2016-05-12 23:12:11 -07:00
|
|
|
|
2018-11-26 22:06:53 -08:00
|
|
|
{ std::lock_guard<std::mutex> ___{device->EffectLock};
|
2018-11-20 09:47:49 -08:00
|
|
|
ALeffect *effect{value ? LookupEffect(device, value) : nullptr};
|
|
|
|
if(!(value == 0 || effect != nullptr))
|
|
|
|
SETERR_RETURN(context.get(), AL_INVALID_VALUE,, "Invalid effect ID %u", value);
|
|
|
|
err = InitializeEffect(context.get(), slot, effect);
|
2016-05-12 23:12:11 -07:00
|
|
|
}
|
2013-10-07 11:30:11 -07:00
|
|
|
if(err != AL_NO_ERROR)
|
2018-11-20 09:47:49 -08:00
|
|
|
{
|
|
|
|
alSetError(context.get(), err, "Effect initialization failed");
|
|
|
|
return;
|
|
|
|
}
|
2013-10-07 11:30:11 -07:00
|
|
|
break;
|
2007-12-18 14:22:59 -08:00
|
|
|
|
2013-10-07 11:30:11 -07:00
|
|
|
case AL_EFFECTSLOT_AUXILIARY_SEND_AUTO:
|
|
|
|
if(!(value == AL_TRUE || value == AL_FALSE))
|
2018-11-20 09:47:49 -08:00
|
|
|
SETERR_RETURN(context.get(), AL_INVALID_VALUE,,
|
|
|
|
"Effect slot auxiliary send auto out of range");
|
2013-10-07 11:30:11 -07:00
|
|
|
slot->AuxSendAuto = value;
|
|
|
|
break;
|
2007-12-18 17:41:44 -08:00
|
|
|
|
2013-10-07 11:30:11 -07:00
|
|
|
default:
|
2018-11-20 09:47:49 -08:00
|
|
|
SETERR_RETURN(context.get(), AL_INVALID_ENUM,,
|
|
|
|
"Invalid effect slot integer property 0x%04x", param);
|
2007-12-17 17:43:19 -08:00
|
|
|
}
|
2016-08-25 06:17:36 -07:00
|
|
|
DO_UPDATEPROPS();
|
2007-12-17 17:43:19 -08:00
|
|
|
}
|
|
|
|
|
2012-04-19 22:40:40 -07:00
|
|
|
AL_API ALvoid AL_APIENTRY alAuxiliaryEffectSlotiv(ALuint effectslot, ALenum param, const ALint *values)
|
2007-12-17 17:43:19 -08:00
|
|
|
{
|
2011-06-16 09:14:41 -07:00
|
|
|
switch(param)
|
|
|
|
{
|
2013-10-07 11:30:11 -07:00
|
|
|
case AL_EFFECTSLOT_EFFECT:
|
|
|
|
case AL_EFFECTSLOT_AUXILIARY_SEND_AUTO:
|
|
|
|
alAuxiliaryEffectSloti(effectslot, param, values[0]);
|
|
|
|
return;
|
2011-06-16 09:14:41 -07:00
|
|
|
}
|
|
|
|
|
2018-11-20 09:47:49 -08:00
|
|
|
ContextRef context{GetContextRef()};
|
|
|
|
if(UNLIKELY(!context)) return;
|
|
|
|
|
2018-11-26 21:50:48 -08:00
|
|
|
std::lock_guard<std::mutex> _{context->EffectSlotLock};
|
2018-11-20 09:47:49 -08:00
|
|
|
ALeffectslot *slot = LookupEffectSlot(context.get(), effectslot);
|
|
|
|
if(UNLIKELY(!slot))
|
|
|
|
SETERR_RETURN(context.get(), AL_INVALID_NAME,, "Invalid effect slot ID %u", effectslot);
|
2007-12-17 17:43:19 -08:00
|
|
|
|
2013-10-07 11:30:11 -07:00
|
|
|
switch(param)
|
2007-12-17 17:43:19 -08:00
|
|
|
{
|
2013-10-07 11:30:11 -07:00
|
|
|
default:
|
2018-11-20 09:47:49 -08:00
|
|
|
SETERR_RETURN(context.get(), AL_INVALID_ENUM,,
|
|
|
|
"Invalid effect slot integer-vector property 0x%04x", param);
|
2007-12-17 17:43:19 -08:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2012-04-19 22:40:40 -07:00
|
|
|
AL_API ALvoid AL_APIENTRY alAuxiliaryEffectSlotf(ALuint effectslot, ALenum param, ALfloat value)
|
2007-12-17 17:43:19 -08:00
|
|
|
{
|
2018-11-20 09:47:49 -08:00
|
|
|
ContextRef context{GetContextRef()};
|
|
|
|
if(UNLIKELY(!context)) return;
|
2007-12-17 17:43:19 -08:00
|
|
|
|
2018-11-26 21:37:58 -08:00
|
|
|
std::lock_guard<std::mutex> _{context->PropLock};
|
2018-11-26 21:50:48 -08:00
|
|
|
std::lock_guard<std::mutex> __{context->EffectSlotLock};
|
2018-11-20 09:47:49 -08:00
|
|
|
ALeffectslot *slot = LookupEffectSlot(context.get(), effectslot);
|
|
|
|
if(UNLIKELY(!slot))
|
|
|
|
SETERR_RETURN(context.get(), AL_INVALID_NAME,, "Invalid effect slot ID %u", effectslot);
|
2007-12-17 17:43:19 -08:00
|
|
|
|
2013-10-07 11:30:11 -07:00
|
|
|
switch(param)
|
2007-12-17 17:43:19 -08:00
|
|
|
{
|
2013-10-07 11:30:11 -07:00
|
|
|
case AL_EFFECTSLOT_GAIN:
|
|
|
|
if(!(value >= 0.0f && value <= 1.0f))
|
2018-11-20 09:47:49 -08:00
|
|
|
SETERR_RETURN(context.get(), AL_INVALID_VALUE,, "Effect slot gain out of range");
|
2013-10-07 11:30:11 -07:00
|
|
|
slot->Gain = value;
|
|
|
|
break;
|
2007-12-18 15:47:24 -08:00
|
|
|
|
2013-10-07 11:30:11 -07:00
|
|
|
default:
|
2018-11-20 09:47:49 -08:00
|
|
|
SETERR_RETURN(context.get(), AL_INVALID_ENUM,, "Invalid effect slot float property 0x%04x",
|
|
|
|
param);
|
2007-12-17 17:43:19 -08:00
|
|
|
}
|
2016-08-25 06:17:36 -07:00
|
|
|
DO_UPDATEPROPS();
|
2007-12-17 17:43:19 -08:00
|
|
|
}
|
|
|
|
|
2012-04-19 22:40:40 -07:00
|
|
|
AL_API ALvoid AL_APIENTRY alAuxiliaryEffectSlotfv(ALuint effectslot, ALenum param, const ALfloat *values)
|
2007-12-17 17:43:19 -08:00
|
|
|
{
|
2011-06-16 09:14:41 -07:00
|
|
|
switch(param)
|
|
|
|
{
|
2013-10-07 11:30:11 -07:00
|
|
|
case AL_EFFECTSLOT_GAIN:
|
|
|
|
alAuxiliaryEffectSlotf(effectslot, param, values[0]);
|
|
|
|
return;
|
2011-06-16 09:14:41 -07:00
|
|
|
}
|
|
|
|
|
2018-11-20 09:47:49 -08:00
|
|
|
ContextRef context{GetContextRef()};
|
|
|
|
if(UNLIKELY(!context)) return;
|
|
|
|
|
2018-11-26 21:50:48 -08:00
|
|
|
std::lock_guard<std::mutex> _{context->EffectSlotLock};
|
2018-11-20 09:47:49 -08:00
|
|
|
ALeffectslot *slot = LookupEffectSlot(context.get(), effectslot);
|
|
|
|
if(UNLIKELY(!slot))
|
|
|
|
SETERR_RETURN(context.get(), AL_INVALID_NAME,, "Invalid effect slot ID %u", effectslot);
|
2007-12-17 17:43:19 -08:00
|
|
|
|
2013-10-07 11:30:11 -07:00
|
|
|
switch(param)
|
2007-12-17 17:43:19 -08:00
|
|
|
{
|
2013-10-07 11:30:11 -07:00
|
|
|
default:
|
2018-11-20 09:47:49 -08:00
|
|
|
SETERR_RETURN(context.get(), AL_INVALID_ENUM,,
|
|
|
|
"Invalid effect slot float-vector property 0x%04x", param);
|
2007-12-17 17:43:19 -08:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2012-04-19 22:40:40 -07:00
|
|
|
AL_API ALvoid AL_APIENTRY alGetAuxiliaryEffectSloti(ALuint effectslot, ALenum param, ALint *value)
|
2007-12-17 17:43:19 -08:00
|
|
|
{
|
2018-11-20 09:47:49 -08:00
|
|
|
ContextRef context{GetContextRef()};
|
|
|
|
if(UNLIKELY(!context)) return;
|
2007-12-17 17:43:19 -08:00
|
|
|
|
2018-11-26 21:50:48 -08:00
|
|
|
std::lock_guard<std::mutex> _{context->EffectSlotLock};
|
2018-11-20 09:47:49 -08:00
|
|
|
ALeffectslot *slot = LookupEffectSlot(context.get(), effectslot);
|
|
|
|
if(UNLIKELY(!slot))
|
|
|
|
SETERR_RETURN(context.get(), AL_INVALID_NAME,, "Invalid effect slot ID %u", effectslot);
|
2007-12-17 17:43:19 -08:00
|
|
|
|
2013-10-07 11:30:11 -07:00
|
|
|
switch(param)
|
2007-12-17 17:43:19 -08:00
|
|
|
{
|
2013-10-07 11:30:11 -07:00
|
|
|
case AL_EFFECTSLOT_AUXILIARY_SEND_AUTO:
|
|
|
|
*value = slot->AuxSendAuto;
|
|
|
|
break;
|
2007-12-18 17:41:44 -08:00
|
|
|
|
2013-10-07 11:30:11 -07:00
|
|
|
default:
|
2018-11-20 09:47:49 -08:00
|
|
|
SETERR_RETURN(context.get(), AL_INVALID_ENUM,,
|
|
|
|
"Invalid effect slot integer property 0x%04x", param);
|
2007-12-17 17:43:19 -08:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2012-04-19 22:40:40 -07:00
|
|
|
AL_API ALvoid AL_APIENTRY alGetAuxiliaryEffectSlotiv(ALuint effectslot, ALenum param, ALint *values)
|
2007-12-17 17:43:19 -08:00
|
|
|
{
|
2011-06-16 09:14:41 -07:00
|
|
|
switch(param)
|
|
|
|
{
|
2013-10-07 11:30:11 -07:00
|
|
|
case AL_EFFECTSLOT_EFFECT:
|
|
|
|
case AL_EFFECTSLOT_AUXILIARY_SEND_AUTO:
|
|
|
|
alGetAuxiliaryEffectSloti(effectslot, param, values);
|
|
|
|
return;
|
2011-06-16 09:14:41 -07:00
|
|
|
}
|
|
|
|
|
2018-11-20 09:47:49 -08:00
|
|
|
ContextRef context{GetContextRef()};
|
|
|
|
if(UNLIKELY(!context)) return;
|
|
|
|
|
2018-11-26 21:50:48 -08:00
|
|
|
std::lock_guard<std::mutex> _{context->EffectSlotLock};
|
2018-11-20 09:47:49 -08:00
|
|
|
ALeffectslot *slot = LookupEffectSlot(context.get(), effectslot);
|
|
|
|
if(UNLIKELY(!slot))
|
|
|
|
SETERR_RETURN(context.get(), AL_INVALID_NAME,, "Invalid effect slot ID %u", effectslot);
|
2007-12-17 17:43:19 -08:00
|
|
|
|
2013-10-07 11:30:11 -07:00
|
|
|
switch(param)
|
2007-12-17 17:43:19 -08:00
|
|
|
{
|
2013-10-07 11:30:11 -07:00
|
|
|
default:
|
2018-11-20 09:47:49 -08:00
|
|
|
SETERR_RETURN(context.get(), AL_INVALID_ENUM,,
|
|
|
|
"Invalid effect slot integer-vector property 0x%04x", param);
|
2007-12-17 17:43:19 -08:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2012-04-19 22:40:40 -07:00
|
|
|
AL_API ALvoid AL_APIENTRY alGetAuxiliaryEffectSlotf(ALuint effectslot, ALenum param, ALfloat *value)
|
2007-12-17 17:43:19 -08:00
|
|
|
{
|
2018-11-20 09:47:49 -08:00
|
|
|
ContextRef context{GetContextRef()};
|
|
|
|
if(UNLIKELY(!context)) return;
|
2007-12-17 17:43:19 -08:00
|
|
|
|
2018-11-26 21:50:48 -08:00
|
|
|
std::lock_guard<std::mutex> _{context->EffectSlotLock};
|
2018-11-20 09:47:49 -08:00
|
|
|
ALeffectslot *slot = LookupEffectSlot(context.get(), effectslot);
|
|
|
|
if(UNLIKELY(!slot))
|
|
|
|
SETERR_RETURN(context.get(), AL_INVALID_NAME,, "Invalid effect slot ID %u", effectslot);
|
2007-12-17 17:43:19 -08:00
|
|
|
|
2013-10-07 11:30:11 -07:00
|
|
|
switch(param)
|
2007-12-17 17:43:19 -08:00
|
|
|
{
|
2013-10-07 11:30:11 -07:00
|
|
|
case AL_EFFECTSLOT_GAIN:
|
|
|
|
*value = slot->Gain;
|
|
|
|
break;
|
2007-12-18 15:47:24 -08:00
|
|
|
|
2013-10-07 11:30:11 -07:00
|
|
|
default:
|
2018-11-20 09:47:49 -08:00
|
|
|
SETERR_RETURN(context.get(), AL_INVALID_ENUM,,
|
|
|
|
"Invalid effect slot float property 0x%04x", param);
|
2007-12-17 17:43:19 -08:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2012-04-19 22:40:40 -07:00
|
|
|
AL_API ALvoid AL_APIENTRY alGetAuxiliaryEffectSlotfv(ALuint effectslot, ALenum param, ALfloat *values)
|
2007-12-17 17:43:19 -08:00
|
|
|
{
|
2011-06-16 09:14:41 -07:00
|
|
|
switch(param)
|
|
|
|
{
|
2013-10-07 11:30:11 -07:00
|
|
|
case AL_EFFECTSLOT_GAIN:
|
|
|
|
alGetAuxiliaryEffectSlotf(effectslot, param, values);
|
|
|
|
return;
|
2011-06-16 09:14:41 -07:00
|
|
|
}
|
|
|
|
|
2018-11-20 09:47:49 -08:00
|
|
|
ContextRef context{GetContextRef()};
|
|
|
|
if(UNLIKELY(!context)) return;
|
|
|
|
|
2018-11-26 21:50:48 -08:00
|
|
|
std::lock_guard<std::mutex> _{context->EffectSlotLock};
|
2018-11-20 09:47:49 -08:00
|
|
|
ALeffectslot *slot = LookupEffectSlot(context.get(), effectslot);
|
|
|
|
if(UNLIKELY(!slot))
|
|
|
|
SETERR_RETURN(context.get(), AL_INVALID_NAME,, "Invalid effect slot ID %u", effectslot);
|
2007-12-17 17:43:19 -08:00
|
|
|
|
2013-10-07 11:30:11 -07:00
|
|
|
switch(param)
|
2007-12-17 17:43:19 -08:00
|
|
|
{
|
2013-10-07 11:30:11 -07:00
|
|
|
default:
|
2018-11-20 09:47:49 -08:00
|
|
|
SETERR_RETURN(context.get(), AL_INVALID_ENUM,,
|
|
|
|
"Invalid effect slot float-vector property 0x%04x", param);
|
2007-12-17 17:43:19 -08:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2017-09-27 11:13:18 -07:00
|
|
|
ALenum InitializeEffect(ALCcontext *Context, ALeffectslot *EffectSlot, ALeffect *effect)
|
2013-03-19 05:39:34 -07:00
|
|
|
{
|
2018-11-20 09:47:49 -08:00
|
|
|
ALenum newtype{effect ? effect->type : AL_EFFECT_NULL};
|
2016-05-12 18:26:33 -07:00
|
|
|
if(newtype != EffectSlot->Effect.Type)
|
2011-09-01 18:51:24 -07:00
|
|
|
{
|
2018-11-20 09:47:49 -08:00
|
|
|
EffectStateFactory *factory{getFactoryByType(newtype)};
|
2013-05-21 12:47:18 -07:00
|
|
|
if(!factory)
|
|
|
|
{
|
|
|
|
ERR("Failed to find factory for effect type 0x%04x\n", newtype);
|
|
|
|
return AL_INVALID_ENUM;
|
|
|
|
}
|
2018-11-20 09:47:49 -08:00
|
|
|
EffectState *State{factory->create()};
|
2016-05-27 19:40:54 -07:00
|
|
|
if(!State) return AL_OUT_OF_MEMORY;
|
2013-03-19 05:39:34 -07:00
|
|
|
|
2018-11-21 09:07:02 -08:00
|
|
|
FPUCtl mixer_mode{};
|
|
|
|
ALCdevice *Device{Context->Device};
|
2018-11-26 21:29:11 -08:00
|
|
|
std::unique_lock<std::mutex> backlock{Device->BackendLock};
|
2018-11-21 09:07:02 -08:00
|
|
|
State->mOutBuffer = Device->Dry.Buffer;
|
|
|
|
State->mOutChannels = Device->Dry.NumChannels;
|
|
|
|
if(State->deviceUpdate(Device) == AL_FALSE)
|
|
|
|
{
|
|
|
|
backlock.unlock();
|
|
|
|
mixer_mode.leave();
|
|
|
|
State->DecRef();
|
|
|
|
return AL_OUT_OF_MEMORY;
|
|
|
|
}
|
|
|
|
mixer_mode.leave();
|
2011-09-29 05:25:01 -07:00
|
|
|
|
2016-05-12 19:05:06 -07:00
|
|
|
if(!effect)
|
|
|
|
{
|
|
|
|
EffectSlot->Effect.Type = AL_EFFECT_NULL;
|
|
|
|
memset(&EffectSlot->Effect.Props, 0, sizeof(EffectSlot->Effect.Props));
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
EffectSlot->Effect.Type = effect->type;
|
2016-07-06 13:33:40 -07:00
|
|
|
EffectSlot->Effect.Props = effect->Props;
|
2016-05-12 19:05:06 -07:00
|
|
|
}
|
2016-05-12 18:26:33 -07:00
|
|
|
|
2018-11-19 22:34:26 -08:00
|
|
|
EffectSlot->Effect.State->DecRef();
|
2016-05-12 19:05:06 -07:00
|
|
|
EffectSlot->Effect.State = State;
|
2009-05-29 01:32:54 -07:00
|
|
|
}
|
2016-05-12 19:05:06 -07:00
|
|
|
else if(effect)
|
2016-07-06 13:33:40 -07:00
|
|
|
EffectSlot->Effect.Props = effect->Props;
|
2012-03-13 14:58:34 -07:00
|
|
|
|
2016-08-25 04:57:58 -07:00
|
|
|
/* Remove state references from old effect slot property updates. */
|
2018-11-20 09:47:49 -08:00
|
|
|
ALeffectslotProps *props{Context->FreeEffectslotProps.load()};
|
2016-08-25 04:57:58 -07:00
|
|
|
while(props)
|
|
|
|
{
|
2017-03-08 03:38:28 -08:00
|
|
|
if(props->State)
|
2018-11-19 22:34:26 -08:00
|
|
|
props->State->DecRef();
|
2018-11-16 18:28:39 -08:00
|
|
|
props->State = nullptr;
|
2018-11-26 18:19:58 -08:00
|
|
|
props = props->next.load(std::memory_order_relaxed);
|
2016-08-25 04:57:58 -07:00
|
|
|
}
|
|
|
|
|
2012-03-13 14:58:34 -07:00
|
|
|
return AL_NO_ERROR;
|
Implement AL_EFFECT_REVERB
Here is a quick description of how the reverb effect works:
+--->---+*(4)
| V new sample
+-----+---+---+ |
|extra|ltr|ref| <- +*(1)
+-----+---+---+
(3,5)*| |*(2)
+-->|
V
out sample
1) Apply master reverb gain to incoming sample and place it at the head of the
buffer. The master reverb gainhf was already applied when the source was
initially mixed.
2) Copy the delayed reflection sample to an output sample and apply the
reflection gain.
3) Apply the late reverb gain to the late reverb sample
4) Copy the end of the buffer, applying a decay gain and the decay hf ratio,
and add to the late reverb.
5) Copy the late reverb sample, adding to the output sample.
Then the head and sampling points are shifted forward, and done again for each
new sample. The extra buffer length is determined by the Reverb Density
property. A value of 0 gives a length of 0.1 seconds (long, with fairly
distinct echos) , and 1 gives 0.075 seconds (short, indistinct echos).
The decay gain is calculated such that after a number of loops to satisfy the
Decay Time, a sample will be 1/32768th as powerful (virtually insignificant to
the resulting output, and only getting further reduced). It is calculated as:
DecayGain = pow(1.0f/32768.0f, 1.0/(DecayTime/ExtraLength));
Things to note: Reverb Diffusion is not currently handled, nor is Decay HF
Limit. Decay HF Ratios above 1 probably give incorrect results. Also, this
method likely sucks, but it's the best I can come up with before release. :)
2008-01-18 21:25:40 -08:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2018-11-19 22:34:26 -08:00
|
|
|
void EffectState::IncRef() noexcept
|
2016-08-25 04:57:58 -07:00
|
|
|
{
|
2018-11-19 22:34:26 -08:00
|
|
|
auto ref = IncrementRef(&mRef);
|
|
|
|
TRACEREF("%p increasing refcount to %u\n", this, ref);
|
2016-08-25 03:42:43 -07:00
|
|
|
}
|
|
|
|
|
2018-11-19 22:34:26 -08:00
|
|
|
void EffectState::DecRef() noexcept
|
2016-05-12 18:26:33 -07:00
|
|
|
{
|
2018-11-19 22:34:26 -08:00
|
|
|
auto ref = DecrementRef(&mRef);
|
|
|
|
TRACEREF("%p decreasing refcount to %u\n", this, ref);
|
|
|
|
if(ref == 0) delete this;
|
2016-05-12 18:26:33 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2012-01-20 16:23:15 -08:00
|
|
|
ALenum InitEffectSlot(ALeffectslot *slot)
|
|
|
|
{
|
2018-11-18 06:15:02 -08:00
|
|
|
EffectStateFactory *factory{getFactoryByType(slot->Effect.Type)};
|
2018-12-02 15:29:26 -08:00
|
|
|
if(!factory) return AL_INVALID_VALUE;
|
2018-11-19 06:43:37 -08:00
|
|
|
slot->Effect.State = factory->create();
|
2018-02-28 19:37:12 -08:00
|
|
|
if(!slot->Effect.State) return AL_OUT_OF_MEMORY;
|
2012-01-20 16:23:15 -08:00
|
|
|
|
2018-11-19 22:34:26 -08:00
|
|
|
slot->Effect.State->IncRef();
|
2018-11-19 23:48:45 -08:00
|
|
|
slot->Params.mEffectState = slot->Effect.State;
|
2012-01-20 16:23:15 -08:00
|
|
|
return AL_NO_ERROR;
|
|
|
|
}
|
|
|
|
|
2018-11-18 06:15:02 -08:00
|
|
|
ALeffectslot::~ALeffectslot()
|
2016-05-12 18:26:33 -07:00
|
|
|
{
|
2018-11-18 06:15:02 -08:00
|
|
|
struct ALeffectslotProps *props{Update.load()};
|
2016-05-12 18:26:33 -07:00
|
|
|
if(props)
|
|
|
|
{
|
2018-11-19 22:34:26 -08:00
|
|
|
if(props->State) props->State->DecRef();
|
2016-05-12 18:26:33 -07:00
|
|
|
TRACE("Freed unapplied AuxiliaryEffectSlot update %p\n", props);
|
|
|
|
al_free(props);
|
|
|
|
}
|
|
|
|
|
2018-11-18 06:15:02 -08:00
|
|
|
if(Effect.State)
|
2018-11-19 22:34:26 -08:00
|
|
|
Effect.State->DecRef();
|
2018-11-19 23:48:45 -08:00
|
|
|
if(Params.mEffectState)
|
|
|
|
Params.mEffectState->DecRef();
|
2016-05-12 18:26:33 -07:00
|
|
|
}
|
|
|
|
|
2017-09-27 11:13:18 -07:00
|
|
|
void UpdateEffectSlotProps(ALeffectslot *slot, ALCcontext *context)
|
2016-05-12 18:26:33 -07:00
|
|
|
{
|
2016-08-25 18:19:13 -07:00
|
|
|
/* Get an unused property container, or allocate a new one as needed. */
|
2018-11-20 09:47:49 -08:00
|
|
|
ALeffectslotProps *props{context->FreeEffectslotProps.load(std::memory_order_relaxed)};
|
2016-08-25 04:57:58 -07:00
|
|
|
if(!props)
|
2018-11-16 18:28:39 -08:00
|
|
|
props = static_cast<ALeffectslotProps*>(al_calloc(16, sizeof(*props)));
|
2016-08-25 18:19:13 -07:00
|
|
|
else
|
2016-05-12 18:26:33 -07:00
|
|
|
{
|
2016-08-25 18:19:13 -07:00
|
|
|
struct ALeffectslotProps *next;
|
|
|
|
do {
|
2018-11-19 03:21:58 -08:00
|
|
|
next = props->next.load(std::memory_order_relaxed);
|
|
|
|
} while(context->FreeEffectslotProps.compare_exchange_weak(props, next,
|
|
|
|
std::memory_order_seq_cst, std::memory_order_acquire) == 0);
|
2016-05-12 18:26:33 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
/* Copy in current property values. */
|
2017-03-08 03:38:28 -08:00
|
|
|
props->Gain = slot->Gain;
|
|
|
|
props->AuxSendAuto = slot->AuxSendAuto;
|
2016-05-12 18:26:33 -07:00
|
|
|
|
2017-03-08 03:38:28 -08:00
|
|
|
props->Type = slot->Effect.Type;
|
2016-07-06 13:33:40 -07:00
|
|
|
props->Props = slot->Effect.Props;
|
2016-05-12 18:26:33 -07:00
|
|
|
/* Swap out any stale effect state object there may be in the container, to
|
|
|
|
* delete it.
|
|
|
|
*/
|
2018-11-20 09:47:49 -08:00
|
|
|
EffectState *oldstate{props->State};
|
2018-11-19 22:34:26 -08:00
|
|
|
slot->Effect.State->IncRef();
|
2017-03-08 03:38:28 -08:00
|
|
|
props->State = slot->Effect.State;
|
2016-05-12 18:26:33 -07:00
|
|
|
|
|
|
|
/* Set the new container for updating internal parameters. */
|
2018-11-19 03:21:58 -08:00
|
|
|
props = slot->Update.exchange(props, std::memory_order_acq_rel);
|
2016-05-12 18:26:33 -07:00
|
|
|
if(props)
|
|
|
|
{
|
|
|
|
/* If there was an unused update container, put it back in the
|
|
|
|
* freelist.
|
|
|
|
*/
|
2018-09-21 02:37:37 -07:00
|
|
|
if(props->State)
|
2018-11-19 22:34:26 -08:00
|
|
|
props->State->DecRef();
|
2018-11-16 18:28:39 -08:00
|
|
|
props->State = nullptr;
|
2018-11-19 01:20:03 -08:00
|
|
|
AtomicReplaceHead(context->FreeEffectslotProps, props);
|
2016-05-12 18:26:33 -07:00
|
|
|
}
|
|
|
|
|
2016-08-25 04:57:58 -07:00
|
|
|
if(oldstate)
|
2018-11-19 22:34:26 -08:00
|
|
|
oldstate->DecRef();
|
2016-05-12 18:26:33 -07:00
|
|
|
}
|
|
|
|
|
2016-08-25 06:17:36 -07:00
|
|
|
void UpdateAllEffectSlotProps(ALCcontext *context)
|
|
|
|
{
|
2018-11-26 21:50:48 -08:00
|
|
|
std::lock_guard<std::mutex> _{context->EffectSlotLock};
|
2018-11-20 09:47:49 -08:00
|
|
|
ALeffectslotArray *auxslots{context->ActiveAuxSlots.load(std::memory_order_acquire)};
|
|
|
|
for(ALsizei i{0};i < auxslots->count;i++)
|
2016-08-25 06:17:36 -07:00
|
|
|
{
|
2017-03-27 23:16:23 -07:00
|
|
|
ALeffectslot *slot = auxslots->slot[i];
|
2018-11-20 10:45:01 -08:00
|
|
|
if(!slot->PropsClean.test_and_set(std::memory_order_acq_rel))
|
2017-09-27 11:13:18 -07:00
|
|
|
UpdateEffectSlotProps(slot, context);
|
2016-08-25 06:17:36 -07:00
|
|
|
}
|
|
|
|
}
|