view OpenAL32/alEffect.c @ 12:9558b856ebdf

Added tag hardcoded_but_working for changeset 17ace5a879b2
author Robert McIntyre <rlm@mit.edu>
date Mon, 31 Oct 2011 03:33:37 -0700
parents f9476ff7637e
children
line wrap: on
line source
1 /**
2 * OpenAL cross platform audio library
3 * Copyright (C) 1999-2007 by authors.
4 * This library is free software; you can redistribute it and/or
5 * modify it under the terms of the GNU Library General Public
6 * License as published by the Free Software Foundation; either
7 * version 2 of the License, or (at your option) any later version.
8 *
9 * This library is distributed in the hope that it will be useful,
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
12 * Library General Public License for more details.
13 *
14 * You should have received a copy of the GNU Library General Public
15 * License along with this library; if not, write to the
16 * Free Software Foundation, Inc., 59 Temple Place - Suite 330,
17 * Boston, MA 02111-1307, USA.
18 * Or go to http://www.gnu.org/copyleft/lgpl.html
19 */
21 #include "config.h"
23 #include <stdlib.h>
24 #include <math.h>
26 #include "AL/al.h"
27 #include "AL/alc.h"
28 #include "alMain.h"
29 #include "alEffect.h"
30 #include "alThunk.h"
31 #include "alError.h"
34 ALboolean DisabledEffects[MAX_EFFECTS];
37 static void InitEffectParams(ALeffect *effect, ALenum type);
39 #define LookupEffect(m, k) ((ALeffect*)LookupUIntMapKey(&(m), (k)))
41 AL_API ALvoid AL_APIENTRY alGenEffects(ALsizei n, ALuint *effects)
42 {
43 ALCcontext *Context;
44 ALsizei i=0;
46 Context = GetLockedContext();
47 if(!Context) return;
49 if(n < 0 || IsBadWritePtr((void*)effects, n * sizeof(ALuint)))
50 alSetError(Context, AL_INVALID_VALUE);
51 else
52 {
53 ALCdevice *device = Context->Device;
54 ALenum err;
56 while(i < n)
57 {
58 ALeffect *effect = calloc(1, sizeof(ALeffect));
59 if(!effect)
60 {
61 alSetError(Context, AL_OUT_OF_MEMORY);
62 alDeleteEffects(i, effects);
63 break;
64 }
66 err = NewThunkEntry(&effect->effect);
67 if(err == AL_NO_ERROR)
68 err = InsertUIntMapEntry(&device->EffectMap, effect->effect, effect);
69 if(err != AL_NO_ERROR)
70 {
71 FreeThunkEntry(effect->effect);
72 memset(effect, 0, sizeof(ALeffect));
73 free(effect);
75 alSetError(Context, err);
76 alDeleteEffects(i, effects);
77 break;
78 }
80 effects[i++] = effect->effect;
81 InitEffectParams(effect, AL_EFFECT_NULL);
82 }
83 }
85 UnlockContext(Context);
86 }
88 AL_API ALvoid AL_APIENTRY alDeleteEffects(ALsizei n, ALuint *effects)
89 {
90 ALCcontext *Context;
91 ALCdevice *device;
92 ALeffect *ALEffect;
93 ALboolean Failed;
94 ALsizei i;
96 Context = GetLockedContext();
97 if(!Context) return;
99 Failed = AL_TRUE;
100 device = Context->Device;
101 if(n < 0)
102 alSetError(Context, AL_INVALID_VALUE);
103 else
104 {
105 Failed = AL_FALSE;
106 // Check that all effects are valid
107 for(i = 0;i < n;i++)
108 {
109 if(!effects[i])
110 continue;
112 if(LookupEffect(device->EffectMap, effects[i]) == NULL)
113 {
114 alSetError(Context, AL_INVALID_NAME);
115 Failed = AL_TRUE;
116 break;
117 }
118 }
119 }
121 if(!Failed)
122 {
123 // All effects are valid
124 for(i = 0;i < n;i++)
125 {
126 // Recheck that the effect is valid, because there could be duplicated names
127 if((ALEffect=LookupEffect(device->EffectMap, effects[i])) == NULL)
128 continue;
130 RemoveUIntMapKey(&device->EffectMap, ALEffect->effect);
131 FreeThunkEntry(ALEffect->effect);
133 memset(ALEffect, 0, sizeof(ALeffect));
134 free(ALEffect);
135 }
136 }
138 UnlockContext(Context);
139 }
141 AL_API ALboolean AL_APIENTRY alIsEffect(ALuint effect)
142 {
143 ALCcontext *Context;
144 ALboolean result;
146 Context = GetLockedContext();
147 if(!Context) return AL_FALSE;
149 result = ((!effect || LookupEffect(Context->Device->EffectMap, effect)) ?
150 AL_TRUE : AL_FALSE);
152 UnlockContext(Context);
154 return result;
155 }
157 AL_API ALvoid AL_APIENTRY alEffecti(ALuint effect, ALenum param, ALint iValue)
158 {
159 ALCcontext *Context;
160 ALCdevice *Device;
161 ALeffect *ALEffect;
163 Context = GetLockedContext();
164 if(!Context) return;
166 Device = Context->Device;
167 if((ALEffect=LookupEffect(Device->EffectMap, effect)) != NULL)
168 {
169 if(param == AL_EFFECT_TYPE)
170 {
171 ALboolean isOk = (iValue == AL_EFFECT_NULL);
172 ALint i;
173 for(i = 0;!isOk && EffectList[i].val;i++)
174 {
175 if(iValue == EffectList[i].val &&
176 !DisabledEffects[EffectList[i].type])
177 isOk = AL_TRUE;
178 }
180 if(isOk)
181 InitEffectParams(ALEffect, iValue);
182 else
183 alSetError(Context, AL_INVALID_VALUE);
184 }
185 else if(ALEffect->type == AL_EFFECT_EAXREVERB)
186 {
187 switch(param)
188 {
189 case AL_EAXREVERB_DECAY_HFLIMIT:
190 if(iValue >= AL_EAXREVERB_MIN_DECAY_HFLIMIT &&
191 iValue <= AL_EAXREVERB_MAX_DECAY_HFLIMIT)
192 ALEffect->Params.Reverb.DecayHFLimit = iValue;
193 else
194 alSetError(Context, AL_INVALID_VALUE);
195 break;
197 default:
198 alSetError(Context, AL_INVALID_ENUM);
199 break;
200 }
201 }
202 else if(ALEffect->type == AL_EFFECT_REVERB)
203 {
204 switch(param)
205 {
206 case AL_REVERB_DECAY_HFLIMIT:
207 if(iValue >= AL_REVERB_MIN_DECAY_HFLIMIT &&
208 iValue <= AL_REVERB_MAX_DECAY_HFLIMIT)
209 ALEffect->Params.Reverb.DecayHFLimit = iValue;
210 else
211 alSetError(Context, AL_INVALID_VALUE);
212 break;
214 default:
215 alSetError(Context, AL_INVALID_ENUM);
216 break;
217 }
218 }
219 else if(ALEffect->type == AL_EFFECT_ECHO)
220 {
221 switch(param)
222 {
223 default:
224 alSetError(Context, AL_INVALID_ENUM);
225 break;
226 }
227 }
228 else if(ALEffect->type == AL_EFFECT_RING_MODULATOR)
229 {
230 switch(param)
231 {
232 case AL_RING_MODULATOR_FREQUENCY:
233 if(iValue >= AL_RING_MODULATOR_MIN_FREQUENCY &&
234 iValue <= AL_RING_MODULATOR_MAX_FREQUENCY)
235 ALEffect->Params.Modulator.Frequency = iValue;
236 else
237 alSetError(Context, AL_INVALID_VALUE);
238 break;
240 case AL_RING_MODULATOR_HIGHPASS_CUTOFF:
241 if(iValue >= AL_RING_MODULATOR_MIN_HIGHPASS_CUTOFF &&
242 iValue <= AL_RING_MODULATOR_MAX_HIGHPASS_CUTOFF)
243 ALEffect->Params.Modulator.HighPassCutoff = iValue;
244 else
245 alSetError(Context, AL_INVALID_VALUE);
246 break;
248 case AL_RING_MODULATOR_WAVEFORM:
249 if(iValue >= AL_RING_MODULATOR_MIN_WAVEFORM &&
250 iValue <= AL_RING_MODULATOR_MAX_WAVEFORM)
251 ALEffect->Params.Modulator.Waveform = iValue;
252 else
253 alSetError(Context, AL_INVALID_VALUE);
254 break;
256 default:
257 alSetError(Context, AL_INVALID_ENUM);
258 break;
259 }
260 }
261 else
262 alSetError(Context, AL_INVALID_ENUM);
263 }
264 else
265 alSetError(Context, AL_INVALID_NAME);
267 UnlockContext(Context);
268 }
270 AL_API ALvoid AL_APIENTRY alEffectiv(ALuint effect, ALenum param, ALint *piValues)
271 {
272 /* There are no multi-value int effect parameters */
273 alEffecti(effect, param, piValues[0]);
274 }
276 AL_API ALvoid AL_APIENTRY alEffectf(ALuint effect, ALenum param, ALfloat flValue)
277 {
278 ALCcontext *Context;
279 ALCdevice *Device;
280 ALeffect *ALEffect;
282 Context = GetLockedContext();
283 if(!Context) return;
285 Device = Context->Device;
286 if((ALEffect=LookupEffect(Device->EffectMap, effect)) != NULL)
287 {
288 if(ALEffect->type == AL_EFFECT_EAXREVERB)
289 {
290 switch(param)
291 {
292 case AL_EAXREVERB_DENSITY:
293 if(flValue >= AL_EAXREVERB_MIN_DENSITY &&
294 flValue <= AL_EAXREVERB_MAX_DENSITY)
295 ALEffect->Params.Reverb.Density = flValue;
296 else
297 alSetError(Context, AL_INVALID_VALUE);
298 break;
300 case AL_EAXREVERB_DIFFUSION:
301 if(flValue >= AL_EAXREVERB_MIN_DIFFUSION &&
302 flValue <= AL_EAXREVERB_MAX_DIFFUSION)
303 ALEffect->Params.Reverb.Diffusion = flValue;
304 else
305 alSetError(Context, AL_INVALID_VALUE);
306 break;
308 case AL_EAXREVERB_GAIN:
309 if(flValue >= AL_EAXREVERB_MIN_GAIN &&
310 flValue <= AL_EAXREVERB_MAX_GAIN)
311 ALEffect->Params.Reverb.Gain = flValue;
312 else
313 alSetError(Context, AL_INVALID_VALUE);
314 break;
316 case AL_EAXREVERB_GAINHF:
317 if(flValue >= AL_EAXREVERB_MIN_GAINHF &&
318 flValue <= AL_EAXREVERB_MAX_GAINHF)
319 ALEffect->Params.Reverb.GainHF = flValue;
320 else
321 alSetError(Context, AL_INVALID_VALUE);
322 break;
324 case AL_EAXREVERB_GAINLF:
325 if(flValue >= AL_EAXREVERB_MIN_GAINLF &&
326 flValue <= AL_EAXREVERB_MAX_GAINLF)
327 ALEffect->Params.Reverb.GainLF = flValue;
328 else
329 alSetError(Context, AL_INVALID_VALUE);
330 break;
332 case AL_EAXREVERB_DECAY_TIME:
333 if(flValue >= AL_EAXREVERB_MIN_DECAY_TIME &&
334 flValue <= AL_EAXREVERB_MAX_DECAY_TIME)
335 ALEffect->Params.Reverb.DecayTime = flValue;
336 else
337 alSetError(Context, AL_INVALID_VALUE);
338 break;
340 case AL_EAXREVERB_DECAY_HFRATIO:
341 if(flValue >= AL_EAXREVERB_MIN_DECAY_HFRATIO &&
342 flValue <= AL_EAXREVERB_MAX_DECAY_HFRATIO)
343 ALEffect->Params.Reverb.DecayHFRatio = flValue;
344 else
345 alSetError(Context, AL_INVALID_VALUE);
346 break;
348 case AL_EAXREVERB_DECAY_LFRATIO:
349 if(flValue >= AL_EAXREVERB_MIN_DECAY_LFRATIO &&
350 flValue <= AL_EAXREVERB_MAX_DECAY_LFRATIO)
351 ALEffect->Params.Reverb.DecayLFRatio = flValue;
352 else
353 alSetError(Context, AL_INVALID_VALUE);
354 break;
356 case AL_EAXREVERB_REFLECTIONS_GAIN:
357 if(flValue >= AL_EAXREVERB_MIN_REFLECTIONS_GAIN &&
358 flValue <= AL_EAXREVERB_MAX_REFLECTIONS_GAIN)
359 ALEffect->Params.Reverb.ReflectionsGain = flValue;
360 else
361 alSetError(Context, AL_INVALID_VALUE);
362 break;
364 case AL_EAXREVERB_REFLECTIONS_DELAY:
365 if(flValue >= AL_EAXREVERB_MIN_REFLECTIONS_DELAY &&
366 flValue <= AL_EAXREVERB_MAX_REFLECTIONS_DELAY)
367 ALEffect->Params.Reverb.ReflectionsDelay = flValue;
368 else
369 alSetError(Context, AL_INVALID_VALUE);
370 break;
372 case AL_EAXREVERB_LATE_REVERB_GAIN:
373 if(flValue >= AL_EAXREVERB_MIN_LATE_REVERB_GAIN &&
374 flValue <= AL_EAXREVERB_MAX_LATE_REVERB_GAIN)
375 ALEffect->Params.Reverb.LateReverbGain = flValue;
376 else
377 alSetError(Context, AL_INVALID_VALUE);
378 break;
380 case AL_EAXREVERB_LATE_REVERB_DELAY:
381 if(flValue >= AL_EAXREVERB_MIN_LATE_REVERB_DELAY &&
382 flValue <= AL_EAXREVERB_MAX_LATE_REVERB_DELAY)
383 ALEffect->Params.Reverb.LateReverbDelay = flValue;
384 else
385 alSetError(Context, AL_INVALID_VALUE);
386 break;
388 case AL_EAXREVERB_AIR_ABSORPTION_GAINHF:
389 if(flValue >= AL_EAXREVERB_MIN_AIR_ABSORPTION_GAINHF &&
390 flValue <= AL_EAXREVERB_MAX_AIR_ABSORPTION_GAINHF)
391 ALEffect->Params.Reverb.AirAbsorptionGainHF = flValue;
392 else
393 alSetError(Context, AL_INVALID_VALUE);
394 break;
396 case AL_EAXREVERB_ECHO_TIME:
397 if(flValue >= AL_EAXREVERB_MIN_ECHO_TIME &&
398 flValue <= AL_EAXREVERB_MAX_ECHO_TIME)
399 ALEffect->Params.Reverb.EchoTime = flValue;
400 else
401 alSetError(Context, AL_INVALID_VALUE);
402 break;
404 case AL_EAXREVERB_ECHO_DEPTH:
405 if(flValue >= AL_EAXREVERB_MIN_ECHO_DEPTH &&
406 flValue <= AL_EAXREVERB_MAX_ECHO_DEPTH)
407 ALEffect->Params.Reverb.EchoDepth = flValue;
408 else
409 alSetError(Context, AL_INVALID_VALUE);
410 break;
412 case AL_EAXREVERB_MODULATION_TIME:
413 if(flValue >= AL_EAXREVERB_MIN_MODULATION_TIME &&
414 flValue <= AL_EAXREVERB_MAX_MODULATION_TIME)
415 ALEffect->Params.Reverb.ModulationTime = flValue;
416 else
417 alSetError(Context, AL_INVALID_VALUE);
418 break;
420 case AL_EAXREVERB_MODULATION_DEPTH:
421 if(flValue >= AL_EAXREVERB_MIN_MODULATION_DEPTH &&
422 flValue <= AL_EAXREVERB_MAX_MODULATION_DEPTH)
423 ALEffect->Params.Reverb.ModulationDepth = flValue;
424 else
425 alSetError(Context, AL_INVALID_VALUE);
426 break;
428 case AL_EAXREVERB_HFREFERENCE:
429 if(flValue >= AL_EAXREVERB_MIN_HFREFERENCE &&
430 flValue <= AL_EAXREVERB_MAX_HFREFERENCE)
431 ALEffect->Params.Reverb.HFReference = flValue;
432 else
433 alSetError(Context, AL_INVALID_VALUE);
434 break;
436 case AL_EAXREVERB_LFREFERENCE:
437 if(flValue >= AL_EAXREVERB_MIN_LFREFERENCE &&
438 flValue <= AL_EAXREVERB_MAX_LFREFERENCE)
439 ALEffect->Params.Reverb.LFReference = flValue;
440 else
441 alSetError(Context, AL_INVALID_VALUE);
442 break;
444 case AL_EAXREVERB_ROOM_ROLLOFF_FACTOR:
445 if(flValue >= 0.0f && flValue <= 10.0f)
446 ALEffect->Params.Reverb.RoomRolloffFactor = flValue;
447 else
448 alSetError(Context, AL_INVALID_VALUE);
449 break;
451 default:
452 alSetError(Context, AL_INVALID_ENUM);
453 break;
454 }
455 }
456 else if(ALEffect->type == AL_EFFECT_REVERB)
457 {
458 switch(param)
459 {
460 case AL_REVERB_DENSITY:
461 if(flValue >= AL_REVERB_MIN_DENSITY &&
462 flValue <= AL_REVERB_MAX_DENSITY)
463 ALEffect->Params.Reverb.Density = flValue;
464 else
465 alSetError(Context, AL_INVALID_VALUE);
466 break;
468 case AL_REVERB_DIFFUSION:
469 if(flValue >= AL_REVERB_MIN_DIFFUSION &&
470 flValue <= AL_REVERB_MAX_DIFFUSION)
471 ALEffect->Params.Reverb.Diffusion = flValue;
472 else
473 alSetError(Context, AL_INVALID_VALUE);
474 break;
476 case AL_REVERB_GAIN:
477 if(flValue >= AL_REVERB_MIN_GAIN &&
478 flValue <= AL_REVERB_MAX_GAIN)
479 ALEffect->Params.Reverb.Gain = flValue;
480 else
481 alSetError(Context, AL_INVALID_VALUE);
482 break;
484 case AL_REVERB_GAINHF:
485 if(flValue >= AL_REVERB_MIN_GAINHF &&
486 flValue <= AL_REVERB_MAX_GAINHF)
487 ALEffect->Params.Reverb.GainHF = flValue;
488 else
489 alSetError(Context, AL_INVALID_VALUE);
490 break;
492 case AL_REVERB_DECAY_TIME:
493 if(flValue >= AL_REVERB_MIN_DECAY_TIME &&
494 flValue <= AL_REVERB_MAX_DECAY_TIME)
495 ALEffect->Params.Reverb.DecayTime = flValue;
496 else
497 alSetError(Context, AL_INVALID_VALUE);
498 break;
500 case AL_REVERB_DECAY_HFRATIO:
501 if(flValue >= AL_REVERB_MIN_DECAY_HFRATIO &&
502 flValue <= AL_REVERB_MAX_DECAY_HFRATIO)
503 ALEffect->Params.Reverb.DecayHFRatio = flValue;
504 else
505 alSetError(Context, AL_INVALID_VALUE);
506 break;
508 case AL_REVERB_REFLECTIONS_GAIN:
509 if(flValue >= AL_REVERB_MIN_REFLECTIONS_GAIN &&
510 flValue <= AL_REVERB_MAX_REFLECTIONS_GAIN)
511 ALEffect->Params.Reverb.ReflectionsGain = flValue;
512 else
513 alSetError(Context, AL_INVALID_VALUE);
514 break;
516 case AL_REVERB_REFLECTIONS_DELAY:
517 if(flValue >= AL_REVERB_MIN_REFLECTIONS_DELAY &&
518 flValue <= AL_REVERB_MAX_REFLECTIONS_DELAY)
519 ALEffect->Params.Reverb.ReflectionsDelay = flValue;
520 else
521 alSetError(Context, AL_INVALID_VALUE);
522 break;
524 case AL_REVERB_LATE_REVERB_GAIN:
525 if(flValue >= AL_REVERB_MIN_LATE_REVERB_GAIN &&
526 flValue <= AL_REVERB_MAX_LATE_REVERB_GAIN)
527 ALEffect->Params.Reverb.LateReverbGain = flValue;
528 else
529 alSetError(Context, AL_INVALID_VALUE);
530 break;
532 case AL_REVERB_LATE_REVERB_DELAY:
533 if(flValue >= AL_REVERB_MIN_LATE_REVERB_DELAY &&
534 flValue <= AL_REVERB_MAX_LATE_REVERB_DELAY)
535 ALEffect->Params.Reverb.LateReverbDelay = flValue;
536 else
537 alSetError(Context, AL_INVALID_VALUE);
538 break;
540 case AL_REVERB_AIR_ABSORPTION_GAINHF:
541 if(flValue >= AL_REVERB_MIN_AIR_ABSORPTION_GAINHF &&
542 flValue <= AL_REVERB_MAX_AIR_ABSORPTION_GAINHF)
543 ALEffect->Params.Reverb.AirAbsorptionGainHF = flValue;
544 else
545 alSetError(Context, AL_INVALID_VALUE);
546 break;
548 case AL_REVERB_ROOM_ROLLOFF_FACTOR:
549 if(flValue >= AL_REVERB_MIN_ROOM_ROLLOFF_FACTOR &&
550 flValue <= AL_REVERB_MAX_ROOM_ROLLOFF_FACTOR)
551 ALEffect->Params.Reverb.RoomRolloffFactor = flValue;
552 else
553 alSetError(Context, AL_INVALID_VALUE);
554 break;
556 default:
557 alSetError(Context, AL_INVALID_ENUM);
558 break;
559 }
560 }
561 else if(ALEffect->type == AL_EFFECT_ECHO)
562 {
563 switch(param)
564 {
565 case AL_ECHO_DELAY:
566 if(flValue >= AL_ECHO_MIN_DELAY && flValue <= AL_ECHO_MAX_DELAY)
567 ALEffect->Params.Echo.Delay = flValue;
568 else
569 alSetError(Context, AL_INVALID_VALUE);
570 break;
572 case AL_ECHO_LRDELAY:
573 if(flValue >= AL_ECHO_MIN_LRDELAY && flValue <= AL_ECHO_MAX_LRDELAY)
574 ALEffect->Params.Echo.LRDelay = flValue;
575 else
576 alSetError(Context, AL_INVALID_VALUE);
577 break;
579 case AL_ECHO_DAMPING:
580 if(flValue >= AL_ECHO_MIN_DAMPING && flValue <= AL_ECHO_MAX_DAMPING)
581 ALEffect->Params.Echo.Damping = flValue;
582 else
583 alSetError(Context, AL_INVALID_VALUE);
584 break;
586 case AL_ECHO_FEEDBACK:
587 if(flValue >= AL_ECHO_MIN_FEEDBACK && flValue <= AL_ECHO_MAX_FEEDBACK)
588 ALEffect->Params.Echo.Feedback = flValue;
589 else
590 alSetError(Context, AL_INVALID_VALUE);
591 break;
593 case AL_ECHO_SPREAD:
594 if(flValue >= AL_ECHO_MIN_SPREAD && flValue <= AL_ECHO_MAX_SPREAD)
595 ALEffect->Params.Echo.Spread = flValue;
596 else
597 alSetError(Context, AL_INVALID_VALUE);
598 break;
600 default:
601 alSetError(Context, AL_INVALID_ENUM);
602 break;
603 }
604 }
605 else if(ALEffect->type == AL_EFFECT_RING_MODULATOR)
606 {
607 switch(param)
608 {
609 case AL_RING_MODULATOR_FREQUENCY:
610 if(flValue >= AL_RING_MODULATOR_MIN_FREQUENCY &&
611 flValue <= AL_RING_MODULATOR_MAX_FREQUENCY)
612 ALEffect->Params.Modulator.Frequency = flValue;
613 else
614 alSetError(Context, AL_INVALID_VALUE);
615 break;
617 case AL_RING_MODULATOR_HIGHPASS_CUTOFF:
618 if(flValue >= AL_RING_MODULATOR_MIN_HIGHPASS_CUTOFF &&
619 flValue <= AL_RING_MODULATOR_MAX_HIGHPASS_CUTOFF)
620 ALEffect->Params.Modulator.HighPassCutoff = flValue;
621 else
622 alSetError(Context, AL_INVALID_VALUE);
623 break;
625 default:
626 alSetError(Context, AL_INVALID_ENUM);
627 break;
628 }
629 }
630 else if(ALEffect->type == AL_EFFECT_DEDICATED_LOW_FREQUENCY_EFFECT ||
631 ALEffect->type == AL_EFFECT_DEDICATED_DIALOGUE)
632 {
633 switch(param)
634 {
635 case AL_DEDICATED_GAIN:
636 if(flValue >= 0.0f && isfinite(flValue))
637 ALEffect->Params.Dedicated.Gain = flValue;
638 else
639 alSetError(Context, AL_INVALID_VALUE);
640 break;
642 default:
643 alSetError(Context, AL_INVALID_ENUM);
644 break;
645 }
646 }
647 else
648 alSetError(Context, AL_INVALID_ENUM);
649 }
650 else
651 alSetError(Context, AL_INVALID_NAME);
653 UnlockContext(Context);
654 }
656 AL_API ALvoid AL_APIENTRY alEffectfv(ALuint effect, ALenum param, ALfloat *pflValues)
657 {
658 ALCcontext *Context;
659 ALCdevice *Device;
660 ALeffect *ALEffect;
662 Context = GetLockedContext();
663 if(!Context) return;
665 Device = Context->Device;
666 if((ALEffect=LookupEffect(Device->EffectMap, effect)) != NULL)
667 {
668 if(ALEffect->type == AL_EFFECT_EAXREVERB)
669 {
670 switch(param)
671 {
672 case AL_EAXREVERB_REFLECTIONS_PAN:
673 if(isfinite(pflValues[0]) && isfinite(pflValues[1]) && isfinite(pflValues[2]))
674 {
675 ALEffect->Params.Reverb.ReflectionsPan[0] = pflValues[0];
676 ALEffect->Params.Reverb.ReflectionsPan[1] = pflValues[1];
677 ALEffect->Params.Reverb.ReflectionsPan[2] = pflValues[2];
678 }
679 else
680 alSetError(Context, AL_INVALID_VALUE);
681 break;
682 case AL_EAXREVERB_LATE_REVERB_PAN:
683 if(isfinite(pflValues[0]) && isfinite(pflValues[1]) && isfinite(pflValues[2]))
684 {
685 ALEffect->Params.Reverb.LateReverbPan[0] = pflValues[0];
686 ALEffect->Params.Reverb.LateReverbPan[1] = pflValues[1];
687 ALEffect->Params.Reverb.LateReverbPan[2] = pflValues[2];
688 }
689 else
690 alSetError(Context, AL_INVALID_VALUE);
691 break;
693 default:
694 UnlockContext(Context);
695 alEffectf(effect, param, pflValues[0]);
696 return;
697 }
698 }
699 else
700 {
701 UnlockContext(Context);
702 alEffectf(effect, param, pflValues[0]);
703 return;
704 }
705 }
706 else
707 alSetError(Context, AL_INVALID_NAME);
709 UnlockContext(Context);
710 }
712 AL_API ALvoid AL_APIENTRY alGetEffecti(ALuint effect, ALenum param, ALint *piValue)
713 {
714 ALCcontext *Context;
715 ALCdevice *Device;
716 ALeffect *ALEffect;
718 Context = GetLockedContext();
719 if(!Context) return;
721 Device = Context->Device;
722 if((ALEffect=LookupEffect(Device->EffectMap, effect)) != NULL)
723 {
724 if(param == AL_EFFECT_TYPE)
725 {
726 *piValue = ALEffect->type;
727 }
728 else if(ALEffect->type == AL_EFFECT_EAXREVERB)
729 {
730 switch(param)
731 {
732 case AL_EAXREVERB_DECAY_HFLIMIT:
733 *piValue = ALEffect->Params.Reverb.DecayHFLimit;
734 break;
736 default:
737 alSetError(Context, AL_INVALID_ENUM);
738 break;
739 }
740 }
741 else if(ALEffect->type == AL_EFFECT_REVERB)
742 {
743 switch(param)
744 {
745 case AL_REVERB_DECAY_HFLIMIT:
746 *piValue = ALEffect->Params.Reverb.DecayHFLimit;
747 break;
749 default:
750 alSetError(Context, AL_INVALID_ENUM);
751 break;
752 }
753 }
754 else if(ALEffect->type == AL_EFFECT_ECHO)
755 {
756 switch(param)
757 {
758 default:
759 alSetError(Context, AL_INVALID_ENUM);
760 break;
761 }
762 }
763 else if(ALEffect->type == AL_EFFECT_RING_MODULATOR)
764 {
765 switch(param)
766 {
767 case AL_RING_MODULATOR_FREQUENCY:
768 *piValue = (ALint)ALEffect->Params.Modulator.Frequency;
769 break;
770 case AL_RING_MODULATOR_HIGHPASS_CUTOFF:
771 *piValue = (ALint)ALEffect->Params.Modulator.HighPassCutoff;
772 break;
773 case AL_RING_MODULATOR_WAVEFORM:
774 *piValue = ALEffect->Params.Modulator.Waveform;
775 break;
777 default:
778 alSetError(Context, AL_INVALID_ENUM);
779 break;
780 }
781 }
782 else
783 alSetError(Context, AL_INVALID_ENUM);
784 }
785 else
786 alSetError(Context, AL_INVALID_NAME);
788 UnlockContext(Context);
789 }
791 AL_API ALvoid AL_APIENTRY alGetEffectiv(ALuint effect, ALenum param, ALint *piValues)
792 {
793 /* There are no multi-value int effect parameters */
794 alGetEffecti(effect, param, piValues);
795 }
797 AL_API ALvoid AL_APIENTRY alGetEffectf(ALuint effect, ALenum param, ALfloat *pflValue)
798 {
799 ALCcontext *Context;
800 ALCdevice *Device;
801 ALeffect *ALEffect;
803 Context = GetLockedContext();
804 if(!Context) return;
806 Device = Context->Device;
807 if((ALEffect=LookupEffect(Device->EffectMap, effect)) != NULL)
808 {
809 if(ALEffect->type == AL_EFFECT_EAXREVERB)
810 {
811 switch(param)
812 {
813 case AL_EAXREVERB_DENSITY:
814 *pflValue = ALEffect->Params.Reverb.Density;
815 break;
817 case AL_EAXREVERB_DIFFUSION:
818 *pflValue = ALEffect->Params.Reverb.Diffusion;
819 break;
821 case AL_EAXREVERB_GAIN:
822 *pflValue = ALEffect->Params.Reverb.Gain;
823 break;
825 case AL_EAXREVERB_GAINHF:
826 *pflValue = ALEffect->Params.Reverb.GainHF;
827 break;
829 case AL_EAXREVERB_GAINLF:
830 *pflValue = ALEffect->Params.Reverb.GainLF;
831 break;
833 case AL_EAXREVERB_DECAY_TIME:
834 *pflValue = ALEffect->Params.Reverb.DecayTime;
835 break;
837 case AL_EAXREVERB_DECAY_HFRATIO:
838 *pflValue = ALEffect->Params.Reverb.DecayHFRatio;
839 break;
841 case AL_EAXREVERB_DECAY_LFRATIO:
842 *pflValue = ALEffect->Params.Reverb.DecayLFRatio;
843 break;
845 case AL_EAXREVERB_REFLECTIONS_GAIN:
846 *pflValue = ALEffect->Params.Reverb.ReflectionsGain;
847 break;
849 case AL_EAXREVERB_REFLECTIONS_DELAY:
850 *pflValue = ALEffect->Params.Reverb.ReflectionsDelay;
851 break;
853 case AL_EAXREVERB_LATE_REVERB_GAIN:
854 *pflValue = ALEffect->Params.Reverb.LateReverbGain;
855 break;
857 case AL_EAXREVERB_LATE_REVERB_DELAY:
858 *pflValue = ALEffect->Params.Reverb.LateReverbDelay;
859 break;
861 case AL_EAXREVERB_AIR_ABSORPTION_GAINHF:
862 *pflValue = ALEffect->Params.Reverb.AirAbsorptionGainHF;
863 break;
865 case AL_EAXREVERB_ECHO_TIME:
866 *pflValue = ALEffect->Params.Reverb.EchoTime;
867 break;
869 case AL_EAXREVERB_ECHO_DEPTH:
870 *pflValue = ALEffect->Params.Reverb.EchoDepth;
871 break;
873 case AL_EAXREVERB_MODULATION_TIME:
874 *pflValue = ALEffect->Params.Reverb.ModulationTime;
875 break;
877 case AL_EAXREVERB_MODULATION_DEPTH:
878 *pflValue = ALEffect->Params.Reverb.ModulationDepth;
879 break;
881 case AL_EAXREVERB_HFREFERENCE:
882 *pflValue = ALEffect->Params.Reverb.HFReference;
883 break;
885 case AL_EAXREVERB_LFREFERENCE:
886 *pflValue = ALEffect->Params.Reverb.LFReference;
887 break;
889 case AL_EAXREVERB_ROOM_ROLLOFF_FACTOR:
890 *pflValue = ALEffect->Params.Reverb.RoomRolloffFactor;
891 break;
893 default:
894 alSetError(Context, AL_INVALID_ENUM);
895 break;
896 }
897 }
898 else if(ALEffect->type == AL_EFFECT_REVERB)
899 {
900 switch(param)
901 {
902 case AL_REVERB_DENSITY:
903 *pflValue = ALEffect->Params.Reverb.Density;
904 break;
906 case AL_REVERB_DIFFUSION:
907 *pflValue = ALEffect->Params.Reverb.Diffusion;
908 break;
910 case AL_REVERB_GAIN:
911 *pflValue = ALEffect->Params.Reverb.Gain;
912 break;
914 case AL_REVERB_GAINHF:
915 *pflValue = ALEffect->Params.Reverb.GainHF;
916 break;
918 case AL_REVERB_DECAY_TIME:
919 *pflValue = ALEffect->Params.Reverb.DecayTime;
920 break;
922 case AL_REVERB_DECAY_HFRATIO:
923 *pflValue = ALEffect->Params.Reverb.DecayHFRatio;
924 break;
926 case AL_REVERB_REFLECTIONS_GAIN:
927 *pflValue = ALEffect->Params.Reverb.ReflectionsGain;
928 break;
930 case AL_REVERB_REFLECTIONS_DELAY:
931 *pflValue = ALEffect->Params.Reverb.ReflectionsDelay;
932 break;
934 case AL_REVERB_LATE_REVERB_GAIN:
935 *pflValue = ALEffect->Params.Reverb.LateReverbGain;
936 break;
938 case AL_REVERB_LATE_REVERB_DELAY:
939 *pflValue = ALEffect->Params.Reverb.LateReverbDelay;
940 break;
942 case AL_REVERB_AIR_ABSORPTION_GAINHF:
943 *pflValue = ALEffect->Params.Reverb.AirAbsorptionGainHF;
944 break;
946 case AL_REVERB_ROOM_ROLLOFF_FACTOR:
947 *pflValue = ALEffect->Params.Reverb.RoomRolloffFactor;
948 break;
950 default:
951 alSetError(Context, AL_INVALID_ENUM);
952 break;
953 }
954 }
955 else if(ALEffect->type == AL_EFFECT_ECHO)
956 {
957 switch(param)
958 {
959 case AL_ECHO_DELAY:
960 *pflValue = ALEffect->Params.Echo.Delay;
961 break;
963 case AL_ECHO_LRDELAY:
964 *pflValue = ALEffect->Params.Echo.LRDelay;
965 break;
967 case AL_ECHO_DAMPING:
968 *pflValue = ALEffect->Params.Echo.Damping;
969 break;
971 case AL_ECHO_FEEDBACK:
972 *pflValue = ALEffect->Params.Echo.Feedback;
973 break;
975 case AL_ECHO_SPREAD:
976 *pflValue = ALEffect->Params.Echo.Spread;
977 break;
979 default:
980 alSetError(Context, AL_INVALID_ENUM);
981 break;
982 }
983 }
984 else if(ALEffect->type == AL_EFFECT_RING_MODULATOR)
985 {
986 switch(param)
987 {
988 case AL_RING_MODULATOR_FREQUENCY:
989 *pflValue = ALEffect->Params.Modulator.Frequency;
990 break;
991 case AL_RING_MODULATOR_HIGHPASS_CUTOFF:
992 *pflValue = ALEffect->Params.Modulator.HighPassCutoff;
993 break;
995 default:
996 alSetError(Context, AL_INVALID_ENUM);
997 break;
998 }
999 }
1000 else if(ALEffect->type == AL_EFFECT_DEDICATED_LOW_FREQUENCY_EFFECT ||
1001 ALEffect->type == AL_EFFECT_DEDICATED_DIALOGUE)
1003 switch(param)
1005 case AL_DEDICATED_GAIN:
1006 *pflValue = ALEffect->Params.Dedicated.Gain;
1007 break;
1009 default:
1010 alSetError(Context, AL_INVALID_ENUM);
1011 break;
1014 else
1015 alSetError(Context, AL_INVALID_ENUM);
1017 else
1018 alSetError(Context, AL_INVALID_NAME);
1020 UnlockContext(Context);
1023 AL_API ALvoid AL_APIENTRY alGetEffectfv(ALuint effect, ALenum param, ALfloat *pflValues)
1025 ALCcontext *Context;
1026 ALCdevice *Device;
1027 ALeffect *ALEffect;
1029 Context = GetLockedContext();
1030 if(!Context) return;
1032 Device = Context->Device;
1033 if((ALEffect=LookupEffect(Device->EffectMap, effect)) != NULL)
1035 if(ALEffect->type == AL_EFFECT_EAXREVERB)
1037 switch(param)
1039 case AL_EAXREVERB_REFLECTIONS_PAN:
1040 pflValues[0] = ALEffect->Params.Reverb.ReflectionsPan[0];
1041 pflValues[1] = ALEffect->Params.Reverb.ReflectionsPan[1];
1042 pflValues[2] = ALEffect->Params.Reverb.ReflectionsPan[2];
1043 break;
1044 case AL_EAXREVERB_LATE_REVERB_PAN:
1045 pflValues[0] = ALEffect->Params.Reverb.LateReverbPan[0];
1046 pflValues[1] = ALEffect->Params.Reverb.LateReverbPan[1];
1047 pflValues[2] = ALEffect->Params.Reverb.LateReverbPan[2];
1048 break;
1050 default:
1051 UnlockContext(Context);
1052 alGetEffectf(effect, param, pflValues);
1053 return;
1056 else
1058 UnlockContext(Context);
1059 alGetEffectf(effect, param, pflValues);
1060 return;
1063 else
1064 alSetError(Context, AL_INVALID_NAME);
1066 UnlockContext(Context);
1070 ALvoid ReleaseALEffects(ALCdevice *device)
1072 ALsizei i;
1073 for(i = 0;i < device->EffectMap.size;i++)
1075 ALeffect *temp = device->EffectMap.array[i].value;
1076 device->EffectMap.array[i].value = NULL;
1078 // Release effect structure
1079 FreeThunkEntry(temp->effect);
1080 memset(temp, 0, sizeof(ALeffect));
1081 free(temp);
1086 static void InitEffectParams(ALeffect *effect, ALenum type)
1088 effect->type = type;
1089 switch(type)
1091 /* NOTE: Standard reverb and EAX reverb use the same defaults for the
1092 * shared parameters, and EAX's additional parameters default to
1093 * values assumed by standard reverb.
1094 */
1095 case AL_EFFECT_EAXREVERB:
1096 case AL_EFFECT_REVERB:
1097 effect->Params.Reverb.Density = AL_EAXREVERB_DEFAULT_DENSITY;
1098 effect->Params.Reverb.Diffusion = AL_EAXREVERB_DEFAULT_DIFFUSION;
1099 effect->Params.Reverb.Gain = AL_EAXREVERB_DEFAULT_GAIN;
1100 effect->Params.Reverb.GainHF = AL_EAXREVERB_DEFAULT_GAINHF;
1101 effect->Params.Reverb.GainLF = AL_EAXREVERB_DEFAULT_GAINLF;
1102 effect->Params.Reverb.DecayTime = AL_EAXREVERB_DEFAULT_DECAY_TIME;
1103 effect->Params.Reverb.DecayHFRatio = AL_EAXREVERB_DEFAULT_DECAY_HFRATIO;
1104 effect->Params.Reverb.DecayLFRatio = AL_EAXREVERB_DEFAULT_DECAY_LFRATIO;
1105 effect->Params.Reverb.ReflectionsGain = AL_EAXREVERB_DEFAULT_REFLECTIONS_GAIN;
1106 effect->Params.Reverb.ReflectionsDelay = AL_EAXREVERB_DEFAULT_REFLECTIONS_DELAY;
1107 effect->Params.Reverb.ReflectionsPan[0] = AL_EAXREVERB_DEFAULT_REFLECTIONS_PAN_XYZ;
1108 effect->Params.Reverb.ReflectionsPan[1] = AL_EAXREVERB_DEFAULT_REFLECTIONS_PAN_XYZ;
1109 effect->Params.Reverb.ReflectionsPan[2] = AL_EAXREVERB_DEFAULT_REFLECTIONS_PAN_XYZ;
1110 effect->Params.Reverb.LateReverbGain = AL_EAXREVERB_DEFAULT_LATE_REVERB_GAIN;
1111 effect->Params.Reverb.LateReverbDelay = AL_EAXREVERB_DEFAULT_LATE_REVERB_DELAY;
1112 effect->Params.Reverb.LateReverbPan[0] = AL_EAXREVERB_DEFAULT_LATE_REVERB_PAN_XYZ;
1113 effect->Params.Reverb.LateReverbPan[1] = AL_EAXREVERB_DEFAULT_LATE_REVERB_PAN_XYZ;
1114 effect->Params.Reverb.LateReverbPan[2] = AL_EAXREVERB_DEFAULT_LATE_REVERB_PAN_XYZ;
1115 effect->Params.Reverb.EchoTime = AL_EAXREVERB_DEFAULT_ECHO_TIME;
1116 effect->Params.Reverb.EchoDepth = AL_EAXREVERB_DEFAULT_ECHO_DEPTH;
1117 effect->Params.Reverb.ModulationTime = AL_EAXREVERB_DEFAULT_MODULATION_TIME;
1118 effect->Params.Reverb.ModulationDepth = AL_EAXREVERB_DEFAULT_MODULATION_DEPTH;
1119 effect->Params.Reverb.AirAbsorptionGainHF = AL_EAXREVERB_DEFAULT_AIR_ABSORPTION_GAINHF;
1120 effect->Params.Reverb.HFReference = AL_EAXREVERB_DEFAULT_HFREFERENCE;
1121 effect->Params.Reverb.LFReference = AL_EAXREVERB_DEFAULT_LFREFERENCE;
1122 effect->Params.Reverb.RoomRolloffFactor = AL_EAXREVERB_DEFAULT_ROOM_ROLLOFF_FACTOR;
1123 effect->Params.Reverb.DecayHFLimit = AL_EAXREVERB_DEFAULT_DECAY_HFLIMIT;
1124 break;
1125 case AL_EFFECT_ECHO:
1126 effect->Params.Echo.Delay = AL_ECHO_DEFAULT_DELAY;
1127 effect->Params.Echo.LRDelay = AL_ECHO_DEFAULT_LRDELAY;
1128 effect->Params.Echo.Damping = AL_ECHO_DEFAULT_DAMPING;
1129 effect->Params.Echo.Feedback = AL_ECHO_DEFAULT_FEEDBACK;
1130 effect->Params.Echo.Spread = AL_ECHO_DEFAULT_SPREAD;
1131 break;
1132 case AL_EFFECT_RING_MODULATOR:
1133 effect->Params.Modulator.Frequency = AL_RING_MODULATOR_DEFAULT_FREQUENCY;
1134 effect->Params.Modulator.HighPassCutoff = AL_RING_MODULATOR_DEFAULT_HIGHPASS_CUTOFF;
1135 effect->Params.Modulator.Waveform = AL_RING_MODULATOR_DEFAULT_WAVEFORM;
1136 break;
1137 case AL_EFFECT_DEDICATED_LOW_FREQUENCY_EFFECT:
1138 case AL_EFFECT_DEDICATED_DIALOGUE:
1139 effect->Params.Dedicated.Gain = 1.0f;
1140 break;