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
30 #include "alDatabuffer.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
)
47 ALboolean updateSources
= AL_FALSE
;
49 Context
= GetContextSuspended();
54 case AL_SOURCE_DISTANCE_MODEL
:
55 Context
->SourceDistanceModel
= AL_TRUE
;
56 updateSources
= AL_TRUE
;
60 alSetError(Context
, AL_INVALID_ENUM
);
67 for(pos
= 0;pos
< Context
->SourceMap
.size
;pos
++)
69 ALsource
*source
= Context
->SourceMap
.array
[pos
].value
;
70 source
->NeedsUpdate
= AL_TRUE
;
74 ProcessContext(Context
);
77 AL_API ALvoid AL_APIENTRY
alDisable(ALenum capability
)
80 ALboolean updateSources
= AL_FALSE
;
82 Context
= GetContextSuspended();
87 case AL_SOURCE_DISTANCE_MODEL
:
88 Context
->SourceDistanceModel
= AL_FALSE
;
89 updateSources
= AL_TRUE
;
93 alSetError(Context
, AL_INVALID_ENUM
);
100 for(pos
= 0;pos
< Context
->SourceMap
.size
;pos
++)
102 ALsource
*source
= Context
->SourceMap
.array
[pos
].value
;
103 source
->NeedsUpdate
= AL_TRUE
;
107 ProcessContext(Context
);
110 AL_API ALboolean AL_APIENTRY
alIsEnabled(ALenum capability
)
113 ALboolean value
=AL_FALSE
;
115 Context
= GetContextSuspended();
116 if(!Context
) return AL_FALSE
;
120 case AL_SOURCE_DISTANCE_MODEL
:
121 value
= Context
->SourceDistanceModel
;
125 alSetError(Context
, AL_INVALID_ENUM
);
129 ProcessContext(Context
);
134 AL_API ALboolean AL_APIENTRY
alGetBoolean(ALenum pname
)
137 ALboolean value
=AL_FALSE
;
139 Context
= GetContextSuspended();
140 if(!Context
) return AL_FALSE
;
144 case AL_DOPPLER_FACTOR
:
145 if(Context
->DopplerFactor
!= 0.0f
)
149 case AL_DOPPLER_VELOCITY
:
150 if(Context
->DopplerVelocity
!= 0.0f
)
154 case AL_DISTANCE_MODEL
:
155 if(Context
->DistanceModel
== AL_INVERSE_DISTANCE_CLAMPED
)
159 case AL_SPEED_OF_SOUND
:
160 if(Context
->flSpeedOfSound
!= 0.0f
)
165 alSetError(Context
, AL_INVALID_ENUM
);
169 ProcessContext(Context
);
174 AL_API ALdouble AL_APIENTRY
alGetDouble(ALenum pname
)
177 ALdouble value
= 0.0;
179 Context
= GetContextSuspended();
180 if(!Context
) return 0.0;
184 case AL_DOPPLER_FACTOR
:
185 value
= (double)Context
->DopplerFactor
;
188 case AL_DOPPLER_VELOCITY
:
189 value
= (double)Context
->DopplerVelocity
;
192 case AL_DISTANCE_MODEL
:
193 value
= (double)Context
->DistanceModel
;
196 case AL_SPEED_OF_SOUND
:
197 value
= (double)Context
->flSpeedOfSound
;
201 alSetError(Context
, AL_INVALID_ENUM
);
205 ProcessContext(Context
);
210 AL_API ALfloat AL_APIENTRY
alGetFloat(ALenum pname
)
213 ALfloat value
= 0.0f
;
215 Context
= GetContextSuspended();
216 if(!Context
) return 0.0f
;
220 case AL_DOPPLER_FACTOR
:
221 value
= Context
->DopplerFactor
;
224 case AL_DOPPLER_VELOCITY
:
225 value
= Context
->DopplerVelocity
;
228 case AL_DISTANCE_MODEL
:
229 value
= (float)Context
->DistanceModel
;
232 case AL_SPEED_OF_SOUND
:
233 value
= Context
->flSpeedOfSound
;
237 alSetError(Context
, AL_INVALID_ENUM
);
241 ProcessContext(Context
);
246 AL_API ALint AL_APIENTRY
alGetInteger(ALenum pname
)
251 Context
= GetContextSuspended();
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
->flSpeedOfSound
;
272 case AL_SAMPLE_SOURCE_EXT
:
273 if(Context
->SampleSource
)
274 value
= (ALint
)Context
->SampleSource
->databuffer
;
279 case AL_SAMPLE_SINK_EXT
:
280 if(Context
->SampleSink
)
281 value
= (ALint
)Context
->SampleSink
->databuffer
;
287 alSetError(Context
, AL_INVALID_ENUM
);
291 ProcessContext(Context
);
296 AL_API ALvoid AL_APIENTRY
alGetBooleanv(ALenum pname
,ALboolean
*data
)
300 Context
= GetContextSuspended();
307 case AL_DOPPLER_FACTOR
:
308 *data
= (ALboolean
)((Context
->DopplerFactor
!= 0.0f
) ? AL_TRUE
: AL_FALSE
);
311 case AL_DOPPLER_VELOCITY
:
312 *data
= (ALboolean
)((Context
->DopplerVelocity
!= 0.0f
) ? AL_TRUE
: AL_FALSE
);
315 case AL_DISTANCE_MODEL
:
316 *data
= (ALboolean
)((Context
->DistanceModel
== AL_INVERSE_DISTANCE_CLAMPED
) ? AL_TRUE
: AL_FALSE
);
319 case AL_SPEED_OF_SOUND
:
320 *data
= (ALboolean
)((Context
->flSpeedOfSound
!= 0.0f
) ? AL_TRUE
: AL_FALSE
);
324 alSetError(Context
, AL_INVALID_ENUM
);
330 // data is a NULL pointer
331 alSetError(Context
, AL_INVALID_VALUE
);
334 ProcessContext(Context
);
337 AL_API ALvoid AL_APIENTRY
alGetDoublev(ALenum pname
,ALdouble
*data
)
341 Context
= GetContextSuspended();
348 case AL_DOPPLER_FACTOR
:
349 *data
= (double)Context
->DopplerFactor
;
352 case AL_DOPPLER_VELOCITY
:
353 *data
= (double)Context
->DopplerVelocity
;
356 case AL_DISTANCE_MODEL
:
357 *data
= (double)Context
->DistanceModel
;
360 case AL_SPEED_OF_SOUND
:
361 *data
= (double)Context
->flSpeedOfSound
;
365 alSetError(Context
, AL_INVALID_ENUM
);
371 // data is a NULL pointer
372 alSetError(Context
, AL_INVALID_VALUE
);
375 ProcessContext(Context
);
378 AL_API ALvoid AL_APIENTRY
alGetFloatv(ALenum pname
,ALfloat
*data
)
382 Context
= GetContextSuspended();
389 case AL_DOPPLER_FACTOR
:
390 *data
= Context
->DopplerFactor
;
393 case AL_DOPPLER_VELOCITY
:
394 *data
= Context
->DopplerVelocity
;
397 case AL_DISTANCE_MODEL
:
398 *data
= (float)Context
->DistanceModel
;
401 case AL_SPEED_OF_SOUND
:
402 *data
= Context
->flSpeedOfSound
;
406 alSetError(Context
, AL_INVALID_ENUM
);
412 // data is a NULL pointer
413 alSetError(Context
, AL_INVALID_VALUE
);
416 ProcessContext(Context
);
419 AL_API ALvoid AL_APIENTRY
alGetIntegerv(ALenum pname
,ALint
*data
)
423 Context
= GetContextSuspended();
430 case AL_DOPPLER_FACTOR
:
431 *data
= (ALint
)Context
->DopplerFactor
;
434 case AL_DOPPLER_VELOCITY
:
435 *data
= (ALint
)Context
->DopplerVelocity
;
438 case AL_DISTANCE_MODEL
:
439 *data
= (ALint
)Context
->DistanceModel
;
442 case AL_SPEED_OF_SOUND
:
443 *data
= (ALint
)Context
->flSpeedOfSound
;
446 case AL_SAMPLE_SOURCE_EXT
:
447 if(Context
->SampleSource
)
448 *data
= (ALint
)Context
->SampleSource
->databuffer
;
453 case AL_SAMPLE_SINK_EXT
:
454 if(Context
->SampleSink
)
455 *data
= (ALint
)Context
->SampleSink
->databuffer
;
461 alSetError(Context
, AL_INVALID_ENUM
);
467 // data is a NULL pointer
468 alSetError(Context
, AL_INVALID_VALUE
);
471 ProcessContext(Context
);
474 AL_API
const ALchar
* AL_APIENTRY
alGetString(ALenum pname
)
477 ALCcontext
*pContext
;
479 pContext
= GetContextSuspended();
480 if(!pContext
) return NULL
;
497 value
=pContext
->ExtensionList
;//alExtensions;
504 case AL_INVALID_NAME
:
505 value
=alErrInvalidName
;
508 case AL_INVALID_ENUM
:
509 value
=alErrInvalidEnum
;
512 case AL_INVALID_VALUE
:
513 value
=alErrInvalidValue
;
516 case AL_INVALID_OPERATION
:
517 value
=alErrInvalidOp
;
520 case AL_OUT_OF_MEMORY
:
521 value
=alErrOutOfMemory
;
526 alSetError(pContext
, AL_INVALID_ENUM
);
530 ProcessContext(pContext
);
535 AL_API ALvoid AL_APIENTRY
alDopplerFactor(ALfloat value
)
538 ALboolean updateSources
= AL_FALSE
;
540 Context
= GetContextSuspended();
545 Context
->DopplerFactor
= value
;
546 updateSources
= AL_TRUE
;
549 alSetError(Context
, AL_INVALID_VALUE
);
551 // Force updating the sources for these parameters, since even head-
552 // relative sources are affected
556 for(pos
= 0;pos
< Context
->SourceMap
.size
;pos
++)
558 ALsource
*source
= Context
->SourceMap
.array
[pos
].value
;
559 source
->NeedsUpdate
= AL_TRUE
;
563 ProcessContext(Context
);
566 AL_API ALvoid AL_APIENTRY
alDopplerVelocity(ALfloat value
)
569 ALboolean updateSources
= AL_FALSE
;
571 Context
= GetContextSuspended();
576 Context
->DopplerVelocity
=value
;
577 updateSources
= AL_TRUE
;
580 alSetError(Context
, AL_INVALID_VALUE
);
585 for(pos
= 0;pos
< Context
->SourceMap
.size
;pos
++)
587 ALsource
*source
= Context
->SourceMap
.array
[pos
].value
;
588 source
->NeedsUpdate
= AL_TRUE
;
592 ProcessContext(Context
);
595 AL_API ALvoid AL_APIENTRY
alSpeedOfSound(ALfloat flSpeedOfSound
)
597 ALCcontext
*pContext
;
598 ALboolean updateSources
= AL_FALSE
;
600 pContext
= GetContextSuspended();
601 if(!pContext
) return;
603 if(flSpeedOfSound
> 0.0f
)
605 pContext
->flSpeedOfSound
= flSpeedOfSound
;
606 updateSources
= AL_TRUE
;
609 alSetError(pContext
, AL_INVALID_VALUE
);
614 for(pos
= 0;pos
< pContext
->SourceMap
.size
;pos
++)
616 ALsource
*source
= pContext
->SourceMap
.array
[pos
].value
;
617 source
->NeedsUpdate
= AL_TRUE
;
621 ProcessContext(pContext
);
624 AL_API ALvoid AL_APIENTRY
alDistanceModel(ALenum value
)
627 ALboolean updateSources
= AL_FALSE
;
629 Context
= GetContextSuspended();
635 case AL_INVERSE_DISTANCE
:
636 case AL_INVERSE_DISTANCE_CLAMPED
:
637 case AL_LINEAR_DISTANCE
:
638 case AL_LINEAR_DISTANCE_CLAMPED
:
639 case AL_EXPONENT_DISTANCE
:
640 case AL_EXPONENT_DISTANCE_CLAMPED
:
641 Context
->DistanceModel
= value
;
642 updateSources
= !Context
->SourceDistanceModel
;
646 alSetError(Context
, AL_INVALID_VALUE
);
653 for(pos
= 0;pos
< Context
->SourceMap
.size
;pos
++)
655 ALsource
*source
= Context
->SourceMap
.array
[pos
].value
;
656 source
->NeedsUpdate
= AL_TRUE
;
660 ProcessContext(Context
);