Allow for overriding the default lib destination with LIB_INSTALL_DIR
[openal-soft/openal-hmr.git] / OpenAL32 / alState.c
blobc577ea8df89ced0c0b891370df0c72d4135bb77c
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 "config.h"
23 #include <stdlib.h>
24 #include "alMain.h"
25 #include "AL/alc.h"
26 #include "alError.h"
27 #include "alState.h"
29 static const ALchar alVendor[] = "OpenAL Community";
30 static const ALchar alVersion[] = "1.1";
31 static const ALchar alRenderer[] = "OpenAL Soft";
33 // Error Messages
34 static const ALchar alNoError[] = "No Error";
35 static const ALchar alErrInvalidName[] = "Invalid Name";
36 static const ALchar alErrInvalidEnum[] = "Invalid Enum";
37 static const ALchar alErrInvalidValue[] = "Invalid Value";
38 static const ALchar alErrInvalidOp[] = "Invalid Operation";
39 static const ALchar alErrOutOfMemory[] = "Out of Memory";
41 ALAPI ALvoid ALAPIENTRY alEnable(ALenum capability)
43 ALCcontext *Context;
45 Context=alcGetCurrentContext();
46 if (Context)
48 SuspendContext(Context);
50 switch (capability)
52 default:
53 alSetError(AL_INVALID_ENUM);
54 break;
57 ProcessContext(Context);
59 else
61 // Invalid Context
62 alSetError(AL_INVALID_OPERATION);
66 ALAPI ALvoid ALAPIENTRY alDisable(ALenum capability)
68 ALCcontext *Context;
70 Context=alcGetCurrentContext();
71 if (Context)
73 SuspendContext(Context);
75 switch (capability)
77 default:
78 alSetError(AL_INVALID_ENUM);
79 break;
82 ProcessContext(Context);
84 else
86 // Invalid Context
87 alSetError(AL_INVALID_OPERATION);
91 ALAPI ALboolean ALAPIENTRY alIsEnabled(ALenum capability)
93 ALCcontext *Context;
94 ALboolean value=AL_FALSE;
96 Context=alcGetCurrentContext();
97 if (Context)
99 SuspendContext(Context);
101 switch (capability)
103 default:
104 alSetError(AL_INVALID_ENUM);
105 break;
108 ProcessContext(Context);
110 else
112 // Invalid Context
113 alSetError(AL_INVALID_OPERATION);
116 return value;
119 ALAPI ALboolean ALAPIENTRY alGetBoolean(ALenum pname)
121 ALCcontext *Context;
122 ALboolean value=AL_FALSE;
124 Context=alcGetCurrentContext();
125 if (Context)
127 SuspendContext(Context);
129 switch (pname)
131 case AL_DOPPLER_FACTOR:
132 if (Context->DopplerFactor != 0.0f)
133 value = AL_TRUE;
134 break;
136 case AL_DOPPLER_VELOCITY:
137 if (Context->DopplerVelocity != 0.0f)
138 value = AL_TRUE;
139 break;
141 case AL_DISTANCE_MODEL:
142 if (Context->DistanceModel == AL_INVERSE_DISTANCE_CLAMPED)
143 value = AL_TRUE;
144 break;
146 case AL_SPEED_OF_SOUND:
147 if (Context->flSpeedOfSound != 0.0f)
148 value = AL_TRUE;
149 break;
151 default:
152 alSetError(AL_INVALID_ENUM);
153 break;
156 ProcessContext(Context);
158 else
160 // Invalid Context
161 alSetError(AL_INVALID_OPERATION);
164 return value;
167 ALAPI ALdouble ALAPIENTRY alGetDouble(ALenum pname)
169 ALCcontext *Context;
170 ALdouble value = 0.0;
172 Context=alcGetCurrentContext();
173 if (Context)
175 SuspendContext(Context);
177 switch (pname)
179 case AL_DOPPLER_FACTOR:
180 value = (double)Context->DopplerFactor;
181 break;
183 case AL_DOPPLER_VELOCITY:
184 value = (double)Context->DopplerVelocity;
185 break;
187 case AL_DISTANCE_MODEL:
188 value = (double)Context->DistanceModel;
189 break;
191 case AL_SPEED_OF_SOUND:
192 value = (double)Context->flSpeedOfSound;
193 break;
195 default:
196 alSetError(AL_INVALID_ENUM);
197 break;
200 ProcessContext(Context);
202 else
204 // Invalid Context
205 alSetError(AL_INVALID_OPERATION);
208 return value;
211 ALAPI ALfloat ALAPIENTRY alGetFloat(ALenum pname)
213 ALCcontext *Context;
214 ALfloat value = 0.0f;
216 Context=alcGetCurrentContext();
217 if (Context)
219 SuspendContext(Context);
221 switch (pname)
223 case AL_DOPPLER_FACTOR:
224 value = Context->DopplerFactor;
225 break;
227 case AL_DOPPLER_VELOCITY:
228 value = Context->DopplerVelocity;
229 break;
231 case AL_DISTANCE_MODEL:
232 value = (float)Context->DistanceModel;
233 break;
235 case AL_SPEED_OF_SOUND:
236 value = Context->flSpeedOfSound;
237 break;
239 default:
240 alSetError(AL_INVALID_ENUM);
241 break;
244 ProcessContext(Context);
246 else
248 // Invalid Context
249 alSetError(AL_INVALID_OPERATION);
252 return value;
255 ALAPI ALint ALAPIENTRY alGetInteger(ALenum pname)
257 ALCcontext *Context;
258 ALint value = 0;
260 Context=alcGetCurrentContext();
261 if (Context)
263 SuspendContext(Context);
265 switch (pname)
267 case AL_DOPPLER_FACTOR:
268 value = (ALint)Context->DopplerFactor;
269 break;
271 case AL_DOPPLER_VELOCITY:
272 value = (ALint)Context->DopplerVelocity;
273 break;
275 case AL_DISTANCE_MODEL:
276 value = (ALint)Context->DistanceModel;
277 break;
279 case AL_SPEED_OF_SOUND:
280 value = (ALint)Context->flSpeedOfSound;
281 break;
283 default:
284 alSetError(AL_INVALID_ENUM);
285 break;
288 ProcessContext(Context);
290 else
292 // Invalid Context
293 alSetError(AL_INVALID_OPERATION);
296 return value;
299 ALAPI ALvoid ALAPIENTRY alGetBooleanv(ALenum pname,ALboolean *data)
301 ALCcontext *Context;
303 Context=alcGetCurrentContext();
304 if (Context)
306 SuspendContext(Context);
308 if (data)
310 switch (pname)
312 case AL_DOPPLER_FACTOR:
313 *data = (ALboolean)((Context->DopplerFactor != 0.0f) ? AL_TRUE : AL_FALSE);
314 break;
316 case AL_DOPPLER_VELOCITY:
317 *data = (ALboolean)((Context->DopplerVelocity != 0.0f) ? AL_TRUE : AL_FALSE);
318 break;
320 case AL_DISTANCE_MODEL:
321 *data = (ALboolean)((Context->DistanceModel == AL_INVERSE_DISTANCE_CLAMPED) ? AL_TRUE : AL_FALSE);
322 break;
324 case AL_SPEED_OF_SOUND:
325 *data = (ALboolean)((Context->flSpeedOfSound != 0.0f) ? AL_TRUE : AL_FALSE);
326 break;
328 default:
329 alSetError(AL_INVALID_ENUM);
330 break;
333 else
335 // data is a NULL pointer
336 alSetError(AL_INVALID_VALUE);
339 ProcessContext(Context);
341 else
343 // Invalid Context
344 alSetError(AL_INVALID_OPERATION);
347 return;
350 ALAPI ALvoid ALAPIENTRY alGetDoublev(ALenum pname,ALdouble *data)
352 ALCcontext *Context;
354 Context=alcGetCurrentContext();
355 if (Context)
357 SuspendContext(Context);
359 if (data)
361 switch (pname)
363 case AL_DOPPLER_FACTOR:
364 *data = (double)Context->DopplerFactor;
365 break;
367 case AL_DOPPLER_VELOCITY:
368 *data = (double)Context->DopplerVelocity;
369 break;
371 case AL_DISTANCE_MODEL:
372 *data = (double)Context->DistanceModel;
373 break;
375 case AL_SPEED_OF_SOUND:
376 *data = (double)Context->flSpeedOfSound;
377 break;
379 default:
380 alSetError(AL_INVALID_ENUM);
381 break;
384 else
386 // data is a NULL pointer
387 alSetError(AL_INVALID_VALUE);
390 ProcessContext(Context);
392 else
394 // Invalid Context
395 alSetError(AL_INVALID_OPERATION);
398 return;
401 ALAPI ALvoid ALAPIENTRY alGetFloatv(ALenum pname,ALfloat *data)
403 ALCcontext *Context;
405 Context=alcGetCurrentContext();
406 if (Context)
408 SuspendContext(Context);
410 if (data)
412 switch (pname)
414 case AL_DOPPLER_FACTOR:
415 *data = Context->DopplerFactor;
416 break;
418 case AL_DOPPLER_VELOCITY:
419 *data = Context->DopplerVelocity;
420 break;
422 case AL_DISTANCE_MODEL:
423 *data = (float)Context->DistanceModel;
424 break;
426 case AL_SPEED_OF_SOUND:
427 *data = Context->flSpeedOfSound;
428 break;
430 default:
431 alSetError(AL_INVALID_ENUM);
432 break;
435 else
437 // data is a NULL pointer
438 alSetError(AL_INVALID_VALUE);
441 ProcessContext(Context);
443 else
445 // Invalid Context
446 alSetError(AL_INVALID_OPERATION);
449 return;
452 ALAPI ALvoid ALAPIENTRY alGetIntegerv(ALenum pname,ALint *data)
454 ALCcontext *Context;
456 Context=alcGetCurrentContext();
457 if (Context)
459 SuspendContext(Context);
461 if (data)
463 switch (pname)
465 case AL_DOPPLER_FACTOR:
466 *data = (ALint)Context->DopplerFactor;
467 break;
469 case AL_DOPPLER_VELOCITY:
470 *data = (ALint)Context->DopplerVelocity;
471 break;
473 case AL_DISTANCE_MODEL:
474 *data = (ALint)Context->DistanceModel;
475 break;
477 case AL_SPEED_OF_SOUND:
478 *data = (ALint)Context->flSpeedOfSound;
479 break;
481 default:
482 alSetError(AL_INVALID_ENUM);
483 break;
486 else
488 // data is a NULL pointer
489 alSetError(AL_INVALID_VALUE);
492 ProcessContext(Context);
494 else
496 // Invalid Context
497 alSetError(AL_INVALID_OPERATION);
500 return;
503 ALAPI const ALchar* ALAPIENTRY alGetString(ALenum pname)
505 const ALchar *value;
506 ALCcontext *pContext;
508 pContext = alcGetCurrentContext();
509 if(!pContext)
511 alSetError(AL_INVALID_OPERATION);
512 return NULL;
515 SuspendContext(pContext);
517 switch(pname)
519 case AL_VENDOR:
520 value=alVendor;
521 break;
523 case AL_VERSION:
524 value=alVersion;
525 break;
527 case AL_RENDERER:
528 value=alRenderer;
529 break;
531 case AL_EXTENSIONS:
532 value=pContext->ExtensionList;//alExtensions;
533 break;
535 case AL_NO_ERROR:
536 value=alNoError;
537 break;
539 case AL_INVALID_NAME:
540 value=alErrInvalidName;
541 break;
543 case AL_INVALID_ENUM:
544 value=alErrInvalidEnum;
545 break;
547 case AL_INVALID_VALUE:
548 value=alErrInvalidValue;
549 break;
551 case AL_INVALID_OPERATION:
552 value=alErrInvalidOp;
553 break;
555 case AL_OUT_OF_MEMORY:
556 value=alErrOutOfMemory;
557 break;
559 default:
560 value=NULL;
561 alSetError(AL_INVALID_ENUM);
562 break;
565 ProcessContext(pContext);
567 return value;
570 ALAPI ALvoid ALAPIENTRY alDopplerFactor(ALfloat value)
572 ALCcontext *Context;
574 Context=alcGetCurrentContext();
575 if (Context)
577 SuspendContext(Context);
579 if (value>=0.0f)
580 Context->DopplerFactor = value;
581 else
582 alSetError(AL_INVALID_VALUE);
584 ProcessContext(Context);
586 else
588 // Invalid Context
589 alSetError(AL_INVALID_OPERATION);
592 return;
595 ALAPI ALvoid ALAPIENTRY alDopplerVelocity(ALfloat value)
597 ALCcontext *Context;
599 Context=alcGetCurrentContext();
600 if (Context)
602 SuspendContext(Context);
604 if (value>0.0f)
605 Context->DopplerVelocity=value;
606 else
607 alSetError(AL_INVALID_VALUE);
609 ProcessContext(Context);
611 else
613 // Invalid Context
614 alSetError(AL_INVALID_OPERATION);
617 return;
620 ALAPI ALvoid ALAPIENTRY alSpeedOfSound(ALfloat flSpeedOfSound)
622 ALCcontext *pContext;
624 pContext = alcGetCurrentContext();
625 if (pContext)
627 SuspendContext(pContext);
629 if (flSpeedOfSound > 0.0f)
630 pContext->flSpeedOfSound = flSpeedOfSound;
631 else
632 alSetError(AL_INVALID_VALUE);
634 ProcessContext(pContext);
636 else
638 alSetError(AL_INVALID_OPERATION);
641 return;
644 ALAPI ALvoid ALAPIENTRY alDistanceModel(ALenum value)
646 ALCcontext *Context;
648 Context=alcGetCurrentContext();
649 if (Context)
651 SuspendContext(Context);
653 switch (value)
655 case AL_NONE:
656 case AL_INVERSE_DISTANCE:
657 case AL_INVERSE_DISTANCE_CLAMPED:
658 case AL_LINEAR_DISTANCE:
659 case AL_LINEAR_DISTANCE_CLAMPED:
660 case AL_EXPONENT_DISTANCE:
661 case AL_EXPONENT_DISTANCE_CLAMPED:
662 Context->DistanceModel = value;
663 break;
665 default:
666 alSetError(AL_INVALID_VALUE);
667 break;
670 ProcessContext(Context);
672 else
674 // Invalid Context
675 alSetError(AL_INVALID_OPERATION);
678 return;