Add missing config.h includes
[openal-soft/openbsd.git] / OpenAL32 / alAuxEffectSlot.c
blob3ce845ced54618d8fad1b3a095e3b37efea9baf9
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 "alAuxEffectSlot.h"
29 #include "alThunk.h"
30 #include "alError.h"
33 AL_API ALvoid AL_APIENTRY alGenAuxiliaryEffectSlots(ALsizei n, ALuint *effectslots)
35 ALCcontext *Context;
36 ALsizei i;
38 Context = alcGetCurrentContext();
39 if(!Context)
41 alSetError(AL_INVALID_OPERATION);
42 return;
44 SuspendContext(Context);
46 if (n > 0)
48 /* NOTE: We only support one slot currently */
49 if(n == 1 && Context->AuxiliaryEffectSlotCount == 0)
51 // Check that enough memory has been allocted in the 'effectslots' array for n Effect Slots
52 if (!IsBadWritePtr((void*)effectslots, n * sizeof(ALuint)))
54 ALeffectslot **list = &Context->AuxiliaryEffectSlot;
55 while(*list)
56 list = &(*list)->next;
58 i = 0;
59 while(i < n)
61 *list = calloc(1, sizeof(ALeffectslot));
62 if(!(*list))
64 // We must have run out or memory
65 alDeleteAuxiliaryEffectSlots(i, effectslots);
66 alSetError(AL_OUT_OF_MEMORY);
67 break;
70 (*list)->Gain = 1.0;
71 (*list)->AuxSendAuto = AL_TRUE;
72 (*list)->refcount = 0;
74 effectslots[i] = (ALuint)ALTHUNK_ADDENTRY(*list);
75 (*list)->effectslot = effectslots[i];
77 Context->AuxiliaryEffectSlotCount++;
78 i++;
80 list = &(*list)->next;
84 else
85 alSetError(AL_INVALID_OPERATION);
88 ProcessContext(Context);
91 AL_API ALvoid AL_APIENTRY alDeleteAuxiliaryEffectSlots(ALsizei n, ALuint *effectslots)
93 ALCcontext *Context;
94 ALeffectslot *ALAuxiliaryEffectSlot;
95 ALsizei i;
97 Context = alcGetCurrentContext();
98 if(!Context)
100 alSetError(AL_INVALID_OPERATION);
101 return;
103 SuspendContext(Context);
105 if (n >= 0)
107 // Check that all effectslots are valid
108 for (i = 0; i < n; i++)
110 if (!alIsAuxiliaryEffectSlot(effectslots[i]))
112 alSetError(AL_INVALID_NAME);
113 break;
115 else
117 ALAuxiliaryEffectSlot = (ALeffectslot*)ALTHUNK_LOOKUPENTRY(effectslots[i]);
118 if(ALAuxiliaryEffectSlot->refcount > 0)
120 alSetError(AL_INVALID_NAME);
121 break;
126 if (i == n)
128 // All effectslots are valid
129 for (i = 0; i < n; i++)
131 // Recheck that the effectslot is valid, because there could be duplicated names
132 if (alIsAuxiliaryEffectSlot(effectslots[i]))
134 ALeffectslot **list;
136 ALAuxiliaryEffectSlot = ((ALeffectslot*)ALTHUNK_LOOKUPENTRY(effectslots[i]));
138 // Remove Source from list of Sources
139 list = &Context->AuxiliaryEffectSlot;
140 while(*list && *list != ALAuxiliaryEffectSlot)
141 list = &(*list)->next;
143 if(*list)
144 *list = (*list)->next;
145 ALTHUNK_REMOVEENTRY(ALAuxiliaryEffectSlot->effectslot);
147 memset(ALAuxiliaryEffectSlot, 0, sizeof(ALeffectslot));
148 free(ALAuxiliaryEffectSlot);
150 Context->AuxiliaryEffectSlotCount--;
155 else
156 alSetError(AL_INVALID_VALUE);
158 ProcessContext(Context);
161 AL_API ALboolean AL_APIENTRY alIsAuxiliaryEffectSlot(ALuint effectslot)
163 ALCcontext *Context;
164 ALeffectslot **list;
166 Context = alcGetCurrentContext();
167 if(!Context)
169 alSetError(AL_INVALID_OPERATION);
170 return AL_FALSE;
172 SuspendContext(Context);
174 list = &Context->AuxiliaryEffectSlot;
175 while(*list && (*list)->effectslot != effectslot)
176 list = &(*list)->next;
178 ProcessContext(Context);
180 return (*list ? AL_TRUE : AL_FALSE);
183 AL_API ALvoid AL_APIENTRY alAuxiliaryEffectSloti(ALuint effectslot, ALenum param, ALint iValue)
185 ALCcontext *Context;
187 Context = alcGetCurrentContext();
188 if(!Context)
190 alSetError(AL_INVALID_OPERATION);
191 return;
193 SuspendContext(Context);
195 if (alIsAuxiliaryEffectSlot(effectslot))
197 ALeffectslot *ALEffectSlot = (ALeffectslot*)ALTHUNK_LOOKUPENTRY(effectslot);
199 switch(param)
201 case AL_EFFECTSLOT_EFFECT:
202 if(alIsEffect(iValue))
204 ALeffect *effect = (ALeffect*)ALTHUNK_LOOKUPENTRY(iValue);
205 if(!effect)
207 ALEffectSlot->effect.type = AL_EFFECT_NULL;
208 ALEffectSlot->effect.effect = 0;
210 else
211 memcpy(&ALEffectSlot->effect, effect, sizeof(*effect));
213 else
214 alSetError(AL_INVALID_VALUE);
215 break;
217 case AL_EFFECTSLOT_AUXILIARY_SEND_AUTO:
218 if(iValue == AL_TRUE || iValue == AL_FALSE)
219 ALEffectSlot->AuxSendAuto = iValue;
220 else
221 alSetError(AL_INVALID_VALUE);
222 break;
224 default:
225 alSetError(AL_INVALID_ENUM);
226 break;
229 else
230 alSetError(AL_INVALID_NAME);
232 ProcessContext(Context);
235 AL_API ALvoid AL_APIENTRY alAuxiliaryEffectSlotiv(ALuint effectslot, ALenum param, ALint *piValues)
237 ALCcontext *Context;
239 Context = alcGetCurrentContext();
240 if(!Context)
242 alSetError(AL_INVALID_OPERATION);
243 return;
245 SuspendContext(Context);
247 if (alIsAuxiliaryEffectSlot(effectslot))
249 switch(param)
251 case AL_EFFECTSLOT_EFFECT:
252 case AL_EFFECTSLOT_AUXILIARY_SEND_AUTO:
253 alAuxiliaryEffectSloti(effectslot, param, piValues[0]);
254 break;
256 default:
257 alSetError(AL_INVALID_ENUM);
258 break;
261 else
262 alSetError(AL_INVALID_NAME);
264 ProcessContext(Context);
267 AL_API ALvoid AL_APIENTRY alAuxiliaryEffectSlotf(ALuint effectslot, ALenum param, ALfloat flValue)
269 ALCcontext *Context;
271 Context = alcGetCurrentContext();
272 if(!Context)
274 alSetError(AL_INVALID_OPERATION);
275 return;
277 SuspendContext(Context);
279 if (alIsAuxiliaryEffectSlot(effectslot))
281 ALeffectslot *ALEffectSlot = (ALeffectslot*)ALTHUNK_LOOKUPENTRY(effectslot);
283 switch(param)
285 case AL_EFFECTSLOT_GAIN:
286 if(flValue >= 0.0f && flValue <= 1.0f)
287 ALEffectSlot->Gain = flValue;
288 else
289 alSetError(AL_INVALID_VALUE);
290 break;
292 default:
293 alSetError(AL_INVALID_ENUM);
294 break;
297 else
298 alSetError(AL_INVALID_NAME);
300 ProcessContext(Context);
303 AL_API ALvoid AL_APIENTRY alAuxiliaryEffectSlotfv(ALuint effectslot, ALenum param, ALfloat *pflValues)
305 ALCcontext *Context;
307 Context = alcGetCurrentContext();
308 if(!Context)
310 alSetError(AL_INVALID_OPERATION);
311 return;
313 SuspendContext(Context);
315 if (alIsAuxiliaryEffectSlot(effectslot))
317 switch(param)
319 case AL_EFFECTSLOT_GAIN:
320 alAuxiliaryEffectSlotf(effectslot, param, pflValues[0]);
321 break;
323 default:
324 alSetError(AL_INVALID_ENUM);
325 break;
328 else
329 alSetError(AL_INVALID_NAME);
331 ProcessContext(Context);
334 AL_API ALvoid AL_APIENTRY alGetAuxiliaryEffectSloti(ALuint effectslot, ALenum param, ALint *piValue)
336 ALCcontext *Context;
338 Context = alcGetCurrentContext();
339 if(!Context)
341 alSetError(AL_INVALID_OPERATION);
342 return;
344 SuspendContext(Context);
346 if (alIsAuxiliaryEffectSlot(effectslot))
348 ALeffectslot *ALEffectSlot = (ALeffectslot*)ALTHUNK_LOOKUPENTRY(effectslot);
350 switch(param)
352 case AL_EFFECTSLOT_EFFECT:
353 *piValue = ALEffectSlot->effect.effect;
354 break;
356 case AL_EFFECTSLOT_AUXILIARY_SEND_AUTO:
357 *piValue = ALEffectSlot->AuxSendAuto;
358 break;
360 default:
361 alSetError(AL_INVALID_ENUM);
362 break;
365 else
366 alSetError(AL_INVALID_NAME);
368 ProcessContext(Context);
371 AL_API ALvoid AL_APIENTRY alGetAuxiliaryEffectSlotiv(ALuint effectslot, ALenum param, ALint *piValues)
373 ALCcontext *Context;
375 Context = alcGetCurrentContext();
376 if(!Context)
378 alSetError(AL_INVALID_OPERATION);
379 return;
381 SuspendContext(Context);
383 if (alIsAuxiliaryEffectSlot(effectslot))
385 switch(param)
387 case AL_EFFECTSLOT_EFFECT:
388 case AL_EFFECTSLOT_AUXILIARY_SEND_AUTO:
389 alGetAuxiliaryEffectSloti(effectslot, param, piValues);
390 break;
392 default:
393 alSetError(AL_INVALID_ENUM);
394 break;
397 else
398 alSetError(AL_INVALID_NAME);
400 ProcessContext(Context);
403 AL_API ALvoid AL_APIENTRY alGetAuxiliaryEffectSlotf(ALuint effectslot, ALenum param, ALfloat *pflValue)
405 ALCcontext *Context;
407 Context = alcGetCurrentContext();
408 if(!Context)
410 alSetError(AL_INVALID_OPERATION);
411 return;
413 SuspendContext(Context);
415 if (alIsAuxiliaryEffectSlot(effectslot))
417 ALeffectslot *ALEffectSlot = (ALeffectslot*)ALTHUNK_LOOKUPENTRY(effectslot);
419 switch(param)
421 case AL_EFFECTSLOT_GAIN:
422 *pflValue = ALEffectSlot->Gain;
423 break;
425 default:
426 alSetError(AL_INVALID_ENUM);
427 break;
430 else
431 alSetError(AL_INVALID_NAME);
433 ProcessContext(Context);
436 AL_API ALvoid AL_APIENTRY alGetAuxiliaryEffectSlotfv(ALuint effectslot, ALenum param, ALfloat *pflValues)
438 ALCcontext *Context;
440 Context = alcGetCurrentContext();
441 if(!Context)
443 alSetError(AL_INVALID_OPERATION);
444 return;
446 SuspendContext(Context);
448 if (alIsAuxiliaryEffectSlot(effectslot))
450 switch(param)
452 case AL_EFFECTSLOT_GAIN:
453 alGetAuxiliaryEffectSlotf(effectslot, param, pflValues);
454 break;
456 default:
457 alSetError(AL_INVALID_ENUM);
458 break;
461 else
462 alSetError(AL_INVALID_NAME);
464 ProcessContext(Context);
468 ALvoid ReleaseALAuxiliaryEffectSlots(ALCcontext *Context)
470 #ifdef _DEBUG
471 if(Context->AuxiliaryEffectSlotCount > 0)
472 AL_PRINT("destroycontext: %d AuxiliaryEffectSlot(s) NOT deleted\n", Context->AuxiliaryEffectSlotCount);
473 #endif
475 while(Context->AuxiliaryEffectSlot)
477 ALeffectslot *temp = Context->AuxiliaryEffectSlot;
478 Context->AuxiliaryEffectSlot = Context->AuxiliaryEffectSlot->next;
480 // Release effectslot structure
481 memset(temp, 0, sizeof(ALeffectslot));
482 free(temp);
484 Context->AuxiliaryEffectSlotCount = 0;