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 ALfilter
*g_FilterList
;
34 static ALuint g_FilterCount
;
36 static void InitFilterParams(ALfilter
*filter
, ALenum type
);
39 AL_API ALvoid AL_APIENTRY
alGenFilters(ALsizei n
, ALuint
*filters
)
44 Context
= alcGetCurrentContext();
45 SuspendContext(Context
);
49 // Check that enough memory has been allocted in the 'sources' array for n Sources
50 if (!IsBadWritePtr((void*)filters
, n
* sizeof(ALuint
)))
52 ALfilter
**list
= &g_FilterList
;
54 list
= &(*list
)->next
;
59 *list
= calloc(1, sizeof(ALfilter
));
62 // We must have run out or memory
63 alDeleteFilters(i
, filters
);
64 alSetError(AL_OUT_OF_MEMORY
);
68 filters
[i
] = (ALuint
)ALTHUNK_ADDENTRY(*list
);
69 (*list
)->filter
= filters
[i
];
71 InitFilterParams(*list
, AL_FILTER_NULL
);
78 ProcessContext(Context
);
81 AL_API ALvoid AL_APIENTRY
alDeleteFilters(ALsizei n
, ALuint
*filters
)
87 Context
= alcGetCurrentContext();
88 SuspendContext(Context
);
92 // Check that all filters are valid
93 for (i
= 0; i
< n
; i
++)
95 if (!alIsFilter(filters
[i
]))
97 alSetError(AL_INVALID_NAME
);
104 // All filters are valid
105 for (i
= 0; i
< n
; i
++)
107 // Recheck that the filter is valid, because there could be duplicated names
108 if (filters
[i
] && alIsFilter(filters
[i
]))
112 ALFilter
= ((ALfilter
*)ALTHUNK_LOOKUPENTRY(filters
[i
]));
114 // Remove Source from list of Sources
115 list
= &g_FilterList
;
116 while(*list
&& *list
!= ALFilter
)
117 list
= &(*list
)->next
;
120 *list
= (*list
)->next
;
121 ALTHUNK_REMOVEENTRY(ALFilter
->filter
);
123 memset(ALFilter
, 0, sizeof(ALfilter
));
132 alSetError(AL_INVALID_VALUE
);
134 ProcessContext(Context
);
137 AL_API ALboolean AL_APIENTRY
alIsFilter(ALuint filter
)
142 Context
= alcGetCurrentContext();
143 SuspendContext(Context
);
145 list
= &g_FilterList
;
146 while(*list
&& (*list
)->filter
!= filter
)
147 list
= &(*list
)->next
;
149 ProcessContext(Context
);
151 return ((*list
|| !filter
) ? AL_TRUE
: AL_FALSE
);
154 AL_API ALvoid AL_APIENTRY
alFilteri(ALuint filter
, ALenum param
, ALint iValue
)
158 Context
= alcGetCurrentContext();
159 SuspendContext(Context
);
161 if (filter
&& alIsFilter(filter
))
163 ALfilter
*ALFilter
= (ALfilter
*)ALTHUNK_LOOKUPENTRY(filter
);
168 if(iValue
== AL_FILTER_NULL
||
169 iValue
== AL_FILTER_LOWPASS
)
170 InitFilterParams(ALFilter
, iValue
);
172 alSetError(AL_INVALID_VALUE
);
176 alSetError(AL_INVALID_ENUM
);
181 alSetError(AL_INVALID_NAME
);
183 ProcessContext(Context
);
186 AL_API ALvoid AL_APIENTRY
alFilteriv(ALuint filter
, ALenum param
, ALint
*piValues
)
190 Context
= alcGetCurrentContext();
191 SuspendContext(Context
);
193 if (filter
&& alIsFilter(filter
))
198 alFilteri(filter
, param
, piValues
[0]);
202 alSetError(AL_INVALID_ENUM
);
207 alSetError(AL_INVALID_NAME
);
209 ProcessContext(Context
);
212 AL_API ALvoid AL_APIENTRY
alFilterf(ALuint filter
, ALenum param
, ALfloat flValue
)
216 Context
= alcGetCurrentContext();
217 SuspendContext(Context
);
219 if (filter
&& alIsFilter(filter
))
221 ALfilter
*ALFilter
= (ALfilter
*)ALTHUNK_LOOKUPENTRY(filter
);
225 case AL_LOWPASS_GAIN
:
226 if(ALFilter
->type
== AL_FILTER_LOWPASS
)
228 if(flValue
>= 0.0f
&& flValue
<= 1.0f
)
229 ALFilter
->Gain
= flValue
;
232 alSetError(AL_INVALID_ENUM
);
235 case AL_LOWPASS_GAINHF
:
236 if(ALFilter
->type
== AL_FILTER_LOWPASS
)
238 if(flValue
>= 0.0f
&& flValue
<= 1.0f
)
239 ALFilter
->GainHF
= flValue
;
242 alSetError(AL_INVALID_ENUM
);
246 alSetError(AL_INVALID_ENUM
);
251 alSetError(AL_INVALID_NAME
);
253 ProcessContext(Context
);
256 AL_API ALvoid AL_APIENTRY
alFilterfv(ALuint filter
, ALenum param
, ALfloat
*pflValues
)
260 Context
= alcGetCurrentContext();
261 SuspendContext(Context
);
263 if (filter
&& alIsFilter(filter
))
267 case AL_LOWPASS_GAIN
:
268 case AL_LOWPASS_GAINHF
:
269 alFilterf(filter
, param
, pflValues
[0]);
273 alSetError(AL_INVALID_ENUM
);
278 alSetError(AL_INVALID_NAME
);
280 ProcessContext(Context
);
283 AL_API ALvoid AL_APIENTRY
alGetFilteri(ALuint filter
, ALenum param
, ALint
*piValue
)
289 Context
= alcGetCurrentContext();
290 SuspendContext(Context
);
292 if (filter
&& alIsFilter(filter
))
297 alSetError(AL_INVALID_ENUM
);
302 alSetError(AL_INVALID_NAME
);
304 ProcessContext(Context
);
307 AL_API ALvoid AL_APIENTRY
alGetFilteriv(ALuint filter
, ALenum param
, ALint
*piValues
)
313 Context
= alcGetCurrentContext();
314 SuspendContext(Context
);
316 if (filter
&& alIsFilter(filter
))
321 alSetError(AL_INVALID_ENUM
);
326 alSetError(AL_INVALID_NAME
);
328 ProcessContext(Context
);
331 AL_API ALvoid AL_APIENTRY
alGetFilterf(ALuint filter
, ALenum param
, ALfloat
*pflValue
)
335 Context
= alcGetCurrentContext();
336 SuspendContext(Context
);
338 if (filter
&& alIsFilter(filter
))
340 ALfilter
*ALFilter
= (ALfilter
*)ALTHUNK_LOOKUPENTRY(filter
);
344 case AL_LOWPASS_GAIN
:
345 if(ALFilter
->type
== AL_FILTER_LOWPASS
)
346 *pflValue
= ALFilter
->Gain
;
348 alSetError(AL_INVALID_ENUM
);
351 case AL_LOWPASS_GAINHF
:
352 if(ALFilter
->type
== AL_FILTER_LOWPASS
)
353 *pflValue
= ALFilter
->GainHF
;
355 alSetError(AL_INVALID_ENUM
);
359 alSetError(AL_INVALID_ENUM
);
364 alSetError(AL_INVALID_NAME
);
366 ProcessContext(Context
);
369 AL_API ALvoid AL_APIENTRY
alGetFilterfv(ALuint filter
, ALenum param
, ALfloat
*pflValues
)
373 Context
= alcGetCurrentContext();
374 SuspendContext(Context
);
376 if (filter
&& alIsFilter(filter
))
380 case AL_LOWPASS_GAIN
:
381 case AL_LOWPASS_GAINHF
:
382 alGetFilterf(filter
, param
, pflValues
);
386 alSetError(AL_INVALID_ENUM
);
391 alSetError(AL_INVALID_NAME
);
393 ProcessContext(Context
);
397 ALvoid
ReleaseALFilters(ALvoid
)
400 if(g_FilterCount
> 0)
401 AL_PRINT("exit() %d Filter(s) NOT deleted\n", g_FilterCount
);
406 ALfilter
*temp
= g_FilterList
;
407 g_FilterList
= g_FilterList
->next
;
409 // Release filter structure
410 memset(temp
, 0, sizeof(ALfilter
));
417 static void InitFilterParams(ALfilter
*filter
, ALenum type
)
422 filter
->GainHF
= 1.0;