Add an option for disabling ALSA mmap
[openal-soft/openbsd.git] / OpenAL32 / alListener.c
blob1e02622a7d733d80e5c19468b81bdcacd1f1ed61
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 case AL_METERS_PER_UNIT:
45 if (flValue > 0.0f)
46 pContext->Listener.MetersPerUnit = flValue;
47 else
48 alSetError(AL_INVALID_VALUE);
49 break;
51 default:
52 alSetError(AL_INVALID_ENUM);
53 break;
56 ProcessContext(pContext);
58 else
59 alSetError(AL_INVALID_OPERATION);
61 return;
65 ALAPI ALvoid ALAPIENTRY alListener3f(ALenum eParam, ALfloat flValue1, ALfloat flValue2, ALfloat flValue3)
67 ALCcontext *pContext;
69 pContext = alcGetCurrentContext();
70 if (pContext)
72 SuspendContext(pContext);
74 switch(eParam)
76 case AL_POSITION:
77 pContext->Listener.Position[0] = flValue1;
78 pContext->Listener.Position[1] = flValue2;
79 pContext->Listener.Position[2] = flValue3;
80 break;
82 case AL_VELOCITY:
83 pContext->Listener.Velocity[0] = flValue1;
84 pContext->Listener.Velocity[1] = flValue2;
85 pContext->Listener.Velocity[2] = flValue3;
86 break;
88 default:
89 alSetError(AL_INVALID_ENUM);
90 break;
93 ProcessContext(pContext);
95 else
96 alSetError(AL_INVALID_OPERATION);
98 return;
102 ALAPI ALvoid ALAPIENTRY alListenerfv(ALenum eParam, const ALfloat *pflValues)
104 ALCcontext *pContext;
106 pContext = alcGetCurrentContext();
107 if (pContext)
109 SuspendContext(pContext);
111 if (pflValues)
113 switch (eParam)
115 case AL_GAIN:
116 if (pflValues[0] >= 0.0f)
117 pContext->Listener.Gain = pflValues[0];
118 else
119 alSetError(AL_INVALID_VALUE);
120 break;
122 case AL_METERS_PER_UNIT:
123 if (pflValues[0] > 0.0f)
124 pContext->Listener.MetersPerUnit = pflValues[0];
125 else
126 alSetError(AL_INVALID_VALUE);
127 break;
129 case AL_POSITION:
130 pContext->Listener.Position[0] = pflValues[0];
131 pContext->Listener.Position[1] = pflValues[1];
132 pContext->Listener.Position[2] = pflValues[2];
133 break;
135 case AL_VELOCITY:
136 pContext->Listener.Velocity[0] = pflValues[0];
137 pContext->Listener.Velocity[1] = pflValues[1];
138 pContext->Listener.Velocity[2] = pflValues[2];
139 break;
141 case AL_ORIENTATION:
142 // AT then UP
143 pContext->Listener.Forward[0] = pflValues[0];
144 pContext->Listener.Forward[1] = pflValues[1];
145 pContext->Listener.Forward[2] = pflValues[2];
146 pContext->Listener.Up[0] = pflValues[3];
147 pContext->Listener.Up[1] = pflValues[4];
148 pContext->Listener.Up[2] = pflValues[5];
149 break;
151 default:
152 alSetError(AL_INVALID_ENUM);
153 break;
156 else
157 alSetError(AL_INVALID_VALUE);
159 ProcessContext(pContext);
161 else
162 alSetError(AL_INVALID_OPERATION);
164 return;
168 ALAPI ALvoid ALAPIENTRY alListeneri(ALenum eParam, ALint lValue)
170 ALCcontext *pContext;
172 (void)lValue;
174 pContext = alcGetCurrentContext();
175 if (pContext)
177 SuspendContext(pContext);
179 switch (eParam)
181 default:
182 alSetError(AL_INVALID_ENUM);
183 break;
186 ProcessContext(pContext);
188 else
189 alSetError(AL_INVALID_OPERATION);
191 return;
195 ALAPI void ALAPIENTRY alListener3i(ALenum eParam, ALint lValue1, ALint lValue2, ALint lValue3)
197 ALCcontext *pContext;
199 pContext = alcGetCurrentContext();
200 if (pContext)
202 SuspendContext(pContext);
204 switch(eParam)
206 case AL_POSITION:
207 case AL_VELOCITY:
208 alListener3f(eParam, (ALfloat)lValue1, (ALfloat)lValue2, (ALfloat)lValue3);
209 break;
211 default:
212 alSetError(AL_INVALID_ENUM);
213 break;
216 ProcessContext(pContext);
218 else
219 alSetError(AL_INVALID_OPERATION);
221 return;
225 ALAPI void ALAPIENTRY alListeneriv( ALenum eParam, const ALint* plValues )
227 ALCcontext *pContext;
228 ALfloat flValues[6];
230 pContext = alcGetCurrentContext();
231 if (pContext)
233 SuspendContext(pContext);
235 if (plValues)
237 switch (eParam)
239 case AL_POSITION:
240 case AL_VELOCITY:
241 flValues[0] = (ALfloat)plValues[0];
242 flValues[1] = (ALfloat)plValues[1];
243 flValues[2] = (ALfloat)plValues[2];
244 alListenerfv(eParam, flValues);
245 break;
247 case AL_ORIENTATION:
248 flValues[0] = (ALfloat)plValues[0];
249 flValues[1] = (ALfloat)plValues[1];
250 flValues[2] = (ALfloat)plValues[2];
251 flValues[3] = (ALfloat)plValues[3];
252 flValues[4] = (ALfloat)plValues[4];
253 flValues[5] = (ALfloat)plValues[5];
254 alListenerfv(eParam, flValues);
255 break;
257 default:
258 alSetError(AL_INVALID_ENUM);
259 break;
262 else
263 alSetError(AL_INVALID_VALUE);
265 ProcessContext(pContext);
267 else
268 alSetError(AL_INVALID_OPERATION);
270 return;
274 ALAPI ALvoid ALAPIENTRY alGetListenerf(ALenum eParam, ALfloat *pflValue)
276 ALCcontext *pContext;
278 pContext = alcGetCurrentContext();
279 if (pContext)
281 SuspendContext(pContext);
283 if (pflValue)
285 switch (eParam)
287 case AL_GAIN:
288 *pflValue = pContext->Listener.Gain;
289 break;
291 case AL_METERS_PER_UNIT:
292 *pflValue = pContext->Listener.MetersPerUnit;
293 break;
295 default:
296 alSetError(AL_INVALID_ENUM);
297 break;
300 else
301 alSetError(AL_INVALID_VALUE);
303 ProcessContext(pContext);
305 else
306 alSetError(AL_INVALID_OPERATION);
308 return;
312 ALAPI ALvoid ALAPIENTRY alGetListener3f(ALenum eParam, ALfloat *pflValue1, ALfloat *pflValue2, ALfloat *pflValue3)
314 ALCcontext *pContext;
316 pContext = alcGetCurrentContext();
317 if (pContext)
319 SuspendContext(pContext);
321 if ((pflValue1) && (pflValue2) && (pflValue3))
323 switch (eParam)
325 case AL_POSITION:
326 *pflValue1 = pContext->Listener.Position[0];
327 *pflValue2 = pContext->Listener.Position[1];
328 *pflValue3 = pContext->Listener.Position[2];
329 break;
331 case AL_VELOCITY:
332 *pflValue1 = pContext->Listener.Velocity[0];
333 *pflValue2 = pContext->Listener.Velocity[1];
334 *pflValue3 = pContext->Listener.Velocity[2];
335 break;
337 default:
338 alSetError(AL_INVALID_ENUM);
339 break;
342 else
343 alSetError(AL_INVALID_VALUE);
345 ProcessContext(pContext);
347 else
348 alSetError(AL_INVALID_OPERATION);
350 return;
354 ALAPI ALvoid ALAPIENTRY alGetListenerfv(ALenum eParam, ALfloat *pflValues)
356 ALCcontext *pContext;
358 pContext = alcGetCurrentContext();
359 if (pContext)
361 SuspendContext(pContext);
363 if (pflValues)
365 switch (eParam)
367 case AL_GAIN:
368 pflValues[0] = pContext->Listener.Gain;
369 break;
371 case AL_METERS_PER_UNIT:
372 pflValues[0] = pContext->Listener.MetersPerUnit;
373 break;
375 case AL_POSITION:
376 pflValues[0] = pContext->Listener.Position[0];
377 pflValues[1] = pContext->Listener.Position[1];
378 pflValues[2] = pContext->Listener.Position[2];
379 break;
381 case AL_VELOCITY:
382 pflValues[0] = pContext->Listener.Velocity[0];
383 pflValues[1] = pContext->Listener.Velocity[1];
384 pflValues[2] = pContext->Listener.Velocity[2];
385 break;
387 case AL_ORIENTATION:
388 // AT then UP
389 pflValues[0] = pContext->Listener.Forward[0];
390 pflValues[1] = pContext->Listener.Forward[1];
391 pflValues[2] = pContext->Listener.Forward[2];
392 pflValues[3] = pContext->Listener.Up[0];
393 pflValues[4] = pContext->Listener.Up[1];
394 pflValues[5] = pContext->Listener.Up[2];
395 break;
397 default:
398 alSetError(AL_INVALID_ENUM);
399 break;
402 else
403 alSetError(AL_INVALID_VALUE);
405 ProcessContext(pContext);
407 else
408 alSetError(AL_INVALID_OPERATION);
410 return;
414 ALAPI ALvoid ALAPIENTRY alGetListeneri(ALenum eParam, ALint *plValue)
416 ALCcontext *pContext;
418 pContext = alcGetCurrentContext();
419 if (pContext)
421 SuspendContext(pContext);
423 if (plValue)
425 switch (eParam)
427 default:
428 alSetError(AL_INVALID_ENUM);
429 break;
432 else
433 alSetError(AL_INVALID_VALUE);
435 ProcessContext(pContext);
437 else
438 alSetError(AL_INVALID_OPERATION);
440 return;
444 ALAPI void ALAPIENTRY alGetListener3i(ALenum eParam, ALint *plValue1, ALint *plValue2, ALint *plValue3)
446 ALCcontext *pContext;
448 pContext = alcGetCurrentContext();
449 if (pContext)
451 SuspendContext(pContext);
453 if ((plValue1) && (plValue2) && (plValue3))
455 switch (eParam)
457 case AL_POSITION:
458 *plValue1 = (ALint)pContext->Listener.Position[0];
459 *plValue2 = (ALint)pContext->Listener.Position[1];
460 *plValue3 = (ALint)pContext->Listener.Position[2];
461 break;
463 case AL_VELOCITY:
464 *plValue1 = (ALint)pContext->Listener.Velocity[0];
465 *plValue2 = (ALint)pContext->Listener.Velocity[1];
466 *plValue3 = (ALint)pContext->Listener.Velocity[2];
467 break;
469 default:
470 alSetError(AL_INVALID_ENUM);
471 break;
474 else
475 alSetError(AL_INVALID_VALUE);
477 ProcessContext(pContext);
479 else
480 alSetError(AL_INVALID_OPERATION);
482 return;
486 ALAPI void ALAPIENTRY alGetListeneriv(ALenum eParam, ALint* plValues)
488 ALCcontext *pContext;
490 pContext = alcGetCurrentContext();
491 if (pContext)
493 SuspendContext(pContext);
495 if (plValues)
497 switch (eParam)
499 case AL_POSITION:
500 plValues[0] = (ALint)pContext->Listener.Position[0];
501 plValues[1] = (ALint)pContext->Listener.Position[1];
502 plValues[2] = (ALint)pContext->Listener.Position[2];
503 break;
505 case AL_VELOCITY:
506 plValues[0] = (ALint)pContext->Listener.Velocity[0];
507 plValues[1] = (ALint)pContext->Listener.Velocity[1];
508 plValues[2] = (ALint)pContext->Listener.Velocity[2];
509 break;
511 case AL_ORIENTATION:
512 // AT then UP
513 plValues[0] = (ALint)pContext->Listener.Forward[0];
514 plValues[1] = (ALint)pContext->Listener.Forward[1];
515 plValues[2] = (ALint)pContext->Listener.Forward[2];
516 plValues[3] = (ALint)pContext->Listener.Up[0];
517 plValues[4] = (ALint)pContext->Listener.Up[1];
518 plValues[5] = (ALint)pContext->Listener.Up[2];
519 break;
521 default:
522 alSetError(AL_INVALID_ENUM);
523 break;
526 else
527 alSetError(AL_INVALID_VALUE);
529 ProcessContext(pContext);
531 else
532 alSetError(AL_INVALID_OPERATION);
534 return;