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 ALvoid AL_APIENTRY
alGenFilters(ALsizei n
, ALuint
*filters
)
41 Context
= GetContextSuspended();
46 ALCdevice
*device
= Context
->Device
;
48 // Check that enough memory has been allocted in the 'filters' array for n Filters
49 if (!IsBadWritePtr((void*)filters
, n
* sizeof(ALuint
)))
51 ALfilter
**list
= &device
->FilterList
;
53 list
= &(*list
)->next
;
58 *list
= calloc(1, sizeof(ALfilter
));
61 // We must have run out or memory
62 alDeleteFilters(i
, filters
);
63 alSetError(AL_OUT_OF_MEMORY
);
67 filters
[i
] = (ALuint
)ALTHUNK_ADDENTRY(*list
);
68 (*list
)->filter
= filters
[i
];
70 InitFilterParams(*list
, AL_FILTER_NULL
);
71 device
->FilterCount
++;
74 list
= &(*list
)->next
;
79 ProcessContext(Context
);
82 ALvoid AL_APIENTRY
alDeleteFilters(ALsizei n
, ALuint
*filters
)
88 Context
= GetContextSuspended();
93 ALCdevice
*device
= Context
->Device
;
95 // Check that all filters are valid
96 for (i
= 0; i
< n
; i
++)
98 if (!alIsFilter(filters
[i
]))
100 alSetError(AL_INVALID_NAME
);
107 // All filters are valid
108 for (i
= 0; i
< n
; i
++)
110 // Recheck that the filter is valid, because there could be duplicated names
111 if (filters
[i
] && alIsFilter(filters
[i
]))
115 ALFilter
= ((ALfilter
*)ALTHUNK_LOOKUPENTRY(filters
[i
]));
117 // Remove Source from list of Sources
118 list
= &device
->FilterList
;
119 while(*list
&& *list
!= ALFilter
)
120 list
= &(*list
)->next
;
123 *list
= (*list
)->next
;
124 ALTHUNK_REMOVEENTRY(ALFilter
->filter
);
126 memset(ALFilter
, 0, sizeof(ALfilter
));
129 device
->FilterCount
--;
135 alSetError(AL_INVALID_VALUE
);
137 ProcessContext(Context
);
140 ALboolean AL_APIENTRY
alIsFilter(ALuint filter
)
145 Context
= GetContextSuspended();
146 if(!Context
) return AL_FALSE
;
148 list
= Context
->Device
->FilterList
;
149 while(list
&& list
->filter
!= filter
)
152 ProcessContext(Context
);
154 return ((list
|| !filter
) ? AL_TRUE
: AL_FALSE
);
157 ALvoid AL_APIENTRY
alFilteri(ALuint filter
, ALenum param
, ALint iValue
)
161 Context
= GetContextSuspended();
164 if (filter
&& alIsFilter(filter
))
166 ALfilter
*ALFilter
= (ALfilter
*)ALTHUNK_LOOKUPENTRY(filter
);
171 if(iValue
== AL_FILTER_NULL
||
172 iValue
== AL_FILTER_LOWPASS
)
173 InitFilterParams(ALFilter
, iValue
);
175 alSetError(AL_INVALID_VALUE
);
179 alSetError(AL_INVALID_ENUM
);
184 alSetError(AL_INVALID_NAME
);
186 ProcessContext(Context
);
189 ALvoid AL_APIENTRY
alFilteriv(ALuint filter
, ALenum param
, ALint
*piValues
)
193 Context
= GetContextSuspended();
196 if (filter
&& alIsFilter(filter
))
201 alFilteri(filter
, param
, piValues
[0]);
205 alSetError(AL_INVALID_ENUM
);
210 alSetError(AL_INVALID_NAME
);
212 ProcessContext(Context
);
215 ALvoid AL_APIENTRY
alFilterf(ALuint filter
, ALenum param
, ALfloat flValue
)
219 Context
= GetContextSuspended();
222 if (filter
&& alIsFilter(filter
))
224 ALfilter
*ALFilter
= (ALfilter
*)ALTHUNK_LOOKUPENTRY(filter
);
226 switch(ALFilter
->type
)
228 case AL_FILTER_LOWPASS
:
231 case AL_LOWPASS_GAIN
:
232 if(flValue
>= 0.0f
&& flValue
<= 1.0f
)
233 ALFilter
->Gain
= flValue
;
235 alSetError(AL_INVALID_VALUE
);
238 case AL_LOWPASS_GAINHF
:
239 if(flValue
>= 0.0f
&& flValue
<= 1.0f
)
240 ALFilter
->GainHF
= flValue
;
242 alSetError(AL_INVALID_VALUE
);
246 alSetError(AL_INVALID_ENUM
);
252 alSetError(AL_INVALID_ENUM
);
257 alSetError(AL_INVALID_NAME
);
259 ProcessContext(Context
);
262 ALvoid AL_APIENTRY
alFilterfv(ALuint filter
, ALenum param
, ALfloat
*pflValues
)
266 Context
= GetContextSuspended();
269 if (filter
&& alIsFilter(filter
))
274 alFilterf(filter
, param
, pflValues
[0]);
279 alSetError(AL_INVALID_NAME
);
281 ProcessContext(Context
);
284 ALvoid AL_APIENTRY
alGetFilteri(ALuint filter
, ALenum param
, ALint
*piValue
)
288 Context
= GetContextSuspended();
291 if (filter
&& alIsFilter(filter
))
293 ALfilter
*ALFilter
= (ALfilter
*)ALTHUNK_LOOKUPENTRY(filter
);
298 *piValue
= ALFilter
->type
;
302 alSetError(AL_INVALID_ENUM
);
307 alSetError(AL_INVALID_NAME
);
309 ProcessContext(Context
);
312 ALvoid AL_APIENTRY
alGetFilteriv(ALuint filter
, ALenum param
, ALint
*piValues
)
316 Context
= GetContextSuspended();
319 if (filter
&& alIsFilter(filter
))
324 alGetFilteri(filter
, param
, piValues
);
328 alSetError(AL_INVALID_ENUM
);
333 alSetError(AL_INVALID_NAME
);
335 ProcessContext(Context
);
338 ALvoid AL_APIENTRY
alGetFilterf(ALuint filter
, ALenum param
, ALfloat
*pflValue
)
342 Context
= GetContextSuspended();
345 if (filter
&& alIsFilter(filter
))
347 ALfilter
*ALFilter
= (ALfilter
*)ALTHUNK_LOOKUPENTRY(filter
);
349 switch(ALFilter
->type
)
351 case AL_FILTER_LOWPASS
:
354 case AL_LOWPASS_GAIN
:
355 *pflValue
= ALFilter
->Gain
;
358 case AL_LOWPASS_GAINHF
:
359 *pflValue
= ALFilter
->GainHF
;
363 alSetError(AL_INVALID_ENUM
);
369 alSetError(AL_INVALID_ENUM
);
374 alSetError(AL_INVALID_NAME
);
376 ProcessContext(Context
);
379 ALvoid AL_APIENTRY
alGetFilterfv(ALuint filter
, ALenum param
, ALfloat
*pflValues
)
383 Context
= GetContextSuspended();
386 if (filter
&& alIsFilter(filter
))
391 alGetFilterf(filter
, param
, pflValues
);
396 alSetError(AL_INVALID_NAME
);
398 ProcessContext(Context
);
402 ALvoid
ReleaseALFilters(ALCdevice
*device
)
404 ALfilter
*list
= device
->FilterList
;
407 ALfilter
*temp
= list
;
410 // Release filter structure
411 memset(temp
, 0, sizeof(ALfilter
));
414 device
->FilterList
= NULL
;
415 device
->FilterCount
= 0;
419 static void InitFilterParams(ALfilter
*filter
, ALenum type
)
424 filter
->GainHF
= 1.0;