Swap delta and step, remove double semicolons
[openal-soft.git] / OpenAL32 / alFilter.c
blob9e10595ae710a232020b5bc9ce4197763fe3a72b
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);
36 static void InitFilterParams(ALfilter *filter, ALenum type);
39 AL_API ALvoid AL_APIENTRY alGenFilters(ALsizei n, ALuint *filters)
41 ALCdevice *device;
42 ALCcontext *context;
43 ALsizei cur = 0;
44 ALenum err;
46 context = GetContextRef();
47 if(!context) return;
49 if(!(n >= 0))
50 SET_ERROR_AND_GOTO(context, AL_INVALID_VALUE, done);
52 device = context->Device;
53 for(cur = 0;cur < n;cur++)
55 ALfilter *filter = calloc(1, sizeof(ALfilter));
56 if(!filter)
58 alDeleteFilters(cur, filters);
59 SET_ERROR_AND_GOTO(context, AL_OUT_OF_MEMORY, done);
61 InitFilterParams(filter, AL_FILTER_NULL);
63 err = NewThunkEntry(&filter->id);
64 if(err == AL_NO_ERROR)
65 err = InsertUIntMapEntry(&device->FilterMap, filter->id, filter);
66 if(err != AL_NO_ERROR)
68 FreeThunkEntry(filter->id);
69 memset(filter, 0, sizeof(ALfilter));
70 free(filter);
72 alDeleteFilters(cur, filters);
73 SET_ERROR_AND_GOTO(context, err, done);
76 filters[cur] = filter->id;
79 done:
80 ALCcontext_DecRef(context);
83 AL_API ALvoid AL_APIENTRY alDeleteFilters(ALsizei n, const ALuint *filters)
85 ALCdevice *device;
86 ALCcontext *context;
87 ALfilter *filter;
88 ALsizei i;
90 context = GetContextRef();
91 if(!context) return;
93 if(!(n >= 0))
94 SET_ERROR_AND_GOTO(context, AL_INVALID_VALUE, done);
96 device = context->Device;
97 for(i = 0;i < n;i++)
99 if(filters[i] && LookupFilter(device, filters[i]) == NULL)
100 SET_ERROR_AND_GOTO(context, AL_INVALID_NAME, done);
102 for(i = 0;i < n;i++)
104 if((filter=RemoveFilter(device, filters[i])) == NULL)
105 continue;
106 FreeThunkEntry(filter->id);
108 memset(filter, 0, sizeof(*filter));
109 free(filter);
112 done:
113 ALCcontext_DecRef(context);
116 AL_API ALboolean AL_APIENTRY alIsFilter(ALuint filter)
118 ALCcontext *Context;
119 ALboolean result;
121 Context = GetContextRef();
122 if(!Context) return AL_FALSE;
124 result = ((!filter || LookupFilter(Context->Device, filter)) ?
125 AL_TRUE : AL_FALSE);
127 ALCcontext_DecRef(Context);
129 return result;
132 AL_API ALvoid AL_APIENTRY alFilteri(ALuint filter, ALenum param, ALint value)
134 ALCcontext *Context;
135 ALCdevice *Device;
136 ALfilter *ALFilter;
138 Context = GetContextRef();
139 if(!Context) return;
141 Device = Context->Device;
142 if((ALFilter=LookupFilter(Device, filter)) == NULL)
143 alSetError(Context, AL_INVALID_NAME);
144 else
146 if(param == AL_FILTER_TYPE)
148 if(value == AL_FILTER_NULL || value == AL_FILTER_LOWPASS ||
149 value == AL_FILTER_HIGHPASS || value == AL_FILTER_BANDPASS)
150 InitFilterParams(ALFilter, value);
151 else
152 alSetError(Context, AL_INVALID_VALUE);
154 else
156 /* Call the appropriate handler */
157 ALfilter_SetParami(ALFilter, Context, param, value);
161 ALCcontext_DecRef(Context);
164 AL_API ALvoid AL_APIENTRY alFilteriv(ALuint filter, ALenum param, const ALint *values)
166 ALCcontext *Context;
167 ALCdevice *Device;
168 ALfilter *ALFilter;
170 switch(param)
172 case AL_FILTER_TYPE:
173 alFilteri(filter, param, values[0]);
174 return;
177 Context = GetContextRef();
178 if(!Context) return;
180 Device = Context->Device;
181 if((ALFilter=LookupFilter(Device, filter)) == NULL)
182 alSetError(Context, AL_INVALID_NAME);
183 else
185 /* Call the appropriate handler */
186 ALfilter_SetParamiv(ALFilter, Context, param, values);
189 ALCcontext_DecRef(Context);
192 AL_API ALvoid AL_APIENTRY alFilterf(ALuint filter, ALenum param, ALfloat value)
194 ALCcontext *Context;
195 ALCdevice *Device;
196 ALfilter *ALFilter;
198 Context = GetContextRef();
199 if(!Context) return;
201 Device = Context->Device;
202 if((ALFilter=LookupFilter(Device, filter)) == NULL)
203 alSetError(Context, AL_INVALID_NAME);
204 else
206 /* Call the appropriate handler */
207 ALfilter_SetParamf(ALFilter, Context, param, value);
210 ALCcontext_DecRef(Context);
213 AL_API ALvoid AL_APIENTRY alFilterfv(ALuint filter, ALenum param, const ALfloat *values)
215 ALCcontext *Context;
216 ALCdevice *Device;
217 ALfilter *ALFilter;
219 Context = GetContextRef();
220 if(!Context) return;
222 Device = Context->Device;
223 if((ALFilter=LookupFilter(Device, filter)) == NULL)
224 alSetError(Context, AL_INVALID_NAME);
225 else
227 /* Call the appropriate handler */
228 ALfilter_SetParamfv(ALFilter, Context, param, values);
231 ALCcontext_DecRef(Context);
234 AL_API ALvoid AL_APIENTRY alGetFilteri(ALuint filter, ALenum param, ALint *value)
236 ALCcontext *Context;
237 ALCdevice *Device;
238 ALfilter *ALFilter;
240 Context = GetContextRef();
241 if(!Context) return;
243 Device = Context->Device;
244 if((ALFilter=LookupFilter(Device, filter)) == NULL)
245 alSetError(Context, AL_INVALID_NAME);
246 else
248 if(param == AL_FILTER_TYPE)
249 *value = ALFilter->type;
250 else
252 /* Call the appropriate handler */
253 ALfilter_GetParami(ALFilter, Context, param, value);
257 ALCcontext_DecRef(Context);
260 AL_API ALvoid AL_APIENTRY alGetFilteriv(ALuint filter, ALenum param, ALint *values)
262 ALCcontext *Context;
263 ALCdevice *Device;
264 ALfilter *ALFilter;
266 switch(param)
268 case AL_FILTER_TYPE:
269 alGetFilteri(filter, param, values);
270 return;
273 Context = GetContextRef();
274 if(!Context) return;
276 Device = Context->Device;
277 if((ALFilter=LookupFilter(Device, filter)) == NULL)
278 alSetError(Context, AL_INVALID_NAME);
279 else
281 /* Call the appropriate handler */
282 ALfilter_GetParamiv(ALFilter, Context, param, values);
285 ALCcontext_DecRef(Context);
288 AL_API ALvoid AL_APIENTRY alGetFilterf(ALuint filter, ALenum param, ALfloat *value)
290 ALCcontext *Context;
291 ALCdevice *Device;
292 ALfilter *ALFilter;
294 Context = GetContextRef();
295 if(!Context) return;
297 Device = Context->Device;
298 if((ALFilter=LookupFilter(Device, filter)) == NULL)
299 alSetError(Context, AL_INVALID_NAME);
300 else
302 /* Call the appropriate handler */
303 ALfilter_GetParamf(ALFilter, Context, param, value);
306 ALCcontext_DecRef(Context);
309 AL_API ALvoid AL_APIENTRY alGetFilterfv(ALuint filter, ALenum param, ALfloat *values)
311 ALCcontext *Context;
312 ALCdevice *Device;
313 ALfilter *ALFilter;
315 Context = GetContextRef();
316 if(!Context) return;
318 Device = Context->Device;
319 if((ALFilter=LookupFilter(Device, filter)) == NULL)
320 alSetError(Context, AL_INVALID_NAME);
321 else
323 /* Call the appropriate handler */
324 ALfilter_GetParamfv(ALFilter, Context, param, values);
327 ALCcontext_DecRef(Context);
331 void ALfilterState_clear(ALfilterState *filter)
333 filter->x[0] = 0.0f;
334 filter->x[1] = 0.0f;
335 filter->y[0] = 0.0f;
336 filter->y[1] = 0.0f;
339 void ALfilterState_setParams(ALfilterState *filter, ALfilterType type, ALfloat gain, ALfloat freq_mult, ALfloat bandwidth)
341 ALfloat alpha;
342 ALfloat w0;
344 // Limit gain to -100dB
345 gain = maxf(gain, 0.00001f);
347 w0 = F_2PI * freq_mult;
349 /* Calculate filter coefficients depending on filter type */
350 switch(type)
352 case ALfilterType_HighShelf:
353 alpha = sinf(w0)/2.0f*sqrtf((gain + 1.0f/gain)*(1.0f/0.75f - 1.0f) + 2.0f);
354 filter->b[0] = gain*((gain+1.0f) + (gain-1.0f)*cosf(w0) + 2.0f*sqrtf(gain)*alpha);
355 filter->b[1] = -2.0f*gain*((gain-1.0f) + (gain+1.0f)*cosf(w0) );
356 filter->b[2] = gain*((gain+1.0f) + (gain-1.0f)*cosf(w0) - 2.0f*sqrtf(gain)*alpha);
357 filter->a[0] = (gain+1.0f) - (gain-1.0f)*cosf(w0) + 2.0f*sqrtf(gain)*alpha;
358 filter->a[1] = 2.0f* ((gain-1.0f) - (gain+1.0f)*cosf(w0) );
359 filter->a[2] = (gain+1.0f) - (gain-1.0f)*cosf(w0) - 2.0f*sqrtf(gain)*alpha;
360 break;
361 case ALfilterType_LowShelf:
362 alpha = sinf(w0)/2.0f*sqrtf((gain + 1.0f/gain)*(1.0f/0.75f - 1.0f) + 2.0f);
363 filter->b[0] = gain*((gain+1.0f) - (gain-1.0f)*cosf(w0) + 2.0f*sqrtf(gain)*alpha);
364 filter->b[1] = 2.0f*gain*((gain-1.0f) - (gain+1.0f)*cosf(w0) );
365 filter->b[2] = gain*((gain+1.0f) - (gain-1.0f)*cosf(w0) - 2.0f*sqrtf(gain)*alpha);
366 filter->a[0] = (gain+1.0f) + (gain-1.0f)*cosf(w0) + 2.0f*sqrtf(gain)*alpha;
367 filter->a[1] = -2.0f* ((gain-1.0f) + (gain+1.0f)*cosf(w0) );
368 filter->a[2] = (gain+1.0f) + (gain-1.0f)*cosf(w0) - 2.0f*sqrtf(gain)*alpha;
369 break;
370 case ALfilterType_Peaking:
371 alpha = sinf(w0) * sinhf(logf(2.0f) / 2.0f * bandwidth * w0 / sinf(w0));
372 filter->b[0] = 1.0f + alpha * gain;
373 filter->b[1] = -2.0f * cosf(w0);
374 filter->b[2] = 1.0f - alpha * gain;
375 filter->a[0] = 1.0f + alpha / gain;
376 filter->a[1] = -2.0f * cosf(w0);
377 filter->a[2] = 1.0f - alpha / gain;
378 break;
380 case ALfilterType_LowPass:
381 alpha = sinf(w0) * sinhf(logf(2.0f) / 2.0f * bandwidth * w0 / sinf(w0));
382 filter->b[0] = (1.0f - cosf(w0)) / 2.0f;
383 filter->b[1] = 1.0f - cosf(w0);
384 filter->b[2] = (1.0f - cosf(w0)) / 2.0f;
385 filter->a[0] = 1.0f + alpha;
386 filter->a[1] = -2.0f * cosf(w0);
387 filter->a[2] = 1.0f - alpha;
388 break;
389 case ALfilterType_HighPass:
390 alpha = sinf(w0) * sinhf(logf(2.0f) / 2.0f * bandwidth * w0 / sinf(w0));
391 filter->b[0] = (1.0f + cosf(w0)) / 2.0f;
392 filter->b[1] = 1.0f + cosf(w0);
393 filter->b[2] = (1.0f + cosf(w0)) / 2.0f;
394 filter->a[0] = 1.0f + alpha;
395 filter->a[1] = -2.0f * cosf(w0);
396 filter->a[2] = 1.0f - alpha;
397 break;
398 case ALfilterType_BandPass:
399 alpha = sinf(w0) * sinhf(logf(2.0f) / 2.0f * bandwidth * w0 / sinf(w0));
400 filter->b[0] = alpha;
401 filter->b[1] = 0;
402 filter->b[2] = -alpha;
403 filter->a[0] = 1.0f + alpha;
404 filter->a[1] = -2.0f * cosf(w0);
405 filter->a[2] = 1.0f - alpha;
406 break;
409 filter->b[2] /= filter->a[0];
410 filter->b[1] /= filter->a[0];
411 filter->b[0] /= filter->a[0];
412 filter->a[2] /= filter->a[0];
413 filter->a[1] /= filter->a[0];
414 filter->a[0] /= filter->a[0];
416 filter->process = ALfilterState_processC;
420 static void lp_SetParami(ALfilter *UNUSED(filter), ALCcontext *context, ALenum UNUSED(param), ALint UNUSED(val))
421 { SET_ERROR_AND_RETURN(context, AL_INVALID_ENUM); }
422 static void lp_SetParamiv(ALfilter *UNUSED(filter), ALCcontext *context, ALenum UNUSED(param), const ALint *UNUSED(vals))
423 { SET_ERROR_AND_RETURN(context, AL_INVALID_ENUM); }
424 static void lp_SetParamf(ALfilter *filter, ALCcontext *context, ALenum param, ALfloat val)
426 switch(param)
428 case AL_LOWPASS_GAIN:
429 if(!(val >= AL_LOWPASS_MIN_GAIN && val <= AL_LOWPASS_MAX_GAIN))
430 SET_ERROR_AND_RETURN(context, AL_INVALID_VALUE);
431 filter->Gain = val;
432 break;
434 case AL_LOWPASS_GAINHF:
435 if(!(val >= AL_LOWPASS_MIN_GAINHF && val <= AL_LOWPASS_MAX_GAINHF))
436 SET_ERROR_AND_RETURN(context, AL_INVALID_VALUE);
437 filter->GainHF = val;
438 break;
440 default:
441 SET_ERROR_AND_RETURN(context, AL_INVALID_ENUM);
444 static void lp_SetParamfv(ALfilter *filter, ALCcontext *context, ALenum param, const ALfloat *vals)
446 lp_SetParamf(filter, context, param, vals[0]);
449 static void lp_GetParami(ALfilter *UNUSED(filter), ALCcontext *context, ALenum UNUSED(param), ALint *UNUSED(val))
450 { SET_ERROR_AND_RETURN(context, AL_INVALID_ENUM); }
451 static void lp_GetParamiv(ALfilter *UNUSED(filter), ALCcontext *context, ALenum UNUSED(param), ALint *UNUSED(vals))
452 { SET_ERROR_AND_RETURN(context, AL_INVALID_ENUM); }
453 static void lp_GetParamf(ALfilter *filter, ALCcontext *context, ALenum param, ALfloat *val)
455 switch(param)
457 case AL_LOWPASS_GAIN:
458 *val = filter->Gain;
459 break;
461 case AL_LOWPASS_GAINHF:
462 *val = filter->GainHF;
463 break;
465 default:
466 SET_ERROR_AND_RETURN(context, AL_INVALID_ENUM);
469 static void lp_GetParamfv(ALfilter *filter, ALCcontext *context, ALenum param, ALfloat *vals)
471 lp_GetParamf(filter, context, param, vals);
475 static void hp_SetParami(ALfilter *UNUSED(filter), ALCcontext *context, ALenum UNUSED(param), ALint UNUSED(val))
476 { SET_ERROR_AND_RETURN(context, AL_INVALID_ENUM); }
477 static void hp_SetParamiv(ALfilter *UNUSED(filter), ALCcontext *context, ALenum UNUSED(param), const ALint *UNUSED(vals))
478 { SET_ERROR_AND_RETURN(context, AL_INVALID_ENUM); }
479 static void hp_SetParamf(ALfilter *filter, ALCcontext *context, ALenum param, ALfloat val)
481 switch(param)
483 case AL_HIGHPASS_GAIN:
484 if(!(val >= AL_HIGHPASS_MIN_GAIN && val <= AL_HIGHPASS_MAX_GAIN))
485 SET_ERROR_AND_RETURN(context, AL_INVALID_VALUE);
486 filter->Gain = val;
487 break;
489 case AL_HIGHPASS_GAINLF:
490 if(!(val >= AL_HIGHPASS_MIN_GAINLF && val <= AL_HIGHPASS_MAX_GAINLF))
491 SET_ERROR_AND_RETURN(context, AL_INVALID_VALUE);
492 filter->GainLF = val;
493 break;
495 default:
496 SET_ERROR_AND_RETURN(context, AL_INVALID_ENUM);
499 static void hp_SetParamfv(ALfilter *filter, ALCcontext *context, ALenum param, const ALfloat *vals)
501 hp_SetParamf(filter, context, param, vals[0]);
504 static void hp_GetParami(ALfilter *UNUSED(filter), ALCcontext *context, ALenum UNUSED(param), ALint *UNUSED(val))
505 { SET_ERROR_AND_RETURN(context, AL_INVALID_ENUM); }
506 static void hp_GetParamiv(ALfilter *UNUSED(filter), ALCcontext *context, ALenum UNUSED(param), ALint *UNUSED(vals))
507 { SET_ERROR_AND_RETURN(context, AL_INVALID_ENUM); }
508 static void hp_GetParamf(ALfilter *filter, ALCcontext *context, ALenum param, ALfloat *val)
510 switch(param)
512 case AL_HIGHPASS_GAIN:
513 *val = filter->Gain;
514 break;
516 case AL_HIGHPASS_GAINLF:
517 *val = filter->GainLF;
518 break;
520 default:
521 SET_ERROR_AND_RETURN(context, AL_INVALID_ENUM);
524 static void hp_GetParamfv(ALfilter *filter, ALCcontext *context, ALenum param, ALfloat *vals)
526 hp_GetParamf(filter, context, param, vals);
530 static void bp_SetParami(ALfilter *UNUSED(filter), ALCcontext *context, ALenum UNUSED(param), ALint UNUSED(val))
531 { SET_ERROR_AND_RETURN(context, AL_INVALID_ENUM); }
532 static void bp_SetParamiv(ALfilter *UNUSED(filter), ALCcontext *context, ALenum UNUSED(param), const ALint *UNUSED(vals))
533 { SET_ERROR_AND_RETURN(context, AL_INVALID_ENUM); }
534 static void bp_SetParamf(ALfilter *filter, ALCcontext *context, ALenum param, ALfloat val)
536 switch(param)
538 case AL_BANDPASS_GAIN:
539 if(!(val >= AL_BANDPASS_MIN_GAIN && val <= AL_BANDPASS_MAX_GAIN))
540 SET_ERROR_AND_RETURN(context, AL_INVALID_VALUE);
541 filter->Gain = val;
542 break;
544 case AL_BANDPASS_GAINHF:
545 if(!(val >= AL_BANDPASS_MIN_GAINHF && val <= AL_BANDPASS_MAX_GAINHF))
546 SET_ERROR_AND_RETURN(context, AL_INVALID_VALUE);
547 filter->GainHF = val;
548 break;
550 case AL_BANDPASS_GAINLF:
551 if(!(val >= AL_BANDPASS_MIN_GAINLF && val <= AL_BANDPASS_MAX_GAINLF))
552 SET_ERROR_AND_RETURN(context, AL_INVALID_VALUE);
553 filter->GainLF = val;
554 break;
556 default:
557 SET_ERROR_AND_RETURN(context, AL_INVALID_ENUM);
560 static void bp_SetParamfv(ALfilter *filter, ALCcontext *context, ALenum param, const ALfloat *vals)
562 bp_SetParamf(filter, context, param, vals[0]);
565 static void bp_GetParami(ALfilter *UNUSED(filter), ALCcontext *context, ALenum UNUSED(param), ALint *UNUSED(val))
566 { SET_ERROR_AND_RETURN(context, AL_INVALID_ENUM); }
567 static void bp_GetParamiv(ALfilter *UNUSED(filter), ALCcontext *context, ALenum UNUSED(param), ALint *UNUSED(vals))
568 { SET_ERROR_AND_RETURN(context, AL_INVALID_ENUM); }
569 static void bp_GetParamf(ALfilter *filter, ALCcontext *context, ALenum param, ALfloat *val)
571 switch(param)
573 case AL_BANDPASS_GAIN:
574 *val = filter->Gain;
575 break;
577 case AL_BANDPASS_GAINHF:
578 *val = filter->GainHF;
579 break;
581 case AL_BANDPASS_GAINLF:
582 *val = filter->GainLF;
583 break;
585 default:
586 SET_ERROR_AND_RETURN(context, AL_INVALID_ENUM);
589 static void bp_GetParamfv(ALfilter *filter, ALCcontext *context, ALenum param, ALfloat *vals)
591 bp_GetParamf(filter, context, param, vals);
595 static void null_SetParami(ALfilter *UNUSED(filter), ALCcontext *context, ALenum UNUSED(param), ALint UNUSED(val))
596 { SET_ERROR_AND_RETURN(context, AL_INVALID_ENUM); }
597 static void null_SetParamiv(ALfilter *UNUSED(filter), ALCcontext *context, ALenum UNUSED(param), const ALint *UNUSED(vals))
598 { SET_ERROR_AND_RETURN(context, AL_INVALID_ENUM); }
599 static void null_SetParamf(ALfilter *UNUSED(filter), ALCcontext *context, ALenum UNUSED(param), ALfloat UNUSED(val))
600 { SET_ERROR_AND_RETURN(context, AL_INVALID_ENUM); }
601 static void null_SetParamfv(ALfilter *UNUSED(filter), ALCcontext *context, ALenum UNUSED(param), const ALfloat *UNUSED(vals))
602 { SET_ERROR_AND_RETURN(context, AL_INVALID_ENUM); }
604 static void null_GetParami(ALfilter *UNUSED(filter), ALCcontext *context, ALenum UNUSED(param), ALint *UNUSED(val))
605 { SET_ERROR_AND_RETURN(context, AL_INVALID_ENUM); }
606 static void null_GetParamiv(ALfilter *UNUSED(filter), ALCcontext *context, ALenum UNUSED(param), ALint *UNUSED(vals))
607 { SET_ERROR_AND_RETURN(context, AL_INVALID_ENUM); }
608 static void null_GetParamf(ALfilter *UNUSED(filter), ALCcontext *context, ALenum UNUSED(param), ALfloat *UNUSED(val))
609 { SET_ERROR_AND_RETURN(context, AL_INVALID_ENUM); }
610 static void null_GetParamfv(ALfilter *UNUSED(filter), ALCcontext *context, ALenum UNUSED(param), ALfloat *UNUSED(vals))
611 { SET_ERROR_AND_RETURN(context, AL_INVALID_ENUM); }
614 ALvoid ReleaseALFilters(ALCdevice *device)
616 ALsizei i;
617 for(i = 0;i < device->FilterMap.size;i++)
619 ALfilter *temp = device->FilterMap.array[i].value;
620 device->FilterMap.array[i].value = NULL;
622 // Release filter structure
623 FreeThunkEntry(temp->id);
624 memset(temp, 0, sizeof(ALfilter));
625 free(temp);
630 static void InitFilterParams(ALfilter *filter, ALenum type)
632 if(type == AL_FILTER_LOWPASS)
634 filter->Gain = AL_LOWPASS_DEFAULT_GAIN;
635 filter->GainHF = AL_LOWPASS_DEFAULT_GAINHF;
636 filter->HFReference = LOWPASSFREQREF;
637 filter->GainLF = 1.0f;
638 filter->LFReference = HIGHPASSFREQREF;
640 filter->SetParami = lp_SetParami;
641 filter->SetParamiv = lp_SetParamiv;
642 filter->SetParamf = lp_SetParamf;
643 filter->SetParamfv = lp_SetParamfv;
644 filter->GetParami = lp_GetParami;
645 filter->GetParamiv = lp_GetParamiv;
646 filter->GetParamf = lp_GetParamf;
647 filter->GetParamfv = lp_GetParamfv;
649 else if(type == AL_FILTER_HIGHPASS)
651 filter->Gain = AL_HIGHPASS_DEFAULT_GAIN;
652 filter->GainHF = 1.0f;
653 filter->HFReference = LOWPASSFREQREF;
654 filter->GainLF = AL_HIGHPASS_DEFAULT_GAINLF;
655 filter->LFReference = HIGHPASSFREQREF;
657 filter->SetParami = hp_SetParami;
658 filter->SetParamiv = hp_SetParamiv;
659 filter->SetParamf = hp_SetParamf;
660 filter->SetParamfv = hp_SetParamfv;
661 filter->GetParami = hp_GetParami;
662 filter->GetParamiv = hp_GetParamiv;
663 filter->GetParamf = hp_GetParamf;
664 filter->GetParamfv = hp_GetParamfv;
666 else if(type == AL_FILTER_BANDPASS)
668 filter->Gain = AL_BANDPASS_DEFAULT_GAIN;
669 filter->GainHF = AL_BANDPASS_DEFAULT_GAINHF;
670 filter->HFReference = LOWPASSFREQREF;
671 filter->GainLF = AL_BANDPASS_DEFAULT_GAINLF;
672 filter->LFReference = HIGHPASSFREQREF;
674 filter->SetParami = bp_SetParami;
675 filter->SetParamiv = bp_SetParamiv;
676 filter->SetParamf = bp_SetParamf;
677 filter->SetParamfv = bp_SetParamfv;
678 filter->GetParami = bp_GetParami;
679 filter->GetParamiv = bp_GetParamiv;
680 filter->GetParamf = bp_GetParamf;
681 filter->GetParamfv = bp_GetParamfv;
683 else
685 filter->Gain = 1.0f;
686 filter->GainHF = 1.0f;
687 filter->HFReference = LOWPASSFREQREF;
688 filter->GainLF = 1.0f;
689 filter->LFReference = HIGHPASSFREQREF;
691 filter->SetParami = null_SetParami;
692 filter->SetParamiv = null_SetParamiv;
693 filter->SetParamf = null_SetParamf;
694 filter->SetParamfv = null_SetParamfv;
695 filter->GetParami = null_GetParami;
696 filter->GetParamiv = null_GetParamiv;
697 filter->GetParamf = null_GetParamf;
698 filter->GetParamfv = null_GetParamfv;
700 filter->type = type;