Add base support for ALC_EXT_disconnect
[openal-soft.git] / OpenAL32 / alState.c
blob7d3707666fcfe3a41e066516c4234eda2abb9d22
1 /**
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
21 #include "config.h"
23 #include <stdlib.h>
24 #include "alMain.h"
25 #include "AL/alc.h"
26 #include "AL/alext.h"
27 #include "alError.h"
28 #include "alSource.h"
29 #include "alState.h"
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";
36 // Error Messages
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 ALAPI ALvoid ALAPIENTRY alEnable(ALenum capability)
46 ALCcontext *Context;
48 Context = GetContextSuspended();
49 if(!Context) return;
51 switch(capability)
53 default:
54 alSetError(AL_INVALID_ENUM);
55 break;
58 ProcessContext(Context);
61 ALAPI ALvoid ALAPIENTRY alDisable(ALenum capability)
63 ALCcontext *Context;
65 Context = GetContextSuspended();
66 if(!Context) return;
68 switch(capability)
70 default:
71 alSetError(AL_INVALID_ENUM);
72 break;
75 ProcessContext(Context);
78 ALAPI ALboolean ALAPIENTRY alIsEnabled(ALenum capability)
80 ALCcontext *Context;
81 ALboolean value=AL_FALSE;
83 Context = GetContextSuspended();
84 if(!Context) return AL_FALSE;
86 switch(capability)
88 default:
89 alSetError(AL_INVALID_ENUM);
90 break;
93 ProcessContext(Context);
95 return value;
98 ALAPI ALboolean ALAPIENTRY alGetBoolean(ALenum pname)
100 ALCcontext *Context;
101 ALboolean value=AL_FALSE;
103 Context = GetContextSuspended();
104 if(!Context) return AL_FALSE;
106 switch(pname)
108 case AL_DOPPLER_FACTOR:
109 if(Context->DopplerFactor != 0.0f)
110 value = AL_TRUE;
111 break;
113 case AL_DOPPLER_VELOCITY:
114 if(Context->DopplerVelocity != 0.0f)
115 value = AL_TRUE;
116 break;
118 case AL_DISTANCE_MODEL:
119 if(Context->DistanceModel == AL_INVERSE_DISTANCE_CLAMPED)
120 value = AL_TRUE;
121 break;
123 case AL_SPEED_OF_SOUND:
124 if(Context->flSpeedOfSound != 0.0f)
125 value = AL_TRUE;
126 break;
128 default:
129 alSetError(AL_INVALID_ENUM);
130 break;
133 ProcessContext(Context);
135 return value;
138 ALAPI ALdouble ALAPIENTRY alGetDouble(ALenum pname)
140 ALCcontext *Context;
141 ALdouble value = 0.0;
143 Context = GetContextSuspended();
144 if(!Context) return 0.0;
146 switch(pname)
148 case AL_DOPPLER_FACTOR:
149 value = (double)Context->DopplerFactor;
150 break;
152 case AL_DOPPLER_VELOCITY:
153 value = (double)Context->DopplerVelocity;
154 break;
156 case AL_DISTANCE_MODEL:
157 value = (double)Context->DistanceModel;
158 break;
160 case AL_SPEED_OF_SOUND:
161 value = (double)Context->flSpeedOfSound;
162 break;
164 default:
165 alSetError(AL_INVALID_ENUM);
166 break;
169 ProcessContext(Context);
171 return value;
174 ALAPI ALfloat ALAPIENTRY alGetFloat(ALenum pname)
176 ALCcontext *Context;
177 ALfloat value = 0.0f;
179 Context = GetContextSuspended();
180 if(!Context) return 0.0f;
182 switch(pname)
184 case AL_DOPPLER_FACTOR:
185 value = Context->DopplerFactor;
186 break;
188 case AL_DOPPLER_VELOCITY:
189 value = Context->DopplerVelocity;
190 break;
192 case AL_DISTANCE_MODEL:
193 value = (float)Context->DistanceModel;
194 break;
196 case AL_SPEED_OF_SOUND:
197 value = Context->flSpeedOfSound;
198 break;
200 default:
201 alSetError(AL_INVALID_ENUM);
202 break;
205 ProcessContext(Context);
207 return value;
210 ALAPI ALint ALAPIENTRY alGetInteger(ALenum pname)
212 ALCcontext *Context;
213 ALint value = 0;
215 Context = GetContextSuspended();
216 if(!Context) return 0;
218 switch(pname)
220 case AL_DOPPLER_FACTOR:
221 value = (ALint)Context->DopplerFactor;
222 break;
224 case AL_DOPPLER_VELOCITY:
225 value = (ALint)Context->DopplerVelocity;
226 break;
228 case AL_DISTANCE_MODEL:
229 value = (ALint)Context->DistanceModel;
230 break;
232 case AL_SPEED_OF_SOUND:
233 value = (ALint)Context->flSpeedOfSound;
234 break;
236 case AL_SAMPLE_SOURCE_EXT:
237 if(Context->SampleSource)
238 value = (ALint)Context->SampleSource->databuffer;
239 else
240 value = 0;
241 break;
243 case AL_SAMPLE_SINK_EXT:
244 if(Context->SampleSink)
245 value = (ALint)Context->SampleSink->databuffer;
246 else
247 value = 0;
248 break;
250 default:
251 alSetError(AL_INVALID_ENUM);
252 break;
255 ProcessContext(Context);
257 return value;
260 ALAPI ALvoid ALAPIENTRY alGetBooleanv(ALenum pname,ALboolean *data)
262 ALCcontext *Context;
264 Context = GetContextSuspended();
265 if(!Context) return;
267 if(data)
269 switch(pname)
271 case AL_DOPPLER_FACTOR:
272 *data = (ALboolean)((Context->DopplerFactor != 0.0f) ? AL_TRUE : AL_FALSE);
273 break;
275 case AL_DOPPLER_VELOCITY:
276 *data = (ALboolean)((Context->DopplerVelocity != 0.0f) ? AL_TRUE : AL_FALSE);
277 break;
279 case AL_DISTANCE_MODEL:
280 *data = (ALboolean)((Context->DistanceModel == AL_INVERSE_DISTANCE_CLAMPED) ? AL_TRUE : AL_FALSE);
281 break;
283 case AL_SPEED_OF_SOUND:
284 *data = (ALboolean)((Context->flSpeedOfSound != 0.0f) ? AL_TRUE : AL_FALSE);
285 break;
287 default:
288 alSetError(AL_INVALID_ENUM);
289 break;
292 else
294 // data is a NULL pointer
295 alSetError(AL_INVALID_VALUE);
298 ProcessContext(Context);
301 ALAPI ALvoid ALAPIENTRY alGetDoublev(ALenum pname,ALdouble *data)
303 ALCcontext *Context;
305 Context = GetContextSuspended();
306 if(!Context) return;
308 if(data)
310 switch(pname)
312 case AL_DOPPLER_FACTOR:
313 *data = (double)Context->DopplerFactor;
314 break;
316 case AL_DOPPLER_VELOCITY:
317 *data = (double)Context->DopplerVelocity;
318 break;
320 case AL_DISTANCE_MODEL:
321 *data = (double)Context->DistanceModel;
322 break;
324 case AL_SPEED_OF_SOUND:
325 *data = (double)Context->flSpeedOfSound;
326 break;
328 default:
329 alSetError(AL_INVALID_ENUM);
330 break;
333 else
335 // data is a NULL pointer
336 alSetError(AL_INVALID_VALUE);
339 ProcessContext(Context);
342 ALAPI ALvoid ALAPIENTRY alGetFloatv(ALenum pname,ALfloat *data)
344 ALCcontext *Context;
346 Context = GetContextSuspended();
347 if(!Context) return;
349 if(data)
351 switch(pname)
353 case AL_DOPPLER_FACTOR:
354 *data = Context->DopplerFactor;
355 break;
357 case AL_DOPPLER_VELOCITY:
358 *data = Context->DopplerVelocity;
359 break;
361 case AL_DISTANCE_MODEL:
362 *data = (float)Context->DistanceModel;
363 break;
365 case AL_SPEED_OF_SOUND:
366 *data = Context->flSpeedOfSound;
367 break;
369 default:
370 alSetError(AL_INVALID_ENUM);
371 break;
374 else
376 // data is a NULL pointer
377 alSetError(AL_INVALID_VALUE);
380 ProcessContext(Context);
383 ALAPI ALvoid ALAPIENTRY alGetIntegerv(ALenum pname,ALint *data)
385 ALCcontext *Context;
387 Context = GetContextSuspended();
388 if(!Context) return;
390 if(data)
392 switch(pname)
394 case AL_DOPPLER_FACTOR:
395 *data = (ALint)Context->DopplerFactor;
396 break;
398 case AL_DOPPLER_VELOCITY:
399 *data = (ALint)Context->DopplerVelocity;
400 break;
402 case AL_DISTANCE_MODEL:
403 *data = (ALint)Context->DistanceModel;
404 break;
406 case AL_SPEED_OF_SOUND:
407 *data = (ALint)Context->flSpeedOfSound;
408 break;
410 case AL_SAMPLE_SOURCE_EXT:
411 if(Context->SampleSource)
412 *data = (ALint)Context->SampleSource->databuffer;
413 else
414 *data = 0;
415 break;
417 case AL_SAMPLE_SINK_EXT:
418 if(Context->SampleSink)
419 *data = (ALint)Context->SampleSink->databuffer;
420 else
421 *data = 0;
422 break;
424 default:
425 alSetError(AL_INVALID_ENUM);
426 break;
429 else
431 // data is a NULL pointer
432 alSetError(AL_INVALID_VALUE);
435 ProcessContext(Context);
438 ALAPI const ALchar* ALAPIENTRY alGetString(ALenum pname)
440 const ALchar *value;
441 ALCcontext *pContext;
443 pContext = GetContextSuspended();
444 if(!pContext) return NULL;
446 switch(pname)
448 case AL_VENDOR:
449 value=alVendor;
450 break;
452 case AL_VERSION:
453 value=alVersion;
454 break;
456 case AL_RENDERER:
457 value=alRenderer;
458 break;
460 case AL_EXTENSIONS:
461 value=pContext->ExtensionList;//alExtensions;
462 break;
464 case AL_NO_ERROR:
465 value=alNoError;
466 break;
468 case AL_INVALID_NAME:
469 value=alErrInvalidName;
470 break;
472 case AL_INVALID_ENUM:
473 value=alErrInvalidEnum;
474 break;
476 case AL_INVALID_VALUE:
477 value=alErrInvalidValue;
478 break;
480 case AL_INVALID_OPERATION:
481 value=alErrInvalidOp;
482 break;
484 case AL_OUT_OF_MEMORY:
485 value=alErrOutOfMemory;
486 break;
488 default:
489 value=NULL;
490 alSetError(AL_INVALID_ENUM);
491 break;
494 ProcessContext(pContext);
496 return value;
499 ALAPI ALvoid ALAPIENTRY alDopplerFactor(ALfloat value)
501 ALCcontext *Context;
503 Context = GetContextSuspended();
504 if(!Context) return;
506 if(value >= 0.0f)
507 Context->DopplerFactor = value;
508 else
509 alSetError(AL_INVALID_VALUE);
511 ProcessContext(Context);
514 ALAPI ALvoid ALAPIENTRY alDopplerVelocity(ALfloat value)
516 ALCcontext *Context;
518 Context = GetContextSuspended();
519 if(!Context) return;
521 if(value > 0.0f)
522 Context->DopplerVelocity=value;
523 else
524 alSetError(AL_INVALID_VALUE);
526 ProcessContext(Context);
529 ALAPI ALvoid ALAPIENTRY alSpeedOfSound(ALfloat flSpeedOfSound)
531 ALCcontext *pContext;
533 pContext = GetContextSuspended();
534 if(!pContext) return;
536 if(flSpeedOfSound > 0.0f)
537 pContext->flSpeedOfSound = flSpeedOfSound;
538 else
539 alSetError(AL_INVALID_VALUE);
541 ProcessContext(pContext);
544 ALAPI ALvoid ALAPIENTRY alDistanceModel(ALenum value)
546 ALCcontext *Context;
547 ALsource *Source;
549 Context = GetContextSuspended();
550 if(!Context) return;
552 switch(value)
554 case AL_NONE:
555 case AL_INVERSE_DISTANCE:
556 case AL_INVERSE_DISTANCE_CLAMPED:
557 case AL_LINEAR_DISTANCE:
558 case AL_LINEAR_DISTANCE_CLAMPED:
559 case AL_EXPONENT_DISTANCE:
560 case AL_EXPONENT_DISTANCE_CLAMPED:
561 Context->DistanceModel = value;
562 for(Source = Context->Source;Source != NULL;Source = Source->next)
563 Source->DistanceModel = value;
564 break;
566 default:
567 alSetError(AL_INVALID_VALUE);
568 break;
571 ProcessContext(Context);