2019-07-28 21:29:59 -07:00
|
|
|
#ifndef AL_AUXEFFECTSLOT_H
|
|
|
|
#define AL_AUXEFFECTSLOT_H
|
2007-12-17 17:43:19 -08:00
|
|
|
|
2019-07-28 21:29:59 -07:00
|
|
|
#include <atomic>
|
|
|
|
#include <cstddef>
|
2019-02-20 21:01:08 -08:00
|
|
|
|
2019-07-28 21:29:59 -07:00
|
|
|
#include "AL/al.h"
|
|
|
|
#include "AL/alc.h"
|
|
|
|
#include "AL/efx.h"
|
2007-12-17 17:43:19 -08:00
|
|
|
|
2019-07-28 21:29:59 -07:00
|
|
|
#include "alcmain.h"
|
2018-11-18 02:52:46 -08:00
|
|
|
#include "almalloc.h"
|
2017-03-23 19:16:32 -07:00
|
|
|
#include "atomic.h"
|
2019-07-28 21:29:59 -07:00
|
|
|
#include "effects/base.h"
|
2020-08-22 22:45:26 -07:00
|
|
|
#include "intrusive_ptr.h"
|
2019-07-28 21:29:59 -07:00
|
|
|
#include "vector.h"
|
2014-04-19 02:11:04 -07:00
|
|
|
|
2020-08-24 16:08:09 -07:00
|
|
|
struct ALbuffer;
|
2019-07-28 21:29:59 -07:00
|
|
|
struct ALeffect;
|
2013-10-07 05:41:41 -07:00
|
|
|
struct ALeffectslot;
|
2019-03-22 11:52:55 -07:00
|
|
|
|
2013-05-21 12:47:18 -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 {
|
2020-03-28 15:37:34 -07:00
|
|
|
float Gain;
|
|
|
|
bool 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;
|
2019-03-22 22:48:12 -07:00
|
|
|
EffectProps Props;
|
2016-05-12 18:26:33 -07:00
|
|
|
|
2020-08-22 22:45:26 -07:00
|
|
|
al::intrusive_ptr<EffectState> State;
|
2020-08-24 20:34:50 -07:00
|
|
|
al::intrusive_ptr<EffectBufferBase> Buffer;
|
2016-05-12 18:26:33 -07:00
|
|
|
|
2018-11-26 14:48:26 -08:00
|
|
|
std::atomic<ALeffectslotProps*> next;
|
2019-08-13 22:25:59 -07:00
|
|
|
|
|
|
|
DEF_NEWDEL(ALeffectslotProps)
|
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 {
|
2020-03-28 15:37:34 -07:00
|
|
|
float Gain{1.0f};
|
|
|
|
bool AuxSendAuto{true};
|
2018-12-24 15:17:38 -08:00
|
|
|
ALeffectslot *Target{nullptr};
|
2020-08-24 16:08:09 -07:00
|
|
|
ALbuffer *Buffer{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};
|
2019-03-22 22:48:12 -07:00
|
|
|
EffectProps Props{};
|
2016-05-12 18:26:33 -07:00
|
|
|
|
2020-08-24 16:34:53 -07:00
|
|
|
al::intrusive_ptr<EffectState> State;
|
2020-08-24 19:10:16 -07:00
|
|
|
al::intrusive_ptr<EffectBufferBase> Buffer;
|
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
|
|
|
|
2016-05-12 18:26:33 -07:00
|
|
|
struct {
|
2019-08-13 22:06:14 -07:00
|
|
|
std::atomic<ALeffectslotProps*> Update{nullptr};
|
|
|
|
|
2020-03-28 15:37:34 -07:00
|
|
|
float Gain{1.0f};
|
|
|
|
bool AuxSendAuto{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};
|
2019-03-22 22:48:12 -07:00
|
|
|
EffectProps mEffectProps{};
|
2018-11-19 23:48:45 -08:00
|
|
|
EffectState *mEffectState{nullptr};
|
2020-08-24 20:34:50 -07:00
|
|
|
EffectBufferBase *mEffectBuffer{nullptr};
|
2018-11-18 06:15:02 -08:00
|
|
|
|
2020-04-08 10:15:43 -07:00
|
|
|
float RoomRolloff{0.0f}; /* Added to the source's room rolloff, not multiplied. */
|
|
|
|
float DecayTime{0.0f};
|
|
|
|
float DecayLFRatio{0.0f};
|
|
|
|
float DecayHFRatio{0.0f};
|
2020-03-28 15:37:34 -07:00
|
|
|
bool DecayHFLimit{false};
|
2020-04-08 10:15:43 -07:00
|
|
|
float 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-03-22 19:25:55 -07:00
|
|
|
/* Mixing buffer used by the Wet mix. */
|
2019-05-28 16:22:36 -07:00
|
|
|
al::vector<FloatBufferLine, 16> MixBuffer;
|
2019-03-22 19:25:55 -07: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-03-22 19:25:55 -07:00
|
|
|
MixParams Wet;
|
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();
|
|
|
|
|
2020-05-10 20:16:43 -07:00
|
|
|
ALenum init();
|
|
|
|
ALenum initEffect(ALeffect *effect, ALCcontext *context);
|
|
|
|
void updateProps(ALCcontext *context);
|
|
|
|
|
2019-01-11 07:28:44 -08:00
|
|
|
static ALeffectslotArray *CreatePtrArray(size_t count) noexcept;
|
|
|
|
|
2020-03-23 16:00:50 -07:00
|
|
|
/* This can be new'd for the context's default effect slot. */
|
2019-09-01 17:54:17 -07:00
|
|
|
DEF_NEWDEL(ALeffectslot)
|
2018-11-18 02:52:46 -08:00
|
|
|
};
|
2007-12-17 17:43:19 -08:00
|
|
|
|
2016-08-25 06:17:36 -07:00
|
|
|
void UpdateAllEffectSlotProps(ALCcontext *context);
|
2007-12-17 17:43:19 -08:00
|
|
|
|
|
|
|
#endif
|