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
);
35 DECL_VERIFIER(Filter
, ALfilter
, filter
)
37 ALvoid AL_APIENTRY
alGenFilters(ALsizei n
, ALuint
*filters
)
42 Context
= GetContextSuspended();
47 ALCdevice
*device
= Context
->Device
;
49 // Check that enough memory has been allocted in the 'filters' array for n Filters
50 if (!IsBadWritePtr((void*)filters
, n
* sizeof(ALuint
)))
53 ALfilter
**list
= &device
->FilterList
;
55 list
= &(*list
)->next
;
60 *list
= calloc(1, sizeof(ALfilter
));
65 ALfilter
*temp
= end
->next
;
66 end
->next
= temp
->next
;
68 ALTHUNK_REMOVEENTRY(temp
->filter
);
69 device
->FilterCount
--;
72 alSetError(Context
, AL_OUT_OF_MEMORY
);
76 filters
[i
] = (ALuint
)ALTHUNK_ADDENTRY(*list
);
77 (*list
)->filter
= filters
[i
];
79 InitFilterParams(*list
, AL_FILTER_NULL
);
80 device
->FilterCount
++;
83 list
= &(*list
)->next
;
88 ProcessContext(Context
);
91 ALvoid AL_APIENTRY
alDeleteFilters(ALsizei n
, ALuint
*filters
)
97 Context
= GetContextSuspended();
102 ALCdevice
*device
= Context
->Device
;
104 // Check that all filters are valid
105 for (i
= 0; i
< n
; i
++)
110 if(!VerifyFilter(device
->FilterList
, filters
[i
]))
112 alSetError(Context
, AL_INVALID_NAME
);
119 // All filters are valid
120 for (i
= 0; i
< n
; i
++)
122 // Recheck that the filter is valid, because there could be duplicated names
123 if((ALFilter
=VerifyFilter(device
->FilterList
, filters
[i
])) != NULL
)
127 // Remove Source from list of Sources
128 list
= &device
->FilterList
;
129 while(*list
&& *list
!= ALFilter
)
130 list
= &(*list
)->next
;
133 *list
= (*list
)->next
;
134 ALTHUNK_REMOVEENTRY(ALFilter
->filter
);
136 memset(ALFilter
, 0, sizeof(ALfilter
));
139 device
->FilterCount
--;
145 alSetError(Context
, AL_INVALID_VALUE
);
147 ProcessContext(Context
);
150 ALboolean AL_APIENTRY
alIsFilter(ALuint filter
)
153 ALboolean result
= AL_TRUE
;
155 Context
= GetContextSuspended();
156 if(!Context
) return AL_FALSE
;
159 result
= (VerifyFilter(Context
->Device
->FilterList
, filter
) ?
162 ProcessContext(Context
);
167 ALvoid AL_APIENTRY
alFilteri(ALuint filter
, ALenum param
, ALint iValue
)
173 Context
= GetContextSuspended();
176 Device
= Context
->Device
;
177 if((ALFilter
=VerifyFilter(Device
->FilterList
, filter
)) != NULL
)
182 if(iValue
== AL_FILTER_NULL
||
183 iValue
== AL_FILTER_LOWPASS
)
184 InitFilterParams(ALFilter
, iValue
);
186 alSetError(Context
, AL_INVALID_VALUE
);
190 alSetError(Context
, AL_INVALID_ENUM
);
195 alSetError(Context
, AL_INVALID_NAME
);
197 ProcessContext(Context
);
200 ALvoid AL_APIENTRY
alFilteriv(ALuint filter
, ALenum param
, ALint
*piValues
)
205 Context
= GetContextSuspended();
208 Device
= Context
->Device
;
209 if(VerifyFilter(Device
->FilterList
, filter
) != NULL
)
214 alFilteri(filter
, param
, piValues
[0]);
218 alSetError(Context
, AL_INVALID_ENUM
);
223 alSetError(Context
, AL_INVALID_NAME
);
225 ProcessContext(Context
);
228 ALvoid AL_APIENTRY
alFilterf(ALuint filter
, ALenum param
, ALfloat flValue
)
234 Context
= GetContextSuspended();
237 Device
= Context
->Device
;
238 if((ALFilter
=VerifyFilter(Device
->FilterList
, filter
)) != NULL
)
240 switch(ALFilter
->type
)
242 case AL_FILTER_LOWPASS
:
245 case AL_LOWPASS_GAIN
:
246 if(flValue
>= 0.0f
&& flValue
<= 1.0f
)
247 ALFilter
->Gain
= flValue
;
249 alSetError(Context
, AL_INVALID_VALUE
);
252 case AL_LOWPASS_GAINHF
:
253 if(flValue
>= 0.0f
&& flValue
<= 1.0f
)
254 ALFilter
->GainHF
= flValue
;
256 alSetError(Context
, AL_INVALID_VALUE
);
260 alSetError(Context
, AL_INVALID_ENUM
);
266 alSetError(Context
, AL_INVALID_ENUM
);
271 alSetError(Context
, AL_INVALID_NAME
);
273 ProcessContext(Context
);
276 ALvoid AL_APIENTRY
alFilterfv(ALuint filter
, ALenum param
, ALfloat
*pflValues
)
281 Context
= GetContextSuspended();
284 Device
= Context
->Device
;
285 if(VerifyFilter(Device
->FilterList
, filter
) != NULL
)
290 alFilterf(filter
, param
, pflValues
[0]);
295 alSetError(Context
, AL_INVALID_NAME
);
297 ProcessContext(Context
);
300 ALvoid AL_APIENTRY
alGetFilteri(ALuint filter
, ALenum param
, ALint
*piValue
)
306 Context
= GetContextSuspended();
309 Device
= Context
->Device
;
310 if((ALFilter
=VerifyFilter(Device
->FilterList
, filter
)) != NULL
)
315 *piValue
= ALFilter
->type
;
319 alSetError(Context
, AL_INVALID_ENUM
);
324 alSetError(Context
, AL_INVALID_NAME
);
326 ProcessContext(Context
);
329 ALvoid AL_APIENTRY
alGetFilteriv(ALuint filter
, ALenum param
, ALint
*piValues
)
334 Context
= GetContextSuspended();
337 Device
= Context
->Device
;
338 if(VerifyFilter(Device
->FilterList
, filter
) != NULL
)
343 alGetFilteri(filter
, param
, piValues
);
347 alSetError(Context
, AL_INVALID_ENUM
);
352 alSetError(Context
, AL_INVALID_NAME
);
354 ProcessContext(Context
);
357 ALvoid AL_APIENTRY
alGetFilterf(ALuint filter
, ALenum param
, ALfloat
*pflValue
)
363 Context
= GetContextSuspended();
366 Device
= Context
->Device
;
367 if((ALFilter
=VerifyFilter(Device
->FilterList
, filter
)) != NULL
)
369 switch(ALFilter
->type
)
371 case AL_FILTER_LOWPASS
:
374 case AL_LOWPASS_GAIN
:
375 *pflValue
= ALFilter
->Gain
;
378 case AL_LOWPASS_GAINHF
:
379 *pflValue
= ALFilter
->GainHF
;
383 alSetError(Context
, AL_INVALID_ENUM
);
389 alSetError(Context
, AL_INVALID_ENUM
);
394 alSetError(Context
, AL_INVALID_NAME
);
396 ProcessContext(Context
);
399 ALvoid AL_APIENTRY
alGetFilterfv(ALuint filter
, ALenum param
, ALfloat
*pflValues
)
404 Context
= GetContextSuspended();
407 Device
= Context
->Device
;
408 if(VerifyFilter(Device
->FilterList
, filter
) != NULL
)
413 alGetFilterf(filter
, param
, pflValues
);
418 alSetError(Context
, AL_INVALID_NAME
);
420 ProcessContext(Context
);
424 ALvoid
ReleaseALFilters(ALCdevice
*device
)
426 ALfilter
*list
= device
->FilterList
;
429 ALfilter
*temp
= list
;
432 // Release filter structure
433 memset(temp
, 0, sizeof(ALfilter
));
436 device
->FilterList
= NULL
;
437 device
->FilterCount
= 0;
441 static void InitFilterParams(ALfilter
*filter
, ALenum type
)
446 filter
->GainHF
= 1.0;