Implement opening and closing devices in the router
[openal-soft.git] / OpenAL32 / alFilter.c
blob2a2b96219378ffca91fca6af59bfb51207c7e1d0
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 void LockFiltersRead(ALCdevice *device);
33 extern inline void UnlockFiltersRead(ALCdevice *device);
34 extern inline void LockFiltersWrite(ALCdevice *device);
35 extern inline void UnlockFiltersWrite(ALCdevice *device);
36 extern inline struct ALfilter *LookupFilter(ALCdevice *device, ALuint id);
37 extern inline struct ALfilter *RemoveFilter(ALCdevice *device, ALuint id);
38 extern inline void ALfilterState_clear(ALfilterState *filter);
39 extern inline void ALfilterState_copyParams(ALfilterState *restrict dst, const ALfilterState *restrict src);
40 extern inline void ALfilterState_processPassthru(ALfilterState *filter, const ALfloat *restrict src, ALsizei numsamples);
41 extern inline ALfloat calc_rcpQ_from_slope(ALfloat gain, ALfloat slope);
42 extern inline ALfloat calc_rcpQ_from_bandwidth(ALfloat freq_mult, ALfloat bandwidth);
44 static void InitFilterParams(ALfilter *filter, ALenum type);
47 AL_API ALvoid AL_APIENTRY alGenFilters(ALsizei n, ALuint *filters)
49 ALCdevice *device;
50 ALCcontext *context;
51 ALsizei cur = 0;
52 ALenum err;
54 context = GetContextRef();
55 if(!context) return;
57 if(!(n >= 0))
58 SET_ERROR_AND_GOTO(context, AL_INVALID_VALUE, done);
60 device = context->Device;
61 for(cur = 0;cur < n;cur++)
63 ALfilter *filter = al_calloc(16, sizeof(ALfilter));
64 if(!filter)
66 alDeleteFilters(cur, filters);
67 SET_ERROR_AND_GOTO(context, AL_OUT_OF_MEMORY, done);
69 InitFilterParams(filter, AL_FILTER_NULL);
71 err = NewThunkEntry(&filter->id);
72 if(err == AL_NO_ERROR)
73 err = InsertUIntMapEntry(&device->FilterMap, filter->id, filter);
74 if(err != AL_NO_ERROR)
76 FreeThunkEntry(filter->id);
77 memset(filter, 0, sizeof(ALfilter));
78 al_free(filter);
80 alDeleteFilters(cur, filters);
81 SET_ERROR_AND_GOTO(context, err, done);
84 filters[cur] = filter->id;
87 done:
88 ALCcontext_DecRef(context);
91 AL_API ALvoid AL_APIENTRY alDeleteFilters(ALsizei n, const ALuint *filters)
93 ALCdevice *device;
94 ALCcontext *context;
95 ALfilter *filter;
96 ALsizei i;
98 context = GetContextRef();
99 if(!context) return;
101 device = context->Device;
102 LockFiltersWrite(device);
103 if(!(n >= 0))
104 SET_ERROR_AND_GOTO(context, AL_INVALID_VALUE, done);
105 for(i = 0;i < n;i++)
107 if(filters[i] && LookupFilter(device, filters[i]) == NULL)
108 SET_ERROR_AND_GOTO(context, AL_INVALID_NAME, done);
110 for(i = 0;i < n;i++)
112 if((filter=RemoveFilter(device, filters[i])) == NULL)
113 continue;
114 FreeThunkEntry(filter->id);
116 memset(filter, 0, sizeof(*filter));
117 al_free(filter);
120 done:
121 UnlockFiltersWrite(device);
122 ALCcontext_DecRef(context);
125 AL_API ALboolean AL_APIENTRY alIsFilter(ALuint filter)
127 ALCcontext *Context;
128 ALboolean result;
130 Context = GetContextRef();
131 if(!Context) return AL_FALSE;
133 LockFiltersRead(Context->Device);
134 result = ((!filter || LookupFilter(Context->Device, filter)) ?
135 AL_TRUE : AL_FALSE);
136 UnlockFiltersRead(Context->Device);
138 ALCcontext_DecRef(Context);
140 return result;
143 AL_API ALvoid AL_APIENTRY alFilteri(ALuint filter, ALenum param, ALint value)
145 ALCcontext *Context;
146 ALCdevice *Device;
147 ALfilter *ALFilter;
149 Context = GetContextRef();
150 if(!Context) return;
152 Device = Context->Device;
153 LockFiltersWrite(Device);
154 if((ALFilter=LookupFilter(Device, filter)) == NULL)
155 alSetError(Context, AL_INVALID_NAME);
156 else
158 if(param == AL_FILTER_TYPE)
160 if(value == AL_FILTER_NULL || value == AL_FILTER_LOWPASS ||
161 value == AL_FILTER_HIGHPASS || value == AL_FILTER_BANDPASS)
162 InitFilterParams(ALFilter, value);
163 else
164 alSetError(Context, AL_INVALID_VALUE);
166 else
168 /* Call the appropriate handler */
169 ALfilter_SetParami(ALFilter, Context, param, value);
172 UnlockFiltersWrite(Device);
174 ALCcontext_DecRef(Context);
177 AL_API ALvoid AL_APIENTRY alFilteriv(ALuint filter, ALenum param, const ALint *values)
179 ALCcontext *Context;
180 ALCdevice *Device;
181 ALfilter *ALFilter;
183 switch(param)
185 case AL_FILTER_TYPE:
186 alFilteri(filter, param, values[0]);
187 return;
190 Context = GetContextRef();
191 if(!Context) return;
193 Device = Context->Device;
194 LockFiltersWrite(Device);
195 if((ALFilter=LookupFilter(Device, filter)) == NULL)
196 alSetError(Context, AL_INVALID_NAME);
197 else
199 /* Call the appropriate handler */
200 ALfilter_SetParamiv(ALFilter, Context, param, values);
202 UnlockFiltersWrite(Device);
204 ALCcontext_DecRef(Context);
207 AL_API ALvoid AL_APIENTRY alFilterf(ALuint filter, ALenum param, ALfloat value)
209 ALCcontext *Context;
210 ALCdevice *Device;
211 ALfilter *ALFilter;
213 Context = GetContextRef();
214 if(!Context) return;
216 Device = Context->Device;
217 LockFiltersWrite(Device);
218 if((ALFilter=LookupFilter(Device, filter)) == NULL)
219 alSetError(Context, AL_INVALID_NAME);
220 else
222 /* Call the appropriate handler */
223 ALfilter_SetParamf(ALFilter, Context, param, value);
225 UnlockFiltersWrite(Device);
227 ALCcontext_DecRef(Context);
230 AL_API ALvoid AL_APIENTRY alFilterfv(ALuint filter, ALenum param, const ALfloat *values)
232 ALCcontext *Context;
233 ALCdevice *Device;
234 ALfilter *ALFilter;
236 Context = GetContextRef();
237 if(!Context) return;
239 Device = Context->Device;
240 LockFiltersWrite(Device);
241 if((ALFilter=LookupFilter(Device, filter)) == NULL)
242 alSetError(Context, AL_INVALID_NAME);
243 else
245 /* Call the appropriate handler */
246 ALfilter_SetParamfv(ALFilter, Context, param, values);
248 UnlockFiltersWrite(Device);
250 ALCcontext_DecRef(Context);
253 AL_API ALvoid AL_APIENTRY alGetFilteri(ALuint filter, ALenum param, ALint *value)
255 ALCcontext *Context;
256 ALCdevice *Device;
257 ALfilter *ALFilter;
259 Context = GetContextRef();
260 if(!Context) return;
262 Device = Context->Device;
263 LockFiltersRead(Device);
264 if((ALFilter=LookupFilter(Device, filter)) == NULL)
265 alSetError(Context, AL_INVALID_NAME);
266 else
268 if(param == AL_FILTER_TYPE)
269 *value = ALFilter->type;
270 else
272 /* Call the appropriate handler */
273 ALfilter_GetParami(ALFilter, Context, param, value);
276 UnlockFiltersRead(Device);
278 ALCcontext_DecRef(Context);
281 AL_API ALvoid AL_APIENTRY alGetFilteriv(ALuint filter, ALenum param, ALint *values)
283 ALCcontext *Context;
284 ALCdevice *Device;
285 ALfilter *ALFilter;
287 switch(param)
289 case AL_FILTER_TYPE:
290 alGetFilteri(filter, param, values);
291 return;
294 Context = GetContextRef();
295 if(!Context) return;
297 Device = Context->Device;
298 LockFiltersRead(Device);
299 if((ALFilter=LookupFilter(Device, filter)) == NULL)
300 alSetError(Context, AL_INVALID_NAME);
301 else
303 /* Call the appropriate handler */
304 ALfilter_GetParamiv(ALFilter, Context, param, values);
306 UnlockFiltersRead(Device);
308 ALCcontext_DecRef(Context);
311 AL_API ALvoid AL_APIENTRY alGetFilterf(ALuint filter, ALenum param, ALfloat *value)
313 ALCcontext *Context;
314 ALCdevice *Device;
315 ALfilter *ALFilter;
317 Context = GetContextRef();
318 if(!Context) return;
320 Device = Context->Device;
321 LockFiltersRead(Device);
322 if((ALFilter=LookupFilter(Device, filter)) == NULL)
323 alSetError(Context, AL_INVALID_NAME);
324 else
326 /* Call the appropriate handler */
327 ALfilter_GetParamf(ALFilter, Context, param, value);
329 UnlockFiltersRead(Device);
331 ALCcontext_DecRef(Context);
334 AL_API ALvoid AL_APIENTRY alGetFilterfv(ALuint filter, ALenum param, ALfloat *values)
336 ALCcontext *Context;
337 ALCdevice *Device;
338 ALfilter *ALFilter;
340 Context = GetContextRef();
341 if(!Context) return;
343 Device = Context->Device;
344 LockFiltersRead(Device);
345 if((ALFilter=LookupFilter(Device, filter)) == NULL)
346 alSetError(Context, AL_INVALID_NAME);
347 else
349 /* Call the appropriate handler */
350 ALfilter_GetParamfv(ALFilter, Context, param, values);
352 UnlockFiltersRead(Device);
354 ALCcontext_DecRef(Context);
358 void ALfilterState_setParams(ALfilterState *filter, ALfilterType type, ALfloat gain, ALfloat freq_mult, ALfloat rcpQ)
360 ALfloat alpha, sqrtgain_alpha_2;
361 ALfloat w0, sin_w0, cos_w0;
362 ALfloat a[3] = { 1.0f, 0.0f, 0.0f };
363 ALfloat b[3] = { 1.0f, 0.0f, 0.0f };
365 // Limit gain to -100dB
366 assert(gain > 0.00001f);
368 w0 = F_TAU * freq_mult;
369 sin_w0 = sinf(w0);
370 cos_w0 = cosf(w0);
371 alpha = sin_w0/2.0f * rcpQ;
373 /* Calculate filter coefficients depending on filter type */
374 switch(type)
376 case ALfilterType_HighShelf:
377 sqrtgain_alpha_2 = 2.0f * sqrtf(gain) * alpha;
378 b[0] = gain*((gain+1.0f) + (gain-1.0f)*cos_w0 + sqrtgain_alpha_2);
379 b[1] = -2.0f*gain*((gain-1.0f) + (gain+1.0f)*cos_w0 );
380 b[2] = gain*((gain+1.0f) + (gain-1.0f)*cos_w0 - sqrtgain_alpha_2);
381 a[0] = (gain+1.0f) - (gain-1.0f)*cos_w0 + sqrtgain_alpha_2;
382 a[1] = 2.0f* ((gain-1.0f) - (gain+1.0f)*cos_w0 );
383 a[2] = (gain+1.0f) - (gain-1.0f)*cos_w0 - sqrtgain_alpha_2;
384 break;
385 case ALfilterType_LowShelf:
386 sqrtgain_alpha_2 = 2.0f * sqrtf(gain) * alpha;
387 b[0] = gain*((gain+1.0f) - (gain-1.0f)*cos_w0 + sqrtgain_alpha_2);
388 b[1] = 2.0f*gain*((gain-1.0f) - (gain+1.0f)*cos_w0 );
389 b[2] = gain*((gain+1.0f) - (gain-1.0f)*cos_w0 - sqrtgain_alpha_2);
390 a[0] = (gain+1.0f) + (gain-1.0f)*cos_w0 + sqrtgain_alpha_2;
391 a[1] = -2.0f* ((gain-1.0f) + (gain+1.0f)*cos_w0 );
392 a[2] = (gain+1.0f) + (gain-1.0f)*cos_w0 - sqrtgain_alpha_2;
393 break;
394 case ALfilterType_Peaking:
395 gain = sqrtf(gain);
396 b[0] = 1.0f + alpha * gain;
397 b[1] = -2.0f * cos_w0;
398 b[2] = 1.0f - alpha * gain;
399 a[0] = 1.0f + alpha / gain;
400 a[1] = -2.0f * cos_w0;
401 a[2] = 1.0f - alpha / gain;
402 break;
404 case ALfilterType_LowPass:
405 b[0] = (1.0f - cos_w0) / 2.0f;
406 b[1] = 1.0f - cos_w0;
407 b[2] = (1.0f - cos_w0) / 2.0f;
408 a[0] = 1.0f + alpha;
409 a[1] = -2.0f * cos_w0;
410 a[2] = 1.0f - alpha;
411 break;
412 case ALfilterType_HighPass:
413 b[0] = (1.0f + cos_w0) / 2.0f;
414 b[1] = -(1.0f + cos_w0);
415 b[2] = (1.0f + cos_w0) / 2.0f;
416 a[0] = 1.0f + alpha;
417 a[1] = -2.0f * cos_w0;
418 a[2] = 1.0f - alpha;
419 break;
420 case ALfilterType_BandPass:
421 b[0] = alpha;
422 b[1] = 0;
423 b[2] = -alpha;
424 a[0] = 1.0f + alpha;
425 a[1] = -2.0f * cos_w0;
426 a[2] = 1.0f - alpha;
427 break;
430 filter->a1 = a[1] / a[0];
431 filter->a2 = a[2] / a[0];
432 filter->b0 = b[0] / a[0];
433 filter->b1 = b[1] / a[0];
434 filter->b2 = b[2] / a[0];
438 static void lp_SetParami(ALfilter *UNUSED(filter), ALCcontext *context, ALenum UNUSED(param), ALint UNUSED(val))
439 { SET_ERROR_AND_RETURN(context, AL_INVALID_ENUM); }
440 static void lp_SetParamiv(ALfilter *UNUSED(filter), ALCcontext *context, ALenum UNUSED(param), const ALint *UNUSED(vals))
441 { SET_ERROR_AND_RETURN(context, AL_INVALID_ENUM); }
442 static void lp_SetParamf(ALfilter *filter, ALCcontext *context, ALenum param, ALfloat val)
444 switch(param)
446 case AL_LOWPASS_GAIN:
447 if(!(val >= AL_LOWPASS_MIN_GAIN && val <= AL_LOWPASS_MAX_GAIN))
448 SET_ERROR_AND_RETURN(context, AL_INVALID_VALUE);
449 filter->Gain = val;
450 break;
452 case AL_LOWPASS_GAINHF:
453 if(!(val >= AL_LOWPASS_MIN_GAINHF && val <= AL_LOWPASS_MAX_GAINHF))
454 SET_ERROR_AND_RETURN(context, AL_INVALID_VALUE);
455 filter->GainHF = val;
456 break;
458 default:
459 SET_ERROR_AND_RETURN(context, AL_INVALID_ENUM);
462 static void lp_SetParamfv(ALfilter *filter, ALCcontext *context, ALenum param, const ALfloat *vals)
464 lp_SetParamf(filter, context, param, vals[0]);
467 static void lp_GetParami(ALfilter *UNUSED(filter), ALCcontext *context, ALenum UNUSED(param), ALint *UNUSED(val))
468 { SET_ERROR_AND_RETURN(context, AL_INVALID_ENUM); }
469 static void lp_GetParamiv(ALfilter *UNUSED(filter), ALCcontext *context, ALenum UNUSED(param), ALint *UNUSED(vals))
470 { SET_ERROR_AND_RETURN(context, AL_INVALID_ENUM); }
471 static void lp_GetParamf(ALfilter *filter, ALCcontext *context, ALenum param, ALfloat *val)
473 switch(param)
475 case AL_LOWPASS_GAIN:
476 *val = filter->Gain;
477 break;
479 case AL_LOWPASS_GAINHF:
480 *val = filter->GainHF;
481 break;
483 default:
484 SET_ERROR_AND_RETURN(context, AL_INVALID_ENUM);
487 static void lp_GetParamfv(ALfilter *filter, ALCcontext *context, ALenum param, ALfloat *vals)
489 lp_GetParamf(filter, context, param, vals);
493 static void hp_SetParami(ALfilter *UNUSED(filter), ALCcontext *context, ALenum UNUSED(param), ALint UNUSED(val))
494 { SET_ERROR_AND_RETURN(context, AL_INVALID_ENUM); }
495 static void hp_SetParamiv(ALfilter *UNUSED(filter), ALCcontext *context, ALenum UNUSED(param), const ALint *UNUSED(vals))
496 { SET_ERROR_AND_RETURN(context, AL_INVALID_ENUM); }
497 static void hp_SetParamf(ALfilter *filter, ALCcontext *context, ALenum param, ALfloat val)
499 switch(param)
501 case AL_HIGHPASS_GAIN:
502 if(!(val >= AL_HIGHPASS_MIN_GAIN && val <= AL_HIGHPASS_MAX_GAIN))
503 SET_ERROR_AND_RETURN(context, AL_INVALID_VALUE);
504 filter->Gain = val;
505 break;
507 case AL_HIGHPASS_GAINLF:
508 if(!(val >= AL_HIGHPASS_MIN_GAINLF && val <= AL_HIGHPASS_MAX_GAINLF))
509 SET_ERROR_AND_RETURN(context, AL_INVALID_VALUE);
510 filter->GainLF = val;
511 break;
513 default:
514 SET_ERROR_AND_RETURN(context, AL_INVALID_ENUM);
517 static void hp_SetParamfv(ALfilter *filter, ALCcontext *context, ALenum param, const ALfloat *vals)
519 hp_SetParamf(filter, context, param, vals[0]);
522 static void hp_GetParami(ALfilter *UNUSED(filter), ALCcontext *context, ALenum UNUSED(param), ALint *UNUSED(val))
523 { SET_ERROR_AND_RETURN(context, AL_INVALID_ENUM); }
524 static void hp_GetParamiv(ALfilter *UNUSED(filter), ALCcontext *context, ALenum UNUSED(param), ALint *UNUSED(vals))
525 { SET_ERROR_AND_RETURN(context, AL_INVALID_ENUM); }
526 static void hp_GetParamf(ALfilter *filter, ALCcontext *context, ALenum param, ALfloat *val)
528 switch(param)
530 case AL_HIGHPASS_GAIN:
531 *val = filter->Gain;
532 break;
534 case AL_HIGHPASS_GAINLF:
535 *val = filter->GainLF;
536 break;
538 default:
539 SET_ERROR_AND_RETURN(context, AL_INVALID_ENUM);
542 static void hp_GetParamfv(ALfilter *filter, ALCcontext *context, ALenum param, ALfloat *vals)
544 hp_GetParamf(filter, context, param, vals);
548 static void bp_SetParami(ALfilter *UNUSED(filter), ALCcontext *context, ALenum UNUSED(param), ALint UNUSED(val))
549 { SET_ERROR_AND_RETURN(context, AL_INVALID_ENUM); }
550 static void bp_SetParamiv(ALfilter *UNUSED(filter), ALCcontext *context, ALenum UNUSED(param), const ALint *UNUSED(vals))
551 { SET_ERROR_AND_RETURN(context, AL_INVALID_ENUM); }
552 static void bp_SetParamf(ALfilter *filter, ALCcontext *context, ALenum param, ALfloat val)
554 switch(param)
556 case AL_BANDPASS_GAIN:
557 if(!(val >= AL_BANDPASS_MIN_GAIN && val <= AL_BANDPASS_MAX_GAIN))
558 SET_ERROR_AND_RETURN(context, AL_INVALID_VALUE);
559 filter->Gain = val;
560 break;
562 case AL_BANDPASS_GAINHF:
563 if(!(val >= AL_BANDPASS_MIN_GAINHF && val <= AL_BANDPASS_MAX_GAINHF))
564 SET_ERROR_AND_RETURN(context, AL_INVALID_VALUE);
565 filter->GainHF = val;
566 break;
568 case AL_BANDPASS_GAINLF:
569 if(!(val >= AL_BANDPASS_MIN_GAINLF && val <= AL_BANDPASS_MAX_GAINLF))
570 SET_ERROR_AND_RETURN(context, AL_INVALID_VALUE);
571 filter->GainLF = val;
572 break;
574 default:
575 SET_ERROR_AND_RETURN(context, AL_INVALID_ENUM);
578 static void bp_SetParamfv(ALfilter *filter, ALCcontext *context, ALenum param, const ALfloat *vals)
580 bp_SetParamf(filter, context, param, vals[0]);
583 static void bp_GetParami(ALfilter *UNUSED(filter), ALCcontext *context, ALenum UNUSED(param), ALint *UNUSED(val))
584 { SET_ERROR_AND_RETURN(context, AL_INVALID_ENUM); }
585 static void bp_GetParamiv(ALfilter *UNUSED(filter), ALCcontext *context, ALenum UNUSED(param), ALint *UNUSED(vals))
586 { SET_ERROR_AND_RETURN(context, AL_INVALID_ENUM); }
587 static void bp_GetParamf(ALfilter *filter, ALCcontext *context, ALenum param, ALfloat *val)
589 switch(param)
591 case AL_BANDPASS_GAIN:
592 *val = filter->Gain;
593 break;
595 case AL_BANDPASS_GAINHF:
596 *val = filter->GainHF;
597 break;
599 case AL_BANDPASS_GAINLF:
600 *val = filter->GainLF;
601 break;
603 default:
604 SET_ERROR_AND_RETURN(context, AL_INVALID_ENUM);
607 static void bp_GetParamfv(ALfilter *filter, ALCcontext *context, ALenum param, ALfloat *vals)
609 bp_GetParamf(filter, context, param, vals);
613 static void null_SetParami(ALfilter *UNUSED(filter), ALCcontext *context, ALenum UNUSED(param), ALint UNUSED(val))
614 { SET_ERROR_AND_RETURN(context, AL_INVALID_ENUM); }
615 static void null_SetParamiv(ALfilter *UNUSED(filter), ALCcontext *context, ALenum UNUSED(param), const ALint *UNUSED(vals))
616 { SET_ERROR_AND_RETURN(context, AL_INVALID_ENUM); }
617 static void null_SetParamf(ALfilter *UNUSED(filter), ALCcontext *context, ALenum UNUSED(param), ALfloat UNUSED(val))
618 { SET_ERROR_AND_RETURN(context, AL_INVALID_ENUM); }
619 static void null_SetParamfv(ALfilter *UNUSED(filter), ALCcontext *context, ALenum UNUSED(param), const ALfloat *UNUSED(vals))
620 { SET_ERROR_AND_RETURN(context, AL_INVALID_ENUM); }
622 static void null_GetParami(ALfilter *UNUSED(filter), ALCcontext *context, ALenum UNUSED(param), ALint *UNUSED(val))
623 { SET_ERROR_AND_RETURN(context, AL_INVALID_ENUM); }
624 static void null_GetParamiv(ALfilter *UNUSED(filter), ALCcontext *context, ALenum UNUSED(param), ALint *UNUSED(vals))
625 { SET_ERROR_AND_RETURN(context, AL_INVALID_ENUM); }
626 static void null_GetParamf(ALfilter *UNUSED(filter), ALCcontext *context, ALenum UNUSED(param), ALfloat *UNUSED(val))
627 { SET_ERROR_AND_RETURN(context, AL_INVALID_ENUM); }
628 static void null_GetParamfv(ALfilter *UNUSED(filter), ALCcontext *context, ALenum UNUSED(param), ALfloat *UNUSED(vals))
629 { SET_ERROR_AND_RETURN(context, AL_INVALID_ENUM); }
632 ALvoid ReleaseALFilters(ALCdevice *device)
634 ALsizei i;
635 for(i = 0;i < device->FilterMap.size;i++)
637 ALfilter *temp = device->FilterMap.values[i];
638 device->FilterMap.values[i] = NULL;
640 // Release filter structure
641 FreeThunkEntry(temp->id);
642 memset(temp, 0, sizeof(ALfilter));
643 al_free(temp);
648 static void InitFilterParams(ALfilter *filter, ALenum type)
650 if(type == AL_FILTER_LOWPASS)
652 filter->Gain = AL_LOWPASS_DEFAULT_GAIN;
653 filter->GainHF = AL_LOWPASS_DEFAULT_GAINHF;
654 filter->HFReference = LOWPASSFREQREF;
655 filter->GainLF = 1.0f;
656 filter->LFReference = HIGHPASSFREQREF;
658 filter->SetParami = lp_SetParami;
659 filter->SetParamiv = lp_SetParamiv;
660 filter->SetParamf = lp_SetParamf;
661 filter->SetParamfv = lp_SetParamfv;
662 filter->GetParami = lp_GetParami;
663 filter->GetParamiv = lp_GetParamiv;
664 filter->GetParamf = lp_GetParamf;
665 filter->GetParamfv = lp_GetParamfv;
667 else if(type == AL_FILTER_HIGHPASS)
669 filter->Gain = AL_HIGHPASS_DEFAULT_GAIN;
670 filter->GainHF = 1.0f;
671 filter->HFReference = LOWPASSFREQREF;
672 filter->GainLF = AL_HIGHPASS_DEFAULT_GAINLF;
673 filter->LFReference = HIGHPASSFREQREF;
675 filter->SetParami = hp_SetParami;
676 filter->SetParamiv = hp_SetParamiv;
677 filter->SetParamf = hp_SetParamf;
678 filter->SetParamfv = hp_SetParamfv;
679 filter->GetParami = hp_GetParami;
680 filter->GetParamiv = hp_GetParamiv;
681 filter->GetParamf = hp_GetParamf;
682 filter->GetParamfv = hp_GetParamfv;
684 else if(type == AL_FILTER_BANDPASS)
686 filter->Gain = AL_BANDPASS_DEFAULT_GAIN;
687 filter->GainHF = AL_BANDPASS_DEFAULT_GAINHF;
688 filter->HFReference = LOWPASSFREQREF;
689 filter->GainLF = AL_BANDPASS_DEFAULT_GAINLF;
690 filter->LFReference = HIGHPASSFREQREF;
692 filter->SetParami = bp_SetParami;
693 filter->SetParamiv = bp_SetParamiv;
694 filter->SetParamf = bp_SetParamf;
695 filter->SetParamfv = bp_SetParamfv;
696 filter->GetParami = bp_GetParami;
697 filter->GetParamiv = bp_GetParamiv;
698 filter->GetParamf = bp_GetParamf;
699 filter->GetParamfv = bp_GetParamfv;
701 else
703 filter->Gain = 1.0f;
704 filter->GainHF = 1.0f;
705 filter->HFReference = LOWPASSFREQREF;
706 filter->GainLF = 1.0f;
707 filter->LFReference = HIGHPASSFREQREF;
709 filter->SetParami = null_SetParami;
710 filter->SetParamiv = null_SetParamiv;
711 filter->SetParamf = null_SetParamf;
712 filter->SetParamfv = null_SetParamfv;
713 filter->GetParami = null_GetParami;
714 filter->GetParamiv = null_GetParamiv;
715 filter->GetParamf = null_GetParamf;
716 filter->GetParamfv = null_GetParamfv;
718 filter->type = type;