Add click removal for wet sends
[openal-soft.git] / OpenAL32 / alState.c
blob953b1a172e69804ac4c48727a830d481c2bdaf4b
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 AL_API ALvoid AL_APIENTRY alEnable(ALenum capability)
46 ALCcontext *Context;
47 ALboolean updateSources = AL_FALSE;
49 Context = GetContextSuspended();
50 if(!Context) return;
52 switch(capability)
54 case AL_SOURCE_DISTANCE_MODEL:
55 Context->SourceDistanceModel = AL_TRUE;
56 updateSources = AL_TRUE;
57 break;
59 default:
60 alSetError(Context, AL_INVALID_ENUM);
61 break;
64 if(updateSources)
66 ALsizei pos;
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)
79 ALCcontext *Context;
80 ALboolean updateSources = AL_FALSE;
82 Context = GetContextSuspended();
83 if(!Context) return;
85 switch(capability)
87 case AL_SOURCE_DISTANCE_MODEL:
88 Context->SourceDistanceModel = AL_FALSE;
89 updateSources = AL_TRUE;
90 break;
92 default:
93 alSetError(Context, AL_INVALID_ENUM);
94 break;
97 if(updateSources)
99 ALsizei pos;
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)
112 ALCcontext *Context;
113 ALboolean value=AL_FALSE;
115 Context = GetContextSuspended();
116 if(!Context) return AL_FALSE;
118 switch(capability)
120 case AL_SOURCE_DISTANCE_MODEL:
121 value = Context->SourceDistanceModel;
122 break;
124 default:
125 alSetError(Context, AL_INVALID_ENUM);
126 break;
129 ProcessContext(Context);
131 return value;
134 AL_API ALboolean AL_APIENTRY alGetBoolean(ALenum pname)
136 ALCcontext *Context;
137 ALboolean value=AL_FALSE;
139 Context = GetContextSuspended();
140 if(!Context) return AL_FALSE;
142 switch(pname)
144 case AL_DOPPLER_FACTOR:
145 if(Context->DopplerFactor != 0.0f)
146 value = AL_TRUE;
147 break;
149 case AL_DOPPLER_VELOCITY:
150 if(Context->DopplerVelocity != 0.0f)
151 value = AL_TRUE;
152 break;
154 case AL_DISTANCE_MODEL:
155 if(Context->DistanceModel == AL_INVERSE_DISTANCE_CLAMPED)
156 value = AL_TRUE;
157 break;
159 case AL_SPEED_OF_SOUND:
160 if(Context->flSpeedOfSound != 0.0f)
161 value = AL_TRUE;
162 break;
164 default:
165 alSetError(Context, AL_INVALID_ENUM);
166 break;
169 ProcessContext(Context);
171 return value;
174 AL_API ALdouble AL_APIENTRY alGetDouble(ALenum pname)
176 ALCcontext *Context;
177 ALdouble value = 0.0;
179 Context = GetContextSuspended();
180 if(!Context) return 0.0;
182 switch(pname)
184 case AL_DOPPLER_FACTOR:
185 value = (double)Context->DopplerFactor;
186 break;
188 case AL_DOPPLER_VELOCITY:
189 value = (double)Context->DopplerVelocity;
190 break;
192 case AL_DISTANCE_MODEL:
193 value = (double)Context->DistanceModel;
194 break;
196 case AL_SPEED_OF_SOUND:
197 value = (double)Context->flSpeedOfSound;
198 break;
200 default:
201 alSetError(Context, AL_INVALID_ENUM);
202 break;
205 ProcessContext(Context);
207 return value;
210 AL_API ALfloat AL_APIENTRY alGetFloat(ALenum pname)
212 ALCcontext *Context;
213 ALfloat value = 0.0f;
215 Context = GetContextSuspended();
216 if(!Context) return 0.0f;
218 switch(pname)
220 case AL_DOPPLER_FACTOR:
221 value = Context->DopplerFactor;
222 break;
224 case AL_DOPPLER_VELOCITY:
225 value = Context->DopplerVelocity;
226 break;
228 case AL_DISTANCE_MODEL:
229 value = (float)Context->DistanceModel;
230 break;
232 case AL_SPEED_OF_SOUND:
233 value = Context->flSpeedOfSound;
234 break;
236 default:
237 alSetError(Context, AL_INVALID_ENUM);
238 break;
241 ProcessContext(Context);
243 return value;
246 AL_API ALint AL_APIENTRY alGetInteger(ALenum pname)
248 ALCcontext *Context;
249 ALint value = 0;
251 Context = GetContextSuspended();
252 if(!Context) return 0;
254 switch(pname)
256 case AL_DOPPLER_FACTOR:
257 value = (ALint)Context->DopplerFactor;
258 break;
260 case AL_DOPPLER_VELOCITY:
261 value = (ALint)Context->DopplerVelocity;
262 break;
264 case AL_DISTANCE_MODEL:
265 value = (ALint)Context->DistanceModel;
266 break;
268 case AL_SPEED_OF_SOUND:
269 value = (ALint)Context->flSpeedOfSound;
270 break;
272 case AL_SAMPLE_SOURCE_EXT:
273 if(Context->SampleSource)
274 value = (ALint)Context->SampleSource->databuffer;
275 else
276 value = 0;
277 break;
279 case AL_SAMPLE_SINK_EXT:
280 if(Context->SampleSink)
281 value = (ALint)Context->SampleSink->databuffer;
282 else
283 value = 0;
284 break;
286 default:
287 alSetError(Context, AL_INVALID_ENUM);
288 break;
291 ProcessContext(Context);
293 return value;
296 AL_API ALvoid AL_APIENTRY alGetBooleanv(ALenum pname,ALboolean *data)
298 ALCcontext *Context;
300 Context = GetContextSuspended();
301 if(!Context) return;
303 if(data)
305 switch(pname)
307 case AL_DOPPLER_FACTOR:
308 *data = (ALboolean)((Context->DopplerFactor != 0.0f) ? AL_TRUE : AL_FALSE);
309 break;
311 case AL_DOPPLER_VELOCITY:
312 *data = (ALboolean)((Context->DopplerVelocity != 0.0f) ? AL_TRUE : AL_FALSE);
313 break;
315 case AL_DISTANCE_MODEL:
316 *data = (ALboolean)((Context->DistanceModel == AL_INVERSE_DISTANCE_CLAMPED) ? AL_TRUE : AL_FALSE);
317 break;
319 case AL_SPEED_OF_SOUND:
320 *data = (ALboolean)((Context->flSpeedOfSound != 0.0f) ? AL_TRUE : AL_FALSE);
321 break;
323 default:
324 alSetError(Context, AL_INVALID_ENUM);
325 break;
328 else
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)
339 ALCcontext *Context;
341 Context = GetContextSuspended();
342 if(!Context) return;
344 if(data)
346 switch(pname)
348 case AL_DOPPLER_FACTOR:
349 *data = (double)Context->DopplerFactor;
350 break;
352 case AL_DOPPLER_VELOCITY:
353 *data = (double)Context->DopplerVelocity;
354 break;
356 case AL_DISTANCE_MODEL:
357 *data = (double)Context->DistanceModel;
358 break;
360 case AL_SPEED_OF_SOUND:
361 *data = (double)Context->flSpeedOfSound;
362 break;
364 default:
365 alSetError(Context, AL_INVALID_ENUM);
366 break;
369 else
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)
380 ALCcontext *Context;
382 Context = GetContextSuspended();
383 if(!Context) return;
385 if(data)
387 switch(pname)
389 case AL_DOPPLER_FACTOR:
390 *data = Context->DopplerFactor;
391 break;
393 case AL_DOPPLER_VELOCITY:
394 *data = Context->DopplerVelocity;
395 break;
397 case AL_DISTANCE_MODEL:
398 *data = (float)Context->DistanceModel;
399 break;
401 case AL_SPEED_OF_SOUND:
402 *data = Context->flSpeedOfSound;
403 break;
405 default:
406 alSetError(Context, AL_INVALID_ENUM);
407 break;
410 else
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)
421 ALCcontext *Context;
423 Context = GetContextSuspended();
424 if(!Context) return;
426 if(data)
428 switch(pname)
430 case AL_DOPPLER_FACTOR:
431 *data = (ALint)Context->DopplerFactor;
432 break;
434 case AL_DOPPLER_VELOCITY:
435 *data = (ALint)Context->DopplerVelocity;
436 break;
438 case AL_DISTANCE_MODEL:
439 *data = (ALint)Context->DistanceModel;
440 break;
442 case AL_SPEED_OF_SOUND:
443 *data = (ALint)Context->flSpeedOfSound;
444 break;
446 case AL_SAMPLE_SOURCE_EXT:
447 if(Context->SampleSource)
448 *data = (ALint)Context->SampleSource->databuffer;
449 else
450 *data = 0;
451 break;
453 case AL_SAMPLE_SINK_EXT:
454 if(Context->SampleSink)
455 *data = (ALint)Context->SampleSink->databuffer;
456 else
457 *data = 0;
458 break;
460 default:
461 alSetError(Context, AL_INVALID_ENUM);
462 break;
465 else
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)
476 const ALchar *value;
477 ALCcontext *pContext;
479 pContext = GetContextSuspended();
480 if(!pContext) return NULL;
482 switch(pname)
484 case AL_VENDOR:
485 value=alVendor;
486 break;
488 case AL_VERSION:
489 value=alVersion;
490 break;
492 case AL_RENDERER:
493 value=alRenderer;
494 break;
496 case AL_EXTENSIONS:
497 value=pContext->ExtensionList;//alExtensions;
498 break;
500 case AL_NO_ERROR:
501 value=alNoError;
502 break;
504 case AL_INVALID_NAME:
505 value=alErrInvalidName;
506 break;
508 case AL_INVALID_ENUM:
509 value=alErrInvalidEnum;
510 break;
512 case AL_INVALID_VALUE:
513 value=alErrInvalidValue;
514 break;
516 case AL_INVALID_OPERATION:
517 value=alErrInvalidOp;
518 break;
520 case AL_OUT_OF_MEMORY:
521 value=alErrOutOfMemory;
522 break;
524 default:
525 value=NULL;
526 alSetError(pContext, AL_INVALID_ENUM);
527 break;
530 ProcessContext(pContext);
532 return value;
535 AL_API ALvoid AL_APIENTRY alDopplerFactor(ALfloat value)
537 ALCcontext *Context;
538 ALboolean updateSources = AL_FALSE;
540 Context = GetContextSuspended();
541 if(!Context) return;
543 if(value >= 0.0f)
545 Context->DopplerFactor = value;
546 updateSources = AL_TRUE;
548 else
549 alSetError(Context, AL_INVALID_VALUE);
551 // Force updating the sources for these parameters, since even head-
552 // relative sources are affected
553 if(updateSources)
555 ALsizei pos;
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)
568 ALCcontext *Context;
569 ALboolean updateSources = AL_FALSE;
571 Context = GetContextSuspended();
572 if(!Context) return;
574 if(value > 0.0f)
576 Context->DopplerVelocity=value;
577 updateSources = AL_TRUE;
579 else
580 alSetError(Context, AL_INVALID_VALUE);
582 if(updateSources)
584 ALsizei pos;
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;
608 else
609 alSetError(pContext, AL_INVALID_VALUE);
611 if(updateSources)
613 ALsizei pos;
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)
626 ALCcontext *Context;
627 ALboolean updateSources = AL_FALSE;
629 Context = GetContextSuspended();
630 if(!Context) return;
632 switch(value)
634 case AL_NONE:
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;
643 break;
645 default:
646 alSetError(Context, AL_INVALID_VALUE);
647 break;
650 if(updateSources)
652 ALsizei pos;
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);