Make the context's LastError volatile
[openal-soft.git] / OpenAL32 / Include / alMain.h
blob1110e89eba4fe7efbfe89f7ad4a4b1a02d761aaf
1 #ifndef AL_MAIN_H
2 #define AL_MAIN_H
4 #include <string.h>
5 #include <stdio.h>
6 #include <stdarg.h>
7 #include <assert.h>
8 #include <math.h>
10 #ifdef HAVE_FENV_H
11 #include <fenv.h>
12 #endif
14 #include "AL/al.h"
15 #include "AL/alc.h"
16 #include "AL/alext.h"
18 #ifndef AL_SOFT_deferred_updates
19 #define AL_SOFT_deferred_updates 1
20 #define AL_DEFERRED_UPDATES_SOFT 0xC002
21 typedef ALvoid (AL_APIENTRY*LPALDEFERUPDATESSOFT)(void);
22 typedef ALvoid (AL_APIENTRY*LPALPROCESSUPDATESSOFT)(void);
23 #ifdef AL_ALEXT_PROTOTYPES
24 AL_API ALvoid AL_APIENTRY alDeferUpdatesSOFT(void);
25 AL_API ALvoid AL_APIENTRY alProcessUpdatesSOFT(void);
26 #endif
27 #endif
30 #if defined(HAVE_STDINT_H)
31 #include <stdint.h>
32 typedef int64_t ALint64;
33 typedef uint64_t ALuint64;
34 #elif defined(HAVE___INT64)
35 typedef __int64 ALint64;
36 typedef unsigned __int64 ALuint64;
37 #elif (SIZEOF_LONG == 8)
38 typedef long ALint64;
39 typedef unsigned long ALuint64;
40 #elif (SIZEOF_LONG_LONG == 8)
41 typedef long long ALint64;
42 typedef unsigned long long ALuint64;
43 #endif
45 typedef ptrdiff_t ALintptrEXT;
46 typedef ptrdiff_t ALsizeiptrEXT;
48 #define MAKEU64(x,y) (((ALuint64)(x)<<32)|(ALuint64)(y))
50 #ifdef HAVE_GCC_FORMAT
51 #define PRINTF_STYLE(x, y) __attribute__((format(printf, (x), (y))))
52 #else
53 #define PRINTF_STYLE(x, y)
54 #endif
57 static const union {
58 ALuint u;
59 ALubyte b[sizeof(ALuint)];
60 } EndianTest = { 1 };
61 #define IS_LITTLE_ENDIAN (EndianTest.b[0] == 1)
63 #define COUNTOF(x) (sizeof((x))/sizeof((x)[0]))
65 #ifdef _WIN32
67 #define WIN32_LEAN_AND_MEAN
68 #include <windows.h>
70 typedef DWORD pthread_key_t;
71 int pthread_key_create(pthread_key_t *key, void (*callback)(void*));
72 int pthread_key_delete(pthread_key_t key);
73 void *pthread_getspecific(pthread_key_t key);
74 int pthread_setspecific(pthread_key_t key, void *val);
76 #define HAVE_DYNLOAD 1
77 void *LoadLib(const char *name);
78 void CloseLib(void *handle);
79 void *GetSymbol(void *handle, const char *name);
81 WCHAR *strdupW(const WCHAR *str);
83 typedef LONG pthread_once_t;
84 #define PTHREAD_ONCE_INIT 0
85 void pthread_once(pthread_once_t *once, void (*callback)(void));
87 static __inline int sched_yield(void)
88 { SwitchToThread(); return 0; }
90 #else
92 #include <unistd.h>
93 #include <assert.h>
94 #include <pthread.h>
95 #include <sys/time.h>
96 #include <time.h>
97 #include <errno.h>
99 #define IsBadWritePtr(a,b) ((a) == NULL && (b) != 0)
101 typedef pthread_mutex_t CRITICAL_SECTION;
102 void InitializeCriticalSection(CRITICAL_SECTION *cs);
103 void DeleteCriticalSection(CRITICAL_SECTION *cs);
104 void EnterCriticalSection(CRITICAL_SECTION *cs);
105 void LeaveCriticalSection(CRITICAL_SECTION *cs);
107 ALuint timeGetTime(void);
108 void Sleep(ALuint t);
110 #if defined(HAVE_DLFCN_H)
111 #define HAVE_DYNLOAD 1
112 void *LoadLib(const char *name);
113 void CloseLib(void *handle);
114 void *GetSymbol(void *handle, const char *name);
115 #endif
117 #endif
119 typedef void *volatile XchgPtr;
121 #if defined(__GNUC__) && (__GNUC__ > 4 || (__GNUC__ == 4 && __GNUC_MINOR__ >= 1))
122 typedef ALuint RefCount;
123 static __inline RefCount IncrementRef(volatile RefCount *ptr)
124 { return __sync_add_and_fetch(ptr, 1); }
125 static __inline RefCount DecrementRef(volatile RefCount *ptr)
126 { return __sync_sub_and_fetch(ptr, 1); }
128 static __inline int ExchangeInt(volatile int *ptr, int newval)
130 return __sync_lock_test_and_set(ptr, newval);
132 static __inline void *ExchangePtr(XchgPtr *ptr, void *newval)
134 return __sync_lock_test_and_set(ptr, newval);
136 static __inline ALboolean CompExchangeInt(volatile int *ptr, int oldval, int newval)
138 return __sync_bool_compare_and_swap(ptr, oldval, newval);
140 static __inline ALboolean CompExchangePtr(XchgPtr *ptr, void *oldval, void *newval)
142 return __sync_bool_compare_and_swap(ptr, oldval, newval);
145 #elif defined(__GNUC__) && (defined(__i386__) || defined(__x86_64__))
147 static __inline int xaddl(volatile int *dest, int incr)
149 int ret;
150 __asm__ __volatile__("lock; xaddl %0,(%1)"
151 : "=r" (ret)
152 : "r" (dest), "0" (incr)
153 : "memory");
154 return ret;
157 typedef int RefCount;
158 static __inline RefCount IncrementRef(volatile RefCount *ptr)
159 { return xaddl(ptr, 1)+1; }
160 static __inline RefCount DecrementRef(volatile RefCount *ptr)
161 { return xaddl(ptr, -1)-1; }
163 static __inline int ExchangeInt(volatile int *dest, int newval)
165 int ret;
166 __asm__ __volatile__("lock; xchgl %0,(%1)"
167 : "=r" (ret)
168 : "r" (dest), "0" (newval)
169 : "memory");
170 return ret;
173 static __inline ALboolean CompExchangeInt(volatile int *dest, int oldval, int newval)
175 int ret;
176 __asm__ __volatile__("lock; cmpxchgl %2,(%1)"
177 : "=a" (ret)
178 : "r" (dest), "r" (newval), "0" (oldval)
179 : "memory");
180 return ret == oldval;
183 static __inline void *ExchangePtr(XchgPtr *dest, void *newval)
185 void *ret;
186 __asm__ __volatile__(
187 #ifdef __i386__
188 "lock; xchgl %0,(%1)"
189 #else
190 "lock; xchgq %0,(%1)"
191 #endif
192 : "=r" (ret)
193 : "r" (dest), "0" (newval)
194 : "memory"
196 return ret;
199 static __inline ALboolean CompExchangePtr(XchgPtr *dest, void *oldval, void *newval)
201 void *ret;
202 __asm__ __volatile__(
203 #ifdef __i386__
204 "lock; cmpxchgl %2,(%1)"
205 #else
206 "lock; cmpxchgq %2,(%1)"
207 #endif
208 : "=a" (ret)
209 : "r" (dest), "r" (newval), "0" (oldval)
210 : "memory"
212 return ret == oldval;
215 #elif defined(_WIN32)
217 typedef LONG RefCount;
218 static __inline RefCount IncrementRef(volatile RefCount *ptr)
219 { return InterlockedIncrement(ptr); }
220 static __inline RefCount DecrementRef(volatile RefCount *ptr)
221 { return InterlockedDecrement(ptr); }
223 extern ALbyte LONG_size_does_not_match_int[(sizeof(LONG)==sizeof(int))?1:-1];
225 static __inline int ExchangeInt(volatile int *ptr, int newval)
227 union {
228 volatile int *i;
229 volatile LONG *l;
230 } u = { ptr };
231 return InterlockedExchange(u.l, newval);
233 static __inline void *ExchangePtr(XchgPtr *ptr, void *newval)
235 return InterlockedExchangePointer(ptr, newval);
237 static __inline ALboolean CompExchangeInt(volatile int *ptr, int oldval, int newval)
239 union {
240 volatile int *i;
241 volatile LONG *l;
242 } u = { ptr };
243 return InterlockedCompareExchange(u.l, newval, oldval) == oldval;
245 static __inline ALboolean CompExchangePtr(XchgPtr *ptr, void *oldval, void *newval)
247 return InterlockedCompareExchangePointer(ptr, newval, oldval) == oldval;
250 #elif defined(__APPLE__)
252 #include <libkern/OSAtomic.h>
254 typedef int32_t RefCount;
255 static __inline RefCount IncrementRef(volatile RefCount *ptr)
256 { return OSAtomicIncrement32Barrier(ptr); }
257 static __inline RefCount DecrementRef(volatile RefCount *ptr)
258 { return OSAtomicDecrement32Barrier(ptr); }
260 static __inline int ExchangeInt(volatile int *ptr, int newval)
262 /* Really? No regular old atomic swap? */
263 int oldval;
264 do {
265 oldval = *ptr;
266 } while(!OSAtomicCompareAndSwap32Barrier(oldval, newval, ptr));
267 return oldval;
269 static __inline void *ExchangePtr(XchgPtr *ptr, void *newval)
271 void *oldval;
272 do {
273 oldval = *ptr;
274 } while(!OSAtomicCompareAndSwapPtrBarrier(oldval, newval, ptr));
275 return oldval;
277 static __inline ALboolean CompExchangeInt(volatile int *ptr, int oldval, int newval)
279 return OSAtomicCompareAndSwap32Barrier(oldval, newval, ptr);
281 static __inline ALboolean CompExchangePtr(XchgPtr *ptr, void *oldval, void *newval)
283 return OSAtomicCompareAndSwapPtrBarrier(oldval, newval, ptr);
286 #else
287 #error "No atomic functions available on this platform!"
288 typedef ALuint RefCount;
289 #endif
292 typedef struct {
293 volatile RefCount read_count;
294 volatile RefCount write_count;
295 volatile ALenum read_lock;
296 volatile ALenum read_entry_lock;
297 volatile ALenum write_lock;
298 } RWLock;
300 void RWLockInit(RWLock *lock);
301 void ReadLock(RWLock *lock);
302 void ReadUnlock(RWLock *lock);
303 void WriteLock(RWLock *lock);
304 void WriteUnlock(RWLock *lock);
307 typedef struct UIntMap {
308 struct {
309 ALuint key;
310 ALvoid *value;
311 } *array;
312 ALsizei size;
313 ALsizei maxsize;
314 ALsizei limit;
315 RWLock lock;
316 } UIntMap;
317 extern UIntMap TlsDestructor;
319 void InitUIntMap(UIntMap *map, ALsizei limit);
320 void ResetUIntMap(UIntMap *map);
321 ALenum InsertUIntMapEntry(UIntMap *map, ALuint key, ALvoid *value);
322 ALvoid *RemoveUIntMapKey(UIntMap *map, ALuint key);
323 ALvoid *LookupUIntMapKey(UIntMap *map, ALuint key);
325 static __inline void LockUIntMapRead(UIntMap *map)
326 { ReadLock(&map->lock); }
327 static __inline void UnlockUIntMapRead(UIntMap *map)
328 { ReadUnlock(&map->lock); }
329 static __inline void LockUIntMapWrite(UIntMap *map)
330 { WriteLock(&map->lock); }
331 static __inline void UnlockUIntMapWrite(UIntMap *map)
332 { WriteUnlock(&map->lock); }
335 #ifdef __cplusplus
336 extern "C" {
337 #endif
339 struct Hrtf;
342 #define DEFAULT_OUTPUT_RATE (44100)
343 #define MIN_OUTPUT_RATE (8000)
346 // Find the next power-of-2 for non-power-of-2 numbers.
347 static __inline ALuint NextPowerOf2(ALuint value)
349 if(value > 0)
351 value--;
352 value |= value>>1;
353 value |= value>>2;
354 value |= value>>4;
355 value |= value>>8;
356 value |= value>>16;
358 return value+1;
361 /* Fast float-to-int conversion. Assumes the FPU is already in round-to-zero
362 * mode. */
363 static __inline ALint fastf2i(ALfloat f)
365 #ifdef HAVE_LRINTF
366 return lrintf(f);
367 #elif defined(_MSC_VER) && defined(_M_IX86)
368 ALint i;
369 __asm fld f
370 __asm fistp i
371 return i;
372 #else
373 return (ALint)f;
374 #endif
377 /* Fast float-to-uint conversion. Assumes the FPU is already in round-to-zero
378 * mode. */
379 static __inline ALuint fastf2u(ALfloat f)
380 { return fastf2i(f); }
383 enum DevProbe {
384 ALL_DEVICE_PROBE,
385 CAPTURE_DEVICE_PROBE
388 typedef struct {
389 ALCenum (*OpenPlayback)(ALCdevice*, const ALCchar*);
390 void (*ClosePlayback)(ALCdevice*);
391 ALCboolean (*ResetPlayback)(ALCdevice*);
392 ALCboolean (*StartPlayback)(ALCdevice*);
393 void (*StopPlayback)(ALCdevice*);
395 ALCenum (*OpenCapture)(ALCdevice*, const ALCchar*);
396 void (*CloseCapture)(ALCdevice*);
397 void (*StartCapture)(ALCdevice*);
398 void (*StopCapture)(ALCdevice*);
399 ALCenum (*CaptureSamples)(ALCdevice*, void*, ALCuint);
400 ALCuint (*AvailableSamples)(ALCdevice*);
402 void (*Lock)(ALCdevice*);
403 void (*Unlock)(ALCdevice*);
405 ALint64 (*GetLatency)(ALCdevice*);
406 } BackendFuncs;
408 struct BackendInfo {
409 const char *name;
410 ALCboolean (*Init)(BackendFuncs*);
411 void (*Deinit)(void);
412 void (*Probe)(enum DevProbe);
413 BackendFuncs Funcs;
416 ALCboolean alc_alsa_init(BackendFuncs *func_list);
417 void alc_alsa_deinit(void);
418 void alc_alsa_probe(enum DevProbe type);
419 ALCboolean alc_oss_init(BackendFuncs *func_list);
420 void alc_oss_deinit(void);
421 void alc_oss_probe(enum DevProbe type);
422 ALCboolean alc_solaris_init(BackendFuncs *func_list);
423 void alc_solaris_deinit(void);
424 void alc_solaris_probe(enum DevProbe type);
425 ALCboolean alc_sndio_init(BackendFuncs *func_list);
426 void alc_sndio_deinit(void);
427 void alc_sndio_probe(enum DevProbe type);
428 ALCboolean alcMMDevApiInit(BackendFuncs *func_list);
429 void alcMMDevApiDeinit(void);
430 void alcMMDevApiProbe(enum DevProbe type);
431 ALCboolean alcDSoundInit(BackendFuncs *func_list);
432 void alcDSoundDeinit(void);
433 void alcDSoundProbe(enum DevProbe type);
434 ALCboolean alcWinMMInit(BackendFuncs *FuncList);
435 void alcWinMMDeinit(void);
436 void alcWinMMProbe(enum DevProbe type);
437 ALCboolean alc_pa_init(BackendFuncs *func_list);
438 void alc_pa_deinit(void);
439 void alc_pa_probe(enum DevProbe type);
440 ALCboolean alc_wave_init(BackendFuncs *func_list);
441 void alc_wave_deinit(void);
442 void alc_wave_probe(enum DevProbe type);
443 ALCboolean alc_pulse_init(BackendFuncs *func_list);
444 void alc_pulse_deinit(void);
445 void alc_pulse_probe(enum DevProbe type);
446 ALCboolean alc_ca_init(BackendFuncs *func_list);
447 void alc_ca_deinit(void);
448 void alc_ca_probe(enum DevProbe type);
449 ALCboolean alc_opensl_init(BackendFuncs *func_list);
450 void alc_opensl_deinit(void);
451 void alc_opensl_probe(enum DevProbe type);
452 ALCboolean alc_null_init(BackendFuncs *func_list);
453 void alc_null_deinit(void);
454 void alc_null_probe(enum DevProbe type);
455 ALCboolean alc_loopback_init(BackendFuncs *func_list);
456 void alc_loopback_deinit(void);
457 void alc_loopback_probe(enum DevProbe type);
460 enum DistanceModel {
461 InverseDistanceClamped = AL_INVERSE_DISTANCE_CLAMPED,
462 LinearDistanceClamped = AL_LINEAR_DISTANCE_CLAMPED,
463 ExponentDistanceClamped = AL_EXPONENT_DISTANCE_CLAMPED,
464 InverseDistance = AL_INVERSE_DISTANCE,
465 LinearDistance = AL_LINEAR_DISTANCE,
466 ExponentDistance = AL_EXPONENT_DISTANCE,
467 DisableDistance = AL_NONE,
469 DefaultDistanceModel = InverseDistanceClamped
472 enum Resampler {
473 PointResampler,
474 LinearResampler,
475 CubicResampler,
477 ResamplerMax,
480 enum Channel {
481 FrontLeft = 0,
482 FrontRight,
483 FrontCenter,
484 LFE,
485 BackLeft,
486 BackRight,
487 BackCenter,
488 SideLeft,
489 SideRight,
491 MaxChannels,
495 /* Device formats */
496 enum DevFmtType {
497 DevFmtByte = ALC_BYTE_SOFT,
498 DevFmtUByte = ALC_UNSIGNED_BYTE_SOFT,
499 DevFmtShort = ALC_SHORT_SOFT,
500 DevFmtUShort = ALC_UNSIGNED_SHORT_SOFT,
501 DevFmtInt = ALC_INT_SOFT,
502 DevFmtUInt = ALC_UNSIGNED_INT_SOFT,
503 DevFmtFloat = ALC_FLOAT_SOFT,
505 DevFmtTypeDefault = DevFmtFloat
507 enum DevFmtChannels {
508 DevFmtMono = ALC_MONO_SOFT,
509 DevFmtStereo = ALC_STEREO_SOFT,
510 DevFmtQuad = ALC_QUAD_SOFT,
511 DevFmtX51 = ALC_5POINT1_SOFT,
512 DevFmtX61 = ALC_6POINT1_SOFT,
513 DevFmtX71 = ALC_7POINT1_SOFT,
515 /* Similar to 5.1, except using the side channels instead of back */
516 DevFmtX51Side = 0x80000000,
518 DevFmtChannelsDefault = DevFmtStereo
521 ALuint BytesFromDevFmt(enum DevFmtType type);
522 ALuint ChannelsFromDevFmt(enum DevFmtChannels chans);
523 static __inline ALuint FrameSizeFromDevFmt(enum DevFmtChannels chans,
524 enum DevFmtType type)
526 return ChannelsFromDevFmt(chans) * BytesFromDevFmt(type);
530 extern const struct EffectList {
531 const char *name;
532 int type;
533 const char *ename;
534 ALenum val;
535 } EffectList[];
538 enum DeviceType {
539 Playback,
540 Capture,
541 Loopback
545 /* Size for temporary storage of buffer data, in ALfloats. Larger values need
546 * more memory, while smaller values may need more iterations. The value needs
547 * to be a sensible size, however, as it constrains the max stepping value used
548 * for mixing, as well as the maximum number of samples per mixing iteration.
550 * The mixer requires being able to do two samplings per mixing loop. With the
551 * cubic resampler (which requires 3 padding samples), this limits a 2048
552 * buffer size to about 2044. This means that buffer_freq*source_pitch cannot
553 * exceed device_freq*2044 for a 32-bit buffer.
555 #ifndef BUFFERSIZE
556 #define BUFFERSIZE 2048
557 #endif
560 struct ALCdevice_struct
562 volatile RefCount ref;
564 ALCboolean Connected;
565 enum DeviceType Type;
567 CRITICAL_SECTION Mutex;
569 ALuint Frequency;
570 ALuint UpdateSize;
571 ALuint NumUpdates;
572 enum DevFmtChannels FmtChans;
573 enum DevFmtType FmtType;
575 ALCchar *DeviceName;
577 volatile ALCenum LastError;
579 // Maximum number of sources that can be created
580 ALuint MaxNoOfSources;
581 // Maximum number of slots that can be created
582 ALuint AuxiliaryEffectSlotMax;
584 ALCuint NumMonoSources;
585 ALCuint NumStereoSources;
586 ALuint NumAuxSends;
588 // Map of Buffers for this device
589 UIntMap BufferMap;
591 // Map of Effects for this device
592 UIntMap EffectMap;
594 // Map of Filters for this device
595 UIntMap FilterMap;
597 /* HRTF filter tables */
598 const struct Hrtf *Hrtf;
600 // Stereo-to-binaural filter
601 struct bs2b *Bs2b;
602 ALCint Bs2bLevel;
604 // Device flags
605 ALuint Flags;
607 ALuint ChannelOffsets[MaxChannels];
609 enum Channel Speaker2Chan[MaxChannels];
610 ALfloat SpeakerAngle[MaxChannels];
611 ALuint NumChan;
613 /* Temp storage used for mixing. +1 for the predictive sample. */
614 ALIGN(16) ALfloat SampleData1[BUFFERSIZE+1];
615 ALIGN(16) ALfloat SampleData2[BUFFERSIZE+1];
617 // Dry path buffer mix
618 ALIGN(16) ALfloat DryBuffer[MaxChannels][BUFFERSIZE];
620 ALIGN(16) ALfloat ClickRemoval[MaxChannels];
621 ALIGN(16) ALfloat PendingClicks[MaxChannels];
623 /* Default effect slot */
624 struct ALeffectslot *DefaultSlot;
626 // Contexts created on this device
627 ALCcontext *volatile ContextList;
629 BackendFuncs *Funcs;
630 void *ExtraData; // For the backend's use
632 ALCdevice *volatile next;
635 #define ALCdevice_OpenPlayback(a,b) ((a)->Funcs->OpenPlayback((a), (b)))
636 #define ALCdevice_ClosePlayback(a) ((a)->Funcs->ClosePlayback((a)))
637 #define ALCdevice_ResetPlayback(a) ((a)->Funcs->ResetPlayback((a)))
638 #define ALCdevice_StartPlayback(a) ((a)->Funcs->StartPlayback((a)))
639 #define ALCdevice_StopPlayback(a) ((a)->Funcs->StopPlayback((a)))
640 #define ALCdevice_OpenCapture(a,b) ((a)->Funcs->OpenCapture((a), (b)))
641 #define ALCdevice_CloseCapture(a) ((a)->Funcs->CloseCapture((a)))
642 #define ALCdevice_StartCapture(a) ((a)->Funcs->StartCapture((a)))
643 #define ALCdevice_StopCapture(a) ((a)->Funcs->StopCapture((a)))
644 #define ALCdevice_CaptureSamples(a,b,c) ((a)->Funcs->CaptureSamples((a), (b), (c)))
645 #define ALCdevice_AvailableSamples(a) ((a)->Funcs->AvailableSamples((a)))
646 #define ALCdevice_Lock(a) ((a)->Funcs->Lock((a)))
647 #define ALCdevice_Unlock(a) ((a)->Funcs->Unlock((a)))
648 #define ALCdevice_GetLatency(a) ((a)->Funcs->GetLatency((a)))
650 // Frequency was requested by the app or config file
651 #define DEVICE_FREQUENCY_REQUEST (1<<1)
652 // Channel configuration was requested by the config file
653 #define DEVICE_CHANNELS_REQUEST (1<<2)
654 // Sample type was requested by the config file
655 #define DEVICE_SAMPLE_TYPE_REQUEST (1<<3)
657 // Stereo sources cover 120-degree angles around +/-90
658 #define DEVICE_WIDE_STEREO (1<<16)
660 // Specifies if the device is currently running
661 #define DEVICE_RUNNING (1<<31)
663 /* Invalid channel offset */
664 #define INVALID_OFFSET (~0u)
667 #define LookupBuffer(m, k) ((struct ALbuffer*)LookupUIntMapKey(&(m)->BufferMap, (k)))
668 #define LookupEffect(m, k) ((struct ALeffect*)LookupUIntMapKey(&(m)->EffectMap, (k)))
669 #define LookupFilter(m, k) ((struct ALfilter*)LookupUIntMapKey(&(m)->FilterMap, (k)))
670 #define RemoveBuffer(m, k) ((struct ALbuffer*)RemoveUIntMapKey(&(m)->BufferMap, (k)))
671 #define RemoveEffect(m, k) ((struct ALeffect*)RemoveUIntMapKey(&(m)->EffectMap, (k)))
672 #define RemoveFilter(m, k) ((struct ALfilter*)RemoveUIntMapKey(&(m)->FilterMap, (k)))
675 struct ALCcontext_struct
677 volatile RefCount ref;
679 struct ALlistener *Listener;
681 UIntMap SourceMap;
682 UIntMap EffectSlotMap;
684 volatile ALenum LastError;
686 volatile ALenum UpdateSources;
688 volatile enum DistanceModel DistanceModel;
689 volatile ALboolean SourceDistanceModel;
691 volatile ALfloat DopplerFactor;
692 volatile ALfloat DopplerVelocity;
693 volatile ALfloat SpeedOfSound;
694 volatile ALenum DeferUpdates;
696 struct ALsource **ActiveSources;
697 ALsizei ActiveSourceCount;
698 ALsizei MaxActiveSources;
700 struct ALeffectslot **ActiveEffectSlots;
701 ALsizei ActiveEffectSlotCount;
702 ALsizei MaxActiveEffectSlots;
704 ALCdevice *Device;
705 const ALCchar *ExtensionList;
707 ALCcontext *volatile next;
710 #define LookupSource(m, k) ((struct ALsource*)LookupUIntMapKey(&(m)->SourceMap, (k)))
711 #define LookupEffectSlot(m, k) ((struct ALeffectslot*)LookupUIntMapKey(&(m)->EffectSlotMap, (k)))
712 #define RemoveSource(m, k) ((struct ALsource*)RemoveUIntMapKey(&(m)->SourceMap, (k)))
713 #define RemoveEffectSlot(m, k) ((struct ALeffectslot*)RemoveUIntMapKey(&(m)->EffectSlotMap, (k)))
716 ALCcontext *GetContextRef(void);
718 void ALCcontext_IncRef(ALCcontext *context);
719 void ALCcontext_DecRef(ALCcontext *context);
721 void AppendAllDevicesList(const ALCchar *name);
722 void AppendCaptureDeviceList(const ALCchar *name);
724 void ALCdevice_LockDefault(ALCdevice *device);
725 void ALCdevice_UnlockDefault(ALCdevice *device);
726 ALint64 ALCdevice_GetLatencyDefault(ALCdevice *device);
728 static __inline void LockContext(ALCcontext *context)
729 { ALCdevice_Lock(context->Device); }
730 static __inline void UnlockContext(ALCcontext *context)
731 { ALCdevice_Unlock(context->Device); }
734 void *al_malloc(size_t alignment, size_t size);
735 void *al_calloc(size_t alignment, size_t size);
736 void al_free(void *ptr);
738 typedef struct {
739 int state;
740 #ifdef HAVE_SSE
741 int sse_state;
742 #endif
743 } FPUCtl;
744 void SetMixerFPUMode(FPUCtl *ctl);
745 void RestoreFPUMode(const FPUCtl *ctl);
747 ALvoid *StartThread(ALuint (*func)(ALvoid*), ALvoid *ptr);
748 ALuint StopThread(ALvoid *thread);
750 typedef struct RingBuffer RingBuffer;
751 RingBuffer *CreateRingBuffer(ALsizei frame_size, ALsizei length);
752 void DestroyRingBuffer(RingBuffer *ring);
753 ALsizei RingBufferSize(RingBuffer *ring);
754 void WriteRingBuffer(RingBuffer *ring, const ALubyte *data, ALsizei len);
755 void ReadRingBuffer(RingBuffer *ring, ALubyte *data, ALsizei len);
757 void ReadALConfig(void);
758 void FreeALConfig(void);
759 int ConfigValueExists(const char *blockName, const char *keyName);
760 const char *GetConfigValue(const char *blockName, const char *keyName, const char *def);
761 int GetConfigValueBool(const char *blockName, const char *keyName, int def);
762 int ConfigValueStr(const char *blockName, const char *keyName, const char **ret);
763 int ConfigValueInt(const char *blockName, const char *keyName, int *ret);
764 int ConfigValueUInt(const char *blockName, const char *keyName, unsigned int *ret);
765 int ConfigValueFloat(const char *blockName, const char *keyName, float *ret);
767 void SetRTPriority(void);
769 void SetDefaultChannelOrder(ALCdevice *device);
770 void SetDefaultWFXChannelOrder(ALCdevice *device);
772 const ALCchar *DevFmtTypeString(enum DevFmtType type);
773 const ALCchar *DevFmtChannelsString(enum DevFmtChannels chans);
775 #define HRIR_BITS (7)
776 #define HRIR_LENGTH (1<<HRIR_BITS)
777 #define HRIR_MASK (HRIR_LENGTH-1)
778 #define HRTFDELAY_BITS (20)
779 #define HRTFDELAY_FRACONE (1<<HRTFDELAY_BITS)
780 #define HRTFDELAY_MASK (HRTFDELAY_FRACONE-1)
781 const struct Hrtf *GetHrtf(ALCdevice *device);
782 void FreeHrtfs(void);
783 ALuint GetHrtfIrSize (const struct Hrtf *Hrtf);
784 ALfloat CalcHrtfDelta(ALfloat oldGain, ALfloat newGain, const ALfloat olddir[3], const ALfloat newdir[3]);
785 void GetLerpedHrtfCoeffs(const struct Hrtf *Hrtf, ALfloat elevation, ALfloat azimuth, ALfloat gain, ALfloat (*coeffs)[2], ALuint *delays);
786 ALuint GetMovingHrtfCoeffs(const struct Hrtf *Hrtf, ALfloat elevation, ALfloat azimuth, ALfloat gain, ALfloat delta, ALint counter, ALfloat (*coeffs)[2], ALuint *delays, ALfloat (*coeffStep)[2], ALint *delayStep);
788 void al_print(const char *type, const char *func, const char *fmt, ...) PRINTF_STYLE(3,4);
789 #define AL_PRINT(T, ...) al_print((T), __FUNCTION__, __VA_ARGS__)
791 extern FILE *LogFile;
792 enum LogLevel {
793 NoLog,
794 LogError,
795 LogWarning,
796 LogTrace,
797 LogRef
799 extern enum LogLevel LogLevel;
801 #define TRACEREF(...) do { \
802 if(LogLevel >= LogRef) \
803 AL_PRINT("(--)", __VA_ARGS__); \
804 } while(0)
806 #define TRACE(...) do { \
807 if(LogLevel >= LogTrace) \
808 AL_PRINT("(II)", __VA_ARGS__); \
809 } while(0)
811 #define WARN(...) do { \
812 if(LogLevel >= LogWarning) \
813 AL_PRINT("(WW)", __VA_ARGS__); \
814 } while(0)
816 #define ERR(...) do { \
817 if(LogLevel >= LogError) \
818 AL_PRINT("(EE)", __VA_ARGS__); \
819 } while(0)
822 extern ALint RTPrioLevel;
825 extern ALuint CPUCapFlags;
826 enum {
827 CPU_CAP_SSE = 1<<0,
828 CPU_CAP_NEON = 1<<1,
831 void FillCPUCaps(ALuint capfilter);
835 * Starts a try block. Must not be nested within another try block within the
836 * same function.
838 #define al_try do { \
839 int _al_err=0; \
840 _al_try_label: \
841 if(_al_err == 0)
843 * After a try or another catch block, runs the next block if the given value
844 * was thrown.
846 #define al_catch(val) else if(_al_err == (val))
848 * After a try or catch block, runs the next block for any value thrown and not
849 * caught.
851 #define al_catchany() else
852 /** Marks the end of the final catch (or the try) block. */
853 #define al_endtry } while(0)
856 * The given integer value is "thrown" so as to be caught by a catch block.
857 * Must be called in a try block within the same function. The value must not
858 * be 0.
860 #define al_throw(e) do { \
861 _al_err = (e); \
862 assert(_al_err != 0); \
863 goto _al_try_label; \
864 } while(0)
865 /** Sets an AL error on the given context, before throwing the error code. */
866 #define al_throwerr(ctx, err) do { \
867 alSetError((ctx), (err)); \
868 al_throw((err)); \
869 } while(0)
872 * Throws an AL_INVALID_VALUE error with the given ctx if the given condition
873 * is false.
875 #define CHECK_VALUE(ctx, cond) do { \
876 if(!(cond)) \
877 al_throwerr((ctx), AL_INVALID_VALUE); \
878 } while(0)
880 #ifdef __cplusplus
882 #endif
884 #endif