comparison OpenAL32/alState.c @ 0:f9476ff7637e

initial forking of open-al to create multiple listeners
author Robert McIntyre <rlm@mit.edu>
date Tue, 25 Oct 2011 13:02:31 -0700
parents
children
comparison
equal deleted inserted replaced
-1:000000000000 0:f9476ff7637e
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.
8 *
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.
13 *
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
19 */
20
21 #include "config.h"
22
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 "alAuxEffectSlot.h"
30 #include "alState.h"
31
32 static const ALchar alVendor[] = "OpenAL Community";
33 static const ALchar alVersion[] = "1.1 ALSOFT "ALSOFT_VERSION;
34 static const ALchar alRenderer[] = "OpenAL Soft";
35
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";
43
44 AL_API ALvoid AL_APIENTRY alEnable(ALenum capability)
45 {
46 ALCcontext *Context;
47
48 Context = GetLockedContext();
49 if(!Context) return;
50
51 switch(capability)
52 {
53 case AL_SOURCE_DISTANCE_MODEL:
54 Context->SourceDistanceModel = AL_TRUE;
55 Context->UpdateSources = AL_TRUE;
56 break;
57
58 default:
59 alSetError(Context, AL_INVALID_ENUM);
60 break;
61 }
62
63 UnlockContext(Context);
64 }
65
66 AL_API ALvoid AL_APIENTRY alDisable(ALenum capability)
67 {
68 ALCcontext *Context;
69
70 Context = GetLockedContext();
71 if(!Context) return;
72
73 switch(capability)
74 {
75 case AL_SOURCE_DISTANCE_MODEL:
76 Context->SourceDistanceModel = AL_FALSE;
77 Context->UpdateSources = AL_TRUE;
78 break;
79
80 default:
81 alSetError(Context, AL_INVALID_ENUM);
82 break;
83 }
84
85 UnlockContext(Context);
86 }
87
88 AL_API ALboolean AL_APIENTRY alIsEnabled(ALenum capability)
89 {
90 ALCcontext *Context;
91 ALboolean value=AL_FALSE;
92
93 Context = GetLockedContext();
94 if(!Context) return AL_FALSE;
95
96 switch(capability)
97 {
98 case AL_SOURCE_DISTANCE_MODEL:
99 value = Context->SourceDistanceModel;
100 break;
101
102 default:
103 alSetError(Context, AL_INVALID_ENUM);
104 break;
105 }
106
107 UnlockContext(Context);
108
109 return value;
110 }
111
112 AL_API ALboolean AL_APIENTRY alGetBoolean(ALenum pname)
113 {
114 ALCcontext *Context;
115 ALboolean value=AL_FALSE;
116
117 Context = GetLockedContext();
118 if(!Context) return AL_FALSE;
119
120 switch(pname)
121 {
122 case AL_DOPPLER_FACTOR:
123 if(Context->DopplerFactor != 0.0f)
124 value = AL_TRUE;
125 break;
126
127 case AL_DOPPLER_VELOCITY:
128 if(Context->DopplerVelocity != 0.0f)
129 value = AL_TRUE;
130 break;
131
132 case AL_DISTANCE_MODEL:
133 if(Context->DistanceModel == AL_INVERSE_DISTANCE_CLAMPED)
134 value = AL_TRUE;
135 break;
136
137 case AL_SPEED_OF_SOUND:
138 if(Context->flSpeedOfSound != 0.0f)
139 value = AL_TRUE;
140 break;
141
142 case AL_DEFERRED_UPDATES_SOFT:
143 value = Context->DeferUpdates;
144 break;
145
146 default:
147 alSetError(Context, AL_INVALID_ENUM);
148 break;
149 }
150
151 UnlockContext(Context);
152
153 return value;
154 }
155
156 AL_API ALdouble AL_APIENTRY alGetDouble(ALenum pname)
157 {
158 ALCcontext *Context;
159 ALdouble value = 0.0;
160
161 Context = GetLockedContext();
162 if(!Context) return 0.0;
163
164 switch(pname)
165 {
166 case AL_DOPPLER_FACTOR:
167 value = (double)Context->DopplerFactor;
168 break;
169
170 case AL_DOPPLER_VELOCITY:
171 value = (double)Context->DopplerVelocity;
172 break;
173
174 case AL_DISTANCE_MODEL:
175 value = (double)Context->DistanceModel;
176 break;
177
178 case AL_SPEED_OF_SOUND:
179 value = (double)Context->flSpeedOfSound;
180 break;
181
182 case AL_DEFERRED_UPDATES_SOFT:
183 value = (ALdouble)Context->DeferUpdates;
184 break;
185
186 default:
187 alSetError(Context, AL_INVALID_ENUM);
188 break;
189 }
190
191 UnlockContext(Context);
192
193 return value;
194 }
195
196 AL_API ALfloat AL_APIENTRY alGetFloat(ALenum pname)
197 {
198 ALCcontext *Context;
199 ALfloat value = 0.0f;
200
201 Context = GetLockedContext();
202 if(!Context) return 0.0f;
203
204 switch(pname)
205 {
206 case AL_DOPPLER_FACTOR:
207 value = Context->DopplerFactor;
208 break;
209
210 case AL_DOPPLER_VELOCITY:
211 value = Context->DopplerVelocity;
212 break;
213
214 case AL_DISTANCE_MODEL:
215 value = (float)Context->DistanceModel;
216 break;
217
218 case AL_SPEED_OF_SOUND:
219 value = Context->flSpeedOfSound;
220 break;
221
222 case AL_DEFERRED_UPDATES_SOFT:
223 value = (ALfloat)Context->DeferUpdates;
224 break;
225
226 default:
227 alSetError(Context, AL_INVALID_ENUM);
228 break;
229 }
230
231 UnlockContext(Context);
232
233 return value;
234 }
235
236 AL_API ALint AL_APIENTRY alGetInteger(ALenum pname)
237 {
238 ALCcontext *Context;
239 ALint value = 0;
240
241 Context = GetLockedContext();
242 if(!Context) return 0;
243
244 switch(pname)
245 {
246 case AL_DOPPLER_FACTOR:
247 value = (ALint)Context->DopplerFactor;
248 break;
249
250 case AL_DOPPLER_VELOCITY:
251 value = (ALint)Context->DopplerVelocity;
252 break;
253
254 case AL_DISTANCE_MODEL:
255 value = (ALint)Context->DistanceModel;
256 break;
257
258 case AL_SPEED_OF_SOUND:
259 value = (ALint)Context->flSpeedOfSound;
260 break;
261
262 case AL_DEFERRED_UPDATES_SOFT:
263 value = (ALint)Context->DeferUpdates;
264 break;
265
266 default:
267 alSetError(Context, AL_INVALID_ENUM);
268 break;
269 }
270
271 UnlockContext(Context);
272
273 return value;
274 }
275
276 AL_API ALvoid AL_APIENTRY alGetBooleanv(ALenum pname,ALboolean *data)
277 {
278 ALCcontext *Context;
279
280 if(data)
281 {
282 switch(pname)
283 {
284 case AL_DOPPLER_FACTOR:
285 case AL_DOPPLER_VELOCITY:
286 case AL_DISTANCE_MODEL:
287 case AL_SPEED_OF_SOUND:
288 case AL_DEFERRED_UPDATES_SOFT:
289 *data = alGetBoolean(pname);
290 return;
291 }
292 }
293
294 Context = GetLockedContext();
295 if(!Context) return;
296
297 if(data)
298 {
299 switch(pname)
300 {
301 default:
302 alSetError(Context, AL_INVALID_ENUM);
303 break;
304 }
305 }
306 else
307 {
308 // data is a NULL pointer
309 alSetError(Context, AL_INVALID_VALUE);
310 }
311
312 UnlockContext(Context);
313 }
314
315 AL_API ALvoid AL_APIENTRY alGetDoublev(ALenum pname,ALdouble *data)
316 {
317 ALCcontext *Context;
318
319 if(data)
320 {
321 switch(pname)
322 {
323 case AL_DOPPLER_FACTOR:
324 case AL_DOPPLER_VELOCITY:
325 case AL_DISTANCE_MODEL:
326 case AL_SPEED_OF_SOUND:
327 case AL_DEFERRED_UPDATES_SOFT:
328 *data = alGetDouble(pname);
329 return;
330 }
331 }
332
333 Context = GetLockedContext();
334 if(!Context) return;
335
336 if(data)
337 {
338 switch(pname)
339 {
340 default:
341 alSetError(Context, AL_INVALID_ENUM);
342 break;
343 }
344 }
345 else
346 {
347 // data is a NULL pointer
348 alSetError(Context, AL_INVALID_VALUE);
349 }
350
351 UnlockContext(Context);
352 }
353
354 AL_API ALvoid AL_APIENTRY alGetFloatv(ALenum pname,ALfloat *data)
355 {
356 ALCcontext *Context;
357
358 if(data)
359 {
360 switch(pname)
361 {
362 case AL_DOPPLER_FACTOR:
363 case AL_DOPPLER_VELOCITY:
364 case AL_DISTANCE_MODEL:
365 case AL_SPEED_OF_SOUND:
366 case AL_DEFERRED_UPDATES_SOFT:
367 *data = alGetFloat(pname);
368 return;
369 }
370 }
371
372 Context = GetLockedContext();
373 if(!Context) return;
374
375 if(data)
376 {
377 switch(pname)
378 {
379 default:
380 alSetError(Context, AL_INVALID_ENUM);
381 break;
382 }
383 }
384 else
385 {
386 // data is a NULL pointer
387 alSetError(Context, AL_INVALID_VALUE);
388 }
389
390 UnlockContext(Context);
391 }
392
393 AL_API ALvoid AL_APIENTRY alGetIntegerv(ALenum pname,ALint *data)
394 {
395 ALCcontext *Context;
396
397 if(data)
398 {
399 switch(pname)
400 {
401 case AL_DOPPLER_FACTOR:
402 case AL_DOPPLER_VELOCITY:
403 case AL_DISTANCE_MODEL:
404 case AL_SPEED_OF_SOUND:
405 case AL_DEFERRED_UPDATES_SOFT:
406 *data = alGetInteger(pname);
407 return;
408 }
409 }
410
411 Context = GetLockedContext();
412 if(!Context) return;
413
414 if(data)
415 {
416 switch(pname)
417 {
418 default:
419 alSetError(Context, AL_INVALID_ENUM);
420 break;
421 }
422 }
423 else
424 {
425 // data is a NULL pointer
426 alSetError(Context, AL_INVALID_VALUE);
427 }
428
429 UnlockContext(Context);
430 }
431
432 AL_API const ALchar* AL_APIENTRY alGetString(ALenum pname)
433 {
434 const ALchar *value;
435 ALCcontext *pContext;
436
437 pContext = GetLockedContext();
438 if(!pContext) return NULL;
439
440 switch(pname)
441 {
442 case AL_VENDOR:
443 value=alVendor;
444 break;
445
446 case AL_VERSION:
447 value=alVersion;
448 break;
449
450 case AL_RENDERER:
451 value=alRenderer;
452 break;
453
454 case AL_EXTENSIONS:
455 value=pContext->ExtensionList;//alExtensions;
456 break;
457
458 case AL_NO_ERROR:
459 value=alNoError;
460 break;
461
462 case AL_INVALID_NAME:
463 value=alErrInvalidName;
464 break;
465
466 case AL_INVALID_ENUM:
467 value=alErrInvalidEnum;
468 break;
469
470 case AL_INVALID_VALUE:
471 value=alErrInvalidValue;
472 break;
473
474 case AL_INVALID_OPERATION:
475 value=alErrInvalidOp;
476 break;
477
478 case AL_OUT_OF_MEMORY:
479 value=alErrOutOfMemory;
480 break;
481
482 default:
483 value=NULL;
484 alSetError(pContext, AL_INVALID_ENUM);
485 break;
486 }
487
488 UnlockContext(pContext);
489
490 return value;
491 }
492
493 AL_API ALvoid AL_APIENTRY alDopplerFactor(ALfloat value)
494 {
495 ALCcontext *Context;
496
497 Context = GetLockedContext();
498 if(!Context) return;
499
500 if(value >= 0.0f && isfinite(value))
501 {
502 Context->DopplerFactor = value;
503 Context->UpdateSources = AL_TRUE;
504 }
505 else
506 alSetError(Context, AL_INVALID_VALUE);
507
508 UnlockContext(Context);
509 }
510
511 AL_API ALvoid AL_APIENTRY alDopplerVelocity(ALfloat value)
512 {
513 ALCcontext *Context;
514
515 Context = GetLockedContext();
516 if(!Context) return;
517
518 if(value > 0.0f && isfinite(value))
519 {
520 Context->DopplerVelocity=value;
521 Context->UpdateSources = AL_TRUE;
522 }
523 else
524 alSetError(Context, AL_INVALID_VALUE);
525
526 UnlockContext(Context);
527 }
528
529 AL_API ALvoid AL_APIENTRY alSpeedOfSound(ALfloat flSpeedOfSound)
530 {
531 ALCcontext *pContext;
532
533 pContext = GetLockedContext();
534 if(!pContext) return;
535
536 if(flSpeedOfSound > 0.0f && isfinite(flSpeedOfSound))
537 {
538 pContext->flSpeedOfSound = flSpeedOfSound;
539 pContext->UpdateSources = AL_TRUE;
540 }
541 else
542 alSetError(pContext, AL_INVALID_VALUE);
543
544 UnlockContext(pContext);
545 }
546
547 AL_API ALvoid AL_APIENTRY alDistanceModel(ALenum value)
548 {
549 ALCcontext *Context;
550
551 Context = GetLockedContext();
552 if(!Context) return;
553
554 switch(value)
555 {
556 case AL_NONE:
557 case AL_INVERSE_DISTANCE:
558 case AL_INVERSE_DISTANCE_CLAMPED:
559 case AL_LINEAR_DISTANCE:
560 case AL_LINEAR_DISTANCE_CLAMPED:
561 case AL_EXPONENT_DISTANCE:
562 case AL_EXPONENT_DISTANCE_CLAMPED:
563 Context->DistanceModel = value;
564 Context->UpdateSources = AL_TRUE;
565 break;
566
567 default:
568 alSetError(Context, AL_INVALID_VALUE);
569 break;
570 }
571
572 UnlockContext(Context);
573 }
574
575
576 AL_API ALvoid AL_APIENTRY alDeferUpdatesSOFT(void)
577 {
578 ALCcontext *Context;
579
580 Context = GetLockedContext();
581 if(!Context) return;
582
583 if(!Context->DeferUpdates)
584 {
585 ALboolean UpdateSources;
586 ALsource **src, **src_end;
587 ALeffectslot *ALEffectSlot;
588 ALsizei e;
589
590 Context->DeferUpdates = AL_TRUE;
591
592 /* Make sure all pending updates are performed */
593 UpdateSources = Context->UpdateSources;
594 Context->UpdateSources = AL_FALSE;
595
596 src = Context->ActiveSources;
597 src_end = src + Context->ActiveSourceCount;
598 while(src != src_end)
599 {
600 if((*src)->state != AL_PLAYING)
601 {
602 Context->ActiveSourceCount--;
603 *src = *(--src_end);
604 continue;
605 }
606
607 if((*src)->NeedsUpdate || UpdateSources)
608 {
609 (*src)->NeedsUpdate = AL_FALSE;
610 ALsource_Update(*src, Context);
611 }
612 src++;
613 }
614
615 for(e = 0;e < Context->EffectSlotMap.size;e++)
616 {
617 ALEffectSlot = Context->EffectSlotMap.array[e].value;
618 if(ALEffectSlot->NeedsUpdate)
619 {
620 ALEffectSlot->NeedsUpdate = AL_FALSE;
621 ALEffect_Update(ALEffectSlot->EffectState, Context, ALEffectSlot);
622 }
623 }
624 }
625
626 UnlockContext(Context);
627 }
628
629 AL_API ALvoid AL_APIENTRY alProcessUpdatesSOFT(void)
630 {
631 ALCcontext *Context;
632
633 Context = GetLockedContext();
634 if(!Context) return;
635
636 if(Context->DeferUpdates)
637 {
638 ALsizei pos;
639
640 Context->DeferUpdates = AL_FALSE;
641
642 for(pos = 0;pos < Context->SourceMap.size;pos++)
643 {
644 ALsource *Source = Context->SourceMap.array[pos].value;
645 ALenum new_state;
646
647 if(Source->lOffset != -1)
648 ApplyOffset(Source);
649
650 new_state = Source->new_state;
651 Source->new_state = AL_NONE;
652 if(new_state)
653 SetSourceState(Source, Context, new_state);
654 }
655 }
656
657 UnlockContext(Context);
658 }