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();
45 ALCdevice
*device
= Context
->Device
;
47 // Check that enough memory has been allocted in the 'filters' array for n Filters
48 if (!IsBadWritePtr((void*)filters
, n
* sizeof(ALuint
)))
50 ALfilter
**list
= &device
->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
);
70 device
->FilterCount
++;
73 list
= &(*list
)->next
;
78 ProcessContext(Context
);
81 ALvoid AL_APIENTRY
alDeleteFilters(ALsizei n
, ALuint
*filters
)
87 Context
= GetContextSuspended();
91 ALCdevice
*device
= Context
->Device
;
93 // Check that all filters are valid
94 for (i
= 0; i
< n
; i
++)
96 if (!alIsFilter(filters
[i
]))
98 alSetError(AL_INVALID_NAME
);
105 // All filters are valid
106 for (i
= 0; i
< n
; i
++)
108 // Recheck that the filter is valid, because there could be duplicated names
109 if (filters
[i
] && alIsFilter(filters
[i
]))
113 ALFilter
= ((ALfilter
*)ALTHUNK_LOOKUPENTRY(filters
[i
]));
115 // Remove Source from list of Sources
116 list
= &device
->FilterList
;
117 while(*list
&& *list
!= ALFilter
)
118 list
= &(*list
)->next
;
121 *list
= (*list
)->next
;
122 ALTHUNK_REMOVEENTRY(ALFilter
->filter
);
124 memset(ALFilter
, 0, sizeof(ALfilter
));
127 device
->FilterCount
--;
133 alSetError(AL_INVALID_VALUE
);
135 ProcessContext(Context
);
138 ALboolean AL_APIENTRY
alIsFilter(ALuint filter
)
143 Context
= GetContextSuspended();
145 list
= Context
->Device
->FilterList
;
146 while(list
&& list
->filter
!= filter
)
149 ProcessContext(Context
);
151 return ((list
|| !filter
) ? AL_TRUE
: AL_FALSE
);
154 ALvoid AL_APIENTRY
alFilteri(ALuint filter
, ALenum param
, ALint iValue
)
158 Context
= GetContextSuspended();
160 if (filter
&& alIsFilter(filter
))
162 ALfilter
*ALFilter
= (ALfilter
*)ALTHUNK_LOOKUPENTRY(filter
);
167 if(iValue
== AL_FILTER_NULL
||
168 iValue
== AL_FILTER_LOWPASS
)
169 InitFilterParams(ALFilter
, iValue
);
171 alSetError(AL_INVALID_VALUE
);
175 alSetError(AL_INVALID_ENUM
);
180 alSetError(AL_INVALID_NAME
);
182 ProcessContext(Context
);
185 ALvoid AL_APIENTRY
alFilteriv(ALuint filter
, ALenum param
, ALint
*piValues
)
189 Context
= GetContextSuspended();
191 if (filter
&& alIsFilter(filter
))
196 alFilteri(filter
, param
, piValues
[0]);
200 alSetError(AL_INVALID_ENUM
);
205 alSetError(AL_INVALID_NAME
);
207 ProcessContext(Context
);
210 ALvoid AL_APIENTRY
alFilterf(ALuint filter
, ALenum param
, ALfloat flValue
)
214 Context
= GetContextSuspended();
216 if (filter
&& alIsFilter(filter
))
218 ALfilter
*ALFilter
= (ALfilter
*)ALTHUNK_LOOKUPENTRY(filter
);
220 switch(ALFilter
->type
)
222 case AL_FILTER_LOWPASS
:
225 case AL_LOWPASS_GAIN
:
226 if(flValue
>= 0.0f
&& flValue
<= 1.0f
)
227 ALFilter
->Gain
= flValue
;
229 alSetError(AL_INVALID_VALUE
);
232 case AL_LOWPASS_GAINHF
:
233 if(flValue
>= 0.0f
&& flValue
<= 1.0f
)
234 ALFilter
->GainHF
= flValue
;
236 alSetError(AL_INVALID_VALUE
);
240 alSetError(AL_INVALID_ENUM
);
246 alSetError(AL_INVALID_ENUM
);
251 alSetError(AL_INVALID_NAME
);
253 ProcessContext(Context
);
256 ALvoid AL_APIENTRY
alFilterfv(ALuint filter
, ALenum param
, ALfloat
*pflValues
)
260 Context
= GetContextSuspended();
262 if (filter
&& alIsFilter(filter
))
267 alFilterf(filter
, param
, pflValues
[0]);
272 alSetError(AL_INVALID_NAME
);
274 ProcessContext(Context
);
277 ALvoid AL_APIENTRY
alGetFilteri(ALuint filter
, ALenum param
, ALint
*piValue
)
281 Context
= GetContextSuspended();
283 if (filter
&& alIsFilter(filter
))
285 ALfilter
*ALFilter
= (ALfilter
*)ALTHUNK_LOOKUPENTRY(filter
);
290 *piValue
= ALFilter
->type
;
294 alSetError(AL_INVALID_ENUM
);
299 alSetError(AL_INVALID_NAME
);
301 ProcessContext(Context
);
304 ALvoid AL_APIENTRY
alGetFilteriv(ALuint filter
, ALenum param
, ALint
*piValues
)
308 Context
= GetContextSuspended();
310 if (filter
&& alIsFilter(filter
))
315 alGetFilteri(filter
, param
, piValues
);
319 alSetError(AL_INVALID_ENUM
);
324 alSetError(AL_INVALID_NAME
);
326 ProcessContext(Context
);
329 ALvoid AL_APIENTRY
alGetFilterf(ALuint filter
, ALenum param
, ALfloat
*pflValue
)
333 Context
= GetContextSuspended();
335 if (filter
&& alIsFilter(filter
))
337 ALfilter
*ALFilter
= (ALfilter
*)ALTHUNK_LOOKUPENTRY(filter
);
339 switch(ALFilter
->type
)
341 case AL_FILTER_LOWPASS
:
344 case AL_LOWPASS_GAIN
:
345 *pflValue
= ALFilter
->Gain
;
348 case AL_LOWPASS_GAINHF
:
349 *pflValue
= ALFilter
->GainHF
;
353 alSetError(AL_INVALID_ENUM
);
359 alSetError(AL_INVALID_ENUM
);
364 alSetError(AL_INVALID_NAME
);
366 ProcessContext(Context
);
369 ALvoid AL_APIENTRY
alGetFilterfv(ALuint filter
, ALenum param
, ALfloat
*pflValues
)
373 Context
= GetContextSuspended();
375 if (filter
&& alIsFilter(filter
))
380 alGetFilterf(filter
, param
, pflValues
);
385 alSetError(AL_INVALID_NAME
);
387 ProcessContext(Context
);
391 ALvoid
ReleaseALFilters(ALCdevice
*device
)
393 ALfilter
*list
= device
->FilterList
;
396 ALfilter
*temp
= list
;
399 // Release filter structure
400 memset(temp
, 0, sizeof(ALfilter
));
403 device
->FilterList
= NULL
;
404 device
->FilterCount
= 0;
408 static void InitFilterParams(ALfilter
*filter
, ALenum type
)
413 filter
->GainHF
= 1.0;