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
29 #include "alAuxEffectSlot.h"
32 static const ALchar alVendor
[] = "OpenAL Community";
33 static const ALchar alVersion
[] = "1.1 ALSOFT "ALSOFT_VERSION
;
34 static const ALchar alRenderer
[] = "OpenAL Soft";
37 static const ALchar alNoError
[] = "No Error";
38 static const ALchar alErrInvalidName
[] = "Invalid Name";
39 static const ALchar alErrInvalidEnum
[] = "Invalid Enum";
40 static const ALchar alErrInvalidValue
[] = "Invalid Value";
41 static const ALchar alErrInvalidOp
[] = "Invalid Operation";
42 static const ALchar alErrOutOfMemory
[] = "Out of Memory";
44 AL_API ALvoid AL_APIENTRY
alEnable(ALenum capability
)
48 Context
= GetContextRef();
55 case AL_SOURCE_DISTANCE_MODEL
:
56 Context
->SourceDistanceModel
= AL_TRUE
;
57 Context
->UpdateSources
= AL_TRUE
;
61 al_throwerr(Context
, AL_INVALID_ENUM
);
66 ALCcontext_DecRef(Context
);
69 AL_API ALvoid AL_APIENTRY
alDisable(ALenum capability
)
73 Context
= GetContextRef();
80 case AL_SOURCE_DISTANCE_MODEL
:
81 Context
->SourceDistanceModel
= AL_FALSE
;
82 Context
->UpdateSources
= AL_TRUE
;
86 al_throwerr(Context
, AL_INVALID_ENUM
);
91 ALCcontext_DecRef(Context
);
94 AL_API ALboolean AL_APIENTRY
alIsEnabled(ALenum capability
)
97 ALboolean value
=AL_FALSE
;
99 Context
= GetContextRef();
100 if(!Context
) return AL_FALSE
;
106 case AL_SOURCE_DISTANCE_MODEL
:
107 value
= Context
->SourceDistanceModel
;
111 al_throwerr(Context
, AL_INVALID_ENUM
);
116 ALCcontext_DecRef(Context
);
121 AL_API ALboolean AL_APIENTRY
alGetBoolean(ALenum pname
)
124 ALboolean value
=AL_FALSE
;
126 Context
= GetContextRef();
127 if(!Context
) return AL_FALSE
;
133 case AL_DOPPLER_FACTOR
:
134 if(Context
->DopplerFactor
!= 0.0f
)
138 case AL_DOPPLER_VELOCITY
:
139 if(Context
->DopplerVelocity
!= 0.0f
)
143 case AL_DISTANCE_MODEL
:
144 if(Context
->DistanceModel
== AL_INVERSE_DISTANCE_CLAMPED
)
148 case AL_SPEED_OF_SOUND
:
149 if(Context
->SpeedOfSound
!= 0.0f
)
153 case AL_DEFERRED_UPDATES_SOFT
:
154 value
= Context
->DeferUpdates
;
158 al_throwerr(Context
, AL_INVALID_ENUM
);
163 ALCcontext_DecRef(Context
);
168 AL_API ALdouble AL_APIENTRY
alGetDouble(ALenum pname
)
171 ALdouble value
= 0.0;
173 Context
= GetContextRef();
174 if(!Context
) return 0.0;
180 case AL_DOPPLER_FACTOR
:
181 value
= (ALdouble
)Context
->DopplerFactor
;
184 case AL_DOPPLER_VELOCITY
:
185 value
= (ALdouble
)Context
->DopplerVelocity
;
188 case AL_DISTANCE_MODEL
:
189 value
= (ALdouble
)Context
->DistanceModel
;
192 case AL_SPEED_OF_SOUND
:
193 value
= (ALdouble
)Context
->SpeedOfSound
;
196 case AL_DEFERRED_UPDATES_SOFT
:
197 value
= (ALdouble
)Context
->DeferUpdates
;
201 al_throwerr(Context
, AL_INVALID_ENUM
);
206 ALCcontext_DecRef(Context
);
211 AL_API ALfloat AL_APIENTRY
alGetFloat(ALenum pname
)
214 ALfloat value
= 0.0f
;
216 Context
= GetContextRef();
217 if(!Context
) return 0.0f
;
223 case AL_DOPPLER_FACTOR
:
224 value
= Context
->DopplerFactor
;
227 case AL_DOPPLER_VELOCITY
:
228 value
= Context
->DopplerVelocity
;
231 case AL_DISTANCE_MODEL
:
232 value
= (ALfloat
)Context
->DistanceModel
;
235 case AL_SPEED_OF_SOUND
:
236 value
= Context
->SpeedOfSound
;
239 case AL_DEFERRED_UPDATES_SOFT
:
240 value
= (ALfloat
)Context
->DeferUpdates
;
244 al_throwerr(Context
, AL_INVALID_ENUM
);
249 ALCcontext_DecRef(Context
);
254 AL_API ALint AL_APIENTRY
alGetInteger(ALenum pname
)
259 Context
= GetContextRef();
260 if(!Context
) return 0;
266 case AL_DOPPLER_FACTOR
:
267 value
= (ALint
)Context
->DopplerFactor
;
270 case AL_DOPPLER_VELOCITY
:
271 value
= (ALint
)Context
->DopplerVelocity
;
274 case AL_DISTANCE_MODEL
:
275 value
= (ALint
)Context
->DistanceModel
;
278 case AL_SPEED_OF_SOUND
:
279 value
= (ALint
)Context
->SpeedOfSound
;
282 case AL_DEFERRED_UPDATES_SOFT
:
283 value
= (ALint
)Context
->DeferUpdates
;
287 al_throwerr(Context
, AL_INVALID_ENUM
);
292 ALCcontext_DecRef(Context
);
297 AL_API ALvoid AL_APIENTRY
alGetBooleanv(ALenum pname
, ALboolean
*values
)
305 case AL_DOPPLER_FACTOR
:
306 case AL_DOPPLER_VELOCITY
:
307 case AL_DISTANCE_MODEL
:
308 case AL_SPEED_OF_SOUND
:
309 case AL_DEFERRED_UPDATES_SOFT
:
310 values
[0] = alGetBoolean(pname
);
315 Context
= GetContextRef();
320 CHECK_VALUE(Context
, values
);
324 al_throwerr(Context
, AL_INVALID_ENUM
);
329 ALCcontext_DecRef(Context
);
332 AL_API ALvoid AL_APIENTRY
alGetDoublev(ALenum pname
, ALdouble
*values
)
340 case AL_DOPPLER_FACTOR
:
341 case AL_DOPPLER_VELOCITY
:
342 case AL_DISTANCE_MODEL
:
343 case AL_SPEED_OF_SOUND
:
344 case AL_DEFERRED_UPDATES_SOFT
:
345 values
[0] = alGetDouble(pname
);
350 Context
= GetContextRef();
355 CHECK_VALUE(Context
, values
);
359 al_throwerr(Context
, AL_INVALID_ENUM
);
364 ALCcontext_DecRef(Context
);
367 AL_API ALvoid AL_APIENTRY
alGetFloatv(ALenum pname
, ALfloat
*values
)
375 case AL_DOPPLER_FACTOR
:
376 case AL_DOPPLER_VELOCITY
:
377 case AL_DISTANCE_MODEL
:
378 case AL_SPEED_OF_SOUND
:
379 case AL_DEFERRED_UPDATES_SOFT
:
380 values
[0] = alGetFloat(pname
);
385 Context
= GetContextRef();
390 CHECK_VALUE(Context
, values
);
394 al_throwerr(Context
, AL_INVALID_ENUM
);
399 ALCcontext_DecRef(Context
);
402 AL_API ALvoid AL_APIENTRY
alGetIntegerv(ALenum pname
, ALint
*values
)
410 case AL_DOPPLER_FACTOR
:
411 case AL_DOPPLER_VELOCITY
:
412 case AL_DISTANCE_MODEL
:
413 case AL_SPEED_OF_SOUND
:
414 case AL_DEFERRED_UPDATES_SOFT
:
415 values
[0] = alGetInteger(pname
);
420 Context
= GetContextRef();
425 CHECK_VALUE(Context
, values
);
429 al_throwerr(Context
, AL_INVALID_ENUM
);
434 ALCcontext_DecRef(Context
);
437 AL_API
const ALchar
* AL_APIENTRY
alGetString(ALenum pname
)
442 Context
= GetContextRef();
443 if(!Context
) return NULL
;
462 value
= Context
->ExtensionList
;
469 case AL_INVALID_NAME
:
470 value
= alErrInvalidName
;
473 case AL_INVALID_ENUM
:
474 value
= alErrInvalidEnum
;
477 case AL_INVALID_VALUE
:
478 value
= alErrInvalidValue
;
481 case AL_INVALID_OPERATION
:
482 value
= alErrInvalidOp
;
485 case AL_OUT_OF_MEMORY
:
486 value
= alErrOutOfMemory
;
490 al_throwerr(Context
, AL_INVALID_ENUM
);
499 ALCcontext_DecRef(Context
);
504 AL_API ALvoid AL_APIENTRY
alDopplerFactor(ALfloat value
)
508 Context
= GetContextRef();
513 CHECK_VALUE(Context
, value
>= 0.0f
&& isfinite(value
));
515 Context
->DopplerFactor
= value
;
516 Context
->UpdateSources
= AL_TRUE
;
520 ALCcontext_DecRef(Context
);
523 AL_API ALvoid AL_APIENTRY
alDopplerVelocity(ALfloat value
)
527 Context
= GetContextRef();
532 CHECK_VALUE(Context
, value
>= 0.0f
&& isfinite(value
));
534 Context
->DopplerVelocity
= value
;
535 Context
->UpdateSources
= AL_TRUE
;
539 ALCcontext_DecRef(Context
);
542 AL_API ALvoid AL_APIENTRY
alSpeedOfSound(ALfloat value
)
546 Context
= GetContextRef();
551 CHECK_VALUE(Context
, value
> 0.0f
&& isfinite(value
));
553 Context
->SpeedOfSound
= value
;
554 Context
->UpdateSources
= AL_TRUE
;
558 ALCcontext_DecRef(Context
);
561 AL_API ALvoid AL_APIENTRY
alDistanceModel(ALenum value
)
565 Context
= GetContextRef();
570 CHECK_VALUE(Context
, value
== AL_NONE
||
571 value
== AL_INVERSE_DISTANCE
||
572 value
== AL_INVERSE_DISTANCE_CLAMPED
||
573 value
== AL_LINEAR_DISTANCE
||
574 value
== AL_LINEAR_DISTANCE_CLAMPED
||
575 value
== AL_EXPONENT_DISTANCE
||
576 value
== AL_EXPONENT_DISTANCE_CLAMPED
);
578 Context
->DistanceModel
= value
;
579 if(!Context
->SourceDistanceModel
)
580 Context
->UpdateSources
= AL_TRUE
;
584 ALCcontext_DecRef(Context
);
588 AL_API ALvoid AL_APIENTRY
alDeferUpdatesSOFT(void)
592 Context
= GetContextRef();
595 if(!Context
->DeferUpdates
)
597 ALboolean UpdateSources
;
598 ALsource
**src
, **src_end
;
599 ALeffectslot
**slot
, **slot_end
;
602 fpuState
= SetMixerFPUMode();
604 LockContext(Context
);
605 Context
->DeferUpdates
= AL_TRUE
;
607 /* Make sure all pending updates are performed */
608 UpdateSources
= ExchangeInt(&Context
->UpdateSources
, AL_FALSE
);
610 src
= Context
->ActiveSources
;
611 src_end
= src
+ Context
->ActiveSourceCount
;
612 while(src
!= src_end
)
614 if((*src
)->state
!= AL_PLAYING
)
616 Context
->ActiveSourceCount
--;
621 if(ExchangeInt(&(*src
)->NeedsUpdate
, AL_FALSE
) || UpdateSources
)
622 ALsource_Update(*src
, Context
);
627 slot
= Context
->ActiveEffectSlots
;
628 slot_end
= slot
+ Context
->ActiveEffectSlotCount
;
629 while(slot
!= slot_end
)
631 if(ExchangeInt(&(*slot
)->NeedsUpdate
, AL_FALSE
))
632 ALeffectState_Update((*slot
)->EffectState
, Context
->Device
, *slot
);
636 UnlockContext(Context
);
637 RestoreFPUMode(fpuState
);
640 ALCcontext_DecRef(Context
);
643 AL_API ALvoid AL_APIENTRY
alProcessUpdatesSOFT(void)
647 Context
= GetContextRef();
650 if(ExchangeInt(&Context
->DeferUpdates
, AL_FALSE
))
654 LockContext(Context
);
655 LockUIntMapRead(&Context
->SourceMap
);
656 for(pos
= 0;pos
< Context
->SourceMap
.size
;pos
++)
658 ALsource
*Source
= Context
->SourceMap
.array
[pos
].value
;
661 if((Source
->state
== AL_PLAYING
|| Source
->state
== AL_PAUSED
) &&
662 Source
->Offset
>= 0.0)
665 new_state
= ExchangeInt(&Source
->new_state
, AL_NONE
);
667 SetSourceState(Source
, Context
, new_state
);
669 UnlockUIntMapRead(&Context
->SourceMap
);
670 UnlockContext(Context
);
673 ALCcontext_DecRef(Context
);