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
33 static void InitFilterParams(ALfilter
*filter
, ALenum type
);
36 AL_API ALvoid AL_APIENTRY
alGenFilters(ALsizei n
, ALuint
*filters
)
41 Context
= GetContextRef();
44 if(n
< 0 || IsBadWritePtr((void*)filters
, n
* sizeof(ALuint
)))
45 alSetError(Context
, AL_INVALID_VALUE
);
48 ALCdevice
*device
= Context
->Device
;
53 ALfilter
*filter
= calloc(1, sizeof(ALfilter
));
56 alSetError(Context
, AL_OUT_OF_MEMORY
);
57 alDeleteFilters(i
, filters
);
60 InitFilterParams(filter
, AL_FILTER_NULL
);
62 err
= NewThunkEntry(&filter
->filter
);
63 if(err
== AL_NO_ERROR
)
64 err
= InsertUIntMapEntry(&device
->FilterMap
, filter
->filter
, filter
);
65 if(err
!= AL_NO_ERROR
)
67 FreeThunkEntry(filter
->filter
);
68 memset(filter
, 0, sizeof(ALfilter
));
71 alSetError(Context
, err
);
72 alDeleteFilters(i
, filters
);
76 filters
[i
] = filter
->filter
;
80 ALCcontext_DecRef(Context
);
83 AL_API ALvoid AL_APIENTRY
alDeleteFilters(ALsizei n
, const ALuint
*filters
)
90 Context
= GetContextRef();
93 device
= Context
->Device
;
95 alSetError(Context
, AL_INVALID_VALUE
);
98 // Check that all filters are valid
104 if(LookupFilter(device
, filters
[i
]) == NULL
)
106 alSetError(Context
, AL_INVALID_NAME
);
114 // Recheck that the filter is valid, because there could be duplicated names
115 if((ALFilter
=RemoveFilter(device
, filters
[i
])) == NULL
)
117 FreeThunkEntry(ALFilter
->filter
);
119 memset(ALFilter
, 0, sizeof(ALfilter
));
124 ALCcontext_DecRef(Context
);
127 AL_API ALboolean AL_APIENTRY
alIsFilter(ALuint filter
)
132 Context
= GetContextRef();
133 if(!Context
) return AL_FALSE
;
135 result
= ((!filter
|| LookupFilter(Context
->Device
, filter
)) ?
138 ALCcontext_DecRef(Context
);
143 AL_API ALvoid AL_APIENTRY
alFilteri(ALuint filter
, ALenum param
, ALint iValue
)
149 Context
= GetContextRef();
152 Device
= Context
->Device
;
153 if((ALFilter
=LookupFilter(Device
, filter
)) != NULL
)
158 if(iValue
== AL_FILTER_NULL
|| iValue
== AL_FILTER_LOWPASS
)
159 InitFilterParams(ALFilter
, iValue
);
161 alSetError(Context
, AL_INVALID_VALUE
);
165 /* Call the appropriate handler */
166 ALfilter_SetParami(ALFilter
, Context
, param
, iValue
);
171 alSetError(Context
, AL_INVALID_NAME
);
173 ALCcontext_DecRef(Context
);
176 AL_API ALvoid AL_APIENTRY
alFilteriv(ALuint filter
, ALenum param
, const ALint
*piValues
)
185 alFilteri(filter
, param
, piValues
[0]);
189 Context
= GetContextRef();
192 Device
= Context
->Device
;
193 if((ALFilter
=LookupFilter(Device
, filter
)) != NULL
)
195 /* Call the appropriate handler */
196 ALfilter_SetParamiv(ALFilter
, Context
, param
, piValues
);
199 alSetError(Context
, AL_INVALID_NAME
);
201 ALCcontext_DecRef(Context
);
204 AL_API ALvoid AL_APIENTRY
alFilterf(ALuint filter
, ALenum param
, ALfloat flValue
)
210 Context
= GetContextRef();
213 Device
= Context
->Device
;
214 if((ALFilter
=LookupFilter(Device
, filter
)) != NULL
)
216 /* Call the appropriate handler */
217 ALfilter_SetParamf(ALFilter
, Context
, param
, flValue
);
220 alSetError(Context
, AL_INVALID_NAME
);
222 ALCcontext_DecRef(Context
);
225 AL_API ALvoid AL_APIENTRY
alFilterfv(ALuint filter
, ALenum param
, const ALfloat
*pflValues
)
231 Context
= GetContextRef();
234 Device
= Context
->Device
;
235 if((ALFilter
=LookupFilter(Device
, filter
)) != NULL
)
237 /* Call the appropriate handler */
238 ALfilter_SetParamfv(ALFilter
, Context
, param
, pflValues
);
241 alSetError(Context
, AL_INVALID_NAME
);
243 ALCcontext_DecRef(Context
);
246 AL_API ALvoid AL_APIENTRY
alGetFilteri(ALuint filter
, ALenum param
, ALint
*piValue
)
252 Context
= GetContextRef();
255 Device
= Context
->Device
;
256 if((ALFilter
=LookupFilter(Device
, filter
)) != NULL
)
261 *piValue
= ALFilter
->type
;
265 /* Call the appropriate handler */
266 ALfilter_GetParami(ALFilter
, Context
, param
, piValue
);
271 alSetError(Context
, AL_INVALID_NAME
);
273 ALCcontext_DecRef(Context
);
276 AL_API ALvoid AL_APIENTRY
alGetFilteriv(ALuint filter
, ALenum param
, ALint
*piValues
)
285 alGetFilteri(filter
, param
, piValues
);
289 Context
= GetContextRef();
292 Device
= Context
->Device
;
293 if((ALFilter
=LookupFilter(Device
, filter
)) != NULL
)
295 /* Call the appropriate handler */
296 ALfilter_GetParamiv(ALFilter
, Context
, param
, piValues
);
299 alSetError(Context
, AL_INVALID_NAME
);
301 ALCcontext_DecRef(Context
);
304 AL_API ALvoid AL_APIENTRY
alGetFilterf(ALuint filter
, ALenum param
, ALfloat
*pflValue
)
310 Context
= GetContextRef();
313 Device
= Context
->Device
;
314 if((ALFilter
=LookupFilter(Device
, filter
)) != NULL
)
316 /* Call the appropriate handler */
317 ALfilter_GetParamf(ALFilter
, Context
, param
, pflValue
);
320 alSetError(Context
, AL_INVALID_NAME
);
322 ALCcontext_DecRef(Context
);
325 AL_API ALvoid AL_APIENTRY
alGetFilterfv(ALuint filter
, ALenum param
, ALfloat
*pflValues
)
331 Context
= GetContextRef();
334 Device
= Context
->Device
;
335 if((ALFilter
=LookupFilter(Device
, filter
)) != NULL
)
337 /* Call the appropriate handler */
338 ALfilter_GetParamfv(ALFilter
, Context
, param
, pflValues
);
341 alSetError(Context
, AL_INVALID_NAME
);
343 ALCcontext_DecRef(Context
);
347 ALfloat
lpCoeffCalc(ALfloat g
, ALfloat cw
)
351 /* Be careful with gains < 0.001, as that causes the coefficient head
352 * towards 1, which will flatten the signal */
353 if(g
< 0.9999f
) /* 1-epsilon */
356 a
= (1 - g
*cw
- aluSqrt(2*g
*(1-cw
) - g
*g
*(1 - cw
*cw
))) /
364 static void lp_SetParami(ALfilter
*filter
, ALCcontext
*context
, ALenum param
, ALint val
)
365 { (void)filter
;(void)param
;(void)val
; alSetError(context
, AL_INVALID_ENUM
); }
366 static void lp_SetParamiv(ALfilter
*filter
, ALCcontext
*context
, ALenum param
, const ALint
*vals
)
367 { (void)filter
;(void)param
;(void)vals
; alSetError(context
, AL_INVALID_ENUM
); }
368 static void lp_SetParamf(ALfilter
*filter
, ALCcontext
*context
, ALenum param
, ALfloat val
)
372 case AL_LOWPASS_GAIN
:
373 if(val
>= AL_LOWPASS_MIN_GAIN
&& val
<= AL_LOWPASS_MAX_GAIN
)
376 alSetError(context
, AL_INVALID_VALUE
);
379 case AL_LOWPASS_GAINHF
:
380 if(val
>= AL_LOWPASS_MIN_GAINHF
&& val
<= AL_LOWPASS_MAX_GAINHF
)
381 filter
->GainHF
= val
;
383 alSetError(context
, AL_INVALID_VALUE
);
387 alSetError(context
, AL_INVALID_ENUM
);
391 static void lp_SetParamfv(ALfilter
*filter
, ALCcontext
*context
, ALenum param
, const ALfloat
*vals
)
393 lp_SetParamf(filter
, context
, param
, vals
[0]);
396 static void lp_GetParami(ALfilter
*filter
, ALCcontext
*context
, ALenum param
, ALint
*val
)
397 { (void)filter
;(void)param
;(void)val
; alSetError(context
, AL_INVALID_ENUM
); }
398 static void lp_GetParamiv(ALfilter
*filter
, ALCcontext
*context
, ALenum param
, ALint
*vals
)
399 { (void)filter
;(void)param
;(void)vals
; alSetError(context
, AL_INVALID_ENUM
); }
400 static void lp_GetParamf(ALfilter
*filter
, ALCcontext
*context
, ALenum param
, ALfloat
*val
)
404 case AL_LOWPASS_GAIN
:
408 case AL_LOWPASS_GAINHF
:
409 *val
= filter
->GainHF
;
413 alSetError(context
, AL_INVALID_ENUM
);
417 static void lp_GetParamfv(ALfilter
*filter
, ALCcontext
*context
, ALenum param
, ALfloat
*vals
)
419 lp_GetParamf(filter
, context
, param
, vals
);
423 static void null_SetParami(ALfilter
*filter
, ALCcontext
*context
, ALenum param
, ALint val
)
424 { (void)filter
;(void)param
;(void)val
; alSetError(context
, AL_INVALID_ENUM
); }
425 static void null_SetParamiv(ALfilter
*filter
, ALCcontext
*context
, ALenum param
, const ALint
*vals
)
426 { (void)filter
;(void)param
;(void)vals
; alSetError(context
, AL_INVALID_ENUM
); }
427 static void null_SetParamf(ALfilter
*filter
, ALCcontext
*context
, ALenum param
, ALfloat val
)
428 { (void)filter
;(void)param
;(void)val
; alSetError(context
, AL_INVALID_ENUM
); }
429 static void null_SetParamfv(ALfilter
*filter
, ALCcontext
*context
, ALenum param
, const ALfloat
*vals
)
430 { (void)filter
;(void)param
;(void)vals
; alSetError(context
, AL_INVALID_ENUM
); }
432 static void null_GetParami(ALfilter
*filter
, ALCcontext
*context
, ALenum param
, ALint
*val
)
433 { (void)filter
;(void)param
;(void)val
; alSetError(context
, AL_INVALID_ENUM
); }
434 static void null_GetParamiv(ALfilter
*filter
, ALCcontext
*context
, ALenum param
, ALint
*vals
)
435 { (void)filter
;(void)param
;(void)vals
; alSetError(context
, AL_INVALID_ENUM
); }
436 static void null_GetParamf(ALfilter
*filter
, ALCcontext
*context
, ALenum param
, ALfloat
*val
)
437 { (void)filter
;(void)param
;(void)val
; alSetError(context
, AL_INVALID_ENUM
); }
438 static void null_GetParamfv(ALfilter
*filter
, ALCcontext
*context
, ALenum param
, ALfloat
*vals
)
439 { (void)filter
;(void)param
;(void)vals
; alSetError(context
, AL_INVALID_ENUM
); }
442 ALvoid
ReleaseALFilters(ALCdevice
*device
)
445 for(i
= 0;i
< device
->FilterMap
.size
;i
++)
447 ALfilter
*temp
= device
->FilterMap
.array
[i
].value
;
448 device
->FilterMap
.array
[i
].value
= NULL
;
450 // Release filter structure
451 FreeThunkEntry(temp
->filter
);
452 memset(temp
, 0, sizeof(ALfilter
));
458 static void InitFilterParams(ALfilter
*filter
, ALenum type
)
460 if(type
== AL_FILTER_LOWPASS
)
462 filter
->Gain
= AL_LOWPASS_DEFAULT_GAIN
;
463 filter
->GainHF
= AL_LOWPASS_DEFAULT_GAINHF
;
465 filter
->SetParami
= lp_SetParami
;
466 filter
->SetParamiv
= lp_SetParamiv
;
467 filter
->SetParamf
= lp_SetParamf
;
468 filter
->SetParamfv
= lp_SetParamfv
;
469 filter
->GetParami
= lp_GetParami
;
470 filter
->GetParamiv
= lp_GetParamiv
;
471 filter
->GetParamf
= lp_GetParamf
;
472 filter
->GetParamfv
= lp_GetParamfv
;
476 filter
->SetParami
= null_SetParami
;
477 filter
->SetParamiv
= null_SetParamiv
;
478 filter
->SetParamf
= null_SetParamf
;
479 filter
->SetParamfv
= null_SetParamfv
;
480 filter
->GetParami
= null_GetParami
;
481 filter
->GetParamiv
= null_GetParamiv
;
482 filter
->GetParamf
= null_GetParamf
;
483 filter
->GetParamfv
= null_GetParamfv
;