Add the start of AL_SOFT_source_latency
[openal-soft/openal-hmr.git] / OpenAL32 / Include / alMain.h
blobd12fe3f8bfdcd0b64ae8192107e9c7d2533a641a
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 #ifdef HAVE_GCC_FORMAT
78 #define PRINTF_STYLE(x, y) __attribute__((format(printf, (x), (y))))
79 #else
80 #define PRINTF_STYLE(x, y)
81 #endif
83 #if defined(HAVE_RESTRICT)
84 #define RESTRICT restrict
85 #elif defined(HAVE___RESTRICT)
86 #define RESTRICT __restrict
87 #else
88 #define RESTRICT
89 #endif
92 static const union {
93 ALuint u;
94 ALubyte b[sizeof(ALuint)];
95 } EndianTest = { 1 };
96 #define IS_LITTLE_ENDIAN (EndianTest.b[0] == 1)
98 #define COUNTOF(x) (sizeof((x))/sizeof((x)[0]))
100 #ifdef _WIN32
102 #include <windows.h>
104 typedef DWORD pthread_key_t;
105 int pthread_key_create(pthread_key_t *key, void (*callback)(void*));
106 int pthread_key_delete(pthread_key_t key);
107 void *pthread_getspecific(pthread_key_t key);
108 int pthread_setspecific(pthread_key_t key, void *val);
110 #define HAVE_DYNLOAD 1
111 void *LoadLib(const char *name);
112 void CloseLib(void *handle);
113 void *GetSymbol(void *handle, const char *name);
115 WCHAR *strdupW(const WCHAR *str);
117 typedef LONG pthread_once_t;
118 #define PTHREAD_ONCE_INIT 0
119 void pthread_once(pthread_once_t *once, void (*callback)(void));
121 static __inline int sched_yield(void)
122 { SwitchToThread(); return 0; }
124 #else
126 #include <unistd.h>
127 #include <assert.h>
128 #include <pthread.h>
129 #include <sys/time.h>
130 #include <time.h>
131 #include <errno.h>
133 #define IsBadWritePtr(a,b) ((a) == NULL && (b) != 0)
135 typedef pthread_mutex_t CRITICAL_SECTION;
136 void InitializeCriticalSection(CRITICAL_SECTION *cs);
137 void DeleteCriticalSection(CRITICAL_SECTION *cs);
138 void EnterCriticalSection(CRITICAL_SECTION *cs);
139 void LeaveCriticalSection(CRITICAL_SECTION *cs);
141 ALuint timeGetTime(void);
142 void Sleep(ALuint t);
144 #if defined(HAVE_DLFCN_H)
145 #define HAVE_DYNLOAD 1
146 void *LoadLib(const char *name);
147 void CloseLib(void *handle);
148 void *GetSymbol(void *handle, const char *name);
149 #endif
151 #endif
153 typedef void *volatile XchgPtr;
155 #if defined(__GNUC__) && (__GNUC__ > 4 || (__GNUC__ == 4 && __GNUC_MINOR__ >= 1))
156 typedef ALuint RefCount;
157 static __inline RefCount IncrementRef(volatile RefCount *ptr)
158 { return __sync_add_and_fetch(ptr, 1); }
159 static __inline RefCount DecrementRef(volatile RefCount *ptr)
160 { return __sync_sub_and_fetch(ptr, 1); }
162 static __inline int ExchangeInt(volatile int *ptr, int newval)
164 return __sync_lock_test_and_set(ptr, newval);
166 static __inline void *ExchangePtr(XchgPtr *ptr, void *newval)
168 return __sync_lock_test_and_set(ptr, newval);
170 static __inline ALboolean CompExchangeInt(volatile int *ptr, int oldval, int newval)
172 return __sync_bool_compare_and_swap(ptr, oldval, newval);
174 static __inline ALboolean CompExchangePtr(XchgPtr *ptr, void *oldval, void *newval)
176 return __sync_bool_compare_and_swap(ptr, oldval, newval);
179 #elif defined(__GNUC__) && (defined(__i386__) || defined(__x86_64__))
181 static __inline int xaddl(volatile int *dest, int incr)
183 int ret;
184 __asm__ __volatile__("lock; xaddl %0,(%1)"
185 : "=r" (ret)
186 : "r" (dest), "0" (incr)
187 : "memory");
188 return ret;
191 typedef int RefCount;
192 static __inline RefCount IncrementRef(volatile RefCount *ptr)
193 { return xaddl(ptr, 1)+1; }
194 static __inline RefCount DecrementRef(volatile RefCount *ptr)
195 { return xaddl(ptr, -1)-1; }
197 static __inline int ExchangeInt(volatile int *dest, int newval)
199 int ret;
200 __asm__ __volatile__("lock; xchgl %0,(%1)"
201 : "=r" (ret)
202 : "r" (dest), "0" (newval)
203 : "memory");
204 return ret;
207 static __inline ALboolean CompExchangeInt(volatile int *dest, int oldval, int newval)
209 int ret;
210 __asm__ __volatile__("lock; cmpxchgl %2,(%1)"
211 : "=a" (ret)
212 : "r" (dest), "r" (newval), "0" (oldval)
213 : "memory");
214 return ret == oldval;
217 static __inline void *ExchangePtr(XchgPtr *dest, void *newval)
219 void *ret;
220 __asm__ __volatile__(
221 #ifdef __i386__
222 "lock; xchgl %0,(%1)"
223 #else
224 "lock; xchgq %0,(%1)"
225 #endif
226 : "=r" (ret)
227 : "r" (dest), "0" (newval)
228 : "memory"
230 return ret;
233 static __inline ALboolean CompExchangePtr(XchgPtr *dest, void *oldval, void *newval)
235 void *ret;
236 __asm__ __volatile__(
237 #ifdef __i386__
238 "lock; cmpxchgl %2,(%1)"
239 #else
240 "lock; cmpxchgq %2,(%1)"
241 #endif
242 : "=a" (ret)
243 : "r" (dest), "r" (newval), "0" (oldval)
244 : "memory"
246 return ret == oldval;
249 #elif defined(_WIN32)
251 typedef LONG RefCount;
252 static __inline RefCount IncrementRef(volatile RefCount *ptr)
253 { return InterlockedIncrement(ptr); }
254 static __inline RefCount DecrementRef(volatile RefCount *ptr)
255 { return InterlockedDecrement(ptr); }
257 extern ALbyte LONG_size_does_not_match_int[(sizeof(LONG)==sizeof(int))?1:-1];
259 static __inline int ExchangeInt(volatile int *ptr, int newval)
261 union {
262 volatile int *i;
263 volatile LONG *l;
264 } u = { ptr };
265 return InterlockedExchange(u.l, newval);
267 static __inline void *ExchangePtr(XchgPtr *ptr, void *newval)
269 return InterlockedExchangePointer(ptr, newval);
271 static __inline ALboolean CompExchangeInt(volatile int *ptr, int oldval, int newval)
273 union {
274 volatile int *i;
275 volatile LONG *l;
276 } u = { ptr };
277 return InterlockedCompareExchange(u.l, newval, oldval) == oldval;
279 static __inline ALboolean CompExchangePtr(XchgPtr *ptr, void *oldval, void *newval)
281 return InterlockedCompareExchangePointer(ptr, newval, oldval) == oldval;
284 #elif defined(__APPLE__)
286 #include <libkern/OSAtomic.h>
288 typedef int32_t RefCount;
289 static __inline RefCount IncrementRef(volatile RefCount *ptr)
290 { return OSAtomicIncrement32Barrier(ptr); }
291 static __inline RefCount DecrementRef(volatile RefCount *ptr)
292 { return OSAtomicDecrement32Barrier(ptr); }
294 static __inline int ExchangeInt(volatile int *ptr, int newval)
296 /* Really? No regular old atomic swap? */
297 int oldval;
298 do {
299 oldval = *ptr;
300 } while(!OSAtomicCompareAndSwap32Barrier(oldval, newval, ptr));
301 return oldval;
303 static __inline void *ExchangePtr(XchgPtr *ptr, void *newval)
305 void *oldval;
306 do {
307 oldval = *ptr;
308 } while(!OSAtomicCompareAndSwapPtrBarrier(oldval, newval, ptr));
309 return oldval;
311 static __inline ALboolean CompExchangeInt(volatile int *ptr, int oldval, int newval)
313 return OSAtomicCompareAndSwap32Barrier(oldval, newval, ptr);
315 static __inline ALboolean CompExchangePtr(XchgPtr *ptr, void *oldval, void *newval)
317 return OSAtomicCompareAndSwapPtrBarrier(oldval, newval, ptr);
320 #else
321 #error "No atomic functions available on this platform!"
322 typedef ALuint RefCount;
323 #endif
326 typedef struct {
327 volatile RefCount read_count;
328 volatile RefCount write_count;
329 volatile ALenum read_lock;
330 volatile ALenum read_entry_lock;
331 volatile ALenum write_lock;
332 } RWLock;
334 void RWLockInit(RWLock *lock);
335 void ReadLock(RWLock *lock);
336 void ReadUnlock(RWLock *lock);
337 void WriteLock(RWLock *lock);
338 void WriteUnlock(RWLock *lock);
341 typedef struct UIntMap {
342 struct {
343 ALuint key;
344 ALvoid *value;
345 } *array;
346 ALsizei size;
347 ALsizei maxsize;
348 ALsizei limit;
349 RWLock lock;
350 } UIntMap;
351 extern UIntMap TlsDestructor;
353 void InitUIntMap(UIntMap *map, ALsizei limit);
354 void ResetUIntMap(UIntMap *map);
355 ALenum InsertUIntMapEntry(UIntMap *map, ALuint key, ALvoid *value);
356 ALvoid *RemoveUIntMapKey(UIntMap *map, ALuint key);
357 ALvoid *LookupUIntMapKey(UIntMap *map, ALuint key);
359 static __inline void LockUIntMapRead(UIntMap *map)
360 { ReadLock(&map->lock); }
361 static __inline void UnlockUIntMapRead(UIntMap *map)
362 { ReadUnlock(&map->lock); }
363 static __inline void LockUIntMapWrite(UIntMap *map)
364 { WriteLock(&map->lock); }
365 static __inline void UnlockUIntMapWrite(UIntMap *map)
366 { WriteUnlock(&map->lock); }
368 #include "alListener.h"
369 #include "alu.h"
371 #ifdef __cplusplus
372 extern "C" {
373 #endif
376 #define DEFAULT_OUTPUT_RATE (44100)
377 #define MIN_OUTPUT_RATE (8000)
379 #define SPEEDOFSOUNDMETRESPERSEC (343.3f)
380 #define AIRABSORBGAINHF (0.99426f) /* -0.05dB */
382 #define LOWPASSFREQREF (5000)
385 struct Hrtf;
388 // Find the next power-of-2 for non-power-of-2 numbers.
389 static __inline ALuint NextPowerOf2(ALuint value)
391 ALuint powerOf2 = 1;
393 if(value)
395 value--;
396 while(value)
398 value >>= 1;
399 powerOf2 <<= 1;
402 return powerOf2;
405 /* Fast float-to-int conversion. Assumes the FPU is already in round-to-zero
406 * mode. */
407 static __inline ALint fastf2i(ALfloat f)
409 ALint i;
410 #if defined(_MSC_VER) && defined(_M_IX86)
411 __asm fld f
412 __asm fistp i
413 #elif defined(__GNUC__) && (defined(__i386__) || defined(__x86_64__))
414 __asm__ __volatile__("flds %1\n\t"
415 "fistpl %0\n\t"
416 : "=m" (i)
417 : "m" (f));
418 #else
419 i = (ALint)f;
420 #endif
421 return i;
424 /* Fast float-to-uint conversion. Assumes the FPU is already in round-to-zero
425 * mode. */
426 static __inline ALuint fastf2u(ALfloat f)
427 { return fastf2i(f); }
430 enum DevProbe {
431 ALL_DEVICE_PROBE,
432 CAPTURE_DEVICE_PROBE
435 typedef struct {
436 ALCenum (*OpenPlayback)(ALCdevice*, const ALCchar*);
437 void (*ClosePlayback)(ALCdevice*);
438 ALCboolean (*ResetPlayback)(ALCdevice*);
439 ALCboolean (*StartPlayback)(ALCdevice*);
440 void (*StopPlayback)(ALCdevice*);
442 ALCenum (*OpenCapture)(ALCdevice*, const ALCchar*);
443 void (*CloseCapture)(ALCdevice*);
444 void (*StartCapture)(ALCdevice*);
445 void (*StopCapture)(ALCdevice*);
446 ALCenum (*CaptureSamples)(ALCdevice*, void*, ALCuint);
447 ALCuint (*AvailableSamples)(ALCdevice*);
449 ALint64 (*GetLatency)(ALCdevice*);
450 } BackendFuncs;
452 struct BackendInfo {
453 const char *name;
454 ALCboolean (*Init)(BackendFuncs*);
455 void (*Deinit)(void);
456 void (*Probe)(enum DevProbe);
457 BackendFuncs Funcs;
460 ALCboolean alc_alsa_init(BackendFuncs *func_list);
461 void alc_alsa_deinit(void);
462 void alc_alsa_probe(enum DevProbe type);
463 ALCboolean alc_oss_init(BackendFuncs *func_list);
464 void alc_oss_deinit(void);
465 void alc_oss_probe(enum DevProbe type);
466 ALCboolean alc_solaris_init(BackendFuncs *func_list);
467 void alc_solaris_deinit(void);
468 void alc_solaris_probe(enum DevProbe type);
469 ALCboolean alc_sndio_init(BackendFuncs *func_list);
470 void alc_sndio_deinit(void);
471 void alc_sndio_probe(enum DevProbe type);
472 ALCboolean alcMMDevApiInit(BackendFuncs *func_list);
473 void alcMMDevApiDeinit(void);
474 void alcMMDevApiProbe(enum DevProbe type);
475 ALCboolean alcDSoundInit(BackendFuncs *func_list);
476 void alcDSoundDeinit(void);
477 void alcDSoundProbe(enum DevProbe type);
478 ALCboolean alcWinMMInit(BackendFuncs *FuncList);
479 void alcWinMMDeinit(void);
480 void alcWinMMProbe(enum DevProbe type);
481 ALCboolean alc_pa_init(BackendFuncs *func_list);
482 void alc_pa_deinit(void);
483 void alc_pa_probe(enum DevProbe type);
484 ALCboolean alc_wave_init(BackendFuncs *func_list);
485 void alc_wave_deinit(void);
486 void alc_wave_probe(enum DevProbe type);
487 ALCboolean alc_pulse_init(BackendFuncs *func_list);
488 void alc_pulse_deinit(void);
489 void alc_pulse_probe(enum DevProbe type);
490 ALCboolean alc_ca_init(BackendFuncs *func_list);
491 void alc_ca_deinit(void);
492 void alc_ca_probe(enum DevProbe type);
493 ALCboolean alc_opensl_init(BackendFuncs *func_list);
494 void alc_opensl_deinit(void);
495 void alc_opensl_probe(enum DevProbe type);
496 ALCboolean alc_null_init(BackendFuncs *func_list);
497 void alc_null_deinit(void);
498 void alc_null_probe(enum DevProbe type);
499 ALCboolean alc_loopback_init(BackendFuncs *func_list);
500 void alc_loopback_deinit(void);
501 void alc_loopback_probe(enum DevProbe type);
504 /* Device formats */
505 enum DevFmtType {
506 DevFmtByte = ALC_BYTE_SOFT,
507 DevFmtUByte = ALC_UNSIGNED_BYTE_SOFT,
508 DevFmtShort = ALC_SHORT_SOFT,
509 DevFmtUShort = ALC_UNSIGNED_SHORT_SOFT,
510 DevFmtInt = ALC_INT_SOFT,
511 DevFmtUInt = ALC_UNSIGNED_INT_SOFT,
512 DevFmtFloat = ALC_FLOAT_SOFT,
514 DevFmtTypeDefault = DevFmtFloat
516 enum DevFmtChannels {
517 DevFmtMono = ALC_MONO_SOFT,
518 DevFmtStereo = ALC_STEREO_SOFT,
519 DevFmtQuad = ALC_QUAD_SOFT,
520 DevFmtX51 = ALC_5POINT1_SOFT,
521 DevFmtX61 = ALC_6POINT1_SOFT,
522 DevFmtX71 = ALC_7POINT1_SOFT,
524 /* Similar to 5.1, except using the side channels instead of back */
525 DevFmtX51Side = 0x80000000,
527 DevFmtChannelsDefault = DevFmtStereo
530 ALuint BytesFromDevFmt(enum DevFmtType type);
531 ALuint ChannelsFromDevFmt(enum DevFmtChannels chans);
532 static __inline ALuint FrameSizeFromDevFmt(enum DevFmtChannels chans,
533 enum DevFmtType type)
535 return ChannelsFromDevFmt(chans) * BytesFromDevFmt(type);
539 extern const struct EffectList {
540 const char *name;
541 int type;
542 const char *ename;
543 ALenum val;
544 } EffectList[];
547 enum DeviceType {
548 Playback,
549 Capture,
550 Loopback
553 struct ALCdevice_struct
555 volatile RefCount ref;
557 ALCboolean Connected;
558 enum DeviceType Type;
560 CRITICAL_SECTION Mutex;
562 ALuint Frequency;
563 ALuint UpdateSize;
564 ALuint NumUpdates;
565 enum DevFmtChannels FmtChans;
566 enum DevFmtType FmtType;
568 ALCchar *DeviceName;
570 volatile ALCenum LastError;
572 // Maximum number of sources that can be created
573 ALuint MaxNoOfSources;
574 // Maximum number of slots that can be created
575 ALuint AuxiliaryEffectSlotMax;
577 ALCuint NumMonoSources;
578 ALCuint NumStereoSources;
579 ALuint NumAuxSends;
581 // Map of Buffers for this device
582 UIntMap BufferMap;
584 // Map of Effects for this device
585 UIntMap EffectMap;
587 // Map of Filters for this device
588 UIntMap FilterMap;
590 /* HRTF filter tables */
591 const struct Hrtf *Hrtf;
593 // Stereo-to-binaural filter
594 struct bs2b *Bs2b;
595 ALCint Bs2bLevel;
597 // Device flags
598 ALuint Flags;
600 // Dry path buffer mix
601 ALfloat DryBuffer[BUFFERSIZE][MaxChannels];
603 enum Channel DevChannels[MaxChannels];
605 enum Channel Speaker2Chan[MaxChannels];
606 ALfloat SpeakerAngle[MaxChannels];
607 ALuint NumChan;
609 ALfloat ClickRemoval[MaxChannels];
610 ALfloat PendingClicks[MaxChannels];
612 /* Default effect slot */
613 struct ALeffectslot *DefaultSlot;
615 // Contexts created on this device
616 ALCcontext *volatile ContextList;
618 BackendFuncs *Funcs;
619 void *ExtraData; // For the backend's use
621 ALCdevice *volatile next;
624 #define ALCdevice_OpenPlayback(a,b) ((a)->Funcs->OpenPlayback((a), (b)))
625 #define ALCdevice_ClosePlayback(a) ((a)->Funcs->ClosePlayback((a)))
626 #define ALCdevice_ResetPlayback(a) ((a)->Funcs->ResetPlayback((a)))
627 #define ALCdevice_StartPlayback(a) ((a)->Funcs->StartPlayback((a)))
628 #define ALCdevice_StopPlayback(a) ((a)->Funcs->StopPlayback((a)))
629 #define ALCdevice_OpenCapture(a,b) ((a)->Funcs->OpenCapture((a), (b)))
630 #define ALCdevice_CloseCapture(a) ((a)->Funcs->CloseCapture((a)))
631 #define ALCdevice_StartCapture(a) ((a)->Funcs->StartCapture((a)))
632 #define ALCdevice_StopCapture(a) ((a)->Funcs->StopCapture((a)))
633 #define ALCdevice_CaptureSamples(a,b,c) ((a)->Funcs->CaptureSamples((a), (b), (c)))
634 #define ALCdevice_AvailableSamples(a) ((a)->Funcs->AvailableSamples((a)))
635 #define ALCdevice_GetLatency(a) ((a)->Funcs->GetLatency((a)))
637 // Frequency was requested by the app or config file
638 #define DEVICE_FREQUENCY_REQUEST (1<<1)
639 // Channel configuration was requested by the config file
640 #define DEVICE_CHANNELS_REQUEST (1<<2)
641 // Sample type was requested by the config file
642 #define DEVICE_SAMPLE_TYPE_REQUEST (1<<3)
644 // Stereo sources cover 120-degree angles around +/-90
645 #define DEVICE_WIDE_STEREO (1<<16)
647 // Specifies if the device is currently running
648 #define DEVICE_RUNNING (1<<31)
650 #define LookupBuffer(m, k) ((struct ALbuffer*)LookupUIntMapKey(&(m)->BufferMap, (k)))
651 #define LookupEffect(m, k) ((struct ALeffect*)LookupUIntMapKey(&(m)->EffectMap, (k)))
652 #define LookupFilter(m, k) ((struct ALfilter*)LookupUIntMapKey(&(m)->FilterMap, (k)))
653 #define RemoveBuffer(m, k) ((struct ALbuffer*)RemoveUIntMapKey(&(m)->BufferMap, (k)))
654 #define RemoveEffect(m, k) ((struct ALeffect*)RemoveUIntMapKey(&(m)->EffectMap, (k)))
655 #define RemoveFilter(m, k) ((struct ALfilter*)RemoveUIntMapKey(&(m)->FilterMap, (k)))
658 struct ALCcontext_struct
660 volatile RefCount ref;
662 ALlistener Listener;
664 UIntMap SourceMap;
665 UIntMap EffectSlotMap;
667 ALenum LastError;
669 volatile ALenum UpdateSources;
671 volatile enum DistanceModel DistanceModel;
672 volatile ALboolean SourceDistanceModel;
674 volatile ALfloat DopplerFactor;
675 volatile ALfloat DopplerVelocity;
676 volatile ALfloat SpeedOfSound;
677 volatile ALenum DeferUpdates;
679 struct ALsource **ActiveSources;
680 ALsizei ActiveSourceCount;
681 ALsizei MaxActiveSources;
683 struct ALeffectslot **ActiveEffectSlots;
684 ALsizei ActiveEffectSlotCount;
685 ALsizei MaxActiveEffectSlots;
687 ALCdevice *Device;
688 const ALCchar *ExtensionList;
690 ALCcontext *volatile next;
693 #define LookupSource(m, k) ((struct ALsource*)LookupUIntMapKey(&(m)->SourceMap, (k)))
694 #define LookupEffectSlot(m, k) ((struct ALeffectslot*)LookupUIntMapKey(&(m)->EffectSlotMap, (k)))
695 #define RemoveSource(m, k) ((struct ALsource*)RemoveUIntMapKey(&(m)->SourceMap, (k)))
696 #define RemoveEffectSlot(m, k) ((struct ALeffectslot*)RemoveUIntMapKey(&(m)->EffectSlotMap, (k)))
698 ALCcontext *GetContextRef(void);
700 void ALCcontext_IncRef(ALCcontext *context);
701 void ALCcontext_DecRef(ALCcontext *context);
703 void AppendAllDevicesList(const ALCchar *name);
704 void AppendCaptureDeviceList(const ALCchar *name);
706 static __inline void LockDevice(ALCdevice *device)
707 { EnterCriticalSection(&device->Mutex); }
708 static __inline void UnlockDevice(ALCdevice *device)
709 { LeaveCriticalSection(&device->Mutex); }
711 static __inline void LockContext(ALCcontext *context)
712 { LockDevice(context->Device); }
713 static __inline void UnlockContext(ALCcontext *context)
714 { UnlockDevice(context->Device); }
717 void *al_malloc(size_t alignment, size_t size);
718 void *al_calloc(size_t alignment, size_t size);
719 void al_free(void *ptr);
721 ALvoid *StartThread(ALuint (*func)(ALvoid*), ALvoid *ptr);
722 ALuint StopThread(ALvoid *thread);
724 typedef struct RingBuffer RingBuffer;
725 RingBuffer *CreateRingBuffer(ALsizei frame_size, ALsizei length);
726 void DestroyRingBuffer(RingBuffer *ring);
727 ALsizei RingBufferSize(RingBuffer *ring);
728 void WriteRingBuffer(RingBuffer *ring, const ALubyte *data, ALsizei len);
729 void ReadRingBuffer(RingBuffer *ring, ALubyte *data, ALsizei len);
731 void ReadALConfig(void);
732 void FreeALConfig(void);
733 int ConfigValueExists(const char *blockName, const char *keyName);
734 const char *GetConfigValue(const char *blockName, const char *keyName, const char *def);
735 int GetConfigValueBool(const char *blockName, const char *keyName, int def);
736 int ConfigValueStr(const char *blockName, const char *keyName, const char **ret);
737 int ConfigValueInt(const char *blockName, const char *keyName, int *ret);
738 int ConfigValueUInt(const char *blockName, const char *keyName, unsigned int *ret);
739 int ConfigValueFloat(const char *blockName, const char *keyName, float *ret);
741 void SetRTPriority(void);
743 void SetDefaultChannelOrder(ALCdevice *device);
744 void SetDefaultWFXChannelOrder(ALCdevice *device);
746 const ALCchar *DevFmtTypeString(enum DevFmtType type);
747 const ALCchar *DevFmtChannelsString(enum DevFmtChannels chans);
749 #define HRIR_BITS (5)
750 #define HRIR_LENGTH (1<<HRIR_BITS)
751 #define HRIR_MASK (HRIR_LENGTH-1)
752 #define HRTFDELAY_BITS (20)
753 #define HRTFDELAY_FRACONE (1<<HRTFDELAY_BITS)
754 #define HRTFDELAY_MASK (HRTFDELAY_FRACONE-1)
755 void InitHrtf(void);
756 void FreeHrtf(void);
757 const struct Hrtf *GetHrtf(ALCdevice *device);
758 ALfloat CalcHrtfDelta(ALfloat oldGain, ALfloat newGain, const ALfloat olddir[3], const ALfloat newdir[3]);
759 void GetLerpedHrtfCoeffs(const struct Hrtf *Hrtf, ALfloat elevation, ALfloat azimuth, ALfloat gain, ALfloat (*coeffs)[2], ALuint *delays);
760 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);
762 void al_print(const char *func, const char *fmt, ...) PRINTF_STYLE(2,3);
763 #define AL_PRINT(...) al_print(__FUNCTION__, __VA_ARGS__)
765 extern FILE *LogFile;
766 enum LogLevel {
767 NoLog,
768 LogError,
769 LogWarning,
770 LogTrace,
771 LogRef
773 extern enum LogLevel LogLevel;
775 #define TRACEREF(...) do { \
776 if(LogLevel >= LogRef) \
777 AL_PRINT(__VA_ARGS__); \
778 } while(0)
780 #define TRACE(...) do { \
781 if(LogLevel >= LogTrace) \
782 AL_PRINT(__VA_ARGS__); \
783 } while(0)
785 #define WARN(...) do { \
786 if(LogLevel >= LogWarning) \
787 AL_PRINT(__VA_ARGS__); \
788 } while(0)
790 #define ERR(...) do { \
791 if(LogLevel >= LogError) \
792 AL_PRINT(__VA_ARGS__); \
793 } while(0)
796 extern ALint RTPrioLevel;
799 extern ALuint CPUCapFlags;
800 enum {
801 CPU_CAP_SSE = 1<<0,
802 CPU_CAP_NEON = 1<<1,
805 void FillCPUCaps(ALuint capfilter);
809 * Starts a try block. Must not be nested within another try block within the
810 * same function.
812 #define al_try do { \
813 int _al_err=0; \
814 _al_try_label: \
815 if(_al_err == 0)
817 * After a try or another catch block, runs the next block if the given value
818 * was thrown.
820 #define al_catch(val) else if(_al_err == (val))
822 * After a try or catch block, runs the next block for any value thrown and not
823 * caught.
825 #define al_catchany() else
826 /** Marks the end of the final catch (or the try) block. */
827 #define al_endtry } while(0)
830 * The given integer value is "thrown" so as to be caught by a catch block.
831 * Must be called in a try block within the same function. The value must not
832 * be 0.
834 #define al_throw(e) do { \
835 _al_err = (e); \
836 assert(_al_err != 0); \
837 goto _al_try_label; \
838 } while(0)
839 /** Sets an AL error on the given context, before throwing the error code. */
840 #define al_throwerr(ctx, err) do { \
841 alSetError((ctx), (err)); \
842 al_throw((err)); \
843 } while(0)
846 * Throws an AL_INVALID_VALUE error with the given ctx if the given condition
847 * is false.
849 #define CHECK_VALUE(ctx, cond) do { \
850 if(!(cond)) \
851 al_throwerr((ctx), AL_INVALID_VALUE); \
852 } while(0)
854 #ifdef __cplusplus
856 #endif
858 #endif