zenilib  0.5.3.0
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Groups Pages
alState.c
Go to the documentation of this file.
1 
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 
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 
45 {
46  ALCcontext *Context;
47 
48  Context = GetContextRef();
49  if(!Context) return;
50 
51  al_try
52  {
53  switch(capability)
54  {
56  Context->SourceDistanceModel = AL_TRUE;
57  Context->UpdateSources = AL_TRUE;
58  break;
59 
60  default:
61  al_throwerr(Context, AL_INVALID_ENUM);
62  }
63  }
64  al_endtry;
65 
66  ALCcontext_DecRef(Context);
67 }
68 
70 {
71  ALCcontext *Context;
72 
73  Context = GetContextRef();
74  if(!Context) return;
75 
76  al_try
77  {
78  switch(capability)
79  {
81  Context->SourceDistanceModel = AL_FALSE;
82  Context->UpdateSources = AL_TRUE;
83  break;
84 
85  default:
86  al_throwerr(Context, AL_INVALID_ENUM);
87  }
88  }
89  al_endtry;
90 
91  ALCcontext_DecRef(Context);
92 }
93 
95 {
96  ALCcontext *Context;
98 
99  Context = GetContextRef();
100  if(!Context) return AL_FALSE;
101 
102  al_try
103  {
104  switch(capability)
105  {
107  value = Context->SourceDistanceModel;
108  break;
109 
110  default:
111  al_throwerr(Context, AL_INVALID_ENUM);
112  }
113  }
114  al_endtry;
115 
116  ALCcontext_DecRef(Context);
117 
118  return value;
119 }
120 
122 {
123  ALCcontext *Context;
125 
126  Context = GetContextRef();
127  if(!Context) return AL_FALSE;
128 
129  al_try
130  {
131  switch(pname)
132  {
133  case AL_DOPPLER_FACTOR:
134  if(Context->DopplerFactor != 0.0f)
135  value = AL_TRUE;
136  break;
137 
138  case AL_DOPPLER_VELOCITY:
139  if(Context->DopplerVelocity != 0.0f)
140  value = AL_TRUE;
141  break;
142 
143  case AL_DISTANCE_MODEL:
145  value = AL_TRUE;
146  break;
147 
148  case AL_SPEED_OF_SOUND:
149  if(Context->SpeedOfSound != 0.0f)
150  value = AL_TRUE;
151  break;
152 
154  value = Context->DeferUpdates;
155  break;
156 
157  default:
158  al_throwerr(Context, AL_INVALID_ENUM);
159  }
160  }
161  al_endtry;
162 
163  ALCcontext_DecRef(Context);
164 
165  return value;
166 }
167 
169 {
170  ALCcontext *Context;
171  ALdouble value = 0.0;
172 
173  Context = GetContextRef();
174  if(!Context) return 0.0;
175 
176  al_try
177  {
178  switch(pname)
179  {
180  case AL_DOPPLER_FACTOR:
181  value = (ALdouble)Context->DopplerFactor;
182  break;
183 
184  case AL_DOPPLER_VELOCITY:
185  value = (ALdouble)Context->DopplerVelocity;
186  break;
187 
188  case AL_DISTANCE_MODEL:
189  value = (ALdouble)Context->DistanceModel;
190  break;
191 
192  case AL_SPEED_OF_SOUND:
193  value = (ALdouble)Context->SpeedOfSound;
194  break;
195 
197  value = (ALdouble)Context->DeferUpdates;
198  break;
199 
200  default:
201  al_throwerr(Context, AL_INVALID_ENUM);
202  }
203  }
204  al_endtry;
205 
206  ALCcontext_DecRef(Context);
207 
208  return value;
209 }
210 
212 {
213  ALCcontext *Context;
214  ALfloat value = 0.0f;
215 
216  Context = GetContextRef();
217  if(!Context) return 0.0f;
218 
219  al_try
220  {
221  switch(pname)
222  {
223  case AL_DOPPLER_FACTOR:
224  value = Context->DopplerFactor;
225  break;
226 
227  case AL_DOPPLER_VELOCITY:
228  value = Context->DopplerVelocity;
229  break;
230 
231  case AL_DISTANCE_MODEL:
232  value = (ALfloat)Context->DistanceModel;
233  break;
234 
235  case AL_SPEED_OF_SOUND:
236  value = Context->SpeedOfSound;
237  break;
238 
240  value = (ALfloat)Context->DeferUpdates;
241  break;
242 
243  default:
244  al_throwerr(Context, AL_INVALID_ENUM);
245  }
246  }
247  al_endtry;
248 
249  ALCcontext_DecRef(Context);
250 
251  return value;
252 }
253 
255 {
256  ALCcontext *Context;
257  ALint value = 0;
258 
259  Context = GetContextRef();
260  if(!Context) return 0;
261 
262  al_try
263  {
264  switch(pname)
265  {
266  case AL_DOPPLER_FACTOR:
267  value = (ALint)Context->DopplerFactor;
268  break;
269 
270  case AL_DOPPLER_VELOCITY:
271  value = (ALint)Context->DopplerVelocity;
272  break;
273 
274  case AL_DISTANCE_MODEL:
275  value = (ALint)Context->DistanceModel;
276  break;
277 
278  case AL_SPEED_OF_SOUND:
279  value = (ALint)Context->SpeedOfSound;
280  break;
281 
283  value = (ALint)Context->DeferUpdates;
284  break;
285 
286  default:
287  al_throwerr(Context, AL_INVALID_ENUM);
288  }
289  }
290  al_endtry;
291 
292  ALCcontext_DecRef(Context);
293 
294  return value;
295 }
296 
298 {
299  ALCcontext *Context;
300 
301  if(values)
302  {
303  switch(pname)
304  {
305  case AL_DOPPLER_FACTOR:
306  case AL_DOPPLER_VELOCITY:
307  case AL_DISTANCE_MODEL:
308  case AL_SPEED_OF_SOUND:
310  values[0] = alGetBoolean(pname);
311  return;
312  }
313  }
314 
315  Context = GetContextRef();
316  if(!Context) return;
317 
318  al_try
319  {
320  CHECK_VALUE(Context, values);
321  switch(pname)
322  {
323  default:
324  al_throwerr(Context, AL_INVALID_ENUM);
325  }
326  }
327  al_endtry;
328 
329  ALCcontext_DecRef(Context);
330 }
331 
333 {
334  ALCcontext *Context;
335 
336  if(values)
337  {
338  switch(pname)
339  {
340  case AL_DOPPLER_FACTOR:
341  case AL_DOPPLER_VELOCITY:
342  case AL_DISTANCE_MODEL:
343  case AL_SPEED_OF_SOUND:
345  values[0] = alGetDouble(pname);
346  return;
347  }
348  }
349 
350  Context = GetContextRef();
351  if(!Context) return;
352 
353  al_try
354  {
355  CHECK_VALUE(Context, values);
356  switch(pname)
357  {
358  default:
359  al_throwerr(Context, AL_INVALID_ENUM);
360  }
361  }
362  al_endtry;
363 
364  ALCcontext_DecRef(Context);
365 }
366 
368 {
369  ALCcontext *Context;
370 
371  if(values)
372  {
373  switch(pname)
374  {
375  case AL_DOPPLER_FACTOR:
376  case AL_DOPPLER_VELOCITY:
377  case AL_DISTANCE_MODEL:
378  case AL_SPEED_OF_SOUND:
380  values[0] = alGetFloat(pname);
381  return;
382  }
383  }
384 
385  Context = GetContextRef();
386  if(!Context) return;
387 
388  al_try
389  {
390  CHECK_VALUE(Context, values);
391  switch(pname)
392  {
393  default:
394  al_throwerr(Context, AL_INVALID_ENUM);
395  }
396  }
397  al_endtry;
398 
399  ALCcontext_DecRef(Context);
400 }
401 
403 {
404  ALCcontext *Context;
405 
406  if(values)
407  {
408  switch(pname)
409  {
410  case AL_DOPPLER_FACTOR:
411  case AL_DOPPLER_VELOCITY:
412  case AL_DISTANCE_MODEL:
413  case AL_SPEED_OF_SOUND:
415  values[0] = alGetInteger(pname);
416  return;
417  }
418  }
419 
420  Context = GetContextRef();
421  if(!Context) return;
422 
423  al_try
424  {
425  CHECK_VALUE(Context, values);
426  switch(pname)
427  {
428  default:
429  al_throwerr(Context, AL_INVALID_ENUM);
430  }
431  }
432  al_endtry;
433 
434  ALCcontext_DecRef(Context);
435 }
436 
438 {
439  const ALchar *value;
440  ALCcontext *Context;
441 
442  Context = GetContextRef();
443  if(!Context) return NULL;
444 
445  al_try
446  {
447  switch(pname)
448  {
449  case AL_VENDOR:
450  value = alVendor;
451  break;
452 
453  case AL_VERSION:
454  value = alVersion;
455  break;
456 
457  case AL_RENDERER:
458  value = alRenderer;
459  break;
460 
461  case AL_EXTENSIONS:
462  value = Context->ExtensionList;
463  break;
464 
465  case AL_NO_ERROR:
466  value = alNoError;
467  break;
468 
469  case AL_INVALID_NAME:
470  value = alErrInvalidName;
471  break;
472 
473  case AL_INVALID_ENUM:
474  value = alErrInvalidEnum;
475  break;
476 
477  case AL_INVALID_VALUE:
478  value = alErrInvalidValue;
479  break;
480 
482  value = alErrInvalidOp;
483  break;
484 
485  case AL_OUT_OF_MEMORY:
486  value = alErrOutOfMemory;
487  break;
488 
489  default:
490  al_throwerr(Context, AL_INVALID_ENUM);
491  }
492  }
493  al_catchany()
494  {
495  value = NULL;
496  }
497  al_endtry;
498 
499  ALCcontext_DecRef(Context);
500 
501  return value;
502 }
503 
505 {
506  ALCcontext *Context;
507 
508  Context = GetContextRef();
509  if(!Context) return;
510 
511  al_try
512  {
513  CHECK_VALUE(Context, value >= 0.0f && isfinite(value));
514 
515  Context->DopplerFactor = value;
516  Context->UpdateSources = AL_TRUE;
517  }
518  al_endtry;
519 
520  ALCcontext_DecRef(Context);
521 }
522 
524 {
525  ALCcontext *Context;
526 
527  Context = GetContextRef();
528  if(!Context) return;
529 
530  al_try
531  {
532  CHECK_VALUE(Context, value >= 0.0f && isfinite(value));
533 
534  Context->DopplerVelocity = value;
535  Context->UpdateSources = AL_TRUE;
536  }
537  al_endtry;
538 
539  ALCcontext_DecRef(Context);
540 }
541 
543 {
544  ALCcontext *Context;
545 
546  Context = GetContextRef();
547  if(!Context) return;
548 
549  al_try
550  {
551  CHECK_VALUE(Context, value > 0.0f && isfinite(value));
552 
553  Context->SpeedOfSound = value;
554  Context->UpdateSources = AL_TRUE;
555  }
556  al_endtry;
557 
558  ALCcontext_DecRef(Context);
559 }
560 
562 {
563  ALCcontext *Context;
564 
565  Context = GetContextRef();
566  if(!Context) return;
567 
568  al_try
569  {
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 ||
577 
578  Context->DistanceModel = value;
579  if(!Context->SourceDistanceModel)
580  Context->UpdateSources = AL_TRUE;
581  }
582  al_endtry;
583 
584  ALCcontext_DecRef(Context);
585 }
586 
587 
589 {
590  ALCcontext *Context;
591 
592  Context = GetContextRef();
593  if(!Context) return;
594 
595  if(!Context->DeferUpdates)
596  {
597  ALboolean UpdateSources;
598  ALsource **src, **src_end;
599  ALeffectslot **slot, **slot_end;
600  FPUCtl oldMode;
601 
602  SetMixerFPUMode(&oldMode);
603 
604  LockContext(Context);
605  Context->DeferUpdates = AL_TRUE;
606 
607  /* Make sure all pending updates are performed */
608  UpdateSources = ExchangeInt(&Context->UpdateSources, AL_FALSE);
609 
610  src = Context->ActiveSources;
611  src_end = src + Context->ActiveSourceCount;
612  while(src != src_end)
613  {
614  if((*src)->state != AL_PLAYING)
615  {
616  Context->ActiveSourceCount--;
617  *src = *(--src_end);
618  continue;
619  }
620 
621  if(ExchangeInt(&(*src)->NeedsUpdate, AL_FALSE) || UpdateSources)
622  ALsource_Update(*src, Context);
623 
624  src++;
625  }
626 
627  slot = Context->ActiveEffectSlots;
628  slot_end = slot + Context->ActiveEffectSlotCount;
629  while(slot != slot_end)
630  {
631  if(ExchangeInt(&(*slot)->NeedsUpdate, AL_FALSE))
632  ALeffectState_Update((*slot)->EffectState, Context->Device, *slot);
633  slot++;
634  }
635 
636  UnlockContext(Context);
637  RestoreFPUMode(&oldMode);
638  }
639 
640  ALCcontext_DecRef(Context);
641 }
642 
644 {
645  ALCcontext *Context;
646 
647  Context = GetContextRef();
648  if(!Context) return;
649 
650  if(ExchangeInt(&Context->DeferUpdates, AL_FALSE))
651  {
652  ALsizei pos;
653 
654  LockContext(Context);
655  LockUIntMapRead(&Context->SourceMap);
656  for(pos = 0;pos < Context->SourceMap.size;pos++)
657  {
658  ALsource *Source = Context->SourceMap.array[pos].value;
659  ALenum new_state;
660 
661  if((Source->state == AL_PLAYING || Source->state == AL_PAUSED) &&
662  Source->Offset >= 0.0)
663  ApplyOffset(Source);
664 
665  new_state = ExchangeInt(&Source->new_state, AL_NONE);
666  if(new_state)
667  SetSourceState(Source, Context, new_state);
668  }
669  UnlockUIntMapRead(&Context->SourceMap);
670  UnlockContext(Context);
671  }
672 
673  ALCcontext_DecRef(Context);
674 }
ALdouble Offset
Definition: alSource.h:118
enum DistanceModel DistanceModel
Definition: alMain.h:688
#define AL_APIENTRY
Definition: al.h:21
#define AL_VERSION
Definition: al.h:385
volatile ALenum UpdateSources
Definition: alMain.h:686
volatile ALfloat DopplerFactor
Definition: alMain.h:691
void ALvoid
Definition: al.h:74
#define AL_INVERSE_DISTANCE_CLAMPED
Definition: al.h:446
#define AL_NONE
Definition: al.h:80
AL_API void AL_APIENTRY alGetDoublev(ALenum param, ALdouble *values)
Definition: alState.c:332
static const ALchar alErrInvalidOp[]
Definition: alState.c:41
#define CHECK_VALUE(ctx, cond)
Definition: alMain.h:875
#define ALeffectState_Update(a, b, c)
volatile ALenum state
Definition: alSource.h:125
#define AL_TRUE
Definition: al.h:86
static const ALchar alErrOutOfMemory[]
Definition: alState.c:42
char ALchar
Definition: al.h:41
#define NULL
Definition: ftobjs.h:61
ALsizei ActiveEffectSlotCount
Definition: alMain.h:701
struct ALsource ** ActiveSources
Definition: alMain.h:696
GLclampf f
Definition: glew.h:3390
#define ALsource_Update(s, a)
Definition: alSource.h:179
struct UIntMap::@59 * array
volatile ALfloat SpeedOfSound
Definition: alMain.h:693
#define al_throwerr(ctx, err)
Definition: alMain.h:866
#define AL_INVALID_VALUE
Definition: al.h:373
const ALCchar * ExtensionList
Definition: alMain.h:705
int ALsizei
Definition: al.h:62
#define al_try
Definition: alMain.h:838
int ALint
Definition: al.h:56
UIntMap SourceMap
Definition: alMain.h:681
#define AL_FALSE
Definition: al.h:83
static const ALchar alNoError[]
Definition: alState.c:37
static const ALchar alRenderer[]
Definition: alState.c:34
AL_API ALboolean AL_APIENTRY alIsEnabled(ALenum capability)
Definition: alState.c:94
#define al_endtry
Definition: alMain.h:853
AL_API void AL_APIENTRY alDopplerFactor(ALfloat value)
Definition: alState.c:504
GLenum pname
Definition: gl2ext.h:806
void RestoreFPUMode(const FPUCtl *ctl)
Definition: helpers.c:235
AL_API void AL_APIENTRY alGetBooleanv(ALenum param, ALboolean *values)
Definition: alState.c:297
void SetMixerFPUMode(FPUCtl *ctl)
Definition: helpers.c:193
ALCcontext * GetContextRef(void)
Definition: ALc.c:1999
AL_API ALdouble AL_APIENTRY alGetDouble(ALenum param)
Definition: alState.c:168
ALsizei ActiveSourceCount
Definition: alMain.h:697
AL_API ALboolean AL_APIENTRY alGetBoolean(ALenum param)
Definition: alState.c:121
float ALfloat
Definition: al.h:68
#define AL_PAUSED
Definition: al.h:240
#define AL_EXPONENT_DISTANCE
Definition: al.h:449
ALvoid * value
Definition: alMain.h:310
AL_API void AL_APIENTRY alDopplerVelocity(ALfloat value)
Definition: alState.c:523
#define AL_EXPONENT_DISTANCE_CLAMPED
Definition: al.h:450
double ALdouble
Definition: al.h:71
AL_API ALvoid AL_APIENTRY alDeferUpdatesSOFT(void)
Definition: alState.c:588
#define AL_DOPPLER_VELOCITY
Definition: al.h:408
static const ALchar alErrInvalidName[]
Definition: alState.c:38
#define AL_PLAYING
Definition: al.h:239
#define AL_EXTENSIONS
Definition: al.h:389
AL_API void AL_APIENTRY alGetFloatv(ALenum param, ALfloat *values)
Definition: alState.c:367
#define AL_SPEED_OF_SOUND
Definition: al.h:420
#define al_catchany()
Definition: alMain.h:851
#define AL_INVALID_NAME
Definition: al.h:367
static const ALchar alErrInvalidEnum[]
Definition: alState.c:39
#define AL_DEFERRED_UPDATES_SOFT
Definition: alMain.h:20
#define AL_DISTANCE_MODEL
Definition: al.h:441
#define AL_INVERSE_DISTANCE
Definition: al.h:445
ALsizei size
Definition: alMain.h:312
AL_API ALint AL_APIENTRY alGetInteger(ALenum param)
Definition: alState.c:254
static __inline void UnlockUIntMapRead(UIntMap *map)
Definition: alMain.h:327
static const ALchar alVendor[]
Definition: alState.c:32
ALenum new_state
Definition: alSource.h:126
volatile ALboolean SourceDistanceModel
Definition: alMain.h:689
int ALenum
Definition: al.h:65
volatile ALenum DeferUpdates
Definition: alMain.h:694
#define AL_API
Definition: al.h:14
AL_API ALfloat AL_APIENTRY alGetFloat(ALenum param)
Definition: alState.c:211
volatile ALfloat DopplerVelocity
Definition: alMain.h:692
AL_API void AL_APIENTRY alGetIntegerv(ALenum param, ALint *values)
Definition: alState.c:402
static const ALchar alVersion[]
Definition: alState.c:33
#define AL_LINEAR_DISTANCE_CLAMPED
Definition: al.h:448
AL_API void AL_APIENTRY alEnable(ALenum capability)
Definition: alState.c:44
static const ALchar alErrInvalidValue[]
Definition: alState.c:40
void ALCcontext_DecRef(ALCcontext *context)
Definition: ALc.c:1949
EGLSurface EGLint void ** value
Definition: eglext.h:301
Definition: alMain.h:738
AL_API const ALchar *AL_APIENTRY alGetString(ALenum param)
Definition: alState.c:437
AL_API ALvoid AL_APIENTRY alProcessUpdatesSOFT(void)
Definition: alState.c:643
static __inline void LockUIntMapRead(UIntMap *map)
Definition: alMain.h:325
#define AL_OUT_OF_MEMORY
Definition: al.h:379
AL_API void AL_APIENTRY alDisable(ALenum capability)
Definition: alState.c:69
char ALboolean
Definition: al.h:38
AL_API void AL_APIENTRY alDistanceModel(ALenum distanceModel)
Definition: alState.c:561
#define AL_DOPPLER_FACTOR
Definition: al.h:400
ALCdevice * Device
Definition: alMain.h:704
static __inline void LockContext(ALCcontext *context)
Definition: alMain.h:728
GLenum src
Definition: glew.h:2396
#define AL_VENDOR
Definition: al.h:383
static __inline void UnlockContext(ALCcontext *context)
Definition: alMain.h:730
struct ALeffectslot ** ActiveEffectSlots
Definition: alMain.h:700
#define AL_INVALID_ENUM
Definition: al.h:370
ALvoid SetSourceState(ALsource *Source, ALCcontext *Context, ALenum state)
Definition: alSource.c:2312
ALboolean ApplyOffset(ALsource *Source)
Definition: alSource.c:2596
#define AL_NO_ERROR
Definition: al.h:364
#define AL_INVALID_OPERATION
Definition: al.h:376
AL_API void AL_APIENTRY alSpeedOfSound(ALfloat value)
Definition: alState.c:542
GLint GLsizei const GLuint64 * values
Definition: glew.h:3473
#define AL_LINEAR_DISTANCE
Definition: al.h:447
#define AL_RENDERER
Definition: al.h:387
#define AL_SOURCE_DISTANCE_MODEL
Definition: alext.h:164