Use the MIN/MAX/DEFAULT macros for checking and setting the effect parameters
[openal-soft/openal-hmr.git] / OpenAL32 / alEffect.c
blobfe5897c9b205ac4ce7d9e608521d88189d431b5a
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.
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.
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
21 #include "config.h"
23 #include <stdlib.h>
25 #include "AL/al.h"
26 #include "AL/alc.h"
27 #include "alMain.h"
28 #include "alEffect.h"
29 #include "alThunk.h"
30 #include "alError.h"
33 ALboolean DisabledEffects[MAX_EFFECTS];
36 static ALeffect *g_EffectList;
37 static ALuint g_EffectCount;
39 static void InitEffectParams(ALeffect *effect, ALenum type);
42 ALvoid AL_APIENTRY alGenEffects(ALsizei n, ALuint *effects)
44 ALCcontext *Context;
45 ALsizei i;
47 Context = alcGetCurrentContext();
48 SuspendContext(Context);
50 if (n > 0)
52 // Check that enough memory has been allocted in the 'effects' array for n Effects
53 if (!IsBadWritePtr((void*)effects, n * sizeof(ALuint)))
55 ALeffect **list = &g_EffectList;
56 while(*list)
57 list = &(*list)->next;
59 i = 0;
60 while(i < n)
62 *list = calloc(1, sizeof(ALeffect));
63 if(!(*list))
65 // We must have run out or memory
66 alDeleteEffects(i, effects);
67 alSetError(AL_OUT_OF_MEMORY);
68 break;
71 effects[i] = (ALuint)ALTHUNK_ADDENTRY(*list);
72 (*list)->effect = effects[i];
74 InitEffectParams(*list, AL_EFFECT_NULL);
75 g_EffectCount++;
76 i++;
78 list = &(*list)->next;
83 ProcessContext(Context);
86 ALvoid AL_APIENTRY alDeleteEffects(ALsizei n, ALuint *effects)
88 ALCcontext *Context;
89 ALeffect *ALEffect;
90 ALsizei i;
92 Context = alcGetCurrentContext();
93 SuspendContext(Context);
95 if (n >= 0)
97 // Check that all effects are valid
98 for (i = 0; i < n; i++)
100 if (!alIsEffect(effects[i]))
102 alSetError(AL_INVALID_NAME);
103 break;
107 if (i == n)
109 // All effects are valid
110 for (i = 0; i < n; i++)
112 // Recheck that the effect is valid, because there could be duplicated names
113 if (effects[i] && alIsEffect(effects[i]))
115 ALeffect **list;
117 ALEffect = ((ALeffect*)ALTHUNK_LOOKUPENTRY(effects[i]));
119 // Remove Source from list of Sources
120 list = &g_EffectList;
121 while(*list && *list != ALEffect)
122 list = &(*list)->next;
124 if(*list)
125 *list = (*list)->next;
126 ALTHUNK_REMOVEENTRY(ALEffect->effect);
128 memset(ALEffect, 0, sizeof(ALeffect));
129 free(ALEffect);
131 g_EffectCount--;
136 else
137 alSetError(AL_INVALID_VALUE);
139 ProcessContext(Context);
142 ALboolean AL_APIENTRY alIsEffect(ALuint effect)
144 ALCcontext *Context;
145 ALeffect **list;
147 Context = alcGetCurrentContext();
148 SuspendContext(Context);
150 list = &g_EffectList;
151 while(*list && (*list)->effect != effect)
152 list = &(*list)->next;
154 ProcessContext(Context);
156 return ((*list || !effect) ? AL_TRUE : AL_FALSE);
159 ALvoid AL_APIENTRY alEffecti(ALuint effect, ALenum param, ALint iValue)
161 ALCcontext *Context;
163 Context = alcGetCurrentContext();
164 SuspendContext(Context);
166 if (effect && alIsEffect(effect))
168 ALeffect *ALEffect = (ALeffect*)ALTHUNK_LOOKUPENTRY(effect);
170 if(param == AL_EFFECT_TYPE)
172 ALboolean isOk = (iValue == AL_EFFECT_NULL ||
173 (iValue == AL_EFFECT_EAXREVERB && !DisabledEffects[EAXREVERB]) ||
174 (iValue == AL_EFFECT_REVERB && !DisabledEffects[REVERB]) ||
175 (iValue == AL_EFFECT_ECHO && !DisabledEffects[ECHO]));
177 if(isOk)
178 InitEffectParams(ALEffect, iValue);
179 else
180 alSetError(AL_INVALID_VALUE);
182 else if(ALEffect->type == AL_EFFECT_EAXREVERB)
184 switch(param)
186 case AL_EAXREVERB_DECAY_HFLIMIT:
187 if(iValue >= AL_EAXREVERB_MIN_DECAY_HFLIMIT &&
188 iValue <= AL_EAXREVERB_MAX_DECAY_HFLIMIT)
189 ALEffect->Reverb.DecayHFLimit = iValue;
190 else
191 alSetError(AL_INVALID_VALUE);
192 break;
194 default:
195 alSetError(AL_INVALID_ENUM);
196 break;
199 else if(ALEffect->type == AL_EFFECT_REVERB)
201 switch(param)
203 case AL_REVERB_DECAY_HFLIMIT:
204 if(iValue >= AL_REVERB_MIN_DECAY_HFLIMIT &&
205 iValue <= AL_REVERB_MAX_DECAY_HFLIMIT)
206 ALEffect->Reverb.DecayHFLimit = iValue;
207 else
208 alSetError(AL_INVALID_VALUE);
209 break;
211 default:
212 alSetError(AL_INVALID_ENUM);
213 break;
216 else if(ALEffect->type == AL_EFFECT_ECHO)
218 switch(param)
220 default:
221 alSetError(AL_INVALID_ENUM);
222 break;
225 else
226 alSetError(AL_INVALID_ENUM);
228 else
229 alSetError(AL_INVALID_NAME);
231 ProcessContext(Context);
234 ALvoid AL_APIENTRY alEffectiv(ALuint effect, ALenum param, ALint *piValues)
236 ALCcontext *Context;
238 Context = alcGetCurrentContext();
239 SuspendContext(Context);
241 if (effect && alIsEffect(effect))
243 ALeffect *ALEffect = (ALeffect*)ALTHUNK_LOOKUPENTRY(effect);
245 if(param == AL_EFFECT_TYPE)
247 alEffecti(effect, param, piValues[0]);
249 else if(ALEffect->type == AL_EFFECT_EAXREVERB)
251 switch(param)
253 case AL_EAXREVERB_DECAY_HFLIMIT:
254 alEffecti(effect, param, piValues[0]);
255 break;
257 default:
258 alSetError(AL_INVALID_ENUM);
259 break;
262 else if(ALEffect->type == AL_EFFECT_REVERB)
264 switch(param)
266 case AL_REVERB_DECAY_HFLIMIT:
267 alEffecti(effect, param, piValues[0]);
268 break;
270 default:
271 alSetError(AL_INVALID_ENUM);
272 break;
275 else if(ALEffect->type == AL_EFFECT_ECHO)
277 switch(param)
279 default:
280 alSetError(AL_INVALID_ENUM);
281 break;
284 else
285 alSetError(AL_INVALID_ENUM);
287 else
288 alSetError(AL_INVALID_NAME);
290 ProcessContext(Context);
293 ALvoid AL_APIENTRY alEffectf(ALuint effect, ALenum param, ALfloat flValue)
295 ALCcontext *Context;
297 Context = alcGetCurrentContext();
298 SuspendContext(Context);
300 if (effect && alIsEffect(effect))
302 ALeffect *ALEffect = (ALeffect*)ALTHUNK_LOOKUPENTRY(effect);
304 if(ALEffect->type == AL_EFFECT_EAXREVERB)
306 switch(param)
308 case AL_EAXREVERB_DENSITY:
309 if(flValue >= AL_EAXREVERB_MIN_DENSITY &&
310 flValue <= AL_EAXREVERB_MAX_DENSITY)
311 ALEffect->Reverb.Density = flValue;
312 else
313 alSetError(AL_INVALID_VALUE);
314 break;
316 case AL_EAXREVERB_DIFFUSION:
317 if(flValue >= AL_EAXREVERB_MIN_DIFFUSION &&
318 flValue <= AL_EAXREVERB_MAX_DIFFUSION)
319 ALEffect->Reverb.Diffusion = flValue;
320 else
321 alSetError(AL_INVALID_VALUE);
322 break;
324 case AL_EAXREVERB_GAIN:
325 if(flValue >= AL_EAXREVERB_MIN_GAIN &&
326 flValue <= AL_EAXREVERB_MAX_GAIN)
327 ALEffect->Reverb.Gain = flValue;
328 else
329 alSetError(AL_INVALID_VALUE);
330 break;
332 case AL_EAXREVERB_GAINHF:
333 if(flValue >= AL_EAXREVERB_MIN_GAINHF &&
334 flValue <= AL_EAXREVERB_MAX_GAIN)
335 ALEffect->Reverb.GainHF = flValue;
336 else
337 alSetError(AL_INVALID_VALUE);
338 break;
340 case AL_EAXREVERB_GAINLF:
341 if(flValue >= AL_EAXREVERB_MIN_GAINLF &&
342 flValue <= AL_EAXREVERB_MAX_GAINLF)
343 ALEffect->Reverb.GainLF = flValue;
344 else
345 alSetError(AL_INVALID_VALUE);
346 break;
348 case AL_EAXREVERB_DECAY_TIME:
349 if(flValue >= AL_EAXREVERB_MIN_DECAY_TIME &&
350 flValue <= AL_EAXREVERB_MAX_DECAY_TIME)
351 ALEffect->Reverb.DecayTime = flValue;
352 else
353 alSetError(AL_INVALID_VALUE);
354 break;
356 case AL_EAXREVERB_DECAY_HFRATIO:
357 if(flValue >= AL_EAXREVERB_MIN_DECAY_HFRATIO &&
358 flValue <= AL_EAXREVERB_MAX_DECAY_HFRATIO)
359 ALEffect->Reverb.DecayHFRatio = flValue;
360 else
361 alSetError(AL_INVALID_VALUE);
362 break;
364 case AL_EAXREVERB_DECAY_LFRATIO:
365 if(flValue >= AL_EAXREVERB_MIN_DECAY_LFRATIO &&
366 flValue <= AL_EAXREVERB_MAX_DECAY_LFRATIO)
367 ALEffect->Reverb.DecayLFRatio = flValue;
368 else
369 alSetError(AL_INVALID_VALUE);
370 break;
372 case AL_EAXREVERB_REFLECTIONS_GAIN:
373 if(flValue >= AL_EAXREVERB_MIN_REFLECTIONS_GAIN &&
374 flValue <= AL_EAXREVERB_MAX_REFLECTIONS_GAIN)
375 ALEffect->Reverb.ReflectionsGain = flValue;
376 else
377 alSetError(AL_INVALID_VALUE);
378 break;
380 case AL_EAXREVERB_REFLECTIONS_DELAY:
381 if(flValue >= AL_EAXREVERB_MIN_REFLECTIONS_DELAY &&
382 flValue <= AL_EAXREVERB_MAX_REFLECTIONS_DELAY)
383 ALEffect->Reverb.ReflectionsDelay = flValue;
384 else
385 alSetError(AL_INVALID_VALUE);
386 break;
388 case AL_EAXREVERB_LATE_REVERB_GAIN:
389 if(flValue >= AL_EAXREVERB_MIN_LATE_REVERB_GAIN &&
390 flValue <= AL_EAXREVERB_MAX_LATE_REVERB_GAIN)
391 ALEffect->Reverb.LateReverbGain = flValue;
392 else
393 alSetError(AL_INVALID_VALUE);
394 break;
396 case AL_EAXREVERB_LATE_REVERB_DELAY:
397 if(flValue >= AL_EAXREVERB_MIN_LATE_REVERB_DELAY &&
398 flValue <= AL_EAXREVERB_MAX_LATE_REVERB_DELAY)
399 ALEffect->Reverb.LateReverbDelay = flValue;
400 else
401 alSetError(AL_INVALID_VALUE);
402 break;
404 case AL_EAXREVERB_AIR_ABSORPTION_GAINHF:
405 if(flValue >= AL_EAXREVERB_MIN_AIR_ABSORPTION_GAINHF &&
406 flValue <= AL_EAXREVERB_MAX_AIR_ABSORPTION_GAINHF)
407 ALEffect->Reverb.AirAbsorptionGainHF = flValue;
408 else
409 alSetError(AL_INVALID_VALUE);
410 break;
412 case AL_EAXREVERB_ECHO_TIME:
413 if(flValue >= AL_EAXREVERB_MIN_ECHO_TIME &&
414 flValue <= AL_EAXREVERB_MAX_ECHO_TIME)
415 ALEffect->Reverb.EchoTime = flValue;
416 else
417 alSetError(AL_INVALID_VALUE);
418 break;
420 case AL_EAXREVERB_ECHO_DEPTH:
421 if(flValue >= AL_EAXREVERB_MIN_ECHO_DEPTH &&
422 flValue <= AL_EAXREVERB_MAX_ECHO_DEPTH)
423 ALEffect->Reverb.EchoDepth = flValue;
424 else
425 alSetError(AL_INVALID_VALUE);
426 break;
428 case AL_EAXREVERB_MODULATION_TIME:
429 if(flValue >= AL_EAXREVERB_MIN_MODULATION_TIME &&
430 flValue <= AL_EAXREVERB_MAX_MODULATION_TIME)
431 ALEffect->Reverb.ModulationTime = flValue;
432 else
433 alSetError(AL_INVALID_VALUE);
434 break;
436 case AL_EAXREVERB_MODULATION_DEPTH:
437 if(flValue >= AL_EAXREVERB_MIN_MODULATION_DEPTH &&
438 flValue <= AL_EAXREVERB_MAX_MODULATION_DEPTH)
439 ALEffect->Reverb.ModulationDepth = flValue;
440 else
441 alSetError(AL_INVALID_VALUE);
442 break;
444 case AL_EAXREVERB_HFREFERENCE:
445 if(flValue >= AL_EAXREVERB_MIN_HFREFERENCE &&
446 flValue <= AL_EAXREVERB_MAX_HFREFERENCE)
447 ALEffect->Reverb.HFReference = flValue;
448 else
449 alSetError(AL_INVALID_VALUE);
450 break;
452 case AL_EAXREVERB_LFREFERENCE:
453 if(flValue >= AL_EAXREVERB_MIN_LFREFERENCE &&
454 flValue <= AL_EAXREVERB_MAX_LFREFERENCE)
455 ALEffect->Reverb.LFReference = flValue;
456 else
457 alSetError(AL_INVALID_VALUE);
458 break;
460 case AL_EAXREVERB_ROOM_ROLLOFF_FACTOR:
461 if(flValue >= 0.0f && flValue <= 10.0f)
462 ALEffect->Reverb.RoomRolloffFactor = flValue;
463 else
464 alSetError(AL_INVALID_VALUE);
465 break;
467 default:
468 alSetError(AL_INVALID_ENUM);
469 break;
472 else if(ALEffect->type == AL_EFFECT_REVERB)
474 switch(param)
476 case AL_REVERB_DENSITY:
477 if(flValue >= AL_REVERB_MIN_DENSITY &&
478 flValue <= AL_REVERB_MAX_DENSITY)
479 ALEffect->Reverb.Density = flValue;
480 else
481 alSetError(AL_INVALID_VALUE);
482 break;
484 case AL_REVERB_DIFFUSION:
485 if(flValue >= AL_REVERB_MIN_DIFFUSION &&
486 flValue <= AL_REVERB_MAX_DIFFUSION)
487 ALEffect->Reverb.Diffusion = flValue;
488 else
489 alSetError(AL_INVALID_VALUE);
490 break;
492 case AL_REVERB_GAIN:
493 if(flValue >= AL_REVERB_MIN_GAIN &&
494 flValue <= AL_REVERB_MAX_GAIN)
495 ALEffect->Reverb.Gain = flValue;
496 else
497 alSetError(AL_INVALID_VALUE);
498 break;
500 case AL_REVERB_GAINHF:
501 if(flValue >= AL_REVERB_MIN_GAINHF &&
502 flValue <= AL_REVERB_MAX_GAINHF)
503 ALEffect->Reverb.GainHF = flValue;
504 else
505 alSetError(AL_INVALID_VALUE);
506 break;
508 case AL_REVERB_DECAY_TIME:
509 if(flValue >= AL_REVERB_MIN_DECAY_TIME &&
510 flValue <= AL_REVERB_MAX_DECAY_TIME)
511 ALEffect->Reverb.DecayTime = flValue;
512 else
513 alSetError(AL_INVALID_VALUE);
514 break;
516 case AL_REVERB_DECAY_HFRATIO:
517 if(flValue >= AL_REVERB_MIN_DECAY_HFRATIO &&
518 flValue <= AL_REVERB_MAX_DECAY_HFRATIO)
519 ALEffect->Reverb.DecayHFRatio = flValue;
520 else
521 alSetError(AL_INVALID_VALUE);
522 break;
524 case AL_REVERB_REFLECTIONS_GAIN:
525 if(flValue >= AL_REVERB_MIN_REFLECTIONS_GAIN &&
526 flValue <= AL_REVERB_MAX_REFLECTIONS_GAIN)
527 ALEffect->Reverb.ReflectionsGain = flValue;
528 else
529 alSetError(AL_INVALID_VALUE);
530 break;
532 case AL_REVERB_REFLECTIONS_DELAY:
533 if(flValue >= AL_REVERB_MIN_REFLECTIONS_DELAY &&
534 flValue <= AL_REVERB_MAX_REFLECTIONS_DELAY)
535 ALEffect->Reverb.ReflectionsDelay = flValue;
536 else
537 alSetError(AL_INVALID_VALUE);
538 break;
540 case AL_REVERB_LATE_REVERB_GAIN:
541 if(flValue >= AL_REVERB_MIN_LATE_REVERB_GAIN &&
542 flValue <= AL_REVERB_MAX_LATE_REVERB_GAIN)
543 ALEffect->Reverb.LateReverbGain = flValue;
544 else
545 alSetError(AL_INVALID_VALUE);
546 break;
548 case AL_REVERB_LATE_REVERB_DELAY:
549 if(flValue >= AL_REVERB_MIN_LATE_REVERB_DELAY &&
550 flValue <= AL_REVERB_MAX_LATE_REVERB_DELAY)
551 ALEffect->Reverb.LateReverbDelay = flValue;
552 else
553 alSetError(AL_INVALID_VALUE);
554 break;
556 case AL_REVERB_AIR_ABSORPTION_GAINHF:
557 if(flValue >= AL_REVERB_MIN_AIR_ABSORPTION_GAINHF &&
558 flValue <= AL_REVERB_MAX_AIR_ABSORPTION_GAINHF)
559 ALEffect->Reverb.AirAbsorptionGainHF = flValue;
560 else
561 alSetError(AL_INVALID_VALUE);
562 break;
564 case AL_REVERB_ROOM_ROLLOFF_FACTOR:
565 if(flValue >= AL_REVERB_MIN_ROOM_ROLLOFF_FACTOR &&
566 flValue <= AL_REVERB_MAX_ROOM_ROLLOFF_FACTOR)
567 ALEffect->Reverb.RoomRolloffFactor = flValue;
568 else
569 alSetError(AL_INVALID_VALUE);
570 break;
572 default:
573 alSetError(AL_INVALID_ENUM);
574 break;
577 else if(ALEffect->type == AL_EFFECT_ECHO)
579 switch(param)
581 case AL_ECHO_DELAY:
582 if(flValue >= AL_ECHO_MIN_DELAY && flValue <= AL_ECHO_MAX_DELAY)
583 ALEffect->Echo.Delay = flValue;
584 else
585 alSetError(AL_INVALID_VALUE);
586 break;
588 case AL_ECHO_LRDELAY:
589 if(flValue >= AL_ECHO_MIN_LRDELAY && flValue <= AL_ECHO_MAX_LRDELAY)
590 ALEffect->Echo.LRDelay = flValue;
591 else
592 alSetError(AL_INVALID_VALUE);
593 break;
595 case AL_ECHO_DAMPING:
596 if(flValue >= AL_ECHO_MIN_DAMPING && flValue <= AL_ECHO_MAX_DAMPING)
597 ALEffect->Echo.Damping = flValue;
598 else
599 alSetError(AL_INVALID_VALUE);
600 break;
602 case AL_ECHO_FEEDBACK:
603 if(flValue >= AL_ECHO_MIN_FEEDBACK && flValue <= AL_ECHO_MAX_FEEDBACK)
604 ALEffect->Echo.Feedback = flValue;
605 else
606 alSetError(AL_INVALID_VALUE);
607 break;
609 case AL_ECHO_SPREAD:
610 if(flValue >= AL_ECHO_MIN_SPREAD && flValue <= AL_ECHO_MAX_SPREAD)
611 ALEffect->Echo.Spread = flValue;
612 else
613 alSetError(AL_INVALID_VALUE);
614 break;
616 default:
617 alSetError(AL_INVALID_ENUM);
618 break;
621 else
622 alSetError(AL_INVALID_ENUM);
624 else
625 alSetError(AL_INVALID_NAME);
627 ProcessContext(Context);
630 ALvoid AL_APIENTRY alEffectfv(ALuint effect, ALenum param, ALfloat *pflValues)
632 ALCcontext *Context;
634 Context = alcGetCurrentContext();
635 SuspendContext(Context);
637 if (effect && alIsEffect(effect))
639 ALeffect *ALEffect = (ALeffect*)ALTHUNK_LOOKUPENTRY(effect);
641 if(ALEffect->type == AL_EFFECT_EAXREVERB)
643 switch(param)
645 case AL_EAXREVERB_DENSITY:
646 case AL_EAXREVERB_DIFFUSION:
647 case AL_EAXREVERB_GAIN:
648 case AL_EAXREVERB_GAINHF:
649 case AL_EAXREVERB_GAINLF:
650 case AL_EAXREVERB_DECAY_TIME:
651 case AL_EAXREVERB_DECAY_HFRATIO:
652 case AL_EAXREVERB_DECAY_LFRATIO:
653 case AL_EAXREVERB_REFLECTIONS_GAIN:
654 case AL_EAXREVERB_REFLECTIONS_DELAY:
655 case AL_EAXREVERB_LATE_REVERB_GAIN:
656 case AL_EAXREVERB_LATE_REVERB_DELAY:
657 case AL_EAXREVERB_AIR_ABSORPTION_GAINHF:
658 case AL_EAXREVERB_ECHO_TIME:
659 case AL_EAXREVERB_ECHO_DEPTH:
660 case AL_EAXREVERB_MODULATION_TIME:
661 case AL_EAXREVERB_MODULATION_DEPTH:
662 case AL_EAXREVERB_HFREFERENCE:
663 case AL_EAXREVERB_LFREFERENCE:
664 case AL_EAXREVERB_ROOM_ROLLOFF_FACTOR:
665 alEffectf(effect, param, pflValues[0]);
666 break;
668 case AL_EAXREVERB_REFLECTIONS_PAN:
669 ALEffect->Reverb.ReflectionsPan[0] = pflValues[0];
670 ALEffect->Reverb.ReflectionsPan[1] = pflValues[1];
671 ALEffect->Reverb.ReflectionsPan[2] = pflValues[2];
672 break;
673 case AL_EAXREVERB_LATE_REVERB_PAN:
674 ALEffect->Reverb.LateReverbPan[0] = pflValues[0];
675 ALEffect->Reverb.LateReverbPan[1] = pflValues[1];
676 ALEffect->Reverb.LateReverbPan[2] = pflValues[2];
677 break;
679 default:
680 alSetError(AL_INVALID_ENUM);
681 break;
684 else if(ALEffect->type == AL_EFFECT_REVERB)
686 switch(param)
688 case AL_REVERB_DENSITY:
689 case AL_REVERB_DIFFUSION:
690 case AL_REVERB_GAIN:
691 case AL_REVERB_GAINHF:
692 case AL_REVERB_DECAY_TIME:
693 case AL_REVERB_DECAY_HFRATIO:
694 case AL_REVERB_REFLECTIONS_GAIN:
695 case AL_REVERB_REFLECTIONS_DELAY:
696 case AL_REVERB_LATE_REVERB_GAIN:
697 case AL_REVERB_LATE_REVERB_DELAY:
698 case AL_REVERB_AIR_ABSORPTION_GAINHF:
699 case AL_REVERB_ROOM_ROLLOFF_FACTOR:
700 alEffectf(effect, param, pflValues[0]);
701 break;
703 default:
704 alSetError(AL_INVALID_ENUM);
705 break;
708 else if(ALEffect->type == AL_EFFECT_ECHO)
710 switch(param)
712 case AL_ECHO_DELAY:
713 case AL_ECHO_LRDELAY:
714 case AL_ECHO_DAMPING:
715 case AL_ECHO_FEEDBACK:
716 case AL_ECHO_SPREAD:
717 alEffectf(effect, param, pflValues[0]);
718 break;
720 default:
721 alSetError(AL_INVALID_ENUM);
722 break;
725 else
726 alSetError(AL_INVALID_ENUM);
728 else
729 alSetError(AL_INVALID_NAME);
731 ProcessContext(Context);
734 ALvoid AL_APIENTRY alGetEffecti(ALuint effect, ALenum param, ALint *piValue)
736 ALCcontext *Context;
738 Context = alcGetCurrentContext();
739 SuspendContext(Context);
741 if (effect && alIsEffect(effect))
743 ALeffect *ALEffect = (ALeffect*)ALTHUNK_LOOKUPENTRY(effect);
745 if(param == AL_EFFECT_TYPE)
747 *piValue = ALEffect->type;
749 else if(ALEffect->type == AL_EFFECT_EAXREVERB)
751 switch(param)
753 case AL_EAXREVERB_DECAY_HFLIMIT:
754 *piValue = ALEffect->Reverb.DecayHFLimit;
755 break;
757 default:
758 alSetError(AL_INVALID_ENUM);
759 break;
762 else if(ALEffect->type == AL_EFFECT_REVERB)
764 switch(param)
766 case AL_REVERB_DECAY_HFLIMIT:
767 *piValue = ALEffect->Reverb.DecayHFLimit;
768 break;
770 default:
771 alSetError(AL_INVALID_ENUM);
772 break;
775 else if(ALEffect->type == AL_EFFECT_ECHO)
777 switch(param)
779 default:
780 alSetError(AL_INVALID_ENUM);
781 break;
784 else
785 alSetError(AL_INVALID_ENUM);
787 else
788 alSetError(AL_INVALID_NAME);
790 ProcessContext(Context);
793 ALvoid AL_APIENTRY alGetEffectiv(ALuint effect, ALenum param, ALint *piValues)
795 ALCcontext *Context;
797 Context = alcGetCurrentContext();
798 SuspendContext(Context);
800 if (effect && alIsEffect(effect))
802 ALeffect *ALEffect = (ALeffect*)ALTHUNK_LOOKUPENTRY(effect);
804 if(param == AL_EFFECT_TYPE)
806 alGetEffecti(effect, param, piValues);
808 else if(ALEffect->type == AL_EFFECT_EAXREVERB)
810 switch(param)
812 case AL_EAXREVERB_DECAY_HFLIMIT:
813 alGetEffecti(effect, param, piValues);
814 break;
816 default:
817 alSetError(AL_INVALID_ENUM);
818 break;
821 else if(ALEffect->type == AL_EFFECT_REVERB)
823 switch(param)
825 case AL_REVERB_DECAY_HFLIMIT:
826 alGetEffecti(effect, param, piValues);
827 break;
829 default:
830 alSetError(AL_INVALID_ENUM);
831 break;
834 else if(ALEffect->type == AL_EFFECT_ECHO)
836 switch(param)
838 default:
839 alSetError(AL_INVALID_ENUM);
840 break;
843 else
844 alSetError(AL_INVALID_ENUM);
846 else
847 alSetError(AL_INVALID_NAME);
849 ProcessContext(Context);
852 ALvoid AL_APIENTRY alGetEffectf(ALuint effect, ALenum param, ALfloat *pflValue)
854 ALCcontext *Context;
856 Context = alcGetCurrentContext();
857 SuspendContext(Context);
859 if (effect && alIsEffect(effect))
861 ALeffect *ALEffect = (ALeffect*)ALTHUNK_LOOKUPENTRY(effect);
863 if(ALEffect->type == AL_EFFECT_EAXREVERB)
865 switch(param)
867 case AL_EAXREVERB_DENSITY:
868 *pflValue = ALEffect->Reverb.Density;
869 break;
871 case AL_EAXREVERB_DIFFUSION:
872 *pflValue = ALEffect->Reverb.Diffusion;
873 break;
875 case AL_EAXREVERB_GAIN:
876 *pflValue = ALEffect->Reverb.Gain;
877 break;
879 case AL_EAXREVERB_GAINHF:
880 *pflValue = ALEffect->Reverb.GainHF;
881 break;
883 case AL_EAXREVERB_GAINLF:
884 *pflValue = ALEffect->Reverb.GainLF;
885 break;
887 case AL_EAXREVERB_DECAY_TIME:
888 *pflValue = ALEffect->Reverb.DecayTime;
889 break;
891 case AL_EAXREVERB_DECAY_HFRATIO:
892 *pflValue = ALEffect->Reverb.DecayHFRatio;
893 break;
895 case AL_EAXREVERB_DECAY_LFRATIO:
896 *pflValue = ALEffect->Reverb.DecayLFRatio;
897 break;
899 case AL_EAXREVERB_REFLECTIONS_GAIN:
900 *pflValue = ALEffect->Reverb.ReflectionsGain;
901 break;
903 case AL_EAXREVERB_REFLECTIONS_DELAY:
904 *pflValue = ALEffect->Reverb.ReflectionsDelay;
905 break;
907 case AL_EAXREVERB_LATE_REVERB_GAIN:
908 *pflValue = ALEffect->Reverb.LateReverbGain;
909 break;
911 case AL_EAXREVERB_LATE_REVERB_DELAY:
912 *pflValue = ALEffect->Reverb.LateReverbDelay;
913 break;
915 case AL_EAXREVERB_AIR_ABSORPTION_GAINHF:
916 *pflValue = ALEffect->Reverb.AirAbsorptionGainHF;
917 break;
919 case AL_EAXREVERB_ECHO_TIME:
920 *pflValue = ALEffect->Reverb.EchoTime;
921 break;
923 case AL_EAXREVERB_ECHO_DEPTH:
924 *pflValue = ALEffect->Reverb.EchoDepth;
925 break;
927 case AL_EAXREVERB_MODULATION_TIME:
928 *pflValue = ALEffect->Reverb.ModulationTime;
929 break;
931 case AL_EAXREVERB_MODULATION_DEPTH:
932 *pflValue = ALEffect->Reverb.ModulationDepth;
933 break;
935 case AL_EAXREVERB_HFREFERENCE:
936 *pflValue = ALEffect->Reverb.HFReference;
937 break;
939 case AL_EAXREVERB_LFREFERENCE:
940 *pflValue = ALEffect->Reverb.LFReference;
941 break;
943 case AL_EAXREVERB_ROOM_ROLLOFF_FACTOR:
944 *pflValue = ALEffect->Reverb.RoomRolloffFactor;
945 break;
947 default:
948 alSetError(AL_INVALID_ENUM);
949 break;
952 else if(ALEffect->type == AL_EFFECT_REVERB)
954 switch(param)
956 case AL_REVERB_DENSITY:
957 *pflValue = ALEffect->Reverb.Density;
958 break;
960 case AL_REVERB_DIFFUSION:
961 *pflValue = ALEffect->Reverb.Diffusion;
962 break;
964 case AL_REVERB_GAIN:
965 *pflValue = ALEffect->Reverb.Gain;
966 break;
968 case AL_REVERB_GAINHF:
969 *pflValue = ALEffect->Reverb.GainHF;
970 break;
972 case AL_REVERB_DECAY_TIME:
973 *pflValue = ALEffect->Reverb.DecayTime;
974 break;
976 case AL_REVERB_DECAY_HFRATIO:
977 *pflValue = ALEffect->Reverb.DecayHFRatio;
978 break;
980 case AL_REVERB_REFLECTIONS_GAIN:
981 *pflValue = ALEffect->Reverb.ReflectionsGain;
982 break;
984 case AL_REVERB_REFLECTIONS_DELAY:
985 *pflValue = ALEffect->Reverb.ReflectionsDelay;
986 break;
988 case AL_REVERB_LATE_REVERB_GAIN:
989 *pflValue = ALEffect->Reverb.LateReverbGain;
990 break;
992 case AL_REVERB_LATE_REVERB_DELAY:
993 *pflValue = ALEffect->Reverb.LateReverbDelay;
994 break;
996 case AL_REVERB_AIR_ABSORPTION_GAINHF:
997 *pflValue = ALEffect->Reverb.AirAbsorptionGainHF;
998 break;
1000 case AL_REVERB_ROOM_ROLLOFF_FACTOR:
1001 *pflValue = ALEffect->Reverb.RoomRolloffFactor;
1002 break;
1004 default:
1005 alSetError(AL_INVALID_ENUM);
1006 break;
1009 else if(ALEffect->type == AL_EFFECT_ECHO)
1011 switch(param)
1013 case AL_ECHO_DELAY:
1014 *pflValue = ALEffect->Echo.Delay;
1015 break;
1017 case AL_ECHO_LRDELAY:
1018 *pflValue = ALEffect->Echo.LRDelay;
1019 break;
1021 case AL_ECHO_DAMPING:
1022 *pflValue = ALEffect->Echo.Damping;
1023 break;
1025 case AL_ECHO_FEEDBACK:
1026 *pflValue = ALEffect->Echo.Feedback;
1027 break;
1029 case AL_ECHO_SPREAD:
1030 *pflValue = ALEffect->Echo.Spread;
1031 break;
1033 default:
1034 alSetError(AL_INVALID_ENUM);
1035 break;
1038 else
1039 alSetError(AL_INVALID_ENUM);
1041 else
1042 alSetError(AL_INVALID_NAME);
1044 ProcessContext(Context);
1047 ALvoid AL_APIENTRY alGetEffectfv(ALuint effect, ALenum param, ALfloat *pflValues)
1049 ALCcontext *Context;
1051 Context = alcGetCurrentContext();
1052 SuspendContext(Context);
1054 if (effect && alIsEffect(effect))
1056 ALeffect *ALEffect = (ALeffect*)ALTHUNK_LOOKUPENTRY(effect);
1058 if(ALEffect->type == AL_EFFECT_EAXREVERB)
1060 switch(param)
1062 case AL_EAXREVERB_DENSITY:
1063 case AL_EAXREVERB_DIFFUSION:
1064 case AL_EAXREVERB_GAIN:
1065 case AL_EAXREVERB_GAINHF:
1066 case AL_EAXREVERB_GAINLF:
1067 case AL_EAXREVERB_DECAY_TIME:
1068 case AL_EAXREVERB_DECAY_HFRATIO:
1069 case AL_EAXREVERB_DECAY_LFRATIO:
1070 case AL_EAXREVERB_REFLECTIONS_GAIN:
1071 case AL_EAXREVERB_REFLECTIONS_DELAY:
1072 case AL_EAXREVERB_LATE_REVERB_GAIN:
1073 case AL_EAXREVERB_LATE_REVERB_DELAY:
1074 case AL_EAXREVERB_AIR_ABSORPTION_GAINHF:
1075 case AL_EAXREVERB_ECHO_TIME:
1076 case AL_EAXREVERB_ECHO_DEPTH:
1077 case AL_EAXREVERB_MODULATION_TIME:
1078 case AL_EAXREVERB_MODULATION_DEPTH:
1079 case AL_EAXREVERB_HFREFERENCE:
1080 case AL_EAXREVERB_LFREFERENCE:
1081 case AL_EAXREVERB_ROOM_ROLLOFF_FACTOR:
1082 alGetEffectf(effect, param, pflValues);
1083 break;
1085 case AL_EAXREVERB_REFLECTIONS_PAN:
1086 pflValues[0] = ALEffect->Reverb.ReflectionsPan[0];
1087 pflValues[1] = ALEffect->Reverb.ReflectionsPan[1];
1088 pflValues[2] = ALEffect->Reverb.ReflectionsPan[2];
1089 break;
1090 case AL_EAXREVERB_LATE_REVERB_PAN:
1091 pflValues[0] = ALEffect->Reverb.LateReverbPan[0];
1092 pflValues[1] = ALEffect->Reverb.LateReverbPan[1];
1093 pflValues[2] = ALEffect->Reverb.LateReverbPan[2];
1094 break;
1096 default:
1097 alSetError(AL_INVALID_ENUM);
1098 break;
1101 else if(ALEffect->type == AL_EFFECT_REVERB)
1103 switch(param)
1105 case AL_REVERB_DENSITY:
1106 case AL_REVERB_DIFFUSION:
1107 case AL_REVERB_GAIN:
1108 case AL_REVERB_GAINHF:
1109 case AL_REVERB_DECAY_TIME:
1110 case AL_REVERB_DECAY_HFRATIO:
1111 case AL_REVERB_REFLECTIONS_GAIN:
1112 case AL_REVERB_REFLECTIONS_DELAY:
1113 case AL_REVERB_LATE_REVERB_GAIN:
1114 case AL_REVERB_LATE_REVERB_DELAY:
1115 case AL_REVERB_AIR_ABSORPTION_GAINHF:
1116 case AL_REVERB_ROOM_ROLLOFF_FACTOR:
1117 alGetEffectf(effect, param, pflValues);
1118 break;
1120 default:
1121 alSetError(AL_INVALID_ENUM);
1122 break;
1125 else if(ALEffect->type == AL_EFFECT_ECHO)
1127 switch(param)
1129 case AL_ECHO_DELAY:
1130 case AL_ECHO_LRDELAY:
1131 case AL_ECHO_DAMPING:
1132 case AL_ECHO_FEEDBACK:
1133 case AL_ECHO_SPREAD:
1134 alGetEffectf(effect, param, pflValues);
1135 break;
1137 default:
1138 alSetError(AL_INVALID_ENUM);
1139 break;
1142 else
1143 alSetError(AL_INVALID_ENUM);
1145 else
1146 alSetError(AL_INVALID_NAME);
1148 ProcessContext(Context);
1152 ALvoid ReleaseALEffects(ALvoid)
1154 #ifdef _DEBUG
1155 if(g_EffectCount > 0)
1156 AL_PRINT("exit(): deleting %d Effect(s)\n", g_EffectCount);
1157 #endif
1159 while(g_EffectList)
1161 ALeffect *temp = g_EffectList;
1162 g_EffectList = g_EffectList->next;
1164 // Release effect structure
1165 memset(temp, 0, sizeof(ALeffect));
1166 free(temp);
1168 g_EffectCount = 0;
1172 static void InitEffectParams(ALeffect *effect, ALenum type)
1174 effect->type = type;
1175 switch(type)
1177 /* NOTE: Standard reverb and EAX reverb use the same defaults for the
1178 * shared parameters, and EAX's additional parameters default to
1179 * values assumed by standard reverb.
1181 case AL_EFFECT_EAXREVERB:
1182 case AL_EFFECT_REVERB:
1183 effect->Reverb.Density = AL_EAXREVERB_DEFAULT_DENSITY;
1184 effect->Reverb.Diffusion = AL_EAXREVERB_DEFAULT_DIFFUSION;
1185 effect->Reverb.Gain = AL_EAXREVERB_DEFAULT_GAIN;
1186 effect->Reverb.GainHF = AL_EAXREVERB_DEFAULT_GAINHF;
1187 effect->Reverb.GainLF = AL_EAXREVERB_DEFAULT_GAINLF;
1188 effect->Reverb.DecayTime = AL_EAXREVERB_DEFAULT_DECAY_TIME;
1189 effect->Reverb.DecayHFRatio = AL_EAXREVERB_DEFAULT_DECAY_HFRATIO;
1190 effect->Reverb.DecayLFRatio = AL_EAXREVERB_DEFAULT_DECAY_LFRATIO;
1191 effect->Reverb.ReflectionsGain = AL_EAXREVERB_DEFAULT_REFLECTIONS_GAIN;
1192 effect->Reverb.ReflectionsDelay = AL_EAXREVERB_DEFAULT_REFLECTIONS_DELAY;
1193 effect->Reverb.ReflectionsPan[0] = AL_EAXREVERB_DEFAULT_REFLECTIONS_PAN_XYZ;
1194 effect->Reverb.ReflectionsPan[1] = AL_EAXREVERB_DEFAULT_REFLECTIONS_PAN_XYZ;
1195 effect->Reverb.ReflectionsPan[2] = AL_EAXREVERB_DEFAULT_REFLECTIONS_PAN_XYZ;
1196 effect->Reverb.LateReverbGain = AL_EAXREVERB_DEFAULT_LATE_REVERB_GAIN;
1197 effect->Reverb.LateReverbDelay = AL_EAXREVERB_DEFAULT_LATE_REVERB_DELAY;
1198 effect->Reverb.LateReverbPan[0] = AL_EAXREVERB_DEFAULT_LATE_REVERB_PAN_XYZ;
1199 effect->Reverb.LateReverbPan[1] = AL_EAXREVERB_DEFAULT_LATE_REVERB_PAN_XYZ;
1200 effect->Reverb.LateReverbPan[2] = AL_EAXREVERB_DEFAULT_LATE_REVERB_PAN_XYZ;
1201 effect->Reverb.EchoTime = AL_EAXREVERB_DEFAULT_ECHO_TIME;
1202 effect->Reverb.EchoDepth = AL_EAXREVERB_DEFAULT_ECHO_DEPTH;
1203 effect->Reverb.ModulationTime = AL_EAXREVERB_DEFAULT_MODULATION_TIME;
1204 effect->Reverb.ModulationDepth = AL_EAXREVERB_DEFAULT_MODULATION_DEPTH;
1205 effect->Reverb.AirAbsorptionGainHF = AL_EAXREVERB_DEFAULT_AIR_ABSORPTION_GAINHF;
1206 effect->Reverb.HFReference = AL_EAXREVERB_DEFAULT_HFREFERENCE;
1207 effect->Reverb.LFReference = AL_EAXREVERB_DEFAULT_LFREFERENCE;
1208 effect->Reverb.RoomRolloffFactor = AL_EAXREVERB_DEFAULT_ROOM_ROLLOFF_FACTOR;
1209 effect->Reverb.DecayHFLimit = AL_EAXREVERB_DEFAULT_DECAY_HFLIMIT;
1210 break;
1211 case AL_EFFECT_ECHO:
1212 effect->Echo.Delay = AL_ECHO_DEFAULT_DELAY;
1213 effect->Echo.LRDelay = AL_ECHO_DEFAULT_LRDELAY;
1214 effect->Echo.Damping = AL_ECHO_DEFAULT_DAMPING;
1215 effect->Echo.Feedback = AL_ECHO_DEFAULT_FEEDBACK;
1216 effect->Echo.Spread = AL_ECHO_DEFAULT_SPREAD;
1217 break;