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
);
67 effectslots
[i
] = (ALuint
)ALTHUNK_ADDENTRY(*list
);
68 (*list
)->effectslot
= effectslots
[i
];
70 g_AuxiliaryEffectSlotCount
++;
76 alSetError(AL_INVALID_OPERATION
);
79 ProcessContext(Context
);
82 AL_API ALvoid AL_APIENTRY
alDeleteAuxiliaryEffectSlots(ALsizei n
, ALuint
*effectslots
)
85 ALeffectslot
*ALAuxiliaryEffectSlot
;
88 Context
= alcGetCurrentContext();
89 SuspendContext(Context
);
93 // Check that all effectslots are valid
94 for (i
= 0; i
< n
; i
++)
96 if (!alIsAuxiliaryEffectSlot(effectslots
[i
]))
98 alSetError(AL_INVALID_NAME
);
105 // All effectslots are valid
106 for (i
= 0; i
< n
; i
++)
108 // Recheck that the effectslot is valid, because there could be duplicated names
109 if (alIsAuxiliaryEffectSlot(effectslots
[i
]))
113 ALAuxiliaryEffectSlot
= ((ALeffectslot
*)ALTHUNK_LOOKUPENTRY(effectslots
[i
]));
115 // Remove Source from list of Sources
116 list
= &g_AuxiliaryEffectSlotList
;
117 while(*list
&& *list
!= ALAuxiliaryEffectSlot
)
118 list
= &(*list
)->next
;
121 *list
= (*list
)->next
;
122 ALTHUNK_REMOVEENTRY(ALAuxiliaryEffectSlot
->effectslot
);
124 memset(ALAuxiliaryEffectSlot
, 0, sizeof(ALeffectslot
));
125 free(ALAuxiliaryEffectSlot
);
127 g_AuxiliaryEffectSlotCount
--;
133 alSetError(AL_INVALID_VALUE
);
135 ProcessContext(Context
);
138 AL_API ALboolean AL_APIENTRY
alIsAuxiliaryEffectSlot(ALuint effectslot
)
143 Context
= alcGetCurrentContext();
144 SuspendContext(Context
);
146 list
= &g_AuxiliaryEffectSlotList
;
147 while(*list
&& (*list
)->effectslot
!= effectslot
)
148 list
= &(*list
)->next
;
150 ProcessContext(Context
);
152 return (*list
? AL_TRUE
: AL_FALSE
);
155 AL_API ALvoid AL_APIENTRY
alAuxiliaryEffectSloti(ALuint effectslot
, ALenum param
, ALint iValue
)
159 Context
= alcGetCurrentContext();
160 SuspendContext(Context
);
162 if (alIsAuxiliaryEffectSlot(effectslot
))
164 ALeffectslot
*ALEffectSlot
= (ALeffectslot
*)ALTHUNK_LOOKUPENTRY(effectslot
);
168 case AL_EFFECTSLOT_EFFECT
:
169 if(alIsEffect(iValue
))
171 ALeffect
*effect
= (ALeffect
*)ALTHUNK_LOOKUPENTRY(iValue
);
174 ALEffectSlot
->effect
.type
= AL_EFFECT_NULL
;
175 ALEffectSlot
->effect
.effect
= 0;
178 memcpy(&ALEffectSlot
->effect
, effect
, sizeof(*effect
));
181 alSetError(AL_INVALID_VALUE
);
185 alSetError(AL_INVALID_ENUM
);
190 alSetError(AL_INVALID_NAME
);
192 ProcessContext(Context
);
195 AL_API ALvoid AL_APIENTRY
alAuxiliaryEffectSlotiv(ALuint effectslot
, ALenum param
, ALint
*piValues
)
199 Context
= alcGetCurrentContext();
200 SuspendContext(Context
);
202 if (alIsAuxiliaryEffectSlot(effectslot
))
206 case AL_EFFECTSLOT_EFFECT
:
207 alAuxiliaryEffectSloti(effectslot
, param
, piValues
[0]);
211 alSetError(AL_INVALID_ENUM
);
216 alSetError(AL_INVALID_NAME
);
218 ProcessContext(Context
);
221 AL_API ALvoid AL_APIENTRY
alAuxiliaryEffectSlotf(ALuint effectslot
, ALenum param
, ALfloat flValue
)
227 Context
= alcGetCurrentContext();
228 SuspendContext(Context
);
230 if (alIsAuxiliaryEffectSlot(effectslot
))
235 alSetError(AL_INVALID_ENUM
);
240 alSetError(AL_INVALID_NAME
);
242 ProcessContext(Context
);
245 AL_API ALvoid AL_APIENTRY
alAuxiliaryEffectSlotfv(ALuint effectslot
, ALenum param
, ALfloat
*pflValues
)
251 Context
= alcGetCurrentContext();
252 SuspendContext(Context
);
254 if (alIsAuxiliaryEffectSlot(effectslot
))
259 alSetError(AL_INVALID_ENUM
);
264 alSetError(AL_INVALID_NAME
);
266 ProcessContext(Context
);
269 AL_API ALvoid AL_APIENTRY
alGetAuxiliaryEffectSloti(ALuint effectslot
, ALenum param
, ALint
*piValue
)
273 Context
= alcGetCurrentContext();
274 SuspendContext(Context
);
276 if (alIsAuxiliaryEffectSlot(effectslot
))
278 ALeffectslot
*ALEffectSlot
= (ALeffectslot
*)ALTHUNK_LOOKUPENTRY(effectslot
);
282 case AL_EFFECTSLOT_EFFECT
:
283 *piValue
= ALEffectSlot
->effect
.effect
;
287 alSetError(AL_INVALID_ENUM
);
292 alSetError(AL_INVALID_NAME
);
294 ProcessContext(Context
);
297 AL_API ALvoid AL_APIENTRY
alGetAuxiliaryEffectSlotiv(ALuint effectslot
, ALenum param
, ALint
*piValues
)
301 Context
= alcGetCurrentContext();
302 SuspendContext(Context
);
304 if (alIsAuxiliaryEffectSlot(effectslot
))
308 case AL_EFFECTSLOT_EFFECT
:
309 alGetAuxiliaryEffectSloti(effectslot
, param
, piValues
);
313 alSetError(AL_INVALID_ENUM
);
318 alSetError(AL_INVALID_NAME
);
320 ProcessContext(Context
);
323 AL_API ALvoid AL_APIENTRY
alGetAuxiliaryEffectSlotf(ALuint effectslot
, ALenum param
, ALfloat
*pflValue
)
329 Context
= alcGetCurrentContext();
330 SuspendContext(Context
);
332 if (alIsAuxiliaryEffectSlot(effectslot
))
337 alSetError(AL_INVALID_ENUM
);
342 alSetError(AL_INVALID_NAME
);
344 ProcessContext(Context
);
347 AL_API ALvoid AL_APIENTRY
alGetAuxiliaryEffectSlotfv(ALuint effectslot
, ALenum param
, ALfloat
*pflValues
)
353 Context
= alcGetCurrentContext();
354 SuspendContext(Context
);
356 if (alIsAuxiliaryEffectSlot(effectslot
))
361 alSetError(AL_INVALID_ENUM
);
366 alSetError(AL_INVALID_NAME
);
368 ProcessContext(Context
);
372 ALvoid
ReleaseALAuxiliaryEffectSlots(ALvoid
)
375 if(g_AuxiliaryEffectSlotCount
> 0)
376 AL_PRINT("exit() %d AuxiliaryEffectSlot(s) NOT deleted\n", g_AuxiliaryEffectSlotCount
);
379 while(g_AuxiliaryEffectSlotList
)
381 ALeffectslot
*temp
= g_AuxiliaryEffectSlotList
;
382 g_AuxiliaryEffectSlotList
= g_AuxiliaryEffectSlotList
->next
;
384 // Release effectslot structure
385 memset(temp
, 0, sizeof(ALeffectslot
));
388 g_AuxiliaryEffectSlotCount
= 0;