Properly export alGetSource3i64SOFT
[openal-soft.git] / OpenAL32 / Include / alMain.h
blobbb8345dbaf5458225d528d460c364e330c99f556
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*LPALGETSOURCE3I64SOFT)(ALuint,ALenum,ALint64SOFT*,ALint64SOFT*,ALint64SOFT*);
52 typedef void (AL_APIENTRY*LPALGETSOURCEI64VSOFT)(ALuint,ALenum,ALint64SOFT*);
53 #ifdef AL_ALEXT_PROTOTYPES
54 AL_API void AL_APIENTRY alGetSourcei64SOFT(ALuint source, ALenum param, ALint64SOFT *values);
55 AL_API void AL_APIENTRY alGetSource3i64SOFT(ALuint source, ALenum param, ALint64SOFT *value1, ALint64SOFT *value2, ALint64SOFT *value3);
56 AL_API void AL_APIENTRY alGetSourcei64vSOFT(ALuint source, ALenum param, ALint64SOFT *values);
57 #endif
58 #endif
61 #if defined(HAVE_STDINT_H)
62 #include <stdint.h>
63 typedef int64_t ALint64;
64 typedef uint64_t ALuint64;
65 #elif defined(HAVE___INT64)
66 typedef __int64 ALint64;
67 typedef unsigned __int64 ALuint64;
68 #elif (SIZEOF_LONG == 8)
69 typedef long ALint64;
70 typedef unsigned long ALuint64;
71 #elif (SIZEOF_LONG_LONG == 8)
72 typedef long long ALint64;
73 typedef unsigned long long ALuint64;
74 #endif
76 typedef ptrdiff_t ALintptrEXT;
77 typedef ptrdiff_t ALsizeiptrEXT;
79 #define MAKEU64(x,y) (((ALuint64)(x)<<32)|(ALuint64)(y))
81 #ifdef HAVE_GCC_FORMAT
82 #define PRINTF_STYLE(x, y) __attribute__((format(printf, (x), (y))))
83 #else
84 #define PRINTF_STYLE(x, y)
85 #endif
87 #if defined(HAVE_RESTRICT)
88 #define RESTRICT restrict
89 #elif defined(HAVE___RESTRICT)
90 #define RESTRICT __restrict
91 #else
92 #define RESTRICT
93 #endif
96 static const union {
97 ALuint u;
98 ALubyte b[sizeof(ALuint)];
99 } EndianTest = { 1 };
100 #define IS_LITTLE_ENDIAN (EndianTest.b[0] == 1)
102 #define COUNTOF(x) (sizeof((x))/sizeof((x)[0]))
104 #ifdef _WIN32
106 #include <windows.h>
108 typedef DWORD pthread_key_t;
109 int pthread_key_create(pthread_key_t *key, void (*callback)(void*));
110 int pthread_key_delete(pthread_key_t key);
111 void *pthread_getspecific(pthread_key_t key);
112 int pthread_setspecific(pthread_key_t key, void *val);
114 #define HAVE_DYNLOAD 1
115 void *LoadLib(const char *name);
116 void CloseLib(void *handle);
117 void *GetSymbol(void *handle, const char *name);
119 WCHAR *strdupW(const WCHAR *str);
121 typedef LONG pthread_once_t;
122 #define PTHREAD_ONCE_INIT 0
123 void pthread_once(pthread_once_t *once, void (*callback)(void));
125 static __inline int sched_yield(void)
126 { SwitchToThread(); return 0; }
128 #else
130 #include <unistd.h>
131 #include <assert.h>
132 #include <pthread.h>
133 #include <sys/time.h>
134 #include <time.h>
135 #include <errno.h>
137 #define IsBadWritePtr(a,b) ((a) == NULL && (b) != 0)
139 typedef pthread_mutex_t CRITICAL_SECTION;
140 void InitializeCriticalSection(CRITICAL_SECTION *cs);
141 void DeleteCriticalSection(CRITICAL_SECTION *cs);
142 void EnterCriticalSection(CRITICAL_SECTION *cs);
143 void LeaveCriticalSection(CRITICAL_SECTION *cs);
145 ALuint timeGetTime(void);
146 void Sleep(ALuint t);
148 #if defined(HAVE_DLFCN_H)
149 #define HAVE_DYNLOAD 1
150 void *LoadLib(const char *name);
151 void CloseLib(void *handle);
152 void *GetSymbol(void *handle, const char *name);
153 #endif
155 #endif
157 typedef void *volatile XchgPtr;
159 #if defined(__GNUC__) && (__GNUC__ > 4 || (__GNUC__ == 4 && __GNUC_MINOR__ >= 1))
160 typedef ALuint RefCount;
161 static __inline RefCount IncrementRef(volatile RefCount *ptr)
162 { return __sync_add_and_fetch(ptr, 1); }
163 static __inline RefCount DecrementRef(volatile RefCount *ptr)
164 { return __sync_sub_and_fetch(ptr, 1); }
166 static __inline int ExchangeInt(volatile int *ptr, int newval)
168 return __sync_lock_test_and_set(ptr, newval);
170 static __inline void *ExchangePtr(XchgPtr *ptr, void *newval)
172 return __sync_lock_test_and_set(ptr, newval);
174 static __inline ALboolean CompExchangeInt(volatile int *ptr, int oldval, int newval)
176 return __sync_bool_compare_and_swap(ptr, oldval, newval);
178 static __inline ALboolean CompExchangePtr(XchgPtr *ptr, void *oldval, void *newval)
180 return __sync_bool_compare_and_swap(ptr, oldval, newval);
183 #elif defined(__GNUC__) && (defined(__i386__) || defined(__x86_64__))
185 static __inline int xaddl(volatile int *dest, int incr)
187 int ret;
188 __asm__ __volatile__("lock; xaddl %0,(%1)"
189 : "=r" (ret)
190 : "r" (dest), "0" (incr)
191 : "memory");
192 return ret;
195 typedef int RefCount;
196 static __inline RefCount IncrementRef(volatile RefCount *ptr)
197 { return xaddl(ptr, 1)+1; }
198 static __inline RefCount DecrementRef(volatile RefCount *ptr)
199 { return xaddl(ptr, -1)-1; }
201 static __inline int ExchangeInt(volatile int *dest, int newval)
203 int ret;
204 __asm__ __volatile__("lock; xchgl %0,(%1)"
205 : "=r" (ret)
206 : "r" (dest), "0" (newval)
207 : "memory");
208 return ret;
211 static __inline ALboolean CompExchangeInt(volatile int *dest, int oldval, int newval)
213 int ret;
214 __asm__ __volatile__("lock; cmpxchgl %2,(%1)"
215 : "=a" (ret)
216 : "r" (dest), "r" (newval), "0" (oldval)
217 : "memory");
218 return ret == oldval;
221 static __inline void *ExchangePtr(XchgPtr *dest, void *newval)
223 void *ret;
224 __asm__ __volatile__(
225 #ifdef __i386__
226 "lock; xchgl %0,(%1)"
227 #else
228 "lock; xchgq %0,(%1)"
229 #endif
230 : "=r" (ret)
231 : "r" (dest), "0" (newval)
232 : "memory"
234 return ret;
237 static __inline ALboolean CompExchangePtr(XchgPtr *dest, void *oldval, void *newval)
239 void *ret;
240 __asm__ __volatile__(
241 #ifdef __i386__
242 "lock; cmpxchgl %2,(%1)"
243 #else
244 "lock; cmpxchgq %2,(%1)"
245 #endif
246 : "=a" (ret)
247 : "r" (dest), "r" (newval), "0" (oldval)
248 : "memory"
250 return ret == oldval;
253 #elif defined(_WIN32)
255 typedef LONG RefCount;
256 static __inline RefCount IncrementRef(volatile RefCount *ptr)
257 { return InterlockedIncrement(ptr); }
258 static __inline RefCount DecrementRef(volatile RefCount *ptr)
259 { return InterlockedDecrement(ptr); }
261 extern ALbyte LONG_size_does_not_match_int[(sizeof(LONG)==sizeof(int))?1:-1];
263 static __inline int ExchangeInt(volatile int *ptr, int newval)
265 union {
266 volatile int *i;
267 volatile LONG *l;
268 } u = { ptr };
269 return InterlockedExchange(u.l, newval);
271 static __inline void *ExchangePtr(XchgPtr *ptr, void *newval)
273 return InterlockedExchangePointer(ptr, newval);
275 static __inline ALboolean CompExchangeInt(volatile int *ptr, int oldval, int newval)
277 union {
278 volatile int *i;
279 volatile LONG *l;
280 } u = { ptr };
281 return InterlockedCompareExchange(u.l, newval, oldval) == oldval;
283 static __inline ALboolean CompExchangePtr(XchgPtr *ptr, void *oldval, void *newval)
285 return InterlockedCompareExchangePointer(ptr, newval, oldval) == oldval;
288 #elif defined(__APPLE__)
290 #include <libkern/OSAtomic.h>
292 typedef int32_t RefCount;
293 static __inline RefCount IncrementRef(volatile RefCount *ptr)
294 { return OSAtomicIncrement32Barrier(ptr); }
295 static __inline RefCount DecrementRef(volatile RefCount *ptr)
296 { return OSAtomicDecrement32Barrier(ptr); }
298 static __inline int ExchangeInt(volatile int *ptr, int newval)
300 /* Really? No regular old atomic swap? */
301 int oldval;
302 do {
303 oldval = *ptr;
304 } while(!OSAtomicCompareAndSwap32Barrier(oldval, newval, ptr));
305 return oldval;
307 static __inline void *ExchangePtr(XchgPtr *ptr, void *newval)
309 void *oldval;
310 do {
311 oldval = *ptr;
312 } while(!OSAtomicCompareAndSwapPtrBarrier(oldval, newval, ptr));
313 return oldval;
315 static __inline ALboolean CompExchangeInt(volatile int *ptr, int oldval, int newval)
317 return OSAtomicCompareAndSwap32Barrier(oldval, newval, ptr);
319 static __inline ALboolean CompExchangePtr(XchgPtr *ptr, void *oldval, void *newval)
321 return OSAtomicCompareAndSwapPtrBarrier(oldval, newval, ptr);
324 #else
325 #error "No atomic functions available on this platform!"
326 typedef ALuint RefCount;
327 #endif
330 typedef struct {
331 volatile RefCount read_count;
332 volatile RefCount write_count;
333 volatile ALenum read_lock;
334 volatile ALenum read_entry_lock;
335 volatile ALenum write_lock;
336 } RWLock;
338 void RWLockInit(RWLock *lock);
339 void ReadLock(RWLock *lock);
340 void ReadUnlock(RWLock *lock);
341 void WriteLock(RWLock *lock);
342 void WriteUnlock(RWLock *lock);
345 typedef struct UIntMap {
346 struct {
347 ALuint key;
348 ALvoid *value;
349 } *array;
350 ALsizei size;
351 ALsizei maxsize;
352 ALsizei limit;
353 RWLock lock;
354 } UIntMap;
355 extern UIntMap TlsDestructor;
357 void InitUIntMap(UIntMap *map, ALsizei limit);
358 void ResetUIntMap(UIntMap *map);
359 ALenum InsertUIntMapEntry(UIntMap *map, ALuint key, ALvoid *value);
360 ALvoid *RemoveUIntMapKey(UIntMap *map, ALuint key);
361 ALvoid *LookupUIntMapKey(UIntMap *map, ALuint key);
363 static __inline void LockUIntMapRead(UIntMap *map)
364 { ReadLock(&map->lock); }
365 static __inline void UnlockUIntMapRead(UIntMap *map)
366 { ReadUnlock(&map->lock); }
367 static __inline void LockUIntMapWrite(UIntMap *map)
368 { WriteLock(&map->lock); }
369 static __inline void UnlockUIntMapWrite(UIntMap *map)
370 { WriteUnlock(&map->lock); }
372 #include "alListener.h"
373 #include "alu.h"
375 #ifdef __cplusplus
376 extern "C" {
377 #endif
380 #define DEFAULT_OUTPUT_RATE (44100)
381 #define MIN_OUTPUT_RATE (8000)
383 #define SPEEDOFSOUNDMETRESPERSEC (343.3f)
384 #define AIRABSORBGAINHF (0.99426f) /* -0.05dB */
386 #define LOWPASSFREQREF (5000)
389 struct Hrtf;
392 // Find the next power-of-2 for non-power-of-2 numbers.
393 static __inline ALuint NextPowerOf2(ALuint value)
395 ALuint powerOf2 = 1;
397 if(value)
399 value--;
400 while(value)
402 value >>= 1;
403 powerOf2 <<= 1;
406 return powerOf2;
409 /* Fast float-to-int conversion. Assumes the FPU is already in round-to-zero
410 * mode. */
411 static __inline ALint fastf2i(ALfloat f)
413 ALint i;
414 #if defined(_MSC_VER) && defined(_M_IX86)
415 __asm fld f
416 __asm fistp i
417 #elif defined(__GNUC__) && (defined(__i386__) || defined(__x86_64__))
418 __asm__ __volatile__("flds %1\n\t"
419 "fistpl %0\n\t"
420 : "=m" (i)
421 : "m" (f));
422 #else
423 i = (ALint)f;
424 #endif
425 return i;
428 /* Fast float-to-uint conversion. Assumes the FPU is already in round-to-zero
429 * mode. */
430 static __inline ALuint fastf2u(ALfloat f)
431 { return fastf2i(f); }
434 enum DevProbe {
435 ALL_DEVICE_PROBE,
436 CAPTURE_DEVICE_PROBE
439 typedef struct {
440 ALCenum (*OpenPlayback)(ALCdevice*, const ALCchar*);
441 void (*ClosePlayback)(ALCdevice*);
442 ALCboolean (*ResetPlayback)(ALCdevice*);
443 ALCboolean (*StartPlayback)(ALCdevice*);
444 void (*StopPlayback)(ALCdevice*);
446 ALCenum (*OpenCapture)(ALCdevice*, const ALCchar*);
447 void (*CloseCapture)(ALCdevice*);
448 void (*StartCapture)(ALCdevice*);
449 void (*StopCapture)(ALCdevice*);
450 ALCenum (*CaptureSamples)(ALCdevice*, void*, ALCuint);
451 ALCuint (*AvailableSamples)(ALCdevice*);
453 void (*Lock)(ALCdevice*);
454 void (*Unlock)(ALCdevice*);
456 ALint64 (*GetLatency)(ALCdevice*);
457 } BackendFuncs;
459 struct BackendInfo {
460 const char *name;
461 ALCboolean (*Init)(BackendFuncs*);
462 void (*Deinit)(void);
463 void (*Probe)(enum DevProbe);
464 BackendFuncs Funcs;
467 ALCboolean alc_alsa_init(BackendFuncs *func_list);
468 void alc_alsa_deinit(void);
469 void alc_alsa_probe(enum DevProbe type);
470 ALCboolean alc_oss_init(BackendFuncs *func_list);
471 void alc_oss_deinit(void);
472 void alc_oss_probe(enum DevProbe type);
473 ALCboolean alc_solaris_init(BackendFuncs *func_list);
474 void alc_solaris_deinit(void);
475 void alc_solaris_probe(enum DevProbe type);
476 ALCboolean alc_sndio_init(BackendFuncs *func_list);
477 void alc_sndio_deinit(void);
478 void alc_sndio_probe(enum DevProbe type);
479 ALCboolean alcMMDevApiInit(BackendFuncs *func_list);
480 void alcMMDevApiDeinit(void);
481 void alcMMDevApiProbe(enum DevProbe type);
482 ALCboolean alcDSoundInit(BackendFuncs *func_list);
483 void alcDSoundDeinit(void);
484 void alcDSoundProbe(enum DevProbe type);
485 ALCboolean alcWinMMInit(BackendFuncs *FuncList);
486 void alcWinMMDeinit(void);
487 void alcWinMMProbe(enum DevProbe type);
488 ALCboolean alc_pa_init(BackendFuncs *func_list);
489 void alc_pa_deinit(void);
490 void alc_pa_probe(enum DevProbe type);
491 ALCboolean alc_wave_init(BackendFuncs *func_list);
492 void alc_wave_deinit(void);
493 void alc_wave_probe(enum DevProbe type);
494 ALCboolean alc_pulse_init(BackendFuncs *func_list);
495 void alc_pulse_deinit(void);
496 void alc_pulse_probe(enum DevProbe type);
497 ALCboolean alc_ca_init(BackendFuncs *func_list);
498 void alc_ca_deinit(void);
499 void alc_ca_probe(enum DevProbe type);
500 ALCboolean alc_opensl_init(BackendFuncs *func_list);
501 void alc_opensl_deinit(void);
502 void alc_opensl_probe(enum DevProbe type);
503 ALCboolean alc_null_init(BackendFuncs *func_list);
504 void alc_null_deinit(void);
505 void alc_null_probe(enum DevProbe type);
506 ALCboolean alc_loopback_init(BackendFuncs *func_list);
507 void alc_loopback_deinit(void);
508 void alc_loopback_probe(enum DevProbe type);
511 /* Device formats */
512 enum DevFmtType {
513 DevFmtByte = ALC_BYTE_SOFT,
514 DevFmtUByte = ALC_UNSIGNED_BYTE_SOFT,
515 DevFmtShort = ALC_SHORT_SOFT,
516 DevFmtUShort = ALC_UNSIGNED_SHORT_SOFT,
517 DevFmtInt = ALC_INT_SOFT,
518 DevFmtUInt = ALC_UNSIGNED_INT_SOFT,
519 DevFmtFloat = ALC_FLOAT_SOFT,
521 DevFmtTypeDefault = DevFmtFloat
523 enum DevFmtChannels {
524 DevFmtMono = ALC_MONO_SOFT,
525 DevFmtStereo = ALC_STEREO_SOFT,
526 DevFmtQuad = ALC_QUAD_SOFT,
527 DevFmtX51 = ALC_5POINT1_SOFT,
528 DevFmtX61 = ALC_6POINT1_SOFT,
529 DevFmtX71 = ALC_7POINT1_SOFT,
531 /* Similar to 5.1, except using the side channels instead of back */
532 DevFmtX51Side = 0x80000000,
534 DevFmtChannelsDefault = DevFmtStereo
537 ALuint BytesFromDevFmt(enum DevFmtType type);
538 ALuint ChannelsFromDevFmt(enum DevFmtChannels chans);
539 static __inline ALuint FrameSizeFromDevFmt(enum DevFmtChannels chans,
540 enum DevFmtType type)
542 return ChannelsFromDevFmt(chans) * BytesFromDevFmt(type);
546 extern const struct EffectList {
547 const char *name;
548 int type;
549 const char *ename;
550 ALenum val;
551 } EffectList[];
554 enum DeviceType {
555 Playback,
556 Capture,
557 Loopback
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 // Dry path buffer mix
608 ALfloat DryBuffer[BUFFERSIZE][MaxChannels];
610 enum Channel DevChannels[MaxChannels];
612 enum Channel Speaker2Chan[MaxChannels];
613 ALfloat SpeakerAngle[MaxChannels];
614 ALuint NumChan;
616 ALfloat ClickRemoval[MaxChannels];
617 ALfloat PendingClicks[MaxChannels];
619 /* Default effect slot */
620 struct ALeffectslot *DefaultSlot;
622 // Contexts created on this device
623 ALCcontext *volatile ContextList;
625 BackendFuncs *Funcs;
626 void *ExtraData; // For the backend's use
628 ALCdevice *volatile next;
631 #define ALCdevice_OpenPlayback(a,b) ((a)->Funcs->OpenPlayback((a), (b)))
632 #define ALCdevice_ClosePlayback(a) ((a)->Funcs->ClosePlayback((a)))
633 #define ALCdevice_ResetPlayback(a) ((a)->Funcs->ResetPlayback((a)))
634 #define ALCdevice_StartPlayback(a) ((a)->Funcs->StartPlayback((a)))
635 #define ALCdevice_StopPlayback(a) ((a)->Funcs->StopPlayback((a)))
636 #define ALCdevice_OpenCapture(a,b) ((a)->Funcs->OpenCapture((a), (b)))
637 #define ALCdevice_CloseCapture(a) ((a)->Funcs->CloseCapture((a)))
638 #define ALCdevice_StartCapture(a) ((a)->Funcs->StartCapture((a)))
639 #define ALCdevice_StopCapture(a) ((a)->Funcs->StopCapture((a)))
640 #define ALCdevice_CaptureSamples(a,b,c) ((a)->Funcs->CaptureSamples((a), (b), (c)))
641 #define ALCdevice_AvailableSamples(a) ((a)->Funcs->AvailableSamples((a)))
642 #define ALCdevice_Lock(a) ((a)->Funcs->Lock((a)))
643 #define ALCdevice_Unlock(a) ((a)->Funcs->Unlock((a)))
644 #define ALCdevice_GetLatency(a) ((a)->Funcs->GetLatency((a)))
646 // Frequency was requested by the app or config file
647 #define DEVICE_FREQUENCY_REQUEST (1<<1)
648 // Channel configuration was requested by the config file
649 #define DEVICE_CHANNELS_REQUEST (1<<2)
650 // Sample type was requested by the config file
651 #define DEVICE_SAMPLE_TYPE_REQUEST (1<<3)
653 // Stereo sources cover 120-degree angles around +/-90
654 #define DEVICE_WIDE_STEREO (1<<16)
656 // Specifies if the device is currently running
657 #define DEVICE_RUNNING (1<<31)
659 #define LookupBuffer(m, k) ((struct ALbuffer*)LookupUIntMapKey(&(m)->BufferMap, (k)))
660 #define LookupEffect(m, k) ((struct ALeffect*)LookupUIntMapKey(&(m)->EffectMap, (k)))
661 #define LookupFilter(m, k) ((struct ALfilter*)LookupUIntMapKey(&(m)->FilterMap, (k)))
662 #define RemoveBuffer(m, k) ((struct ALbuffer*)RemoveUIntMapKey(&(m)->BufferMap, (k)))
663 #define RemoveEffect(m, k) ((struct ALeffect*)RemoveUIntMapKey(&(m)->EffectMap, (k)))
664 #define RemoveFilter(m, k) ((struct ALfilter*)RemoveUIntMapKey(&(m)->FilterMap, (k)))
667 struct ALCcontext_struct
669 volatile RefCount ref;
671 ALlistener Listener;
673 UIntMap SourceMap;
674 UIntMap EffectSlotMap;
676 ALenum LastError;
678 volatile ALenum UpdateSources;
680 volatile enum DistanceModel DistanceModel;
681 volatile ALboolean SourceDistanceModel;
683 volatile ALfloat DopplerFactor;
684 volatile ALfloat DopplerVelocity;
685 volatile ALfloat SpeedOfSound;
686 volatile ALenum DeferUpdates;
688 struct ALsource **ActiveSources;
689 ALsizei ActiveSourceCount;
690 ALsizei MaxActiveSources;
692 struct ALeffectslot **ActiveEffectSlots;
693 ALsizei ActiveEffectSlotCount;
694 ALsizei MaxActiveEffectSlots;
696 ALCdevice *Device;
697 const ALCchar *ExtensionList;
699 ALCcontext *volatile next;
702 #define LookupSource(m, k) ((struct ALsource*)LookupUIntMapKey(&(m)->SourceMap, (k)))
703 #define LookupEffectSlot(m, k) ((struct ALeffectslot*)LookupUIntMapKey(&(m)->EffectSlotMap, (k)))
704 #define RemoveSource(m, k) ((struct ALsource*)RemoveUIntMapKey(&(m)->SourceMap, (k)))
705 #define RemoveEffectSlot(m, k) ((struct ALeffectslot*)RemoveUIntMapKey(&(m)->EffectSlotMap, (k)))
707 ALCcontext *GetContextRef(void);
709 void ALCcontext_IncRef(ALCcontext *context);
710 void ALCcontext_DecRef(ALCcontext *context);
712 void AppendAllDevicesList(const ALCchar *name);
713 void AppendCaptureDeviceList(const ALCchar *name);
715 void ALCdevice_LockDefault(ALCdevice *device);
716 void ALCdevice_UnlockDefault(ALCdevice *device);
717 ALint64 ALCdevice_GetLatencyDefault(ALCdevice *device);
719 static __inline void LockContext(ALCcontext *context)
720 { ALCdevice_Lock(context->Device); }
721 static __inline void UnlockContext(ALCcontext *context)
722 { ALCdevice_Unlock(context->Device); }
725 void *al_malloc(size_t alignment, size_t size);
726 void *al_calloc(size_t alignment, size_t size);
727 void al_free(void *ptr);
729 ALvoid *StartThread(ALuint (*func)(ALvoid*), ALvoid *ptr);
730 ALuint StopThread(ALvoid *thread);
732 typedef struct RingBuffer RingBuffer;
733 RingBuffer *CreateRingBuffer(ALsizei frame_size, ALsizei length);
734 void DestroyRingBuffer(RingBuffer *ring);
735 ALsizei RingBufferSize(RingBuffer *ring);
736 void WriteRingBuffer(RingBuffer *ring, const ALubyte *data, ALsizei len);
737 void ReadRingBuffer(RingBuffer *ring, ALubyte *data, ALsizei len);
739 void ReadALConfig(void);
740 void FreeALConfig(void);
741 int ConfigValueExists(const char *blockName, const char *keyName);
742 const char *GetConfigValue(const char *blockName, const char *keyName, const char *def);
743 int GetConfigValueBool(const char *blockName, const char *keyName, int def);
744 int ConfigValueStr(const char *blockName, const char *keyName, const char **ret);
745 int ConfigValueInt(const char *blockName, const char *keyName, int *ret);
746 int ConfigValueUInt(const char *blockName, const char *keyName, unsigned int *ret);
747 int ConfigValueFloat(const char *blockName, const char *keyName, float *ret);
749 void SetRTPriority(void);
751 void SetDefaultChannelOrder(ALCdevice *device);
752 void SetDefaultWFXChannelOrder(ALCdevice *device);
754 const ALCchar *DevFmtTypeString(enum DevFmtType type);
755 const ALCchar *DevFmtChannelsString(enum DevFmtChannels chans);
757 #define HRIR_BITS (5)
758 #define HRIR_LENGTH (1<<HRIR_BITS)
759 #define HRIR_MASK (HRIR_LENGTH-1)
760 #define HRTFDELAY_BITS (20)
761 #define HRTFDELAY_FRACONE (1<<HRTFDELAY_BITS)
762 #define HRTFDELAY_MASK (HRTFDELAY_FRACONE-1)
763 void InitHrtf(void);
764 void FreeHrtf(void);
765 const struct Hrtf *GetHrtf(ALCdevice *device);
766 ALfloat CalcHrtfDelta(ALfloat oldGain, ALfloat newGain, const ALfloat olddir[3], const ALfloat newdir[3]);
767 void GetLerpedHrtfCoeffs(const struct Hrtf *Hrtf, ALfloat elevation, ALfloat azimuth, ALfloat gain, ALfloat (*coeffs)[2], ALuint *delays);
768 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);
770 void al_print(const char *func, const char *fmt, ...) PRINTF_STYLE(2,3);
771 #define AL_PRINT(...) al_print(__FUNCTION__, __VA_ARGS__)
773 extern FILE *LogFile;
774 enum LogLevel {
775 NoLog,
776 LogError,
777 LogWarning,
778 LogTrace,
779 LogRef
781 extern enum LogLevel LogLevel;
783 #define TRACEREF(...) do { \
784 if(LogLevel >= LogRef) \
785 AL_PRINT(__VA_ARGS__); \
786 } while(0)
788 #define TRACE(...) do { \
789 if(LogLevel >= LogTrace) \
790 AL_PRINT(__VA_ARGS__); \
791 } while(0)
793 #define WARN(...) do { \
794 if(LogLevel >= LogWarning) \
795 AL_PRINT(__VA_ARGS__); \
796 } while(0)
798 #define ERR(...) do { \
799 if(LogLevel >= LogError) \
800 AL_PRINT(__VA_ARGS__); \
801 } while(0)
804 extern ALint RTPrioLevel;
807 extern ALuint CPUCapFlags;
808 enum {
809 CPU_CAP_SSE = 1<<0,
810 CPU_CAP_NEON = 1<<1,
813 void FillCPUCaps(ALuint capfilter);
817 * Starts a try block. Must not be nested within another try block within the
818 * same function.
820 #define al_try do { \
821 int _al_err=0; \
822 _al_try_label: \
823 if(_al_err == 0)
825 * After a try or another catch block, runs the next block if the given value
826 * was thrown.
828 #define al_catch(val) else if(_al_err == (val))
830 * After a try or catch block, runs the next block for any value thrown and not
831 * caught.
833 #define al_catchany() else
834 /** Marks the end of the final catch (or the try) block. */
835 #define al_endtry } while(0)
838 * The given integer value is "thrown" so as to be caught by a catch block.
839 * Must be called in a try block within the same function. The value must not
840 * be 0.
842 #define al_throw(e) do { \
843 _al_err = (e); \
844 assert(_al_err != 0); \
845 goto _al_try_label; \
846 } while(0)
847 /** Sets an AL error on the given context, before throwing the error code. */
848 #define al_throwerr(ctx, err) do { \
849 alSetError((ctx), (err)); \
850 al_throw((err)); \
851 } while(0)
854 * Throws an AL_INVALID_VALUE error with the given ctx if the given condition
855 * is false.
857 #define CHECK_VALUE(ctx, cond) do { \
858 if(!(cond)) \
859 al_throwerr((ctx), AL_INVALID_VALUE); \
860 } while(0)
862 #ifdef __cplusplus
864 #endif
866 #endif