Loading [MathJax]/extensions/tex2jax.js
Free Electron
All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Macros Modules Pages
alAuxEffectSlot.h
1 #ifndef _AL_AUXEFFECTSLOT_H_
2 #define _AL_AUXEFFECTSLOT_H_
3 
4 #include "alMain.h"
5 #include "alEffect.h"
6 
7 #include "atomic.h"
8 #include "align.h"
9 
10 #ifdef __cplusplus
11 extern "C" {
12 #endif
13 
14 struct ALeffectStateVtable;
15 struct ALeffectslot;
16 
17 typedef struct ALeffectState {
18  RefCount Ref;
19  const struct ALeffectStateVtable *vtbl;
20 
21  ALfloat (*OutBuffer)[BUFFERSIZE];
22  ALsizei OutChannels;
23 } ALeffectState;
24 
25 void ALeffectState_Construct(ALeffectState *state);
26 void ALeffectState_Destruct(ALeffectState *state);
27 
28 struct ALeffectStateVtable {
29  void (*const Destruct)(ALeffectState *state);
30 
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);
34 
35  void (*const Delete)(void *ptr);
36 };
37 
38 /* Small hack to use a pointer-to-array types as a normal argument type.
39  * Shouldn't be used directly.
40  */
41 typedef ALfloat ALfloatBUFFERSIZE[BUFFERSIZE];
42 
43 #define DEFINE_ALEFFECTSTATE_VTABLE(T) \
44 DECLARE_THUNK(T, ALeffectState, void, Destruct) \
45 DECLARE_THUNK1(T, ALeffectState, ALboolean, deviceUpdate, ALCdevice*) \
46 DECLARE_THUNK3(T, ALeffectState, void, update, const ALCcontext*, const ALeffectslot*, const ALeffectProps*) \
47 DECLARE_THUNK4(T, ALeffectState, void, process, ALsizei, const ALfloatBUFFERSIZE*restrict, ALfloatBUFFERSIZE*restrict, ALsizei) \
48 static void T##_ALeffectState_Delete(void *ptr) \
49 { return T##_Delete(STATIC_UPCAST(T, ALeffectState, (ALeffectState*)ptr)); } \
50  \
51 static const struct ALeffectStateVtable T##_ALeffectState_vtable = { \
52  T##_ALeffectState_Destruct, \
53  \
54  T##_ALeffectState_deviceUpdate, \
55  T##_ALeffectState_update, \
56  T##_ALeffectState_process, \
57  \
58  T##_ALeffectState_Delete, \
59 }
60 
61 
62 struct EffectStateFactoryVtable;
63 
64 typedef struct EffectStateFactory {
65  const struct EffectStateFactoryVtable *vtab;
66 } EffectStateFactory;
67 
68 struct EffectStateFactoryVtable {
69  ALeffectState *(*const create)(EffectStateFactory *factory);
70 };
71 #define EffectStateFactory_create(x) ((x)->vtab->create((x)))
72 
73 #define DEFINE_EFFECTSTATEFACTORY_VTABLE(T) \
74 DECLARE_THUNK(T, EffectStateFactory, ALeffectState*, create) \
75  \
76 static const struct EffectStateFactoryVtable T##_EffectStateFactory_vtable = { \
77  T##_EffectStateFactory_create, \
78 }
79 
80 
81 #define MAX_EFFECT_CHANNELS (4)
82 
83 
84 struct ALeffectslotArray {
85  ALsizei count;
86  struct ALeffectslot *slot[];
87 };
88 
89 
90 struct ALeffectslotProps {
91  ALfloat Gain;
92  ALboolean AuxSendAuto;
93 
94  ALenum Type;
95  ALeffectProps Props;
96 
97  ALeffectState *State;
98 
99  ATOMIC(struct ALeffectslotProps*) next;
100 };
101 
102 
103 typedef struct ALeffectslot {
104  ALfloat Gain;
105  ALboolean AuxSendAuto;
106 
107  struct {
108  ALenum Type;
109  ALeffectProps Props;
110 
111  ALeffectState *State;
112  } Effect;
113 
114  ATOMIC_FLAG PropsClean;
115 
116  RefCount ref;
117 
118  ATOMIC(struct ALeffectslotProps*) Update;
119 
120  struct {
121  ALfloat Gain;
122  ALboolean AuxSendAuto;
123 
124  ALenum EffectType;
125  ALeffectProps EffectProps;
126  ALeffectState *EffectState;
127 
128  ALfloat RoomRolloff; /* Added to the source's room rolloff, not multiplied. */
129  ALfloat DecayTime;
130  ALfloat DecayLFRatio;
131  ALfloat DecayHFRatio;
132  ALboolean DecayHFLimit;
133  ALfloat AirAbsorptionGainHF;
134  } Params;
135 
136  /* Self ID */
137  ALuint id;
138 
139  ALsizei NumChannels;
140  BFChannelConfig ChanMap[MAX_EFFECT_CHANNELS];
141  /* Wet buffer configuration is ACN channel order with N3D scaling:
142  * * Channel 0 is the unattenuated mono signal.
143  * * Channel 1 is OpenAL -X * sqrt(3)
144  * * Channel 2 is OpenAL Y * sqrt(3)
145  * * Channel 3 is OpenAL -Z * sqrt(3)
146  * Consequently, effects that only want to work with mono input can use
147  * channel 0 by itself. Effects that want multichannel can process the
148  * ambisonics signal and make a B-Format source pan for first-order device
149  * output (FOAOut).
150  */
151  alignas(16) ALfloat WetBuffer[MAX_EFFECT_CHANNELS][BUFFERSIZE];
152 } ALeffectslot;
153 
154 ALenum InitEffectSlot(ALeffectslot *slot);
155 void DeinitEffectSlot(ALeffectslot *slot);
156 void UpdateEffectSlotProps(ALeffectslot *slot, ALCcontext *context);
157 void UpdateAllEffectSlotProps(ALCcontext *context);
158 ALvoid ReleaseALAuxiliaryEffectSlots(ALCcontext *Context);
159 
160 
161 EffectStateFactory *NullStateFactory_getFactory(void);
162 EffectStateFactory *ReverbStateFactory_getFactory(void);
163 EffectStateFactory *AutowahStateFactory_getFactory(void);
164 EffectStateFactory *ChorusStateFactory_getFactory(void);
165 EffectStateFactory *CompressorStateFactory_getFactory(void);
166 EffectStateFactory *DistortionStateFactory_getFactory(void);
167 EffectStateFactory *EchoStateFactory_getFactory(void);
168 EffectStateFactory *EqualizerStateFactory_getFactory(void);
169 EffectStateFactory *FlangerStateFactory_getFactory(void);
170 EffectStateFactory *FshifterStateFactory_getFactory(void);
171 EffectStateFactory *ModulatorStateFactory_getFactory(void);
172 EffectStateFactory *PshifterStateFactory_getFactory(void);
173 
174 EffectStateFactory *DedicatedStateFactory_getFactory(void);
175 
176 
177 ALenum InitializeEffect(ALCcontext *Context, ALeffectslot *EffectSlot, ALeffect *effect);
178 
179 void ALeffectState_DecRef(ALeffectState *state);
180 
181 #ifdef __cplusplus
182 }
183 #endif
184 
185 #endif