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
31 #include "alListener.h"
33 #include "alAuxEffectSlot.h"
35 #include "backends/base.h"
38 static const ALchar alVendor
[] = "OpenAL Community";
39 static const ALchar alVersion
[] = "1.1 ALSOFT "ALSOFT_VERSION
;
40 static const ALchar alRenderer
[] = "OpenAL Soft";
43 static const ALchar alNoError
[] = "No Error";
44 static const ALchar alErrInvalidName
[] = "Invalid Name";
45 static const ALchar alErrInvalidEnum
[] = "Invalid Enum";
46 static const ALchar alErrInvalidValue
[] = "Invalid Value";
47 static const ALchar alErrInvalidOp
[] = "Invalid Operation";
48 static const ALchar alErrOutOfMemory
[] = "Out of Memory";
50 AL_API ALvoid AL_APIENTRY
alEnable(ALenum capability
)
54 context
= GetContextRef();
57 WriteLock(&context
->PropLock
);
60 case AL_SOURCE_DISTANCE_MODEL
:
61 context
->SourceDistanceModel
= AL_TRUE
;
65 SET_ERROR_AND_GOTO(context
, AL_INVALID_ENUM
, done
);
67 if(!ATOMIC_LOAD(&context
->DeferUpdates
, almemory_order_acquire
))
68 UpdateListenerProps(context
);
71 WriteUnlock(&context
->PropLock
);
72 ALCcontext_DecRef(context
);
75 AL_API ALvoid AL_APIENTRY
alDisable(ALenum capability
)
79 context
= GetContextRef();
82 WriteLock(&context
->PropLock
);
85 case AL_SOURCE_DISTANCE_MODEL
:
86 context
->SourceDistanceModel
= AL_FALSE
;
90 SET_ERROR_AND_GOTO(context
, AL_INVALID_ENUM
, done
);
92 if(!ATOMIC_LOAD(&context
->DeferUpdates
, almemory_order_acquire
))
93 UpdateListenerProps(context
);
96 WriteUnlock(&context
->PropLock
);
97 ALCcontext_DecRef(context
);
100 AL_API ALboolean AL_APIENTRY
alIsEnabled(ALenum capability
)
103 ALboolean value
=AL_FALSE
;
105 context
= GetContextRef();
106 if(!context
) return AL_FALSE
;
110 case AL_SOURCE_DISTANCE_MODEL
:
111 value
= context
->SourceDistanceModel
;
115 SET_ERROR_AND_GOTO(context
, AL_INVALID_ENUM
, done
);
119 ALCcontext_DecRef(context
);
124 AL_API ALboolean AL_APIENTRY
alGetBoolean(ALenum pname
)
127 ALboolean value
=AL_FALSE
;
129 context
= GetContextRef();
130 if(!context
) return AL_FALSE
;
134 case AL_DOPPLER_FACTOR
:
135 if(context
->DopplerFactor
!= 0.0f
)
139 case AL_DOPPLER_VELOCITY
:
140 if(context
->DopplerVelocity
!= 0.0f
)
144 case AL_DISTANCE_MODEL
:
145 if(context
->DistanceModel
== AL_INVERSE_DISTANCE_CLAMPED
)
149 case AL_SPEED_OF_SOUND
:
150 if(context
->SpeedOfSound
!= 0.0f
)
154 case AL_DEFERRED_UPDATES_SOFT
:
155 if(ATOMIC_LOAD(&context
->DeferUpdates
, almemory_order_acquire
))
159 case AL_GAIN_LIMIT_SOFT
:
160 if(GAIN_MIX_MAX
/context
->GainBoost
!= 0.0f
)
165 SET_ERROR_AND_GOTO(context
, AL_INVALID_ENUM
, done
);
169 ALCcontext_DecRef(context
);
174 AL_API ALdouble AL_APIENTRY
alGetDouble(ALenum pname
)
177 ALdouble value
= 0.0;
179 context
= GetContextRef();
180 if(!context
) return 0.0;
184 case AL_DOPPLER_FACTOR
:
185 value
= (ALdouble
)context
->DopplerFactor
;
188 case AL_DOPPLER_VELOCITY
:
189 value
= (ALdouble
)context
->DopplerVelocity
;
192 case AL_DISTANCE_MODEL
:
193 value
= (ALdouble
)context
->DistanceModel
;
196 case AL_SPEED_OF_SOUND
:
197 value
= (ALdouble
)context
->SpeedOfSound
;
200 case AL_DEFERRED_UPDATES_SOFT
:
201 if(ATOMIC_LOAD(&context
->DeferUpdates
, almemory_order_acquire
))
202 value
= (ALdouble
)AL_TRUE
;
205 case AL_GAIN_LIMIT_SOFT
:
206 value
= (ALdouble
)GAIN_MIX_MAX
/context
->GainBoost
;
210 SET_ERROR_AND_GOTO(context
, AL_INVALID_ENUM
, done
);
214 ALCcontext_DecRef(context
);
219 AL_API ALfloat AL_APIENTRY
alGetFloat(ALenum pname
)
222 ALfloat value
= 0.0f
;
224 context
= GetContextRef();
225 if(!context
) return 0.0f
;
229 case AL_DOPPLER_FACTOR
:
230 value
= context
->DopplerFactor
;
233 case AL_DOPPLER_VELOCITY
:
234 value
= context
->DopplerVelocity
;
237 case AL_DISTANCE_MODEL
:
238 value
= (ALfloat
)context
->DistanceModel
;
241 case AL_SPEED_OF_SOUND
:
242 value
= context
->SpeedOfSound
;
245 case AL_DEFERRED_UPDATES_SOFT
:
246 if(ATOMIC_LOAD(&context
->DeferUpdates
, almemory_order_acquire
))
247 value
= (ALfloat
)AL_TRUE
;
250 case AL_GAIN_LIMIT_SOFT
:
251 value
= GAIN_MIX_MAX
/context
->GainBoost
;
255 SET_ERROR_AND_GOTO(context
, AL_INVALID_ENUM
, done
);
259 ALCcontext_DecRef(context
);
264 AL_API ALint AL_APIENTRY
alGetInteger(ALenum pname
)
269 context
= GetContextRef();
270 if(!context
) return 0;
274 case AL_DOPPLER_FACTOR
:
275 value
= (ALint
)context
->DopplerFactor
;
278 case AL_DOPPLER_VELOCITY
:
279 value
= (ALint
)context
->DopplerVelocity
;
282 case AL_DISTANCE_MODEL
:
283 value
= (ALint
)context
->DistanceModel
;
286 case AL_SPEED_OF_SOUND
:
287 value
= (ALint
)context
->SpeedOfSound
;
290 case AL_DEFERRED_UPDATES_SOFT
:
291 if(ATOMIC_LOAD(&context
->DeferUpdates
, almemory_order_acquire
))
292 value
= (ALint
)AL_TRUE
;
295 case AL_GAIN_LIMIT_SOFT
:
296 value
= (ALint
)(GAIN_MIX_MAX
/context
->GainBoost
);
300 SET_ERROR_AND_GOTO(context
, AL_INVALID_ENUM
, done
);
304 ALCcontext_DecRef(context
);
309 AL_API ALint64SOFT AL_APIENTRY
alGetInteger64SOFT(ALenum pname
)
312 ALint64SOFT value
= 0;
314 context
= GetContextRef();
315 if(!context
) return 0;
319 case AL_DOPPLER_FACTOR
:
320 value
= (ALint64SOFT
)context
->DopplerFactor
;
323 case AL_DOPPLER_VELOCITY
:
324 value
= (ALint64SOFT
)context
->DopplerVelocity
;
327 case AL_DISTANCE_MODEL
:
328 value
= (ALint64SOFT
)context
->DistanceModel
;
331 case AL_SPEED_OF_SOUND
:
332 value
= (ALint64SOFT
)context
->SpeedOfSound
;
335 case AL_DEFERRED_UPDATES_SOFT
:
336 if(ATOMIC_LOAD(&context
->DeferUpdates
, almemory_order_acquire
))
337 value
= (ALint64SOFT
)AL_TRUE
;
340 case AL_GAIN_LIMIT_SOFT
:
341 value
= (ALint64SOFT
)(GAIN_MIX_MAX
/context
->GainBoost
);
345 SET_ERROR_AND_GOTO(context
, AL_INVALID_ENUM
, done
);
349 ALCcontext_DecRef(context
);
354 AL_API ALvoid AL_APIENTRY
alGetBooleanv(ALenum pname
, ALboolean
*values
)
362 case AL_DOPPLER_FACTOR
:
363 case AL_DOPPLER_VELOCITY
:
364 case AL_DISTANCE_MODEL
:
365 case AL_SPEED_OF_SOUND
:
366 case AL_DEFERRED_UPDATES_SOFT
:
367 case AL_GAIN_LIMIT_SOFT
:
368 values
[0] = alGetBoolean(pname
);
373 context
= GetContextRef();
377 SET_ERROR_AND_GOTO(context
, AL_INVALID_VALUE
, done
);
381 SET_ERROR_AND_GOTO(context
, AL_INVALID_ENUM
, done
);
385 ALCcontext_DecRef(context
);
388 AL_API ALvoid AL_APIENTRY
alGetDoublev(ALenum pname
, ALdouble
*values
)
396 case AL_DOPPLER_FACTOR
:
397 case AL_DOPPLER_VELOCITY
:
398 case AL_DISTANCE_MODEL
:
399 case AL_SPEED_OF_SOUND
:
400 case AL_DEFERRED_UPDATES_SOFT
:
401 case AL_GAIN_LIMIT_SOFT
:
402 values
[0] = alGetDouble(pname
);
407 context
= GetContextRef();
411 SET_ERROR_AND_GOTO(context
, AL_INVALID_VALUE
, done
);
415 SET_ERROR_AND_GOTO(context
, AL_INVALID_ENUM
, done
);
419 ALCcontext_DecRef(context
);
422 AL_API ALvoid AL_APIENTRY
alGetFloatv(ALenum pname
, ALfloat
*values
)
430 case AL_DOPPLER_FACTOR
:
431 case AL_DOPPLER_VELOCITY
:
432 case AL_DISTANCE_MODEL
:
433 case AL_SPEED_OF_SOUND
:
434 case AL_DEFERRED_UPDATES_SOFT
:
435 case AL_GAIN_LIMIT_SOFT
:
436 values
[0] = alGetFloat(pname
);
441 context
= GetContextRef();
445 SET_ERROR_AND_GOTO(context
, AL_INVALID_VALUE
, done
);
449 SET_ERROR_AND_GOTO(context
, AL_INVALID_ENUM
, done
);
453 ALCcontext_DecRef(context
);
456 AL_API ALvoid AL_APIENTRY
alGetIntegerv(ALenum pname
, ALint
*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 case AL_GAIN_LIMIT_SOFT
:
470 values
[0] = alGetInteger(pname
);
475 context
= GetContextRef();
481 SET_ERROR_AND_GOTO(context
, AL_INVALID_ENUM
, done
);
485 ALCcontext_DecRef(context
);
488 AL_API
void AL_APIENTRY
alGetInteger64vSOFT(ALenum pname
, ALint64SOFT
*values
)
496 case AL_DOPPLER_FACTOR
:
497 case AL_DOPPLER_VELOCITY
:
498 case AL_DISTANCE_MODEL
:
499 case AL_SPEED_OF_SOUND
:
500 case AL_DEFERRED_UPDATES_SOFT
:
501 case AL_GAIN_LIMIT_SOFT
:
502 values
[0] = alGetInteger64SOFT(pname
);
507 context
= GetContextRef();
513 SET_ERROR_AND_GOTO(context
, AL_INVALID_ENUM
, done
);
517 ALCcontext_DecRef(context
);
520 AL_API
const ALchar
* AL_APIENTRY
alGetString(ALenum pname
)
522 const ALchar
*value
= NULL
;
525 context
= GetContextRef();
526 if(!context
) return NULL
;
543 value
= context
->ExtensionList
;
550 case AL_INVALID_NAME
:
551 value
= alErrInvalidName
;
554 case AL_INVALID_ENUM
:
555 value
= alErrInvalidEnum
;
558 case AL_INVALID_VALUE
:
559 value
= alErrInvalidValue
;
562 case AL_INVALID_OPERATION
:
563 value
= alErrInvalidOp
;
566 case AL_OUT_OF_MEMORY
:
567 value
= alErrOutOfMemory
;
571 SET_ERROR_AND_GOTO(context
, AL_INVALID_ENUM
, done
);
575 ALCcontext_DecRef(context
);
580 AL_API ALvoid AL_APIENTRY
alDopplerFactor(ALfloat value
)
584 context
= GetContextRef();
587 if(!(value
>= 0.0f
&& isfinite(value
)))
588 SET_ERROR_AND_GOTO(context
, AL_INVALID_VALUE
, done
);
590 WriteLock(&context
->PropLock
);
591 context
->DopplerFactor
= value
;
592 if(!ATOMIC_LOAD(&context
->DeferUpdates
, almemory_order_acquire
))
593 UpdateListenerProps(context
);
594 WriteUnlock(&context
->PropLock
);
597 ALCcontext_DecRef(context
);
600 AL_API ALvoid AL_APIENTRY
alDopplerVelocity(ALfloat value
)
604 context
= GetContextRef();
607 if(!(value
>= 0.0f
&& isfinite(value
)))
608 SET_ERROR_AND_GOTO(context
, AL_INVALID_VALUE
, done
);
610 WriteLock(&context
->PropLock
);
611 context
->DopplerVelocity
= value
;
612 if(!ATOMIC_LOAD(&context
->DeferUpdates
, almemory_order_acquire
))
613 UpdateListenerProps(context
);
614 WriteUnlock(&context
->PropLock
);
617 ALCcontext_DecRef(context
);
620 AL_API ALvoid AL_APIENTRY
alSpeedOfSound(ALfloat value
)
624 context
= GetContextRef();
627 if(!(value
> 0.0f
&& isfinite(value
)))
628 SET_ERROR_AND_GOTO(context
, AL_INVALID_VALUE
, done
);
630 WriteLock(&context
->PropLock
);
631 context
->SpeedOfSound
= value
;
632 if(!ATOMIC_LOAD(&context
->DeferUpdates
, almemory_order_acquire
))
633 UpdateListenerProps(context
);
634 WriteUnlock(&context
->PropLock
);
637 ALCcontext_DecRef(context
);
640 AL_API ALvoid AL_APIENTRY
alDistanceModel(ALenum value
)
644 context
= GetContextRef();
647 if(!(value
== AL_INVERSE_DISTANCE
|| value
== AL_INVERSE_DISTANCE_CLAMPED
||
648 value
== AL_LINEAR_DISTANCE
|| value
== AL_LINEAR_DISTANCE_CLAMPED
||
649 value
== AL_EXPONENT_DISTANCE
|| value
== AL_EXPONENT_DISTANCE_CLAMPED
||
651 SET_ERROR_AND_GOTO(context
, AL_INVALID_VALUE
, done
);
653 WriteLock(&context
->PropLock
);
654 context
->DistanceModel
= value
;
655 if(!context
->SourceDistanceModel
)
657 if(!ATOMIC_LOAD(&context
->DeferUpdates
, almemory_order_acquire
))
658 UpdateListenerProps(context
);
660 WriteUnlock(&context
->PropLock
);
663 ALCcontext_DecRef(context
);
667 AL_API ALvoid AL_APIENTRY
alDeferUpdatesSOFT(void)
671 context
= GetContextRef();
674 ALCcontext_DeferUpdates(context
);
676 ALCcontext_DecRef(context
);
679 AL_API ALvoid AL_APIENTRY
alProcessUpdatesSOFT(void)
683 context
= GetContextRef();
686 ALCcontext_ProcessUpdates(context
);
688 ALCcontext_DecRef(context
);