2007-12-18 01:43:19 +00: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 12:11:03 +00:00
|
|
|
* Free Software Foundation, Inc.,
|
|
|
|
* 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
|
2007-12-18 01:43:19 +00:00
|
|
|
* Or go to http://www.gnu.org/copyleft/lgpl.html
|
|
|
|
*/
|
|
|
|
|
|
|
|
#include "config.h"
|
|
|
|
|
2008-01-16 22:09:04 +00: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-19 05:25:40 +00:00
|
|
|
#include <math.h>
|
2008-01-16 22:09:04 +00:00
|
|
|
|
2007-12-18 01:43:19 +00:00
|
|
|
#include "AL/al.h"
|
|
|
|
#include "AL/alc.h"
|
|
|
|
#include "alMain.h"
|
|
|
|
#include "alAuxEffectSlot.h"
|
2008-01-01 03:34:52 +00:00
|
|
|
#include "alError.h"
|
2016-05-12 01:40:17 +00:00
|
|
|
#include "alListener.h"
|
2009-11-26 00:21:47 +00:00
|
|
|
#include "alSource.h"
|
2007-12-18 01:43:19 +00:00
|
|
|
|
2018-01-11 16:44:52 +00:00
|
|
|
#include "fpu_modes.h"
|
2016-03-29 07:44:58 +00:00
|
|
|
#include "almalloc.h"
|
|
|
|
|
2007-12-18 01:43:19 +00:00
|
|
|
|
2018-01-28 05:16:24 +00:00
|
|
|
extern inline void LockEffectSlotList(ALCcontext *context);
|
|
|
|
extern inline void UnlockEffectSlotList(ALCcontext *context);
|
|
|
|
|
2018-02-22 20:03:52 +00:00
|
|
|
static void AddActiveEffectSlots(const ALuint *slotids, ALsizei count, ALCcontext *context);
|
|
|
|
static void RemoveActiveEffectSlots(const ALuint *slotids, ALsizei count, ALCcontext *context);
|
|
|
|
|
2018-01-28 08:10:12 +00:00
|
|
|
static const struct {
|
|
|
|
ALenum Type;
|
2018-03-01 03:37:12 +00:00
|
|
|
EffectStateFactory* (*GetFactory)(void);
|
2018-01-28 08:10:12 +00:00
|
|
|
} FactoryList[] = {
|
2018-03-01 03:37:12 +00:00
|
|
|
{ AL_EFFECT_NULL, NullStateFactory_getFactory },
|
|
|
|
{ AL_EFFECT_EAXREVERB, ReverbStateFactory_getFactory },
|
|
|
|
{ AL_EFFECT_REVERB, ReverbStateFactory_getFactory },
|
|
|
|
{ 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 15:23:03 +00:00
|
|
|
{ AL_EFFECT_FREQUENCY_SHIFTER, FshifterStateFactory_getFactory },
|
2018-03-01 03:37:12 +00:00
|
|
|
{ AL_EFFECT_RING_MODULATOR, ModulatorStateFactory_getFactory },
|
2018-03-18 16:47:17 +00:00
|
|
|
{ AL_EFFECT_PITCH_SHIFTER, PshifterStateFactory_getFactory},
|
2018-03-01 03:37:12 +00:00
|
|
|
{ AL_EFFECT_DEDICATED_DIALOGUE, DedicatedStateFactory_getFactory },
|
|
|
|
{ AL_EFFECT_DEDICATED_LOW_FREQUENCY_EFFECT, DedicatedStateFactory_getFactory }
|
2018-01-28 08:10:12 +00:00
|
|
|
};
|
|
|
|
|
2018-03-01 03:37:12 +00:00
|
|
|
static inline EffectStateFactory *getFactoryByType(ALenum type)
|
2013-05-21 19:47:18 +00:00
|
|
|
{
|
2018-01-28 08:10:12 +00:00
|
|
|
size_t i;
|
|
|
|
for(i = 0;i < COUNTOF(FactoryList);i++)
|
|
|
|
{
|
|
|
|
if(FactoryList[i].Type == type)
|
|
|
|
return FactoryList[i].GetFactory();
|
|
|
|
}
|
2013-05-27 20:41:16 +00:00
|
|
|
return NULL;
|
2013-05-21 19:47:18 +00:00
|
|
|
}
|
2013-03-19 12:39:34 +00:00
|
|
|
|
2016-08-25 11:57:58 +00:00
|
|
|
static void ALeffectState_IncRef(ALeffectState *state);
|
|
|
|
|
2018-01-28 01:24:18 +00:00
|
|
|
|
|
|
|
static inline ALeffectslot *LookupEffectSlot(ALCcontext *context, ALuint id)
|
|
|
|
{
|
|
|
|
id--;
|
|
|
|
if(UNLIKELY(id >= VECTOR_SIZE(context->EffectSlotList)))
|
|
|
|
return NULL;
|
|
|
|
return VECTOR_ELEM(context->EffectSlotList, id);
|
|
|
|
}
|
|
|
|
|
2018-01-28 03:01:25 +00:00
|
|
|
static inline ALeffect *LookupEffect(ALCdevice *device, ALuint id)
|
|
|
|
{
|
|
|
|
EffectSubList *sublist;
|
|
|
|
ALuint lidx = (id-1) >> 6;
|
|
|
|
ALsizei slidx = (id-1) & 0x3f;
|
|
|
|
|
|
|
|
if(UNLIKELY(lidx >= VECTOR_SIZE(device->EffectList)))
|
|
|
|
return NULL;
|
|
|
|
sublist = &VECTOR_ELEM(device->EffectList, lidx);
|
|
|
|
if(UNLIKELY(sublist->FreeMask & (U64(1)<<slidx)))
|
|
|
|
return NULL;
|
|
|
|
return sublist->Effects + slidx;
|
|
|
|
}
|
|
|
|
|
2018-01-28 01:24:18 +00:00
|
|
|
|
2016-08-25 13:17:36 +00:00
|
|
|
#define DO_UPDATEPROPS() do { \
|
|
|
|
if(!ATOMIC_LOAD(&context->DeferUpdates, almemory_order_acquire)) \
|
2017-09-27 18:13:18 +00:00
|
|
|
UpdateEffectSlotProps(slot, context); \
|
2016-08-25 13:17:36 +00:00
|
|
|
else \
|
2017-03-24 02:16:32 +00:00
|
|
|
ATOMIC_FLAG_CLEAR(&slot->PropsClean, almemory_order_release); \
|
2016-08-25 13:17:36 +00:00
|
|
|
} while(0)
|
|
|
|
|
2010-05-12 09:20:14 +00:00
|
|
|
|
2010-03-24 00:44:01 +00:00
|
|
|
AL_API ALvoid AL_APIENTRY alGenAuxiliaryEffectSlots(ALsizei n, ALuint *effectslots)
|
2007-12-18 01:43:19 +00:00
|
|
|
{
|
2018-01-28 07:07:29 +00:00
|
|
|
ALCdevice *device;
|
2013-10-07 18:30:11 +00:00
|
|
|
ALCcontext *context;
|
|
|
|
ALsizei cur;
|
2007-12-18 01:43:19 +00:00
|
|
|
|
2013-10-07 18:30:11 +00:00
|
|
|
context = GetContextRef();
|
|
|
|
if(!context) return;
|
2007-12-18 01:43:19 +00:00
|
|
|
|
2013-10-07 18:30:11 +00:00
|
|
|
if(!(n >= 0))
|
2018-01-25 23:59:59 +00:00
|
|
|
SETERR_GOTO(context, AL_INVALID_VALUE, done, "Generating %d effect slots", n);
|
2018-02-22 20:03:52 +00:00
|
|
|
if(n == 0) goto done;
|
2014-04-11 03:49:01 +00:00
|
|
|
|
2018-01-28 01:24:18 +00:00
|
|
|
LockEffectSlotList(context);
|
2018-02-22 20:03:52 +00:00
|
|
|
device = context->Device;
|
2018-01-29 01:56:47 +00:00
|
|
|
if(device->AuxiliaryEffectSlotMax - VECTOR_SIZE(context->EffectSlotList) < (ALuint)n)
|
2018-01-28 07:07:29 +00:00
|
|
|
{
|
|
|
|
UnlockEffectSlotList(context);
|
|
|
|
SETERR_GOTO(context, AL_OUT_OF_MEMORY, done, "Exceeding %u auxiliary effect slot limit",
|
|
|
|
device->AuxiliaryEffectSlotMax);
|
|
|
|
}
|
2013-10-07 18:30:11 +00:00
|
|
|
for(cur = 0;cur < n;cur++)
|
2007-12-18 01:43:19 +00:00
|
|
|
{
|
2018-01-28 01:24:18 +00:00
|
|
|
ALeffectslotPtr *iter = VECTOR_BEGIN(context->EffectSlotList);
|
|
|
|
ALeffectslotPtr *end = VECTOR_END(context->EffectSlotList);
|
|
|
|
ALeffectslot *slot = NULL;
|
2018-03-04 22:00:28 +00:00
|
|
|
ALenum err = AL_OUT_OF_MEMORY;
|
2017-03-28 06:16:23 +00:00
|
|
|
|
2018-01-28 01:24:18 +00:00
|
|
|
for(;iter != end;iter++)
|
|
|
|
{
|
|
|
|
if(!*iter)
|
|
|
|
break;
|
2007-12-18 01:43:19 +00:00
|
|
|
}
|
2018-01-28 01:24:18 +00:00
|
|
|
if(iter == end)
|
|
|
|
{
|
|
|
|
VECTOR_PUSH_BACK(context->EffectSlotList, NULL);
|
|
|
|
iter = &VECTOR_BACK(context->EffectSlotList);
|
|
|
|
}
|
|
|
|
slot = al_calloc(16, sizeof(ALeffectslot));
|
|
|
|
if(!slot || (err=InitEffectSlot(slot)) != AL_NO_ERROR)
|
2013-03-24 20:55:41 +00:00
|
|
|
{
|
2013-10-07 18:30:11 +00:00
|
|
|
al_free(slot);
|
2018-01-28 01:24:18 +00:00
|
|
|
UnlockEffectSlotList(context);
|
2013-10-07 18:30:11 +00:00
|
|
|
|
2012-04-25 05:57:23 +00:00
|
|
|
alDeleteAuxiliaryEffectSlots(cur, effectslots);
|
2018-01-28 01:24:18 +00:00
|
|
|
SETERR_GOTO(context, err, done, "Effect slot object allocation failed");
|
2013-03-24 20:55:41 +00:00
|
|
|
}
|
2016-01-28 08:02:46 +00:00
|
|
|
aluInitEffectPanning(slot);
|
|
|
|
|
2018-01-28 01:24:18 +00:00
|
|
|
slot->id = (iter - VECTOR_BEGIN(context->EffectSlotList)) + 1;
|
|
|
|
*iter = slot;
|
|
|
|
|
2013-10-07 18:30:11 +00:00
|
|
|
effectslots[cur] = slot->id;
|
|
|
|
}
|
2018-02-22 20:03:52 +00:00
|
|
|
AddActiveEffectSlots(effectslots, n, context);
|
2018-01-28 01:24:18 +00:00
|
|
|
UnlockEffectSlotList(context);
|
2007-12-18 01:43:19 +00:00
|
|
|
|
2013-10-07 18:30:11 +00:00
|
|
|
done:
|
|
|
|
ALCcontext_DecRef(context);
|
2007-12-18 01:43:19 +00:00
|
|
|
}
|
|
|
|
|
2011-09-22 07:31:42 +00:00
|
|
|
AL_API ALvoid AL_APIENTRY alDeleteAuxiliaryEffectSlots(ALsizei n, const ALuint *effectslots)
|
2007-12-18 01:43:19 +00:00
|
|
|
{
|
2013-10-07 18:30:11 +00:00
|
|
|
ALCcontext *context;
|
2012-04-25 05:57:23 +00:00
|
|
|
ALeffectslot *slot;
|
2007-12-18 01:43:19 +00:00
|
|
|
ALsizei i;
|
|
|
|
|
2013-10-07 18:30:11 +00:00
|
|
|
context = GetContextRef();
|
|
|
|
if(!context) return;
|
2007-12-18 01:43:19 +00:00
|
|
|
|
2018-01-28 01:24:18 +00:00
|
|
|
LockEffectSlotList(context);
|
2013-10-07 18:30:11 +00:00
|
|
|
if(!(n >= 0))
|
2018-01-25 23:59:59 +00:00
|
|
|
SETERR_GOTO(context, AL_INVALID_VALUE, done, "Deleting %d effect slots", n);
|
2018-02-22 20:03:52 +00:00
|
|
|
if(n == 0) goto done;
|
|
|
|
|
2013-10-07 18:30:11 +00:00
|
|
|
for(i = 0;i < n;i++)
|
2007-12-18 01:43:19 +00:00
|
|
|
{
|
2013-10-07 18:30:11 +00:00
|
|
|
if((slot=LookupEffectSlot(context, effectslots[i])) == NULL)
|
2018-01-25 23:59:59 +00:00
|
|
|
SETERR_GOTO(context, AL_INVALID_NAME, done, "Invalid effect slot ID %u",
|
|
|
|
effectslots[i]);
|
2014-05-14 09:47:07 +00:00
|
|
|
if(ReadRef(&slot->ref) != 0)
|
2018-01-25 23:59:59 +00:00
|
|
|
SETERR_GOTO(context, AL_INVALID_NAME, done, "Deleting in-use effect slot %u",
|
|
|
|
effectslots[i]);
|
2013-10-07 18:30:11 +00:00
|
|
|
}
|
2007-12-18 01:43:19 +00:00
|
|
|
|
2013-10-07 18:30:11 +00:00
|
|
|
// All effectslots are valid
|
2018-02-22 20:03:52 +00:00
|
|
|
RemoveActiveEffectSlots(effectslots, n, context);
|
2013-10-07 18:30:11 +00:00
|
|
|
for(i = 0;i < n;i++)
|
|
|
|
{
|
2018-01-28 01:24:18 +00:00
|
|
|
if((slot=LookupEffectSlot(context, effectslots[i])) == NULL)
|
2013-10-07 18:30:11 +00:00
|
|
|
continue;
|
2018-01-28 01:24:18 +00:00
|
|
|
VECTOR_ELEM(context->EffectSlotList, effectslots[i]-1) = NULL;
|
2007-12-18 01:43:19 +00:00
|
|
|
|
2016-05-13 01:26:33 +00:00
|
|
|
DeinitEffectSlot(slot);
|
2007-12-18 01:43:19 +00:00
|
|
|
|
2013-10-07 18:30:11 +00:00
|
|
|
memset(slot, 0, sizeof(*slot));
|
|
|
|
al_free(slot);
|
2007-12-18 01:43:19 +00:00
|
|
|
}
|
|
|
|
|
2013-10-07 18:30:11 +00:00
|
|
|
done:
|
2018-01-28 01:24:18 +00:00
|
|
|
UnlockEffectSlotList(context);
|
2013-10-07 18:30:11 +00:00
|
|
|
ALCcontext_DecRef(context);
|
2007-12-18 01:43:19 +00:00
|
|
|
}
|
|
|
|
|
2010-03-24 00:44:01 +00:00
|
|
|
AL_API ALboolean AL_APIENTRY alIsAuxiliaryEffectSlot(ALuint effectslot)
|
2007-12-18 01:43:19 +00:00
|
|
|
{
|
2013-10-07 18:30:11 +00:00
|
|
|
ALCcontext *context;
|
|
|
|
ALboolean ret;
|
2007-12-18 01:43:19 +00:00
|
|
|
|
2013-10-07 18:30:11 +00:00
|
|
|
context = GetContextRef();
|
|
|
|
if(!context) return AL_FALSE;
|
2007-12-18 01:43:19 +00:00
|
|
|
|
2018-01-28 01:24:18 +00:00
|
|
|
LockEffectSlotList(context);
|
2013-10-07 18:30:11 +00:00
|
|
|
ret = (LookupEffectSlot(context, effectslot) ? AL_TRUE : AL_FALSE);
|
2018-01-28 01:24:18 +00:00
|
|
|
UnlockEffectSlotList(context);
|
2007-12-18 01:43:19 +00:00
|
|
|
|
2013-10-07 18:30:11 +00:00
|
|
|
ALCcontext_DecRef(context);
|
2007-12-18 01:43:19 +00:00
|
|
|
|
2013-10-07 18:30:11 +00:00
|
|
|
return ret;
|
2007-12-18 01:43:19 +00:00
|
|
|
}
|
|
|
|
|
2012-04-20 05:40:40 +00:00
|
|
|
AL_API ALvoid AL_APIENTRY alAuxiliaryEffectSloti(ALuint effectslot, ALenum param, ALint value)
|
2007-12-18 01:43:19 +00:00
|
|
|
{
|
2013-10-07 18:30:11 +00:00
|
|
|
ALCdevice *device;
|
|
|
|
ALCcontext *context;
|
|
|
|
ALeffectslot *slot;
|
2012-04-25 05:57:23 +00:00
|
|
|
ALeffect *effect = NULL;
|
|
|
|
ALenum err;
|
2007-12-18 01:43:19 +00:00
|
|
|
|
2013-10-07 18:30:11 +00:00
|
|
|
context = GetContextRef();
|
|
|
|
if(!context) return;
|
2007-12-18 01:43:19 +00:00
|
|
|
|
2018-03-03 21:42:37 +00:00
|
|
|
almtx_lock(&context->PropLock);
|
2018-01-28 01:24:18 +00:00
|
|
|
LockEffectSlotList(context);
|
2013-10-07 18:30:11 +00:00
|
|
|
if((slot=LookupEffectSlot(context, effectslot)) == NULL)
|
2018-01-25 23:59:59 +00:00
|
|
|
SETERR_GOTO(context, AL_INVALID_NAME, done, "Invalid effect slot ID %u", effectslot);
|
2013-10-07 18:30:11 +00:00
|
|
|
switch(param)
|
2007-12-18 01:43:19 +00:00
|
|
|
{
|
2013-10-07 18:30:11 +00:00
|
|
|
case AL_EFFECTSLOT_EFFECT:
|
2016-05-13 01:26:33 +00:00
|
|
|
device = context->Device;
|
2016-05-13 06:12:11 +00:00
|
|
|
|
2018-01-28 05:16:24 +00:00
|
|
|
LockEffectList(device);
|
2013-10-07 18:30:11 +00:00
|
|
|
effect = (value ? LookupEffect(device, value) : NULL);
|
|
|
|
if(!(value == 0 || effect != NULL))
|
2016-05-13 06:12:11 +00:00
|
|
|
{
|
2018-01-28 05:16:24 +00:00
|
|
|
UnlockEffectList(device);
|
2018-01-25 23:59:59 +00:00
|
|
|
SETERR_GOTO(context, AL_INVALID_VALUE, done, "Invalid effect ID %u", value);
|
2016-05-13 06:12:11 +00:00
|
|
|
}
|
2017-09-27 18:13:18 +00:00
|
|
|
err = InitializeEffect(context, slot, effect);
|
2018-01-28 05:16:24 +00:00
|
|
|
UnlockEffectList(device);
|
2016-05-13 06:12:11 +00:00
|
|
|
|
2013-10-07 18:30:11 +00:00
|
|
|
if(err != AL_NO_ERROR)
|
2018-01-25 23:59:59 +00:00
|
|
|
SETERR_GOTO(context, err, done, "Effect initialization failed");
|
2013-10-07 18:30:11 +00:00
|
|
|
break;
|
2007-12-18 22:22:59 +00:00
|
|
|
|
2013-10-07 18:30:11 +00:00
|
|
|
case AL_EFFECTSLOT_AUXILIARY_SEND_AUTO:
|
|
|
|
if(!(value == AL_TRUE || value == AL_FALSE))
|
2018-01-25 23:59:59 +00:00
|
|
|
SETERR_GOTO(context, AL_INVALID_VALUE, done,
|
|
|
|
"Effect slot auxiliary send auto out of range");
|
2013-10-07 18:30:11 +00:00
|
|
|
slot->AuxSendAuto = value;
|
|
|
|
break;
|
2007-12-19 01:41:44 +00:00
|
|
|
|
2013-10-07 18:30:11 +00:00
|
|
|
default:
|
2018-01-25 23:59:59 +00:00
|
|
|
SETERR_GOTO(context, AL_INVALID_ENUM, done, "Invalid effect slot integer property 0x%04x",
|
|
|
|
param);
|
2007-12-18 01:43:19 +00:00
|
|
|
}
|
2016-08-25 13:17:36 +00:00
|
|
|
DO_UPDATEPROPS();
|
2007-12-18 01:43:19 +00:00
|
|
|
|
2013-10-07 18:30:11 +00:00
|
|
|
done:
|
2018-01-28 01:24:18 +00:00
|
|
|
UnlockEffectSlotList(context);
|
2018-03-03 21:42:37 +00:00
|
|
|
almtx_unlock(&context->PropLock);
|
2013-10-07 18:30:11 +00:00
|
|
|
ALCcontext_DecRef(context);
|
2007-12-18 01:43:19 +00:00
|
|
|
}
|
|
|
|
|
2012-04-20 05:40:40 +00:00
|
|
|
AL_API ALvoid AL_APIENTRY alAuxiliaryEffectSlotiv(ALuint effectslot, ALenum param, const ALint *values)
|
2007-12-18 01:43:19 +00:00
|
|
|
{
|
2013-10-07 18:30:11 +00:00
|
|
|
ALCcontext *context;
|
2007-12-18 01:43:19 +00:00
|
|
|
|
2011-06-16 16:14:41 +00:00
|
|
|
switch(param)
|
|
|
|
{
|
2013-10-07 18:30:11 +00:00
|
|
|
case AL_EFFECTSLOT_EFFECT:
|
|
|
|
case AL_EFFECTSLOT_AUXILIARY_SEND_AUTO:
|
|
|
|
alAuxiliaryEffectSloti(effectslot, param, values[0]);
|
|
|
|
return;
|
2011-06-16 16:14:41 +00:00
|
|
|
}
|
|
|
|
|
2013-10-07 18:30:11 +00:00
|
|
|
context = GetContextRef();
|
|
|
|
if(!context) return;
|
2007-12-18 01:43:19 +00:00
|
|
|
|
2018-01-28 01:24:18 +00:00
|
|
|
LockEffectSlotList(context);
|
2013-10-07 18:30:11 +00:00
|
|
|
if(LookupEffectSlot(context, effectslot) == NULL)
|
2018-01-25 23:59:59 +00:00
|
|
|
SETERR_GOTO(context, AL_INVALID_NAME, done, "Invalid effect slot ID %u", effectslot);
|
2013-10-07 18:30:11 +00:00
|
|
|
switch(param)
|
2007-12-18 01:43:19 +00:00
|
|
|
{
|
2013-10-07 18:30:11 +00:00
|
|
|
default:
|
2018-01-25 23:59:59 +00:00
|
|
|
alSetError(context, AL_INVALID_ENUM, "Invalid effect slot integer-vector property 0x%04x",
|
|
|
|
param);
|
2007-12-18 01:43:19 +00:00
|
|
|
}
|
|
|
|
|
2013-10-07 18:30:11 +00:00
|
|
|
done:
|
2018-01-28 01:24:18 +00:00
|
|
|
UnlockEffectSlotList(context);
|
2013-10-07 18:30:11 +00:00
|
|
|
ALCcontext_DecRef(context);
|
2007-12-18 01:43:19 +00:00
|
|
|
}
|
|
|
|
|
2012-04-20 05:40:40 +00:00
|
|
|
AL_API ALvoid AL_APIENTRY alAuxiliaryEffectSlotf(ALuint effectslot, ALenum param, ALfloat value)
|
2007-12-18 01:43:19 +00:00
|
|
|
{
|
2013-10-07 18:30:11 +00:00
|
|
|
ALCcontext *context;
|
|
|
|
ALeffectslot *slot;
|
2007-12-18 01:43:19 +00:00
|
|
|
|
2013-10-07 18:30:11 +00:00
|
|
|
context = GetContextRef();
|
|
|
|
if(!context) return;
|
2007-12-18 01:43:19 +00:00
|
|
|
|
2018-03-03 21:42:37 +00:00
|
|
|
almtx_lock(&context->PropLock);
|
2018-01-28 01:24:18 +00:00
|
|
|
LockEffectSlotList(context);
|
2013-10-07 18:30:11 +00:00
|
|
|
if((slot=LookupEffectSlot(context, effectslot)) == NULL)
|
2018-01-25 23:59:59 +00:00
|
|
|
SETERR_GOTO(context, AL_INVALID_NAME, done, "Invalid effect slot ID %u", effectslot);
|
2013-10-07 18:30:11 +00:00
|
|
|
switch(param)
|
2007-12-18 01:43:19 +00:00
|
|
|
{
|
2013-10-07 18:30:11 +00:00
|
|
|
case AL_EFFECTSLOT_GAIN:
|
|
|
|
if(!(value >= 0.0f && value <= 1.0f))
|
2018-01-25 23:59:59 +00:00
|
|
|
SETERR_GOTO(context, AL_INVALID_VALUE, done, "Effect slot gain out of range");
|
2013-10-07 18:30:11 +00:00
|
|
|
slot->Gain = value;
|
|
|
|
break;
|
2007-12-18 23:47:24 +00:00
|
|
|
|
2013-10-07 18:30:11 +00:00
|
|
|
default:
|
2018-01-25 23:59:59 +00:00
|
|
|
SETERR_GOTO(context, AL_INVALID_ENUM, done, "Invalid effect slot float property 0x%04x",
|
|
|
|
param);
|
2007-12-18 01:43:19 +00:00
|
|
|
}
|
2016-08-25 13:17:36 +00:00
|
|
|
DO_UPDATEPROPS();
|
2007-12-18 01:43:19 +00:00
|
|
|
|
2013-10-07 18:30:11 +00:00
|
|
|
done:
|
2018-01-28 01:24:18 +00:00
|
|
|
UnlockEffectSlotList(context);
|
2018-03-03 21:42:37 +00:00
|
|
|
almtx_unlock(&context->PropLock);
|
2013-10-07 18:30:11 +00:00
|
|
|
ALCcontext_DecRef(context);
|
2007-12-18 01:43:19 +00:00
|
|
|
}
|
|
|
|
|
2012-04-20 05:40:40 +00:00
|
|
|
AL_API ALvoid AL_APIENTRY alAuxiliaryEffectSlotfv(ALuint effectslot, ALenum param, const ALfloat *values)
|
2007-12-18 01:43:19 +00:00
|
|
|
{
|
2013-10-07 18:30:11 +00:00
|
|
|
ALCcontext *context;
|
2007-12-18 01:43:19 +00:00
|
|
|
|
2011-06-16 16:14:41 +00:00
|
|
|
switch(param)
|
|
|
|
{
|
2013-10-07 18:30:11 +00:00
|
|
|
case AL_EFFECTSLOT_GAIN:
|
|
|
|
alAuxiliaryEffectSlotf(effectslot, param, values[0]);
|
|
|
|
return;
|
2011-06-16 16:14:41 +00:00
|
|
|
}
|
|
|
|
|
2013-10-07 18:30:11 +00:00
|
|
|
context = GetContextRef();
|
|
|
|
if(!context) return;
|
2007-12-18 01:43:19 +00:00
|
|
|
|
2018-01-28 01:24:18 +00:00
|
|
|
LockEffectSlotList(context);
|
2013-10-07 18:30:11 +00:00
|
|
|
if(LookupEffectSlot(context, effectslot) == NULL)
|
2018-01-25 23:59:59 +00:00
|
|
|
SETERR_GOTO(context, AL_INVALID_NAME, done, "Invalid effect slot ID %u", effectslot);
|
2013-10-07 18:30:11 +00:00
|
|
|
switch(param)
|
2007-12-18 01:43:19 +00:00
|
|
|
{
|
2013-10-07 18:30:11 +00:00
|
|
|
default:
|
2018-01-25 23:59:59 +00:00
|
|
|
alSetError(context, AL_INVALID_ENUM, "Invalid effect slot float-vector property 0x%04x",
|
|
|
|
param);
|
2007-12-18 01:43:19 +00:00
|
|
|
}
|
|
|
|
|
2013-10-07 18:30:11 +00:00
|
|
|
done:
|
2018-01-28 01:24:18 +00:00
|
|
|
UnlockEffectSlotList(context);
|
2013-10-07 18:30:11 +00:00
|
|
|
ALCcontext_DecRef(context);
|
2007-12-18 01:43:19 +00:00
|
|
|
}
|
|
|
|
|
2012-04-20 05:40:40 +00:00
|
|
|
AL_API ALvoid AL_APIENTRY alGetAuxiliaryEffectSloti(ALuint effectslot, ALenum param, ALint *value)
|
2007-12-18 01:43:19 +00:00
|
|
|
{
|
2013-10-07 18:30:11 +00:00
|
|
|
ALCcontext *context;
|
|
|
|
ALeffectslot *slot;
|
2007-12-18 01:43:19 +00:00
|
|
|
|
2013-10-07 18:30:11 +00:00
|
|
|
context = GetContextRef();
|
|
|
|
if(!context) return;
|
2007-12-18 01:43:19 +00:00
|
|
|
|
2018-01-28 01:24:18 +00:00
|
|
|
LockEffectSlotList(context);
|
2013-10-07 18:30:11 +00:00
|
|
|
if((slot=LookupEffectSlot(context, effectslot)) == NULL)
|
2018-01-25 23:59:59 +00:00
|
|
|
SETERR_GOTO(context, AL_INVALID_NAME, done, "Invalid effect slot ID %u", effectslot);
|
2013-10-07 18:30:11 +00:00
|
|
|
switch(param)
|
2007-12-18 01:43:19 +00:00
|
|
|
{
|
2013-10-07 18:30:11 +00:00
|
|
|
case AL_EFFECTSLOT_AUXILIARY_SEND_AUTO:
|
|
|
|
*value = slot->AuxSendAuto;
|
|
|
|
break;
|
2007-12-19 01:41:44 +00:00
|
|
|
|
2013-10-07 18:30:11 +00:00
|
|
|
default:
|
2018-01-25 23:59:59 +00:00
|
|
|
alSetError(context, AL_INVALID_ENUM, "Invalid effect slot integer property 0x%04x", param);
|
2007-12-18 01:43:19 +00:00
|
|
|
}
|
|
|
|
|
2013-10-07 18:30:11 +00:00
|
|
|
done:
|
2018-01-28 01:24:18 +00:00
|
|
|
UnlockEffectSlotList(context);
|
2013-10-07 18:30:11 +00:00
|
|
|
ALCcontext_DecRef(context);
|
2007-12-18 01:43:19 +00:00
|
|
|
}
|
|
|
|
|
2012-04-20 05:40:40 +00:00
|
|
|
AL_API ALvoid AL_APIENTRY alGetAuxiliaryEffectSlotiv(ALuint effectslot, ALenum param, ALint *values)
|
2007-12-18 01:43:19 +00:00
|
|
|
{
|
2013-10-07 18:30:11 +00:00
|
|
|
ALCcontext *context;
|
2007-12-18 01:43:19 +00:00
|
|
|
|
2011-06-16 16:14:41 +00:00
|
|
|
switch(param)
|
|
|
|
{
|
2013-10-07 18:30:11 +00:00
|
|
|
case AL_EFFECTSLOT_EFFECT:
|
|
|
|
case AL_EFFECTSLOT_AUXILIARY_SEND_AUTO:
|
|
|
|
alGetAuxiliaryEffectSloti(effectslot, param, values);
|
|
|
|
return;
|
2011-06-16 16:14:41 +00:00
|
|
|
}
|
|
|
|
|
2013-10-07 18:30:11 +00:00
|
|
|
context = GetContextRef();
|
|
|
|
if(!context) return;
|
2007-12-18 01:43:19 +00:00
|
|
|
|
2018-01-28 01:24:18 +00:00
|
|
|
LockEffectSlotList(context);
|
2013-10-07 18:30:11 +00:00
|
|
|
if(LookupEffectSlot(context, effectslot) == NULL)
|
2018-01-25 23:59:59 +00:00
|
|
|
SETERR_GOTO(context, AL_INVALID_NAME, done, "Invalid effect slot ID %u", effectslot);
|
2013-10-07 18:30:11 +00:00
|
|
|
switch(param)
|
2007-12-18 01:43:19 +00:00
|
|
|
{
|
2013-10-07 18:30:11 +00:00
|
|
|
default:
|
2018-01-25 23:59:59 +00:00
|
|
|
alSetError(context, AL_INVALID_ENUM, "Invalid effect slot integer-vector property 0x%04x",
|
|
|
|
param);
|
2007-12-18 01:43:19 +00:00
|
|
|
}
|
|
|
|
|
2013-10-07 18:30:11 +00:00
|
|
|
done:
|
2018-01-28 01:24:18 +00:00
|
|
|
UnlockEffectSlotList(context);
|
2013-10-07 18:30:11 +00:00
|
|
|
ALCcontext_DecRef(context);
|
2007-12-18 01:43:19 +00:00
|
|
|
}
|
|
|
|
|
2012-04-20 05:40:40 +00:00
|
|
|
AL_API ALvoid AL_APIENTRY alGetAuxiliaryEffectSlotf(ALuint effectslot, ALenum param, ALfloat *value)
|
2007-12-18 01:43:19 +00:00
|
|
|
{
|
2013-10-07 18:30:11 +00:00
|
|
|
ALCcontext *context;
|
|
|
|
ALeffectslot *slot;
|
2007-12-18 01:43:19 +00:00
|
|
|
|
2013-10-07 18:30:11 +00:00
|
|
|
context = GetContextRef();
|
|
|
|
if(!context) return;
|
2007-12-18 01:43:19 +00:00
|
|
|
|
2018-01-28 01:24:18 +00:00
|
|
|
LockEffectSlotList(context);
|
2013-10-07 18:30:11 +00:00
|
|
|
if((slot=LookupEffectSlot(context, effectslot)) == NULL)
|
2018-01-25 23:59:59 +00:00
|
|
|
SETERR_GOTO(context, AL_INVALID_NAME, done, "Invalid effect slot ID %u", effectslot);
|
2013-10-07 18:30:11 +00:00
|
|
|
switch(param)
|
2007-12-18 01:43:19 +00:00
|
|
|
{
|
2013-10-07 18:30:11 +00:00
|
|
|
case AL_EFFECTSLOT_GAIN:
|
|
|
|
*value = slot->Gain;
|
|
|
|
break;
|
2007-12-18 23:47:24 +00:00
|
|
|
|
2013-10-07 18:30:11 +00:00
|
|
|
default:
|
2018-01-25 23:59:59 +00:00
|
|
|
alSetError(context, AL_INVALID_ENUM, "Invalid effect slot float property 0x%04x", param);
|
2007-12-18 01:43:19 +00:00
|
|
|
}
|
|
|
|
|
2013-10-07 18:30:11 +00:00
|
|
|
done:
|
2018-01-28 01:24:18 +00:00
|
|
|
UnlockEffectSlotList(context);
|
2013-10-07 18:30:11 +00:00
|
|
|
ALCcontext_DecRef(context);
|
2007-12-18 01:43:19 +00:00
|
|
|
}
|
|
|
|
|
2012-04-20 05:40:40 +00:00
|
|
|
AL_API ALvoid AL_APIENTRY alGetAuxiliaryEffectSlotfv(ALuint effectslot, ALenum param, ALfloat *values)
|
2007-12-18 01:43:19 +00:00
|
|
|
{
|
2013-10-07 18:30:11 +00:00
|
|
|
ALCcontext *context;
|
2007-12-18 01:43:19 +00:00
|
|
|
|
2011-06-16 16:14:41 +00:00
|
|
|
switch(param)
|
|
|
|
{
|
2013-10-07 18:30:11 +00:00
|
|
|
case AL_EFFECTSLOT_GAIN:
|
|
|
|
alGetAuxiliaryEffectSlotf(effectslot, param, values);
|
|
|
|
return;
|
2011-06-16 16:14:41 +00:00
|
|
|
}
|
|
|
|
|
2013-10-07 18:30:11 +00:00
|
|
|
context = GetContextRef();
|
|
|
|
if(!context) return;
|
2007-12-18 01:43:19 +00:00
|
|
|
|
2018-01-28 01:24:18 +00:00
|
|
|
LockEffectSlotList(context);
|
2013-10-07 18:30:11 +00:00
|
|
|
if(LookupEffectSlot(context, effectslot) == NULL)
|
2018-01-25 23:59:59 +00:00
|
|
|
SETERR_GOTO(context, AL_INVALID_NAME, done, "Invalid effect slot ID %u", effectslot);
|
2013-10-07 18:30:11 +00:00
|
|
|
switch(param)
|
2007-12-18 01:43:19 +00:00
|
|
|
{
|
2013-10-07 18:30:11 +00:00
|
|
|
default:
|
2018-01-25 23:59:59 +00:00
|
|
|
alSetError(context, AL_INVALID_ENUM, "Invalid effect slot float-vector property 0x%04x",
|
|
|
|
param);
|
2007-12-18 01:43:19 +00:00
|
|
|
}
|
|
|
|
|
2013-10-07 18:30:11 +00:00
|
|
|
done:
|
2018-01-28 01:24:18 +00:00
|
|
|
UnlockEffectSlotList(context);
|
2013-10-07 18:30:11 +00:00
|
|
|
ALCcontext_DecRef(context);
|
2007-12-18 01:43:19 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2017-09-27 18:13:18 +00:00
|
|
|
ALenum InitializeEffect(ALCcontext *Context, ALeffectslot *EffectSlot, ALeffect *effect)
|
2013-03-19 12:39:34 +00:00
|
|
|
{
|
2017-09-27 18:13:18 +00:00
|
|
|
ALCdevice *Device = Context->Device;
|
2013-03-19 12:39:34 +00:00
|
|
|
ALenum newtype = (effect ? effect->type : AL_EFFECT_NULL);
|
2016-08-25 11:57:58 +00:00
|
|
|
struct ALeffectslotProps *props;
|
|
|
|
ALeffectState *State;
|
2011-09-02 01:51:24 +00:00
|
|
|
|
2016-05-13 01:26:33 +00:00
|
|
|
if(newtype != EffectSlot->Effect.Type)
|
2011-09-02 01:51:24 +00:00
|
|
|
{
|
2018-03-01 03:37:12 +00:00
|
|
|
EffectStateFactory *factory;
|
2013-03-19 12:39:34 +00:00
|
|
|
|
2013-05-21 19:47:18 +00:00
|
|
|
factory = getFactoryByType(newtype);
|
|
|
|
if(!factory)
|
|
|
|
{
|
|
|
|
ERR("Failed to find factory for effect type 0x%04x\n", newtype);
|
|
|
|
return AL_INVALID_ENUM;
|
|
|
|
}
|
2018-03-01 03:37:12 +00:00
|
|
|
State = EffectStateFactory_create(factory);
|
2016-05-28 02:40:54 +00:00
|
|
|
if(!State) return AL_OUT_OF_MEMORY;
|
2013-03-19 12:39:34 +00:00
|
|
|
|
2017-07-14 05:30:39 +00:00
|
|
|
START_MIXER_MODE();
|
2016-05-28 02:40:54 +00:00
|
|
|
almtx_lock(&Device->BackendLock);
|
2016-03-17 17:10:26 +00:00
|
|
|
State->OutBuffer = Device->Dry.Buffer;
|
|
|
|
State->OutChannels = Device->Dry.NumChannels;
|
2013-11-03 00:30:28 +00:00
|
|
|
if(V(State,deviceUpdate)(Device) == AL_FALSE)
|
2009-05-31 18:54:49 +00:00
|
|
|
{
|
2016-05-28 02:40:54 +00:00
|
|
|
almtx_unlock(&Device->BackendLock);
|
2017-07-14 05:30:39 +00:00
|
|
|
LEAVE_MIXER_MODE();
|
2016-08-25 11:57:58 +00:00
|
|
|
ALeffectState_DecRef(State);
|
2012-03-13 21:58:34 +00:00
|
|
|
return AL_OUT_OF_MEMORY;
|
2009-05-31 18:54:49 +00:00
|
|
|
}
|
2016-05-28 02:40:54 +00:00
|
|
|
almtx_unlock(&Device->BackendLock);
|
2017-07-14 05:30:39 +00:00
|
|
|
END_MIXER_MODE();
|
2011-09-29 12:25:01 +00:00
|
|
|
|
2016-05-13 02:05:06 +00: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 20:33:40 +00:00
|
|
|
EffectSlot->Effect.Props = effect->Props;
|
2016-05-13 02:05:06 +00:00
|
|
|
}
|
2016-05-13 01:26:33 +00:00
|
|
|
|
2016-08-25 11:57:58 +00:00
|
|
|
ALeffectState_DecRef(EffectSlot->Effect.State);
|
2016-05-13 02:05:06 +00:00
|
|
|
EffectSlot->Effect.State = State;
|
2009-05-29 08:32:54 +00:00
|
|
|
}
|
2016-05-13 02:05:06 +00:00
|
|
|
else if(effect)
|
2016-07-06 20:33:40 +00:00
|
|
|
EffectSlot->Effect.Props = effect->Props;
|
2012-03-13 21:58:34 +00:00
|
|
|
|
2016-08-25 11:57:58 +00:00
|
|
|
/* Remove state references from old effect slot property updates. */
|
2017-09-27 18:13:18 +00:00
|
|
|
props = ATOMIC_LOAD_SEQ(&Context->FreeEffectslotProps);
|
2016-08-25 11:57:58 +00:00
|
|
|
while(props)
|
|
|
|
{
|
2017-03-08 11:38:28 +00:00
|
|
|
if(props->State)
|
|
|
|
ALeffectState_DecRef(props->State);
|
|
|
|
props->State = NULL;
|
2016-08-25 13:17:36 +00:00
|
|
|
props = ATOMIC_LOAD(&props->next, almemory_order_relaxed);
|
2016-08-25 11:57:58 +00:00
|
|
|
}
|
|
|
|
|
2012-03-13 21:58:34 +00: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-19 05:25:40 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2016-08-25 11:57:58 +00:00
|
|
|
static void ALeffectState_IncRef(ALeffectState *state)
|
|
|
|
{
|
|
|
|
uint ref;
|
|
|
|
ref = IncrementRef(&state->Ref);
|
|
|
|
TRACEREF("%p increasing refcount to %u\n", state, ref);
|
|
|
|
}
|
|
|
|
|
2017-09-27 18:13:18 +00:00
|
|
|
void ALeffectState_DecRef(ALeffectState *state)
|
2016-08-25 11:57:58 +00:00
|
|
|
{
|
|
|
|
uint ref;
|
|
|
|
ref = DecrementRef(&state->Ref);
|
|
|
|
TRACEREF("%p decreasing refcount to %u\n", state, ref);
|
|
|
|
if(ref == 0) DELETE_OBJ(state);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2016-08-25 10:42:43 +00:00
|
|
|
void ALeffectState_Construct(ALeffectState *state)
|
|
|
|
{
|
|
|
|
InitRef(&state->Ref, 1);
|
|
|
|
|
|
|
|
state->OutBuffer = NULL;
|
|
|
|
state->OutChannels = 0;
|
|
|
|
}
|
|
|
|
|
2016-05-13 01:26:33 +00:00
|
|
|
void ALeffectState_Destruct(ALeffectState *UNUSED(state))
|
|
|
|
{
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2018-02-22 20:03:52 +00:00
|
|
|
static void AddActiveEffectSlots(const ALuint *slotids, ALsizei count, ALCcontext *context)
|
|
|
|
{
|
|
|
|
struct ALeffectslotArray *curarray = ATOMIC_LOAD(&context->ActiveAuxSlots,
|
|
|
|
almemory_order_acquire);
|
|
|
|
struct ALeffectslotArray *newarray = NULL;
|
|
|
|
ALsizei newcount = curarray->count + count;
|
|
|
|
ALCdevice *device = context->Device;
|
|
|
|
ALsizei i, j;
|
|
|
|
|
|
|
|
/* Insert the new effect slots into the head of the array, followed by the
|
|
|
|
* existing ones.
|
|
|
|
*/
|
|
|
|
newarray = al_calloc(DEF_ALIGN, FAM_SIZE(struct ALeffectslotArray, slot, newcount));
|
|
|
|
newarray->count = newcount;
|
|
|
|
for(i = 0;i < count;i++)
|
|
|
|
newarray->slot[i] = LookupEffectSlot(context, slotids[i]);
|
|
|
|
for(j = 0;i < newcount;)
|
|
|
|
newarray->slot[i++] = curarray->slot[j++];
|
|
|
|
/* Remove any duplicates (first instance of each will be kept). */
|
|
|
|
for(i = 1;i < newcount;i++)
|
|
|
|
{
|
|
|
|
for(j = i;j != 0;)
|
|
|
|
{
|
2018-03-04 23:11:17 +00:00
|
|
|
if(UNLIKELY(newarray->slot[i] == newarray->slot[--j]))
|
|
|
|
{
|
|
|
|
newcount--;
|
|
|
|
for(j = i;j < newcount;j++)
|
|
|
|
newarray->slot[j] = newarray->slot[j+1];
|
|
|
|
i--;
|
2018-02-22 20:03:52 +00:00
|
|
|
break;
|
2018-03-04 23:11:17 +00:00
|
|
|
}
|
2018-02-22 20:03:52 +00:00
|
|
|
}
|
|
|
|
}
|
2018-03-04 23:11:17 +00:00
|
|
|
|
|
|
|
/* Reallocate newarray if the new size ended up smaller from duplicate
|
|
|
|
* removal.
|
|
|
|
*/
|
|
|
|
if(UNLIKELY(newcount < newarray->count))
|
|
|
|
{
|
|
|
|
struct ALeffectslotArray *tmpnewarray = al_calloc(DEF_ALIGN,
|
|
|
|
FAM_SIZE(struct ALeffectslotArray, slot, newcount));
|
|
|
|
memcpy(tmpnewarray, newarray, FAM_SIZE(struct ALeffectslotArray, slot, newcount));
|
|
|
|
al_free(newarray);
|
|
|
|
newarray = tmpnewarray;
|
|
|
|
newarray->count = newcount;
|
|
|
|
}
|
2018-02-22 20:03:52 +00:00
|
|
|
|
|
|
|
curarray = ATOMIC_EXCHANGE_PTR(&context->ActiveAuxSlots, newarray, almemory_order_acq_rel);
|
|
|
|
while((ATOMIC_LOAD(&device->MixCount, almemory_order_acquire)&1))
|
|
|
|
althrd_yield();
|
|
|
|
al_free(curarray);
|
|
|
|
}
|
|
|
|
|
|
|
|
static void RemoveActiveEffectSlots(const ALuint *slotids, ALsizei count, ALCcontext *context)
|
|
|
|
{
|
|
|
|
struct ALeffectslotArray *curarray = ATOMIC_LOAD(&context->ActiveAuxSlots,
|
|
|
|
almemory_order_acquire);
|
|
|
|
struct ALeffectslotArray *newarray = NULL;
|
|
|
|
ALCdevice *device = context->Device;
|
|
|
|
ALsizei i, j;
|
|
|
|
|
2018-03-04 23:11:17 +00:00
|
|
|
/* 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.
|
|
|
|
*/
|
|
|
|
newarray = al_calloc(DEF_ALIGN, FAM_SIZE(struct ALeffectslotArray, slot, curarray->count));
|
|
|
|
newarray->count = 0;
|
|
|
|
for(i = 0;i < curarray->count;i++)
|
2018-02-22 20:03:52 +00:00
|
|
|
{
|
2018-03-04 23:11:17 +00:00
|
|
|
/* Insert this slot into the new array only if it's not one to remove. */
|
|
|
|
ALeffectslot *slot = curarray->slot[i];
|
|
|
|
for(j = count;j != 0;)
|
2018-02-22 20:03:52 +00:00
|
|
|
{
|
2018-03-04 23:11:17 +00:00
|
|
|
if(slot->id == slotids[--j])
|
|
|
|
goto skip_ins;
|
2018-02-22 20:03:52 +00:00
|
|
|
}
|
2018-03-04 23:11:17 +00:00
|
|
|
newarray->slot[newarray->count++] = slot;
|
|
|
|
skip_ins: ;
|
2018-02-22 20:03:52 +00:00
|
|
|
}
|
|
|
|
|
2018-03-04 23:11:17 +00:00
|
|
|
/* TODO: Could reallocate newarray now that we know it's needed size. */
|
|
|
|
|
2018-02-22 20:03:52 +00:00
|
|
|
curarray = ATOMIC_EXCHANGE_PTR(&context->ActiveAuxSlots, newarray, almemory_order_acq_rel);
|
|
|
|
while((ATOMIC_LOAD(&device->MixCount, almemory_order_acquire)&1))
|
|
|
|
althrd_yield();
|
|
|
|
al_free(curarray);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2012-01-21 00:23:15 +00:00
|
|
|
ALenum InitEffectSlot(ALeffectslot *slot)
|
|
|
|
{
|
2018-03-01 03:37:12 +00:00
|
|
|
EffectStateFactory *factory;
|
2012-01-21 00:23:15 +00:00
|
|
|
|
2016-05-13 01:26:33 +00:00
|
|
|
slot->Effect.Type = AL_EFFECT_NULL;
|
2013-05-26 05:07:31 +00:00
|
|
|
|
2013-05-21 19:47:18 +00:00
|
|
|
factory = getFactoryByType(AL_EFFECT_NULL);
|
2018-03-01 03:37:12 +00:00
|
|
|
slot->Effect.State = EffectStateFactory_create(factory);
|
|
|
|
if(!slot->Effect.State) return AL_OUT_OF_MEMORY;
|
2012-01-21 00:23:15 +00:00
|
|
|
|
|
|
|
slot->Gain = 1.0;
|
|
|
|
slot->AuxSendAuto = AL_TRUE;
|
2017-03-24 02:16:32 +00:00
|
|
|
ATOMIC_FLAG_TEST_AND_SET(&slot->PropsClean, almemory_order_relaxed);
|
2014-05-14 09:47:07 +00:00
|
|
|
InitRef(&slot->ref, 0);
|
2012-01-21 00:23:15 +00:00
|
|
|
|
2016-05-13 01:26:33 +00:00
|
|
|
ATOMIC_INIT(&slot->Update, NULL);
|
|
|
|
|
|
|
|
slot->Params.Gain = 1.0f;
|
|
|
|
slot->Params.AuxSendAuto = AL_TRUE;
|
2016-08-25 11:57:58 +00:00
|
|
|
ALeffectState_IncRef(slot->Effect.State);
|
2016-05-13 01:26:33 +00:00
|
|
|
slot->Params.EffectState = slot->Effect.State;
|
|
|
|
slot->Params.RoomRolloff = 0.0f;
|
|
|
|
slot->Params.DecayTime = 0.0f;
|
2018-03-12 05:40:08 +00:00
|
|
|
slot->Params.DecayLFRatio = 0.0f;
|
2017-05-20 01:59:04 +00:00
|
|
|
slot->Params.DecayHFRatio = 0.0f;
|
|
|
|
slot->Params.DecayHFLimit = AL_FALSE;
|
2017-05-28 05:33:40 +00:00
|
|
|
slot->Params.AirAbsorptionGainHF = 1.0f;
|
2016-05-13 01:26:33 +00:00
|
|
|
|
2012-01-21 00:23:15 +00:00
|
|
|
return AL_NO_ERROR;
|
|
|
|
}
|
|
|
|
|
2016-05-13 01:26:33 +00:00
|
|
|
void DeinitEffectSlot(ALeffectslot *slot)
|
|
|
|
{
|
|
|
|
struct ALeffectslotProps *props;
|
|
|
|
|
2016-12-21 04:49:37 +00:00
|
|
|
props = ATOMIC_LOAD_SEQ(&slot->Update);
|
2016-05-13 01:26:33 +00:00
|
|
|
if(props)
|
|
|
|
{
|
2017-03-08 11:38:28 +00:00
|
|
|
if(props->State) ALeffectState_DecRef(props->State);
|
2016-05-13 01:26:33 +00:00
|
|
|
TRACE("Freed unapplied AuxiliaryEffectSlot update %p\n", props);
|
|
|
|
al_free(props);
|
|
|
|
}
|
|
|
|
|
2016-08-25 11:57:58 +00:00
|
|
|
ALeffectState_DecRef(slot->Effect.State);
|
|
|
|
if(slot->Params.EffectState)
|
|
|
|
ALeffectState_DecRef(slot->Params.EffectState);
|
2016-05-13 01:26:33 +00:00
|
|
|
}
|
|
|
|
|
2017-09-27 18:13:18 +00:00
|
|
|
void UpdateEffectSlotProps(ALeffectslot *slot, ALCcontext *context)
|
2016-05-13 01:26:33 +00:00
|
|
|
{
|
|
|
|
struct ALeffectslotProps *props;
|
|
|
|
ALeffectState *oldstate;
|
|
|
|
|
2016-08-26 01:19:13 +00:00
|
|
|
/* Get an unused property container, or allocate a new one as needed. */
|
2017-09-27 18:13:18 +00:00
|
|
|
props = ATOMIC_LOAD(&context->FreeEffectslotProps, almemory_order_relaxed);
|
2016-08-25 11:57:58 +00:00
|
|
|
if(!props)
|
2016-08-26 01:19:13 +00:00
|
|
|
props = al_calloc(16, sizeof(*props));
|
|
|
|
else
|
2016-05-13 01:26:33 +00:00
|
|
|
{
|
2016-08-26 01:19:13 +00:00
|
|
|
struct ALeffectslotProps *next;
|
|
|
|
do {
|
|
|
|
next = ATOMIC_LOAD(&props->next, almemory_order_relaxed);
|
2017-09-27 18:13:18 +00:00
|
|
|
} while(ATOMIC_COMPARE_EXCHANGE_PTR_WEAK(&context->FreeEffectslotProps, &props, next,
|
2017-04-15 00:47:55 +00:00
|
|
|
almemory_order_seq_cst, almemory_order_acquire) == 0);
|
2016-05-13 01:26:33 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/* Copy in current property values. */
|
2017-03-08 11:38:28 +00:00
|
|
|
props->Gain = slot->Gain;
|
|
|
|
props->AuxSendAuto = slot->AuxSendAuto;
|
2016-05-13 01:26:33 +00:00
|
|
|
|
2017-03-08 11:38:28 +00:00
|
|
|
props->Type = slot->Effect.Type;
|
2016-07-06 20:33:40 +00:00
|
|
|
props->Props = slot->Effect.Props;
|
2016-05-13 01:26:33 +00:00
|
|
|
/* Swap out any stale effect state object there may be in the container, to
|
|
|
|
* delete it.
|
|
|
|
*/
|
2016-08-25 13:17:36 +00:00
|
|
|
ALeffectState_IncRef(slot->Effect.State);
|
2017-03-08 11:38:28 +00:00
|
|
|
oldstate = props->State;
|
|
|
|
props->State = slot->Effect.State;
|
2016-05-13 01:26:33 +00:00
|
|
|
|
|
|
|
/* Set the new container for updating internal parameters. */
|
2017-04-15 00:47:55 +00:00
|
|
|
props = ATOMIC_EXCHANGE_PTR(&slot->Update, props, almemory_order_acq_rel);
|
2016-05-13 01:26:33 +00:00
|
|
|
if(props)
|
|
|
|
{
|
|
|
|
/* If there was an unused update container, put it back in the
|
|
|
|
* freelist.
|
|
|
|
*/
|
2017-09-27 18:13:18 +00:00
|
|
|
ATOMIC_REPLACE_HEAD(struct ALeffectslotProps*, &context->FreeEffectslotProps, props);
|
2016-05-13 01:26:33 +00:00
|
|
|
}
|
|
|
|
|
2016-08-25 11:57:58 +00:00
|
|
|
if(oldstate)
|
|
|
|
ALeffectState_DecRef(oldstate);
|
2016-05-13 01:26:33 +00:00
|
|
|
}
|
|
|
|
|
2016-08-25 13:17:36 +00:00
|
|
|
void UpdateAllEffectSlotProps(ALCcontext *context)
|
|
|
|
{
|
2017-03-28 06:16:23 +00:00
|
|
|
struct ALeffectslotArray *auxslots;
|
|
|
|
ALsizei i;
|
2016-08-25 13:17:36 +00:00
|
|
|
|
2018-01-28 01:24:18 +00:00
|
|
|
LockEffectSlotList(context);
|
2017-03-28 06:16:23 +00:00
|
|
|
auxslots = ATOMIC_LOAD(&context->ActiveAuxSlots, almemory_order_acquire);
|
|
|
|
for(i = 0;i < auxslots->count;i++)
|
2016-08-25 13:17:36 +00:00
|
|
|
{
|
2017-03-28 06:16:23 +00:00
|
|
|
ALeffectslot *slot = auxslots->slot[i];
|
2017-03-24 02:32:53 +00:00
|
|
|
if(!ATOMIC_FLAG_TEST_AND_SET(&slot->PropsClean, almemory_order_acq_rel))
|
2017-09-27 18:13:18 +00:00
|
|
|
UpdateEffectSlotProps(slot, context);
|
2016-08-25 13:17:36 +00:00
|
|
|
}
|
2018-01-28 01:24:18 +00:00
|
|
|
UnlockEffectSlotList(context);
|
2016-08-25 13:17:36 +00:00
|
|
|
}
|
|
|
|
|
2018-01-28 01:24:18 +00:00
|
|
|
ALvoid ReleaseALAuxiliaryEffectSlots(ALCcontext *context)
|
2007-12-18 01:43:19 +00:00
|
|
|
{
|
2018-01-28 01:24:18 +00:00
|
|
|
ALeffectslotPtr *iter = VECTOR_BEGIN(context->EffectSlotList);
|
|
|
|
ALeffectslotPtr *end = VECTOR_END(context->EffectSlotList);
|
|
|
|
size_t leftover = 0;
|
|
|
|
|
|
|
|
for(;iter != end;iter++)
|
2007-12-18 01:43:19 +00:00
|
|
|
{
|
2018-01-28 01:24:18 +00:00
|
|
|
ALeffectslot *slot = *iter;
|
|
|
|
if(!slot) continue;
|
|
|
|
*iter = NULL;
|
2007-12-18 01:43:19 +00:00
|
|
|
|
2018-01-28 01:24:18 +00:00
|
|
|
DeinitEffectSlot(slot);
|
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-19 05:25:40 +00:00
|
|
|
|
2018-01-28 01:24:18 +00:00
|
|
|
memset(slot, 0, sizeof(*slot));
|
|
|
|
al_free(slot);
|
|
|
|
++leftover;
|
2007-12-18 01:43:19 +00:00
|
|
|
}
|
2018-01-28 01:24:18 +00:00
|
|
|
if(leftover > 0)
|
|
|
|
WARN("(%p) Deleted "SZFMT" AuxiliaryEffectSlot%s\n", context, leftover, (leftover==1)?"":"s");
|
2007-12-18 01:43:19 +00:00
|
|
|
}
|