Removed project files that are generated by "android update project" step.
[openal-soft/android.git] / OpenAL32 / alFilter.c
blob35a58c7a1db00a2dfdb638332ba3e597e4208b25
1 /**
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
21 #include "config.h"
23 #include <stdlib.h>
25 #include "AL/al.h"
26 #include "AL/alc.h"
27 #include "alMain.h"
28 #include "alFilter.h"
29 #include "alThunk.h"
30 #include "alError.h"
33 static void InitFilterParams(ALfilter *filter, ALenum type);
35 #define LookupFilter(m, k) ((ALfilter*)LookupUIntMapKey(&(m), (k)))
37 AL_API ALvoid AL_APIENTRY alGenFilters(ALsizei n, ALuint *filters)
39 ALCcontext *Context;
40 ALsizei i=0;
42 Context = GetContextSuspended();
43 if(!Context) return;
45 if (n > 0)
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)))
52 ALenum err;
54 while(i < n)
56 ALfilter *filter = calloc(1, sizeof(ALfilter));
57 if(!filter)
59 alSetError(Context, AL_OUT_OF_MEMORY);
60 alDeleteFilters(i, filters);
61 break;
64 filter->filter = ALTHUNK_ADDENTRY(filter);
65 err = InsertUIntMapEntry(&device->FilterMap, filter->filter,
66 filter);
67 if(err != AL_NO_ERROR)
69 ALTHUNK_REMOVEENTRY(filter->filter);
70 memset(filter, 0, sizeof(ALfilter));
71 free(filter);
73 alSetError(Context, err);
74 alDeleteFilters(i, filters);
75 break;
78 filters[i++] = filter->filter;
79 InitFilterParams(filter, AL_FILTER_NULL);
84 ProcessContext(Context);
87 AL_API ALvoid AL_APIENTRY alDeleteFilters(ALsizei n, ALuint *filters)
89 ALCcontext *Context;
90 ALfilter *ALFilter;
91 ALsizei i;
93 Context = GetContextSuspended();
94 if(!Context) return;
96 if (n >= 0)
98 ALCdevice *device = Context->Device;
100 // Check that all filters are valid
101 for (i = 0; i < n; i++)
103 if(!filters[i])
104 continue;
106 if(!LookupFilter(device->FilterMap, filters[i]))
108 alSetError(Context, AL_INVALID_NAME);
109 break;
113 if (i == n)
115 // All filters are valid
116 for (i = 0; i < n; i++)
118 // Recheck that the filter is valid, because there could be duplicated names
119 if((ALFilter=LookupFilter(device->FilterMap, filters[i])) != NULL)
121 RemoveUIntMapKey(&device->FilterMap, ALFilter->filter);
122 ALTHUNK_REMOVEENTRY(ALFilter->filter);
124 memset(ALFilter, 0, sizeof(ALfilter));
125 free(ALFilter);
130 else
131 alSetError(Context, AL_INVALID_VALUE);
133 ProcessContext(Context);
136 AL_API ALboolean AL_APIENTRY alIsFilter(ALuint filter)
138 ALCcontext *Context;
139 ALboolean result;
141 Context = GetContextSuspended();
142 if(!Context) return AL_FALSE;
144 result = ((!filter || LookupFilter(Context->Device->FilterMap, filter)) ?
145 AL_TRUE : AL_FALSE);
147 ProcessContext(Context);
149 return result;
152 AL_API ALvoid AL_APIENTRY alFilteri(ALuint filter, ALenum param, ALint iValue)
154 ALCcontext *Context;
155 ALCdevice *Device;
156 ALfilter *ALFilter;
158 Context = GetContextSuspended();
159 if(!Context) return;
161 Device = Context->Device;
162 if((ALFilter=LookupFilter(Device->FilterMap, filter)) != NULL)
164 switch(param)
166 case AL_FILTER_TYPE:
167 if(iValue == AL_FILTER_NULL ||
168 iValue == AL_FILTER_LOWPASS)
169 InitFilterParams(ALFilter, iValue);
170 else
171 alSetError(Context, AL_INVALID_VALUE);
172 break;
174 default:
175 alSetError(Context, AL_INVALID_ENUM);
176 break;
179 else
180 alSetError(Context, AL_INVALID_NAME);
182 ProcessContext(Context);
185 AL_API ALvoid AL_APIENTRY alFilteriv(ALuint filter, ALenum param, ALint *piValues)
187 ALCcontext *Context;
188 ALCdevice *Device;
190 Context = GetContextSuspended();
191 if(!Context) return;
193 Device = Context->Device;
194 if(LookupFilter(Device->FilterMap, filter) != NULL)
196 switch(param)
198 case AL_FILTER_TYPE:
199 alFilteri(filter, param, piValues[0]);
200 break;
202 default:
203 alSetError(Context, AL_INVALID_ENUM);
204 break;
207 else
208 alSetError(Context, AL_INVALID_NAME);
210 ProcessContext(Context);
213 AL_API ALvoid AL_APIENTRY alFilterf(ALuint filter, ALenum param, ALfloat flValue)
215 ALCcontext *Context;
216 ALCdevice *Device;
217 ALfilter *ALFilter;
219 Context = GetContextSuspended();
220 if(!Context) return;
222 Device = Context->Device;
223 if((ALFilter=LookupFilter(Device->FilterMap, filter)) != NULL)
225 switch(ALFilter->type)
227 case AL_FILTER_LOWPASS:
228 switch(param)
230 case AL_LOWPASS_GAIN:
231 if(flValue >= 0.0f && flValue <= 1.0f)
232 ALFilter->Gain = flValue;
233 else
234 alSetError(Context, AL_INVALID_VALUE);
235 break;
237 case AL_LOWPASS_GAINHF:
238 if(flValue >= 0.0f && flValue <= 1.0f)
239 ALFilter->GainHF = flValue;
240 else
241 alSetError(Context, AL_INVALID_VALUE);
242 break;
244 default:
245 alSetError(Context, AL_INVALID_ENUM);
246 break;
248 break;
250 default:
251 alSetError(Context, AL_INVALID_ENUM);
252 break;
255 else
256 alSetError(Context, AL_INVALID_NAME);
258 ProcessContext(Context);
261 AL_API ALvoid AL_APIENTRY alFilterfv(ALuint filter, ALenum param, ALfloat *pflValues)
263 ALCcontext *Context;
264 ALCdevice *Device;
266 Context = GetContextSuspended();
267 if(!Context) return;
269 Device = Context->Device;
270 if(LookupFilter(Device->FilterMap, filter) != NULL)
272 switch(param)
274 default:
275 alFilterf(filter, param, pflValues[0]);
276 break;
279 else
280 alSetError(Context, AL_INVALID_NAME);
282 ProcessContext(Context);
285 AL_API ALvoid AL_APIENTRY alGetFilteri(ALuint filter, ALenum param, ALint *piValue)
287 ALCcontext *Context;
288 ALCdevice *Device;
289 ALfilter *ALFilter;
291 Context = GetContextSuspended();
292 if(!Context) return;
294 Device = Context->Device;
295 if((ALFilter=LookupFilter(Device->FilterMap, filter)) != NULL)
297 switch(param)
299 case AL_FILTER_TYPE:
300 *piValue = ALFilter->type;
301 break;
303 default:
304 alSetError(Context, AL_INVALID_ENUM);
305 break;
308 else
309 alSetError(Context, AL_INVALID_NAME);
311 ProcessContext(Context);
314 AL_API ALvoid AL_APIENTRY alGetFilteriv(ALuint filter, ALenum param, ALint *piValues)
316 ALCcontext *Context;
317 ALCdevice *Device;
319 Context = GetContextSuspended();
320 if(!Context) return;
322 Device = Context->Device;
323 if(LookupFilter(Device->FilterMap, filter) != NULL)
325 switch(param)
327 case AL_FILTER_TYPE:
328 alGetFilteri(filter, param, piValues);
329 break;
331 default:
332 alSetError(Context, AL_INVALID_ENUM);
333 break;
336 else
337 alSetError(Context, AL_INVALID_NAME);
339 ProcessContext(Context);
342 AL_API ALvoid AL_APIENTRY alGetFilterf(ALuint filter, ALenum param, ALfloat *pflValue)
344 ALCcontext *Context;
345 ALCdevice *Device;
346 ALfilter *ALFilter;
348 Context = GetContextSuspended();
349 if(!Context) return;
351 Device = Context->Device;
352 if((ALFilter=LookupFilter(Device->FilterMap, filter)) != NULL)
354 switch(ALFilter->type)
356 case AL_FILTER_LOWPASS:
357 switch(param)
359 case AL_LOWPASS_GAIN:
360 *pflValue = ALFilter->Gain;
361 break;
363 case AL_LOWPASS_GAINHF:
364 *pflValue = ALFilter->GainHF;
365 break;
367 default:
368 alSetError(Context, AL_INVALID_ENUM);
369 break;
371 break;
373 default:
374 alSetError(Context, AL_INVALID_ENUM);
375 break;
378 else
379 alSetError(Context, AL_INVALID_NAME);
381 ProcessContext(Context);
384 AL_API ALvoid AL_APIENTRY alGetFilterfv(ALuint filter, ALenum param, ALfloat *pflValues)
386 ALCcontext *Context;
387 ALCdevice *Device;
389 Context = GetContextSuspended();
390 if(!Context) return;
392 Device = Context->Device;
393 if(LookupFilter(Device->FilterMap, filter) != NULL)
395 switch(param)
397 default:
398 alGetFilterf(filter, param, pflValues);
399 break;
402 else
403 alSetError(Context, AL_INVALID_NAME);
405 ProcessContext(Context);
409 ALvoid ReleaseALFilters(ALCdevice *device)
411 ALsizei i;
412 for(i = 0;i < device->FilterMap.size;i++)
414 ALfilter *temp = device->FilterMap.array[i].value;
415 device->FilterMap.array[i].value = NULL;
417 // Release filter structure
418 ALTHUNK_REMOVEENTRY(temp->filter);
419 memset(temp, 0, sizeof(ALfilter));
420 free(temp);
425 static void InitFilterParams(ALfilter *filter, ALenum type)
427 filter->type = type;
429 filter->Gain = 1.0;
430 filter->GainHF = 1.0;