2007-12-17 17:43:19 -08:00
|
|
|
#ifndef _AL_AUXEFFECTSLOT_H_
|
|
|
|
#define _AL_AUXEFFECTSLOT_H_
|
|
|
|
|
2019-02-20 21:01:08 -08:00
|
|
|
#include <array>
|
|
|
|
|
2012-09-14 02:42:36 -07:00
|
|
|
#include "alMain.h"
|
2008-07-25 19:31:12 -07:00
|
|
|
#include "alEffect.h"
|
2019-02-20 21:01:08 -08:00
|
|
|
#include "ambidefs.h"
|
2007-12-17 17:43:19 -08:00
|
|
|
|
2018-11-18 02:52:46 -08:00
|
|
|
#include "almalloc.h"
|
2017-03-23 19:16:32 -07:00
|
|
|
#include "atomic.h"
|
2014-04-19 02:11:04 -07:00
|
|
|
|
2007-12-17 17:43:19 -08:00
|
|
|
|
2013-10-07 05:41:41 -07:00
|
|
|
struct ALeffectslot;
|
2019-03-22 11:52:55 -07:00
|
|
|
union ALeffectProps;
|
|
|
|
|
2013-05-21 12:47:18 -07:00
|
|
|
|
2018-12-24 13:29:36 -08:00
|
|
|
struct EffectTarget {
|
|
|
|
MixParams *Main;
|
|
|
|
RealMixParams *RealOut;
|
|
|
|
};
|
2016-03-17 10:10:26 -07:00
|
|
|
|
2018-11-19 22:34:26 -08:00
|
|
|
struct EffectState {
|
|
|
|
RefCount mRef{1u};
|
2013-05-21 04:18:02 -07:00
|
|
|
|
2018-11-19 22:34:26 -08:00
|
|
|
ALfloat (*mOutBuffer)[BUFFERSIZE]{nullptr};
|
|
|
|
ALsizei mOutChannels{0};
|
2016-05-12 18:26:33 -07:00
|
|
|
|
2013-05-29 11:17:45 -07:00
|
|
|
|
2018-11-19 22:34:26 -08:00
|
|
|
virtual ~EffectState() = default;
|
2013-05-25 21:04:00 -07:00
|
|
|
|
2018-12-22 18:43:34 -08:00
|
|
|
virtual ALboolean deviceUpdate(const ALCdevice *device) = 0;
|
2018-12-24 13:29:36 -08:00
|
|
|
virtual void update(const ALCcontext *context, const ALeffectslot *slot, const ALeffectProps *props, const EffectTarget target) = 0;
|
2019-02-21 02:57:39 -08:00
|
|
|
virtual void process(ALsizei samplesToDo, const ALfloat (*RESTRICT samplesIn)[BUFFERSIZE], const ALsizei numInput, ALfloat (*RESTRICT samplesOut)[BUFFERSIZE], const ALsizei numOutput) = 0;
|
2013-05-21 04:18:02 -07:00
|
|
|
|
2018-11-19 22:34:26 -08:00
|
|
|
void IncRef() noexcept;
|
|
|
|
void DecRef() noexcept;
|
|
|
|
};
|
2013-05-21 04:18:02 -07:00
|
|
|
|
2013-05-21 12:47:18 -07:00
|
|
|
|
2018-11-19 06:43:37 -08:00
|
|
|
struct EffectStateFactory {
|
|
|
|
virtual ~EffectStateFactory() { }
|
2013-10-07 05:41:41 -07:00
|
|
|
|
2018-11-19 22:34:26 -08:00
|
|
|
virtual EffectState *create() = 0;
|
2019-03-22 12:58:24 -07:00
|
|
|
virtual ALeffectProps getDefaultProps() const noexcept = 0;
|
2013-05-21 12:47:18 -07:00
|
|
|
};
|
2012-09-14 02:42:36 -07:00
|
|
|
|
2009-05-29 13:30:50 -07:00
|
|
|
|
2019-01-11 07:28:44 -08:00
|
|
|
using ALeffectslotArray = al::FlexArray<ALeffectslot*>;
|
2017-03-27 23:16:23 -07:00
|
|
|
|
|
|
|
|
2016-05-12 18:26:33 -07:00
|
|
|
struct ALeffectslotProps {
|
2017-03-08 03:38:28 -08:00
|
|
|
ALfloat Gain;
|
|
|
|
ALboolean AuxSendAuto;
|
2018-12-24 15:17:38 -08:00
|
|
|
ALeffectslot *Target;
|
2016-05-12 18:26:33 -07:00
|
|
|
|
2017-03-08 03:38:28 -08:00
|
|
|
ALenum Type;
|
2016-05-12 18:26:33 -07:00
|
|
|
ALeffectProps Props;
|
|
|
|
|
2018-11-19 22:34:26 -08:00
|
|
|
EffectState *State;
|
2016-05-12 18:26:33 -07:00
|
|
|
|
2018-11-26 14:48:26 -08:00
|
|
|
std::atomic<ALeffectslotProps*> next;
|
2016-05-12 18:26:33 -07:00
|
|
|
};
|
|
|
|
|
2007-12-18 14:22:59 -08:00
|
|
|
|
2018-11-18 02:52:46 -08:00
|
|
|
struct ALeffectslot {
|
2018-11-18 06:15:02 -08:00
|
|
|
ALfloat Gain{1.0f};
|
|
|
|
ALboolean AuxSendAuto{AL_TRUE};
|
2018-12-24 15:17:38 -08:00
|
|
|
ALeffectslot *Target{nullptr};
|
2007-12-18 15:47:24 -08:00
|
|
|
|
2016-05-12 18:26:33 -07:00
|
|
|
struct {
|
2018-11-18 06:15:02 -08:00
|
|
|
ALenum Type{AL_EFFECT_NULL};
|
|
|
|
ALeffectProps Props{};
|
2016-05-12 18:26:33 -07:00
|
|
|
|
2018-11-19 22:34:26 -08:00
|
|
|
EffectState *State{nullptr};
|
2016-05-12 18:26:33 -07:00
|
|
|
} Effect;
|
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
|
|
|
|
2019-02-04 19:59:19 -08:00
|
|
|
std::atomic_flag PropsClean;
|
2017-03-23 19:16:32 -07:00
|
|
|
|
2018-11-18 06:15:02 -08:00
|
|
|
RefCount ref{0u};
|
2008-01-16 13:20:09 -08:00
|
|
|
|
2018-11-26 14:48:26 -08:00
|
|
|
std::atomic<ALeffectslotProps*> Update{nullptr};
|
2016-05-12 18:26:33 -07:00
|
|
|
|
|
|
|
struct {
|
2018-11-18 06:15:02 -08:00
|
|
|
ALfloat Gain{1.0f};
|
|
|
|
ALboolean AuxSendAuto{AL_TRUE};
|
2018-12-22 22:14:25 -08:00
|
|
|
ALeffectslot *Target{nullptr};
|
2018-11-18 06:15:02 -08:00
|
|
|
|
|
|
|
ALenum EffectType{AL_EFFECT_NULL};
|
|
|
|
ALeffectProps EffectProps{};
|
2018-11-19 23:48:45 -08:00
|
|
|
EffectState *mEffectState{nullptr};
|
2018-11-18 06:15:02 -08:00
|
|
|
|
|
|
|
ALfloat RoomRolloff{0.0f}; /* Added to the source's room rolloff, not multiplied. */
|
|
|
|
ALfloat DecayTime{0.0f};
|
|
|
|
ALfloat DecayLFRatio{0.0f};
|
|
|
|
ALfloat DecayHFRatio{0.0f};
|
|
|
|
ALboolean DecayHFLimit{AL_FALSE};
|
|
|
|
ALfloat AirAbsorptionGainHF{1.0f};
|
2016-05-12 18:26:33 -07:00
|
|
|
} Params;
|
|
|
|
|
2012-04-19 22:28:01 -07:00
|
|
|
/* Self ID */
|
2018-11-18 06:15:02 -08:00
|
|
|
ALuint id{};
|
2016-01-28 00:02:46 -08:00
|
|
|
|
2019-02-20 21:01:08 -08:00
|
|
|
/* Wet buffer configuration is ACN channel order with N3D scaling.
|
2016-01-28 00:02:46 -08:00
|
|
|
* Consequently, effects that only want to work with mono input can use
|
|
|
|
* channel 0 by itself. Effects that want multichannel can process the
|
2019-02-20 21:01:08 -08:00
|
|
|
* ambisonics signal and make a B-Format source pan.
|
2016-01-28 00:02:46 -08:00
|
|
|
*/
|
2019-02-20 21:01:08 -08:00
|
|
|
al::vector<std::array<ALfloat,BUFFERSIZE>,16> WetBuffer;
|
|
|
|
BFChannelConfig ChanMap[MAX_AMBI_CHANNELS];
|
2018-11-18 02:52:46 -08:00
|
|
|
|
2019-02-04 21:28:37 -08:00
|
|
|
ALeffectslot() { PropsClean.test_and_set(std::memory_order_relaxed); }
|
2018-11-18 06:15:02 -08:00
|
|
|
ALeffectslot(const ALeffectslot&) = delete;
|
|
|
|
ALeffectslot& operator=(const ALeffectslot&) = delete;
|
|
|
|
~ALeffectslot();
|
|
|
|
|
2019-01-11 07:28:44 -08:00
|
|
|
static ALeffectslotArray *CreatePtrArray(size_t count) noexcept;
|
|
|
|
|
2019-02-20 22:00:26 -08:00
|
|
|
DEF_PLACE_NEWDEL()
|
2018-11-18 02:52:46 -08:00
|
|
|
};
|
2007-12-17 17:43:19 -08:00
|
|
|
|
2012-01-20 16:23:15 -08:00
|
|
|
ALenum InitEffectSlot(ALeffectslot *slot);
|
2017-09-27 11:13:18 -07:00
|
|
|
void UpdateEffectSlotProps(ALeffectslot *slot, ALCcontext *context);
|
2016-08-25 06:17:36 -07:00
|
|
|
void UpdateAllEffectSlotProps(ALCcontext *context);
|
2007-12-17 17:43:19 -08:00
|
|
|
|
2009-05-29 13:30:50 -07:00
|
|
|
|
2018-02-28 19:37:12 -08:00
|
|
|
EffectStateFactory *NullStateFactory_getFactory(void);
|
|
|
|
EffectStateFactory *ReverbStateFactory_getFactory(void);
|
2019-03-22 11:57:32 -07:00
|
|
|
EffectStateFactory *StdReverbStateFactory_getFactory(void);
|
2018-07-22 00:48:54 +02:00
|
|
|
EffectStateFactory *AutowahStateFactory_getFactory(void);
|
2018-02-28 19:37:12 -08:00
|
|
|
EffectStateFactory *ChorusStateFactory_getFactory(void);
|
|
|
|
EffectStateFactory *CompressorStateFactory_getFactory(void);
|
|
|
|
EffectStateFactory *DistortionStateFactory_getFactory(void);
|
|
|
|
EffectStateFactory *EchoStateFactory_getFactory(void);
|
|
|
|
EffectStateFactory *EqualizerStateFactory_getFactory(void);
|
|
|
|
EffectStateFactory *FlangerStateFactory_getFactory(void);
|
2018-05-20 17:23:03 +02:00
|
|
|
EffectStateFactory *FshifterStateFactory_getFactory(void);
|
2018-02-28 19:37:12 -08:00
|
|
|
EffectStateFactory *ModulatorStateFactory_getFactory(void);
|
2018-03-18 17:47:17 +01:00
|
|
|
EffectStateFactory *PshifterStateFactory_getFactory(void);
|
2013-05-21 12:47:18 -07:00
|
|
|
|
2018-02-28 19:37:12 -08:00
|
|
|
EffectStateFactory *DedicatedStateFactory_getFactory(void);
|
2013-05-21 12:47:18 -07:00
|
|
|
|
2009-05-29 13:30:50 -07:00
|
|
|
|
2017-09-27 11:13:18 -07:00
|
|
|
ALenum InitializeEffect(ALCcontext *Context, ALeffectslot *EffectSlot, ALeffect *effect);
|
2009-05-29 13:30:50 -07:00
|
|
|
|
2007-12-17 17:43:19 -08:00
|
|
|
#endif
|