]> git.tdb.fi Git - ext/openal.git/blob - al/effects/reverb.cpp
Import OpenAL Soft 1.23.1 sources
[ext/openal.git] / al / effects / reverb.cpp
1
2 #include "config.h"
3
4 #include <cmath>
5
6 #include "AL/al.h"
7 #include "AL/efx.h"
8
9 #include "alc/effects/base.h"
10 #include "effects.h"
11
12 #ifdef ALSOFT_EAX
13 #include <cassert>
14 #include "alnumeric.h"
15 #include "AL/efx-presets.h"
16 #include "al/eax/exception.h"
17 #include "al/eax/utils.h"
18 #endif // ALSOFT_EAX
19
20
21 namespace {
22
23 void Reverb_setParami(EffectProps *props, ALenum param, int val)
24 {
25     switch(param)
26     {
27     case AL_EAXREVERB_DECAY_HFLIMIT:
28         if(!(val >= AL_EAXREVERB_MIN_DECAY_HFLIMIT && val <= AL_EAXREVERB_MAX_DECAY_HFLIMIT))
29             throw effect_exception{AL_INVALID_VALUE, "EAX Reverb decay hflimit out of range"};
30         props->Reverb.DecayHFLimit = val != AL_FALSE;
31         break;
32
33     default:
34         throw effect_exception{AL_INVALID_ENUM, "Invalid EAX reverb integer property 0x%04x",
35             param};
36     }
37 }
38 void Reverb_setParamiv(EffectProps *props, ALenum param, const int *vals)
39 { Reverb_setParami(props, param, vals[0]); }
40 void Reverb_setParamf(EffectProps *props, ALenum param, float val)
41 {
42     switch(param)
43     {
44     case AL_EAXREVERB_DENSITY:
45         if(!(val >= AL_EAXREVERB_MIN_DENSITY && val <= AL_EAXREVERB_MAX_DENSITY))
46             throw effect_exception{AL_INVALID_VALUE, "EAX Reverb density out of range"};
47         props->Reverb.Density = val;
48         break;
49
50     case AL_EAXREVERB_DIFFUSION:
51         if(!(val >= AL_EAXREVERB_MIN_DIFFUSION && val <= AL_EAXREVERB_MAX_DIFFUSION))
52             throw effect_exception{AL_INVALID_VALUE, "EAX Reverb diffusion out of range"};
53         props->Reverb.Diffusion = val;
54         break;
55
56     case AL_EAXREVERB_GAIN:
57         if(!(val >= AL_EAXREVERB_MIN_GAIN && val <= AL_EAXREVERB_MAX_GAIN))
58             throw effect_exception{AL_INVALID_VALUE, "EAX Reverb gain out of range"};
59         props->Reverb.Gain = val;
60         break;
61
62     case AL_EAXREVERB_GAINHF:
63         if(!(val >= AL_EAXREVERB_MIN_GAINHF && val <= AL_EAXREVERB_MAX_GAINHF))
64             throw effect_exception{AL_INVALID_VALUE, "EAX Reverb gainhf out of range"};
65         props->Reverb.GainHF = val;
66         break;
67
68     case AL_EAXREVERB_GAINLF:
69         if(!(val >= AL_EAXREVERB_MIN_GAINLF && val <= AL_EAXREVERB_MAX_GAINLF))
70             throw effect_exception{AL_INVALID_VALUE, "EAX Reverb gainlf out of range"};
71         props->Reverb.GainLF = val;
72         break;
73
74     case AL_EAXREVERB_DECAY_TIME:
75         if(!(val >= AL_EAXREVERB_MIN_DECAY_TIME && val <= AL_EAXREVERB_MAX_DECAY_TIME))
76             throw effect_exception{AL_INVALID_VALUE, "EAX Reverb decay time out of range"};
77         props->Reverb.DecayTime = val;
78         break;
79
80     case AL_EAXREVERB_DECAY_HFRATIO:
81         if(!(val >= AL_EAXREVERB_MIN_DECAY_HFRATIO && val <= AL_EAXREVERB_MAX_DECAY_HFRATIO))
82             throw effect_exception{AL_INVALID_VALUE, "EAX Reverb decay hfratio out of range"};
83         props->Reverb.DecayHFRatio = val;
84         break;
85
86     case AL_EAXREVERB_DECAY_LFRATIO:
87         if(!(val >= AL_EAXREVERB_MIN_DECAY_LFRATIO && val <= AL_EAXREVERB_MAX_DECAY_LFRATIO))
88             throw effect_exception{AL_INVALID_VALUE, "EAX Reverb decay lfratio out of range"};
89         props->Reverb.DecayLFRatio = val;
90         break;
91
92     case AL_EAXREVERB_REFLECTIONS_GAIN:
93         if(!(val >= AL_EAXREVERB_MIN_REFLECTIONS_GAIN && val <= AL_EAXREVERB_MAX_REFLECTIONS_GAIN))
94             throw effect_exception{AL_INVALID_VALUE, "EAX Reverb reflections gain out of range"};
95         props->Reverb.ReflectionsGain = val;
96         break;
97
98     case AL_EAXREVERB_REFLECTIONS_DELAY:
99         if(!(val >= AL_EAXREVERB_MIN_REFLECTIONS_DELAY && val <= AL_EAXREVERB_MAX_REFLECTIONS_DELAY))
100             throw effect_exception{AL_INVALID_VALUE, "EAX Reverb reflections delay out of range"};
101         props->Reverb.ReflectionsDelay = val;
102         break;
103
104     case AL_EAXREVERB_LATE_REVERB_GAIN:
105         if(!(val >= AL_EAXREVERB_MIN_LATE_REVERB_GAIN && val <= AL_EAXREVERB_MAX_LATE_REVERB_GAIN))
106             throw effect_exception{AL_INVALID_VALUE, "EAX Reverb late reverb gain out of range"};
107         props->Reverb.LateReverbGain = val;
108         break;
109
110     case AL_EAXREVERB_LATE_REVERB_DELAY:
111         if(!(val >= AL_EAXREVERB_MIN_LATE_REVERB_DELAY && val <= AL_EAXREVERB_MAX_LATE_REVERB_DELAY))
112             throw effect_exception{AL_INVALID_VALUE, "EAX Reverb late reverb delay out of range"};
113         props->Reverb.LateReverbDelay = val;
114         break;
115
116     case AL_EAXREVERB_ECHO_TIME:
117         if(!(val >= AL_EAXREVERB_MIN_ECHO_TIME && val <= AL_EAXREVERB_MAX_ECHO_TIME))
118             throw effect_exception{AL_INVALID_VALUE, "EAX Reverb echo time out of range"};
119         props->Reverb.EchoTime = val;
120         break;
121
122     case AL_EAXREVERB_ECHO_DEPTH:
123         if(!(val >= AL_EAXREVERB_MIN_ECHO_DEPTH && val <= AL_EAXREVERB_MAX_ECHO_DEPTH))
124             throw effect_exception{AL_INVALID_VALUE, "EAX Reverb echo depth out of range"};
125         props->Reverb.EchoDepth = val;
126         break;
127
128     case AL_EAXREVERB_MODULATION_TIME:
129         if(!(val >= AL_EAXREVERB_MIN_MODULATION_TIME && val <= AL_EAXREVERB_MAX_MODULATION_TIME))
130             throw effect_exception{AL_INVALID_VALUE, "EAX Reverb modulation time out of range"};
131         props->Reverb.ModulationTime = val;
132         break;
133
134     case AL_EAXREVERB_MODULATION_DEPTH:
135         if(!(val >= AL_EAXREVERB_MIN_MODULATION_DEPTH && val <= AL_EAXREVERB_MAX_MODULATION_DEPTH))
136             throw effect_exception{AL_INVALID_VALUE, "EAX Reverb modulation depth out of range"};
137         props->Reverb.ModulationDepth = val;
138         break;
139
140     case AL_EAXREVERB_AIR_ABSORPTION_GAINHF:
141         if(!(val >= AL_EAXREVERB_MIN_AIR_ABSORPTION_GAINHF && val <= AL_EAXREVERB_MAX_AIR_ABSORPTION_GAINHF))
142             throw effect_exception{AL_INVALID_VALUE, "EAX Reverb air absorption gainhf out of range"};
143         props->Reverb.AirAbsorptionGainHF = val;
144         break;
145
146     case AL_EAXREVERB_HFREFERENCE:
147         if(!(val >= AL_EAXREVERB_MIN_HFREFERENCE && val <= AL_EAXREVERB_MAX_HFREFERENCE))
148             throw effect_exception{AL_INVALID_VALUE, "EAX Reverb hfreference out of range"};
149         props->Reverb.HFReference = val;
150         break;
151
152     case AL_EAXREVERB_LFREFERENCE:
153         if(!(val >= AL_EAXREVERB_MIN_LFREFERENCE && val <= AL_EAXREVERB_MAX_LFREFERENCE))
154             throw effect_exception{AL_INVALID_VALUE, "EAX Reverb lfreference out of range"};
155         props->Reverb.LFReference = val;
156         break;
157
158     case AL_EAXREVERB_ROOM_ROLLOFF_FACTOR:
159         if(!(val >= AL_EAXREVERB_MIN_ROOM_ROLLOFF_FACTOR && val <= AL_EAXREVERB_MAX_ROOM_ROLLOFF_FACTOR))
160             throw effect_exception{AL_INVALID_VALUE, "EAX Reverb room rolloff factor out of range"};
161         props->Reverb.RoomRolloffFactor = val;
162         break;
163
164     default:
165         throw effect_exception{AL_INVALID_ENUM, "Invalid EAX reverb float property 0x%04x", param};
166     }
167 }
168 void Reverb_setParamfv(EffectProps *props, ALenum param, const float *vals)
169 {
170     switch(param)
171     {
172     case AL_EAXREVERB_REFLECTIONS_PAN:
173         if(!(std::isfinite(vals[0]) && std::isfinite(vals[1]) && std::isfinite(vals[2])))
174             throw effect_exception{AL_INVALID_VALUE, "EAX Reverb reflections pan out of range"};
175         props->Reverb.ReflectionsPan[0] = vals[0];
176         props->Reverb.ReflectionsPan[1] = vals[1];
177         props->Reverb.ReflectionsPan[2] = vals[2];
178         break;
179     case AL_EAXREVERB_LATE_REVERB_PAN:
180         if(!(std::isfinite(vals[0]) && std::isfinite(vals[1]) && std::isfinite(vals[2])))
181             throw effect_exception{AL_INVALID_VALUE, "EAX Reverb late reverb pan out of range"};
182         props->Reverb.LateReverbPan[0] = vals[0];
183         props->Reverb.LateReverbPan[1] = vals[1];
184         props->Reverb.LateReverbPan[2] = vals[2];
185         break;
186
187     default:
188         Reverb_setParamf(props, param, vals[0]);
189         break;
190     }
191 }
192
193 void Reverb_getParami(const EffectProps *props, ALenum param, int *val)
194 {
195     switch(param)
196     {
197     case AL_EAXREVERB_DECAY_HFLIMIT:
198         *val = props->Reverb.DecayHFLimit;
199         break;
200
201     default:
202         throw effect_exception{AL_INVALID_ENUM, "Invalid EAX reverb integer property 0x%04x",
203             param};
204     }
205 }
206 void Reverb_getParamiv(const EffectProps *props, ALenum param, int *vals)
207 { Reverb_getParami(props, param, vals); }
208 void Reverb_getParamf(const EffectProps *props, ALenum param, float *val)
209 {
210     switch(param)
211     {
212     case AL_EAXREVERB_DENSITY:
213         *val = props->Reverb.Density;
214         break;
215
216     case AL_EAXREVERB_DIFFUSION:
217         *val = props->Reverb.Diffusion;
218         break;
219
220     case AL_EAXREVERB_GAIN:
221         *val = props->Reverb.Gain;
222         break;
223
224     case AL_EAXREVERB_GAINHF:
225         *val = props->Reverb.GainHF;
226         break;
227
228     case AL_EAXREVERB_GAINLF:
229         *val = props->Reverb.GainLF;
230         break;
231
232     case AL_EAXREVERB_DECAY_TIME:
233         *val = props->Reverb.DecayTime;
234         break;
235
236     case AL_EAXREVERB_DECAY_HFRATIO:
237         *val = props->Reverb.DecayHFRatio;
238         break;
239
240     case AL_EAXREVERB_DECAY_LFRATIO:
241         *val = props->Reverb.DecayLFRatio;
242         break;
243
244     case AL_EAXREVERB_REFLECTIONS_GAIN:
245         *val = props->Reverb.ReflectionsGain;
246         break;
247
248     case AL_EAXREVERB_REFLECTIONS_DELAY:
249         *val = props->Reverb.ReflectionsDelay;
250         break;
251
252     case AL_EAXREVERB_LATE_REVERB_GAIN:
253         *val = props->Reverb.LateReverbGain;
254         break;
255
256     case AL_EAXREVERB_LATE_REVERB_DELAY:
257         *val = props->Reverb.LateReverbDelay;
258         break;
259
260     case AL_EAXREVERB_ECHO_TIME:
261         *val = props->Reverb.EchoTime;
262         break;
263
264     case AL_EAXREVERB_ECHO_DEPTH:
265         *val = props->Reverb.EchoDepth;
266         break;
267
268     case AL_EAXREVERB_MODULATION_TIME:
269         *val = props->Reverb.ModulationTime;
270         break;
271
272     case AL_EAXREVERB_MODULATION_DEPTH:
273         *val = props->Reverb.ModulationDepth;
274         break;
275
276     case AL_EAXREVERB_AIR_ABSORPTION_GAINHF:
277         *val = props->Reverb.AirAbsorptionGainHF;
278         break;
279
280     case AL_EAXREVERB_HFREFERENCE:
281         *val = props->Reverb.HFReference;
282         break;
283
284     case AL_EAXREVERB_LFREFERENCE:
285         *val = props->Reverb.LFReference;
286         break;
287
288     case AL_EAXREVERB_ROOM_ROLLOFF_FACTOR:
289         *val = props->Reverb.RoomRolloffFactor;
290         break;
291
292     default:
293         throw effect_exception{AL_INVALID_ENUM, "Invalid EAX reverb float property 0x%04x", param};
294     }
295 }
296 void Reverb_getParamfv(const EffectProps *props, ALenum param, float *vals)
297 {
298     switch(param)
299     {
300     case AL_EAXREVERB_REFLECTIONS_PAN:
301         vals[0] = props->Reverb.ReflectionsPan[0];
302         vals[1] = props->Reverb.ReflectionsPan[1];
303         vals[2] = props->Reverb.ReflectionsPan[2];
304         break;
305     case AL_EAXREVERB_LATE_REVERB_PAN:
306         vals[0] = props->Reverb.LateReverbPan[0];
307         vals[1] = props->Reverb.LateReverbPan[1];
308         vals[2] = props->Reverb.LateReverbPan[2];
309         break;
310
311     default:
312         Reverb_getParamf(props, param, vals);
313         break;
314     }
315 }
316
317 EffectProps genDefaultProps() noexcept
318 {
319     EffectProps props{};
320     props.Reverb.Density   = AL_EAXREVERB_DEFAULT_DENSITY;
321     props.Reverb.Diffusion = AL_EAXREVERB_DEFAULT_DIFFUSION;
322     props.Reverb.Gain   = AL_EAXREVERB_DEFAULT_GAIN;
323     props.Reverb.GainHF = AL_EAXREVERB_DEFAULT_GAINHF;
324     props.Reverb.GainLF = AL_EAXREVERB_DEFAULT_GAINLF;
325     props.Reverb.DecayTime    = AL_EAXREVERB_DEFAULT_DECAY_TIME;
326     props.Reverb.DecayHFRatio = AL_EAXREVERB_DEFAULT_DECAY_HFRATIO;
327     props.Reverb.DecayLFRatio = AL_EAXREVERB_DEFAULT_DECAY_LFRATIO;
328     props.Reverb.ReflectionsGain   = AL_EAXREVERB_DEFAULT_REFLECTIONS_GAIN;
329     props.Reverb.ReflectionsDelay  = AL_EAXREVERB_DEFAULT_REFLECTIONS_DELAY;
330     props.Reverb.ReflectionsPan[0] = AL_EAXREVERB_DEFAULT_REFLECTIONS_PAN_XYZ;
331     props.Reverb.ReflectionsPan[1] = AL_EAXREVERB_DEFAULT_REFLECTIONS_PAN_XYZ;
332     props.Reverb.ReflectionsPan[2] = AL_EAXREVERB_DEFAULT_REFLECTIONS_PAN_XYZ;
333     props.Reverb.LateReverbGain   = AL_EAXREVERB_DEFAULT_LATE_REVERB_GAIN;
334     props.Reverb.LateReverbDelay  = AL_EAXREVERB_DEFAULT_LATE_REVERB_DELAY;
335     props.Reverb.LateReverbPan[0] = AL_EAXREVERB_DEFAULT_LATE_REVERB_PAN_XYZ;
336     props.Reverb.LateReverbPan[1] = AL_EAXREVERB_DEFAULT_LATE_REVERB_PAN_XYZ;
337     props.Reverb.LateReverbPan[2] = AL_EAXREVERB_DEFAULT_LATE_REVERB_PAN_XYZ;
338     props.Reverb.EchoTime  = AL_EAXREVERB_DEFAULT_ECHO_TIME;
339     props.Reverb.EchoDepth = AL_EAXREVERB_DEFAULT_ECHO_DEPTH;
340     props.Reverb.ModulationTime  = AL_EAXREVERB_DEFAULT_MODULATION_TIME;
341     props.Reverb.ModulationDepth = AL_EAXREVERB_DEFAULT_MODULATION_DEPTH;
342     props.Reverb.AirAbsorptionGainHF = AL_EAXREVERB_DEFAULT_AIR_ABSORPTION_GAINHF;
343     props.Reverb.HFReference = AL_EAXREVERB_DEFAULT_HFREFERENCE;
344     props.Reverb.LFReference = AL_EAXREVERB_DEFAULT_LFREFERENCE;
345     props.Reverb.RoomRolloffFactor = AL_EAXREVERB_DEFAULT_ROOM_ROLLOFF_FACTOR;
346     props.Reverb.DecayHFLimit = AL_EAXREVERB_DEFAULT_DECAY_HFLIMIT;
347     return props;
348 }
349
350
351 void StdReverb_setParami(EffectProps *props, ALenum param, int val)
352 {
353     switch(param)
354     {
355     case AL_REVERB_DECAY_HFLIMIT:
356         if(!(val >= AL_REVERB_MIN_DECAY_HFLIMIT && val <= AL_REVERB_MAX_DECAY_HFLIMIT))
357             throw effect_exception{AL_INVALID_VALUE, "Reverb decay hflimit out of range"};
358         props->Reverb.DecayHFLimit = val != AL_FALSE;
359         break;
360
361     default:
362         throw effect_exception{AL_INVALID_ENUM, "Invalid reverb integer property 0x%04x", param};
363     }
364 }
365 void StdReverb_setParamiv(EffectProps *props, ALenum param, const int *vals)
366 { StdReverb_setParami(props, param, vals[0]); }
367 void StdReverb_setParamf(EffectProps *props, ALenum param, float val)
368 {
369     switch(param)
370     {
371     case AL_REVERB_DENSITY:
372         if(!(val >= AL_REVERB_MIN_DENSITY && val <= AL_REVERB_MAX_DENSITY))
373             throw effect_exception{AL_INVALID_VALUE, "Reverb density out of range"};
374         props->Reverb.Density = val;
375         break;
376
377     case AL_REVERB_DIFFUSION:
378         if(!(val >= AL_REVERB_MIN_DIFFUSION && val <= AL_REVERB_MAX_DIFFUSION))
379             throw effect_exception{AL_INVALID_VALUE, "Reverb diffusion out of range"};
380         props->Reverb.Diffusion = val;
381         break;
382
383     case AL_REVERB_GAIN:
384         if(!(val >= AL_REVERB_MIN_GAIN && val <= AL_REVERB_MAX_GAIN))
385             throw effect_exception{AL_INVALID_VALUE, "Reverb gain out of range"};
386         props->Reverb.Gain = val;
387         break;
388
389     case AL_REVERB_GAINHF:
390         if(!(val >= AL_REVERB_MIN_GAINHF && val <= AL_REVERB_MAX_GAINHF))
391             throw effect_exception{AL_INVALID_VALUE, "Reverb gainhf out of range"};
392         props->Reverb.GainHF = val;
393         break;
394
395     case AL_REVERB_DECAY_TIME:
396         if(!(val >= AL_REVERB_MIN_DECAY_TIME && val <= AL_REVERB_MAX_DECAY_TIME))
397             throw effect_exception{AL_INVALID_VALUE, "Reverb decay time out of range"};
398         props->Reverb.DecayTime = val;
399         break;
400
401     case AL_REVERB_DECAY_HFRATIO:
402         if(!(val >= AL_REVERB_MIN_DECAY_HFRATIO && val <= AL_REVERB_MAX_DECAY_HFRATIO))
403             throw effect_exception{AL_INVALID_VALUE, "Reverb decay hfratio out of range"};
404         props->Reverb.DecayHFRatio = val;
405         break;
406
407     case AL_REVERB_REFLECTIONS_GAIN:
408         if(!(val >= AL_REVERB_MIN_REFLECTIONS_GAIN && val <= AL_REVERB_MAX_REFLECTIONS_GAIN))
409             throw effect_exception{AL_INVALID_VALUE, "Reverb reflections gain out of range"};
410         props->Reverb.ReflectionsGain = val;
411         break;
412
413     case AL_REVERB_REFLECTIONS_DELAY:
414         if(!(val >= AL_REVERB_MIN_REFLECTIONS_DELAY && val <= AL_REVERB_MAX_REFLECTIONS_DELAY))
415             throw effect_exception{AL_INVALID_VALUE, "Reverb reflections delay out of range"};
416         props->Reverb.ReflectionsDelay = val;
417         break;
418
419     case AL_REVERB_LATE_REVERB_GAIN:
420         if(!(val >= AL_REVERB_MIN_LATE_REVERB_GAIN && val <= AL_REVERB_MAX_LATE_REVERB_GAIN))
421             throw effect_exception{AL_INVALID_VALUE, "Reverb late reverb gain out of range"};
422         props->Reverb.LateReverbGain = val;
423         break;
424
425     case AL_REVERB_LATE_REVERB_DELAY:
426         if(!(val >= AL_REVERB_MIN_LATE_REVERB_DELAY && val <= AL_REVERB_MAX_LATE_REVERB_DELAY))
427             throw effect_exception{AL_INVALID_VALUE, "Reverb late reverb delay out of range"};
428         props->Reverb.LateReverbDelay = val;
429         break;
430
431     case AL_REVERB_AIR_ABSORPTION_GAINHF:
432         if(!(val >= AL_REVERB_MIN_AIR_ABSORPTION_GAINHF && val <= AL_REVERB_MAX_AIR_ABSORPTION_GAINHF))
433             throw effect_exception{AL_INVALID_VALUE, "Reverb air absorption gainhf out of range"};
434         props->Reverb.AirAbsorptionGainHF = val;
435         break;
436
437     case AL_REVERB_ROOM_ROLLOFF_FACTOR:
438         if(!(val >= AL_REVERB_MIN_ROOM_ROLLOFF_FACTOR && val <= AL_REVERB_MAX_ROOM_ROLLOFF_FACTOR))
439             throw effect_exception{AL_INVALID_VALUE, "Reverb room rolloff factor out of range"};
440         props->Reverb.RoomRolloffFactor = val;
441         break;
442
443     default:
444         throw effect_exception{AL_INVALID_ENUM, "Invalid reverb float property 0x%04x", param};
445     }
446 }
447 void StdReverb_setParamfv(EffectProps *props, ALenum param, const float *vals)
448 { StdReverb_setParamf(props, param, vals[0]); }
449
450 void StdReverb_getParami(const EffectProps *props, ALenum param, int *val)
451 {
452     switch(param)
453     {
454     case AL_REVERB_DECAY_HFLIMIT:
455         *val = props->Reverb.DecayHFLimit;
456         break;
457
458     default:
459         throw effect_exception{AL_INVALID_ENUM, "Invalid reverb integer property 0x%04x", param};
460     }
461 }
462 void StdReverb_getParamiv(const EffectProps *props, ALenum param, int *vals)
463 { StdReverb_getParami(props, param, vals); }
464 void StdReverb_getParamf(const EffectProps *props, ALenum param, float *val)
465 {
466     switch(param)
467     {
468     case AL_REVERB_DENSITY:
469         *val = props->Reverb.Density;
470         break;
471
472     case AL_REVERB_DIFFUSION:
473         *val = props->Reverb.Diffusion;
474         break;
475
476     case AL_REVERB_GAIN:
477         *val = props->Reverb.Gain;
478         break;
479
480     case AL_REVERB_GAINHF:
481         *val = props->Reverb.GainHF;
482         break;
483
484     case AL_REVERB_DECAY_TIME:
485         *val = props->Reverb.DecayTime;
486         break;
487
488     case AL_REVERB_DECAY_HFRATIO:
489         *val = props->Reverb.DecayHFRatio;
490         break;
491
492     case AL_REVERB_REFLECTIONS_GAIN:
493         *val = props->Reverb.ReflectionsGain;
494         break;
495
496     case AL_REVERB_REFLECTIONS_DELAY:
497         *val = props->Reverb.ReflectionsDelay;
498         break;
499
500     case AL_REVERB_LATE_REVERB_GAIN:
501         *val = props->Reverb.LateReverbGain;
502         break;
503
504     case AL_REVERB_LATE_REVERB_DELAY:
505         *val = props->Reverb.LateReverbDelay;
506         break;
507
508     case AL_REVERB_AIR_ABSORPTION_GAINHF:
509         *val = props->Reverb.AirAbsorptionGainHF;
510         break;
511
512     case AL_REVERB_ROOM_ROLLOFF_FACTOR:
513         *val = props->Reverb.RoomRolloffFactor;
514         break;
515
516     default:
517         throw effect_exception{AL_INVALID_ENUM, "Invalid reverb float property 0x%04x", param};
518     }
519 }
520 void StdReverb_getParamfv(const EffectProps *props, ALenum param, float *vals)
521 { StdReverb_getParamf(props, param, vals); }
522
523 EffectProps genDefaultStdProps() noexcept
524 {
525     EffectProps props{};
526     props.Reverb.Density   = AL_REVERB_DEFAULT_DENSITY;
527     props.Reverb.Diffusion = AL_REVERB_DEFAULT_DIFFUSION;
528     props.Reverb.Gain   = AL_REVERB_DEFAULT_GAIN;
529     props.Reverb.GainHF = AL_REVERB_DEFAULT_GAINHF;
530     props.Reverb.GainLF = 1.0f;
531     props.Reverb.DecayTime    = AL_REVERB_DEFAULT_DECAY_TIME;
532     props.Reverb.DecayHFRatio = AL_REVERB_DEFAULT_DECAY_HFRATIO;
533     props.Reverb.DecayLFRatio = 1.0f;
534     props.Reverb.ReflectionsGain   = AL_REVERB_DEFAULT_REFLECTIONS_GAIN;
535     props.Reverb.ReflectionsDelay  = AL_REVERB_DEFAULT_REFLECTIONS_DELAY;
536     props.Reverb.ReflectionsPan[0] = 0.0f;
537     props.Reverb.ReflectionsPan[1] = 0.0f;
538     props.Reverb.ReflectionsPan[2] = 0.0f;
539     props.Reverb.LateReverbGain   = AL_REVERB_DEFAULT_LATE_REVERB_GAIN;
540     props.Reverb.LateReverbDelay  = AL_REVERB_DEFAULT_LATE_REVERB_DELAY;
541     props.Reverb.LateReverbPan[0] = 0.0f;
542     props.Reverb.LateReverbPan[1] = 0.0f;
543     props.Reverb.LateReverbPan[2] = 0.0f;
544     props.Reverb.EchoTime  = 0.25f;
545     props.Reverb.EchoDepth = 0.0f;
546     props.Reverb.ModulationTime  = 0.25f;
547     props.Reverb.ModulationDepth = 0.0f;
548     props.Reverb.AirAbsorptionGainHF = AL_REVERB_DEFAULT_AIR_ABSORPTION_GAINHF;
549     props.Reverb.HFReference = 5000.0f;
550     props.Reverb.LFReference = 250.0f;
551     props.Reverb.RoomRolloffFactor = AL_REVERB_DEFAULT_ROOM_ROLLOFF_FACTOR;
552     props.Reverb.DecayHFLimit = AL_REVERB_DEFAULT_DECAY_HFLIMIT;
553     return props;
554 }
555
556 } // namespace
557
558 DEFINE_ALEFFECT_VTABLE(Reverb);
559
560 const EffectProps ReverbEffectProps{genDefaultProps()};
561
562 DEFINE_ALEFFECT_VTABLE(StdReverb);
563
564 const EffectProps StdReverbEffectProps{genDefaultStdProps()};
565
566 #ifdef ALSOFT_EAX
567 namespace {
568
569 class EaxReverbEffectException : public EaxException
570 {
571 public:
572     explicit EaxReverbEffectException(const char* message)
573         : EaxException{"EAX_REVERB_EFFECT", message}
574     {}
575 }; // EaxReverbEffectException
576
577 struct EnvironmentValidator1 {
578     void operator()(unsigned long ulEnvironment) const
579     {
580         eax_validate_range<EaxReverbEffectException>(
581             "Environment",
582             ulEnvironment,
583             EAXREVERB_MINENVIRONMENT,
584             EAX1REVERB_MAXENVIRONMENT);
585     }
586 }; // EnvironmentValidator1
587
588 struct VolumeValidator {
589     void operator()(float volume) const
590     {
591         eax_validate_range<EaxReverbEffectException>(
592             "Volume",
593             volume,
594             EAX1REVERB_MINVOLUME,
595             EAX1REVERB_MAXVOLUME);
596     }
597 }; // VolumeValidator
598
599 struct DecayTimeValidator {
600     void operator()(float flDecayTime) const
601     {
602         eax_validate_range<EaxReverbEffectException>(
603             "Decay Time",
604             flDecayTime,
605             EAXREVERB_MINDECAYTIME,
606             EAXREVERB_MAXDECAYTIME);
607     }
608 }; // DecayTimeValidator
609
610 struct DampingValidator {
611     void operator()(float damping) const
612     {
613         eax_validate_range<EaxReverbEffectException>(
614             "Damping",
615             damping,
616             EAX1REVERB_MINDAMPING,
617             EAX1REVERB_MAXDAMPING);
618     }
619 }; // DampingValidator
620
621 struct AllValidator1 {
622     void operator()(const EAX_REVERBPROPERTIES& all) const
623     {
624         EnvironmentValidator1{}(all.environment);
625         VolumeValidator{}(all.fVolume);
626         DecayTimeValidator{}(all.fDecayTime_sec);
627         DampingValidator{}(all.fDamping);
628     }
629 }; // AllValidator1
630
631 struct RoomValidator {
632     void operator()(long lRoom) const
633     {
634         eax_validate_range<EaxReverbEffectException>(
635             "Room",
636             lRoom,
637             EAXREVERB_MINROOM,
638             EAXREVERB_MAXROOM);
639     }
640 }; // RoomValidator
641
642 struct RoomHFValidator {
643     void operator()(long lRoomHF) const
644     {
645         eax_validate_range<EaxReverbEffectException>(
646             "Room HF",
647             lRoomHF,
648             EAXREVERB_MINROOMHF,
649             EAXREVERB_MAXROOMHF);
650     }
651 }; // RoomHFValidator
652
653 struct RoomRolloffFactorValidator {
654     void operator()(float flRoomRolloffFactor) const
655     {
656         eax_validate_range<EaxReverbEffectException>(
657             "Room Rolloff Factor",
658             flRoomRolloffFactor,
659             EAXREVERB_MINROOMROLLOFFFACTOR,
660             EAXREVERB_MAXROOMROLLOFFFACTOR);
661     }
662 }; // RoomRolloffFactorValidator
663
664 struct DecayHFRatioValidator {
665     void operator()(float flDecayHFRatio) const
666     {
667         eax_validate_range<EaxReverbEffectException>(
668             "Decay HF Ratio",
669             flDecayHFRatio,
670             EAXREVERB_MINDECAYHFRATIO,
671             EAXREVERB_MAXDECAYHFRATIO);
672     }
673 }; // DecayHFRatioValidator
674
675 struct ReflectionsValidator {
676     void operator()(long lReflections) const
677     {
678         eax_validate_range<EaxReverbEffectException>(
679             "Reflections",
680             lReflections,
681             EAXREVERB_MINREFLECTIONS,
682             EAXREVERB_MAXREFLECTIONS);
683     }
684 }; // ReflectionsValidator
685
686 struct ReflectionsDelayValidator {
687     void operator()(float flReflectionsDelay) const
688     {
689         eax_validate_range<EaxReverbEffectException>(
690             "Reflections Delay",
691             flReflectionsDelay,
692             EAXREVERB_MINREFLECTIONSDELAY,
693             EAXREVERB_MAXREFLECTIONSDELAY);
694     }
695 }; // ReflectionsDelayValidator
696
697 struct ReverbValidator {
698     void operator()(long lReverb) const
699     {
700         eax_validate_range<EaxReverbEffectException>(
701             "Reverb",
702             lReverb,
703             EAXREVERB_MINREVERB,
704             EAXREVERB_MAXREVERB);
705     }
706 }; // ReverbValidator
707
708 struct ReverbDelayValidator {
709     void operator()(float flReverbDelay) const
710     {
711         eax_validate_range<EaxReverbEffectException>(
712             "Reverb Delay",
713             flReverbDelay,
714             EAXREVERB_MINREVERBDELAY,
715             EAXREVERB_MAXREVERBDELAY);
716     }
717 }; // ReverbDelayValidator
718
719 struct EnvironmentSizeValidator {
720     void operator()(float flEnvironmentSize) const
721     {
722         eax_validate_range<EaxReverbEffectException>(
723             "Environment Size",
724             flEnvironmentSize,
725             EAXREVERB_MINENVIRONMENTSIZE,
726             EAXREVERB_MAXENVIRONMENTSIZE);
727     }
728 }; // EnvironmentSizeValidator
729
730 struct EnvironmentDiffusionValidator {
731     void operator()(float flEnvironmentDiffusion) const
732     {
733         eax_validate_range<EaxReverbEffectException>(
734             "Environment Diffusion",
735             flEnvironmentDiffusion,
736             EAXREVERB_MINENVIRONMENTDIFFUSION,
737             EAXREVERB_MAXENVIRONMENTDIFFUSION);
738     }
739 }; // EnvironmentDiffusionValidator
740
741 struct AirAbsorptionHFValidator {
742     void operator()(float flAirAbsorptionHF) const
743     {
744         eax_validate_range<EaxReverbEffectException>(
745             "Air Absorbtion HF",
746             flAirAbsorptionHF,
747             EAXREVERB_MINAIRABSORPTIONHF,
748             EAXREVERB_MAXAIRABSORPTIONHF);
749     }
750 }; // AirAbsorptionHFValidator
751
752 struct FlagsValidator2 {
753     void operator()(unsigned long ulFlags) const
754     {
755         eax_validate_range<EaxReverbEffectException>(
756             "Flags",
757             ulFlags,
758             0UL,
759             ~EAX2LISTENERFLAGS_RESERVED);
760     }
761 }; // FlagsValidator2
762
763 struct AllValidator2 {
764     void operator()(const EAX20LISTENERPROPERTIES& all) const
765     {
766         RoomValidator{}(all.lRoom);
767         RoomHFValidator{}(all.lRoomHF);
768         RoomRolloffFactorValidator{}(all.flRoomRolloffFactor);
769         DecayTimeValidator{}(all.flDecayTime);
770         DecayHFRatioValidator{}(all.flDecayHFRatio);
771         ReflectionsValidator{}(all.lReflections);
772         ReflectionsDelayValidator{}(all.flReflectionsDelay);
773         ReverbValidator{}(all.lReverb);
774         ReverbDelayValidator{}(all.flReverbDelay);
775         EnvironmentValidator1{}(all.dwEnvironment);
776         EnvironmentSizeValidator{}(all.flEnvironmentSize);
777         EnvironmentDiffusionValidator{}(all.flEnvironmentDiffusion);
778         AirAbsorptionHFValidator{}(all.flAirAbsorptionHF);
779         FlagsValidator2{}(all.dwFlags);
780     }
781 }; // AllValidator2
782
783 struct EnvironmentValidator3 {
784     void operator()(unsigned long ulEnvironment) const
785     {
786         eax_validate_range<EaxReverbEffectException>(
787             "Environment",
788             ulEnvironment,
789             EAXREVERB_MINENVIRONMENT,
790             EAX30REVERB_MAXENVIRONMENT);
791     }
792 }; // EnvironmentValidator1
793
794 struct RoomLFValidator {
795     void operator()(long lRoomLF) const
796     {
797         eax_validate_range<EaxReverbEffectException>(
798             "Room LF",
799             lRoomLF,
800             EAXREVERB_MINROOMLF,
801             EAXREVERB_MAXROOMLF);
802     }
803 }; // RoomLFValidator
804
805 struct DecayLFRatioValidator {
806     void operator()(float flDecayLFRatio) const
807     {
808         eax_validate_range<EaxReverbEffectException>(
809             "Decay LF Ratio",
810             flDecayLFRatio,
811             EAXREVERB_MINDECAYLFRATIO,
812             EAXREVERB_MAXDECAYLFRATIO);
813     }
814 }; // DecayLFRatioValidator
815
816 struct VectorValidator {
817     void operator()(const EAXVECTOR&) const
818     {}
819 }; // VectorValidator
820
821 struct EchoTimeValidator {
822     void operator()(float flEchoTime) const
823     {
824         eax_validate_range<EaxReverbEffectException>(
825             "Echo Time",
826             flEchoTime,
827             EAXREVERB_MINECHOTIME,
828             EAXREVERB_MAXECHOTIME);
829     }
830 }; // EchoTimeValidator
831
832 struct EchoDepthValidator {
833     void operator()(float flEchoDepth) const
834     {
835         eax_validate_range<EaxReverbEffectException>(
836             "Echo Depth",
837             flEchoDepth,
838             EAXREVERB_MINECHODEPTH,
839             EAXREVERB_MAXECHODEPTH);
840     }
841 }; // EchoDepthValidator
842
843 struct ModulationTimeValidator {
844     void operator()(float flModulationTime) const
845     {
846         eax_validate_range<EaxReverbEffectException>(
847             "Modulation Time",
848             flModulationTime,
849             EAXREVERB_MINMODULATIONTIME,
850             EAXREVERB_MAXMODULATIONTIME);
851     }
852 }; // ModulationTimeValidator
853
854 struct ModulationDepthValidator {
855     void operator()(float flModulationDepth) const
856     {
857         eax_validate_range<EaxReverbEffectException>(
858             "Modulation Depth",
859             flModulationDepth,
860             EAXREVERB_MINMODULATIONDEPTH,
861             EAXREVERB_MAXMODULATIONDEPTH);
862     }
863 }; // ModulationDepthValidator
864
865 struct HFReferenceValidator {
866     void operator()(float flHFReference) const
867     {
868         eax_validate_range<EaxReverbEffectException>(
869             "HF Reference",
870             flHFReference,
871             EAXREVERB_MINHFREFERENCE,
872             EAXREVERB_MAXHFREFERENCE);
873     }
874 }; // HFReferenceValidator
875
876 struct LFReferenceValidator {
877     void operator()(float flLFReference) const
878     {
879         eax_validate_range<EaxReverbEffectException>(
880             "LF Reference",
881             flLFReference,
882             EAXREVERB_MINLFREFERENCE,
883             EAXREVERB_MAXLFREFERENCE);
884     }
885 }; // LFReferenceValidator
886
887 struct FlagsValidator3 {
888     void operator()(unsigned long ulFlags) const
889     {
890         eax_validate_range<EaxReverbEffectException>(
891             "Flags",
892             ulFlags,
893             0UL,
894             ~EAXREVERBFLAGS_RESERVED);
895     }
896 }; // FlagsValidator3
897
898 struct AllValidator3 {
899     void operator()(const EAXREVERBPROPERTIES& all) const
900     {
901         EnvironmentValidator3{}(all.ulEnvironment);
902         EnvironmentSizeValidator{}(all.flEnvironmentSize);
903         EnvironmentDiffusionValidator{}(all.flEnvironmentDiffusion);
904         RoomValidator{}(all.lRoom);
905         RoomHFValidator{}(all.lRoomHF);
906         RoomLFValidator{}(all.lRoomLF);
907         DecayTimeValidator{}(all.flDecayTime);
908         DecayHFRatioValidator{}(all.flDecayHFRatio);
909         DecayLFRatioValidator{}(all.flDecayLFRatio);
910         ReflectionsValidator{}(all.lReflections);
911         ReflectionsDelayValidator{}(all.flReflectionsDelay);
912         VectorValidator{}(all.vReflectionsPan);
913         ReverbValidator{}(all.lReverb);
914         ReverbDelayValidator{}(all.flReverbDelay);
915         VectorValidator{}(all.vReverbPan);
916         EchoTimeValidator{}(all.flEchoTime);
917         EchoDepthValidator{}(all.flEchoDepth);
918         ModulationTimeValidator{}(all.flModulationTime);
919         ModulationDepthValidator{}(all.flModulationDepth);
920         AirAbsorptionHFValidator{}(all.flAirAbsorptionHF);
921         HFReferenceValidator{}(all.flHFReference);
922         LFReferenceValidator{}(all.flLFReference);
923         RoomRolloffFactorValidator{}(all.flRoomRolloffFactor);
924         FlagsValidator3{}(all.ulFlags);
925     }
926 }; // AllValidator3
927
928 struct EnvironmentDeferrer2 {
929     void operator()(EAX20LISTENERPROPERTIES& props, unsigned long dwEnvironment) const
930     {
931         props = EAX2REVERB_PRESETS[dwEnvironment];
932     }
933 }; // EnvironmentDeferrer2
934
935 struct EnvironmentSizeDeferrer2 {
936     void operator()(EAX20LISTENERPROPERTIES& props, float flEnvironmentSize) const
937     {
938         if (props.flEnvironmentSize == flEnvironmentSize)
939         {
940             return;
941         }
942
943         const auto scale = flEnvironmentSize / props.flEnvironmentSize;
944         props.flEnvironmentSize = flEnvironmentSize;
945
946         if ((props.dwFlags & EAX2LISTENERFLAGS_DECAYTIMESCALE) != 0)
947         {
948             props.flDecayTime = clamp(
949                 props.flDecayTime * scale,
950                 EAXREVERB_MINDECAYTIME,
951                 EAXREVERB_MAXDECAYTIME);
952         }
953
954         if ((props.dwFlags & EAX2LISTENERFLAGS_REFLECTIONSSCALE) != 0 &&
955             (props.dwFlags & EAX2LISTENERFLAGS_REFLECTIONSDELAYSCALE) != 0)
956         {
957             props.lReflections = clamp(
958                 props.lReflections - static_cast<long>(gain_to_level_mb(scale)),
959                 EAXREVERB_MINREFLECTIONS,
960                 EAXREVERB_MAXREFLECTIONS);
961         }
962
963         if ((props.dwFlags & EAX2LISTENERFLAGS_REFLECTIONSDELAYSCALE) != 0)
964         {
965             props.flReflectionsDelay = clamp(
966                 props.flReflectionsDelay * scale,
967                 EAXREVERB_MINREFLECTIONSDELAY,
968                 EAXREVERB_MAXREFLECTIONSDELAY);
969         }
970
971         if ((props.dwFlags & EAX2LISTENERFLAGS_REVERBSCALE) != 0)
972         {
973             const auto log_scalar = ((props.dwFlags & EAXREVERBFLAGS_DECAYTIMESCALE) != 0) ? 2'000.0F : 3'000.0F;
974
975             props.lReverb = clamp(
976                 props.lReverb - static_cast<long>(std::log10(scale) * log_scalar),
977                 EAXREVERB_MINREVERB,
978                 EAXREVERB_MAXREVERB);
979         }
980
981         if ((props.dwFlags & EAX2LISTENERFLAGS_REVERBDELAYSCALE) != 0)
982         {
983             props.flReverbDelay = clamp(
984                 props.flReverbDelay * scale,
985                 EAXREVERB_MINREVERBDELAY,
986                 EAXREVERB_MAXREVERBDELAY);
987         }
988     }
989 }; // EnvironmentSizeDeferrer2
990
991 struct EnvironmentDeferrer3 {
992     void operator()(EAXREVERBPROPERTIES& props, unsigned long ulEnvironment) const
993     {
994         if (ulEnvironment == EAX_ENVIRONMENT_UNDEFINED)
995         {
996             props.ulEnvironment = EAX_ENVIRONMENT_UNDEFINED;
997             return;
998         }
999
1000         props = EAXREVERB_PRESETS[ulEnvironment];
1001     }
1002 }; // EnvironmentDeferrer3
1003
1004 struct EnvironmentSizeDeferrer3 {
1005     void operator()(EAXREVERBPROPERTIES& props, float flEnvironmentSize) const
1006     {
1007         if (props.flEnvironmentSize == flEnvironmentSize)
1008         {
1009             return;
1010         }
1011
1012         const auto scale = flEnvironmentSize / props.flEnvironmentSize;
1013         props.ulEnvironment = EAX_ENVIRONMENT_UNDEFINED;
1014         props.flEnvironmentSize = flEnvironmentSize;
1015
1016         if ((props.ulFlags & EAXREVERBFLAGS_DECAYTIMESCALE) != 0)
1017         {
1018             props.flDecayTime = clamp(
1019                 props.flDecayTime * scale,
1020                 EAXREVERB_MINDECAYTIME,
1021                 EAXREVERB_MAXDECAYTIME);
1022         }
1023
1024         if ((props.ulFlags & EAXREVERBFLAGS_REFLECTIONSSCALE) != 0 &&
1025             (props.ulFlags & EAXREVERBFLAGS_REFLECTIONSDELAYSCALE) != 0)
1026         {
1027             props.lReflections = clamp(
1028                 props.lReflections - static_cast<long>(gain_to_level_mb(scale)),
1029                 EAXREVERB_MINREFLECTIONS,
1030                 EAXREVERB_MAXREFLECTIONS);
1031         }
1032
1033         if ((props.ulFlags & EAXREVERBFLAGS_REFLECTIONSDELAYSCALE) != 0)
1034         {
1035             props.flReflectionsDelay = clamp(
1036                 props.flReflectionsDelay * scale,
1037                 EAXREVERB_MINREFLECTIONSDELAY,
1038                 EAXREVERB_MAXREFLECTIONSDELAY);
1039         }
1040
1041         if ((props.ulFlags & EAXREVERBFLAGS_REVERBSCALE) != 0)
1042         {
1043             const auto log_scalar = ((props.ulFlags & EAXREVERBFLAGS_DECAYTIMESCALE) != 0) ? 2'000.0F : 3'000.0F;
1044             props.lReverb = clamp(
1045                 props.lReverb - static_cast<long>(std::log10(scale) * log_scalar),
1046                 EAXREVERB_MINREVERB,
1047                 EAXREVERB_MAXREVERB);
1048         }
1049
1050         if ((props.ulFlags & EAXREVERBFLAGS_REVERBDELAYSCALE) != 0)
1051         {
1052             props.flReverbDelay = clamp(
1053                 props.flReverbDelay * scale,
1054                 EAXREVERB_MINREVERBDELAY,
1055                 EAXREVERB_MAXREVERBDELAY);
1056         }
1057
1058         if ((props.ulFlags & EAXREVERBFLAGS_ECHOTIMESCALE) != 0)
1059         {
1060             props.flEchoTime = clamp(
1061                 props.flEchoTime * scale,
1062                 EAXREVERB_MINECHOTIME,
1063                 EAXREVERB_MAXECHOTIME);
1064         }
1065
1066         if ((props.ulFlags & EAXREVERBFLAGS_MODULATIONTIMESCALE) != 0)
1067         {
1068             props.flModulationTime = clamp(
1069                 props.flModulationTime * scale,
1070                 EAXREVERB_MINMODULATIONTIME,
1071                 EAXREVERB_MAXMODULATIONTIME);
1072         }
1073     }
1074 }; // EnvironmentSizeDeferrer3
1075
1076 } // namespace
1077
1078
1079 struct EaxReverbCommitter::Exception : public EaxReverbEffectException
1080 {
1081     using EaxReverbEffectException::EaxReverbEffectException;
1082 };
1083
1084 [[noreturn]] void EaxReverbCommitter::fail(const char* message)
1085 {
1086     throw Exception{message};
1087 }
1088
1089 void EaxReverbCommitter::translate(const EAX_REVERBPROPERTIES& src, EaxEffectProps& dst) noexcept
1090 {
1091     assert(src.environment <= EAX1REVERB_MAXENVIRONMENT);
1092     dst.mType = EaxEffectType::Reverb;
1093     dst.mReverb = EAXREVERB_PRESETS[src.environment];
1094     dst.mReverb.flDecayTime = src.fDecayTime_sec;
1095     dst.mReverb.flDecayHFRatio = src.fDamping;
1096     dst.mReverb.lReverb = mini(static_cast<int>(gain_to_level_mb(src.fVolume)), 0);
1097 }
1098
1099 void EaxReverbCommitter::translate(const EAX20LISTENERPROPERTIES& src, EaxEffectProps& dst) noexcept
1100 {
1101     assert(src.dwEnvironment <= EAX1REVERB_MAXENVIRONMENT);
1102     const auto& env = EAXREVERB_PRESETS[src.dwEnvironment];
1103     dst.mType = EaxEffectType::Reverb;
1104     dst.mReverb.ulEnvironment = src.dwEnvironment;
1105     dst.mReverb.flEnvironmentSize = src.flEnvironmentSize;
1106     dst.mReverb.flEnvironmentDiffusion = src.flEnvironmentDiffusion;
1107     dst.mReverb.lRoom = src.lRoom;
1108     dst.mReverb.lRoomHF = src.lRoomHF;
1109     dst.mReverb.lRoomLF = env.lRoomLF;
1110     dst.mReverb.flDecayTime = src.flDecayTime;
1111     dst.mReverb.flDecayHFRatio = src.flDecayHFRatio;
1112     dst.mReverb.flDecayLFRatio = env.flDecayLFRatio;
1113     dst.mReverb.lReflections = src.lReflections;
1114     dst.mReverb.flReflectionsDelay = src.flReflectionsDelay;
1115     dst.mReverb.vReflectionsPan = env.vReflectionsPan;
1116     dst.mReverb.lReverb = src.lReverb;
1117     dst.mReverb.flReverbDelay = src.flReverbDelay;
1118     dst.mReverb.vReverbPan = env.vReverbPan;
1119     dst.mReverb.flEchoTime = env.flEchoTime;
1120     dst.mReverb.flEchoDepth = env.flEchoDepth;
1121     dst.mReverb.flModulationTime = env.flModulationTime;
1122     dst.mReverb.flModulationDepth = env.flModulationDepth;
1123     dst.mReverb.flAirAbsorptionHF = src.flAirAbsorptionHF;
1124     dst.mReverb.flHFReference = env.flHFReference;
1125     dst.mReverb.flLFReference = env.flLFReference;
1126     dst.mReverb.flRoomRolloffFactor = src.flRoomRolloffFactor;
1127     dst.mReverb.ulFlags = src.dwFlags;
1128 }
1129
1130 void EaxReverbCommitter::translate(const EAXREVERBPROPERTIES& src, EaxEffectProps& dst) noexcept
1131 {
1132     dst.mType = EaxEffectType::Reverb;
1133     dst.mReverb = src;
1134 }
1135
1136 bool EaxReverbCommitter::commit(const EAX_REVERBPROPERTIES &props)
1137 {
1138     EaxEffectProps dst{};
1139     translate(props, dst);
1140     return commit(dst);
1141 }
1142
1143 bool EaxReverbCommitter::commit(const EAX20LISTENERPROPERTIES &props)
1144 {
1145     EaxEffectProps dst{};
1146     translate(props, dst);
1147     return commit(dst);
1148 }
1149
1150 bool EaxReverbCommitter::commit(const EAXREVERBPROPERTIES &props)
1151 {
1152     EaxEffectProps dst{};
1153     translate(props, dst);
1154     return commit(dst);
1155 }
1156
1157 bool EaxReverbCommitter::commit(const EaxEffectProps &props)
1158 {
1159     if(props.mType == mEaxProps.mType
1160         && memcmp(&props.mReverb, &mEaxProps.mReverb, sizeof(mEaxProps.mReverb)) == 0)
1161         return false;
1162
1163     mEaxProps = props;
1164
1165     const auto size = props.mReverb.flEnvironmentSize;
1166     const auto density = (size * size * size) / 16.0F;
1167     mAlProps.Reverb.Density = std::min(density, AL_EAXREVERB_MAX_DENSITY);
1168     mAlProps.Reverb.Diffusion = props.mReverb.flEnvironmentDiffusion;
1169     mAlProps.Reverb.Gain = level_mb_to_gain(static_cast<float>(props.mReverb.lRoom));
1170     mAlProps.Reverb.GainHF = level_mb_to_gain(static_cast<float>(props.mReverb.lRoomHF));
1171     mAlProps.Reverb.GainLF = level_mb_to_gain(static_cast<float>(props.mReverb.lRoomLF));
1172     mAlProps.Reverb.DecayTime = props.mReverb.flDecayTime;
1173     mAlProps.Reverb.DecayHFRatio = props.mReverb.flDecayHFRatio;
1174     mAlProps.Reverb.DecayLFRatio = mEaxProps.mReverb.flDecayLFRatio;
1175     mAlProps.Reverb.ReflectionsGain = level_mb_to_gain(static_cast<float>(props.mReverb.lReflections));
1176     mAlProps.Reverb.ReflectionsDelay = props.mReverb.flReflectionsDelay;
1177     mAlProps.Reverb.ReflectionsPan[0] = props.mReverb.vReflectionsPan.x;
1178     mAlProps.Reverb.ReflectionsPan[1] = props.mReverb.vReflectionsPan.y;
1179     mAlProps.Reverb.ReflectionsPan[2] = props.mReverb.vReflectionsPan.z;
1180     mAlProps.Reverb.LateReverbGain = level_mb_to_gain(static_cast<float>(props.mReverb.lReverb));
1181     mAlProps.Reverb.LateReverbDelay = props.mReverb.flReverbDelay;
1182     mAlProps.Reverb.LateReverbPan[0] = props.mReverb.vReverbPan.x;
1183     mAlProps.Reverb.LateReverbPan[1] = props.mReverb.vReverbPan.y;
1184     mAlProps.Reverb.LateReverbPan[2] = props.mReverb.vReverbPan.z;
1185     mAlProps.Reverb.EchoTime = props.mReverb.flEchoTime;
1186     mAlProps.Reverb.EchoDepth = props.mReverb.flEchoDepth;
1187     mAlProps.Reverb.ModulationTime = props.mReverb.flModulationTime;
1188     mAlProps.Reverb.ModulationDepth = props.mReverb.flModulationDepth;
1189     mAlProps.Reverb.AirAbsorptionGainHF = level_mb_to_gain(props.mReverb.flAirAbsorptionHF);
1190     mAlProps.Reverb.HFReference = props.mReverb.flHFReference;
1191     mAlProps.Reverb.LFReference = props.mReverb.flLFReference;
1192     mAlProps.Reverb.RoomRolloffFactor = props.mReverb.flRoomRolloffFactor;
1193     mAlProps.Reverb.DecayHFLimit = ((props.mReverb.ulFlags & EAXREVERBFLAGS_DECAYHFLIMIT) != 0);
1194     return true;
1195 }
1196
1197 void EaxReverbCommitter::SetDefaults(EAX_REVERBPROPERTIES &props)
1198 {
1199     props = EAX1REVERB_PRESETS[EAX_ENVIRONMENT_GENERIC];
1200 }
1201
1202 void EaxReverbCommitter::SetDefaults(EAX20LISTENERPROPERTIES &props)
1203 {
1204     props = EAX2REVERB_PRESETS[EAX2_ENVIRONMENT_GENERIC];
1205     props.lRoom = -10'000L;
1206 }
1207
1208 void EaxReverbCommitter::SetDefaults(EAXREVERBPROPERTIES &props)
1209 {
1210     props = EAXREVERB_PRESETS[EAX_ENVIRONMENT_GENERIC];
1211 }
1212
1213 void EaxReverbCommitter::SetDefaults(EaxEffectProps &props)
1214 {
1215     props.mType = EaxEffectType::Reverb;
1216     SetDefaults(props.mReverb);
1217 }
1218
1219
1220 void EaxReverbCommitter::Get(const EaxCall &call, const EAX_REVERBPROPERTIES &props)
1221 {
1222     switch(call.get_property_id())
1223     {
1224     case DSPROPERTY_EAX_ALL: call.set_value<Exception>(props); break;
1225     case DSPROPERTY_EAX_ENVIRONMENT: call.set_value<Exception>(props.environment); break;
1226     case DSPROPERTY_EAX_VOLUME: call.set_value<Exception>(props.fVolume); break;
1227     case DSPROPERTY_EAX_DECAYTIME: call.set_value<Exception>(props.fDecayTime_sec); break;
1228     case DSPROPERTY_EAX_DAMPING: call.set_value<Exception>(props.fDamping); break;
1229     default: fail_unknown_property_id();
1230     }
1231 }
1232
1233 void EaxReverbCommitter::Get(const EaxCall &call, const EAX20LISTENERPROPERTIES &props)
1234 {
1235     switch(call.get_property_id())
1236     {
1237     case DSPROPERTY_EAX20LISTENER_NONE: break;
1238     case DSPROPERTY_EAX20LISTENER_ALLPARAMETERS: call.set_value<Exception>(props); break;
1239     case DSPROPERTY_EAX20LISTENER_ROOM: call.set_value<Exception>(props.lRoom); break;
1240     case DSPROPERTY_EAX20LISTENER_ROOMHF: call.set_value<Exception>(props.lRoomHF); break;
1241     case DSPROPERTY_EAX20LISTENER_ROOMROLLOFFFACTOR: call.set_value<Exception>(props.flRoomRolloffFactor); break;
1242     case DSPROPERTY_EAX20LISTENER_DECAYTIME: call.set_value<Exception>(props.flDecayTime); break;
1243     case DSPROPERTY_EAX20LISTENER_DECAYHFRATIO: call.set_value<Exception>(props.flDecayHFRatio); break;
1244     case DSPROPERTY_EAX20LISTENER_REFLECTIONS: call.set_value<Exception>(props.lReflections); break;
1245     case DSPROPERTY_EAX20LISTENER_REFLECTIONSDELAY: call.set_value<Exception>(props.flReflectionsDelay); break;
1246     case DSPROPERTY_EAX20LISTENER_REVERB: call.set_value<Exception>(props.lReverb); break;
1247     case DSPROPERTY_EAX20LISTENER_REVERBDELAY: call.set_value<Exception>(props.flReverbDelay); break;
1248     case DSPROPERTY_EAX20LISTENER_ENVIRONMENT: call.set_value<Exception>(props.dwEnvironment); break;
1249     case DSPROPERTY_EAX20LISTENER_ENVIRONMENTSIZE: call.set_value<Exception>(props.flEnvironmentSize); break;
1250     case DSPROPERTY_EAX20LISTENER_ENVIRONMENTDIFFUSION: call.set_value<Exception>(props.flEnvironmentDiffusion); break;
1251     case DSPROPERTY_EAX20LISTENER_AIRABSORPTIONHF: call.set_value<Exception>(props.flAirAbsorptionHF); break;
1252     case DSPROPERTY_EAX20LISTENER_FLAGS: call.set_value<Exception>(props.dwFlags); break;
1253     default: fail_unknown_property_id();
1254     }
1255 }
1256
1257 void EaxReverbCommitter::Get(const EaxCall &call, const EAXREVERBPROPERTIES &props)
1258 {
1259     switch(call.get_property_id())
1260     {
1261     case EAXREVERB_NONE: break;
1262     case EAXREVERB_ALLPARAMETERS: call.set_value<Exception>(props); break;
1263     case EAXREVERB_ENVIRONMENT: call.set_value<Exception>(props.ulEnvironment); break;
1264     case EAXREVERB_ENVIRONMENTSIZE: call.set_value<Exception>(props.flEnvironmentSize); break;
1265     case EAXREVERB_ENVIRONMENTDIFFUSION: call.set_value<Exception>(props.flEnvironmentDiffusion); break;
1266     case EAXREVERB_ROOM: call.set_value<Exception>(props.lRoom); break;
1267     case EAXREVERB_ROOMHF: call.set_value<Exception>(props.lRoomHF); break;
1268     case EAXREVERB_ROOMLF: call.set_value<Exception>(props.lRoomLF); break;
1269     case EAXREVERB_DECAYTIME: call.set_value<Exception>(props.flDecayTime); break;
1270     case EAXREVERB_DECAYHFRATIO: call.set_value<Exception>(props.flDecayHFRatio); break;
1271     case EAXREVERB_DECAYLFRATIO: call.set_value<Exception>(props.flDecayLFRatio); break;
1272     case EAXREVERB_REFLECTIONS: call.set_value<Exception>(props.lReflections); break;
1273     case EAXREVERB_REFLECTIONSDELAY: call.set_value<Exception>(props.flReflectionsDelay); break;
1274     case EAXREVERB_REFLECTIONSPAN: call.set_value<Exception>(props.vReflectionsPan); break;
1275     case EAXREVERB_REVERB: call.set_value<Exception>(props.lReverb); break;
1276     case EAXREVERB_REVERBDELAY: call.set_value<Exception>(props.flReverbDelay); break;
1277     case EAXREVERB_REVERBPAN: call.set_value<Exception>(props.vReverbPan); break;
1278     case EAXREVERB_ECHOTIME: call.set_value<Exception>(props.flEchoTime); break;
1279     case EAXREVERB_ECHODEPTH: call.set_value<Exception>(props.flEchoDepth); break;
1280     case EAXREVERB_MODULATIONTIME: call.set_value<Exception>(props.flModulationTime); break;
1281     case EAXREVERB_MODULATIONDEPTH: call.set_value<Exception>(props.flModulationDepth); break;
1282     case EAXREVERB_AIRABSORPTIONHF: call.set_value<Exception>(props.flAirAbsorptionHF); break;
1283     case EAXREVERB_HFREFERENCE: call.set_value<Exception>(props.flHFReference); break;
1284     case EAXREVERB_LFREFERENCE: call.set_value<Exception>(props.flLFReference); break;
1285     case EAXREVERB_ROOMROLLOFFFACTOR: call.set_value<Exception>(props.flRoomRolloffFactor); break;
1286     case EAXREVERB_FLAGS: call.set_value<Exception>(props.ulFlags); break;
1287     default: fail_unknown_property_id();
1288     }
1289 }
1290
1291 void EaxReverbCommitter::Get(const EaxCall &call, const EaxEffectProps &props)
1292 {
1293     Get(call, props.mReverb);
1294 }
1295
1296
1297 void EaxReverbCommitter::Set(const EaxCall &call, EAX_REVERBPROPERTIES &props)
1298 {
1299     switch(call.get_property_id())
1300     {
1301     case DSPROPERTY_EAX_ALL: defer<AllValidator1>(call, props); break;
1302     case DSPROPERTY_EAX_ENVIRONMENT: defer<EnvironmentValidator1>(call, props.environment); break;
1303     case DSPROPERTY_EAX_VOLUME: defer<VolumeValidator>(call, props.fVolume); break;
1304     case DSPROPERTY_EAX_DECAYTIME: defer<DecayTimeValidator>(call, props.fDecayTime_sec); break;
1305     case DSPROPERTY_EAX_DAMPING: defer<DampingValidator>(call, props.fDamping); break;
1306     default: fail_unknown_property_id();
1307     }
1308 }
1309
1310 void EaxReverbCommitter::Set(const EaxCall &call, EAX20LISTENERPROPERTIES &props)
1311 {
1312     switch(call.get_property_id())
1313     {
1314     case DSPROPERTY_EAX20LISTENER_NONE:
1315         break;
1316
1317     case DSPROPERTY_EAX20LISTENER_ALLPARAMETERS:
1318         defer<AllValidator2>(call, props);
1319         break;
1320
1321     case DSPROPERTY_EAX20LISTENER_ROOM:
1322         defer<RoomValidator>(call, props.lRoom);
1323         break;
1324
1325     case DSPROPERTY_EAX20LISTENER_ROOMHF:
1326         defer<RoomHFValidator>(call, props.lRoomHF);
1327         break;
1328
1329     case DSPROPERTY_EAX20LISTENER_ROOMROLLOFFFACTOR:
1330         defer<RoomRolloffFactorValidator>(call, props.flRoomRolloffFactor);
1331         break;
1332
1333     case DSPROPERTY_EAX20LISTENER_DECAYTIME:
1334         defer<DecayTimeValidator>(call, props.flDecayTime);
1335         break;
1336
1337     case DSPROPERTY_EAX20LISTENER_DECAYHFRATIO:
1338         defer<DecayHFRatioValidator>(call, props.flDecayHFRatio);
1339         break;
1340
1341     case DSPROPERTY_EAX20LISTENER_REFLECTIONS:
1342         defer<ReflectionsValidator>(call, props.lReflections);
1343         break;
1344
1345     case DSPROPERTY_EAX20LISTENER_REFLECTIONSDELAY:
1346         defer<ReflectionsDelayValidator>(call, props.flReverbDelay);
1347         break;
1348
1349     case DSPROPERTY_EAX20LISTENER_REVERB:
1350         defer<ReverbValidator>(call, props.lReverb);
1351         break;
1352
1353     case DSPROPERTY_EAX20LISTENER_REVERBDELAY:
1354         defer<ReverbDelayValidator>(call, props.flReverbDelay);
1355         break;
1356
1357     case DSPROPERTY_EAX20LISTENER_ENVIRONMENT:
1358         defer<EnvironmentValidator1, EnvironmentDeferrer2>(call, props, props.dwEnvironment);
1359         break;
1360
1361     case DSPROPERTY_EAX20LISTENER_ENVIRONMENTSIZE:
1362         defer<EnvironmentSizeValidator, EnvironmentSizeDeferrer2>(call, props, props.flEnvironmentSize);
1363         break;
1364
1365     case DSPROPERTY_EAX20LISTENER_ENVIRONMENTDIFFUSION:
1366         defer<EnvironmentDiffusionValidator>(call, props.flEnvironmentDiffusion);
1367         break;
1368
1369     case DSPROPERTY_EAX20LISTENER_AIRABSORPTIONHF:
1370         defer<AirAbsorptionHFValidator>(call, props.flAirAbsorptionHF);
1371         break;
1372
1373     case DSPROPERTY_EAX20LISTENER_FLAGS:
1374         defer<FlagsValidator2>(call, props.dwFlags);
1375         break;
1376
1377     default:
1378         fail_unknown_property_id();
1379     }
1380 }
1381
1382 void EaxReverbCommitter::Set(const EaxCall &call, EAXREVERBPROPERTIES &props)
1383 {
1384     switch(call.get_property_id())
1385     {
1386     case EAXREVERB_NONE:
1387         break;
1388
1389     case EAXREVERB_ALLPARAMETERS:
1390         defer<AllValidator3>(call, props);
1391         break;
1392
1393     case EAXREVERB_ENVIRONMENT:
1394         defer<EnvironmentValidator3, EnvironmentDeferrer3>(call, props, props.ulEnvironment);
1395         break;
1396
1397     case EAXREVERB_ENVIRONMENTSIZE:
1398         defer<EnvironmentSizeValidator, EnvironmentSizeDeferrer3>(call, props, props.flEnvironmentSize);
1399         break;
1400
1401     case EAXREVERB_ENVIRONMENTDIFFUSION:
1402         defer3<EnvironmentDiffusionValidator>(call, props, props.flEnvironmentDiffusion);
1403         break;
1404
1405     case EAXREVERB_ROOM:
1406         defer3<RoomValidator>(call, props, props.lRoom);
1407         break;
1408
1409     case EAXREVERB_ROOMHF:
1410         defer3<RoomHFValidator>(call, props, props.lRoomHF);
1411         break;
1412
1413     case EAXREVERB_ROOMLF:
1414         defer3<RoomLFValidator>(call, props, props.lRoomLF);
1415         break;
1416
1417     case EAXREVERB_DECAYTIME:
1418         defer3<DecayTimeValidator>(call, props, props.flDecayTime);
1419         break;
1420
1421     case EAXREVERB_DECAYHFRATIO:
1422         defer3<DecayHFRatioValidator>(call, props, props.flDecayHFRatio);
1423         break;
1424
1425     case EAXREVERB_DECAYLFRATIO:
1426         defer3<DecayLFRatioValidator>(call, props, props.flDecayLFRatio);
1427         break;
1428
1429     case EAXREVERB_REFLECTIONS:
1430         defer3<ReflectionsValidator>(call, props, props.lReflections);
1431         break;
1432
1433     case EAXREVERB_REFLECTIONSDELAY:
1434         defer3<ReflectionsDelayValidator>(call, props, props.flReflectionsDelay);
1435         break;
1436
1437     case EAXREVERB_REFLECTIONSPAN:
1438         defer3<VectorValidator>(call, props, props.vReflectionsPan);
1439         break;
1440
1441     case EAXREVERB_REVERB:
1442         defer3<ReverbValidator>(call, props, props.lReverb);
1443         break;
1444
1445     case EAXREVERB_REVERBDELAY:
1446         defer3<ReverbDelayValidator>(call, props, props.flReverbDelay);
1447         break;
1448
1449     case EAXREVERB_REVERBPAN:
1450         defer3<VectorValidator>(call, props, props.vReverbPan);
1451         break;
1452
1453     case EAXREVERB_ECHOTIME:
1454         defer3<EchoTimeValidator>(call, props, props.flEchoTime);
1455         break;
1456
1457     case EAXREVERB_ECHODEPTH:
1458         defer3<EchoDepthValidator>(call, props, props.flEchoDepth);
1459         break;
1460
1461     case EAXREVERB_MODULATIONTIME:
1462         defer3<ModulationTimeValidator>(call, props, props.flModulationTime);
1463         break;
1464
1465     case EAXREVERB_MODULATIONDEPTH:
1466         defer3<ModulationDepthValidator>(call, props, props.flModulationDepth);
1467         break;
1468
1469     case EAXREVERB_AIRABSORPTIONHF:
1470         defer3<AirAbsorptionHFValidator>(call, props, props.flAirAbsorptionHF);
1471         break;
1472
1473     case EAXREVERB_HFREFERENCE:
1474         defer3<HFReferenceValidator>(call, props, props.flHFReference);
1475         break;
1476
1477     case EAXREVERB_LFREFERENCE:
1478         defer3<LFReferenceValidator>(call, props, props.flLFReference);
1479         break;
1480
1481     case EAXREVERB_ROOMROLLOFFFACTOR:
1482         defer3<RoomRolloffFactorValidator>(call, props, props.flRoomRolloffFactor);
1483         break;
1484
1485     case EAXREVERB_FLAGS:
1486         defer3<FlagsValidator3>(call, props, props.ulFlags);
1487         break;
1488
1489     default:
1490         fail_unknown_property_id();
1491     }
1492 }
1493
1494 void EaxReverbCommitter::Set(const EaxCall &call, EaxEffectProps &props)
1495 {
1496     Set(call, props.mReverb);
1497 }
1498
1499 #endif // ALSOFT_EAX