Get rid of an unnecessary copy of ALeffectProps
[openal-soft.git] / OpenAL32 / Include / alAuxEffectSlot.h
blob28c0b46f78aa894e983183c6377f812db09954ab
1 #ifndef _AL_AUXEFFECTSLOT_H_
2 #define _AL_AUXEFFECTSLOT_H_
4 #include "alMain.h"
5 #include "alEffect.h"
7 #include "align.h"
9 #ifdef __cplusplus
10 extern "C" {
11 #endif
13 struct ALeffectStateVtable;
14 struct ALeffectslot;
16 typedef struct ALeffectState {
17 const struct ALeffectStateVtable *vtbl;
19 ALfloat (*OutBuffer)[BUFFERSIZE];
20 ALuint OutChannels;
21 } ALeffectState;
23 void ALeffectState_Destruct(ALeffectState *state);
25 struct ALeffectStateVtable {
26 void (*const Destruct)(ALeffectState *state);
28 ALboolean (*const deviceUpdate)(ALeffectState *state, ALCdevice *device);
29 void (*const update)(ALeffectState *state, const ALCdevice *device, const struct ALeffectslot *slot, const union ALeffectProps *props);
30 void (*const process)(ALeffectState *state, ALuint samplesToDo, const ALfloat (*restrict samplesIn)[BUFFERSIZE], ALfloat (*restrict samplesOut)[BUFFERSIZE], ALuint numChannels);
32 void (*const Delete)(void *ptr);
35 #define DEFINE_ALEFFECTSTATE_VTABLE(T) \
36 DECLARE_THUNK(T, ALeffectState, void, Destruct) \
37 DECLARE_THUNK1(T, ALeffectState, ALboolean, deviceUpdate, ALCdevice*) \
38 DECLARE_THUNK3(T, ALeffectState, void, update, const ALCdevice*, const ALeffectslot*, const ALeffectProps*) \
39 DECLARE_THUNK4(T, ALeffectState, void, process, ALuint, const ALfloatBUFFERSIZE*restrict, ALfloatBUFFERSIZE*restrict, ALuint) \
40 static void T##_ALeffectState_Delete(void *ptr) \
41 { return T##_Delete(STATIC_UPCAST(T, ALeffectState, (ALeffectState*)ptr)); } \
43 static const struct ALeffectStateVtable T##_ALeffectState_vtable = { \
44 T##_ALeffectState_Destruct, \
46 T##_ALeffectState_deviceUpdate, \
47 T##_ALeffectState_update, \
48 T##_ALeffectState_process, \
50 T##_ALeffectState_Delete, \
54 struct ALeffectStateFactoryVtable;
56 typedef struct ALeffectStateFactory {
57 const struct ALeffectStateFactoryVtable *vtbl;
58 } ALeffectStateFactory;
60 struct ALeffectStateFactoryVtable {
61 ALeffectState *(*const create)(ALeffectStateFactory *factory);
64 #define DEFINE_ALEFFECTSTATEFACTORY_VTABLE(T) \
65 DECLARE_THUNK(T, ALeffectStateFactory, ALeffectState*, create) \
67 static const struct ALeffectStateFactoryVtable T##_ALeffectStateFactory_vtable = { \
68 T##_ALeffectStateFactory_create, \
72 #define MAX_EFFECT_CHANNELS (4)
75 struct ALeffectslotProps {
76 ATOMIC(ALfloat) Gain;
77 ATOMIC(ALboolean) AuxSendAuto;
79 ATOMIC(ALenum) Type;
80 ALeffectProps Props;
82 /* Flag indicates if State should be updated. */
83 ATOMIC(ALboolean) UpdateState;
84 ATOMIC(ALeffectState*) State;
86 ATOMIC(struct ALeffectslotProps*) next;
90 typedef struct ALeffectslot {
91 volatile ALfloat Gain;
92 volatile ALboolean AuxSendAuto;
94 struct {
95 ALenum Type;
96 ALeffectProps Props;
98 ALeffectState *State;
99 } Effect;
101 RefCount ref;
103 ATOMIC(struct ALeffectslotProps*) Update;
104 ATOMIC(struct ALeffectslotProps*) FreeList;
106 struct {
107 ALfloat Gain;
108 ALboolean AuxSendAuto;
110 ALenum EffectType;
111 ALeffectState *EffectState;
113 ALfloat RoomRolloff; /* Added to the source's room rolloff, not multiplied. */
114 ALfloat DecayTime;
115 ALfloat AirAbsorptionGainHF;
116 } Params;
118 /* Self ID */
119 ALuint id;
121 ALuint NumChannels;
122 BFChannelConfig ChanMap[MAX_EFFECT_CHANNELS];
123 /* Wet buffer configuration is ACN channel order with N3D scaling:
124 * * Channel 0 is the unattenuated mono signal.
125 * * Channel 1 is OpenAL -X
126 * * Channel 2 is OpenAL Y
127 * * Channel 3 is OpenAL -Z
128 * Consequently, effects that only want to work with mono input can use
129 * channel 0 by itself. Effects that want multichannel can process the
130 * ambisonics signal and make a B-Format pan (ComputeFirstOrderGains) for
131 * first-order device output (FOAOut).
133 alignas(16) ALfloat WetBuffer[MAX_EFFECT_CHANNELS][BUFFERSIZE];
134 } ALeffectslot;
136 inline struct ALeffectslot *LookupEffectSlot(ALCcontext *context, ALuint id)
137 { return (struct ALeffectslot*)LookupUIntMapKey(&context->EffectSlotMap, id); }
138 inline struct ALeffectslot *RemoveEffectSlot(ALCcontext *context, ALuint id)
139 { return (struct ALeffectslot*)RemoveUIntMapKey(&context->EffectSlotMap, id); }
141 ALenum InitEffectSlot(ALeffectslot *slot);
142 void DeinitEffectSlot(ALeffectslot *slot);
143 void UpdateEffectSlotProps(ALeffectslot *slot, ALboolean withstate);
144 ALvoid ReleaseALAuxiliaryEffectSlots(ALCcontext *Context);
147 ALeffectStateFactory *ALnullStateFactory_getFactory(void);
148 ALeffectStateFactory *ALreverbStateFactory_getFactory(void);
149 ALeffectStateFactory *ALautowahStateFactory_getFactory(void);
150 ALeffectStateFactory *ALchorusStateFactory_getFactory(void);
151 ALeffectStateFactory *ALcompressorStateFactory_getFactory(void);
152 ALeffectStateFactory *ALdistortionStateFactory_getFactory(void);
153 ALeffectStateFactory *ALechoStateFactory_getFactory(void);
154 ALeffectStateFactory *ALequalizerStateFactory_getFactory(void);
155 ALeffectStateFactory *ALflangerStateFactory_getFactory(void);
156 ALeffectStateFactory *ALmodulatorStateFactory_getFactory(void);
158 ALeffectStateFactory *ALdedicatedStateFactory_getFactory(void);
161 ALenum InitializeEffect(ALCdevice *Device, ALeffectslot *EffectSlot, ALeffect *effect);
163 void InitEffectFactoryMap(void);
164 void DeinitEffectFactoryMap(void);
166 #ifdef __cplusplus
168 #endif
170 #endif