Add a macro to help make a 64-bit value
[openal-soft/openal-hmr.git] / OpenAL32 / Include / alMain.h
blob303a990b0f30a93fc69128ad4516a477872bdc60
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>
9 #ifdef HAVE_FENV_H
10 #include <fenv.h>
11 #endif
13 #ifdef HAVE_FPU_CONTROL_H
14 #include <fpu_control.h>
15 #endif
17 #include "AL/al.h"
18 #include "AL/alc.h"
19 #include "AL/alext.h"
21 /* Define int64_t and uint64_t types */
22 #if defined(__STDC_VERSION__) && __STDC_VERSION__ >= 199901L
23 #include <inttypes.h>
24 #elif defined(_WIN32) && defined(__GNUC__)
25 #include <stdint.h>
26 #elif defined(_WIN32)
27 typedef __int64 int64_t;
28 typedef unsigned __int64 uint64_t;
29 #else
30 /* Fallback if nothing above works */
31 #include <inttypes.h>
32 #endif
34 #ifndef AL_SOFT_deferred_updates
35 #define AL_SOFT_deferred_updates 1
36 #define AL_DEFERRED_UPDATES_SOFT 0xC002
37 typedef ALvoid (AL_APIENTRY*LPALDEFERUPDATESSOFT)(void);
38 typedef ALvoid (AL_APIENTRY*LPALPROCESSUPDATESSOFT)(void);
39 #ifdef AL_ALEXT_PROTOTYPES
40 AL_API ALvoid AL_APIENTRY alDeferUpdatesSOFT(void);
41 AL_API ALvoid AL_APIENTRY alProcessUpdatesSOFT(void);
42 #endif
43 #endif
45 #ifndef AL_SOFT_source_latency
46 #define AL_SOFT_source_latency 1
47 #define AL_SAMPLE_OFFSET_LATENCY_SOFT 0x1200
48 typedef int64_t ALint64SOFT;
49 typedef uint64_t ALuint64SOFT;
50 typedef void (AL_APIENTRY*LPALGETSOURCEI64SOFT)(ALuint,ALenum,ALint64SOFT*);
51 typedef void (AL_APIENTRY*LPALGETSOURCEI64VSOFT)(ALuint,ALenum,ALint64SOFT*);
52 #ifdef AL_ALEXT_PROTOTYPES
53 AL_API void AL_APIENTRY alGetSourcei64SOFT(ALuint source, ALenum param, ALint64SOFT *values);
54 AL_API void AL_APIENTRY alGetSourcei64vSOFT(ALuint source, ALenum param, ALint64SOFT *values);
55 #endif
56 #endif
59 #if defined(HAVE_STDINT_H)
60 #include <stdint.h>
61 typedef int64_t ALint64;
62 typedef uint64_t ALuint64;
63 #elif defined(HAVE___INT64)
64 typedef __int64 ALint64;
65 typedef unsigned __int64 ALuint64;
66 #elif (SIZEOF_LONG == 8)
67 typedef long ALint64;
68 typedef unsigned long ALuint64;
69 #elif (SIZEOF_LONG_LONG == 8)
70 typedef long long ALint64;
71 typedef unsigned long long ALuint64;
72 #endif
74 typedef ptrdiff_t ALintptrEXT;
75 typedef ptrdiff_t ALsizeiptrEXT;
77 #define MAKEU64(x,y) (((ALuint64)(x)<<32)|(ALuint64)(y))
79 #ifdef HAVE_GCC_FORMAT
80 #define PRINTF_STYLE(x, y) __attribute__((format(printf, (x), (y))))
81 #else
82 #define PRINTF_STYLE(x, y)
83 #endif
85 #if defined(HAVE_RESTRICT)
86 #define RESTRICT restrict
87 #elif defined(HAVE___RESTRICT)
88 #define RESTRICT __restrict
89 #else
90 #define RESTRICT
91 #endif
94 static const union {
95 ALuint u;
96 ALubyte b[sizeof(ALuint)];
97 } EndianTest = { 1 };
98 #define IS_LITTLE_ENDIAN (EndianTest.b[0] == 1)
100 #define COUNTOF(x) (sizeof((x))/sizeof((x)[0]))
102 #ifdef _WIN32
104 #include <windows.h>
106 typedef DWORD pthread_key_t;
107 int pthread_key_create(pthread_key_t *key, void (*callback)(void*));
108 int pthread_key_delete(pthread_key_t key);
109 void *pthread_getspecific(pthread_key_t key);
110 int pthread_setspecific(pthread_key_t key, void *val);
112 #define HAVE_DYNLOAD 1
113 void *LoadLib(const char *name);
114 void CloseLib(void *handle);
115 void *GetSymbol(void *handle, const char *name);
117 WCHAR *strdupW(const WCHAR *str);
119 typedef LONG pthread_once_t;
120 #define PTHREAD_ONCE_INIT 0
121 void pthread_once(pthread_once_t *once, void (*callback)(void));
123 static __inline int sched_yield(void)
124 { SwitchToThread(); return 0; }
126 #else
128 #include <unistd.h>
129 #include <assert.h>
130 #include <pthread.h>
131 #include <sys/time.h>
132 #include <time.h>
133 #include <errno.h>
135 #define IsBadWritePtr(a,b) ((a) == NULL && (b) != 0)
137 typedef pthread_mutex_t CRITICAL_SECTION;
138 void InitializeCriticalSection(CRITICAL_SECTION *cs);
139 void DeleteCriticalSection(CRITICAL_SECTION *cs);
140 void EnterCriticalSection(CRITICAL_SECTION *cs);
141 void LeaveCriticalSection(CRITICAL_SECTION *cs);
143 ALuint timeGetTime(void);
144 void Sleep(ALuint t);
146 #if defined(HAVE_DLFCN_H)
147 #define HAVE_DYNLOAD 1
148 void *LoadLib(const char *name);
149 void CloseLib(void *handle);
150 void *GetSymbol(void *handle, const char *name);
151 #endif
153 #endif
155 typedef void *volatile XchgPtr;
157 #if defined(__GNUC__) && (__GNUC__ > 4 || (__GNUC__ == 4 && __GNUC_MINOR__ >= 1))
158 typedef ALuint RefCount;
159 static __inline RefCount IncrementRef(volatile RefCount *ptr)
160 { return __sync_add_and_fetch(ptr, 1); }
161 static __inline RefCount DecrementRef(volatile RefCount *ptr)
162 { return __sync_sub_and_fetch(ptr, 1); }
164 static __inline int ExchangeInt(volatile int *ptr, int newval)
166 return __sync_lock_test_and_set(ptr, newval);
168 static __inline void *ExchangePtr(XchgPtr *ptr, void *newval)
170 return __sync_lock_test_and_set(ptr, newval);
172 static __inline ALboolean CompExchangeInt(volatile int *ptr, int oldval, int newval)
174 return __sync_bool_compare_and_swap(ptr, oldval, newval);
176 static __inline ALboolean CompExchangePtr(XchgPtr *ptr, void *oldval, void *newval)
178 return __sync_bool_compare_and_swap(ptr, oldval, newval);
181 #elif defined(__GNUC__) && (defined(__i386__) || defined(__x86_64__))
183 static __inline int xaddl(volatile int *dest, int incr)
185 int ret;
186 __asm__ __volatile__("lock; xaddl %0,(%1)"
187 : "=r" (ret)
188 : "r" (dest), "0" (incr)
189 : "memory");
190 return ret;
193 typedef int RefCount;
194 static __inline RefCount IncrementRef(volatile RefCount *ptr)
195 { return xaddl(ptr, 1)+1; }
196 static __inline RefCount DecrementRef(volatile RefCount *ptr)
197 { return xaddl(ptr, -1)-1; }
199 static __inline int ExchangeInt(volatile int *dest, int newval)
201 int ret;
202 __asm__ __volatile__("lock; xchgl %0,(%1)"
203 : "=r" (ret)
204 : "r" (dest), "0" (newval)
205 : "memory");
206 return ret;
209 static __inline ALboolean CompExchangeInt(volatile int *dest, int oldval, int newval)
211 int ret;
212 __asm__ __volatile__("lock; cmpxchgl %2,(%1)"
213 : "=a" (ret)
214 : "r" (dest), "r" (newval), "0" (oldval)
215 : "memory");
216 return ret == oldval;
219 static __inline void *ExchangePtr(XchgPtr *dest, void *newval)
221 void *ret;
222 __asm__ __volatile__(
223 #ifdef __i386__
224 "lock; xchgl %0,(%1)"
225 #else
226 "lock; xchgq %0,(%1)"
227 #endif
228 : "=r" (ret)
229 : "r" (dest), "0" (newval)
230 : "memory"
232 return ret;
235 static __inline ALboolean CompExchangePtr(XchgPtr *dest, void *oldval, void *newval)
237 void *ret;
238 __asm__ __volatile__(
239 #ifdef __i386__
240 "lock; cmpxchgl %2,(%1)"
241 #else
242 "lock; cmpxchgq %2,(%1)"
243 #endif
244 : "=a" (ret)
245 : "r" (dest), "r" (newval), "0" (oldval)
246 : "memory"
248 return ret == oldval;
251 #elif defined(_WIN32)
253 typedef LONG RefCount;
254 static __inline RefCount IncrementRef(volatile RefCount *ptr)
255 { return InterlockedIncrement(ptr); }
256 static __inline RefCount DecrementRef(volatile RefCount *ptr)
257 { return InterlockedDecrement(ptr); }
259 extern ALbyte LONG_size_does_not_match_int[(sizeof(LONG)==sizeof(int))?1:-1];
261 static __inline int ExchangeInt(volatile int *ptr, int newval)
263 union {
264 volatile int *i;
265 volatile LONG *l;
266 } u = { ptr };
267 return InterlockedExchange(u.l, newval);
269 static __inline void *ExchangePtr(XchgPtr *ptr, void *newval)
271 return InterlockedExchangePointer(ptr, newval);
273 static __inline ALboolean CompExchangeInt(volatile int *ptr, int oldval, int newval)
275 union {
276 volatile int *i;
277 volatile LONG *l;
278 } u = { ptr };
279 return InterlockedCompareExchange(u.l, newval, oldval) == oldval;
281 static __inline ALboolean CompExchangePtr(XchgPtr *ptr, void *oldval, void *newval)
283 return InterlockedCompareExchangePointer(ptr, newval, oldval) == oldval;
286 #elif defined(__APPLE__)
288 #include <libkern/OSAtomic.h>
290 typedef int32_t RefCount;
291 static __inline RefCount IncrementRef(volatile RefCount *ptr)
292 { return OSAtomicIncrement32Barrier(ptr); }
293 static __inline RefCount DecrementRef(volatile RefCount *ptr)
294 { return OSAtomicDecrement32Barrier(ptr); }
296 static __inline int ExchangeInt(volatile int *ptr, int newval)
298 /* Really? No regular old atomic swap? */
299 int oldval;
300 do {
301 oldval = *ptr;
302 } while(!OSAtomicCompareAndSwap32Barrier(oldval, newval, ptr));
303 return oldval;
305 static __inline void *ExchangePtr(XchgPtr *ptr, void *newval)
307 void *oldval;
308 do {
309 oldval = *ptr;
310 } while(!OSAtomicCompareAndSwapPtrBarrier(oldval, newval, ptr));
311 return oldval;
313 static __inline ALboolean CompExchangeInt(volatile int *ptr, int oldval, int newval)
315 return OSAtomicCompareAndSwap32Barrier(oldval, newval, ptr);
317 static __inline ALboolean CompExchangePtr(XchgPtr *ptr, void *oldval, void *newval)
319 return OSAtomicCompareAndSwapPtrBarrier(oldval, newval, ptr);
322 #else
323 #error "No atomic functions available on this platform!"
324 typedef ALuint RefCount;
325 #endif
328 typedef struct {
329 volatile RefCount read_count;
330 volatile RefCount write_count;
331 volatile ALenum read_lock;
332 volatile ALenum read_entry_lock;
333 volatile ALenum write_lock;
334 } RWLock;
336 void RWLockInit(RWLock *lock);
337 void ReadLock(RWLock *lock);
338 void ReadUnlock(RWLock *lock);
339 void WriteLock(RWLock *lock);
340 void WriteUnlock(RWLock *lock);
343 typedef struct UIntMap {
344 struct {
345 ALuint key;
346 ALvoid *value;
347 } *array;
348 ALsizei size;
349 ALsizei maxsize;
350 ALsizei limit;
351 RWLock lock;
352 } UIntMap;
353 extern UIntMap TlsDestructor;
355 void InitUIntMap(UIntMap *map, ALsizei limit);
356 void ResetUIntMap(UIntMap *map);
357 ALenum InsertUIntMapEntry(UIntMap *map, ALuint key, ALvoid *value);
358 ALvoid *RemoveUIntMapKey(UIntMap *map, ALuint key);
359 ALvoid *LookupUIntMapKey(UIntMap *map, ALuint key);
361 static __inline void LockUIntMapRead(UIntMap *map)
362 { ReadLock(&map->lock); }
363 static __inline void UnlockUIntMapRead(UIntMap *map)
364 { ReadUnlock(&map->lock); }
365 static __inline void LockUIntMapWrite(UIntMap *map)
366 { WriteLock(&map->lock); }
367 static __inline void UnlockUIntMapWrite(UIntMap *map)
368 { WriteUnlock(&map->lock); }
370 #include "alListener.h"
371 #include "alu.h"
373 #ifdef __cplusplus
374 extern "C" {
375 #endif
378 #define DEFAULT_OUTPUT_RATE (44100)
379 #define MIN_OUTPUT_RATE (8000)
381 #define SPEEDOFSOUNDMETRESPERSEC (343.3f)
382 #define AIRABSORBGAINHF (0.99426f) /* -0.05dB */
384 #define LOWPASSFREQREF (5000)
387 struct Hrtf;
390 // Find the next power-of-2 for non-power-of-2 numbers.
391 static __inline ALuint NextPowerOf2(ALuint value)
393 ALuint powerOf2 = 1;
395 if(value)
397 value--;
398 while(value)
400 value >>= 1;
401 powerOf2 <<= 1;
404 return powerOf2;
407 /* Fast float-to-int conversion. Assumes the FPU is already in round-to-zero
408 * mode. */
409 static __inline ALint fastf2i(ALfloat f)
411 ALint i;
412 #if defined(_MSC_VER) && defined(_M_IX86)
413 __asm fld f
414 __asm fistp i
415 #elif defined(__GNUC__) && (defined(__i386__) || defined(__x86_64__))
416 __asm__ __volatile__("flds %1\n\t"
417 "fistpl %0\n\t"
418 : "=m" (i)
419 : "m" (f));
420 #else
421 i = (ALint)f;
422 #endif
423 return i;
426 /* Fast float-to-uint conversion. Assumes the FPU is already in round-to-zero
427 * mode. */
428 static __inline ALuint fastf2u(ALfloat f)
429 { return fastf2i(f); }
432 enum DevProbe {
433 ALL_DEVICE_PROBE,
434 CAPTURE_DEVICE_PROBE
437 typedef struct {
438 ALCenum (*OpenPlayback)(ALCdevice*, const ALCchar*);
439 void (*ClosePlayback)(ALCdevice*);
440 ALCboolean (*ResetPlayback)(ALCdevice*);
441 ALCboolean (*StartPlayback)(ALCdevice*);
442 void (*StopPlayback)(ALCdevice*);
444 ALCenum (*OpenCapture)(ALCdevice*, const ALCchar*);
445 void (*CloseCapture)(ALCdevice*);
446 void (*StartCapture)(ALCdevice*);
447 void (*StopCapture)(ALCdevice*);
448 ALCenum (*CaptureSamples)(ALCdevice*, void*, ALCuint);
449 ALCuint (*AvailableSamples)(ALCdevice*);
451 void (*Lock)(ALCdevice*);
452 void (*Unlock)(ALCdevice*);
454 ALint64 (*GetLatency)(ALCdevice*);
455 } BackendFuncs;
457 struct BackendInfo {
458 const char *name;
459 ALCboolean (*Init)(BackendFuncs*);
460 void (*Deinit)(void);
461 void (*Probe)(enum DevProbe);
462 BackendFuncs Funcs;
465 ALCboolean alc_alsa_init(BackendFuncs *func_list);
466 void alc_alsa_deinit(void);
467 void alc_alsa_probe(enum DevProbe type);
468 ALCboolean alc_oss_init(BackendFuncs *func_list);
469 void alc_oss_deinit(void);
470 void alc_oss_probe(enum DevProbe type);
471 ALCboolean alc_solaris_init(BackendFuncs *func_list);
472 void alc_solaris_deinit(void);
473 void alc_solaris_probe(enum DevProbe type);
474 ALCboolean alc_sndio_init(BackendFuncs *func_list);
475 void alc_sndio_deinit(void);
476 void alc_sndio_probe(enum DevProbe type);
477 ALCboolean alcMMDevApiInit(BackendFuncs *func_list);
478 void alcMMDevApiDeinit(void);
479 void alcMMDevApiProbe(enum DevProbe type);
480 ALCboolean alcDSoundInit(BackendFuncs *func_list);
481 void alcDSoundDeinit(void);
482 void alcDSoundProbe(enum DevProbe type);
483 ALCboolean alcWinMMInit(BackendFuncs *FuncList);
484 void alcWinMMDeinit(void);
485 void alcWinMMProbe(enum DevProbe type);
486 ALCboolean alc_pa_init(BackendFuncs *func_list);
487 void alc_pa_deinit(void);
488 void alc_pa_probe(enum DevProbe type);
489 ALCboolean alc_wave_init(BackendFuncs *func_list);
490 void alc_wave_deinit(void);
491 void alc_wave_probe(enum DevProbe type);
492 ALCboolean alc_pulse_init(BackendFuncs *func_list);
493 void alc_pulse_deinit(void);
494 void alc_pulse_probe(enum DevProbe type);
495 ALCboolean alc_ca_init(BackendFuncs *func_list);
496 void alc_ca_deinit(void);
497 void alc_ca_probe(enum DevProbe type);
498 ALCboolean alc_opensl_init(BackendFuncs *func_list);
499 void alc_opensl_deinit(void);
500 void alc_opensl_probe(enum DevProbe type);
501 ALCboolean alc_null_init(BackendFuncs *func_list);
502 void alc_null_deinit(void);
503 void alc_null_probe(enum DevProbe type);
504 ALCboolean alc_loopback_init(BackendFuncs *func_list);
505 void alc_loopback_deinit(void);
506 void alc_loopback_probe(enum DevProbe type);
509 /* Device formats */
510 enum DevFmtType {
511 DevFmtByte = ALC_BYTE_SOFT,
512 DevFmtUByte = ALC_UNSIGNED_BYTE_SOFT,
513 DevFmtShort = ALC_SHORT_SOFT,
514 DevFmtUShort = ALC_UNSIGNED_SHORT_SOFT,
515 DevFmtInt = ALC_INT_SOFT,
516 DevFmtUInt = ALC_UNSIGNED_INT_SOFT,
517 DevFmtFloat = ALC_FLOAT_SOFT,
519 DevFmtTypeDefault = DevFmtFloat
521 enum DevFmtChannels {
522 DevFmtMono = ALC_MONO_SOFT,
523 DevFmtStereo = ALC_STEREO_SOFT,
524 DevFmtQuad = ALC_QUAD_SOFT,
525 DevFmtX51 = ALC_5POINT1_SOFT,
526 DevFmtX61 = ALC_6POINT1_SOFT,
527 DevFmtX71 = ALC_7POINT1_SOFT,
529 /* Similar to 5.1, except using the side channels instead of back */
530 DevFmtX51Side = 0x80000000,
532 DevFmtChannelsDefault = DevFmtStereo
535 ALuint BytesFromDevFmt(enum DevFmtType type);
536 ALuint ChannelsFromDevFmt(enum DevFmtChannels chans);
537 static __inline ALuint FrameSizeFromDevFmt(enum DevFmtChannels chans,
538 enum DevFmtType type)
540 return ChannelsFromDevFmt(chans) * BytesFromDevFmt(type);
544 extern const struct EffectList {
545 const char *name;
546 int type;
547 const char *ename;
548 ALenum val;
549 } EffectList[];
552 enum DeviceType {
553 Playback,
554 Capture,
555 Loopback
558 struct ALCdevice_struct
560 volatile RefCount ref;
562 ALCboolean Connected;
563 enum DeviceType Type;
565 CRITICAL_SECTION Mutex;
567 ALuint Frequency;
568 ALuint UpdateSize;
569 ALuint NumUpdates;
570 enum DevFmtChannels FmtChans;
571 enum DevFmtType FmtType;
573 ALCchar *DeviceName;
575 volatile ALCenum LastError;
577 // Maximum number of sources that can be created
578 ALuint MaxNoOfSources;
579 // Maximum number of slots that can be created
580 ALuint AuxiliaryEffectSlotMax;
582 ALCuint NumMonoSources;
583 ALCuint NumStereoSources;
584 ALuint NumAuxSends;
586 // Map of Buffers for this device
587 UIntMap BufferMap;
589 // Map of Effects for this device
590 UIntMap EffectMap;
592 // Map of Filters for this device
593 UIntMap FilterMap;
595 /* HRTF filter tables */
596 const struct Hrtf *Hrtf;
598 // Stereo-to-binaural filter
599 struct bs2b *Bs2b;
600 ALCint Bs2bLevel;
602 // Device flags
603 ALuint Flags;
605 // Dry path buffer mix
606 ALfloat DryBuffer[BUFFERSIZE][MaxChannels];
608 enum Channel DevChannels[MaxChannels];
610 enum Channel Speaker2Chan[MaxChannels];
611 ALfloat SpeakerAngle[MaxChannels];
612 ALuint NumChan;
614 ALfloat ClickRemoval[MaxChannels];
615 ALfloat PendingClicks[MaxChannels];
617 /* Default effect slot */
618 struct ALeffectslot *DefaultSlot;
620 // Contexts created on this device
621 ALCcontext *volatile ContextList;
623 BackendFuncs *Funcs;
624 void *ExtraData; // For the backend's use
626 ALCdevice *volatile next;
629 #define ALCdevice_OpenPlayback(a,b) ((a)->Funcs->OpenPlayback((a), (b)))
630 #define ALCdevice_ClosePlayback(a) ((a)->Funcs->ClosePlayback((a)))
631 #define ALCdevice_ResetPlayback(a) ((a)->Funcs->ResetPlayback((a)))
632 #define ALCdevice_StartPlayback(a) ((a)->Funcs->StartPlayback((a)))
633 #define ALCdevice_StopPlayback(a) ((a)->Funcs->StopPlayback((a)))
634 #define ALCdevice_OpenCapture(a,b) ((a)->Funcs->OpenCapture((a), (b)))
635 #define ALCdevice_CloseCapture(a) ((a)->Funcs->CloseCapture((a)))
636 #define ALCdevice_StartCapture(a) ((a)->Funcs->StartCapture((a)))
637 #define ALCdevice_StopCapture(a) ((a)->Funcs->StopCapture((a)))
638 #define ALCdevice_CaptureSamples(a,b,c) ((a)->Funcs->CaptureSamples((a), (b), (c)))
639 #define ALCdevice_AvailableSamples(a) ((a)->Funcs->AvailableSamples((a)))
640 #define ALCdevice_Lock(a) ((a)->Funcs->Lock((a)))
641 #define ALCdevice_Unlock(a) ((a)->Funcs->Unlock((a)))
642 #define ALCdevice_GetLatency(a) ((a)->Funcs->GetLatency((a)))
644 // Frequency was requested by the app or config file
645 #define DEVICE_FREQUENCY_REQUEST (1<<1)
646 // Channel configuration was requested by the config file
647 #define DEVICE_CHANNELS_REQUEST (1<<2)
648 // Sample type was requested by the config file
649 #define DEVICE_SAMPLE_TYPE_REQUEST (1<<3)
651 // Stereo sources cover 120-degree angles around +/-90
652 #define DEVICE_WIDE_STEREO (1<<16)
654 // Specifies if the device is currently running
655 #define DEVICE_RUNNING (1<<31)
657 #define LookupBuffer(m, k) ((struct ALbuffer*)LookupUIntMapKey(&(m)->BufferMap, (k)))
658 #define LookupEffect(m, k) ((struct ALeffect*)LookupUIntMapKey(&(m)->EffectMap, (k)))
659 #define LookupFilter(m, k) ((struct ALfilter*)LookupUIntMapKey(&(m)->FilterMap, (k)))
660 #define RemoveBuffer(m, k) ((struct ALbuffer*)RemoveUIntMapKey(&(m)->BufferMap, (k)))
661 #define RemoveEffect(m, k) ((struct ALeffect*)RemoveUIntMapKey(&(m)->EffectMap, (k)))
662 #define RemoveFilter(m, k) ((struct ALfilter*)RemoveUIntMapKey(&(m)->FilterMap, (k)))
665 struct ALCcontext_struct
667 volatile RefCount ref;
669 ALlistener Listener;
671 UIntMap SourceMap;
672 UIntMap EffectSlotMap;
674 ALenum LastError;
676 volatile ALenum UpdateSources;
678 volatile enum DistanceModel DistanceModel;
679 volatile ALboolean SourceDistanceModel;
681 volatile ALfloat DopplerFactor;
682 volatile ALfloat DopplerVelocity;
683 volatile ALfloat SpeedOfSound;
684 volatile ALenum DeferUpdates;
686 struct ALsource **ActiveSources;
687 ALsizei ActiveSourceCount;
688 ALsizei MaxActiveSources;
690 struct ALeffectslot **ActiveEffectSlots;
691 ALsizei ActiveEffectSlotCount;
692 ALsizei MaxActiveEffectSlots;
694 ALCdevice *Device;
695 const ALCchar *ExtensionList;
697 ALCcontext *volatile next;
700 #define LookupSource(m, k) ((struct ALsource*)LookupUIntMapKey(&(m)->SourceMap, (k)))
701 #define LookupEffectSlot(m, k) ((struct ALeffectslot*)LookupUIntMapKey(&(m)->EffectSlotMap, (k)))
702 #define RemoveSource(m, k) ((struct ALsource*)RemoveUIntMapKey(&(m)->SourceMap, (k)))
703 #define RemoveEffectSlot(m, k) ((struct ALeffectslot*)RemoveUIntMapKey(&(m)->EffectSlotMap, (k)))
705 ALCcontext *GetContextRef(void);
707 void ALCcontext_IncRef(ALCcontext *context);
708 void ALCcontext_DecRef(ALCcontext *context);
710 void AppendAllDevicesList(const ALCchar *name);
711 void AppendCaptureDeviceList(const ALCchar *name);
713 void ALCdevice_LockDefault(ALCdevice *device);
714 void ALCdevice_UnlockDefault(ALCdevice *device);
715 ALint64 ALCdevice_GetLatencyDefault(ALCdevice *device);
717 static __inline void LockContext(ALCcontext *context)
718 { ALCdevice_Lock(context->Device); }
719 static __inline void UnlockContext(ALCcontext *context)
720 { ALCdevice_Unlock(context->Device); }
723 void *al_malloc(size_t alignment, size_t size);
724 void *al_calloc(size_t alignment, size_t size);
725 void al_free(void *ptr);
727 ALvoid *StartThread(ALuint (*func)(ALvoid*), ALvoid *ptr);
728 ALuint StopThread(ALvoid *thread);
730 typedef struct RingBuffer RingBuffer;
731 RingBuffer *CreateRingBuffer(ALsizei frame_size, ALsizei length);
732 void DestroyRingBuffer(RingBuffer *ring);
733 ALsizei RingBufferSize(RingBuffer *ring);
734 void WriteRingBuffer(RingBuffer *ring, const ALubyte *data, ALsizei len);
735 void ReadRingBuffer(RingBuffer *ring, ALubyte *data, ALsizei len);
737 void ReadALConfig(void);
738 void FreeALConfig(void);
739 int ConfigValueExists(const char *blockName, const char *keyName);
740 const char *GetConfigValue(const char *blockName, const char *keyName, const char *def);
741 int GetConfigValueBool(const char *blockName, const char *keyName, int def);
742 int ConfigValueStr(const char *blockName, const char *keyName, const char **ret);
743 int ConfigValueInt(const char *blockName, const char *keyName, int *ret);
744 int ConfigValueUInt(const char *blockName, const char *keyName, unsigned int *ret);
745 int ConfigValueFloat(const char *blockName, const char *keyName, float *ret);
747 void SetRTPriority(void);
749 void SetDefaultChannelOrder(ALCdevice *device);
750 void SetDefaultWFXChannelOrder(ALCdevice *device);
752 const ALCchar *DevFmtTypeString(enum DevFmtType type);
753 const ALCchar *DevFmtChannelsString(enum DevFmtChannels chans);
755 #define HRIR_BITS (5)
756 #define HRIR_LENGTH (1<<HRIR_BITS)
757 #define HRIR_MASK (HRIR_LENGTH-1)
758 #define HRTFDELAY_BITS (20)
759 #define HRTFDELAY_FRACONE (1<<HRTFDELAY_BITS)
760 #define HRTFDELAY_MASK (HRTFDELAY_FRACONE-1)
761 void InitHrtf(void);
762 void FreeHrtf(void);
763 const struct Hrtf *GetHrtf(ALCdevice *device);
764 ALfloat CalcHrtfDelta(ALfloat oldGain, ALfloat newGain, const ALfloat olddir[3], const ALfloat newdir[3]);
765 void GetLerpedHrtfCoeffs(const struct Hrtf *Hrtf, ALfloat elevation, ALfloat azimuth, ALfloat gain, ALfloat (*coeffs)[2], ALuint *delays);
766 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);
768 void al_print(const char *func, const char *fmt, ...) PRINTF_STYLE(2,3);
769 #define AL_PRINT(...) al_print(__FUNCTION__, __VA_ARGS__)
771 extern FILE *LogFile;
772 enum LogLevel {
773 NoLog,
774 LogError,
775 LogWarning,
776 LogTrace,
777 LogRef
779 extern enum LogLevel LogLevel;
781 #define TRACEREF(...) do { \
782 if(LogLevel >= LogRef) \
783 AL_PRINT(__VA_ARGS__); \
784 } while(0)
786 #define TRACE(...) do { \
787 if(LogLevel >= LogTrace) \
788 AL_PRINT(__VA_ARGS__); \
789 } while(0)
791 #define WARN(...) do { \
792 if(LogLevel >= LogWarning) \
793 AL_PRINT(__VA_ARGS__); \
794 } while(0)
796 #define ERR(...) do { \
797 if(LogLevel >= LogError) \
798 AL_PRINT(__VA_ARGS__); \
799 } while(0)
802 extern ALint RTPrioLevel;
805 extern ALuint CPUCapFlags;
806 enum {
807 CPU_CAP_SSE = 1<<0,
808 CPU_CAP_NEON = 1<<1,
811 void FillCPUCaps(ALuint capfilter);
815 * Starts a try block. Must not be nested within another try block within the
816 * same function.
818 #define al_try do { \
819 int _al_err=0; \
820 _al_try_label: \
821 if(_al_err == 0)
823 * After a try or another catch block, runs the next block if the given value
824 * was thrown.
826 #define al_catch(val) else if(_al_err == (val))
828 * After a try or catch block, runs the next block for any value thrown and not
829 * caught.
831 #define al_catchany() else
832 /** Marks the end of the final catch (or the try) block. */
833 #define al_endtry } while(0)
836 * The given integer value is "thrown" so as to be caught by a catch block.
837 * Must be called in a try block within the same function. The value must not
838 * be 0.
840 #define al_throw(e) do { \
841 _al_err = (e); \
842 assert(_al_err != 0); \
843 goto _al_try_label; \
844 } while(0)
845 /** Sets an AL error on the given context, before throwing the error code. */
846 #define al_throwerr(ctx, err) do { \
847 alSetError((ctx), (err)); \
848 al_throw((err)); \
849 } while(0)
852 * Throws an AL_INVALID_VALUE error with the given ctx if the given condition
853 * is false.
855 #define CHECK_VALUE(ctx, cond) do { \
856 if(!(cond)) \
857 al_throwerr((ctx), AL_INVALID_VALUE); \
858 } while(0)
860 #ifdef __cplusplus
862 #endif
864 #endif