Re-update effect slots when context properties change
[openal-soft.git] / OpenAL32 / Include / alAuxEffectSlot.h
blob908c72c553c20f526b3b927cae01e5563a85f8ba
1 #ifndef _AL_AUXEFFECTSLOT_H_
2 #define _AL_AUXEFFECTSLOT_H_
4 #include "alMain.h"
5 #include "alEffect.h"
7 #include "atomic.h"
8 #include "align.h"
10 #ifdef __cplusplus
11 extern "C" {
12 #endif
14 struct ALeffectStateVtable;
15 struct ALeffectslot;
17 typedef struct ALeffectState {
18 RefCount Ref;
19 const struct ALeffectStateVtable *vtbl;
21 ALfloat (*OutBuffer)[BUFFERSIZE];
22 ALsizei OutChannels;
23 } ALeffectState;
25 void ALeffectState_Construct(ALeffectState *state);
26 void ALeffectState_Destruct(ALeffectState *state);
28 struct ALeffectStateVtable {
29 void (*const Destruct)(ALeffectState *state);
31 ALboolean (*const deviceUpdate)(ALeffectState *state, ALCdevice *device);
32 void (*const update)(ALeffectState *state, const ALCcontext *context, const struct ALeffectslot *slot, const union ALeffectProps *props);
33 void (*const process)(ALeffectState *state, ALsizei samplesToDo, const ALfloat (*restrict samplesIn)[BUFFERSIZE], ALfloat (*restrict samplesOut)[BUFFERSIZE], ALsizei numChannels);
35 void (*const Delete)(void *ptr);
38 #define DEFINE_ALEFFECTSTATE_VTABLE(T) \
39 DECLARE_THUNK(T, ALeffectState, void, Destruct) \
40 DECLARE_THUNK1(T, ALeffectState, ALboolean, deviceUpdate, ALCdevice*) \
41 DECLARE_THUNK3(T, ALeffectState, void, update, const ALCcontext*, const ALeffectslot*, const ALeffectProps*) \
42 DECLARE_THUNK4(T, ALeffectState, void, process, ALsizei, const ALfloatBUFFERSIZE*restrict, ALfloatBUFFERSIZE*restrict, ALsizei) \
43 static void T##_ALeffectState_Delete(void *ptr) \
44 { return T##_Delete(STATIC_UPCAST(T, ALeffectState, (ALeffectState*)ptr)); } \
46 static const struct ALeffectStateVtable T##_ALeffectState_vtable = { \
47 T##_ALeffectState_Destruct, \
49 T##_ALeffectState_deviceUpdate, \
50 T##_ALeffectState_update, \
51 T##_ALeffectState_process, \
53 T##_ALeffectState_Delete, \
57 struct ALeffectStateFactoryVtable;
59 typedef struct ALeffectStateFactory {
60 const struct ALeffectStateFactoryVtable *vtbl;
61 } ALeffectStateFactory;
63 struct ALeffectStateFactoryVtable {
64 ALeffectState *(*const create)(ALeffectStateFactory *factory);
67 #define DEFINE_ALEFFECTSTATEFACTORY_VTABLE(T) \
68 DECLARE_THUNK(T, ALeffectStateFactory, ALeffectState*, create) \
70 static const struct ALeffectStateFactoryVtable T##_ALeffectStateFactory_vtable = { \
71 T##_ALeffectStateFactory_create, \
75 #define MAX_EFFECT_CHANNELS (4)
78 struct ALeffectslotArray {
79 ALsizei count;
80 struct ALeffectslot *slot[];
84 struct ALeffectslotProps {
85 ALfloat Gain;
86 ALboolean AuxSendAuto;
88 ALenum Type;
89 ALeffectProps Props;
91 ALeffectState *State;
93 ATOMIC(struct ALeffectslotProps*) next;
97 typedef struct ALeffectslot {
98 ALfloat Gain;
99 ALboolean AuxSendAuto;
101 struct {
102 ALenum Type;
103 ALeffectProps Props;
105 ALeffectState *State;
106 } Effect;
108 ATOMIC_FLAG PropsClean;
110 RefCount ref;
112 ATOMIC(struct ALeffectslotProps*) Update;
114 struct {
115 ALfloat Gain;
116 ALboolean AuxSendAuto;
118 ALenum EffectType;
119 ALeffectProps EffectProps;
120 ALeffectState *EffectState;
122 ALfloat RoomRolloff; /* Added to the source's room rolloff, not multiplied. */
123 ALfloat DecayTime;
124 ALfloat DecayHFRatio;
125 ALboolean DecayHFLimit;
126 ALfloat AirAbsorptionGainHF;
127 } Params;
129 /* Self ID */
130 ALuint id;
132 ALsizei NumChannels;
133 BFChannelConfig ChanMap[MAX_EFFECT_CHANNELS];
134 /* Wet buffer configuration is ACN channel order with N3D scaling:
135 * * Channel 0 is the unattenuated mono signal.
136 * * Channel 1 is OpenAL -X
137 * * Channel 2 is OpenAL Y
138 * * Channel 3 is OpenAL -Z
139 * Consequently, effects that only want to work with mono input can use
140 * channel 0 by itself. Effects that want multichannel can process the
141 * ambisonics signal and make a B-Format pan (ComputeFirstOrderGains) for
142 * first-order device output (FOAOut).
144 alignas(16) ALfloat WetBuffer[MAX_EFFECT_CHANNELS][BUFFERSIZE];
145 } ALeffectslot;
147 inline void LockEffectSlotsRead(ALCcontext *context)
148 { LockUIntMapRead(&context->EffectSlotMap); }
149 inline void UnlockEffectSlotsRead(ALCcontext *context)
150 { UnlockUIntMapRead(&context->EffectSlotMap); }
151 inline void LockEffectSlotsWrite(ALCcontext *context)
152 { LockUIntMapWrite(&context->EffectSlotMap); }
153 inline void UnlockEffectSlotsWrite(ALCcontext *context)
154 { UnlockUIntMapWrite(&context->EffectSlotMap); }
156 inline struct ALeffectslot *LookupEffectSlot(ALCcontext *context, ALuint id)
157 { return (struct ALeffectslot*)LookupUIntMapKeyNoLock(&context->EffectSlotMap, id); }
158 inline struct ALeffectslot *RemoveEffectSlot(ALCcontext *context, ALuint id)
159 { return (struct ALeffectslot*)RemoveUIntMapKeyNoLock(&context->EffectSlotMap, id); }
161 ALenum InitEffectSlot(ALeffectslot *slot);
162 void DeinitEffectSlot(ALeffectslot *slot);
163 void UpdateEffectSlotProps(ALeffectslot *slot, ALCcontext *context);
164 void UpdateAllEffectSlotProps(ALCcontext *context);
165 ALvoid ReleaseALAuxiliaryEffectSlots(ALCcontext *Context);
168 ALeffectStateFactory *ALnullStateFactory_getFactory(void);
169 ALeffectStateFactory *ALreverbStateFactory_getFactory(void);
170 ALeffectStateFactory *ALchorusStateFactory_getFactory(void);
171 ALeffectStateFactory *ALcompressorStateFactory_getFactory(void);
172 ALeffectStateFactory *ALdistortionStateFactory_getFactory(void);
173 ALeffectStateFactory *ALechoStateFactory_getFactory(void);
174 ALeffectStateFactory *ALequalizerStateFactory_getFactory(void);
175 ALeffectStateFactory *ALflangerStateFactory_getFactory(void);
176 ALeffectStateFactory *ALmodulatorStateFactory_getFactory(void);
178 ALeffectStateFactory *ALdedicatedStateFactory_getFactory(void);
181 ALenum InitializeEffect(ALCcontext *Context, ALeffectslot *EffectSlot, ALeffect *effect);
183 void InitEffectFactoryMap(void);
184 void DeinitEffectFactoryMap(void);
186 void ALeffectState_DecRef(ALeffectState *state);
188 #ifdef __cplusplus
190 #endif
192 #endif