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
28 #include "alAuxEffectSlot.h"
33 AL_API ALvoid AL_APIENTRY
alGenAuxiliaryEffectSlots(ALsizei n
, ALuint
*effectslots
)
38 Context
= alcGetCurrentContext();
41 alSetError(AL_INVALID_OPERATION
);
44 SuspendContext(Context
);
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
;
56 list
= &(*list
)->next
;
61 *list
= calloc(1, sizeof(ALeffectslot
));
64 // We must have run out or memory
65 alDeleteAuxiliaryEffectSlots(i
, effectslots
);
66 alSetError(AL_OUT_OF_MEMORY
);
71 (*list
)->AuxSendAuto
= AL_TRUE
;
72 (*list
)->refcount
= 0;
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
);
117 ALAuxiliaryEffectSlot
= (ALeffectslot
*)ALTHUNK_LOOKUPENTRY(effectslots
[i
]);
118 if(ALAuxiliaryEffectSlot
->refcount
> 0)
120 alSetError(AL_INVALID_NAME
);
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
]))
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
;
144 *list
= (*list
)->next
;
145 ALTHUNK_REMOVEENTRY(ALAuxiliaryEffectSlot
->effectslot
);
147 memset(ALAuxiliaryEffectSlot
, 0, sizeof(ALeffectslot
));
148 free(ALAuxiliaryEffectSlot
);
150 Context
->AuxiliaryEffectSlotCount
--;
156 alSetError(AL_INVALID_VALUE
);
158 ProcessContext(Context
);
161 AL_API ALboolean AL_APIENTRY
alIsAuxiliaryEffectSlot(ALuint effectslot
)
166 Context
= alcGetCurrentContext();
169 alSetError(AL_INVALID_OPERATION
);
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
)
187 Context
= alcGetCurrentContext();
190 alSetError(AL_INVALID_OPERATION
);
193 SuspendContext(Context
);
195 if (alIsAuxiliaryEffectSlot(effectslot
))
197 ALeffectslot
*ALEffectSlot
= (ALeffectslot
*)ALTHUNK_LOOKUPENTRY(effectslot
);
201 case AL_EFFECTSLOT_EFFECT
:
202 if(alIsEffect(iValue
))
204 ALeffect
*effect
= (ALeffect
*)ALTHUNK_LOOKUPENTRY(iValue
);
207 ALEffectSlot
->effect
.type
= AL_EFFECT_NULL
;
208 ALEffectSlot
->effect
.effect
= 0;
211 memcpy(&ALEffectSlot
->effect
, effect
, sizeof(*effect
));
214 alSetError(AL_INVALID_VALUE
);
217 case AL_EFFECTSLOT_AUXILIARY_SEND_AUTO
:
218 if(iValue
== AL_TRUE
|| iValue
== AL_FALSE
)
219 ALEffectSlot
->AuxSendAuto
= iValue
;
221 alSetError(AL_INVALID_VALUE
);
225 alSetError(AL_INVALID_ENUM
);
230 alSetError(AL_INVALID_NAME
);
232 ProcessContext(Context
);
235 AL_API ALvoid AL_APIENTRY
alAuxiliaryEffectSlotiv(ALuint effectslot
, ALenum param
, ALint
*piValues
)
239 Context
= alcGetCurrentContext();
242 alSetError(AL_INVALID_OPERATION
);
245 SuspendContext(Context
);
247 if (alIsAuxiliaryEffectSlot(effectslot
))
251 case AL_EFFECTSLOT_EFFECT
:
252 case AL_EFFECTSLOT_AUXILIARY_SEND_AUTO
:
253 alAuxiliaryEffectSloti(effectslot
, param
, piValues
[0]);
257 alSetError(AL_INVALID_ENUM
);
262 alSetError(AL_INVALID_NAME
);
264 ProcessContext(Context
);
267 AL_API ALvoid AL_APIENTRY
alAuxiliaryEffectSlotf(ALuint effectslot
, ALenum param
, ALfloat flValue
)
271 Context
= alcGetCurrentContext();
274 alSetError(AL_INVALID_OPERATION
);
277 SuspendContext(Context
);
279 if (alIsAuxiliaryEffectSlot(effectslot
))
281 ALeffectslot
*ALEffectSlot
= (ALeffectslot
*)ALTHUNK_LOOKUPENTRY(effectslot
);
285 case AL_EFFECTSLOT_GAIN
:
286 if(flValue
>= 0.0f
&& flValue
<= 1.0f
)
287 ALEffectSlot
->Gain
= flValue
;
289 alSetError(AL_INVALID_VALUE
);
293 alSetError(AL_INVALID_ENUM
);
298 alSetError(AL_INVALID_NAME
);
300 ProcessContext(Context
);
303 AL_API ALvoid AL_APIENTRY
alAuxiliaryEffectSlotfv(ALuint effectslot
, ALenum param
, ALfloat
*pflValues
)
307 Context
= alcGetCurrentContext();
310 alSetError(AL_INVALID_OPERATION
);
313 SuspendContext(Context
);
315 if (alIsAuxiliaryEffectSlot(effectslot
))
319 case AL_EFFECTSLOT_GAIN
:
320 alAuxiliaryEffectSlotf(effectslot
, param
, pflValues
[0]);
324 alSetError(AL_INVALID_ENUM
);
329 alSetError(AL_INVALID_NAME
);
331 ProcessContext(Context
);
334 AL_API ALvoid AL_APIENTRY
alGetAuxiliaryEffectSloti(ALuint effectslot
, ALenum param
, ALint
*piValue
)
338 Context
= alcGetCurrentContext();
341 alSetError(AL_INVALID_OPERATION
);
344 SuspendContext(Context
);
346 if (alIsAuxiliaryEffectSlot(effectslot
))
348 ALeffectslot
*ALEffectSlot
= (ALeffectslot
*)ALTHUNK_LOOKUPENTRY(effectslot
);
352 case AL_EFFECTSLOT_EFFECT
:
353 *piValue
= ALEffectSlot
->effect
.effect
;
356 case AL_EFFECTSLOT_AUXILIARY_SEND_AUTO
:
357 *piValue
= ALEffectSlot
->AuxSendAuto
;
361 alSetError(AL_INVALID_ENUM
);
366 alSetError(AL_INVALID_NAME
);
368 ProcessContext(Context
);
371 AL_API ALvoid AL_APIENTRY
alGetAuxiliaryEffectSlotiv(ALuint effectslot
, ALenum param
, ALint
*piValues
)
375 Context
= alcGetCurrentContext();
378 alSetError(AL_INVALID_OPERATION
);
381 SuspendContext(Context
);
383 if (alIsAuxiliaryEffectSlot(effectslot
))
387 case AL_EFFECTSLOT_EFFECT
:
388 case AL_EFFECTSLOT_AUXILIARY_SEND_AUTO
:
389 alGetAuxiliaryEffectSloti(effectslot
, param
, piValues
);
393 alSetError(AL_INVALID_ENUM
);
398 alSetError(AL_INVALID_NAME
);
400 ProcessContext(Context
);
403 AL_API ALvoid AL_APIENTRY
alGetAuxiliaryEffectSlotf(ALuint effectslot
, ALenum param
, ALfloat
*pflValue
)
407 Context
= alcGetCurrentContext();
410 alSetError(AL_INVALID_OPERATION
);
413 SuspendContext(Context
);
415 if (alIsAuxiliaryEffectSlot(effectslot
))
417 ALeffectslot
*ALEffectSlot
= (ALeffectslot
*)ALTHUNK_LOOKUPENTRY(effectslot
);
421 case AL_EFFECTSLOT_GAIN
:
422 *pflValue
= ALEffectSlot
->Gain
;
426 alSetError(AL_INVALID_ENUM
);
431 alSetError(AL_INVALID_NAME
);
433 ProcessContext(Context
);
436 AL_API ALvoid AL_APIENTRY
alGetAuxiliaryEffectSlotfv(ALuint effectslot
, ALenum param
, ALfloat
*pflValues
)
440 Context
= alcGetCurrentContext();
443 alSetError(AL_INVALID_OPERATION
);
446 SuspendContext(Context
);
448 if (alIsAuxiliaryEffectSlot(effectslot
))
452 case AL_EFFECTSLOT_GAIN
:
453 alGetAuxiliaryEffectSlotf(effectslot
, param
, pflValues
);
457 alSetError(AL_INVALID_ENUM
);
462 alSetError(AL_INVALID_NAME
);
464 ProcessContext(Context
);
468 ALvoid
ReleaseALAuxiliaryEffectSlots(ALCcontext
*Context
)
471 if(Context
->AuxiliaryEffectSlotCount
> 0)
472 AL_PRINT("destroycontext: %d AuxiliaryEffectSlot(s) NOT deleted\n", Context
->AuxiliaryEffectSlotCount
);
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
));
484 Context
->AuxiliaryEffectSlotCount
= 0;