Free Electron
alEffect.h
1 #ifndef _AL_EFFECT_H_
2 #define _AL_EFFECT_H_
3 
4 #include "alMain.h"
5 
6 #ifdef __cplusplus
7 extern "C" {
8 #endif
9 
10 struct ALeffect;
11 
12 enum {
13  EAXREVERB_EFFECT = 0,
14  REVERB_EFFECT,
15  AUTOWAH_EFFECT,
16  CHORUS_EFFECT,
17  COMPRESSOR_EFFECT,
18  DISTORTION_EFFECT,
19  ECHO_EFFECT,
20  EQUALIZER_EFFECT,
21  FLANGER_EFFECT,
22  FSHIFTER_EFFECT,
23  MODULATOR_EFFECT,
24  PSHIFTER_EFFECT,
25  DEDICATED_EFFECT,
26 
27  MAX_EFFECTS
28 };
29 extern ALboolean DisabledEffects[MAX_EFFECTS];
30 
31 extern ALfloat ReverbBoost;
32 
33 struct EffectList {
34  const char name[16];
35  int type;
36  ALenum val;
37 };
38 #define EFFECTLIST_SIZE 14
39 extern const struct EffectList EffectList[EFFECTLIST_SIZE];
40 
41 
42 struct ALeffectVtable {
43  void (*const setParami)(struct ALeffect *effect, ALCcontext *context, ALenum param, ALint val);
44  void (*const setParamiv)(struct ALeffect *effect, ALCcontext *context, ALenum param, const ALint *vals);
45  void (*const setParamf)(struct ALeffect *effect, ALCcontext *context, ALenum param, ALfloat val);
46  void (*const setParamfv)(struct ALeffect *effect, ALCcontext *context, ALenum param, const ALfloat *vals);
47 
48  void (*const getParami)(const struct ALeffect *effect, ALCcontext *context, ALenum param, ALint *val);
49  void (*const getParamiv)(const struct ALeffect *effect, ALCcontext *context, ALenum param, ALint *vals);
50  void (*const getParamf)(const struct ALeffect *effect, ALCcontext *context, ALenum param, ALfloat *val);
51  void (*const getParamfv)(const struct ALeffect *effect, ALCcontext *context, ALenum param, ALfloat *vals);
52 };
53 
54 #define DEFINE_ALEFFECT_VTABLE(T) \
55 const struct ALeffectVtable T##_vtable = { \
56  T##_setParami, T##_setParamiv, \
57  T##_setParamf, T##_setParamfv, \
58  T##_getParami, T##_getParamiv, \
59  T##_getParamf, T##_getParamfv, \
60 }
61 
62 extern const struct ALeffectVtable ALeaxreverb_vtable;
63 extern const struct ALeffectVtable ALreverb_vtable;
64 extern const struct ALeffectVtable ALautowah_vtable;
65 extern const struct ALeffectVtable ALchorus_vtable;
66 extern const struct ALeffectVtable ALcompressor_vtable;
67 extern const struct ALeffectVtable ALdistortion_vtable;
68 extern const struct ALeffectVtable ALecho_vtable;
69 extern const struct ALeffectVtable ALequalizer_vtable;
70 extern const struct ALeffectVtable ALflanger_vtable;
71 extern const struct ALeffectVtable ALfshifter_vtable;
72 extern const struct ALeffectVtable ALmodulator_vtable;
73 extern const struct ALeffectVtable ALnull_vtable;
74 extern const struct ALeffectVtable ALpshifter_vtable;
75 extern const struct ALeffectVtable ALdedicated_vtable;
76 
77 
78 typedef union ALeffectProps {
79  struct {
80  // Shared Reverb Properties
81  ALfloat Density;
82  ALfloat Diffusion;
83  ALfloat Gain;
84  ALfloat GainHF;
85  ALfloat DecayTime;
86  ALfloat DecayHFRatio;
87  ALfloat ReflectionsGain;
88  ALfloat ReflectionsDelay;
89  ALfloat LateReverbGain;
90  ALfloat LateReverbDelay;
91  ALfloat AirAbsorptionGainHF;
92  ALfloat RoomRolloffFactor;
93  ALboolean DecayHFLimit;
94 
95  // Additional EAX Reverb Properties
96  ALfloat GainLF;
97  ALfloat DecayLFRatio;
98  ALfloat ReflectionsPan[3];
99  ALfloat LateReverbPan[3];
100  ALfloat EchoTime;
101  ALfloat EchoDepth;
102  ALfloat ModulationTime;
103  ALfloat ModulationDepth;
104  ALfloat HFReference;
105  ALfloat LFReference;
106  } Reverb;
107 
108  struct {
109  ALfloat AttackTime;
110  ALfloat ReleaseTime;
111  ALfloat Resonance;
112  ALfloat PeakGain;
113  } Autowah;
114 
115  struct {
116  ALint Waveform;
117  ALint Phase;
118  ALfloat Rate;
119  ALfloat Depth;
120  ALfloat Feedback;
121  ALfloat Delay;
122  } Chorus; /* Also Flanger */
123 
124  struct {
125  ALboolean OnOff;
126  } Compressor;
127 
128  struct {
129  ALfloat Edge;
130  ALfloat Gain;
131  ALfloat LowpassCutoff;
132  ALfloat EQCenter;
133  ALfloat EQBandwidth;
134  } Distortion;
135 
136  struct {
137  ALfloat Delay;
138  ALfloat LRDelay;
139 
140  ALfloat Damping;
141  ALfloat Feedback;
142 
143  ALfloat Spread;
144  } Echo;
145 
146  struct {
147  ALfloat LowCutoff;
148  ALfloat LowGain;
149  ALfloat Mid1Center;
150  ALfloat Mid1Gain;
151  ALfloat Mid1Width;
152  ALfloat Mid2Center;
153  ALfloat Mid2Gain;
154  ALfloat Mid2Width;
155  ALfloat HighCutoff;
156  ALfloat HighGain;
157  } Equalizer;
158 
159  struct {
160  ALfloat Frequency;
161  ALint LeftDirection;
162  ALint RightDirection;
163  } Fshifter;
164 
165  struct {
166  ALfloat Frequency;
167  ALfloat HighPassCutoff;
168  ALint Waveform;
169  } Modulator;
170 
171  struct {
172  ALint CoarseTune;
173  ALint FineTune;
174  } Pshifter;
175 
176  struct {
177  ALfloat Gain;
178  } Dedicated;
179 } ALeffectProps;
180 
181 typedef struct ALeffect {
182  // Effect type (AL_EFFECT_NULL, ...)
183  ALenum type;
184 
185  ALeffectProps Props;
186 
187  const struct ALeffectVtable *vtab;
188 
189  /* Self ID */
190  ALuint id;
191 } ALeffect;
192 #define ALeffect_setParami(o, c, p, v) ((o)->vtab->setParami(o, c, p, v))
193 #define ALeffect_setParamf(o, c, p, v) ((o)->vtab->setParamf(o, c, p, v))
194 #define ALeffect_setParamiv(o, c, p, v) ((o)->vtab->setParamiv(o, c, p, v))
195 #define ALeffect_setParamfv(o, c, p, v) ((o)->vtab->setParamfv(o, c, p, v))
196 #define ALeffect_getParami(o, c, p, v) ((o)->vtab->getParami(o, c, p, v))
197 #define ALeffect_getParamf(o, c, p, v) ((o)->vtab->getParamf(o, c, p, v))
198 #define ALeffect_getParamiv(o, c, p, v) ((o)->vtab->getParamiv(o, c, p, v))
199 #define ALeffect_getParamfv(o, c, p, v) ((o)->vtab->getParamfv(o, c, p, v))
200 
201 inline ALboolean IsReverbEffect(ALenum type)
202 { return type == AL_EFFECT_REVERB || type == AL_EFFECT_EAXREVERB; }
203 
204 void InitEffect(ALeffect *effect);
205 void ReleaseALEffects(ALCdevice *device);
206 
207 void LoadReverbPreset(const char *name, ALeffect *effect);
208 
209 #ifdef __cplusplus
210 }
211 #endif
212 
213 #endif