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"
31 static ALeffectslot
*g_AuxiliaryEffectSlotList
;
32 static ALuint g_AuxiliaryEffectSlotCount
;
35 AL_API ALvoid AL_APIENTRY
alGenAuxiliaryEffectSlots(ALsizei n
, ALuint
*effectslots
)
40 Context
= alcGetCurrentContext();
41 SuspendContext(Context
);
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
;
53 list
= &(*list
)->next
;
58 *list
= calloc(1, sizeof(ALeffectslot
));
61 // We must have run out or memory
62 alDeleteAuxiliaryEffectSlots(i
, effectslots
);
63 alSetError(AL_OUT_OF_MEMORY
);
68 (*list
)->AuxSendAuto
= AL_TRUE
;
70 effectslots
[i
] = (ALuint
)ALTHUNK_ADDENTRY(*list
);
71 (*list
)->effectslot
= effectslots
[i
];
73 g_AuxiliaryEffectSlotCount
++;
79 alSetError(AL_INVALID_OPERATION
);
82 ProcessContext(Context
);
85 AL_API ALvoid AL_APIENTRY
alDeleteAuxiliaryEffectSlots(ALsizei n
, ALuint
*effectslots
)
88 ALeffectslot
*ALAuxiliaryEffectSlot
;
91 Context
= alcGetCurrentContext();
92 SuspendContext(Context
);
96 // Check that all effectslots are valid
97 for (i
= 0; i
< n
; i
++)
99 if (!alIsAuxiliaryEffectSlot(effectslots
[i
]))
101 alSetError(AL_INVALID_NAME
);
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
]))
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
;
124 *list
= (*list
)->next
;
125 ALTHUNK_REMOVEENTRY(ALAuxiliaryEffectSlot
->effectslot
);
127 memset(ALAuxiliaryEffectSlot
, 0, sizeof(ALeffectslot
));
128 free(ALAuxiliaryEffectSlot
);
130 g_AuxiliaryEffectSlotCount
--;
136 alSetError(AL_INVALID_VALUE
);
138 ProcessContext(Context
);
141 AL_API ALboolean AL_APIENTRY
alIsAuxiliaryEffectSlot(ALuint effectslot
)
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
)
162 Context
= alcGetCurrentContext();
163 SuspendContext(Context
);
165 if (alIsAuxiliaryEffectSlot(effectslot
))
167 ALeffectslot
*ALEffectSlot
= (ALeffectslot
*)ALTHUNK_LOOKUPENTRY(effectslot
);
171 case AL_EFFECTSLOT_EFFECT
:
172 if(alIsEffect(iValue
))
174 ALeffect
*effect
= (ALeffect
*)ALTHUNK_LOOKUPENTRY(iValue
);
177 ALEffectSlot
->effect
.type
= AL_EFFECT_NULL
;
178 ALEffectSlot
->effect
.effect
= 0;
181 memcpy(&ALEffectSlot
->effect
, effect
, sizeof(*effect
));
184 alSetError(AL_INVALID_VALUE
);
187 case AL_EFFECTSLOT_AUXILIARY_SEND_AUTO
:
188 if(iValue
== AL_TRUE
|| iValue
== AL_FALSE
)
189 ALEffectSlot
->AuxSendAuto
= iValue
;
191 alSetError(AL_INVALID_VALUE
);
195 alSetError(AL_INVALID_ENUM
);
200 alSetError(AL_INVALID_NAME
);
202 ProcessContext(Context
);
205 AL_API ALvoid AL_APIENTRY
alAuxiliaryEffectSlotiv(ALuint effectslot
, ALenum param
, ALint
*piValues
)
209 Context
= alcGetCurrentContext();
210 SuspendContext(Context
);
212 if (alIsAuxiliaryEffectSlot(effectslot
))
216 case AL_EFFECTSLOT_EFFECT
:
217 case AL_EFFECTSLOT_AUXILIARY_SEND_AUTO
:
218 alAuxiliaryEffectSloti(effectslot
, param
, piValues
[0]);
222 alSetError(AL_INVALID_ENUM
);
227 alSetError(AL_INVALID_NAME
);
229 ProcessContext(Context
);
232 AL_API ALvoid AL_APIENTRY
alAuxiliaryEffectSlotf(ALuint effectslot
, ALenum param
, ALfloat flValue
)
238 Context
= alcGetCurrentContext();
239 SuspendContext(Context
);
241 if (alIsAuxiliaryEffectSlot(effectslot
))
243 ALeffectslot
*ALEffectSlot
= (ALeffectslot
*)ALTHUNK_LOOKUPENTRY(effectslot
);
247 case AL_EFFECTSLOT_GAIN
:
248 if(flValue
>= 0.0f
&& flValue
<= 1.0f
)
249 ALEffectSlot
->Gain
= flValue
;
251 alSetError(AL_INVALID_VALUE
);
255 alSetError(AL_INVALID_ENUM
);
260 alSetError(AL_INVALID_NAME
);
262 ProcessContext(Context
);
265 AL_API ALvoid AL_APIENTRY
alAuxiliaryEffectSlotfv(ALuint effectslot
, ALenum param
, ALfloat
*pflValues
)
269 Context
= alcGetCurrentContext();
270 SuspendContext(Context
);
272 if (alIsAuxiliaryEffectSlot(effectslot
))
276 case AL_EFFECTSLOT_GAIN
:
277 alAuxiliaryEffectSlotf(effectslot
, param
, pflValues
[0]);
281 alSetError(AL_INVALID_ENUM
);
286 alSetError(AL_INVALID_NAME
);
288 ProcessContext(Context
);
291 AL_API ALvoid AL_APIENTRY
alGetAuxiliaryEffectSloti(ALuint effectslot
, ALenum param
, ALint
*piValue
)
295 Context
= alcGetCurrentContext();
296 SuspendContext(Context
);
298 if (alIsAuxiliaryEffectSlot(effectslot
))
300 ALeffectslot
*ALEffectSlot
= (ALeffectslot
*)ALTHUNK_LOOKUPENTRY(effectslot
);
304 case AL_EFFECTSLOT_EFFECT
:
305 *piValue
= ALEffectSlot
->effect
.effect
;
308 case AL_EFFECTSLOT_AUXILIARY_SEND_AUTO
:
309 *piValue
= ALEffectSlot
->AuxSendAuto
;
313 alSetError(AL_INVALID_ENUM
);
318 alSetError(AL_INVALID_NAME
);
320 ProcessContext(Context
);
323 AL_API ALvoid AL_APIENTRY
alGetAuxiliaryEffectSlotiv(ALuint effectslot
, ALenum param
, ALint
*piValues
)
327 Context
= alcGetCurrentContext();
328 SuspendContext(Context
);
330 if (alIsAuxiliaryEffectSlot(effectslot
))
334 case AL_EFFECTSLOT_EFFECT
:
335 case AL_EFFECTSLOT_AUXILIARY_SEND_AUTO
:
336 alGetAuxiliaryEffectSloti(effectslot
, param
, piValues
);
340 alSetError(AL_INVALID_ENUM
);
345 alSetError(AL_INVALID_NAME
);
347 ProcessContext(Context
);
350 AL_API ALvoid AL_APIENTRY
alGetAuxiliaryEffectSlotf(ALuint effectslot
, ALenum param
, ALfloat
*pflValue
)
354 Context
= alcGetCurrentContext();
355 SuspendContext(Context
);
357 if (alIsAuxiliaryEffectSlot(effectslot
))
359 ALeffectslot
*ALEffectSlot
= (ALeffectslot
*)ALTHUNK_LOOKUPENTRY(effectslot
);
363 case AL_EFFECTSLOT_GAIN
:
364 *pflValue
= ALEffectSlot
->Gain
;
368 alSetError(AL_INVALID_ENUM
);
373 alSetError(AL_INVALID_NAME
);
375 ProcessContext(Context
);
378 AL_API ALvoid AL_APIENTRY
alGetAuxiliaryEffectSlotfv(ALuint effectslot
, ALenum param
, ALfloat
*pflValues
)
382 Context
= alcGetCurrentContext();
383 SuspendContext(Context
);
385 if (alIsAuxiliaryEffectSlot(effectslot
))
389 case AL_EFFECTSLOT_GAIN
:
390 alGetAuxiliaryEffectSlotf(effectslot
, param
, pflValues
);
394 alSetError(AL_INVALID_ENUM
);
399 alSetError(AL_INVALID_NAME
);
401 ProcessContext(Context
);
405 ALvoid
ReleaseALAuxiliaryEffectSlots(ALvoid
)
408 if(g_AuxiliaryEffectSlotCount
> 0)
409 AL_PRINT("exit() %d AuxiliaryEffectSlot(s) NOT deleted\n", g_AuxiliaryEffectSlotCount
);
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
));
421 g_AuxiliaryEffectSlotCount
= 0;