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"
33 static ALeffectslot
*g_AuxiliaryEffectSlotList
;
34 static ALuint g_AuxiliaryEffectSlotCount
;
37 AL_API ALvoid AL_APIENTRY
alGenAuxiliaryEffectSlots(ALsizei n
, ALuint
*effectslots
)
42 Context
= alcGetCurrentContext();
43 SuspendContext(Context
);
47 /* NOTE: We only support one slot currently */
48 if(n
== 1 && g_AuxiliaryEffectSlotCount
== 0)
50 // Check that enough memory has been allocted in the 'sources' array for n Sources
51 if (!IsBadWritePtr((void*)effectslots
, n
* sizeof(ALuint
)))
53 ALeffectslot
**list
= &g_AuxiliaryEffectSlotList
;
55 list
= &(*list
)->next
;
60 *list
= calloc(1, sizeof(ALeffectslot
));
63 // We must have run out or memory
64 alDeleteAuxiliaryEffectSlots(i
, effectslots
);
65 alSetError(AL_OUT_OF_MEMORY
);
70 (*list
)->AuxSendAuto
= AL_TRUE
;
72 effectslots
[i
] = (ALuint
)ALTHUNK_ADDENTRY(*list
);
73 (*list
)->effectslot
= effectslots
[i
];
75 g_AuxiliaryEffectSlotCount
++;
81 alSetError(AL_INVALID_OPERATION
);
84 ProcessContext(Context
);
87 AL_API ALvoid AL_APIENTRY
alDeleteAuxiliaryEffectSlots(ALsizei n
, ALuint
*effectslots
)
90 ALeffectslot
*ALAuxiliaryEffectSlot
;
93 Context
= alcGetCurrentContext();
94 SuspendContext(Context
);
98 // Check that all effectslots are valid
99 for (i
= 0; i
< n
; i
++)
101 if (!alIsAuxiliaryEffectSlot(effectslots
[i
]))
103 alSetError(AL_INVALID_NAME
);
110 // All effectslots are valid
111 for (i
= 0; i
< n
; i
++)
113 // Recheck that the effectslot is valid, because there could be duplicated names
114 if (alIsAuxiliaryEffectSlot(effectslots
[i
]))
118 ALAuxiliaryEffectSlot
= ((ALeffectslot
*)ALTHUNK_LOOKUPENTRY(effectslots
[i
]));
120 // Remove Source from list of Sources
121 list
= &g_AuxiliaryEffectSlotList
;
122 while(*list
&& *list
!= ALAuxiliaryEffectSlot
)
123 list
= &(*list
)->next
;
126 *list
= (*list
)->next
;
127 ALTHUNK_REMOVEENTRY(ALAuxiliaryEffectSlot
->effectslot
);
129 memset(ALAuxiliaryEffectSlot
, 0, sizeof(ALeffectslot
));
130 free(ALAuxiliaryEffectSlot
);
132 g_AuxiliaryEffectSlotCount
--;
138 alSetError(AL_INVALID_VALUE
);
140 ProcessContext(Context
);
143 AL_API ALboolean AL_APIENTRY
alIsAuxiliaryEffectSlot(ALuint effectslot
)
148 Context
= alcGetCurrentContext();
149 SuspendContext(Context
);
151 list
= &g_AuxiliaryEffectSlotList
;
152 while(*list
&& (*list
)->effectslot
!= effectslot
)
153 list
= &(*list
)->next
;
155 ProcessContext(Context
);
157 return (*list
? AL_TRUE
: AL_FALSE
);
160 AL_API ALvoid AL_APIENTRY
alAuxiliaryEffectSloti(ALuint effectslot
, ALenum param
, ALint iValue
)
164 Context
= alcGetCurrentContext();
165 SuspendContext(Context
);
167 if (alIsAuxiliaryEffectSlot(effectslot
))
169 ALeffectslot
*ALEffectSlot
= (ALeffectslot
*)ALTHUNK_LOOKUPENTRY(effectslot
);
173 case AL_EFFECTSLOT_EFFECT
:
174 if(alIsEffect(iValue
))
176 ALeffect
*effect
= (ALeffect
*)ALTHUNK_LOOKUPENTRY(iValue
);
179 ALEffectSlot
->effect
.type
= AL_EFFECT_NULL
;
180 ALEffectSlot
->effect
.effect
= 0;
183 memcpy(&ALEffectSlot
->effect
, effect
, sizeof(*effect
));
186 alSetError(AL_INVALID_VALUE
);
189 case AL_EFFECTSLOT_AUXILIARY_SEND_AUTO
:
190 if(iValue
== AL_TRUE
|| iValue
== AL_FALSE
)
191 ALEffectSlot
->AuxSendAuto
= iValue
;
193 alSetError(AL_INVALID_VALUE
);
197 alSetError(AL_INVALID_ENUM
);
202 alSetError(AL_INVALID_NAME
);
204 ProcessContext(Context
);
207 AL_API ALvoid AL_APIENTRY
alAuxiliaryEffectSlotiv(ALuint effectslot
, ALenum param
, ALint
*piValues
)
211 Context
= alcGetCurrentContext();
212 SuspendContext(Context
);
214 if (alIsAuxiliaryEffectSlot(effectslot
))
218 case AL_EFFECTSLOT_EFFECT
:
219 case AL_EFFECTSLOT_AUXILIARY_SEND_AUTO
:
220 alAuxiliaryEffectSloti(effectslot
, param
, piValues
[0]);
224 alSetError(AL_INVALID_ENUM
);
229 alSetError(AL_INVALID_NAME
);
231 ProcessContext(Context
);
234 AL_API ALvoid AL_APIENTRY
alAuxiliaryEffectSlotf(ALuint effectslot
, ALenum param
, ALfloat flValue
)
240 Context
= alcGetCurrentContext();
241 SuspendContext(Context
);
243 if (alIsAuxiliaryEffectSlot(effectslot
))
245 ALeffectslot
*ALEffectSlot
= (ALeffectslot
*)ALTHUNK_LOOKUPENTRY(effectslot
);
249 case AL_EFFECTSLOT_GAIN
:
250 if(flValue
>= 0.0f
&& flValue
<= 1.0f
)
251 ALEffectSlot
->Gain
= flValue
;
253 alSetError(AL_INVALID_VALUE
);
257 alSetError(AL_INVALID_ENUM
);
262 alSetError(AL_INVALID_NAME
);
264 ProcessContext(Context
);
267 AL_API ALvoid AL_APIENTRY
alAuxiliaryEffectSlotfv(ALuint effectslot
, ALenum param
, ALfloat
*pflValues
)
271 Context
= alcGetCurrentContext();
272 SuspendContext(Context
);
274 if (alIsAuxiliaryEffectSlot(effectslot
))
278 case AL_EFFECTSLOT_GAIN
:
279 alAuxiliaryEffectSlotf(effectslot
, param
, pflValues
[0]);
283 alSetError(AL_INVALID_ENUM
);
288 alSetError(AL_INVALID_NAME
);
290 ProcessContext(Context
);
293 AL_API ALvoid AL_APIENTRY
alGetAuxiliaryEffectSloti(ALuint effectslot
, ALenum param
, ALint
*piValue
)
297 Context
= alcGetCurrentContext();
298 SuspendContext(Context
);
300 if (alIsAuxiliaryEffectSlot(effectslot
))
302 ALeffectslot
*ALEffectSlot
= (ALeffectslot
*)ALTHUNK_LOOKUPENTRY(effectslot
);
306 case AL_EFFECTSLOT_EFFECT
:
307 *piValue
= ALEffectSlot
->effect
.effect
;
310 case AL_EFFECTSLOT_AUXILIARY_SEND_AUTO
:
311 *piValue
= ALEffectSlot
->AuxSendAuto
;
315 alSetError(AL_INVALID_ENUM
);
320 alSetError(AL_INVALID_NAME
);
322 ProcessContext(Context
);
325 AL_API ALvoid AL_APIENTRY
alGetAuxiliaryEffectSlotiv(ALuint effectslot
, ALenum param
, ALint
*piValues
)
329 Context
= alcGetCurrentContext();
330 SuspendContext(Context
);
332 if (alIsAuxiliaryEffectSlot(effectslot
))
336 case AL_EFFECTSLOT_EFFECT
:
337 case AL_EFFECTSLOT_AUXILIARY_SEND_AUTO
:
338 alGetAuxiliaryEffectSloti(effectslot
, param
, piValues
);
342 alSetError(AL_INVALID_ENUM
);
347 alSetError(AL_INVALID_NAME
);
349 ProcessContext(Context
);
352 AL_API ALvoid AL_APIENTRY
alGetAuxiliaryEffectSlotf(ALuint effectslot
, ALenum param
, ALfloat
*pflValue
)
356 Context
= alcGetCurrentContext();
357 SuspendContext(Context
);
359 if (alIsAuxiliaryEffectSlot(effectslot
))
361 ALeffectslot
*ALEffectSlot
= (ALeffectslot
*)ALTHUNK_LOOKUPENTRY(effectslot
);
365 case AL_EFFECTSLOT_GAIN
:
366 *pflValue
= ALEffectSlot
->Gain
;
370 alSetError(AL_INVALID_ENUM
);
375 alSetError(AL_INVALID_NAME
);
377 ProcessContext(Context
);
380 AL_API ALvoid AL_APIENTRY
alGetAuxiliaryEffectSlotfv(ALuint effectslot
, ALenum param
, ALfloat
*pflValues
)
384 Context
= alcGetCurrentContext();
385 SuspendContext(Context
);
387 if (alIsAuxiliaryEffectSlot(effectslot
))
391 case AL_EFFECTSLOT_GAIN
:
392 alGetAuxiliaryEffectSlotf(effectslot
, param
, pflValues
);
396 alSetError(AL_INVALID_ENUM
);
401 alSetError(AL_INVALID_NAME
);
403 ProcessContext(Context
);
407 ALvoid
ReleaseALAuxiliaryEffectSlots(ALvoid
)
410 if(g_AuxiliaryEffectSlotCount
> 0)
411 AL_PRINT("exit() %d AuxiliaryEffectSlot(s) NOT deleted\n", g_AuxiliaryEffectSlotCount
);
414 while(g_AuxiliaryEffectSlotList
)
416 ALeffectslot
*temp
= g_AuxiliaryEffectSlotList
;
417 g_AuxiliaryEffectSlotList
= g_AuxiliaryEffectSlotList
->next
;
419 // Release effectslot structure
420 memset(temp
, 0, sizeof(ALeffectslot
));
423 g_AuxiliaryEffectSlotCount
= 0;