Use pa_xmalloc instead of pa_xmalloc0
[openal-soft/openal-hmr.git] / OpenAL32 / alEffect.c
blob14c92e2a67c6c32625cb53ba2a2c81d26403a5e4
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 void InitEffectParams(ALeffect *effect, ALenum type);
40 ALvoid AL_APIENTRY alGenEffects(ALsizei n, ALuint *effects)
42 ALCcontext *Context;
43 ALsizei i;
45 Context = GetContextSuspended();
46 if(!Context) return;
48 if (n > 0)
50 ALCdevice *device = Context->Device;
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 = &device->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 device->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 = GetContextSuspended();
93 if(!Context) return;
95 if (n >= 0)
97 ALCdevice *device = Context->Device;
99 // Check that all effects are valid
100 for (i = 0; i < n; i++)
102 if (!alIsEffect(effects[i]))
104 alSetError(AL_INVALID_NAME);
105 break;
109 if (i == n)
111 // All effects are valid
112 for (i = 0; i < n; i++)
114 // Recheck that the effect is valid, because there could be duplicated names
115 if (effects[i] && alIsEffect(effects[i]))
117 ALeffect **list;
119 ALEffect = ((ALeffect*)ALTHUNK_LOOKUPENTRY(effects[i]));
121 // Remove Source from list of Sources
122 list = &device->EffectList;
123 while(*list && *list != ALEffect)
124 list = &(*list)->next;
126 if(*list)
127 *list = (*list)->next;
128 ALTHUNK_REMOVEENTRY(ALEffect->effect);
130 memset(ALEffect, 0, sizeof(ALeffect));
131 free(ALEffect);
133 device->EffectCount--;
138 else
139 alSetError(AL_INVALID_VALUE);
141 ProcessContext(Context);
144 ALboolean AL_APIENTRY alIsEffect(ALuint effect)
146 ALCcontext *Context;
147 ALeffect *list;
149 Context = GetContextSuspended();
150 if(!Context) return AL_FALSE;
152 list = Context->Device->EffectList;
153 while(list && list->effect != effect)
154 list = list->next;
156 ProcessContext(Context);
158 return ((list || !effect) ? AL_TRUE : AL_FALSE);
161 ALvoid AL_APIENTRY alEffecti(ALuint effect, ALenum param, ALint iValue)
163 ALCcontext *Context;
165 Context = GetContextSuspended();
166 if(!Context) return;
168 if (effect && alIsEffect(effect))
170 ALeffect *ALEffect = (ALeffect*)ALTHUNK_LOOKUPENTRY(effect);
172 if(param == AL_EFFECT_TYPE)
174 ALboolean isOk = (iValue == AL_EFFECT_NULL ||
175 (iValue == AL_EFFECT_EAXREVERB && !DisabledEffects[EAXREVERB]) ||
176 (iValue == AL_EFFECT_REVERB && !DisabledEffects[REVERB]) ||
177 (iValue == AL_EFFECT_ECHO && !DisabledEffects[ECHO]));
179 if(isOk)
180 InitEffectParams(ALEffect, iValue);
181 else
182 alSetError(AL_INVALID_VALUE);
184 else if(ALEffect->type == AL_EFFECT_EAXREVERB)
186 switch(param)
188 case AL_EAXREVERB_DECAY_HFLIMIT:
189 if(iValue >= AL_EAXREVERB_MIN_DECAY_HFLIMIT &&
190 iValue <= AL_EAXREVERB_MAX_DECAY_HFLIMIT)
191 ALEffect->Reverb.DecayHFLimit = iValue;
192 else
193 alSetError(AL_INVALID_VALUE);
194 break;
196 default:
197 alSetError(AL_INVALID_ENUM);
198 break;
201 else if(ALEffect->type == AL_EFFECT_REVERB)
203 switch(param)
205 case AL_REVERB_DECAY_HFLIMIT:
206 if(iValue >= AL_REVERB_MIN_DECAY_HFLIMIT &&
207 iValue <= AL_REVERB_MAX_DECAY_HFLIMIT)
208 ALEffect->Reverb.DecayHFLimit = iValue;
209 else
210 alSetError(AL_INVALID_VALUE);
211 break;
213 default:
214 alSetError(AL_INVALID_ENUM);
215 break;
218 else if(ALEffect->type == AL_EFFECT_ECHO)
220 switch(param)
222 default:
223 alSetError(AL_INVALID_ENUM);
224 break;
227 else
228 alSetError(AL_INVALID_ENUM);
230 else
231 alSetError(AL_INVALID_NAME);
233 ProcessContext(Context);
236 ALvoid AL_APIENTRY alEffectiv(ALuint effect, ALenum param, ALint *piValues)
238 ALCcontext *Context;
240 Context = GetContextSuspended();
241 if(!Context) return;
243 if (effect && alIsEffect(effect))
245 ALeffect *ALEffect = (ALeffect*)ALTHUNK_LOOKUPENTRY(effect);
247 if(param == AL_EFFECT_TYPE)
249 alEffecti(effect, param, piValues[0]);
251 else if(ALEffect->type == AL_EFFECT_EAXREVERB)
253 switch(param)
255 case AL_EAXREVERB_DECAY_HFLIMIT:
256 alEffecti(effect, param, piValues[0]);
257 break;
259 default:
260 alSetError(AL_INVALID_ENUM);
261 break;
264 else if(ALEffect->type == AL_EFFECT_REVERB)
266 switch(param)
268 case AL_REVERB_DECAY_HFLIMIT:
269 alEffecti(effect, param, piValues[0]);
270 break;
272 default:
273 alSetError(AL_INVALID_ENUM);
274 break;
277 else if(ALEffect->type == AL_EFFECT_ECHO)
279 switch(param)
281 default:
282 alSetError(AL_INVALID_ENUM);
283 break;
286 else
287 alSetError(AL_INVALID_ENUM);
289 else
290 alSetError(AL_INVALID_NAME);
292 ProcessContext(Context);
295 ALvoid AL_APIENTRY alEffectf(ALuint effect, ALenum param, ALfloat flValue)
297 ALCcontext *Context;
299 Context = GetContextSuspended();
300 if(!Context) return;
302 if (effect && alIsEffect(effect))
304 ALeffect *ALEffect = (ALeffect*)ALTHUNK_LOOKUPENTRY(effect);
306 if(ALEffect->type == AL_EFFECT_EAXREVERB)
308 switch(param)
310 case AL_EAXREVERB_DENSITY:
311 if(flValue >= AL_EAXREVERB_MIN_DENSITY &&
312 flValue <= AL_EAXREVERB_MAX_DENSITY)
313 ALEffect->Reverb.Density = flValue;
314 else
315 alSetError(AL_INVALID_VALUE);
316 break;
318 case AL_EAXREVERB_DIFFUSION:
319 if(flValue >= AL_EAXREVERB_MIN_DIFFUSION &&
320 flValue <= AL_EAXREVERB_MAX_DIFFUSION)
321 ALEffect->Reverb.Diffusion = flValue;
322 else
323 alSetError(AL_INVALID_VALUE);
324 break;
326 case AL_EAXREVERB_GAIN:
327 if(flValue >= AL_EAXREVERB_MIN_GAIN &&
328 flValue <= AL_EAXREVERB_MAX_GAIN)
329 ALEffect->Reverb.Gain = flValue;
330 else
331 alSetError(AL_INVALID_VALUE);
332 break;
334 case AL_EAXREVERB_GAINHF:
335 if(flValue >= AL_EAXREVERB_MIN_GAINHF &&
336 flValue <= AL_EAXREVERB_MAX_GAIN)
337 ALEffect->Reverb.GainHF = flValue;
338 else
339 alSetError(AL_INVALID_VALUE);
340 break;
342 case AL_EAXREVERB_GAINLF:
343 if(flValue >= AL_EAXREVERB_MIN_GAINLF &&
344 flValue <= AL_EAXREVERB_MAX_GAINLF)
345 ALEffect->Reverb.GainLF = flValue;
346 else
347 alSetError(AL_INVALID_VALUE);
348 break;
350 case AL_EAXREVERB_DECAY_TIME:
351 if(flValue >= AL_EAXREVERB_MIN_DECAY_TIME &&
352 flValue <= AL_EAXREVERB_MAX_DECAY_TIME)
353 ALEffect->Reverb.DecayTime = flValue;
354 else
355 alSetError(AL_INVALID_VALUE);
356 break;
358 case AL_EAXREVERB_DECAY_HFRATIO:
359 if(flValue >= AL_EAXREVERB_MIN_DECAY_HFRATIO &&
360 flValue <= AL_EAXREVERB_MAX_DECAY_HFRATIO)
361 ALEffect->Reverb.DecayHFRatio = flValue;
362 else
363 alSetError(AL_INVALID_VALUE);
364 break;
366 case AL_EAXREVERB_DECAY_LFRATIO:
367 if(flValue >= AL_EAXREVERB_MIN_DECAY_LFRATIO &&
368 flValue <= AL_EAXREVERB_MAX_DECAY_LFRATIO)
369 ALEffect->Reverb.DecayLFRatio = flValue;
370 else
371 alSetError(AL_INVALID_VALUE);
372 break;
374 case AL_EAXREVERB_REFLECTIONS_GAIN:
375 if(flValue >= AL_EAXREVERB_MIN_REFLECTIONS_GAIN &&
376 flValue <= AL_EAXREVERB_MAX_REFLECTIONS_GAIN)
377 ALEffect->Reverb.ReflectionsGain = flValue;
378 else
379 alSetError(AL_INVALID_VALUE);
380 break;
382 case AL_EAXREVERB_REFLECTIONS_DELAY:
383 if(flValue >= AL_EAXREVERB_MIN_REFLECTIONS_DELAY &&
384 flValue <= AL_EAXREVERB_MAX_REFLECTIONS_DELAY)
385 ALEffect->Reverb.ReflectionsDelay = flValue;
386 else
387 alSetError(AL_INVALID_VALUE);
388 break;
390 case AL_EAXREVERB_LATE_REVERB_GAIN:
391 if(flValue >= AL_EAXREVERB_MIN_LATE_REVERB_GAIN &&
392 flValue <= AL_EAXREVERB_MAX_LATE_REVERB_GAIN)
393 ALEffect->Reverb.LateReverbGain = flValue;
394 else
395 alSetError(AL_INVALID_VALUE);
396 break;
398 case AL_EAXREVERB_LATE_REVERB_DELAY:
399 if(flValue >= AL_EAXREVERB_MIN_LATE_REVERB_DELAY &&
400 flValue <= AL_EAXREVERB_MAX_LATE_REVERB_DELAY)
401 ALEffect->Reverb.LateReverbDelay = flValue;
402 else
403 alSetError(AL_INVALID_VALUE);
404 break;
406 case AL_EAXREVERB_AIR_ABSORPTION_GAINHF:
407 if(flValue >= AL_EAXREVERB_MIN_AIR_ABSORPTION_GAINHF &&
408 flValue <= AL_EAXREVERB_MAX_AIR_ABSORPTION_GAINHF)
409 ALEffect->Reverb.AirAbsorptionGainHF = flValue;
410 else
411 alSetError(AL_INVALID_VALUE);
412 break;
414 case AL_EAXREVERB_ECHO_TIME:
415 if(flValue >= AL_EAXREVERB_MIN_ECHO_TIME &&
416 flValue <= AL_EAXREVERB_MAX_ECHO_TIME)
417 ALEffect->Reverb.EchoTime = flValue;
418 else
419 alSetError(AL_INVALID_VALUE);
420 break;
422 case AL_EAXREVERB_ECHO_DEPTH:
423 if(flValue >= AL_EAXREVERB_MIN_ECHO_DEPTH &&
424 flValue <= AL_EAXREVERB_MAX_ECHO_DEPTH)
425 ALEffect->Reverb.EchoDepth = flValue;
426 else
427 alSetError(AL_INVALID_VALUE);
428 break;
430 case AL_EAXREVERB_MODULATION_TIME:
431 if(flValue >= AL_EAXREVERB_MIN_MODULATION_TIME &&
432 flValue <= AL_EAXREVERB_MAX_MODULATION_TIME)
433 ALEffect->Reverb.ModulationTime = flValue;
434 else
435 alSetError(AL_INVALID_VALUE);
436 break;
438 case AL_EAXREVERB_MODULATION_DEPTH:
439 if(flValue >= AL_EAXREVERB_MIN_MODULATION_DEPTH &&
440 flValue <= AL_EAXREVERB_MAX_MODULATION_DEPTH)
441 ALEffect->Reverb.ModulationDepth = flValue;
442 else
443 alSetError(AL_INVALID_VALUE);
444 break;
446 case AL_EAXREVERB_HFREFERENCE:
447 if(flValue >= AL_EAXREVERB_MIN_HFREFERENCE &&
448 flValue <= AL_EAXREVERB_MAX_HFREFERENCE)
449 ALEffect->Reverb.HFReference = flValue;
450 else
451 alSetError(AL_INVALID_VALUE);
452 break;
454 case AL_EAXREVERB_LFREFERENCE:
455 if(flValue >= AL_EAXREVERB_MIN_LFREFERENCE &&
456 flValue <= AL_EAXREVERB_MAX_LFREFERENCE)
457 ALEffect->Reverb.LFReference = flValue;
458 else
459 alSetError(AL_INVALID_VALUE);
460 break;
462 case AL_EAXREVERB_ROOM_ROLLOFF_FACTOR:
463 if(flValue >= 0.0f && flValue <= 10.0f)
464 ALEffect->Reverb.RoomRolloffFactor = flValue;
465 else
466 alSetError(AL_INVALID_VALUE);
467 break;
469 default:
470 alSetError(AL_INVALID_ENUM);
471 break;
474 else if(ALEffect->type == AL_EFFECT_REVERB)
476 switch(param)
478 case AL_REVERB_DENSITY:
479 if(flValue >= AL_REVERB_MIN_DENSITY &&
480 flValue <= AL_REVERB_MAX_DENSITY)
481 ALEffect->Reverb.Density = flValue;
482 else
483 alSetError(AL_INVALID_VALUE);
484 break;
486 case AL_REVERB_DIFFUSION:
487 if(flValue >= AL_REVERB_MIN_DIFFUSION &&
488 flValue <= AL_REVERB_MAX_DIFFUSION)
489 ALEffect->Reverb.Diffusion = flValue;
490 else
491 alSetError(AL_INVALID_VALUE);
492 break;
494 case AL_REVERB_GAIN:
495 if(flValue >= AL_REVERB_MIN_GAIN &&
496 flValue <= AL_REVERB_MAX_GAIN)
497 ALEffect->Reverb.Gain = flValue;
498 else
499 alSetError(AL_INVALID_VALUE);
500 break;
502 case AL_REVERB_GAINHF:
503 if(flValue >= AL_REVERB_MIN_GAINHF &&
504 flValue <= AL_REVERB_MAX_GAINHF)
505 ALEffect->Reverb.GainHF = flValue;
506 else
507 alSetError(AL_INVALID_VALUE);
508 break;
510 case AL_REVERB_DECAY_TIME:
511 if(flValue >= AL_REVERB_MIN_DECAY_TIME &&
512 flValue <= AL_REVERB_MAX_DECAY_TIME)
513 ALEffect->Reverb.DecayTime = flValue;
514 else
515 alSetError(AL_INVALID_VALUE);
516 break;
518 case AL_REVERB_DECAY_HFRATIO:
519 if(flValue >= AL_REVERB_MIN_DECAY_HFRATIO &&
520 flValue <= AL_REVERB_MAX_DECAY_HFRATIO)
521 ALEffect->Reverb.DecayHFRatio = flValue;
522 else
523 alSetError(AL_INVALID_VALUE);
524 break;
526 case AL_REVERB_REFLECTIONS_GAIN:
527 if(flValue >= AL_REVERB_MIN_REFLECTIONS_GAIN &&
528 flValue <= AL_REVERB_MAX_REFLECTIONS_GAIN)
529 ALEffect->Reverb.ReflectionsGain = flValue;
530 else
531 alSetError(AL_INVALID_VALUE);
532 break;
534 case AL_REVERB_REFLECTIONS_DELAY:
535 if(flValue >= AL_REVERB_MIN_REFLECTIONS_DELAY &&
536 flValue <= AL_REVERB_MAX_REFLECTIONS_DELAY)
537 ALEffect->Reverb.ReflectionsDelay = flValue;
538 else
539 alSetError(AL_INVALID_VALUE);
540 break;
542 case AL_REVERB_LATE_REVERB_GAIN:
543 if(flValue >= AL_REVERB_MIN_LATE_REVERB_GAIN &&
544 flValue <= AL_REVERB_MAX_LATE_REVERB_GAIN)
545 ALEffect->Reverb.LateReverbGain = flValue;
546 else
547 alSetError(AL_INVALID_VALUE);
548 break;
550 case AL_REVERB_LATE_REVERB_DELAY:
551 if(flValue >= AL_REVERB_MIN_LATE_REVERB_DELAY &&
552 flValue <= AL_REVERB_MAX_LATE_REVERB_DELAY)
553 ALEffect->Reverb.LateReverbDelay = flValue;
554 else
555 alSetError(AL_INVALID_VALUE);
556 break;
558 case AL_REVERB_AIR_ABSORPTION_GAINHF:
559 if(flValue >= AL_REVERB_MIN_AIR_ABSORPTION_GAINHF &&
560 flValue <= AL_REVERB_MAX_AIR_ABSORPTION_GAINHF)
561 ALEffect->Reverb.AirAbsorptionGainHF = flValue;
562 else
563 alSetError(AL_INVALID_VALUE);
564 break;
566 case AL_REVERB_ROOM_ROLLOFF_FACTOR:
567 if(flValue >= AL_REVERB_MIN_ROOM_ROLLOFF_FACTOR &&
568 flValue <= AL_REVERB_MAX_ROOM_ROLLOFF_FACTOR)
569 ALEffect->Reverb.RoomRolloffFactor = flValue;
570 else
571 alSetError(AL_INVALID_VALUE);
572 break;
574 default:
575 alSetError(AL_INVALID_ENUM);
576 break;
579 else if(ALEffect->type == AL_EFFECT_ECHO)
581 switch(param)
583 case AL_ECHO_DELAY:
584 if(flValue >= AL_ECHO_MIN_DELAY && flValue <= AL_ECHO_MAX_DELAY)
585 ALEffect->Echo.Delay = flValue;
586 else
587 alSetError(AL_INVALID_VALUE);
588 break;
590 case AL_ECHO_LRDELAY:
591 if(flValue >= AL_ECHO_MIN_LRDELAY && flValue <= AL_ECHO_MAX_LRDELAY)
592 ALEffect->Echo.LRDelay = flValue;
593 else
594 alSetError(AL_INVALID_VALUE);
595 break;
597 case AL_ECHO_DAMPING:
598 if(flValue >= AL_ECHO_MIN_DAMPING && flValue <= AL_ECHO_MAX_DAMPING)
599 ALEffect->Echo.Damping = flValue;
600 else
601 alSetError(AL_INVALID_VALUE);
602 break;
604 case AL_ECHO_FEEDBACK:
605 if(flValue >= AL_ECHO_MIN_FEEDBACK && flValue <= AL_ECHO_MAX_FEEDBACK)
606 ALEffect->Echo.Feedback = flValue;
607 else
608 alSetError(AL_INVALID_VALUE);
609 break;
611 case AL_ECHO_SPREAD:
612 if(flValue >= AL_ECHO_MIN_SPREAD && flValue <= AL_ECHO_MAX_SPREAD)
613 ALEffect->Echo.Spread = flValue;
614 else
615 alSetError(AL_INVALID_VALUE);
616 break;
618 default:
619 alSetError(AL_INVALID_ENUM);
620 break;
623 else
624 alSetError(AL_INVALID_ENUM);
626 else
627 alSetError(AL_INVALID_NAME);
629 ProcessContext(Context);
632 ALvoid AL_APIENTRY alEffectfv(ALuint effect, ALenum param, ALfloat *pflValues)
634 ALCcontext *Context;
636 Context = GetContextSuspended();
637 if(!Context) return;
639 if (effect && alIsEffect(effect))
641 ALeffect *ALEffect = (ALeffect*)ALTHUNK_LOOKUPENTRY(effect);
643 if(ALEffect->type == AL_EFFECT_EAXREVERB)
645 switch(param)
647 case AL_EAXREVERB_DENSITY:
648 case AL_EAXREVERB_DIFFUSION:
649 case AL_EAXREVERB_GAIN:
650 case AL_EAXREVERB_GAINHF:
651 case AL_EAXREVERB_GAINLF:
652 case AL_EAXREVERB_DECAY_TIME:
653 case AL_EAXREVERB_DECAY_HFRATIO:
654 case AL_EAXREVERB_DECAY_LFRATIO:
655 case AL_EAXREVERB_REFLECTIONS_GAIN:
656 case AL_EAXREVERB_REFLECTIONS_DELAY:
657 case AL_EAXREVERB_LATE_REVERB_GAIN:
658 case AL_EAXREVERB_LATE_REVERB_DELAY:
659 case AL_EAXREVERB_AIR_ABSORPTION_GAINHF:
660 case AL_EAXREVERB_ECHO_TIME:
661 case AL_EAXREVERB_ECHO_DEPTH:
662 case AL_EAXREVERB_MODULATION_TIME:
663 case AL_EAXREVERB_MODULATION_DEPTH:
664 case AL_EAXREVERB_HFREFERENCE:
665 case AL_EAXREVERB_LFREFERENCE:
666 case AL_EAXREVERB_ROOM_ROLLOFF_FACTOR:
667 alEffectf(effect, param, pflValues[0]);
668 break;
670 case AL_EAXREVERB_REFLECTIONS_PAN:
671 if(!isnan(pflValues[0]) && !isnan(pflValues[1]) && !isnan(pflValues[2]))
673 ALEffect->Reverb.ReflectionsPan[0] = pflValues[0];
674 ALEffect->Reverb.ReflectionsPan[1] = pflValues[1];
675 ALEffect->Reverb.ReflectionsPan[2] = pflValues[2];
677 else
678 alSetError(AL_INVALID_VALUE);
679 break;
680 case AL_EAXREVERB_LATE_REVERB_PAN:
681 if(!isnan(pflValues[0]) && !isnan(pflValues[1]) && !isnan(pflValues[2]))
683 ALEffect->Reverb.LateReverbPan[0] = pflValues[0];
684 ALEffect->Reverb.LateReverbPan[1] = pflValues[1];
685 ALEffect->Reverb.LateReverbPan[2] = pflValues[2];
687 else
688 alSetError(AL_INVALID_VALUE);
689 break;
691 default:
692 alSetError(AL_INVALID_ENUM);
693 break;
696 else if(ALEffect->type == AL_EFFECT_REVERB)
698 switch(param)
700 case AL_REVERB_DENSITY:
701 case AL_REVERB_DIFFUSION:
702 case AL_REVERB_GAIN:
703 case AL_REVERB_GAINHF:
704 case AL_REVERB_DECAY_TIME:
705 case AL_REVERB_DECAY_HFRATIO:
706 case AL_REVERB_REFLECTIONS_GAIN:
707 case AL_REVERB_REFLECTIONS_DELAY:
708 case AL_REVERB_LATE_REVERB_GAIN:
709 case AL_REVERB_LATE_REVERB_DELAY:
710 case AL_REVERB_AIR_ABSORPTION_GAINHF:
711 case AL_REVERB_ROOM_ROLLOFF_FACTOR:
712 alEffectf(effect, param, pflValues[0]);
713 break;
715 default:
716 alSetError(AL_INVALID_ENUM);
717 break;
720 else if(ALEffect->type == AL_EFFECT_ECHO)
722 switch(param)
724 case AL_ECHO_DELAY:
725 case AL_ECHO_LRDELAY:
726 case AL_ECHO_DAMPING:
727 case AL_ECHO_FEEDBACK:
728 case AL_ECHO_SPREAD:
729 alEffectf(effect, param, pflValues[0]);
730 break;
732 default:
733 alSetError(AL_INVALID_ENUM);
734 break;
737 else
738 alSetError(AL_INVALID_ENUM);
740 else
741 alSetError(AL_INVALID_NAME);
743 ProcessContext(Context);
746 ALvoid AL_APIENTRY alGetEffecti(ALuint effect, ALenum param, ALint *piValue)
748 ALCcontext *Context;
750 Context = GetContextSuspended();
751 if(!Context) return;
753 if (effect && alIsEffect(effect))
755 ALeffect *ALEffect = (ALeffect*)ALTHUNK_LOOKUPENTRY(effect);
757 if(param == AL_EFFECT_TYPE)
759 *piValue = ALEffect->type;
761 else if(ALEffect->type == AL_EFFECT_EAXREVERB)
763 switch(param)
765 case AL_EAXREVERB_DECAY_HFLIMIT:
766 *piValue = ALEffect->Reverb.DecayHFLimit;
767 break;
769 default:
770 alSetError(AL_INVALID_ENUM);
771 break;
774 else if(ALEffect->type == AL_EFFECT_REVERB)
776 switch(param)
778 case AL_REVERB_DECAY_HFLIMIT:
779 *piValue = ALEffect->Reverb.DecayHFLimit;
780 break;
782 default:
783 alSetError(AL_INVALID_ENUM);
784 break;
787 else if(ALEffect->type == AL_EFFECT_ECHO)
789 switch(param)
791 default:
792 alSetError(AL_INVALID_ENUM);
793 break;
796 else
797 alSetError(AL_INVALID_ENUM);
799 else
800 alSetError(AL_INVALID_NAME);
802 ProcessContext(Context);
805 ALvoid AL_APIENTRY alGetEffectiv(ALuint effect, ALenum param, ALint *piValues)
807 ALCcontext *Context;
809 Context = GetContextSuspended();
810 if(!Context) return;
812 if (effect && alIsEffect(effect))
814 ALeffect *ALEffect = (ALeffect*)ALTHUNK_LOOKUPENTRY(effect);
816 if(param == AL_EFFECT_TYPE)
818 alGetEffecti(effect, param, piValues);
820 else if(ALEffect->type == AL_EFFECT_EAXREVERB)
822 switch(param)
824 case AL_EAXREVERB_DECAY_HFLIMIT:
825 alGetEffecti(effect, param, piValues);
826 break;
828 default:
829 alSetError(AL_INVALID_ENUM);
830 break;
833 else if(ALEffect->type == AL_EFFECT_REVERB)
835 switch(param)
837 case AL_REVERB_DECAY_HFLIMIT:
838 alGetEffecti(effect, param, piValues);
839 break;
841 default:
842 alSetError(AL_INVALID_ENUM);
843 break;
846 else if(ALEffect->type == AL_EFFECT_ECHO)
848 switch(param)
850 default:
851 alSetError(AL_INVALID_ENUM);
852 break;
855 else
856 alSetError(AL_INVALID_ENUM);
858 else
859 alSetError(AL_INVALID_NAME);
861 ProcessContext(Context);
864 ALvoid AL_APIENTRY alGetEffectf(ALuint effect, ALenum param, ALfloat *pflValue)
866 ALCcontext *Context;
868 Context = GetContextSuspended();
869 if(!Context) return;
871 if (effect && alIsEffect(effect))
873 ALeffect *ALEffect = (ALeffect*)ALTHUNK_LOOKUPENTRY(effect);
875 if(ALEffect->type == AL_EFFECT_EAXREVERB)
877 switch(param)
879 case AL_EAXREVERB_DENSITY:
880 *pflValue = ALEffect->Reverb.Density;
881 break;
883 case AL_EAXREVERB_DIFFUSION:
884 *pflValue = ALEffect->Reverb.Diffusion;
885 break;
887 case AL_EAXREVERB_GAIN:
888 *pflValue = ALEffect->Reverb.Gain;
889 break;
891 case AL_EAXREVERB_GAINHF:
892 *pflValue = ALEffect->Reverb.GainHF;
893 break;
895 case AL_EAXREVERB_GAINLF:
896 *pflValue = ALEffect->Reverb.GainLF;
897 break;
899 case AL_EAXREVERB_DECAY_TIME:
900 *pflValue = ALEffect->Reverb.DecayTime;
901 break;
903 case AL_EAXREVERB_DECAY_HFRATIO:
904 *pflValue = ALEffect->Reverb.DecayHFRatio;
905 break;
907 case AL_EAXREVERB_DECAY_LFRATIO:
908 *pflValue = ALEffect->Reverb.DecayLFRatio;
909 break;
911 case AL_EAXREVERB_REFLECTIONS_GAIN:
912 *pflValue = ALEffect->Reverb.ReflectionsGain;
913 break;
915 case AL_EAXREVERB_REFLECTIONS_DELAY:
916 *pflValue = ALEffect->Reverb.ReflectionsDelay;
917 break;
919 case AL_EAXREVERB_LATE_REVERB_GAIN:
920 *pflValue = ALEffect->Reverb.LateReverbGain;
921 break;
923 case AL_EAXREVERB_LATE_REVERB_DELAY:
924 *pflValue = ALEffect->Reverb.LateReverbDelay;
925 break;
927 case AL_EAXREVERB_AIR_ABSORPTION_GAINHF:
928 *pflValue = ALEffect->Reverb.AirAbsorptionGainHF;
929 break;
931 case AL_EAXREVERB_ECHO_TIME:
932 *pflValue = ALEffect->Reverb.EchoTime;
933 break;
935 case AL_EAXREVERB_ECHO_DEPTH:
936 *pflValue = ALEffect->Reverb.EchoDepth;
937 break;
939 case AL_EAXREVERB_MODULATION_TIME:
940 *pflValue = ALEffect->Reverb.ModulationTime;
941 break;
943 case AL_EAXREVERB_MODULATION_DEPTH:
944 *pflValue = ALEffect->Reverb.ModulationDepth;
945 break;
947 case AL_EAXREVERB_HFREFERENCE:
948 *pflValue = ALEffect->Reverb.HFReference;
949 break;
951 case AL_EAXREVERB_LFREFERENCE:
952 *pflValue = ALEffect->Reverb.LFReference;
953 break;
955 case AL_EAXREVERB_ROOM_ROLLOFF_FACTOR:
956 *pflValue = ALEffect->Reverb.RoomRolloffFactor;
957 break;
959 default:
960 alSetError(AL_INVALID_ENUM);
961 break;
964 else if(ALEffect->type == AL_EFFECT_REVERB)
966 switch(param)
968 case AL_REVERB_DENSITY:
969 *pflValue = ALEffect->Reverb.Density;
970 break;
972 case AL_REVERB_DIFFUSION:
973 *pflValue = ALEffect->Reverb.Diffusion;
974 break;
976 case AL_REVERB_GAIN:
977 *pflValue = ALEffect->Reverb.Gain;
978 break;
980 case AL_REVERB_GAINHF:
981 *pflValue = ALEffect->Reverb.GainHF;
982 break;
984 case AL_REVERB_DECAY_TIME:
985 *pflValue = ALEffect->Reverb.DecayTime;
986 break;
988 case AL_REVERB_DECAY_HFRATIO:
989 *pflValue = ALEffect->Reverb.DecayHFRatio;
990 break;
992 case AL_REVERB_REFLECTIONS_GAIN:
993 *pflValue = ALEffect->Reverb.ReflectionsGain;
994 break;
996 case AL_REVERB_REFLECTIONS_DELAY:
997 *pflValue = ALEffect->Reverb.ReflectionsDelay;
998 break;
1000 case AL_REVERB_LATE_REVERB_GAIN:
1001 *pflValue = ALEffect->Reverb.LateReverbGain;
1002 break;
1004 case AL_REVERB_LATE_REVERB_DELAY:
1005 *pflValue = ALEffect->Reverb.LateReverbDelay;
1006 break;
1008 case AL_REVERB_AIR_ABSORPTION_GAINHF:
1009 *pflValue = ALEffect->Reverb.AirAbsorptionGainHF;
1010 break;
1012 case AL_REVERB_ROOM_ROLLOFF_FACTOR:
1013 *pflValue = ALEffect->Reverb.RoomRolloffFactor;
1014 break;
1016 default:
1017 alSetError(AL_INVALID_ENUM);
1018 break;
1021 else if(ALEffect->type == AL_EFFECT_ECHO)
1023 switch(param)
1025 case AL_ECHO_DELAY:
1026 *pflValue = ALEffect->Echo.Delay;
1027 break;
1029 case AL_ECHO_LRDELAY:
1030 *pflValue = ALEffect->Echo.LRDelay;
1031 break;
1033 case AL_ECHO_DAMPING:
1034 *pflValue = ALEffect->Echo.Damping;
1035 break;
1037 case AL_ECHO_FEEDBACK:
1038 *pflValue = ALEffect->Echo.Feedback;
1039 break;
1041 case AL_ECHO_SPREAD:
1042 *pflValue = ALEffect->Echo.Spread;
1043 break;
1045 default:
1046 alSetError(AL_INVALID_ENUM);
1047 break;
1050 else
1051 alSetError(AL_INVALID_ENUM);
1053 else
1054 alSetError(AL_INVALID_NAME);
1056 ProcessContext(Context);
1059 ALvoid AL_APIENTRY alGetEffectfv(ALuint effect, ALenum param, ALfloat *pflValues)
1061 ALCcontext *Context;
1063 Context = GetContextSuspended();
1064 if(!Context) return;
1066 if (effect && alIsEffect(effect))
1068 ALeffect *ALEffect = (ALeffect*)ALTHUNK_LOOKUPENTRY(effect);
1070 if(ALEffect->type == AL_EFFECT_EAXREVERB)
1072 switch(param)
1074 case AL_EAXREVERB_DENSITY:
1075 case AL_EAXREVERB_DIFFUSION:
1076 case AL_EAXREVERB_GAIN:
1077 case AL_EAXREVERB_GAINHF:
1078 case AL_EAXREVERB_GAINLF:
1079 case AL_EAXREVERB_DECAY_TIME:
1080 case AL_EAXREVERB_DECAY_HFRATIO:
1081 case AL_EAXREVERB_DECAY_LFRATIO:
1082 case AL_EAXREVERB_REFLECTIONS_GAIN:
1083 case AL_EAXREVERB_REFLECTIONS_DELAY:
1084 case AL_EAXREVERB_LATE_REVERB_GAIN:
1085 case AL_EAXREVERB_LATE_REVERB_DELAY:
1086 case AL_EAXREVERB_AIR_ABSORPTION_GAINHF:
1087 case AL_EAXREVERB_ECHO_TIME:
1088 case AL_EAXREVERB_ECHO_DEPTH:
1089 case AL_EAXREVERB_MODULATION_TIME:
1090 case AL_EAXREVERB_MODULATION_DEPTH:
1091 case AL_EAXREVERB_HFREFERENCE:
1092 case AL_EAXREVERB_LFREFERENCE:
1093 case AL_EAXREVERB_ROOM_ROLLOFF_FACTOR:
1094 alGetEffectf(effect, param, pflValues);
1095 break;
1097 case AL_EAXREVERB_REFLECTIONS_PAN:
1098 pflValues[0] = ALEffect->Reverb.ReflectionsPan[0];
1099 pflValues[1] = ALEffect->Reverb.ReflectionsPan[1];
1100 pflValues[2] = ALEffect->Reverb.ReflectionsPan[2];
1101 break;
1102 case AL_EAXREVERB_LATE_REVERB_PAN:
1103 pflValues[0] = ALEffect->Reverb.LateReverbPan[0];
1104 pflValues[1] = ALEffect->Reverb.LateReverbPan[1];
1105 pflValues[2] = ALEffect->Reverb.LateReverbPan[2];
1106 break;
1108 default:
1109 alSetError(AL_INVALID_ENUM);
1110 break;
1113 else if(ALEffect->type == AL_EFFECT_REVERB)
1115 switch(param)
1117 case AL_REVERB_DENSITY:
1118 case AL_REVERB_DIFFUSION:
1119 case AL_REVERB_GAIN:
1120 case AL_REVERB_GAINHF:
1121 case AL_REVERB_DECAY_TIME:
1122 case AL_REVERB_DECAY_HFRATIO:
1123 case AL_REVERB_REFLECTIONS_GAIN:
1124 case AL_REVERB_REFLECTIONS_DELAY:
1125 case AL_REVERB_LATE_REVERB_GAIN:
1126 case AL_REVERB_LATE_REVERB_DELAY:
1127 case AL_REVERB_AIR_ABSORPTION_GAINHF:
1128 case AL_REVERB_ROOM_ROLLOFF_FACTOR:
1129 alGetEffectf(effect, param, pflValues);
1130 break;
1132 default:
1133 alSetError(AL_INVALID_ENUM);
1134 break;
1137 else if(ALEffect->type == AL_EFFECT_ECHO)
1139 switch(param)
1141 case AL_ECHO_DELAY:
1142 case AL_ECHO_LRDELAY:
1143 case AL_ECHO_DAMPING:
1144 case AL_ECHO_FEEDBACK:
1145 case AL_ECHO_SPREAD:
1146 alGetEffectf(effect, param, pflValues);
1147 break;
1149 default:
1150 alSetError(AL_INVALID_ENUM);
1151 break;
1154 else
1155 alSetError(AL_INVALID_ENUM);
1157 else
1158 alSetError(AL_INVALID_NAME);
1160 ProcessContext(Context);
1164 ALvoid ReleaseALEffects(ALCdevice *device)
1166 ALeffect *list = device->EffectList;
1167 while(list)
1169 ALeffect *temp = list;
1170 list = list->next;
1172 // Release effect structure
1173 memset(temp, 0, sizeof(ALeffect));
1174 free(temp);
1176 device->EffectList = NULL;
1177 device->EffectCount = 0;
1181 static void InitEffectParams(ALeffect *effect, ALenum type)
1183 effect->type = type;
1184 switch(type)
1186 /* NOTE: Standard reverb and EAX reverb use the same defaults for the
1187 * shared parameters, and EAX's additional parameters default to
1188 * values assumed by standard reverb.
1190 case AL_EFFECT_EAXREVERB:
1191 case AL_EFFECT_REVERB:
1192 effect->Reverb.Density = AL_EAXREVERB_DEFAULT_DENSITY;
1193 effect->Reverb.Diffusion = AL_EAXREVERB_DEFAULT_DIFFUSION;
1194 effect->Reverb.Gain = AL_EAXREVERB_DEFAULT_GAIN;
1195 effect->Reverb.GainHF = AL_EAXREVERB_DEFAULT_GAINHF;
1196 effect->Reverb.GainLF = AL_EAXREVERB_DEFAULT_GAINLF;
1197 effect->Reverb.DecayTime = AL_EAXREVERB_DEFAULT_DECAY_TIME;
1198 effect->Reverb.DecayHFRatio = AL_EAXREVERB_DEFAULT_DECAY_HFRATIO;
1199 effect->Reverb.DecayLFRatio = AL_EAXREVERB_DEFAULT_DECAY_LFRATIO;
1200 effect->Reverb.ReflectionsGain = AL_EAXREVERB_DEFAULT_REFLECTIONS_GAIN;
1201 effect->Reverb.ReflectionsDelay = AL_EAXREVERB_DEFAULT_REFLECTIONS_DELAY;
1202 effect->Reverb.ReflectionsPan[0] = AL_EAXREVERB_DEFAULT_REFLECTIONS_PAN_XYZ;
1203 effect->Reverb.ReflectionsPan[1] = AL_EAXREVERB_DEFAULT_REFLECTIONS_PAN_XYZ;
1204 effect->Reverb.ReflectionsPan[2] = AL_EAXREVERB_DEFAULT_REFLECTIONS_PAN_XYZ;
1205 effect->Reverb.LateReverbGain = AL_EAXREVERB_DEFAULT_LATE_REVERB_GAIN;
1206 effect->Reverb.LateReverbDelay = AL_EAXREVERB_DEFAULT_LATE_REVERB_DELAY;
1207 effect->Reverb.LateReverbPan[0] = AL_EAXREVERB_DEFAULT_LATE_REVERB_PAN_XYZ;
1208 effect->Reverb.LateReverbPan[1] = AL_EAXREVERB_DEFAULT_LATE_REVERB_PAN_XYZ;
1209 effect->Reverb.LateReverbPan[2] = AL_EAXREVERB_DEFAULT_LATE_REVERB_PAN_XYZ;
1210 effect->Reverb.EchoTime = AL_EAXREVERB_DEFAULT_ECHO_TIME;
1211 effect->Reverb.EchoDepth = AL_EAXREVERB_DEFAULT_ECHO_DEPTH;
1212 effect->Reverb.ModulationTime = AL_EAXREVERB_DEFAULT_MODULATION_TIME;
1213 effect->Reverb.ModulationDepth = AL_EAXREVERB_DEFAULT_MODULATION_DEPTH;
1214 effect->Reverb.AirAbsorptionGainHF = AL_EAXREVERB_DEFAULT_AIR_ABSORPTION_GAINHF;
1215 effect->Reverb.HFReference = AL_EAXREVERB_DEFAULT_HFREFERENCE;
1216 effect->Reverb.LFReference = AL_EAXREVERB_DEFAULT_LFREFERENCE;
1217 effect->Reverb.RoomRolloffFactor = AL_EAXREVERB_DEFAULT_ROOM_ROLLOFF_FACTOR;
1218 effect->Reverb.DecayHFLimit = AL_EAXREVERB_DEFAULT_DECAY_HFLIMIT;
1219 break;
1220 case AL_EFFECT_ECHO:
1221 effect->Echo.Delay = AL_ECHO_DEFAULT_DELAY;
1222 effect->Echo.LRDelay = AL_ECHO_DEFAULT_LRDELAY;
1223 effect->Echo.Damping = AL_ECHO_DEFAULT_DAMPING;
1224 effect->Echo.Feedback = AL_ECHO_DEFAULT_FEEDBACK;
1225 effect->Echo.Spread = AL_ECHO_DEFAULT_SPREAD;
1226 break;