Avoid void-pointer arithmetic
[openal-soft.git] / OpenAL32 / alListener.c
blob97fc593cbc723555dadca4e23796d4695cc6d624
1 /**
2 * OpenAL cross platform audio library
3 * Copyright (C) 1999-2000 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
21 #include "alMain.h"
22 #include "AL/alc.h"
23 #include "alError.h"
24 #include "alListener.h"
26 ALAPI ALvoid ALAPIENTRY alListenerf(ALenum eParam, ALfloat flValue)
28 ALCcontext *pContext;
30 pContext = alcGetCurrentContext();
31 if (pContext)
33 SuspendContext(pContext);
35 switch (eParam)
37 case AL_GAIN:
38 if (flValue >= 0.0f)
39 pContext->Listener.Gain = flValue;
40 else
41 alSetError(AL_INVALID_VALUE);
42 break;
44 default:
45 alSetError(AL_INVALID_ENUM);
46 break;
49 ProcessContext(pContext);
51 else
52 alSetError(AL_INVALID_OPERATION);
54 return;
58 ALAPI ALvoid ALAPIENTRY alListener3f(ALenum eParam, ALfloat flValue1, ALfloat flValue2, ALfloat flValue3)
60 ALCcontext *pContext;
62 pContext = alcGetCurrentContext();
63 if (pContext)
65 SuspendContext(pContext);
67 switch(eParam)
69 case AL_POSITION:
70 pContext->Listener.Position[0] = flValue1;
71 pContext->Listener.Position[1] = flValue2;
72 pContext->Listener.Position[2] = flValue3;
73 break;
75 case AL_VELOCITY:
76 pContext->Listener.Velocity[0] = flValue1;
77 pContext->Listener.Velocity[1] = flValue2;
78 pContext->Listener.Velocity[2] = flValue3;
79 break;
81 default:
82 alSetError(AL_INVALID_ENUM);
83 break;
86 ProcessContext(pContext);
88 else
89 alSetError(AL_INVALID_OPERATION);
91 return;
95 ALAPI ALvoid ALAPIENTRY alListenerfv(ALenum eParam, const ALfloat *pflValues)
97 ALCcontext *pContext;
99 pContext = alcGetCurrentContext();
100 if (pContext)
102 SuspendContext(pContext);
104 if (pflValues)
106 switch (eParam)
108 case AL_GAIN:
109 if (pflValues[0] >= 0.0f)
110 pContext->Listener.Gain = pflValues[0];
111 else
112 alSetError(AL_INVALID_VALUE);
113 break;
115 case AL_POSITION:
116 pContext->Listener.Position[0] = pflValues[0];
117 pContext->Listener.Position[1] = pflValues[1];
118 pContext->Listener.Position[2] = pflValues[2];
119 break;
121 case AL_VELOCITY:
122 pContext->Listener.Velocity[0] = pflValues[0];
123 pContext->Listener.Velocity[1] = pflValues[1];
124 pContext->Listener.Velocity[2] = pflValues[2];
125 break;
127 case AL_ORIENTATION:
128 // AT then UP
129 pContext->Listener.Forward[0] = pflValues[0];
130 pContext->Listener.Forward[1] = pflValues[1];
131 pContext->Listener.Forward[2] = pflValues[2];
132 pContext->Listener.Up[0] = pflValues[3];
133 pContext->Listener.Up[1] = pflValues[4];
134 pContext->Listener.Up[2] = pflValues[5];
135 break;
137 default:
138 alSetError(AL_INVALID_ENUM);
139 break;
142 else
143 alSetError(AL_INVALID_VALUE);
145 ProcessContext(pContext);
147 else
148 alSetError(AL_INVALID_OPERATION);
150 return;
154 ALAPI ALvoid ALAPIENTRY alListeneri(ALenum eParam, ALint lValue)
156 ALCcontext *pContext;
158 (void)lValue;
160 pContext = alcGetCurrentContext();
161 if (pContext)
163 SuspendContext(pContext);
165 switch (eParam)
167 default:
168 alSetError(AL_INVALID_ENUM);
169 break;
172 ProcessContext(pContext);
174 else
175 alSetError(AL_INVALID_OPERATION);
177 return;
181 ALAPI void ALAPIENTRY alListener3i(ALenum eParam, ALint lValue1, ALint lValue2, ALint lValue3)
183 ALCcontext *pContext;
185 pContext = alcGetCurrentContext();
186 if (pContext)
188 SuspendContext(pContext);
190 switch(eParam)
192 case AL_POSITION:
193 case AL_VELOCITY:
194 alListener3f(eParam, (ALfloat)lValue1, (ALfloat)lValue2, (ALfloat)lValue3);
195 break;
197 default:
198 alSetError(AL_INVALID_ENUM);
199 break;
202 ProcessContext(pContext);
204 else
205 alSetError(AL_INVALID_OPERATION);
207 return;
211 ALAPI void ALAPIENTRY alListeneriv( ALenum eParam, const ALint* plValues )
213 ALCcontext *pContext;
214 ALfloat flValues[6];
216 pContext = alcGetCurrentContext();
217 if (pContext)
219 SuspendContext(pContext);
221 if (plValues)
223 switch (eParam)
225 case AL_POSITION:
226 case AL_VELOCITY:
227 flValues[0] = (ALfloat)plValues[0];
228 flValues[1] = (ALfloat)plValues[1];
229 flValues[2] = (ALfloat)plValues[2];
230 alListenerfv(eParam, flValues);
231 break;
233 case AL_ORIENTATION:
234 flValues[0] = (ALfloat)plValues[0];
235 flValues[1] = (ALfloat)plValues[1];
236 flValues[2] = (ALfloat)plValues[2];
237 flValues[3] = (ALfloat)plValues[3];
238 flValues[4] = (ALfloat)plValues[4];
239 flValues[5] = (ALfloat)plValues[5];
240 alListenerfv(eParam, flValues);
241 break;
243 default:
244 alSetError(AL_INVALID_ENUM);
245 break;
248 else
249 alSetError(AL_INVALID_VALUE);
251 ProcessContext(pContext);
253 else
254 alSetError(AL_INVALID_OPERATION);
256 return;
260 ALAPI ALvoid ALAPIENTRY alGetListenerf(ALenum eParam, ALfloat *pflValue)
262 ALCcontext *pContext;
264 pContext = alcGetCurrentContext();
265 if (pContext)
267 SuspendContext(pContext);
269 if (pflValue)
271 switch (eParam)
273 case AL_GAIN:
274 *pflValue = pContext->Listener.Gain;
275 break;
277 default:
278 alSetError(AL_INVALID_ENUM);
279 break;
282 else
283 alSetError(AL_INVALID_VALUE);
285 ProcessContext(pContext);
287 else
288 alSetError(AL_INVALID_OPERATION);
290 return;
294 ALAPI ALvoid ALAPIENTRY alGetListener3f(ALenum eParam, ALfloat *pflValue1, ALfloat *pflValue2, ALfloat *pflValue3)
296 ALCcontext *pContext;
298 pContext = alcGetCurrentContext();
299 if (pContext)
301 SuspendContext(pContext);
303 if ((pflValue1) && (pflValue2) && (pflValue3))
305 switch (eParam)
307 case AL_POSITION:
308 *pflValue1 = pContext->Listener.Position[0];
309 *pflValue2 = pContext->Listener.Position[1];
310 *pflValue3 = pContext->Listener.Position[2];
311 break;
313 case AL_VELOCITY:
314 *pflValue1 = pContext->Listener.Velocity[0];
315 *pflValue2 = pContext->Listener.Velocity[1];
316 *pflValue3 = pContext->Listener.Velocity[2];
317 break;
319 default:
320 alSetError(AL_INVALID_ENUM);
321 break;
324 else
325 alSetError(AL_INVALID_VALUE);
327 ProcessContext(pContext);
329 else
330 alSetError(AL_INVALID_OPERATION);
332 return;
336 ALAPI ALvoid ALAPIENTRY alGetListenerfv(ALenum eParam, ALfloat *pflValues)
338 ALCcontext *pContext;
340 pContext = alcGetCurrentContext();
341 if (pContext)
343 SuspendContext(pContext);
345 if (pflValues)
347 switch (eParam)
349 case AL_GAIN:
350 pflValues[0] = pContext->Listener.Gain;
351 break;
353 case AL_POSITION:
354 pflValues[0] = pContext->Listener.Position[0];
355 pflValues[1] = pContext->Listener.Position[1];
356 pflValues[2] = pContext->Listener.Position[2];
357 break;
359 case AL_VELOCITY:
360 pflValues[0] = pContext->Listener.Velocity[0];
361 pflValues[1] = pContext->Listener.Velocity[1];
362 pflValues[2] = pContext->Listener.Velocity[2];
363 break;
365 case AL_ORIENTATION:
366 // AT then UP
367 pflValues[0] = pContext->Listener.Forward[0];
368 pflValues[1] = pContext->Listener.Forward[1];
369 pflValues[2] = pContext->Listener.Forward[2];
370 pflValues[3] = pContext->Listener.Up[0];
371 pflValues[4] = pContext->Listener.Up[1];
372 pflValues[5] = pContext->Listener.Up[2];
373 break;
375 default:
376 alSetError(AL_INVALID_ENUM);
377 break;
380 else
381 alSetError(AL_INVALID_VALUE);
383 ProcessContext(pContext);
385 else
386 alSetError(AL_INVALID_OPERATION);
388 return;
392 ALAPI ALvoid ALAPIENTRY alGetListeneri(ALenum eParam, ALint *plValue)
394 ALCcontext *pContext;
396 pContext = alcGetCurrentContext();
397 if (pContext)
399 SuspendContext(pContext);
401 if (plValue)
403 switch (eParam)
405 default:
406 alSetError(AL_INVALID_ENUM);
407 break;
410 else
411 alSetError(AL_INVALID_VALUE);
413 ProcessContext(pContext);
415 else
416 alSetError(AL_INVALID_OPERATION);
418 return;
422 ALAPI void ALAPIENTRY alGetListener3i(ALenum eParam, ALint *plValue1, ALint *plValue2, ALint *plValue3)
424 ALCcontext *pContext;
426 pContext = alcGetCurrentContext();
427 if (pContext)
429 SuspendContext(pContext);
431 if ((plValue1) && (plValue2) && (plValue3))
433 switch (eParam)
435 case AL_POSITION:
436 *plValue1 = (ALint)pContext->Listener.Position[0];
437 *plValue2 = (ALint)pContext->Listener.Position[1];
438 *plValue3 = (ALint)pContext->Listener.Position[2];
439 break;
441 case AL_VELOCITY:
442 *plValue1 = (ALint)pContext->Listener.Velocity[0];
443 *plValue2 = (ALint)pContext->Listener.Velocity[1];
444 *plValue3 = (ALint)pContext->Listener.Velocity[2];
445 break;
447 default:
448 alSetError(AL_INVALID_ENUM);
449 break;
452 else
453 alSetError(AL_INVALID_VALUE);
455 ProcessContext(pContext);
457 else
458 alSetError(AL_INVALID_OPERATION);
460 return;
464 ALAPI void ALAPIENTRY alGetListeneriv(ALenum eParam, ALint* plValues)
466 ALCcontext *pContext;
468 pContext = alcGetCurrentContext();
469 if (pContext)
471 SuspendContext(pContext);
473 if (plValues)
475 switch (eParam)
477 case AL_POSITION:
478 plValues[0] = (ALint)pContext->Listener.Position[0];
479 plValues[1] = (ALint)pContext->Listener.Position[1];
480 plValues[2] = (ALint)pContext->Listener.Position[2];
481 break;
483 case AL_VELOCITY:
484 plValues[0] = (ALint)pContext->Listener.Velocity[0];
485 plValues[1] = (ALint)pContext->Listener.Velocity[1];
486 plValues[2] = (ALint)pContext->Listener.Velocity[2];
487 break;
489 case AL_ORIENTATION:
490 // AT then UP
491 plValues[0] = (ALint)pContext->Listener.Forward[0];
492 plValues[1] = (ALint)pContext->Listener.Forward[1];
493 plValues[2] = (ALint)pContext->Listener.Forward[2];
494 plValues[3] = (ALint)pContext->Listener.Up[0];
495 plValues[4] = (ALint)pContext->Listener.Up[1];
496 plValues[5] = (ALint)pContext->Listener.Up[2];
497 break;
499 default:
500 alSetError(AL_INVALID_ENUM);
501 break;
504 else
505 alSetError(AL_INVALID_VALUE);
507 ProcessContext(pContext);
509 else
510 alSetError(AL_INVALID_OPERATION);
512 return;