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
29 #include "alListener.h"
31 #include "alAuxEffectSlot.h"
33 #include "backends/base.h"
36 static const ALchar alVendor
[] = "OpenAL Community";
37 static const ALchar alVersion
[] = "1.1 ALSOFT "ALSOFT_VERSION
;
38 static const ALchar alRenderer
[] = "OpenAL Soft";
41 static const ALchar alNoError
[] = "No Error";
42 static const ALchar alErrInvalidName
[] = "Invalid Name";
43 static const ALchar alErrInvalidEnum
[] = "Invalid Enum";
44 static const ALchar alErrInvalidValue
[] = "Invalid Value";
45 static const ALchar alErrInvalidOp
[] = "Invalid Operation";
46 static const ALchar alErrOutOfMemory
[] = "Out of Memory";
48 AL_API ALvoid AL_APIENTRY
alEnable(ALenum capability
)
52 context
= GetContextRef();
55 WriteLock(&context
->PropLock
);
58 case AL_SOURCE_DISTANCE_MODEL
:
59 context
->SourceDistanceModel
= AL_TRUE
;
63 SET_ERROR_AND_GOTO(context
, AL_INVALID_ENUM
, done
);
65 if(!ATOMIC_LOAD(&context
->DeferUpdates
, almemory_order_acquire
))
66 UpdateAllSourceProps(context
);
69 WriteUnlock(&context
->PropLock
);
70 ALCcontext_DecRef(context
);
73 AL_API ALvoid AL_APIENTRY
alDisable(ALenum capability
)
77 context
= GetContextRef();
80 WriteLock(&context
->PropLock
);
83 case AL_SOURCE_DISTANCE_MODEL
:
84 context
->SourceDistanceModel
= AL_FALSE
;
88 SET_ERROR_AND_GOTO(context
, AL_INVALID_ENUM
, done
);
90 if(!ATOMIC_LOAD(&context
->DeferUpdates
, almemory_order_acquire
))
91 UpdateAllSourceProps(context
);
94 WriteUnlock(&context
->PropLock
);
95 ALCcontext_DecRef(context
);
98 AL_API ALboolean AL_APIENTRY
alIsEnabled(ALenum capability
)
101 ALboolean value
=AL_FALSE
;
103 context
= GetContextRef();
104 if(!context
) return AL_FALSE
;
108 case AL_SOURCE_DISTANCE_MODEL
:
109 value
= context
->SourceDistanceModel
;
113 SET_ERROR_AND_GOTO(context
, AL_INVALID_ENUM
, done
);
117 ALCcontext_DecRef(context
);
122 AL_API ALboolean AL_APIENTRY
alGetBoolean(ALenum pname
)
125 ALboolean value
=AL_FALSE
;
127 context
= GetContextRef();
128 if(!context
) return AL_FALSE
;
132 case AL_DOPPLER_FACTOR
:
133 if(context
->DopplerFactor
!= 0.0f
)
137 case AL_DOPPLER_VELOCITY
:
138 if(context
->DopplerVelocity
!= 0.0f
)
142 case AL_DISTANCE_MODEL
:
143 if(context
->DistanceModel
== AL_INVERSE_DISTANCE_CLAMPED
)
147 case AL_SPEED_OF_SOUND
:
148 if(context
->SpeedOfSound
!= 0.0f
)
152 case AL_DEFERRED_UPDATES_SOFT
:
153 value
= ATOMIC_LOAD(&context
->DeferUpdates
, almemory_order_acquire
);
157 SET_ERROR_AND_GOTO(context
, AL_INVALID_ENUM
, done
);
161 ALCcontext_DecRef(context
);
166 AL_API ALdouble AL_APIENTRY
alGetDouble(ALenum pname
)
169 ALdouble value
= 0.0;
171 context
= GetContextRef();
172 if(!context
) return 0.0;
176 case AL_DOPPLER_FACTOR
:
177 value
= (ALdouble
)context
->DopplerFactor
;
180 case AL_DOPPLER_VELOCITY
:
181 value
= (ALdouble
)context
->DopplerVelocity
;
184 case AL_DISTANCE_MODEL
:
185 value
= (ALdouble
)context
->DistanceModel
;
188 case AL_SPEED_OF_SOUND
:
189 value
= (ALdouble
)context
->SpeedOfSound
;
192 case AL_DEFERRED_UPDATES_SOFT
:
193 value
= (ALdouble
)ATOMIC_LOAD(&context
->DeferUpdates
, almemory_order_acquire
);
197 SET_ERROR_AND_GOTO(context
, AL_INVALID_ENUM
, done
);
201 ALCcontext_DecRef(context
);
206 AL_API ALfloat AL_APIENTRY
alGetFloat(ALenum pname
)
209 ALfloat value
= 0.0f
;
211 context
= GetContextRef();
212 if(!context
) return 0.0f
;
216 case AL_DOPPLER_FACTOR
:
217 value
= context
->DopplerFactor
;
220 case AL_DOPPLER_VELOCITY
:
221 value
= context
->DopplerVelocity
;
224 case AL_DISTANCE_MODEL
:
225 value
= (ALfloat
)context
->DistanceModel
;
228 case AL_SPEED_OF_SOUND
:
229 value
= context
->SpeedOfSound
;
232 case AL_DEFERRED_UPDATES_SOFT
:
233 value
= (ALfloat
)ATOMIC_LOAD(&context
->DeferUpdates
, almemory_order_acquire
);
237 SET_ERROR_AND_GOTO(context
, AL_INVALID_ENUM
, done
);
241 ALCcontext_DecRef(context
);
246 AL_API ALint AL_APIENTRY
alGetInteger(ALenum pname
)
251 context
= GetContextRef();
252 if(!context
) return 0;
256 case AL_DOPPLER_FACTOR
:
257 value
= (ALint
)context
->DopplerFactor
;
260 case AL_DOPPLER_VELOCITY
:
261 value
= (ALint
)context
->DopplerVelocity
;
264 case AL_DISTANCE_MODEL
:
265 value
= (ALint
)context
->DistanceModel
;
268 case AL_SPEED_OF_SOUND
:
269 value
= (ALint
)context
->SpeedOfSound
;
272 case AL_DEFERRED_UPDATES_SOFT
:
273 value
= (ALint
)ATOMIC_LOAD(&context
->DeferUpdates
, almemory_order_acquire
);
277 SET_ERROR_AND_GOTO(context
, AL_INVALID_ENUM
, done
);
281 ALCcontext_DecRef(context
);
286 AL_API ALint64SOFT AL_APIENTRY
alGetInteger64SOFT(ALenum pname
)
289 ALint64SOFT value
= 0;
291 context
= GetContextRef();
292 if(!context
) return 0;
296 case AL_DOPPLER_FACTOR
:
297 value
= (ALint64SOFT
)context
->DopplerFactor
;
300 case AL_DOPPLER_VELOCITY
:
301 value
= (ALint64SOFT
)context
->DopplerVelocity
;
304 case AL_DISTANCE_MODEL
:
305 value
= (ALint64SOFT
)context
->DistanceModel
;
308 case AL_SPEED_OF_SOUND
:
309 value
= (ALint64SOFT
)context
->SpeedOfSound
;
312 case AL_DEFERRED_UPDATES_SOFT
:
313 value
= (ALint64SOFT
)ATOMIC_LOAD(&context
->DeferUpdates
, almemory_order_acquire
);
317 SET_ERROR_AND_GOTO(context
, AL_INVALID_ENUM
, done
);
321 ALCcontext_DecRef(context
);
326 AL_API ALvoid AL_APIENTRY
alGetBooleanv(ALenum pname
, ALboolean
*values
)
334 case AL_DOPPLER_FACTOR
:
335 case AL_DOPPLER_VELOCITY
:
336 case AL_DISTANCE_MODEL
:
337 case AL_SPEED_OF_SOUND
:
338 case AL_DEFERRED_UPDATES_SOFT
:
339 values
[0] = alGetBoolean(pname
);
344 context
= GetContextRef();
348 SET_ERROR_AND_GOTO(context
, AL_INVALID_VALUE
, done
);
352 SET_ERROR_AND_GOTO(context
, AL_INVALID_ENUM
, done
);
356 ALCcontext_DecRef(context
);
359 AL_API ALvoid AL_APIENTRY
alGetDoublev(ALenum pname
, ALdouble
*values
)
367 case AL_DOPPLER_FACTOR
:
368 case AL_DOPPLER_VELOCITY
:
369 case AL_DISTANCE_MODEL
:
370 case AL_SPEED_OF_SOUND
:
371 case AL_DEFERRED_UPDATES_SOFT
:
372 values
[0] = alGetDouble(pname
);
377 context
= GetContextRef();
381 SET_ERROR_AND_GOTO(context
, AL_INVALID_VALUE
, done
);
385 SET_ERROR_AND_GOTO(context
, AL_INVALID_ENUM
, done
);
389 ALCcontext_DecRef(context
);
392 AL_API ALvoid AL_APIENTRY
alGetFloatv(ALenum pname
, ALfloat
*values
)
400 case AL_DOPPLER_FACTOR
:
401 case AL_DOPPLER_VELOCITY
:
402 case AL_DISTANCE_MODEL
:
403 case AL_SPEED_OF_SOUND
:
404 case AL_DEFERRED_UPDATES_SOFT
:
405 values
[0] = alGetFloat(pname
);
410 context
= GetContextRef();
414 SET_ERROR_AND_GOTO(context
, AL_INVALID_VALUE
, done
);
418 SET_ERROR_AND_GOTO(context
, AL_INVALID_ENUM
, done
);
422 ALCcontext_DecRef(context
);
425 AL_API ALvoid AL_APIENTRY
alGetIntegerv(ALenum pname
, ALint
*values
)
433 case AL_DOPPLER_FACTOR
:
434 case AL_DOPPLER_VELOCITY
:
435 case AL_DISTANCE_MODEL
:
436 case AL_SPEED_OF_SOUND
:
437 case AL_DEFERRED_UPDATES_SOFT
:
438 values
[0] = alGetInteger(pname
);
443 context
= GetContextRef();
449 SET_ERROR_AND_GOTO(context
, AL_INVALID_ENUM
, done
);
453 ALCcontext_DecRef(context
);
456 AL_API
void AL_APIENTRY
alGetInteger64vSOFT(ALenum pname
, ALint64SOFT
*values
)
464 case AL_DOPPLER_FACTOR
:
465 case AL_DOPPLER_VELOCITY
:
466 case AL_DISTANCE_MODEL
:
467 case AL_SPEED_OF_SOUND
:
468 case AL_DEFERRED_UPDATES_SOFT
:
469 values
[0] = alGetInteger64SOFT(pname
);
474 context
= GetContextRef();
480 SET_ERROR_AND_GOTO(context
, AL_INVALID_ENUM
, done
);
484 ALCcontext_DecRef(context
);
487 AL_API
const ALchar
* AL_APIENTRY
alGetString(ALenum pname
)
489 const ALchar
*value
= NULL
;
492 context
= GetContextRef();
493 if(!context
) return NULL
;
510 value
= context
->ExtensionList
;
517 case AL_INVALID_NAME
:
518 value
= alErrInvalidName
;
521 case AL_INVALID_ENUM
:
522 value
= alErrInvalidEnum
;
525 case AL_INVALID_VALUE
:
526 value
= alErrInvalidValue
;
529 case AL_INVALID_OPERATION
:
530 value
= alErrInvalidOp
;
533 case AL_OUT_OF_MEMORY
:
534 value
= alErrOutOfMemory
;
538 SET_ERROR_AND_GOTO(context
, AL_INVALID_ENUM
, done
);
542 ALCcontext_DecRef(context
);
547 AL_API ALvoid AL_APIENTRY
alDopplerFactor(ALfloat value
)
551 context
= GetContextRef();
554 if(!(value
>= 0.0f
&& isfinite(value
)))
555 SET_ERROR_AND_GOTO(context
, AL_INVALID_VALUE
, done
);
557 WriteLock(&context
->PropLock
);
558 context
->DopplerFactor
= value
;
559 if(!ATOMIC_LOAD(&context
->DeferUpdates
, almemory_order_acquire
))
561 UpdateListenerProps(context
);
562 UpdateAllSourceProps(context
);
564 WriteUnlock(&context
->PropLock
);
567 ALCcontext_DecRef(context
);
570 AL_API ALvoid AL_APIENTRY
alDopplerVelocity(ALfloat value
)
574 context
= GetContextRef();
577 if(!(value
>= 0.0f
&& isfinite(value
)))
578 SET_ERROR_AND_GOTO(context
, AL_INVALID_VALUE
, done
);
580 WriteLock(&context
->PropLock
);
581 context
->DopplerVelocity
= value
;
582 if(!ATOMIC_LOAD(&context
->DeferUpdates
, almemory_order_acquire
))
584 UpdateListenerProps(context
);
585 UpdateAllSourceProps(context
);
587 WriteUnlock(&context
->PropLock
);
590 ALCcontext_DecRef(context
);
593 AL_API ALvoid AL_APIENTRY
alSpeedOfSound(ALfloat value
)
597 context
= GetContextRef();
600 if(!(value
> 0.0f
&& isfinite(value
)))
601 SET_ERROR_AND_GOTO(context
, AL_INVALID_VALUE
, done
);
603 WriteLock(&context
->PropLock
);
604 context
->SpeedOfSound
= value
;
605 if(!ATOMIC_LOAD(&context
->DeferUpdates
, almemory_order_acquire
))
607 UpdateListenerProps(context
);
608 UpdateAllSourceProps(context
);
610 WriteUnlock(&context
->PropLock
);
613 ALCcontext_DecRef(context
);
616 AL_API ALvoid AL_APIENTRY
alDistanceModel(ALenum value
)
620 context
= GetContextRef();
623 if(!(value
== AL_INVERSE_DISTANCE
|| value
== AL_INVERSE_DISTANCE_CLAMPED
||
624 value
== AL_LINEAR_DISTANCE
|| value
== AL_LINEAR_DISTANCE_CLAMPED
||
625 value
== AL_EXPONENT_DISTANCE
|| value
== AL_EXPONENT_DISTANCE_CLAMPED
||
627 SET_ERROR_AND_GOTO(context
, AL_INVALID_VALUE
, done
);
629 WriteLock(&context
->PropLock
);
630 context
->DistanceModel
= value
;
631 if(!context
->SourceDistanceModel
)
633 if(!ATOMIC_LOAD(&context
->DeferUpdates
, almemory_order_acquire
))
634 UpdateAllSourceProps(context
);
636 WriteUnlock(&context
->PropLock
);
639 ALCcontext_DecRef(context
);
643 AL_API ALvoid AL_APIENTRY
alDeferUpdatesSOFT(void)
647 context
= GetContextRef();
650 ALCcontext_DeferUpdates(context
);
652 ALCcontext_DecRef(context
);
655 AL_API ALvoid AL_APIENTRY
alProcessUpdatesSOFT(void)
659 context
= GetContextRef();
662 ALCcontext_ProcessUpdates(context
);
664 ALCcontext_DecRef(context
);