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
++;
83 alSetError(AL_INVALID_OPERATION
);
86 ProcessContext(Context
);
89 AL_API ALvoid AL_APIENTRY
alDeleteAuxiliaryEffectSlots(ALsizei n
, ALuint
*effectslots
)
92 ALeffectslot
*ALAuxiliaryEffectSlot
;
95 Context
= alcGetCurrentContext();
98 alSetError(AL_INVALID_OPERATION
);
101 SuspendContext(Context
);
105 // Check that all effectslots are valid
106 for (i
= 0; i
< n
; i
++)
108 if (!alIsAuxiliaryEffectSlot(effectslots
[i
]))
110 alSetError(AL_INVALID_NAME
);
117 // All effectslots are valid
118 for (i
= 0; i
< n
; i
++)
120 // Recheck that the effectslot is valid, because there could be duplicated names
121 if (alIsAuxiliaryEffectSlot(effectslots
[i
]))
125 ALAuxiliaryEffectSlot
= ((ALeffectslot
*)ALTHUNK_LOOKUPENTRY(effectslots
[i
]));
127 // Remove Source from list of Sources
128 list
= &Context
->AuxiliaryEffectSlot
;
129 while(*list
&& *list
!= ALAuxiliaryEffectSlot
)
130 list
= &(*list
)->next
;
133 *list
= (*list
)->next
;
134 ALTHUNK_REMOVEENTRY(ALAuxiliaryEffectSlot
->effectslot
);
136 memset(ALAuxiliaryEffectSlot
, 0, sizeof(ALeffectslot
));
137 free(ALAuxiliaryEffectSlot
);
139 Context
->AuxiliaryEffectSlotCount
--;
145 alSetError(AL_INVALID_VALUE
);
147 ProcessContext(Context
);
150 AL_API ALboolean AL_APIENTRY
alIsAuxiliaryEffectSlot(ALuint effectslot
)
155 Context
= alcGetCurrentContext();
158 alSetError(AL_INVALID_OPERATION
);
161 SuspendContext(Context
);
163 list
= &Context
->AuxiliaryEffectSlot
;
164 while(*list
&& (*list
)->effectslot
!= effectslot
)
165 list
= &(*list
)->next
;
167 ProcessContext(Context
);
169 return (*list
? AL_TRUE
: AL_FALSE
);
172 AL_API ALvoid AL_APIENTRY
alAuxiliaryEffectSloti(ALuint effectslot
, ALenum param
, ALint iValue
)
176 Context
= alcGetCurrentContext();
179 alSetError(AL_INVALID_OPERATION
);
182 SuspendContext(Context
);
184 if (alIsAuxiliaryEffectSlot(effectslot
))
186 ALeffectslot
*ALEffectSlot
= (ALeffectslot
*)ALTHUNK_LOOKUPENTRY(effectslot
);
190 case AL_EFFECTSLOT_EFFECT
:
191 if(alIsEffect(iValue
))
193 ALeffect
*effect
= (ALeffect
*)ALTHUNK_LOOKUPENTRY(iValue
);
196 ALEffectSlot
->effect
.type
= AL_EFFECT_NULL
;
197 ALEffectSlot
->effect
.effect
= 0;
200 memcpy(&ALEffectSlot
->effect
, effect
, sizeof(*effect
));
203 alSetError(AL_INVALID_VALUE
);
206 case AL_EFFECTSLOT_AUXILIARY_SEND_AUTO
:
207 if(iValue
== AL_TRUE
|| iValue
== AL_FALSE
)
208 ALEffectSlot
->AuxSendAuto
= iValue
;
210 alSetError(AL_INVALID_VALUE
);
214 alSetError(AL_INVALID_ENUM
);
219 alSetError(AL_INVALID_NAME
);
221 ProcessContext(Context
);
224 AL_API ALvoid AL_APIENTRY
alAuxiliaryEffectSlotiv(ALuint effectslot
, ALenum param
, ALint
*piValues
)
228 Context
= alcGetCurrentContext();
231 alSetError(AL_INVALID_OPERATION
);
234 SuspendContext(Context
);
236 if (alIsAuxiliaryEffectSlot(effectslot
))
240 case AL_EFFECTSLOT_EFFECT
:
241 case AL_EFFECTSLOT_AUXILIARY_SEND_AUTO
:
242 alAuxiliaryEffectSloti(effectslot
, param
, piValues
[0]);
246 alSetError(AL_INVALID_ENUM
);
251 alSetError(AL_INVALID_NAME
);
253 ProcessContext(Context
);
256 AL_API ALvoid AL_APIENTRY
alAuxiliaryEffectSlotf(ALuint effectslot
, ALenum param
, ALfloat flValue
)
260 Context
= alcGetCurrentContext();
263 alSetError(AL_INVALID_OPERATION
);
266 SuspendContext(Context
);
268 if (alIsAuxiliaryEffectSlot(effectslot
))
270 ALeffectslot
*ALEffectSlot
= (ALeffectslot
*)ALTHUNK_LOOKUPENTRY(effectslot
);
274 case AL_EFFECTSLOT_GAIN
:
275 if(flValue
>= 0.0f
&& flValue
<= 1.0f
)
276 ALEffectSlot
->Gain
= flValue
;
278 alSetError(AL_INVALID_VALUE
);
282 alSetError(AL_INVALID_ENUM
);
287 alSetError(AL_INVALID_NAME
);
289 ProcessContext(Context
);
292 AL_API ALvoid AL_APIENTRY
alAuxiliaryEffectSlotfv(ALuint effectslot
, ALenum param
, ALfloat
*pflValues
)
296 Context
= alcGetCurrentContext();
299 alSetError(AL_INVALID_OPERATION
);
302 SuspendContext(Context
);
304 if (alIsAuxiliaryEffectSlot(effectslot
))
308 case AL_EFFECTSLOT_GAIN
:
309 alAuxiliaryEffectSlotf(effectslot
, param
, pflValues
[0]);
313 alSetError(AL_INVALID_ENUM
);
318 alSetError(AL_INVALID_NAME
);
320 ProcessContext(Context
);
323 AL_API ALvoid AL_APIENTRY
alGetAuxiliaryEffectSloti(ALuint effectslot
, ALenum param
, ALint
*piValue
)
327 Context
= alcGetCurrentContext();
330 alSetError(AL_INVALID_OPERATION
);
333 SuspendContext(Context
);
335 if (alIsAuxiliaryEffectSlot(effectslot
))
337 ALeffectslot
*ALEffectSlot
= (ALeffectslot
*)ALTHUNK_LOOKUPENTRY(effectslot
);
341 case AL_EFFECTSLOT_EFFECT
:
342 *piValue
= ALEffectSlot
->effect
.effect
;
345 case AL_EFFECTSLOT_AUXILIARY_SEND_AUTO
:
346 *piValue
= ALEffectSlot
->AuxSendAuto
;
350 alSetError(AL_INVALID_ENUM
);
355 alSetError(AL_INVALID_NAME
);
357 ProcessContext(Context
);
360 AL_API ALvoid AL_APIENTRY
alGetAuxiliaryEffectSlotiv(ALuint effectslot
, ALenum param
, ALint
*piValues
)
364 Context
= alcGetCurrentContext();
367 alSetError(AL_INVALID_OPERATION
);
370 SuspendContext(Context
);
372 if (alIsAuxiliaryEffectSlot(effectslot
))
376 case AL_EFFECTSLOT_EFFECT
:
377 case AL_EFFECTSLOT_AUXILIARY_SEND_AUTO
:
378 alGetAuxiliaryEffectSloti(effectslot
, param
, piValues
);
382 alSetError(AL_INVALID_ENUM
);
387 alSetError(AL_INVALID_NAME
);
389 ProcessContext(Context
);
392 AL_API ALvoid AL_APIENTRY
alGetAuxiliaryEffectSlotf(ALuint effectslot
, ALenum param
, ALfloat
*pflValue
)
396 Context
= alcGetCurrentContext();
399 alSetError(AL_INVALID_OPERATION
);
402 SuspendContext(Context
);
404 if (alIsAuxiliaryEffectSlot(effectslot
))
406 ALeffectslot
*ALEffectSlot
= (ALeffectslot
*)ALTHUNK_LOOKUPENTRY(effectslot
);
410 case AL_EFFECTSLOT_GAIN
:
411 *pflValue
= ALEffectSlot
->Gain
;
415 alSetError(AL_INVALID_ENUM
);
420 alSetError(AL_INVALID_NAME
);
422 ProcessContext(Context
);
425 AL_API ALvoid AL_APIENTRY
alGetAuxiliaryEffectSlotfv(ALuint effectslot
, ALenum param
, ALfloat
*pflValues
)
429 Context
= alcGetCurrentContext();
432 alSetError(AL_INVALID_OPERATION
);
435 SuspendContext(Context
);
437 if (alIsAuxiliaryEffectSlot(effectslot
))
441 case AL_EFFECTSLOT_GAIN
:
442 alGetAuxiliaryEffectSlotf(effectslot
, param
, pflValues
);
446 alSetError(AL_INVALID_ENUM
);
451 alSetError(AL_INVALID_NAME
);
453 ProcessContext(Context
);
457 ALvoid
ReleaseALAuxiliaryEffectSlots(ALCcontext
*Context
)
460 if(Context
->AuxiliaryEffectSlotCount
> 0)
461 AL_PRINT("exit() %d AuxiliaryEffectSlot(s) NOT deleted\n", Context
->AuxiliaryEffectSlotCount
);
464 while(Context
->AuxiliaryEffectSlot
)
466 ALeffectslot
*temp
= Context
->AuxiliaryEffectSlot
;
467 Context
->AuxiliaryEffectSlot
= Context
->AuxiliaryEffectSlot
->next
;
469 // Release effectslot structure
470 memset(temp
, 0, sizeof(ALeffectslot
));
473 Context
->AuxiliaryEffectSlotCount
= 0;