Document the ambisonic decoder options
[openal-soft.git] / OpenAL32 / alState.c
blobdca413633a41725eb7ff12f0c488f3740a37ff47
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.,
17 * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 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 "AL/al.h"
27 #include "AL/alext.h"
28 #include "alError.h"
29 #include "alSource.h"
30 #include "alAuxEffectSlot.h"
32 #include "backends/base.h"
35 static const ALchar alVendor[] = "OpenAL Community";
36 static const ALchar alVersion[] = "1.1 ALSOFT "ALSOFT_VERSION;
37 static const ALchar alRenderer[] = "OpenAL Soft";
39 // Error Messages
40 static const ALchar alNoError[] = "No Error";
41 static const ALchar alErrInvalidName[] = "Invalid Name";
42 static const ALchar alErrInvalidEnum[] = "Invalid Enum";
43 static const ALchar alErrInvalidValue[] = "Invalid Value";
44 static const ALchar alErrInvalidOp[] = "Invalid Operation";
45 static const ALchar alErrOutOfMemory[] = "Out of Memory";
47 AL_API ALvoid AL_APIENTRY alEnable(ALenum capability)
49 ALCcontext *context;
51 context = GetContextRef();
52 if(!context) return;
54 switch(capability)
56 case AL_SOURCE_DISTANCE_MODEL:
57 context->SourceDistanceModel = AL_TRUE;
58 ATOMIC_STORE(&context->UpdateSources, AL_TRUE);
59 break;
61 default:
62 SET_ERROR_AND_GOTO(context, AL_INVALID_ENUM, done);
65 done:
66 ALCcontext_DecRef(context);
69 AL_API ALvoid AL_APIENTRY alDisable(ALenum capability)
71 ALCcontext *context;
73 context = GetContextRef();
74 if(!context) return;
76 switch(capability)
78 case AL_SOURCE_DISTANCE_MODEL:
79 context->SourceDistanceModel = AL_FALSE;
80 ATOMIC_STORE(&context->UpdateSources, AL_TRUE);
81 break;
83 default:
84 SET_ERROR_AND_GOTO(context, AL_INVALID_ENUM, done);
87 done:
88 ALCcontext_DecRef(context);
91 AL_API ALboolean AL_APIENTRY alIsEnabled(ALenum capability)
93 ALCcontext *context;
94 ALboolean value=AL_FALSE;
96 context = GetContextRef();
97 if(!context) return AL_FALSE;
99 switch(capability)
101 case AL_SOURCE_DISTANCE_MODEL:
102 value = context->SourceDistanceModel;
103 break;
105 default:
106 SET_ERROR_AND_GOTO(context, AL_INVALID_ENUM, done);
109 done:
110 ALCcontext_DecRef(context);
112 return value;
115 AL_API ALboolean AL_APIENTRY alGetBoolean(ALenum pname)
117 ALCcontext *context;
118 ALboolean value=AL_FALSE;
120 context = GetContextRef();
121 if(!context) return AL_FALSE;
123 switch(pname)
125 case AL_DOPPLER_FACTOR:
126 if(context->DopplerFactor != 0.0f)
127 value = AL_TRUE;
128 break;
130 case AL_DOPPLER_VELOCITY:
131 if(context->DopplerVelocity != 0.0f)
132 value = AL_TRUE;
133 break;
135 case AL_DISTANCE_MODEL:
136 if(context->DistanceModel == AL_INVERSE_DISTANCE_CLAMPED)
137 value = AL_TRUE;
138 break;
140 case AL_SPEED_OF_SOUND:
141 if(context->SpeedOfSound != 0.0f)
142 value = AL_TRUE;
143 break;
145 case AL_DEFERRED_UPDATES_SOFT:
146 value = context->DeferUpdates;
147 break;
149 default:
150 SET_ERROR_AND_GOTO(context, AL_INVALID_ENUM, done);
153 done:
154 ALCcontext_DecRef(context);
156 return value;
159 AL_API ALdouble AL_APIENTRY alGetDouble(ALenum pname)
161 ALCcontext *context;
162 ALdouble value = 0.0;
164 context = GetContextRef();
165 if(!context) return 0.0;
167 switch(pname)
169 case AL_DOPPLER_FACTOR:
170 value = (ALdouble)context->DopplerFactor;
171 break;
173 case AL_DOPPLER_VELOCITY:
174 value = (ALdouble)context->DopplerVelocity;
175 break;
177 case AL_DISTANCE_MODEL:
178 value = (ALdouble)context->DistanceModel;
179 break;
181 case AL_SPEED_OF_SOUND:
182 value = (ALdouble)context->SpeedOfSound;
183 break;
185 case AL_DEFERRED_UPDATES_SOFT:
186 value = (ALdouble)context->DeferUpdates;
187 break;
189 default:
190 SET_ERROR_AND_GOTO(context, AL_INVALID_ENUM, done);
193 done:
194 ALCcontext_DecRef(context);
196 return value;
199 AL_API ALfloat AL_APIENTRY alGetFloat(ALenum pname)
201 ALCcontext *context;
202 ALfloat value = 0.0f;
204 context = GetContextRef();
205 if(!context) return 0.0f;
207 switch(pname)
209 case AL_DOPPLER_FACTOR:
210 value = context->DopplerFactor;
211 break;
213 case AL_DOPPLER_VELOCITY:
214 value = context->DopplerVelocity;
215 break;
217 case AL_DISTANCE_MODEL:
218 value = (ALfloat)context->DistanceModel;
219 break;
221 case AL_SPEED_OF_SOUND:
222 value = context->SpeedOfSound;
223 break;
225 case AL_DEFERRED_UPDATES_SOFT:
226 value = (ALfloat)context->DeferUpdates;
227 break;
229 default:
230 SET_ERROR_AND_GOTO(context, AL_INVALID_ENUM, done);
233 done:
234 ALCcontext_DecRef(context);
236 return value;
239 AL_API ALint AL_APIENTRY alGetInteger(ALenum pname)
241 ALCcontext *context;
242 ALint value = 0;
244 context = GetContextRef();
245 if(!context) return 0;
247 switch(pname)
249 case AL_DOPPLER_FACTOR:
250 value = (ALint)context->DopplerFactor;
251 break;
253 case AL_DOPPLER_VELOCITY:
254 value = (ALint)context->DopplerVelocity;
255 break;
257 case AL_DISTANCE_MODEL:
258 value = (ALint)context->DistanceModel;
259 break;
261 case AL_SPEED_OF_SOUND:
262 value = (ALint)context->SpeedOfSound;
263 break;
265 case AL_DEFERRED_UPDATES_SOFT:
266 value = (ALint)context->DeferUpdates;
267 break;
269 default:
270 SET_ERROR_AND_GOTO(context, AL_INVALID_ENUM, done);
273 done:
274 ALCcontext_DecRef(context);
276 return value;
279 AL_API ALint64SOFT AL_APIENTRY alGetInteger64SOFT(ALenum pname)
281 ALCcontext *context;
282 ALint64SOFT value = 0;
284 context = GetContextRef();
285 if(!context) return 0;
287 switch(pname)
289 case AL_DOPPLER_FACTOR:
290 value = (ALint64SOFT)context->DopplerFactor;
291 break;
293 case AL_DOPPLER_VELOCITY:
294 value = (ALint64SOFT)context->DopplerVelocity;
295 break;
297 case AL_DISTANCE_MODEL:
298 value = (ALint64SOFT)context->DistanceModel;
299 break;
301 case AL_SPEED_OF_SOUND:
302 value = (ALint64SOFT)context->SpeedOfSound;
303 break;
305 case AL_DEFERRED_UPDATES_SOFT:
306 value = (ALint64SOFT)context->DeferUpdates;
307 break;
309 default:
310 SET_ERROR_AND_GOTO(context, AL_INVALID_ENUM, done);
313 done:
314 ALCcontext_DecRef(context);
316 return value;
319 AL_API ALvoid AL_APIENTRY alGetBooleanv(ALenum pname, ALboolean *values)
321 ALCcontext *context;
323 if(values)
325 switch(pname)
327 case AL_DOPPLER_FACTOR:
328 case AL_DOPPLER_VELOCITY:
329 case AL_DISTANCE_MODEL:
330 case AL_SPEED_OF_SOUND:
331 case AL_DEFERRED_UPDATES_SOFT:
332 values[0] = alGetBoolean(pname);
333 return;
337 context = GetContextRef();
338 if(!context) return;
340 if(!(values))
341 SET_ERROR_AND_GOTO(context, AL_INVALID_VALUE, done);
342 switch(pname)
344 default:
345 SET_ERROR_AND_GOTO(context, AL_INVALID_ENUM, done);
348 done:
349 ALCcontext_DecRef(context);
352 AL_API ALvoid AL_APIENTRY alGetDoublev(ALenum pname, ALdouble *values)
354 ALCcontext *context;
356 if(values)
358 switch(pname)
360 case AL_DOPPLER_FACTOR:
361 case AL_DOPPLER_VELOCITY:
362 case AL_DISTANCE_MODEL:
363 case AL_SPEED_OF_SOUND:
364 case AL_DEFERRED_UPDATES_SOFT:
365 values[0] = alGetDouble(pname);
366 return;
370 context = GetContextRef();
371 if(!context) return;
373 if(!(values))
374 SET_ERROR_AND_GOTO(context, AL_INVALID_VALUE, done);
375 switch(pname)
377 default:
378 SET_ERROR_AND_GOTO(context, AL_INVALID_ENUM, done);
381 done:
382 ALCcontext_DecRef(context);
385 AL_API ALvoid AL_APIENTRY alGetFloatv(ALenum pname, ALfloat *values)
387 ALCcontext *context;
389 if(values)
391 switch(pname)
393 case AL_DOPPLER_FACTOR:
394 case AL_DOPPLER_VELOCITY:
395 case AL_DISTANCE_MODEL:
396 case AL_SPEED_OF_SOUND:
397 case AL_DEFERRED_UPDATES_SOFT:
398 values[0] = alGetFloat(pname);
399 return;
403 context = GetContextRef();
404 if(!context) return;
406 if(!(values))
407 SET_ERROR_AND_GOTO(context, AL_INVALID_VALUE, done);
408 switch(pname)
410 default:
411 SET_ERROR_AND_GOTO(context, AL_INVALID_ENUM, done);
414 done:
415 ALCcontext_DecRef(context);
418 AL_API ALvoid AL_APIENTRY alGetIntegerv(ALenum pname, ALint *values)
420 ALCcontext *context;
422 if(values)
424 switch(pname)
426 case AL_DOPPLER_FACTOR:
427 case AL_DOPPLER_VELOCITY:
428 case AL_DISTANCE_MODEL:
429 case AL_SPEED_OF_SOUND:
430 case AL_DEFERRED_UPDATES_SOFT:
431 values[0] = alGetInteger(pname);
432 return;
436 context = GetContextRef();
437 if(!context) return;
439 switch(pname)
441 default:
442 SET_ERROR_AND_GOTO(context, AL_INVALID_ENUM, done);
445 done:
446 ALCcontext_DecRef(context);
449 AL_API void AL_APIENTRY alGetInteger64vSOFT(ALenum pname, ALint64SOFT *values)
451 ALCcontext *context;
453 if(values)
455 switch(pname)
457 case AL_DOPPLER_FACTOR:
458 case AL_DOPPLER_VELOCITY:
459 case AL_DISTANCE_MODEL:
460 case AL_SPEED_OF_SOUND:
461 case AL_DEFERRED_UPDATES_SOFT:
462 values[0] = alGetInteger64SOFT(pname);
463 return;
467 context = GetContextRef();
468 if(!context) return;
470 switch(pname)
472 default:
473 SET_ERROR_AND_GOTO(context, AL_INVALID_ENUM, done);
476 done:
477 ALCcontext_DecRef(context);
480 AL_API const ALchar* AL_APIENTRY alGetString(ALenum pname)
482 const ALchar *value = NULL;
483 ALCcontext *context;
485 context = GetContextRef();
486 if(!context) return NULL;
488 switch(pname)
490 case AL_VENDOR:
491 value = alVendor;
492 break;
494 case AL_VERSION:
495 value = alVersion;
496 break;
498 case AL_RENDERER:
499 value = alRenderer;
500 break;
502 case AL_EXTENSIONS:
503 value = context->ExtensionList;
504 break;
506 case AL_NO_ERROR:
507 value = alNoError;
508 break;
510 case AL_INVALID_NAME:
511 value = alErrInvalidName;
512 break;
514 case AL_INVALID_ENUM:
515 value = alErrInvalidEnum;
516 break;
518 case AL_INVALID_VALUE:
519 value = alErrInvalidValue;
520 break;
522 case AL_INVALID_OPERATION:
523 value = alErrInvalidOp;
524 break;
526 case AL_OUT_OF_MEMORY:
527 value = alErrOutOfMemory;
528 break;
530 default:
531 SET_ERROR_AND_GOTO(context, AL_INVALID_ENUM, done);
534 done:
535 ALCcontext_DecRef(context);
537 return value;
540 AL_API ALvoid AL_APIENTRY alDopplerFactor(ALfloat value)
542 ALCcontext *context;
544 context = GetContextRef();
545 if(!context) return;
547 if(!(value >= 0.0f && isfinite(value)))
548 SET_ERROR_AND_GOTO(context, AL_INVALID_VALUE, done);
550 context->DopplerFactor = value;
551 ATOMIC_STORE(&context->UpdateSources, AL_TRUE);
553 done:
554 ALCcontext_DecRef(context);
557 AL_API ALvoid AL_APIENTRY alDopplerVelocity(ALfloat value)
559 ALCcontext *context;
561 context = GetContextRef();
562 if(!context) return;
564 if(!(value >= 0.0f && isfinite(value)))
565 SET_ERROR_AND_GOTO(context, AL_INVALID_VALUE, done);
567 context->DopplerVelocity = value;
568 ATOMIC_STORE(&context->UpdateSources, AL_TRUE);
570 done:
571 ALCcontext_DecRef(context);
574 AL_API ALvoid AL_APIENTRY alSpeedOfSound(ALfloat value)
576 ALCcontext *context;
578 context = GetContextRef();
579 if(!context) return;
581 if(!(value > 0.0f && isfinite(value)))
582 SET_ERROR_AND_GOTO(context, AL_INVALID_VALUE, done);
584 context->SpeedOfSound = value;
585 ATOMIC_STORE(&context->UpdateSources, AL_TRUE);
587 done:
588 ALCcontext_DecRef(context);
591 AL_API ALvoid AL_APIENTRY alDistanceModel(ALenum value)
593 ALCcontext *context;
595 context = GetContextRef();
596 if(!context) return;
598 if(!(value == AL_INVERSE_DISTANCE || value == AL_INVERSE_DISTANCE_CLAMPED ||
599 value == AL_LINEAR_DISTANCE || value == AL_LINEAR_DISTANCE_CLAMPED ||
600 value == AL_EXPONENT_DISTANCE || value == AL_EXPONENT_DISTANCE_CLAMPED ||
601 value == AL_NONE))
602 SET_ERROR_AND_GOTO(context, AL_INVALID_VALUE, done);
604 context->DistanceModel = value;
605 if(!context->SourceDistanceModel)
606 ATOMIC_STORE(&context->UpdateSources, AL_TRUE);
608 done:
609 ALCcontext_DecRef(context);
613 AL_API ALvoid AL_APIENTRY alDeferUpdatesSOFT(void)
615 ALCcontext *context;
617 context = GetContextRef();
618 if(!context) return;
620 ALCcontext_DeferUpdates(context);
622 ALCcontext_DecRef(context);
625 AL_API ALvoid AL_APIENTRY alProcessUpdatesSOFT(void)
627 ALCcontext *context;
629 context = GetContextRef();
630 if(!context) return;
632 ALCcontext_ProcessUpdates(context);
634 ALCcontext_DecRef(context);