Use proper inheritence for the effect state objects
[openal-soft.git] / OpenAL32 / Include / alAuxEffectSlot.h
blobca2cb663c989c00b6057b6133e145b05a9288d2b
1 #ifndef _AL_AUXEFFECTSLOT_H_
2 #define _AL_AUXEFFECTSLOT_H_
4 #include "alMain.h"
5 #include "alEffect.h"
7 #include "almalloc.h"
8 #include "atomic.h"
11 struct ALeffectslot;
14 struct EffectState {
15 RefCount mRef{1u};
17 ALfloat (*mOutBuffer)[BUFFERSIZE]{nullptr};
18 ALsizei mOutChannels{0};
21 virtual ~EffectState() = default;
23 virtual ALboolean deviceUpdate(ALCdevice *device) = 0;
24 virtual void update(const ALCcontext *context, const ALeffectslot *slot, const ALeffectProps *props) = 0;
25 virtual void process(ALsizei samplesToDo, const ALfloat (*RESTRICT samplesIn)[BUFFERSIZE], ALfloat (*RESTRICT samplesOut)[BUFFERSIZE], ALsizei numChannels) = 0;
27 void IncRef() noexcept;
28 void DecRef() noexcept;
32 struct EffectStateFactory {
33 virtual ~EffectStateFactory() { }
35 virtual EffectState *create() = 0;
39 #define MAX_EFFECT_CHANNELS (4)
42 struct ALeffectslotArray {
43 ALsizei count;
44 struct ALeffectslot *slot[];
48 struct ALeffectslotProps {
49 ALfloat Gain;
50 ALboolean AuxSendAuto;
52 ALenum Type;
53 ALeffectProps Props;
55 EffectState *State;
57 ATOMIC(struct ALeffectslotProps*) next;
61 struct ALeffectslot {
62 ALfloat Gain{1.0f};
63 ALboolean AuxSendAuto{AL_TRUE};
65 struct {
66 ALenum Type{AL_EFFECT_NULL};
67 ALeffectProps Props{};
69 EffectState *State{nullptr};
70 } Effect;
72 ATOMIC(ALenum) PropsClean{AL_TRUE};
74 RefCount ref{0u};
76 ATOMIC(struct ALeffectslotProps*) Update{nullptr};
78 struct {
79 ALfloat Gain{1.0f};
80 ALboolean AuxSendAuto{AL_TRUE};
82 ALenum EffectType{AL_EFFECT_NULL};
83 ALeffectProps EffectProps{};
84 EffectState *EffectState{nullptr};
86 ALfloat RoomRolloff{0.0f}; /* Added to the source's room rolloff, not multiplied. */
87 ALfloat DecayTime{0.0f};
88 ALfloat DecayLFRatio{0.0f};
89 ALfloat DecayHFRatio{0.0f};
90 ALboolean DecayHFLimit{AL_FALSE};
91 ALfloat AirAbsorptionGainHF{1.0f};
92 } Params;
94 /* Self ID */
95 ALuint id{};
97 ALsizei NumChannels{};
98 BFChannelConfig ChanMap[MAX_EFFECT_CHANNELS];
99 /* Wet buffer configuration is ACN channel order with N3D scaling:
100 * * Channel 0 is the unattenuated mono signal.
101 * * Channel 1 is OpenAL -X * sqrt(3)
102 * * Channel 2 is OpenAL Y * sqrt(3)
103 * * Channel 3 is OpenAL -Z * sqrt(3)
104 * Consequently, effects that only want to work with mono input can use
105 * channel 0 by itself. Effects that want multichannel can process the
106 * ambisonics signal and make a B-Format source pan for first-order device
107 * output (FOAOut).
109 alignas(16) ALfloat WetBuffer[MAX_EFFECT_CHANNELS][BUFFERSIZE];
111 ALeffectslot() = default;
112 ALeffectslot(const ALeffectslot&) = delete;
113 ALeffectslot& operator=(const ALeffectslot&) = delete;
114 ~ALeffectslot();
116 DEF_NEWDEL(ALeffectslot)
119 ALenum InitEffectSlot(ALeffectslot *slot);
120 void UpdateEffectSlotProps(ALeffectslot *slot, ALCcontext *context);
121 void UpdateAllEffectSlotProps(ALCcontext *context);
122 ALvoid ReleaseALAuxiliaryEffectSlots(ALCcontext *Context);
125 EffectStateFactory *NullStateFactory_getFactory(void);
126 EffectStateFactory *ReverbStateFactory_getFactory(void);
127 EffectStateFactory *AutowahStateFactory_getFactory(void);
128 EffectStateFactory *ChorusStateFactory_getFactory(void);
129 EffectStateFactory *CompressorStateFactory_getFactory(void);
130 EffectStateFactory *DistortionStateFactory_getFactory(void);
131 EffectStateFactory *EchoStateFactory_getFactory(void);
132 EffectStateFactory *EqualizerStateFactory_getFactory(void);
133 EffectStateFactory *FlangerStateFactory_getFactory(void);
134 EffectStateFactory *FshifterStateFactory_getFactory(void);
135 EffectStateFactory *ModulatorStateFactory_getFactory(void);
136 EffectStateFactory *PshifterStateFactory_getFactory(void);
138 EffectStateFactory *DedicatedStateFactory_getFactory(void);
141 ALenum InitializeEffect(ALCcontext *Context, ALeffectslot *EffectSlot, ALeffect *effect);
143 #endif