Reorder some cmake checks
[openal-soft.git] / OpenAL32 / alFilter.c
blob3cf82c32c8978cca9ceafad3fe0cb83904849256
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.,
17 * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
18 * Or go to http://www.gnu.org/copyleft/lgpl.html
21 #include "config.h"
23 #include <stdlib.h>
25 #include "alMain.h"
26 #include "alu.h"
27 #include "alFilter.h"
28 #include "alThunk.h"
29 #include "alError.h"
32 extern inline struct ALfilter *LookupFilter(ALCdevice *device, ALuint id);
33 extern inline struct ALfilter *RemoveFilter(ALCdevice *device, ALuint id);
34 extern inline ALfloat ALfilterState_processSingle(ALfilterState *filter, ALfloat sample);
35 extern inline ALfloat calc_rcpQ_from_slope(ALfloat gain, ALfloat slope);
36 extern inline ALfloat calc_rcpQ_from_bandwidth(ALfloat freq_mult, ALfloat bandwidth);
38 static void InitFilterParams(ALfilter *filter, ALenum type);
41 AL_API ALvoid AL_APIENTRY alGenFilters(ALsizei n, ALuint *filters)
43 ALCdevice *device;
44 ALCcontext *context;
45 ALsizei cur = 0;
46 ALenum err;
48 context = GetContextRef();
49 if(!context) return;
51 if(!(n >= 0))
52 SET_ERROR_AND_GOTO(context, AL_INVALID_VALUE, done);
54 device = context->Device;
55 for(cur = 0;cur < n;cur++)
57 ALfilter *filter = calloc(1, sizeof(ALfilter));
58 if(!filter)
60 alDeleteFilters(cur, filters);
61 SET_ERROR_AND_GOTO(context, AL_OUT_OF_MEMORY, done);
63 InitFilterParams(filter, AL_FILTER_NULL);
65 err = NewThunkEntry(&filter->id);
66 if(err == AL_NO_ERROR)
67 err = InsertUIntMapEntry(&device->FilterMap, filter->id, filter);
68 if(err != AL_NO_ERROR)
70 FreeThunkEntry(filter->id);
71 memset(filter, 0, sizeof(ALfilter));
72 free(filter);
74 alDeleteFilters(cur, filters);
75 SET_ERROR_AND_GOTO(context, err, done);
78 filters[cur] = filter->id;
81 done:
82 ALCcontext_DecRef(context);
85 AL_API ALvoid AL_APIENTRY alDeleteFilters(ALsizei n, const ALuint *filters)
87 ALCdevice *device;
88 ALCcontext *context;
89 ALfilter *filter;
90 ALsizei i;
92 context = GetContextRef();
93 if(!context) return;
95 if(!(n >= 0))
96 SET_ERROR_AND_GOTO(context, AL_INVALID_VALUE, done);
98 device = context->Device;
99 for(i = 0;i < n;i++)
101 if(filters[i] && LookupFilter(device, filters[i]) == NULL)
102 SET_ERROR_AND_GOTO(context, AL_INVALID_NAME, done);
104 for(i = 0;i < n;i++)
106 if((filter=RemoveFilter(device, filters[i])) == NULL)
107 continue;
108 FreeThunkEntry(filter->id);
110 memset(filter, 0, sizeof(*filter));
111 free(filter);
114 done:
115 ALCcontext_DecRef(context);
118 AL_API ALboolean AL_APIENTRY alIsFilter(ALuint filter)
120 ALCcontext *Context;
121 ALboolean result;
123 Context = GetContextRef();
124 if(!Context) return AL_FALSE;
126 result = ((!filter || LookupFilter(Context->Device, filter)) ?
127 AL_TRUE : AL_FALSE);
129 ALCcontext_DecRef(Context);
131 return result;
134 AL_API ALvoid AL_APIENTRY alFilteri(ALuint filter, ALenum param, ALint value)
136 ALCcontext *Context;
137 ALCdevice *Device;
138 ALfilter *ALFilter;
140 Context = GetContextRef();
141 if(!Context) return;
143 Device = Context->Device;
144 if((ALFilter=LookupFilter(Device, filter)) == NULL)
145 alSetError(Context, AL_INVALID_NAME);
146 else
148 if(param == AL_FILTER_TYPE)
150 if(value == AL_FILTER_NULL || value == AL_FILTER_LOWPASS ||
151 value == AL_FILTER_HIGHPASS || value == AL_FILTER_BANDPASS)
152 InitFilterParams(ALFilter, value);
153 else
154 alSetError(Context, AL_INVALID_VALUE);
156 else
158 /* Call the appropriate handler */
159 ALfilter_SetParami(ALFilter, Context, param, value);
163 ALCcontext_DecRef(Context);
166 AL_API ALvoid AL_APIENTRY alFilteriv(ALuint filter, ALenum param, const ALint *values)
168 ALCcontext *Context;
169 ALCdevice *Device;
170 ALfilter *ALFilter;
172 switch(param)
174 case AL_FILTER_TYPE:
175 alFilteri(filter, param, values[0]);
176 return;
179 Context = GetContextRef();
180 if(!Context) return;
182 Device = Context->Device;
183 if((ALFilter=LookupFilter(Device, filter)) == NULL)
184 alSetError(Context, AL_INVALID_NAME);
185 else
187 /* Call the appropriate handler */
188 ALfilter_SetParamiv(ALFilter, Context, param, values);
191 ALCcontext_DecRef(Context);
194 AL_API ALvoid AL_APIENTRY alFilterf(ALuint filter, ALenum param, ALfloat value)
196 ALCcontext *Context;
197 ALCdevice *Device;
198 ALfilter *ALFilter;
200 Context = GetContextRef();
201 if(!Context) return;
203 Device = Context->Device;
204 if((ALFilter=LookupFilter(Device, filter)) == NULL)
205 alSetError(Context, AL_INVALID_NAME);
206 else
208 /* Call the appropriate handler */
209 ALfilter_SetParamf(ALFilter, Context, param, value);
212 ALCcontext_DecRef(Context);
215 AL_API ALvoid AL_APIENTRY alFilterfv(ALuint filter, ALenum param, const ALfloat *values)
217 ALCcontext *Context;
218 ALCdevice *Device;
219 ALfilter *ALFilter;
221 Context = GetContextRef();
222 if(!Context) return;
224 Device = Context->Device;
225 if((ALFilter=LookupFilter(Device, filter)) == NULL)
226 alSetError(Context, AL_INVALID_NAME);
227 else
229 /* Call the appropriate handler */
230 ALfilter_SetParamfv(ALFilter, Context, param, values);
233 ALCcontext_DecRef(Context);
236 AL_API ALvoid AL_APIENTRY alGetFilteri(ALuint filter, ALenum param, ALint *value)
238 ALCcontext *Context;
239 ALCdevice *Device;
240 ALfilter *ALFilter;
242 Context = GetContextRef();
243 if(!Context) return;
245 Device = Context->Device;
246 if((ALFilter=LookupFilter(Device, filter)) == NULL)
247 alSetError(Context, AL_INVALID_NAME);
248 else
250 if(param == AL_FILTER_TYPE)
251 *value = ALFilter->type;
252 else
254 /* Call the appropriate handler */
255 ALfilter_GetParami(ALFilter, Context, param, value);
259 ALCcontext_DecRef(Context);
262 AL_API ALvoid AL_APIENTRY alGetFilteriv(ALuint filter, ALenum param, ALint *values)
264 ALCcontext *Context;
265 ALCdevice *Device;
266 ALfilter *ALFilter;
268 switch(param)
270 case AL_FILTER_TYPE:
271 alGetFilteri(filter, param, values);
272 return;
275 Context = GetContextRef();
276 if(!Context) return;
278 Device = Context->Device;
279 if((ALFilter=LookupFilter(Device, filter)) == NULL)
280 alSetError(Context, AL_INVALID_NAME);
281 else
283 /* Call the appropriate handler */
284 ALfilter_GetParamiv(ALFilter, Context, param, values);
287 ALCcontext_DecRef(Context);
290 AL_API ALvoid AL_APIENTRY alGetFilterf(ALuint filter, ALenum param, ALfloat *value)
292 ALCcontext *Context;
293 ALCdevice *Device;
294 ALfilter *ALFilter;
296 Context = GetContextRef();
297 if(!Context) return;
299 Device = Context->Device;
300 if((ALFilter=LookupFilter(Device, filter)) == NULL)
301 alSetError(Context, AL_INVALID_NAME);
302 else
304 /* Call the appropriate handler */
305 ALfilter_GetParamf(ALFilter, Context, param, value);
308 ALCcontext_DecRef(Context);
311 AL_API ALvoid AL_APIENTRY alGetFilterfv(ALuint filter, ALenum param, ALfloat *values)
313 ALCcontext *Context;
314 ALCdevice *Device;
315 ALfilter *ALFilter;
317 Context = GetContextRef();
318 if(!Context) return;
320 Device = Context->Device;
321 if((ALFilter=LookupFilter(Device, filter)) == NULL)
322 alSetError(Context, AL_INVALID_NAME);
323 else
325 /* Call the appropriate handler */
326 ALfilter_GetParamfv(ALFilter, Context, param, values);
329 ALCcontext_DecRef(Context);
333 void ALfilterState_clear(ALfilterState *filter)
335 filter->x[0] = 0.0f;
336 filter->x[1] = 0.0f;
337 filter->y[0] = 0.0f;
338 filter->y[1] = 0.0f;
341 void ALfilterState_setParams(ALfilterState *filter, ALfilterType type, ALfloat gain, ALfloat freq_mult, ALfloat rcpQ)
343 ALfloat alpha, sqrtgain_alpha_2;
344 ALfloat w0, sin_w0, cos_w0;
346 // Limit gain to -100dB
347 gain = maxf(gain, 0.00001f);
349 w0 = F_TAU * freq_mult;
350 sin_w0 = sinf(w0);
351 cos_w0 = cosf(w0);
352 alpha = sin_w0/2.0f * rcpQ;
354 /* Calculate filter coefficients depending on filter type */
355 switch(type)
357 case ALfilterType_HighShelf:
358 sqrtgain_alpha_2 = 2.0f * sqrtf(gain) * alpha;
359 filter->b[0] = gain*((gain+1.0f) + (gain-1.0f)*cos_w0 + sqrtgain_alpha_2);
360 filter->b[1] = -2.0f*gain*((gain-1.0f) + (gain+1.0f)*cos_w0 );
361 filter->b[2] = gain*((gain+1.0f) + (gain-1.0f)*cos_w0 - sqrtgain_alpha_2);
362 filter->a[0] = (gain+1.0f) - (gain-1.0f)*cos_w0 + sqrtgain_alpha_2;
363 filter->a[1] = 2.0f* ((gain-1.0f) - (gain+1.0f)*cos_w0 );
364 filter->a[2] = (gain+1.0f) - (gain-1.0f)*cos_w0 - sqrtgain_alpha_2;
365 break;
366 case ALfilterType_LowShelf:
367 sqrtgain_alpha_2 = 2.0f * sqrtf(gain) * alpha;
368 filter->b[0] = gain*((gain+1.0f) - (gain-1.0f)*cos_w0 + sqrtgain_alpha_2);
369 filter->b[1] = 2.0f*gain*((gain-1.0f) - (gain+1.0f)*cos_w0 );
370 filter->b[2] = gain*((gain+1.0f) - (gain-1.0f)*cos_w0 - sqrtgain_alpha_2);
371 filter->a[0] = (gain+1.0f) + (gain-1.0f)*cos_w0 + sqrtgain_alpha_2;
372 filter->a[1] = -2.0f* ((gain-1.0f) + (gain+1.0f)*cos_w0 );
373 filter->a[2] = (gain+1.0f) + (gain-1.0f)*cos_w0 - sqrtgain_alpha_2;
374 break;
375 case ALfilterType_Peaking:
376 gain = sqrtf(gain);
377 filter->b[0] = 1.0f + alpha * gain;
378 filter->b[1] = -2.0f * cos_w0;
379 filter->b[2] = 1.0f - alpha * gain;
380 filter->a[0] = 1.0f + alpha / gain;
381 filter->a[1] = -2.0f * cos_w0;
382 filter->a[2] = 1.0f - alpha / gain;
383 break;
385 case ALfilterType_LowPass:
386 filter->b[0] = (1.0f - cos_w0) / 2.0f;
387 filter->b[1] = 1.0f - cos_w0;
388 filter->b[2] = (1.0f - cos_w0) / 2.0f;
389 filter->a[0] = 1.0f + alpha;
390 filter->a[1] = -2.0f * cos_w0;
391 filter->a[2] = 1.0f - alpha;
392 break;
393 case ALfilterType_HighPass:
394 filter->b[0] = (1.0f + cos_w0) / 2.0f;
395 filter->b[1] = -(1.0f + cos_w0);
396 filter->b[2] = (1.0f + cos_w0) / 2.0f;
397 filter->a[0] = 1.0f + alpha;
398 filter->a[1] = -2.0f * cos_w0;
399 filter->a[2] = 1.0f - alpha;
400 break;
401 case ALfilterType_BandPass:
402 filter->b[0] = alpha;
403 filter->b[1] = 0;
404 filter->b[2] = -alpha;
405 filter->a[0] = 1.0f + alpha;
406 filter->a[1] = -2.0f * cos_w0;
407 filter->a[2] = 1.0f - alpha;
408 break;
411 filter->b[2] /= filter->a[0];
412 filter->b[1] /= filter->a[0];
413 filter->b[0] /= filter->a[0];
414 filter->a[2] /= filter->a[0];
415 filter->a[1] /= filter->a[0];
416 filter->a[0] /= filter->a[0];
418 filter->process = ALfilterState_processC;
421 void ALfilterState_processPassthru(ALfilterState *filter, const ALfloat *src, ALuint numsamples)
423 if(numsamples >= 2)
425 filter->x[1] = src[numsamples-2];
426 filter->x[0] = src[numsamples-1];
427 filter->y[1] = src[numsamples-2];
428 filter->y[0] = src[numsamples-1];
430 else if(numsamples == 1)
432 filter->x[1] = filter->x[0];
433 filter->x[0] = src[0];
434 filter->y[1] = filter->y[0];
435 filter->y[0] = src[0];
440 static void lp_SetParami(ALfilter *UNUSED(filter), ALCcontext *context, ALenum UNUSED(param), ALint UNUSED(val))
441 { SET_ERROR_AND_RETURN(context, AL_INVALID_ENUM); }
442 static void lp_SetParamiv(ALfilter *UNUSED(filter), ALCcontext *context, ALenum UNUSED(param), const ALint *UNUSED(vals))
443 { SET_ERROR_AND_RETURN(context, AL_INVALID_ENUM); }
444 static void lp_SetParamf(ALfilter *filter, ALCcontext *context, ALenum param, ALfloat val)
446 switch(param)
448 case AL_LOWPASS_GAIN:
449 if(!(val >= AL_LOWPASS_MIN_GAIN && val <= AL_LOWPASS_MAX_GAIN))
450 SET_ERROR_AND_RETURN(context, AL_INVALID_VALUE);
451 filter->Gain = val;
452 break;
454 case AL_LOWPASS_GAINHF:
455 if(!(val >= AL_LOWPASS_MIN_GAINHF && val <= AL_LOWPASS_MAX_GAINHF))
456 SET_ERROR_AND_RETURN(context, AL_INVALID_VALUE);
457 filter->GainHF = val;
458 break;
460 default:
461 SET_ERROR_AND_RETURN(context, AL_INVALID_ENUM);
464 static void lp_SetParamfv(ALfilter *filter, ALCcontext *context, ALenum param, const ALfloat *vals)
466 lp_SetParamf(filter, context, param, vals[0]);
469 static void lp_GetParami(ALfilter *UNUSED(filter), ALCcontext *context, ALenum UNUSED(param), ALint *UNUSED(val))
470 { SET_ERROR_AND_RETURN(context, AL_INVALID_ENUM); }
471 static void lp_GetParamiv(ALfilter *UNUSED(filter), ALCcontext *context, ALenum UNUSED(param), ALint *UNUSED(vals))
472 { SET_ERROR_AND_RETURN(context, AL_INVALID_ENUM); }
473 static void lp_GetParamf(ALfilter *filter, ALCcontext *context, ALenum param, ALfloat *val)
475 switch(param)
477 case AL_LOWPASS_GAIN:
478 *val = filter->Gain;
479 break;
481 case AL_LOWPASS_GAINHF:
482 *val = filter->GainHF;
483 break;
485 default:
486 SET_ERROR_AND_RETURN(context, AL_INVALID_ENUM);
489 static void lp_GetParamfv(ALfilter *filter, ALCcontext *context, ALenum param, ALfloat *vals)
491 lp_GetParamf(filter, context, param, vals);
495 static void hp_SetParami(ALfilter *UNUSED(filter), ALCcontext *context, ALenum UNUSED(param), ALint UNUSED(val))
496 { SET_ERROR_AND_RETURN(context, AL_INVALID_ENUM); }
497 static void hp_SetParamiv(ALfilter *UNUSED(filter), ALCcontext *context, ALenum UNUSED(param), const ALint *UNUSED(vals))
498 { SET_ERROR_AND_RETURN(context, AL_INVALID_ENUM); }
499 static void hp_SetParamf(ALfilter *filter, ALCcontext *context, ALenum param, ALfloat val)
501 switch(param)
503 case AL_HIGHPASS_GAIN:
504 if(!(val >= AL_HIGHPASS_MIN_GAIN && val <= AL_HIGHPASS_MAX_GAIN))
505 SET_ERROR_AND_RETURN(context, AL_INVALID_VALUE);
506 filter->Gain = val;
507 break;
509 case AL_HIGHPASS_GAINLF:
510 if(!(val >= AL_HIGHPASS_MIN_GAINLF && val <= AL_HIGHPASS_MAX_GAINLF))
511 SET_ERROR_AND_RETURN(context, AL_INVALID_VALUE);
512 filter->GainLF = val;
513 break;
515 default:
516 SET_ERROR_AND_RETURN(context, AL_INVALID_ENUM);
519 static void hp_SetParamfv(ALfilter *filter, ALCcontext *context, ALenum param, const ALfloat *vals)
521 hp_SetParamf(filter, context, param, vals[0]);
524 static void hp_GetParami(ALfilter *UNUSED(filter), ALCcontext *context, ALenum UNUSED(param), ALint *UNUSED(val))
525 { SET_ERROR_AND_RETURN(context, AL_INVALID_ENUM); }
526 static void hp_GetParamiv(ALfilter *UNUSED(filter), ALCcontext *context, ALenum UNUSED(param), ALint *UNUSED(vals))
527 { SET_ERROR_AND_RETURN(context, AL_INVALID_ENUM); }
528 static void hp_GetParamf(ALfilter *filter, ALCcontext *context, ALenum param, ALfloat *val)
530 switch(param)
532 case AL_HIGHPASS_GAIN:
533 *val = filter->Gain;
534 break;
536 case AL_HIGHPASS_GAINLF:
537 *val = filter->GainLF;
538 break;
540 default:
541 SET_ERROR_AND_RETURN(context, AL_INVALID_ENUM);
544 static void hp_GetParamfv(ALfilter *filter, ALCcontext *context, ALenum param, ALfloat *vals)
546 hp_GetParamf(filter, context, param, vals);
550 static void bp_SetParami(ALfilter *UNUSED(filter), ALCcontext *context, ALenum UNUSED(param), ALint UNUSED(val))
551 { SET_ERROR_AND_RETURN(context, AL_INVALID_ENUM); }
552 static void bp_SetParamiv(ALfilter *UNUSED(filter), ALCcontext *context, ALenum UNUSED(param), const ALint *UNUSED(vals))
553 { SET_ERROR_AND_RETURN(context, AL_INVALID_ENUM); }
554 static void bp_SetParamf(ALfilter *filter, ALCcontext *context, ALenum param, ALfloat val)
556 switch(param)
558 case AL_BANDPASS_GAIN:
559 if(!(val >= AL_BANDPASS_MIN_GAIN && val <= AL_BANDPASS_MAX_GAIN))
560 SET_ERROR_AND_RETURN(context, AL_INVALID_VALUE);
561 filter->Gain = val;
562 break;
564 case AL_BANDPASS_GAINHF:
565 if(!(val >= AL_BANDPASS_MIN_GAINHF && val <= AL_BANDPASS_MAX_GAINHF))
566 SET_ERROR_AND_RETURN(context, AL_INVALID_VALUE);
567 filter->GainHF = val;
568 break;
570 case AL_BANDPASS_GAINLF:
571 if(!(val >= AL_BANDPASS_MIN_GAINLF && val <= AL_BANDPASS_MAX_GAINLF))
572 SET_ERROR_AND_RETURN(context, AL_INVALID_VALUE);
573 filter->GainLF = val;
574 break;
576 default:
577 SET_ERROR_AND_RETURN(context, AL_INVALID_ENUM);
580 static void bp_SetParamfv(ALfilter *filter, ALCcontext *context, ALenum param, const ALfloat *vals)
582 bp_SetParamf(filter, context, param, vals[0]);
585 static void bp_GetParami(ALfilter *UNUSED(filter), ALCcontext *context, ALenum UNUSED(param), ALint *UNUSED(val))
586 { SET_ERROR_AND_RETURN(context, AL_INVALID_ENUM); }
587 static void bp_GetParamiv(ALfilter *UNUSED(filter), ALCcontext *context, ALenum UNUSED(param), ALint *UNUSED(vals))
588 { SET_ERROR_AND_RETURN(context, AL_INVALID_ENUM); }
589 static void bp_GetParamf(ALfilter *filter, ALCcontext *context, ALenum param, ALfloat *val)
591 switch(param)
593 case AL_BANDPASS_GAIN:
594 *val = filter->Gain;
595 break;
597 case AL_BANDPASS_GAINHF:
598 *val = filter->GainHF;
599 break;
601 case AL_BANDPASS_GAINLF:
602 *val = filter->GainLF;
603 break;
605 default:
606 SET_ERROR_AND_RETURN(context, AL_INVALID_ENUM);
609 static void bp_GetParamfv(ALfilter *filter, ALCcontext *context, ALenum param, ALfloat *vals)
611 bp_GetParamf(filter, context, param, vals);
615 static void null_SetParami(ALfilter *UNUSED(filter), ALCcontext *context, ALenum UNUSED(param), ALint UNUSED(val))
616 { SET_ERROR_AND_RETURN(context, AL_INVALID_ENUM); }
617 static void null_SetParamiv(ALfilter *UNUSED(filter), ALCcontext *context, ALenum UNUSED(param), const ALint *UNUSED(vals))
618 { SET_ERROR_AND_RETURN(context, AL_INVALID_ENUM); }
619 static void null_SetParamf(ALfilter *UNUSED(filter), ALCcontext *context, ALenum UNUSED(param), ALfloat UNUSED(val))
620 { SET_ERROR_AND_RETURN(context, AL_INVALID_ENUM); }
621 static void null_SetParamfv(ALfilter *UNUSED(filter), ALCcontext *context, ALenum UNUSED(param), const ALfloat *UNUSED(vals))
622 { SET_ERROR_AND_RETURN(context, AL_INVALID_ENUM); }
624 static void null_GetParami(ALfilter *UNUSED(filter), ALCcontext *context, ALenum UNUSED(param), ALint *UNUSED(val))
625 { SET_ERROR_AND_RETURN(context, AL_INVALID_ENUM); }
626 static void null_GetParamiv(ALfilter *UNUSED(filter), ALCcontext *context, ALenum UNUSED(param), ALint *UNUSED(vals))
627 { SET_ERROR_AND_RETURN(context, AL_INVALID_ENUM); }
628 static void null_GetParamf(ALfilter *UNUSED(filter), ALCcontext *context, ALenum UNUSED(param), ALfloat *UNUSED(val))
629 { SET_ERROR_AND_RETURN(context, AL_INVALID_ENUM); }
630 static void null_GetParamfv(ALfilter *UNUSED(filter), ALCcontext *context, ALenum UNUSED(param), ALfloat *UNUSED(vals))
631 { SET_ERROR_AND_RETURN(context, AL_INVALID_ENUM); }
634 ALvoid ReleaseALFilters(ALCdevice *device)
636 ALsizei i;
637 for(i = 0;i < device->FilterMap.size;i++)
639 ALfilter *temp = device->FilterMap.array[i].value;
640 device->FilterMap.array[i].value = NULL;
642 // Release filter structure
643 FreeThunkEntry(temp->id);
644 memset(temp, 0, sizeof(ALfilter));
645 free(temp);
650 static void InitFilterParams(ALfilter *filter, ALenum type)
652 if(type == AL_FILTER_LOWPASS)
654 filter->Gain = AL_LOWPASS_DEFAULT_GAIN;
655 filter->GainHF = AL_LOWPASS_DEFAULT_GAINHF;
656 filter->HFReference = LOWPASSFREQREF;
657 filter->GainLF = 1.0f;
658 filter->LFReference = HIGHPASSFREQREF;
660 filter->SetParami = lp_SetParami;
661 filter->SetParamiv = lp_SetParamiv;
662 filter->SetParamf = lp_SetParamf;
663 filter->SetParamfv = lp_SetParamfv;
664 filter->GetParami = lp_GetParami;
665 filter->GetParamiv = lp_GetParamiv;
666 filter->GetParamf = lp_GetParamf;
667 filter->GetParamfv = lp_GetParamfv;
669 else if(type == AL_FILTER_HIGHPASS)
671 filter->Gain = AL_HIGHPASS_DEFAULT_GAIN;
672 filter->GainHF = 1.0f;
673 filter->HFReference = LOWPASSFREQREF;
674 filter->GainLF = AL_HIGHPASS_DEFAULT_GAINLF;
675 filter->LFReference = HIGHPASSFREQREF;
677 filter->SetParami = hp_SetParami;
678 filter->SetParamiv = hp_SetParamiv;
679 filter->SetParamf = hp_SetParamf;
680 filter->SetParamfv = hp_SetParamfv;
681 filter->GetParami = hp_GetParami;
682 filter->GetParamiv = hp_GetParamiv;
683 filter->GetParamf = hp_GetParamf;
684 filter->GetParamfv = hp_GetParamfv;
686 else if(type == AL_FILTER_BANDPASS)
688 filter->Gain = AL_BANDPASS_DEFAULT_GAIN;
689 filter->GainHF = AL_BANDPASS_DEFAULT_GAINHF;
690 filter->HFReference = LOWPASSFREQREF;
691 filter->GainLF = AL_BANDPASS_DEFAULT_GAINLF;
692 filter->LFReference = HIGHPASSFREQREF;
694 filter->SetParami = bp_SetParami;
695 filter->SetParamiv = bp_SetParamiv;
696 filter->SetParamf = bp_SetParamf;
697 filter->SetParamfv = bp_SetParamfv;
698 filter->GetParami = bp_GetParami;
699 filter->GetParamiv = bp_GetParamiv;
700 filter->GetParamf = bp_GetParamf;
701 filter->GetParamfv = bp_GetParamfv;
703 else
705 filter->Gain = 1.0f;
706 filter->GainHF = 1.0f;
707 filter->HFReference = LOWPASSFREQREF;
708 filter->GainLF = 1.0f;
709 filter->LFReference = HIGHPASSFREQREF;
711 filter->SetParami = null_SetParami;
712 filter->SetParamiv = null_SetParamiv;
713 filter->SetParamf = null_SetParamf;
714 filter->SetParamfv = null_SetParamfv;
715 filter->GetParami = null_GetParami;
716 filter->GetParamiv = null_GetParamiv;
717 filter->GetParamf = null_GetParamf;
718 filter->GetParamfv = null_GetParamfv;
720 filter->type = type;