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();
57 case AL_SOURCE_DISTANCE_MODEL
:
58 context
->SourceDistanceModel
= AL_TRUE
;
62 SET_ERROR_AND_GOTO(context
, AL_INVALID_ENUM
, done
);
64 /* HACK: Force sources to update by doing a listener update */
65 ReadLock(&context
->PropLock
);
66 UpdateListenerProps(context
);
67 ReadUnlock(&context
->PropLock
);
70 ALCcontext_DecRef(context
);
73 AL_API ALvoid AL_APIENTRY
alDisable(ALenum capability
)
77 context
= GetContextRef();
82 case AL_SOURCE_DISTANCE_MODEL
:
83 context
->SourceDistanceModel
= AL_FALSE
;
87 SET_ERROR_AND_GOTO(context
, AL_INVALID_ENUM
, done
);
89 /* HACK: Force sources to update by doing a listener update */
90 ReadLock(&context
->PropLock
);
91 UpdateListenerProps(context
);
92 ReadUnlock(&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
= context
->DeferUpdates
;
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
)context
->DeferUpdates
;
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
)context
->DeferUpdates
;
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
)context
->DeferUpdates
;
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
)context
->DeferUpdates
;
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 UpdateListenerProps(context
);
560 WriteUnlock(&context
->PropLock
);
563 ALCcontext_DecRef(context
);
566 AL_API ALvoid AL_APIENTRY
alDopplerVelocity(ALfloat value
)
570 context
= GetContextRef();
573 if(!(value
>= 0.0f
&& isfinite(value
)))
574 SET_ERROR_AND_GOTO(context
, AL_INVALID_VALUE
, done
);
576 WriteLock(&context
->PropLock
);
577 context
->DopplerVelocity
= value
;
578 UpdateListenerProps(context
);
579 WriteUnlock(&context
->PropLock
);
582 ALCcontext_DecRef(context
);
585 AL_API ALvoid AL_APIENTRY
alSpeedOfSound(ALfloat value
)
589 context
= GetContextRef();
592 if(!(value
> 0.0f
&& isfinite(value
)))
593 SET_ERROR_AND_GOTO(context
, AL_INVALID_VALUE
, done
);
595 WriteLock(&context
->PropLock
);
596 context
->SpeedOfSound
= value
;
597 UpdateListenerProps(context
);
598 WriteUnlock(&context
->PropLock
);
601 ALCcontext_DecRef(context
);
604 AL_API ALvoid AL_APIENTRY
alDistanceModel(ALenum value
)
608 context
= GetContextRef();
611 if(!(value
== AL_INVERSE_DISTANCE
|| value
== AL_INVERSE_DISTANCE_CLAMPED
||
612 value
== AL_LINEAR_DISTANCE
|| value
== AL_LINEAR_DISTANCE_CLAMPED
||
613 value
== AL_EXPONENT_DISTANCE
|| value
== AL_EXPONENT_DISTANCE_CLAMPED
||
615 SET_ERROR_AND_GOTO(context
, AL_INVALID_VALUE
, done
);
617 WriteLock(&context
->PropLock
);
618 context
->DistanceModel
= value
;
619 if(!context
->SourceDistanceModel
)
620 UpdateListenerProps(context
);
621 WriteUnlock(&context
->PropLock
);
624 ALCcontext_DecRef(context
);
628 AL_API ALvoid AL_APIENTRY
alDeferUpdatesSOFT(void)
632 context
= GetContextRef();
635 ALCcontext_DeferUpdates(context
);
637 ALCcontext_DecRef(context
);
640 AL_API ALvoid AL_APIENTRY
alProcessUpdatesSOFT(void)
644 context
= GetContextRef();
647 ALCcontext_ProcessUpdates(context
);
649 ALCcontext_DecRef(context
);