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
29 #include "alAuxEffectSlot.h"
34 AL_API ALvoid AL_APIENTRY
alGenAuxiliaryEffectSlots(ALsizei n
, ALuint
*effectslots
)
39 Context
= alcGetCurrentContext();
42 alSetError(AL_INVALID_OPERATION
);
45 SuspendContext(Context
);
49 /* NOTE: We only support one slot currently */
50 if(n
== 1 && Context
->AuxiliaryEffectSlotCount
== 0)
52 // Check that enough memory has been allocted in the 'effectslots' array for n Effect Slots
53 if (!IsBadWritePtr((void*)effectslots
, n
* sizeof(ALuint
)))
55 ALeffectslot
**list
= &Context
->AuxiliaryEffectSlot
;
57 list
= &(*list
)->next
;
62 *list
= calloc(1, sizeof(ALeffectslot
));
65 // We must have run out or memory
66 alDeleteAuxiliaryEffectSlots(i
, effectslots
);
67 alSetError(AL_OUT_OF_MEMORY
);
72 (*list
)->AuxSendAuto
= AL_TRUE
;
74 effectslots
[i
] = (ALuint
)ALTHUNK_ADDENTRY(*list
);
75 (*list
)->effectslot
= effectslots
[i
];
77 Context
->AuxiliaryEffectSlotCount
++;
80 list
= &(*list
)->next
;
85 alSetError(AL_INVALID_OPERATION
);
88 ProcessContext(Context
);
91 AL_API ALvoid AL_APIENTRY
alDeleteAuxiliaryEffectSlots(ALsizei n
, ALuint
*effectslots
)
94 ALeffectslot
*ALAuxiliaryEffectSlot
;
97 Context
= alcGetCurrentContext();
100 alSetError(AL_INVALID_OPERATION
);
103 SuspendContext(Context
);
107 // Check that all effectslots are valid
108 for (i
= 0; i
< n
; i
++)
110 if (!alIsAuxiliaryEffectSlot(effectslots
[i
]))
112 alSetError(AL_INVALID_NAME
);
119 // All effectslots are valid
120 for (i
= 0; i
< n
; i
++)
122 // Recheck that the effectslot is valid, because there could be duplicated names
123 if (alIsAuxiliaryEffectSlot(effectslots
[i
]))
127 ALAuxiliaryEffectSlot
= ((ALeffectslot
*)ALTHUNK_LOOKUPENTRY(effectslots
[i
]));
129 // Remove Source from list of Sources
130 list
= &Context
->AuxiliaryEffectSlot
;
131 while(*list
&& *list
!= ALAuxiliaryEffectSlot
)
132 list
= &(*list
)->next
;
135 *list
= (*list
)->next
;
136 ALTHUNK_REMOVEENTRY(ALAuxiliaryEffectSlot
->effectslot
);
138 memset(ALAuxiliaryEffectSlot
, 0, sizeof(ALeffectslot
));
139 free(ALAuxiliaryEffectSlot
);
141 Context
->AuxiliaryEffectSlotCount
--;
147 alSetError(AL_INVALID_VALUE
);
149 ProcessContext(Context
);
152 AL_API ALboolean AL_APIENTRY
alIsAuxiliaryEffectSlot(ALuint effectslot
)
157 Context
= alcGetCurrentContext();
160 alSetError(AL_INVALID_OPERATION
);
163 SuspendContext(Context
);
165 list
= &Context
->AuxiliaryEffectSlot
;
166 while(*list
&& (*list
)->effectslot
!= effectslot
)
167 list
= &(*list
)->next
;
169 ProcessContext(Context
);
171 return (*list
? AL_TRUE
: AL_FALSE
);
174 AL_API ALvoid AL_APIENTRY
alAuxiliaryEffectSloti(ALuint effectslot
, ALenum param
, ALint iValue
)
178 Context
= alcGetCurrentContext();
181 alSetError(AL_INVALID_OPERATION
);
184 SuspendContext(Context
);
186 if (alIsAuxiliaryEffectSlot(effectslot
))
188 ALeffectslot
*ALEffectSlot
= (ALeffectslot
*)ALTHUNK_LOOKUPENTRY(effectslot
);
192 case AL_EFFECTSLOT_EFFECT
:
193 if(alIsEffect(iValue
))
195 ALeffect
*effect
= (ALeffect
*)ALTHUNK_LOOKUPENTRY(iValue
);
198 ALEffectSlot
->effect
.type
= AL_EFFECT_NULL
;
199 ALEffectSlot
->effect
.effect
= 0;
202 memcpy(&ALEffectSlot
->effect
, effect
, sizeof(*effect
));
205 alSetError(AL_INVALID_VALUE
);
208 case AL_EFFECTSLOT_AUXILIARY_SEND_AUTO
:
209 if(iValue
== AL_TRUE
|| iValue
== AL_FALSE
)
210 ALEffectSlot
->AuxSendAuto
= iValue
;
212 alSetError(AL_INVALID_VALUE
);
216 alSetError(AL_INVALID_ENUM
);
221 alSetError(AL_INVALID_NAME
);
223 ProcessContext(Context
);
226 AL_API ALvoid AL_APIENTRY
alAuxiliaryEffectSlotiv(ALuint effectslot
, ALenum param
, ALint
*piValues
)
230 Context
= alcGetCurrentContext();
233 alSetError(AL_INVALID_OPERATION
);
236 SuspendContext(Context
);
238 if (alIsAuxiliaryEffectSlot(effectslot
))
242 case AL_EFFECTSLOT_EFFECT
:
243 case AL_EFFECTSLOT_AUXILIARY_SEND_AUTO
:
244 alAuxiliaryEffectSloti(effectslot
, param
, piValues
[0]);
248 alSetError(AL_INVALID_ENUM
);
253 alSetError(AL_INVALID_NAME
);
255 ProcessContext(Context
);
258 AL_API ALvoid AL_APIENTRY
alAuxiliaryEffectSlotf(ALuint effectslot
, ALenum param
, ALfloat flValue
)
262 Context
= alcGetCurrentContext();
265 alSetError(AL_INVALID_OPERATION
);
268 SuspendContext(Context
);
270 if (alIsAuxiliaryEffectSlot(effectslot
))
272 ALeffectslot
*ALEffectSlot
= (ALeffectslot
*)ALTHUNK_LOOKUPENTRY(effectslot
);
276 case AL_EFFECTSLOT_GAIN
:
277 if(flValue
>= 0.0f
&& flValue
<= 1.0f
)
278 ALEffectSlot
->Gain
= flValue
;
280 alSetError(AL_INVALID_VALUE
);
284 alSetError(AL_INVALID_ENUM
);
289 alSetError(AL_INVALID_NAME
);
291 ProcessContext(Context
);
294 AL_API ALvoid AL_APIENTRY
alAuxiliaryEffectSlotfv(ALuint effectslot
, ALenum param
, ALfloat
*pflValues
)
298 Context
= alcGetCurrentContext();
301 alSetError(AL_INVALID_OPERATION
);
304 SuspendContext(Context
);
306 if (alIsAuxiliaryEffectSlot(effectslot
))
310 case AL_EFFECTSLOT_GAIN
:
311 alAuxiliaryEffectSlotf(effectslot
, param
, pflValues
[0]);
315 alSetError(AL_INVALID_ENUM
);
320 alSetError(AL_INVALID_NAME
);
322 ProcessContext(Context
);
325 AL_API ALvoid AL_APIENTRY
alGetAuxiliaryEffectSloti(ALuint effectslot
, ALenum param
, ALint
*piValue
)
329 Context
= alcGetCurrentContext();
332 alSetError(AL_INVALID_OPERATION
);
335 SuspendContext(Context
);
337 if (alIsAuxiliaryEffectSlot(effectslot
))
339 ALeffectslot
*ALEffectSlot
= (ALeffectslot
*)ALTHUNK_LOOKUPENTRY(effectslot
);
343 case AL_EFFECTSLOT_EFFECT
:
344 *piValue
= ALEffectSlot
->effect
.effect
;
347 case AL_EFFECTSLOT_AUXILIARY_SEND_AUTO
:
348 *piValue
= ALEffectSlot
->AuxSendAuto
;
352 alSetError(AL_INVALID_ENUM
);
357 alSetError(AL_INVALID_NAME
);
359 ProcessContext(Context
);
362 AL_API ALvoid AL_APIENTRY
alGetAuxiliaryEffectSlotiv(ALuint effectslot
, ALenum param
, ALint
*piValues
)
366 Context
= alcGetCurrentContext();
369 alSetError(AL_INVALID_OPERATION
);
372 SuspendContext(Context
);
374 if (alIsAuxiliaryEffectSlot(effectslot
))
378 case AL_EFFECTSLOT_EFFECT
:
379 case AL_EFFECTSLOT_AUXILIARY_SEND_AUTO
:
380 alGetAuxiliaryEffectSloti(effectslot
, param
, piValues
);
384 alSetError(AL_INVALID_ENUM
);
389 alSetError(AL_INVALID_NAME
);
391 ProcessContext(Context
);
394 AL_API ALvoid AL_APIENTRY
alGetAuxiliaryEffectSlotf(ALuint effectslot
, ALenum param
, ALfloat
*pflValue
)
398 Context
= alcGetCurrentContext();
401 alSetError(AL_INVALID_OPERATION
);
404 SuspendContext(Context
);
406 if (alIsAuxiliaryEffectSlot(effectslot
))
408 ALeffectslot
*ALEffectSlot
= (ALeffectslot
*)ALTHUNK_LOOKUPENTRY(effectslot
);
412 case AL_EFFECTSLOT_GAIN
:
413 *pflValue
= ALEffectSlot
->Gain
;
417 alSetError(AL_INVALID_ENUM
);
422 alSetError(AL_INVALID_NAME
);
424 ProcessContext(Context
);
427 AL_API ALvoid AL_APIENTRY
alGetAuxiliaryEffectSlotfv(ALuint effectslot
, ALenum param
, ALfloat
*pflValues
)
431 Context
= alcGetCurrentContext();
434 alSetError(AL_INVALID_OPERATION
);
437 SuspendContext(Context
);
439 if (alIsAuxiliaryEffectSlot(effectslot
))
443 case AL_EFFECTSLOT_GAIN
:
444 alGetAuxiliaryEffectSlotf(effectslot
, param
, pflValues
);
448 alSetError(AL_INVALID_ENUM
);
453 alSetError(AL_INVALID_NAME
);
455 ProcessContext(Context
);
459 ALvoid
ReleaseALAuxiliaryEffectSlots(ALCcontext
*Context
)
462 if(Context
->AuxiliaryEffectSlotCount
> 0)
463 AL_PRINT("exit() %d AuxiliaryEffectSlot(s) NOT deleted\n", Context
->AuxiliaryEffectSlotCount
);
466 while(Context
->AuxiliaryEffectSlot
)
468 ALeffectslot
*temp
= Context
->AuxiliaryEffectSlot
;
469 Context
->AuxiliaryEffectSlot
= Context
->AuxiliaryEffectSlot
->next
;
471 // Release effectslot structure
472 memset(temp
, 0, sizeof(ALeffectslot
));
475 Context
->AuxiliaryEffectSlotCount
= 0;