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
31 static ALfilter
*g_FilterList
;
32 static ALuint g_FilterCount
;
34 static void InitFilterParams(ALfilter
*filter
, ALenum type
);
37 AL_API ALvoid AL_APIENTRY
alGenFilters(ALsizei n
, ALuint
*filters
)
42 Context
= alcGetCurrentContext();
43 SuspendContext(Context
);
47 // Check that enough memory has been allocted in the 'sources' array for n Sources
48 if (!IsBadWritePtr((void*)filters
, n
* sizeof(ALuint
)))
50 ALfilter
**list
= &g_FilterList
;
52 list
= &(*list
)->next
;
57 *list
= calloc(1, sizeof(ALfilter
));
60 // We must have run out or memory
61 alDeleteFilters(i
, filters
);
62 alSetError(AL_OUT_OF_MEMORY
);
66 filters
[i
] = (ALuint
)ALTHUNK_ADDENTRY(*list
);
67 (*list
)->filter
= filters
[i
];
69 InitFilterParams(*list
, AL_FILTER_NULL
);
76 ProcessContext(Context
);
79 AL_API ALvoid AL_APIENTRY
alDeleteFilters(ALsizei n
, ALuint
*filters
)
85 Context
= alcGetCurrentContext();
86 SuspendContext(Context
);
90 // Check that all filters are valid
91 for (i
= 0; i
< n
; i
++)
93 if (!alIsFilter(filters
[i
]))
95 alSetError(AL_INVALID_NAME
);
102 // All filters are valid
103 for (i
= 0; i
< n
; i
++)
105 // Recheck that the filter is valid, because there could be duplicated names
106 if (alIsFilter(filters
[i
]))
110 ALFilter
= ((ALfilter
*)ALTHUNK_LOOKUPENTRY(filters
[i
]));
112 // Remove Source from list of Sources
113 list
= &g_FilterList
;
114 while(*list
&& *list
!= ALFilter
)
115 list
= &(*list
)->next
;
118 *list
= (*list
)->next
;
119 ALTHUNK_REMOVEENTRY(ALFilter
->filter
);
121 memset(ALFilter
, 0, sizeof(ALfilter
));
130 alSetError(AL_INVALID_VALUE
);
132 ProcessContext(Context
);
135 AL_API ALboolean AL_APIENTRY
alIsFilter(ALuint filter
)
140 Context
= alcGetCurrentContext();
141 SuspendContext(Context
);
143 list
= &g_FilterList
;
144 while(*list
&& (*list
)->filter
!= filter
)
145 list
= &(*list
)->next
;
147 ProcessContext(Context
);
149 return (*list
? AL_TRUE
: AL_FALSE
);
152 AL_API ALvoid AL_APIENTRY
alFilteri(ALuint filter
, ALenum param
, ALint iValue
)
158 Context
= alcGetCurrentContext();
159 SuspendContext(Context
);
161 if (alIsFilter(filter
))
166 alSetError(AL_INVALID_ENUM
);
171 alSetError(AL_INVALID_NAME
);
173 ProcessContext(Context
);
176 AL_API ALvoid AL_APIENTRY
alFilteriv(ALuint filter
, ALenum param
, ALint
*piValues
)
182 Context
= alcGetCurrentContext();
183 SuspendContext(Context
);
185 if (alIsFilter(filter
))
190 alSetError(AL_INVALID_ENUM
);
195 alSetError(AL_INVALID_NAME
);
197 ProcessContext(Context
);
200 AL_API ALvoid AL_APIENTRY
alFilterf(ALuint filter
, ALenum param
, ALfloat flValue
)
206 Context
= alcGetCurrentContext();
207 SuspendContext(Context
);
209 if (alIsFilter(filter
))
214 alSetError(AL_INVALID_ENUM
);
219 alSetError(AL_INVALID_NAME
);
221 ProcessContext(Context
);
224 AL_API ALvoid AL_APIENTRY
alFilterfv(ALuint filter
, ALenum param
, ALfloat
*pflValues
)
230 Context
= alcGetCurrentContext();
231 SuspendContext(Context
);
233 if (alIsFilter(filter
))
238 alSetError(AL_INVALID_ENUM
);
243 alSetError(AL_INVALID_NAME
);
245 ProcessContext(Context
);
248 AL_API ALvoid AL_APIENTRY
alGetFilteri(ALuint filter
, ALenum param
, ALint
*piValue
)
254 Context
= alcGetCurrentContext();
255 SuspendContext(Context
);
257 if (alIsFilter(filter
))
262 alSetError(AL_INVALID_ENUM
);
267 alSetError(AL_INVALID_NAME
);
269 ProcessContext(Context
);
272 AL_API ALvoid AL_APIENTRY
alGetFilteriv(ALuint filter
, ALenum param
, ALint
*piValues
)
278 Context
= alcGetCurrentContext();
279 SuspendContext(Context
);
281 if (alIsFilter(filter
))
286 alSetError(AL_INVALID_ENUM
);
291 alSetError(AL_INVALID_NAME
);
293 ProcessContext(Context
);
296 AL_API ALvoid AL_APIENTRY
alGetFilterf(ALuint filter
, ALenum param
, ALfloat
*pflValue
)
302 Context
= alcGetCurrentContext();
303 SuspendContext(Context
);
305 if (alIsFilter(filter
))
310 alSetError(AL_INVALID_ENUM
);
315 alSetError(AL_INVALID_NAME
);
317 ProcessContext(Context
);
320 AL_API ALvoid AL_APIENTRY
alGetFilterfv(ALuint filter
, ALenum param
, ALfloat
*pflValues
)
326 Context
= alcGetCurrentContext();
327 SuspendContext(Context
);
329 if (alIsFilter(filter
))
334 alSetError(AL_INVALID_ENUM
);
339 alSetError(AL_INVALID_NAME
);
341 ProcessContext(Context
);
345 static void InitFilterParams(ALfilter
*filter
, ALenum type
)