Use the AuxSendAuto property of the effect slot
[openal-soft/openbsd.git] / OpenAL32 / alAuxEffectSlot.c
blob6b8a335c6d80cd28a4883e8f69a5604e6fb54751
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 <stdlib.h>
23 #include "config.h"
25 #include "AL/al.h"
26 #include "AL/alc.h"
28 #include "alMain.h"
29 #include "alAuxEffectSlot.h"
31 static ALeffectslot *g_AuxiliaryEffectSlotList;
32 static ALuint g_AuxiliaryEffectSlotCount;
35 AL_API ALvoid AL_APIENTRY alGenAuxiliaryEffectSlots(ALsizei n, ALuint *effectslots)
37 ALCcontext *Context;
38 ALsizei i;
40 Context = alcGetCurrentContext();
41 SuspendContext(Context);
43 if (n > 0)
45 /* NOTE: We only support one slot currently */
46 if(n == 1 && g_AuxiliaryEffectSlotCount == 0)
48 // Check that enough memory has been allocted in the 'sources' array for n Sources
49 if (!IsBadWritePtr((void*)effectslots, n * sizeof(ALuint)))
51 ALeffectslot **list = &g_AuxiliaryEffectSlotList;
52 while(*list)
53 list = &(*list)->next;
55 i = 0;
56 while(i < n)
58 *list = calloc(1, sizeof(ALeffectslot));
59 if(!(*list))
61 // We must have run out or memory
62 alDeleteAuxiliaryEffectSlots(i, effectslots);
63 alSetError(AL_OUT_OF_MEMORY);
64 break;
67 (*list)->Gain = 1.0;
68 (*list)->AuxSendAuto = AL_TRUE;
70 effectslots[i] = (ALuint)ALTHUNK_ADDENTRY(*list);
71 (*list)->effectslot = effectslots[i];
73 g_AuxiliaryEffectSlotCount++;
74 i++;
78 else
79 alSetError(AL_INVALID_OPERATION);
82 ProcessContext(Context);
85 AL_API ALvoid AL_APIENTRY alDeleteAuxiliaryEffectSlots(ALsizei n, ALuint *effectslots)
87 ALCcontext *Context;
88 ALeffectslot *ALAuxiliaryEffectSlot;
89 ALsizei i;
91 Context = alcGetCurrentContext();
92 SuspendContext(Context);
94 if (n >= 0)
96 // Check that all effectslots are valid
97 for (i = 0; i < n; i++)
99 if (!alIsAuxiliaryEffectSlot(effectslots[i]))
101 alSetError(AL_INVALID_NAME);
102 break;
106 if (i == n)
108 // All effectslots are valid
109 for (i = 0; i < n; i++)
111 // Recheck that the effectslot is valid, because there could be duplicated names
112 if (alIsAuxiliaryEffectSlot(effectslots[i]))
114 ALeffectslot **list;
116 ALAuxiliaryEffectSlot = ((ALeffectslot*)ALTHUNK_LOOKUPENTRY(effectslots[i]));
118 // Remove Source from list of Sources
119 list = &g_AuxiliaryEffectSlotList;
120 while(*list && *list != ALAuxiliaryEffectSlot)
121 list = &(*list)->next;
123 if(*list)
124 *list = (*list)->next;
125 ALTHUNK_REMOVEENTRY(ALAuxiliaryEffectSlot->effectslot);
127 memset(ALAuxiliaryEffectSlot, 0, sizeof(ALeffectslot));
128 free(ALAuxiliaryEffectSlot);
130 g_AuxiliaryEffectSlotCount--;
135 else
136 alSetError(AL_INVALID_VALUE);
138 ProcessContext(Context);
141 AL_API ALboolean AL_APIENTRY alIsAuxiliaryEffectSlot(ALuint effectslot)
143 ALCcontext *Context;
144 ALeffectslot **list;
146 Context = alcGetCurrentContext();
147 SuspendContext(Context);
149 list = &g_AuxiliaryEffectSlotList;
150 while(*list && (*list)->effectslot != effectslot)
151 list = &(*list)->next;
153 ProcessContext(Context);
155 return (*list ? AL_TRUE : AL_FALSE);
158 AL_API ALvoid AL_APIENTRY alAuxiliaryEffectSloti(ALuint effectslot, ALenum param, ALint iValue)
160 ALCcontext *Context;
162 Context = alcGetCurrentContext();
163 SuspendContext(Context);
165 if (alIsAuxiliaryEffectSlot(effectslot))
167 ALeffectslot *ALEffectSlot = (ALeffectslot*)ALTHUNK_LOOKUPENTRY(effectslot);
169 switch(param)
171 case AL_EFFECTSLOT_EFFECT:
172 if(alIsEffect(iValue))
174 ALeffect *effect = (ALeffect*)ALTHUNK_LOOKUPENTRY(iValue);
175 if(!effect)
177 ALEffectSlot->effect.type = AL_EFFECT_NULL;
178 ALEffectSlot->effect.effect = 0;
180 else
181 memcpy(&ALEffectSlot->effect, effect, sizeof(*effect));
183 else
184 alSetError(AL_INVALID_VALUE);
185 break;
187 case AL_EFFECTSLOT_AUXILIARY_SEND_AUTO:
188 if(iValue == AL_TRUE || iValue == AL_FALSE)
189 ALEffectSlot->AuxSendAuto = iValue;
190 else
191 alSetError(AL_INVALID_VALUE);
192 break;
194 default:
195 alSetError(AL_INVALID_ENUM);
196 break;
199 else
200 alSetError(AL_INVALID_NAME);
202 ProcessContext(Context);
205 AL_API ALvoid AL_APIENTRY alAuxiliaryEffectSlotiv(ALuint effectslot, ALenum param, ALint *piValues)
207 ALCcontext *Context;
209 Context = alcGetCurrentContext();
210 SuspendContext(Context);
212 if (alIsAuxiliaryEffectSlot(effectslot))
214 switch(param)
216 case AL_EFFECTSLOT_EFFECT:
217 case AL_EFFECTSLOT_AUXILIARY_SEND_AUTO:
218 alAuxiliaryEffectSloti(effectslot, param, piValues[0]);
219 break;
221 default:
222 alSetError(AL_INVALID_ENUM);
223 break;
226 else
227 alSetError(AL_INVALID_NAME);
229 ProcessContext(Context);
232 AL_API ALvoid AL_APIENTRY alAuxiliaryEffectSlotf(ALuint effectslot, ALenum param, ALfloat flValue)
234 ALCcontext *Context;
236 (void)flValue;
238 Context = alcGetCurrentContext();
239 SuspendContext(Context);
241 if (alIsAuxiliaryEffectSlot(effectslot))
243 ALeffectslot *ALEffectSlot = (ALeffectslot*)ALTHUNK_LOOKUPENTRY(effectslot);
245 switch(param)
247 case AL_EFFECTSLOT_GAIN:
248 if(flValue >= 0.0f && flValue <= 1.0f)
249 ALEffectSlot->Gain = flValue;
250 else
251 alSetError(AL_INVALID_VALUE);
252 break;
254 default:
255 alSetError(AL_INVALID_ENUM);
256 break;
259 else
260 alSetError(AL_INVALID_NAME);
262 ProcessContext(Context);
265 AL_API ALvoid AL_APIENTRY alAuxiliaryEffectSlotfv(ALuint effectslot, ALenum param, ALfloat *pflValues)
267 ALCcontext *Context;
269 Context = alcGetCurrentContext();
270 SuspendContext(Context);
272 if (alIsAuxiliaryEffectSlot(effectslot))
274 switch(param)
276 case AL_EFFECTSLOT_GAIN:
277 alAuxiliaryEffectSlotf(effectslot, param, pflValues[0]);
278 break;
280 default:
281 alSetError(AL_INVALID_ENUM);
282 break;
285 else
286 alSetError(AL_INVALID_NAME);
288 ProcessContext(Context);
291 AL_API ALvoid AL_APIENTRY alGetAuxiliaryEffectSloti(ALuint effectslot, ALenum param, ALint *piValue)
293 ALCcontext *Context;
295 Context = alcGetCurrentContext();
296 SuspendContext(Context);
298 if (alIsAuxiliaryEffectSlot(effectslot))
300 ALeffectslot *ALEffectSlot = (ALeffectslot*)ALTHUNK_LOOKUPENTRY(effectslot);
302 switch(param)
304 case AL_EFFECTSLOT_EFFECT:
305 *piValue = ALEffectSlot->effect.effect;
306 break;
308 case AL_EFFECTSLOT_AUXILIARY_SEND_AUTO:
309 *piValue = ALEffectSlot->AuxSendAuto;
310 break;
312 default:
313 alSetError(AL_INVALID_ENUM);
314 break;
317 else
318 alSetError(AL_INVALID_NAME);
320 ProcessContext(Context);
323 AL_API ALvoid AL_APIENTRY alGetAuxiliaryEffectSlotiv(ALuint effectslot, ALenum param, ALint *piValues)
325 ALCcontext *Context;
327 Context = alcGetCurrentContext();
328 SuspendContext(Context);
330 if (alIsAuxiliaryEffectSlot(effectslot))
332 switch(param)
334 case AL_EFFECTSLOT_EFFECT:
335 case AL_EFFECTSLOT_AUXILIARY_SEND_AUTO:
336 alGetAuxiliaryEffectSloti(effectslot, param, piValues);
337 break;
339 default:
340 alSetError(AL_INVALID_ENUM);
341 break;
344 else
345 alSetError(AL_INVALID_NAME);
347 ProcessContext(Context);
350 AL_API ALvoid AL_APIENTRY alGetAuxiliaryEffectSlotf(ALuint effectslot, ALenum param, ALfloat *pflValue)
352 ALCcontext *Context;
354 Context = alcGetCurrentContext();
355 SuspendContext(Context);
357 if (alIsAuxiliaryEffectSlot(effectslot))
359 ALeffectslot *ALEffectSlot = (ALeffectslot*)ALTHUNK_LOOKUPENTRY(effectslot);
361 switch(param)
363 case AL_EFFECTSLOT_GAIN:
364 *pflValue = ALEffectSlot->Gain;
365 break;
367 default:
368 alSetError(AL_INVALID_ENUM);
369 break;
372 else
373 alSetError(AL_INVALID_NAME);
375 ProcessContext(Context);
378 AL_API ALvoid AL_APIENTRY alGetAuxiliaryEffectSlotfv(ALuint effectslot, ALenum param, ALfloat *pflValues)
380 ALCcontext *Context;
382 Context = alcGetCurrentContext();
383 SuspendContext(Context);
385 if (alIsAuxiliaryEffectSlot(effectslot))
387 switch(param)
389 case AL_EFFECTSLOT_GAIN:
390 alGetAuxiliaryEffectSlotf(effectslot, param, pflValues);
391 break;
393 default:
394 alSetError(AL_INVALID_ENUM);
395 break;
398 else
399 alSetError(AL_INVALID_NAME);
401 ProcessContext(Context);
405 ALvoid ReleaseALAuxiliaryEffectSlots(ALvoid)
407 #ifdef _DEBUG
408 if(g_AuxiliaryEffectSlotCount > 0)
409 AL_PRINT("exit() %d AuxiliaryEffectSlot(s) NOT deleted\n", g_AuxiliaryEffectSlotCount);
410 #endif
412 while(g_AuxiliaryEffectSlotList)
414 ALeffectslot *temp = g_AuxiliaryEffectSlotList;
415 g_AuxiliaryEffectSlotList = g_AuxiliaryEffectSlotList->next;
417 // Release effectslot structure
418 memset(temp, 0, sizeof(ALeffectslot));
419 free(temp);
421 g_AuxiliaryEffectSlotCount = 0;