Protect ring buffer access with the lock
[openal-soft/openal-hmr.git] / OpenAL32 / alEffect.c
blobf41c769e66c66d02a735dab03a1985f469c8ac0f
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>
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 ALeffect *g_EffectList;
38 static ALuint g_EffectCount;
40 static void InitEffectParams(ALeffect *effect, ALenum type);
43 ALvoid AL_APIENTRY alGenEffects(ALsizei n, ALuint *effects)
45 ALCcontext *Context;
46 ALsizei i;
48 Context = alcGetCurrentContext();
49 SuspendContext(Context);
51 if (n > 0)
53 // Check that enough memory has been allocted in the 'effects' array for n Effects
54 if (!IsBadWritePtr((void*)effects, n * sizeof(ALuint)))
56 ALeffect **list = &g_EffectList;
57 while(*list)
58 list = &(*list)->next;
60 i = 0;
61 while(i < n)
63 *list = calloc(1, sizeof(ALeffect));
64 if(!(*list))
66 // We must have run out or memory
67 alDeleteEffects(i, effects);
68 alSetError(AL_OUT_OF_MEMORY);
69 break;
72 effects[i] = (ALuint)ALTHUNK_ADDENTRY(*list);
73 (*list)->effect = effects[i];
75 InitEffectParams(*list, AL_EFFECT_NULL);
76 g_EffectCount++;
77 i++;
79 list = &(*list)->next;
84 ProcessContext(Context);
87 ALvoid AL_APIENTRY alDeleteEffects(ALsizei n, ALuint *effects)
89 ALCcontext *Context;
90 ALeffect *ALEffect;
91 ALsizei i;
93 Context = alcGetCurrentContext();
94 SuspendContext(Context);
96 if (n >= 0)
98 // Check that all effects are valid
99 for (i = 0; i < n; i++)
101 if (!alIsEffect(effects[i]))
103 alSetError(AL_INVALID_NAME);
104 break;
108 if (i == n)
110 // All effects are valid
111 for (i = 0; i < n; i++)
113 // Recheck that the effect is valid, because there could be duplicated names
114 if (effects[i] && alIsEffect(effects[i]))
116 ALeffect **list;
118 ALEffect = ((ALeffect*)ALTHUNK_LOOKUPENTRY(effects[i]));
120 // Remove Source from list of Sources
121 list = &g_EffectList;
122 while(*list && *list != ALEffect)
123 list = &(*list)->next;
125 if(*list)
126 *list = (*list)->next;
127 ALTHUNK_REMOVEENTRY(ALEffect->effect);
129 memset(ALEffect, 0, sizeof(ALeffect));
130 free(ALEffect);
132 g_EffectCount--;
137 else
138 alSetError(AL_INVALID_VALUE);
140 ProcessContext(Context);
143 ALboolean AL_APIENTRY alIsEffect(ALuint effect)
145 ALCcontext *Context;
146 ALeffect **list;
148 Context = alcGetCurrentContext();
149 SuspendContext(Context);
151 list = &g_EffectList;
152 while(*list && (*list)->effect != effect)
153 list = &(*list)->next;
155 ProcessContext(Context);
157 return ((*list || !effect) ? AL_TRUE : AL_FALSE);
160 ALvoid AL_APIENTRY alEffecti(ALuint effect, ALenum param, ALint iValue)
162 ALCcontext *Context;
164 Context = alcGetCurrentContext();
165 SuspendContext(Context);
167 if (effect && alIsEffect(effect))
169 ALeffect *ALEffect = (ALeffect*)ALTHUNK_LOOKUPENTRY(effect);
171 if(param == AL_EFFECT_TYPE)
173 ALboolean isOk = (iValue == AL_EFFECT_NULL ||
174 (iValue == AL_EFFECT_EAXREVERB && !DisabledEffects[EAXREVERB]) ||
175 (iValue == AL_EFFECT_REVERB && !DisabledEffects[REVERB]) ||
176 (iValue == AL_EFFECT_ECHO && !DisabledEffects[ECHO]));
178 if(isOk)
179 InitEffectParams(ALEffect, iValue);
180 else
181 alSetError(AL_INVALID_VALUE);
183 else if(ALEffect->type == AL_EFFECT_EAXREVERB)
185 switch(param)
187 case AL_EAXREVERB_DECAY_HFLIMIT:
188 if(iValue >= AL_EAXREVERB_MIN_DECAY_HFLIMIT &&
189 iValue <= AL_EAXREVERB_MAX_DECAY_HFLIMIT)
190 ALEffect->Reverb.DecayHFLimit = iValue;
191 else
192 alSetError(AL_INVALID_VALUE);
193 break;
195 default:
196 alSetError(AL_INVALID_ENUM);
197 break;
200 else if(ALEffect->type == AL_EFFECT_REVERB)
202 switch(param)
204 case AL_REVERB_DECAY_HFLIMIT:
205 if(iValue >= AL_REVERB_MIN_DECAY_HFLIMIT &&
206 iValue <= AL_REVERB_MAX_DECAY_HFLIMIT)
207 ALEffect->Reverb.DecayHFLimit = iValue;
208 else
209 alSetError(AL_INVALID_VALUE);
210 break;
212 default:
213 alSetError(AL_INVALID_ENUM);
214 break;
217 else if(ALEffect->type == AL_EFFECT_ECHO)
219 switch(param)
221 default:
222 alSetError(AL_INVALID_ENUM);
223 break;
226 else
227 alSetError(AL_INVALID_ENUM);
229 else
230 alSetError(AL_INVALID_NAME);
232 ProcessContext(Context);
235 ALvoid AL_APIENTRY alEffectiv(ALuint effect, ALenum param, ALint *piValues)
237 ALCcontext *Context;
239 Context = alcGetCurrentContext();
240 SuspendContext(Context);
242 if (effect && alIsEffect(effect))
244 ALeffect *ALEffect = (ALeffect*)ALTHUNK_LOOKUPENTRY(effect);
246 if(param == AL_EFFECT_TYPE)
248 alEffecti(effect, param, piValues[0]);
250 else if(ALEffect->type == AL_EFFECT_EAXREVERB)
252 switch(param)
254 case AL_EAXREVERB_DECAY_HFLIMIT:
255 alEffecti(effect, param, piValues[0]);
256 break;
258 default:
259 alSetError(AL_INVALID_ENUM);
260 break;
263 else if(ALEffect->type == AL_EFFECT_REVERB)
265 switch(param)
267 case AL_REVERB_DECAY_HFLIMIT:
268 alEffecti(effect, param, piValues[0]);
269 break;
271 default:
272 alSetError(AL_INVALID_ENUM);
273 break;
276 else if(ALEffect->type == AL_EFFECT_ECHO)
278 switch(param)
280 default:
281 alSetError(AL_INVALID_ENUM);
282 break;
285 else
286 alSetError(AL_INVALID_ENUM);
288 else
289 alSetError(AL_INVALID_NAME);
291 ProcessContext(Context);
294 ALvoid AL_APIENTRY alEffectf(ALuint effect, ALenum param, ALfloat flValue)
296 ALCcontext *Context;
298 Context = alcGetCurrentContext();
299 SuspendContext(Context);
301 if (effect && alIsEffect(effect))
303 ALeffect *ALEffect = (ALeffect*)ALTHUNK_LOOKUPENTRY(effect);
305 if(ALEffect->type == AL_EFFECT_EAXREVERB)
307 switch(param)
309 case AL_EAXREVERB_DENSITY:
310 if(flValue >= AL_EAXREVERB_MIN_DENSITY &&
311 flValue <= AL_EAXREVERB_MAX_DENSITY)
312 ALEffect->Reverb.Density = flValue;
313 else
314 alSetError(AL_INVALID_VALUE);
315 break;
317 case AL_EAXREVERB_DIFFUSION:
318 if(flValue >= AL_EAXREVERB_MIN_DIFFUSION &&
319 flValue <= AL_EAXREVERB_MAX_DIFFUSION)
320 ALEffect->Reverb.Diffusion = flValue;
321 else
322 alSetError(AL_INVALID_VALUE);
323 break;
325 case AL_EAXREVERB_GAIN:
326 if(flValue >= AL_EAXREVERB_MIN_GAIN &&
327 flValue <= AL_EAXREVERB_MAX_GAIN)
328 ALEffect->Reverb.Gain = flValue;
329 else
330 alSetError(AL_INVALID_VALUE);
331 break;
333 case AL_EAXREVERB_GAINHF:
334 if(flValue >= AL_EAXREVERB_MIN_GAINHF &&
335 flValue <= AL_EAXREVERB_MAX_GAIN)
336 ALEffect->Reverb.GainHF = flValue;
337 else
338 alSetError(AL_INVALID_VALUE);
339 break;
341 case AL_EAXREVERB_GAINLF:
342 if(flValue >= AL_EAXREVERB_MIN_GAINLF &&
343 flValue <= AL_EAXREVERB_MAX_GAINLF)
344 ALEffect->Reverb.GainLF = flValue;
345 else
346 alSetError(AL_INVALID_VALUE);
347 break;
349 case AL_EAXREVERB_DECAY_TIME:
350 if(flValue >= AL_EAXREVERB_MIN_DECAY_TIME &&
351 flValue <= AL_EAXREVERB_MAX_DECAY_TIME)
352 ALEffect->Reverb.DecayTime = flValue;
353 else
354 alSetError(AL_INVALID_VALUE);
355 break;
357 case AL_EAXREVERB_DECAY_HFRATIO:
358 if(flValue >= AL_EAXREVERB_MIN_DECAY_HFRATIO &&
359 flValue <= AL_EAXREVERB_MAX_DECAY_HFRATIO)
360 ALEffect->Reverb.DecayHFRatio = flValue;
361 else
362 alSetError(AL_INVALID_VALUE);
363 break;
365 case AL_EAXREVERB_DECAY_LFRATIO:
366 if(flValue >= AL_EAXREVERB_MIN_DECAY_LFRATIO &&
367 flValue <= AL_EAXREVERB_MAX_DECAY_LFRATIO)
368 ALEffect->Reverb.DecayLFRatio = flValue;
369 else
370 alSetError(AL_INVALID_VALUE);
371 break;
373 case AL_EAXREVERB_REFLECTIONS_GAIN:
374 if(flValue >= AL_EAXREVERB_MIN_REFLECTIONS_GAIN &&
375 flValue <= AL_EAXREVERB_MAX_REFLECTIONS_GAIN)
376 ALEffect->Reverb.ReflectionsGain = flValue;
377 else
378 alSetError(AL_INVALID_VALUE);
379 break;
381 case AL_EAXREVERB_REFLECTIONS_DELAY:
382 if(flValue >= AL_EAXREVERB_MIN_REFLECTIONS_DELAY &&
383 flValue <= AL_EAXREVERB_MAX_REFLECTIONS_DELAY)
384 ALEffect->Reverb.ReflectionsDelay = flValue;
385 else
386 alSetError(AL_INVALID_VALUE);
387 break;
389 case AL_EAXREVERB_LATE_REVERB_GAIN:
390 if(flValue >= AL_EAXREVERB_MIN_LATE_REVERB_GAIN &&
391 flValue <= AL_EAXREVERB_MAX_LATE_REVERB_GAIN)
392 ALEffect->Reverb.LateReverbGain = flValue;
393 else
394 alSetError(AL_INVALID_VALUE);
395 break;
397 case AL_EAXREVERB_LATE_REVERB_DELAY:
398 if(flValue >= AL_EAXREVERB_MIN_LATE_REVERB_DELAY &&
399 flValue <= AL_EAXREVERB_MAX_LATE_REVERB_DELAY)
400 ALEffect->Reverb.LateReverbDelay = flValue;
401 else
402 alSetError(AL_INVALID_VALUE);
403 break;
405 case AL_EAXREVERB_AIR_ABSORPTION_GAINHF:
406 if(flValue >= AL_EAXREVERB_MIN_AIR_ABSORPTION_GAINHF &&
407 flValue <= AL_EAXREVERB_MAX_AIR_ABSORPTION_GAINHF)
408 ALEffect->Reverb.AirAbsorptionGainHF = flValue;
409 else
410 alSetError(AL_INVALID_VALUE);
411 break;
413 case AL_EAXREVERB_ECHO_TIME:
414 if(flValue >= AL_EAXREVERB_MIN_ECHO_TIME &&
415 flValue <= AL_EAXREVERB_MAX_ECHO_TIME)
416 ALEffect->Reverb.EchoTime = flValue;
417 else
418 alSetError(AL_INVALID_VALUE);
419 break;
421 case AL_EAXREVERB_ECHO_DEPTH:
422 if(flValue >= AL_EAXREVERB_MIN_ECHO_DEPTH &&
423 flValue <= AL_EAXREVERB_MAX_ECHO_DEPTH)
424 ALEffect->Reverb.EchoDepth = flValue;
425 else
426 alSetError(AL_INVALID_VALUE);
427 break;
429 case AL_EAXREVERB_MODULATION_TIME:
430 if(flValue >= AL_EAXREVERB_MIN_MODULATION_TIME &&
431 flValue <= AL_EAXREVERB_MAX_MODULATION_TIME)
432 ALEffect->Reverb.ModulationTime = flValue;
433 else
434 alSetError(AL_INVALID_VALUE);
435 break;
437 case AL_EAXREVERB_MODULATION_DEPTH:
438 if(flValue >= AL_EAXREVERB_MIN_MODULATION_DEPTH &&
439 flValue <= AL_EAXREVERB_MAX_MODULATION_DEPTH)
440 ALEffect->Reverb.ModulationDepth = flValue;
441 else
442 alSetError(AL_INVALID_VALUE);
443 break;
445 case AL_EAXREVERB_HFREFERENCE:
446 if(flValue >= AL_EAXREVERB_MIN_HFREFERENCE &&
447 flValue <= AL_EAXREVERB_MAX_HFREFERENCE)
448 ALEffect->Reverb.HFReference = flValue;
449 else
450 alSetError(AL_INVALID_VALUE);
451 break;
453 case AL_EAXREVERB_LFREFERENCE:
454 if(flValue >= AL_EAXREVERB_MIN_LFREFERENCE &&
455 flValue <= AL_EAXREVERB_MAX_LFREFERENCE)
456 ALEffect->Reverb.LFReference = flValue;
457 else
458 alSetError(AL_INVALID_VALUE);
459 break;
461 case AL_EAXREVERB_ROOM_ROLLOFF_FACTOR:
462 if(flValue >= 0.0f && flValue <= 10.0f)
463 ALEffect->Reverb.RoomRolloffFactor = flValue;
464 else
465 alSetError(AL_INVALID_VALUE);
466 break;
468 default:
469 alSetError(AL_INVALID_ENUM);
470 break;
473 else if(ALEffect->type == AL_EFFECT_REVERB)
475 switch(param)
477 case AL_REVERB_DENSITY:
478 if(flValue >= AL_REVERB_MIN_DENSITY &&
479 flValue <= AL_REVERB_MAX_DENSITY)
480 ALEffect->Reverb.Density = flValue;
481 else
482 alSetError(AL_INVALID_VALUE);
483 break;
485 case AL_REVERB_DIFFUSION:
486 if(flValue >= AL_REVERB_MIN_DIFFUSION &&
487 flValue <= AL_REVERB_MAX_DIFFUSION)
488 ALEffect->Reverb.Diffusion = flValue;
489 else
490 alSetError(AL_INVALID_VALUE);
491 break;
493 case AL_REVERB_GAIN:
494 if(flValue >= AL_REVERB_MIN_GAIN &&
495 flValue <= AL_REVERB_MAX_GAIN)
496 ALEffect->Reverb.Gain = flValue;
497 else
498 alSetError(AL_INVALID_VALUE);
499 break;
501 case AL_REVERB_GAINHF:
502 if(flValue >= AL_REVERB_MIN_GAINHF &&
503 flValue <= AL_REVERB_MAX_GAINHF)
504 ALEffect->Reverb.GainHF = flValue;
505 else
506 alSetError(AL_INVALID_VALUE);
507 break;
509 case AL_REVERB_DECAY_TIME:
510 if(flValue >= AL_REVERB_MIN_DECAY_TIME &&
511 flValue <= AL_REVERB_MAX_DECAY_TIME)
512 ALEffect->Reverb.DecayTime = flValue;
513 else
514 alSetError(AL_INVALID_VALUE);
515 break;
517 case AL_REVERB_DECAY_HFRATIO:
518 if(flValue >= AL_REVERB_MIN_DECAY_HFRATIO &&
519 flValue <= AL_REVERB_MAX_DECAY_HFRATIO)
520 ALEffect->Reverb.DecayHFRatio = flValue;
521 else
522 alSetError(AL_INVALID_VALUE);
523 break;
525 case AL_REVERB_REFLECTIONS_GAIN:
526 if(flValue >= AL_REVERB_MIN_REFLECTIONS_GAIN &&
527 flValue <= AL_REVERB_MAX_REFLECTIONS_GAIN)
528 ALEffect->Reverb.ReflectionsGain = flValue;
529 else
530 alSetError(AL_INVALID_VALUE);
531 break;
533 case AL_REVERB_REFLECTIONS_DELAY:
534 if(flValue >= AL_REVERB_MIN_REFLECTIONS_DELAY &&
535 flValue <= AL_REVERB_MAX_REFLECTIONS_DELAY)
536 ALEffect->Reverb.ReflectionsDelay = flValue;
537 else
538 alSetError(AL_INVALID_VALUE);
539 break;
541 case AL_REVERB_LATE_REVERB_GAIN:
542 if(flValue >= AL_REVERB_MIN_LATE_REVERB_GAIN &&
543 flValue <= AL_REVERB_MAX_LATE_REVERB_GAIN)
544 ALEffect->Reverb.LateReverbGain = flValue;
545 else
546 alSetError(AL_INVALID_VALUE);
547 break;
549 case AL_REVERB_LATE_REVERB_DELAY:
550 if(flValue >= AL_REVERB_MIN_LATE_REVERB_DELAY &&
551 flValue <= AL_REVERB_MAX_LATE_REVERB_DELAY)
552 ALEffect->Reverb.LateReverbDelay = flValue;
553 else
554 alSetError(AL_INVALID_VALUE);
555 break;
557 case AL_REVERB_AIR_ABSORPTION_GAINHF:
558 if(flValue >= AL_REVERB_MIN_AIR_ABSORPTION_GAINHF &&
559 flValue <= AL_REVERB_MAX_AIR_ABSORPTION_GAINHF)
560 ALEffect->Reverb.AirAbsorptionGainHF = flValue;
561 else
562 alSetError(AL_INVALID_VALUE);
563 break;
565 case AL_REVERB_ROOM_ROLLOFF_FACTOR:
566 if(flValue >= AL_REVERB_MIN_ROOM_ROLLOFF_FACTOR &&
567 flValue <= AL_REVERB_MAX_ROOM_ROLLOFF_FACTOR)
568 ALEffect->Reverb.RoomRolloffFactor = flValue;
569 else
570 alSetError(AL_INVALID_VALUE);
571 break;
573 default:
574 alSetError(AL_INVALID_ENUM);
575 break;
578 else if(ALEffect->type == AL_EFFECT_ECHO)
580 switch(param)
582 case AL_ECHO_DELAY:
583 if(flValue >= AL_ECHO_MIN_DELAY && flValue <= AL_ECHO_MAX_DELAY)
584 ALEffect->Echo.Delay = flValue;
585 else
586 alSetError(AL_INVALID_VALUE);
587 break;
589 case AL_ECHO_LRDELAY:
590 if(flValue >= AL_ECHO_MIN_LRDELAY && flValue <= AL_ECHO_MAX_LRDELAY)
591 ALEffect->Echo.LRDelay = flValue;
592 else
593 alSetError(AL_INVALID_VALUE);
594 break;
596 case AL_ECHO_DAMPING:
597 if(flValue >= AL_ECHO_MIN_DAMPING && flValue <= AL_ECHO_MAX_DAMPING)
598 ALEffect->Echo.Damping = flValue;
599 else
600 alSetError(AL_INVALID_VALUE);
601 break;
603 case AL_ECHO_FEEDBACK:
604 if(flValue >= AL_ECHO_MIN_FEEDBACK && flValue <= AL_ECHO_MAX_FEEDBACK)
605 ALEffect->Echo.Feedback = flValue;
606 else
607 alSetError(AL_INVALID_VALUE);
608 break;
610 case AL_ECHO_SPREAD:
611 if(flValue >= AL_ECHO_MIN_SPREAD && flValue <= AL_ECHO_MAX_SPREAD)
612 ALEffect->Echo.Spread = flValue;
613 else
614 alSetError(AL_INVALID_VALUE);
615 break;
617 default:
618 alSetError(AL_INVALID_ENUM);
619 break;
622 else
623 alSetError(AL_INVALID_ENUM);
625 else
626 alSetError(AL_INVALID_NAME);
628 ProcessContext(Context);
631 ALvoid AL_APIENTRY alEffectfv(ALuint effect, ALenum param, ALfloat *pflValues)
633 ALCcontext *Context;
635 Context = alcGetCurrentContext();
636 SuspendContext(Context);
638 if (effect && alIsEffect(effect))
640 ALeffect *ALEffect = (ALeffect*)ALTHUNK_LOOKUPENTRY(effect);
642 if(ALEffect->type == AL_EFFECT_EAXREVERB)
644 switch(param)
646 case AL_EAXREVERB_DENSITY:
647 case AL_EAXREVERB_DIFFUSION:
648 case AL_EAXREVERB_GAIN:
649 case AL_EAXREVERB_GAINHF:
650 case AL_EAXREVERB_GAINLF:
651 case AL_EAXREVERB_DECAY_TIME:
652 case AL_EAXREVERB_DECAY_HFRATIO:
653 case AL_EAXREVERB_DECAY_LFRATIO:
654 case AL_EAXREVERB_REFLECTIONS_GAIN:
655 case AL_EAXREVERB_REFLECTIONS_DELAY:
656 case AL_EAXREVERB_LATE_REVERB_GAIN:
657 case AL_EAXREVERB_LATE_REVERB_DELAY:
658 case AL_EAXREVERB_AIR_ABSORPTION_GAINHF:
659 case AL_EAXREVERB_ECHO_TIME:
660 case AL_EAXREVERB_ECHO_DEPTH:
661 case AL_EAXREVERB_MODULATION_TIME:
662 case AL_EAXREVERB_MODULATION_DEPTH:
663 case AL_EAXREVERB_HFREFERENCE:
664 case AL_EAXREVERB_LFREFERENCE:
665 case AL_EAXREVERB_ROOM_ROLLOFF_FACTOR:
666 alEffectf(effect, param, pflValues[0]);
667 break;
669 case AL_EAXREVERB_REFLECTIONS_PAN:
670 if(!isnan(pflValues[0]) && !isnan(pflValues[1]) && !isnan(pflValues[2]))
672 ALEffect->Reverb.ReflectionsPan[0] = pflValues[0];
673 ALEffect->Reverb.ReflectionsPan[1] = pflValues[1];
674 ALEffect->Reverb.ReflectionsPan[2] = pflValues[2];
676 else
677 alSetError(AL_INVALID_VALUE);
678 break;
679 case AL_EAXREVERB_LATE_REVERB_PAN:
680 if(!isnan(pflValues[0]) && !isnan(pflValues[1]) && !isnan(pflValues[2]))
682 ALEffect->Reverb.LateReverbPan[0] = pflValues[0];
683 ALEffect->Reverb.LateReverbPan[1] = pflValues[1];
684 ALEffect->Reverb.LateReverbPan[2] = pflValues[2];
686 else
687 alSetError(AL_INVALID_VALUE);
688 break;
690 default:
691 alSetError(AL_INVALID_ENUM);
692 break;
695 else if(ALEffect->type == AL_EFFECT_REVERB)
697 switch(param)
699 case AL_REVERB_DENSITY:
700 case AL_REVERB_DIFFUSION:
701 case AL_REVERB_GAIN:
702 case AL_REVERB_GAINHF:
703 case AL_REVERB_DECAY_TIME:
704 case AL_REVERB_DECAY_HFRATIO:
705 case AL_REVERB_REFLECTIONS_GAIN:
706 case AL_REVERB_REFLECTIONS_DELAY:
707 case AL_REVERB_LATE_REVERB_GAIN:
708 case AL_REVERB_LATE_REVERB_DELAY:
709 case AL_REVERB_AIR_ABSORPTION_GAINHF:
710 case AL_REVERB_ROOM_ROLLOFF_FACTOR:
711 alEffectf(effect, param, pflValues[0]);
712 break;
714 default:
715 alSetError(AL_INVALID_ENUM);
716 break;
719 else if(ALEffect->type == AL_EFFECT_ECHO)
721 switch(param)
723 case AL_ECHO_DELAY:
724 case AL_ECHO_LRDELAY:
725 case AL_ECHO_DAMPING:
726 case AL_ECHO_FEEDBACK:
727 case AL_ECHO_SPREAD:
728 alEffectf(effect, param, pflValues[0]);
729 break;
731 default:
732 alSetError(AL_INVALID_ENUM);
733 break;
736 else
737 alSetError(AL_INVALID_ENUM);
739 else
740 alSetError(AL_INVALID_NAME);
742 ProcessContext(Context);
745 ALvoid AL_APIENTRY alGetEffecti(ALuint effect, ALenum param, ALint *piValue)
747 ALCcontext *Context;
749 Context = alcGetCurrentContext();
750 SuspendContext(Context);
752 if (effect && alIsEffect(effect))
754 ALeffect *ALEffect = (ALeffect*)ALTHUNK_LOOKUPENTRY(effect);
756 if(param == AL_EFFECT_TYPE)
758 *piValue = ALEffect->type;
760 else if(ALEffect->type == AL_EFFECT_EAXREVERB)
762 switch(param)
764 case AL_EAXREVERB_DECAY_HFLIMIT:
765 *piValue = ALEffect->Reverb.DecayHFLimit;
766 break;
768 default:
769 alSetError(AL_INVALID_ENUM);
770 break;
773 else if(ALEffect->type == AL_EFFECT_REVERB)
775 switch(param)
777 case AL_REVERB_DECAY_HFLIMIT:
778 *piValue = ALEffect->Reverb.DecayHFLimit;
779 break;
781 default:
782 alSetError(AL_INVALID_ENUM);
783 break;
786 else if(ALEffect->type == AL_EFFECT_ECHO)
788 switch(param)
790 default:
791 alSetError(AL_INVALID_ENUM);
792 break;
795 else
796 alSetError(AL_INVALID_ENUM);
798 else
799 alSetError(AL_INVALID_NAME);
801 ProcessContext(Context);
804 ALvoid AL_APIENTRY alGetEffectiv(ALuint effect, ALenum param, ALint *piValues)
806 ALCcontext *Context;
808 Context = alcGetCurrentContext();
809 SuspendContext(Context);
811 if (effect && alIsEffect(effect))
813 ALeffect *ALEffect = (ALeffect*)ALTHUNK_LOOKUPENTRY(effect);
815 if(param == AL_EFFECT_TYPE)
817 alGetEffecti(effect, param, piValues);
819 else if(ALEffect->type == AL_EFFECT_EAXREVERB)
821 switch(param)
823 case AL_EAXREVERB_DECAY_HFLIMIT:
824 alGetEffecti(effect, param, piValues);
825 break;
827 default:
828 alSetError(AL_INVALID_ENUM);
829 break;
832 else if(ALEffect->type == AL_EFFECT_REVERB)
834 switch(param)
836 case AL_REVERB_DECAY_HFLIMIT:
837 alGetEffecti(effect, param, piValues);
838 break;
840 default:
841 alSetError(AL_INVALID_ENUM);
842 break;
845 else if(ALEffect->type == AL_EFFECT_ECHO)
847 switch(param)
849 default:
850 alSetError(AL_INVALID_ENUM);
851 break;
854 else
855 alSetError(AL_INVALID_ENUM);
857 else
858 alSetError(AL_INVALID_NAME);
860 ProcessContext(Context);
863 ALvoid AL_APIENTRY alGetEffectf(ALuint effect, ALenum param, ALfloat *pflValue)
865 ALCcontext *Context;
867 Context = alcGetCurrentContext();
868 SuspendContext(Context);
870 if (effect && alIsEffect(effect))
872 ALeffect *ALEffect = (ALeffect*)ALTHUNK_LOOKUPENTRY(effect);
874 if(ALEffect->type == AL_EFFECT_EAXREVERB)
876 switch(param)
878 case AL_EAXREVERB_DENSITY:
879 *pflValue = ALEffect->Reverb.Density;
880 break;
882 case AL_EAXREVERB_DIFFUSION:
883 *pflValue = ALEffect->Reverb.Diffusion;
884 break;
886 case AL_EAXREVERB_GAIN:
887 *pflValue = ALEffect->Reverb.Gain;
888 break;
890 case AL_EAXREVERB_GAINHF:
891 *pflValue = ALEffect->Reverb.GainHF;
892 break;
894 case AL_EAXREVERB_GAINLF:
895 *pflValue = ALEffect->Reverb.GainLF;
896 break;
898 case AL_EAXREVERB_DECAY_TIME:
899 *pflValue = ALEffect->Reverb.DecayTime;
900 break;
902 case AL_EAXREVERB_DECAY_HFRATIO:
903 *pflValue = ALEffect->Reverb.DecayHFRatio;
904 break;
906 case AL_EAXREVERB_DECAY_LFRATIO:
907 *pflValue = ALEffect->Reverb.DecayLFRatio;
908 break;
910 case AL_EAXREVERB_REFLECTIONS_GAIN:
911 *pflValue = ALEffect->Reverb.ReflectionsGain;
912 break;
914 case AL_EAXREVERB_REFLECTIONS_DELAY:
915 *pflValue = ALEffect->Reverb.ReflectionsDelay;
916 break;
918 case AL_EAXREVERB_LATE_REVERB_GAIN:
919 *pflValue = ALEffect->Reverb.LateReverbGain;
920 break;
922 case AL_EAXREVERB_LATE_REVERB_DELAY:
923 *pflValue = ALEffect->Reverb.LateReverbDelay;
924 break;
926 case AL_EAXREVERB_AIR_ABSORPTION_GAINHF:
927 *pflValue = ALEffect->Reverb.AirAbsorptionGainHF;
928 break;
930 case AL_EAXREVERB_ECHO_TIME:
931 *pflValue = ALEffect->Reverb.EchoTime;
932 break;
934 case AL_EAXREVERB_ECHO_DEPTH:
935 *pflValue = ALEffect->Reverb.EchoDepth;
936 break;
938 case AL_EAXREVERB_MODULATION_TIME:
939 *pflValue = ALEffect->Reverb.ModulationTime;
940 break;
942 case AL_EAXREVERB_MODULATION_DEPTH:
943 *pflValue = ALEffect->Reverb.ModulationDepth;
944 break;
946 case AL_EAXREVERB_HFREFERENCE:
947 *pflValue = ALEffect->Reverb.HFReference;
948 break;
950 case AL_EAXREVERB_LFREFERENCE:
951 *pflValue = ALEffect->Reverb.LFReference;
952 break;
954 case AL_EAXREVERB_ROOM_ROLLOFF_FACTOR:
955 *pflValue = ALEffect->Reverb.RoomRolloffFactor;
956 break;
958 default:
959 alSetError(AL_INVALID_ENUM);
960 break;
963 else if(ALEffect->type == AL_EFFECT_REVERB)
965 switch(param)
967 case AL_REVERB_DENSITY:
968 *pflValue = ALEffect->Reverb.Density;
969 break;
971 case AL_REVERB_DIFFUSION:
972 *pflValue = ALEffect->Reverb.Diffusion;
973 break;
975 case AL_REVERB_GAIN:
976 *pflValue = ALEffect->Reverb.Gain;
977 break;
979 case AL_REVERB_GAINHF:
980 *pflValue = ALEffect->Reverb.GainHF;
981 break;
983 case AL_REVERB_DECAY_TIME:
984 *pflValue = ALEffect->Reverb.DecayTime;
985 break;
987 case AL_REVERB_DECAY_HFRATIO:
988 *pflValue = ALEffect->Reverb.DecayHFRatio;
989 break;
991 case AL_REVERB_REFLECTIONS_GAIN:
992 *pflValue = ALEffect->Reverb.ReflectionsGain;
993 break;
995 case AL_REVERB_REFLECTIONS_DELAY:
996 *pflValue = ALEffect->Reverb.ReflectionsDelay;
997 break;
999 case AL_REVERB_LATE_REVERB_GAIN:
1000 *pflValue = ALEffect->Reverb.LateReverbGain;
1001 break;
1003 case AL_REVERB_LATE_REVERB_DELAY:
1004 *pflValue = ALEffect->Reverb.LateReverbDelay;
1005 break;
1007 case AL_REVERB_AIR_ABSORPTION_GAINHF:
1008 *pflValue = ALEffect->Reverb.AirAbsorptionGainHF;
1009 break;
1011 case AL_REVERB_ROOM_ROLLOFF_FACTOR:
1012 *pflValue = ALEffect->Reverb.RoomRolloffFactor;
1013 break;
1015 default:
1016 alSetError(AL_INVALID_ENUM);
1017 break;
1020 else if(ALEffect->type == AL_EFFECT_ECHO)
1022 switch(param)
1024 case AL_ECHO_DELAY:
1025 *pflValue = ALEffect->Echo.Delay;
1026 break;
1028 case AL_ECHO_LRDELAY:
1029 *pflValue = ALEffect->Echo.LRDelay;
1030 break;
1032 case AL_ECHO_DAMPING:
1033 *pflValue = ALEffect->Echo.Damping;
1034 break;
1036 case AL_ECHO_FEEDBACK:
1037 *pflValue = ALEffect->Echo.Feedback;
1038 break;
1040 case AL_ECHO_SPREAD:
1041 *pflValue = ALEffect->Echo.Spread;
1042 break;
1044 default:
1045 alSetError(AL_INVALID_ENUM);
1046 break;
1049 else
1050 alSetError(AL_INVALID_ENUM);
1052 else
1053 alSetError(AL_INVALID_NAME);
1055 ProcessContext(Context);
1058 ALvoid AL_APIENTRY alGetEffectfv(ALuint effect, ALenum param, ALfloat *pflValues)
1060 ALCcontext *Context;
1062 Context = alcGetCurrentContext();
1063 SuspendContext(Context);
1065 if (effect && alIsEffect(effect))
1067 ALeffect *ALEffect = (ALeffect*)ALTHUNK_LOOKUPENTRY(effect);
1069 if(ALEffect->type == AL_EFFECT_EAXREVERB)
1071 switch(param)
1073 case AL_EAXREVERB_DENSITY:
1074 case AL_EAXREVERB_DIFFUSION:
1075 case AL_EAXREVERB_GAIN:
1076 case AL_EAXREVERB_GAINHF:
1077 case AL_EAXREVERB_GAINLF:
1078 case AL_EAXREVERB_DECAY_TIME:
1079 case AL_EAXREVERB_DECAY_HFRATIO:
1080 case AL_EAXREVERB_DECAY_LFRATIO:
1081 case AL_EAXREVERB_REFLECTIONS_GAIN:
1082 case AL_EAXREVERB_REFLECTIONS_DELAY:
1083 case AL_EAXREVERB_LATE_REVERB_GAIN:
1084 case AL_EAXREVERB_LATE_REVERB_DELAY:
1085 case AL_EAXREVERB_AIR_ABSORPTION_GAINHF:
1086 case AL_EAXREVERB_ECHO_TIME:
1087 case AL_EAXREVERB_ECHO_DEPTH:
1088 case AL_EAXREVERB_MODULATION_TIME:
1089 case AL_EAXREVERB_MODULATION_DEPTH:
1090 case AL_EAXREVERB_HFREFERENCE:
1091 case AL_EAXREVERB_LFREFERENCE:
1092 case AL_EAXREVERB_ROOM_ROLLOFF_FACTOR:
1093 alGetEffectf(effect, param, pflValues);
1094 break;
1096 case AL_EAXREVERB_REFLECTIONS_PAN:
1097 pflValues[0] = ALEffect->Reverb.ReflectionsPan[0];
1098 pflValues[1] = ALEffect->Reverb.ReflectionsPan[1];
1099 pflValues[2] = ALEffect->Reverb.ReflectionsPan[2];
1100 break;
1101 case AL_EAXREVERB_LATE_REVERB_PAN:
1102 pflValues[0] = ALEffect->Reverb.LateReverbPan[0];
1103 pflValues[1] = ALEffect->Reverb.LateReverbPan[1];
1104 pflValues[2] = ALEffect->Reverb.LateReverbPan[2];
1105 break;
1107 default:
1108 alSetError(AL_INVALID_ENUM);
1109 break;
1112 else if(ALEffect->type == AL_EFFECT_REVERB)
1114 switch(param)
1116 case AL_REVERB_DENSITY:
1117 case AL_REVERB_DIFFUSION:
1118 case AL_REVERB_GAIN:
1119 case AL_REVERB_GAINHF:
1120 case AL_REVERB_DECAY_TIME:
1121 case AL_REVERB_DECAY_HFRATIO:
1122 case AL_REVERB_REFLECTIONS_GAIN:
1123 case AL_REVERB_REFLECTIONS_DELAY:
1124 case AL_REVERB_LATE_REVERB_GAIN:
1125 case AL_REVERB_LATE_REVERB_DELAY:
1126 case AL_REVERB_AIR_ABSORPTION_GAINHF:
1127 case AL_REVERB_ROOM_ROLLOFF_FACTOR:
1128 alGetEffectf(effect, param, pflValues);
1129 break;
1131 default:
1132 alSetError(AL_INVALID_ENUM);
1133 break;
1136 else if(ALEffect->type == AL_EFFECT_ECHO)
1138 switch(param)
1140 case AL_ECHO_DELAY:
1141 case AL_ECHO_LRDELAY:
1142 case AL_ECHO_DAMPING:
1143 case AL_ECHO_FEEDBACK:
1144 case AL_ECHO_SPREAD:
1145 alGetEffectf(effect, param, pflValues);
1146 break;
1148 default:
1149 alSetError(AL_INVALID_ENUM);
1150 break;
1153 else
1154 alSetError(AL_INVALID_ENUM);
1156 else
1157 alSetError(AL_INVALID_NAME);
1159 ProcessContext(Context);
1163 ALvoid ReleaseALEffects(ALvoid)
1165 #ifdef _DEBUG
1166 if(g_EffectCount > 0)
1167 AL_PRINT("exit(): deleting %d Effect(s)\n", g_EffectCount);
1168 #endif
1170 while(g_EffectList)
1172 ALeffect *temp = g_EffectList;
1173 g_EffectList = g_EffectList->next;
1175 // Release effect structure
1176 memset(temp, 0, sizeof(ALeffect));
1177 free(temp);
1179 g_EffectCount = 0;
1183 static void InitEffectParams(ALeffect *effect, ALenum type)
1185 effect->type = type;
1186 switch(type)
1188 /* NOTE: Standard reverb and EAX reverb use the same defaults for the
1189 * shared parameters, and EAX's additional parameters default to
1190 * values assumed by standard reverb.
1192 case AL_EFFECT_EAXREVERB:
1193 case AL_EFFECT_REVERB:
1194 effect->Reverb.Density = AL_EAXREVERB_DEFAULT_DENSITY;
1195 effect->Reverb.Diffusion = AL_EAXREVERB_DEFAULT_DIFFUSION;
1196 effect->Reverb.Gain = AL_EAXREVERB_DEFAULT_GAIN;
1197 effect->Reverb.GainHF = AL_EAXREVERB_DEFAULT_GAINHF;
1198 effect->Reverb.GainLF = AL_EAXREVERB_DEFAULT_GAINLF;
1199 effect->Reverb.DecayTime = AL_EAXREVERB_DEFAULT_DECAY_TIME;
1200 effect->Reverb.DecayHFRatio = AL_EAXREVERB_DEFAULT_DECAY_HFRATIO;
1201 effect->Reverb.DecayLFRatio = AL_EAXREVERB_DEFAULT_DECAY_LFRATIO;
1202 effect->Reverb.ReflectionsGain = AL_EAXREVERB_DEFAULT_REFLECTIONS_GAIN;
1203 effect->Reverb.ReflectionsDelay = AL_EAXREVERB_DEFAULT_REFLECTIONS_DELAY;
1204 effect->Reverb.ReflectionsPan[0] = AL_EAXREVERB_DEFAULT_REFLECTIONS_PAN_XYZ;
1205 effect->Reverb.ReflectionsPan[1] = AL_EAXREVERB_DEFAULT_REFLECTIONS_PAN_XYZ;
1206 effect->Reverb.ReflectionsPan[2] = AL_EAXREVERB_DEFAULT_REFLECTIONS_PAN_XYZ;
1207 effect->Reverb.LateReverbGain = AL_EAXREVERB_DEFAULT_LATE_REVERB_GAIN;
1208 effect->Reverb.LateReverbDelay = AL_EAXREVERB_DEFAULT_LATE_REVERB_DELAY;
1209 effect->Reverb.LateReverbPan[0] = AL_EAXREVERB_DEFAULT_LATE_REVERB_PAN_XYZ;
1210 effect->Reverb.LateReverbPan[1] = AL_EAXREVERB_DEFAULT_LATE_REVERB_PAN_XYZ;
1211 effect->Reverb.LateReverbPan[2] = AL_EAXREVERB_DEFAULT_LATE_REVERB_PAN_XYZ;
1212 effect->Reverb.EchoTime = AL_EAXREVERB_DEFAULT_ECHO_TIME;
1213 effect->Reverb.EchoDepth = AL_EAXREVERB_DEFAULT_ECHO_DEPTH;
1214 effect->Reverb.ModulationTime = AL_EAXREVERB_DEFAULT_MODULATION_TIME;
1215 effect->Reverb.ModulationDepth = AL_EAXREVERB_DEFAULT_MODULATION_DEPTH;
1216 effect->Reverb.AirAbsorptionGainHF = AL_EAXREVERB_DEFAULT_AIR_ABSORPTION_GAINHF;
1217 effect->Reverb.HFReference = AL_EAXREVERB_DEFAULT_HFREFERENCE;
1218 effect->Reverb.LFReference = AL_EAXREVERB_DEFAULT_LFREFERENCE;
1219 effect->Reverb.RoomRolloffFactor = AL_EAXREVERB_DEFAULT_ROOM_ROLLOFF_FACTOR;
1220 effect->Reverb.DecayHFLimit = AL_EAXREVERB_DEFAULT_DECAY_HFLIMIT;
1221 break;
1222 case AL_EFFECT_ECHO:
1223 effect->Echo.Delay = AL_ECHO_DEFAULT_DELAY;
1224 effect->Echo.LRDelay = AL_ECHO_DEFAULT_LRDELAY;
1225 effect->Echo.Damping = AL_ECHO_DEFAULT_DAMPING;
1226 effect->Echo.Feedback = AL_ECHO_DEFAULT_FEEDBACK;
1227 effect->Echo.Spread = AL_ECHO_DEFAULT_SPREAD;
1228 break;