Don't bother handling MMX since we don't use it
[openal-soft/openal-hmr.git] / OpenAL32 / Include / alMain.h
blob5665a458eb202000b86f115320f5ada98373457f
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 #ifndef AL_SOFT_deferred_updates
22 #define AL_SOFT_deferred_updates 1
23 #define AL_DEFERRED_UPDATES_SOFT 0xC002
24 typedef ALvoid (AL_APIENTRY*LPALDEFERUPDATESSOFT)(void);
25 typedef ALvoid (AL_APIENTRY*LPALPROCESSUPDATESSOFT)(void);
26 #ifdef AL_ALEXT_PROTOTYPES
27 AL_API ALvoid AL_APIENTRY alDeferUpdatesSOFT(void);
28 AL_API ALvoid AL_APIENTRY alProcessUpdatesSOFT(void);
29 #endif
30 #endif
33 #if defined(HAVE_STDINT_H)
34 #include <stdint.h>
35 typedef int64_t ALint64;
36 typedef uint64_t ALuint64;
37 #elif defined(HAVE___INT64)
38 typedef __int64 ALint64;
39 typedef unsigned __int64 ALuint64;
40 #elif (SIZEOF_LONG == 8)
41 typedef long ALint64;
42 typedef unsigned long ALuint64;
43 #elif (SIZEOF_LONG_LONG == 8)
44 typedef long long ALint64;
45 typedef unsigned long long ALuint64;
46 #endif
48 typedef ptrdiff_t ALintptrEXT;
49 typedef ptrdiff_t ALsizeiptrEXT;
51 #ifdef HAVE_GCC_FORMAT
52 #define PRINTF_STYLE(x, y) __attribute__((format(printf, (x), (y))))
53 #else
54 #define PRINTF_STYLE(x, y)
55 #endif
57 #if defined(HAVE_RESTRICT)
58 #define RESTRICT restrict
59 #elif defined(HAVE___RESTRICT)
60 #define RESTRICT __restrict
61 #else
62 #define RESTRICT
63 #endif
66 static const union {
67 ALuint u;
68 ALubyte b[sizeof(ALuint)];
69 } EndianTest = { 1 };
70 #define IS_LITTLE_ENDIAN (EndianTest.b[0] == 1)
72 #define COUNTOF(x) (sizeof((x))/sizeof((x)[0]))
74 #ifdef _WIN32
76 #include <windows.h>
78 typedef DWORD pthread_key_t;
79 int pthread_key_create(pthread_key_t *key, void (*callback)(void*));
80 int pthread_key_delete(pthread_key_t key);
81 void *pthread_getspecific(pthread_key_t key);
82 int pthread_setspecific(pthread_key_t key, void *val);
84 #define HAVE_DYNLOAD 1
85 void *LoadLib(const char *name);
86 void CloseLib(void *handle);
87 void *GetSymbol(void *handle, const char *name);
89 WCHAR *strdupW(const WCHAR *str);
91 typedef LONG pthread_once_t;
92 #define PTHREAD_ONCE_INIT 0
93 void pthread_once(pthread_once_t *once, void (*callback)(void));
95 static __inline int sched_yield(void)
96 { SwitchToThread(); return 0; }
98 #else
100 #include <unistd.h>
101 #include <assert.h>
102 #include <pthread.h>
103 #include <sys/time.h>
104 #include <time.h>
105 #include <errno.h>
107 #define IsBadWritePtr(a,b) ((a) == NULL && (b) != 0)
109 typedef pthread_mutex_t CRITICAL_SECTION;
110 void InitializeCriticalSection(CRITICAL_SECTION *cs);
111 void DeleteCriticalSection(CRITICAL_SECTION *cs);
112 void EnterCriticalSection(CRITICAL_SECTION *cs);
113 void LeaveCriticalSection(CRITICAL_SECTION *cs);
115 ALuint timeGetTime(void);
116 void Sleep(ALuint t);
118 #if defined(HAVE_DLFCN_H)
119 #define HAVE_DYNLOAD 1
120 void *LoadLib(const char *name);
121 void CloseLib(void *handle);
122 void *GetSymbol(void *handle, const char *name);
123 #endif
125 #endif
127 typedef void *volatile XchgPtr;
129 #if defined(__GNUC__) && (__GNUC__ > 4 || (__GNUC__ == 4 && __GNUC_MINOR__ >= 1))
130 typedef ALuint RefCount;
131 static __inline RefCount IncrementRef(volatile RefCount *ptr)
132 { return __sync_add_and_fetch(ptr, 1); }
133 static __inline RefCount DecrementRef(volatile RefCount *ptr)
134 { return __sync_sub_and_fetch(ptr, 1); }
136 static __inline int ExchangeInt(volatile int *ptr, int newval)
138 return __sync_lock_test_and_set(ptr, newval);
140 static __inline void *ExchangePtr(XchgPtr *ptr, void *newval)
142 return __sync_lock_test_and_set(ptr, newval);
144 static __inline ALboolean CompExchangeInt(volatile int *ptr, int oldval, int newval)
146 return __sync_bool_compare_and_swap(ptr, oldval, newval);
148 static __inline ALboolean CompExchangePtr(XchgPtr *ptr, void *oldval, void *newval)
150 return __sync_bool_compare_and_swap(ptr, oldval, newval);
153 #elif defined(__GNUC__) && (defined(__i386__) || defined(__x86_64__))
155 static __inline int xaddl(volatile int *dest, int incr)
157 int ret;
158 __asm__ __volatile__("lock; xaddl %0,(%1)"
159 : "=r" (ret)
160 : "r" (dest), "0" (incr)
161 : "memory");
162 return ret;
165 typedef int RefCount;
166 static __inline RefCount IncrementRef(volatile RefCount *ptr)
167 { return xaddl(ptr, 1)+1; }
168 static __inline RefCount DecrementRef(volatile RefCount *ptr)
169 { return xaddl(ptr, -1)-1; }
171 static __inline int ExchangeInt(volatile int *dest, int newval)
173 int ret;
174 __asm__ __volatile__("lock; xchgl %0,(%1)"
175 : "=r" (ret)
176 : "r" (dest), "0" (newval)
177 : "memory");
178 return ret;
181 static __inline ALboolean CompExchangeInt(volatile int *dest, int oldval, int newval)
183 int ret;
184 __asm__ __volatile__("lock; cmpxchgl %2,(%1)"
185 : "=a" (ret)
186 : "r" (dest), "r" (newval), "0" (oldval)
187 : "memory");
188 return ret == oldval;
191 static __inline void *ExchangePtr(XchgPtr *dest, void *newval)
193 void *ret;
194 __asm__ __volatile__(
195 #ifdef __i386__
196 "lock; xchgl %0,(%1)"
197 #else
198 "lock; xchgq %0,(%1)"
199 #endif
200 : "=r" (ret)
201 : "r" (dest), "0" (newval)
202 : "memory"
204 return ret;
207 static __inline ALboolean CompExchangePtr(XchgPtr *dest, void *oldval, void *newval)
209 void *ret;
210 __asm__ __volatile__(
211 #ifdef __i386__
212 "lock; cmpxchgl %2,(%1)"
213 #else
214 "lock; cmpxchgq %2,(%1)"
215 #endif
216 : "=a" (ret)
217 : "r" (dest), "r" (newval), "0" (oldval)
218 : "memory"
220 return ret == oldval;
223 #elif defined(_WIN32)
225 typedef LONG RefCount;
226 static __inline RefCount IncrementRef(volatile RefCount *ptr)
227 { return InterlockedIncrement(ptr); }
228 static __inline RefCount DecrementRef(volatile RefCount *ptr)
229 { return InterlockedDecrement(ptr); }
231 extern ALbyte LONG_size_does_not_match_int[(sizeof(LONG)==sizeof(int))?1:-1];
233 static __inline int ExchangeInt(volatile int *ptr, int newval)
235 union {
236 volatile int *i;
237 volatile LONG *l;
238 } u = { ptr };
239 return InterlockedExchange(u.l, newval);
241 static __inline void *ExchangePtr(XchgPtr *ptr, void *newval)
243 return InterlockedExchangePointer(ptr, newval);
245 static __inline ALboolean CompExchangeInt(volatile int *ptr, int oldval, int newval)
247 union {
248 volatile int *i;
249 volatile LONG *l;
250 } u = { ptr };
251 return InterlockedCompareExchange(u.l, newval, oldval) == oldval;
253 static __inline ALboolean CompExchangePtr(XchgPtr *ptr, void *oldval, void *newval)
255 return InterlockedCompareExchangePointer(ptr, newval, oldval) == oldval;
258 #elif defined(__APPLE__)
260 #include <libkern/OSAtomic.h>
262 typedef int32_t RefCount;
263 static __inline RefCount IncrementRef(volatile RefCount *ptr)
264 { return OSAtomicIncrement32Barrier(ptr); }
265 static __inline RefCount DecrementRef(volatile RefCount *ptr)
266 { return OSAtomicDecrement32Barrier(ptr); }
268 static __inline int ExchangeInt(volatile int *ptr, int newval)
270 /* Really? No regular old atomic swap? */
271 int oldval;
272 do {
273 oldval = *ptr;
274 } while(!OSAtomicCompareAndSwap32Barrier(oldval, newval, ptr));
275 return oldval;
277 static __inline void *ExchangePtr(XchgPtr *ptr, void *newval)
279 void *oldval;
280 do {
281 oldval = *ptr;
282 } while(!OSAtomicCompareAndSwapPtrBarrier(oldval, newval, ptr));
283 return oldval;
285 static __inline ALboolean CompExchangeInt(volatile int *ptr, int oldval, int newval)
287 return OSAtomicCompareAndSwap32Barrier(oldval, newval, ptr);
289 static __inline ALboolean CompExchangePtr(XchgPtr *ptr, void *oldval, void *newval)
291 return OSAtomicCompareAndSwapPtrBarrier(oldval, newval, ptr);
294 #else
295 #error "No atomic functions available on this platform!"
296 typedef ALuint RefCount;
297 #endif
300 typedef struct {
301 volatile RefCount read_count;
302 volatile RefCount write_count;
303 volatile ALenum read_lock;
304 volatile ALenum read_entry_lock;
305 volatile ALenum write_lock;
306 } RWLock;
308 void RWLockInit(RWLock *lock);
309 void ReadLock(RWLock *lock);
310 void ReadUnlock(RWLock *lock);
311 void WriteLock(RWLock *lock);
312 void WriteUnlock(RWLock *lock);
315 typedef struct UIntMap {
316 struct {
317 ALuint key;
318 ALvoid *value;
319 } *array;
320 ALsizei size;
321 ALsizei maxsize;
322 ALsizei limit;
323 RWLock lock;
324 } UIntMap;
325 extern UIntMap TlsDestructor;
327 void InitUIntMap(UIntMap *map, ALsizei limit);
328 void ResetUIntMap(UIntMap *map);
329 ALenum InsertUIntMapEntry(UIntMap *map, ALuint key, ALvoid *value);
330 ALvoid *RemoveUIntMapKey(UIntMap *map, ALuint key);
331 ALvoid *LookupUIntMapKey(UIntMap *map, ALuint key);
333 static __inline void LockUIntMapRead(UIntMap *map)
334 { ReadLock(&map->lock); }
335 static __inline void UnlockUIntMapRead(UIntMap *map)
336 { ReadUnlock(&map->lock); }
337 static __inline void LockUIntMapWrite(UIntMap *map)
338 { WriteLock(&map->lock); }
339 static __inline void UnlockUIntMapWrite(UIntMap *map)
340 { WriteUnlock(&map->lock); }
342 #include "alListener.h"
343 #include "alu.h"
345 #ifdef __cplusplus
346 extern "C" {
347 #endif
350 #define DEFAULT_OUTPUT_RATE (44100)
351 #define MIN_OUTPUT_RATE (8000)
353 #define SPEEDOFSOUNDMETRESPERSEC (343.3f)
354 #define AIRABSORBGAINHF (0.99426f) /* -0.05dB */
356 #define LOWPASSFREQREF (5000)
359 struct Hrtf;
362 // Find the next power-of-2 for non-power-of-2 numbers.
363 static __inline ALuint NextPowerOf2(ALuint value)
365 ALuint powerOf2 = 1;
367 if(value)
369 value--;
370 while(value)
372 value >>= 1;
373 powerOf2 <<= 1;
376 return powerOf2;
379 /* Fast float-to-int conversion. Assumes the FPU is already in round-to-zero
380 * mode. */
381 static __inline ALint fastf2i(ALfloat f)
383 ALint i;
384 #if defined(_MSC_VER) && defined(_M_IX86)
385 __asm fld f
386 __asm fistp i
387 #elif defined(__GNUC__) && (defined(__i386__) || defined(__x86_64__))
388 __asm__ __volatile__("flds %1\n\t"
389 "fistpl %0\n\t"
390 : "=m" (i)
391 : "m" (f));
392 #else
393 i = (ALint)f;
394 #endif
395 return i;
398 /* Fast float-to-uint conversion. Assumes the FPU is already in round-to-zero
399 * mode. */
400 static __inline ALuint fastf2u(ALfloat f)
401 { return fastf2i(f); }
404 enum DevProbe {
405 ALL_DEVICE_PROBE,
406 CAPTURE_DEVICE_PROBE
409 typedef struct {
410 ALCenum (*OpenPlayback)(ALCdevice*, const ALCchar*);
411 void (*ClosePlayback)(ALCdevice*);
412 ALCboolean (*ResetPlayback)(ALCdevice*);
413 ALCboolean (*StartPlayback)(ALCdevice*);
414 void (*StopPlayback)(ALCdevice*);
416 ALCenum (*OpenCapture)(ALCdevice*, const ALCchar*);
417 void (*CloseCapture)(ALCdevice*);
418 void (*StartCapture)(ALCdevice*);
419 void (*StopCapture)(ALCdevice*);
420 ALCenum (*CaptureSamples)(ALCdevice*, void*, ALCuint);
421 ALCuint (*AvailableSamples)(ALCdevice*);
422 } BackendFuncs;
424 struct BackendInfo {
425 const char *name;
426 ALCboolean (*Init)(BackendFuncs*);
427 void (*Deinit)(void);
428 void (*Probe)(enum DevProbe);
429 BackendFuncs Funcs;
432 ALCboolean alc_alsa_init(BackendFuncs *func_list);
433 void alc_alsa_deinit(void);
434 void alc_alsa_probe(enum DevProbe type);
435 ALCboolean alc_oss_init(BackendFuncs *func_list);
436 void alc_oss_deinit(void);
437 void alc_oss_probe(enum DevProbe type);
438 ALCboolean alc_solaris_init(BackendFuncs *func_list);
439 void alc_solaris_deinit(void);
440 void alc_solaris_probe(enum DevProbe type);
441 ALCboolean alc_sndio_init(BackendFuncs *func_list);
442 void alc_sndio_deinit(void);
443 void alc_sndio_probe(enum DevProbe type);
444 ALCboolean alcMMDevApiInit(BackendFuncs *func_list);
445 void alcMMDevApiDeinit(void);
446 void alcMMDevApiProbe(enum DevProbe type);
447 ALCboolean alcDSoundInit(BackendFuncs *func_list);
448 void alcDSoundDeinit(void);
449 void alcDSoundProbe(enum DevProbe type);
450 ALCboolean alcWinMMInit(BackendFuncs *FuncList);
451 void alcWinMMDeinit(void);
452 void alcWinMMProbe(enum DevProbe type);
453 ALCboolean alc_pa_init(BackendFuncs *func_list);
454 void alc_pa_deinit(void);
455 void alc_pa_probe(enum DevProbe type);
456 ALCboolean alc_wave_init(BackendFuncs *func_list);
457 void alc_wave_deinit(void);
458 void alc_wave_probe(enum DevProbe type);
459 ALCboolean alc_pulse_init(BackendFuncs *func_list);
460 void alc_pulse_deinit(void);
461 void alc_pulse_probe(enum DevProbe type);
462 ALCboolean alc_ca_init(BackendFuncs *func_list);
463 void alc_ca_deinit(void);
464 void alc_ca_probe(enum DevProbe type);
465 ALCboolean alc_opensl_init(BackendFuncs *func_list);
466 void alc_opensl_deinit(void);
467 void alc_opensl_probe(enum DevProbe type);
468 ALCboolean alc_null_init(BackendFuncs *func_list);
469 void alc_null_deinit(void);
470 void alc_null_probe(enum DevProbe type);
471 ALCboolean alc_loopback_init(BackendFuncs *func_list);
472 void alc_loopback_deinit(void);
473 void alc_loopback_probe(enum DevProbe type);
476 /* Device formats */
477 enum DevFmtType {
478 DevFmtByte = ALC_BYTE_SOFT,
479 DevFmtUByte = ALC_UNSIGNED_BYTE_SOFT,
480 DevFmtShort = ALC_SHORT_SOFT,
481 DevFmtUShort = ALC_UNSIGNED_SHORT_SOFT,
482 DevFmtInt = ALC_INT_SOFT,
483 DevFmtUInt = ALC_UNSIGNED_INT_SOFT,
484 DevFmtFloat = ALC_FLOAT_SOFT,
486 DevFmtTypeDefault = DevFmtFloat
488 enum DevFmtChannels {
489 DevFmtMono = ALC_MONO_SOFT,
490 DevFmtStereo = ALC_STEREO_SOFT,
491 DevFmtQuad = ALC_QUAD_SOFT,
492 DevFmtX51 = ALC_5POINT1_SOFT,
493 DevFmtX61 = ALC_6POINT1_SOFT,
494 DevFmtX71 = ALC_7POINT1_SOFT,
496 /* Similar to 5.1, except using the side channels instead of back */
497 DevFmtX51Side = 0x80000000,
499 DevFmtChannelsDefault = DevFmtStereo
502 ALuint BytesFromDevFmt(enum DevFmtType type);
503 ALuint ChannelsFromDevFmt(enum DevFmtChannels chans);
504 static __inline ALuint FrameSizeFromDevFmt(enum DevFmtChannels chans,
505 enum DevFmtType type)
507 return ChannelsFromDevFmt(chans) * BytesFromDevFmt(type);
511 extern const struct EffectList {
512 const char *name;
513 int type;
514 const char *ename;
515 ALenum val;
516 } EffectList[];
519 enum DeviceType {
520 Playback,
521 Capture,
522 Loopback
525 struct ALCdevice_struct
527 volatile RefCount ref;
529 ALCboolean Connected;
530 enum DeviceType Type;
532 CRITICAL_SECTION Mutex;
534 ALuint Frequency;
535 ALuint UpdateSize;
536 ALuint NumUpdates;
537 enum DevFmtChannels FmtChans;
538 enum DevFmtType FmtType;
540 ALCchar *DeviceName;
542 volatile ALCenum LastError;
544 // Maximum number of sources that can be created
545 ALuint MaxNoOfSources;
546 // Maximum number of slots that can be created
547 ALuint AuxiliaryEffectSlotMax;
549 ALCuint NumMonoSources;
550 ALCuint NumStereoSources;
551 ALuint NumAuxSends;
553 // Map of Buffers for this device
554 UIntMap BufferMap;
556 // Map of Effects for this device
557 UIntMap EffectMap;
559 // Map of Filters for this device
560 UIntMap FilterMap;
562 /* HRTF filter tables */
563 const struct Hrtf *Hrtf;
565 // Stereo-to-binaural filter
566 struct bs2b *Bs2b;
567 ALCint Bs2bLevel;
569 // Device flags
570 ALuint Flags;
572 // Dry path buffer mix
573 ALfloat DryBuffer[BUFFERSIZE][MaxChannels];
575 enum Channel DevChannels[MaxChannels];
577 enum Channel Speaker2Chan[MaxChannels];
578 ALfloat SpeakerAngle[MaxChannels];
579 ALuint NumChan;
581 ALfloat ClickRemoval[MaxChannels];
582 ALfloat PendingClicks[MaxChannels];
584 /* Default effect slot */
585 struct ALeffectslot *DefaultSlot;
587 // Contexts created on this device
588 ALCcontext *volatile ContextList;
590 BackendFuncs *Funcs;
591 void *ExtraData; // For the backend's use
593 ALCdevice *volatile next;
596 #define ALCdevice_OpenPlayback(a,b) ((a)->Funcs->OpenPlayback((a), (b)))
597 #define ALCdevice_ClosePlayback(a) ((a)->Funcs->ClosePlayback((a)))
598 #define ALCdevice_ResetPlayback(a) ((a)->Funcs->ResetPlayback((a)))
599 #define ALCdevice_StartPlayback(a) ((a)->Funcs->StartPlayback((a)))
600 #define ALCdevice_StopPlayback(a) ((a)->Funcs->StopPlayback((a)))
601 #define ALCdevice_OpenCapture(a,b) ((a)->Funcs->OpenCapture((a), (b)))
602 #define ALCdevice_CloseCapture(a) ((a)->Funcs->CloseCapture((a)))
603 #define ALCdevice_StartCapture(a) ((a)->Funcs->StartCapture((a)))
604 #define ALCdevice_StopCapture(a) ((a)->Funcs->StopCapture((a)))
605 #define ALCdevice_CaptureSamples(a,b,c) ((a)->Funcs->CaptureSamples((a), (b), (c)))
606 #define ALCdevice_AvailableSamples(a) ((a)->Funcs->AvailableSamples((a)))
608 // Frequency was requested by the app or config file
609 #define DEVICE_FREQUENCY_REQUEST (1<<1)
610 // Channel configuration was requested by the config file
611 #define DEVICE_CHANNELS_REQUEST (1<<2)
612 // Sample type was requested by the config file
613 #define DEVICE_SAMPLE_TYPE_REQUEST (1<<3)
615 // Stereo sources cover 120-degree angles around +/-90
616 #define DEVICE_WIDE_STEREO (1<<16)
618 // Specifies if the device is currently running
619 #define DEVICE_RUNNING (1<<31)
621 #define LookupBuffer(m, k) ((struct ALbuffer*)LookupUIntMapKey(&(m)->BufferMap, (k)))
622 #define LookupEffect(m, k) ((struct ALeffect*)LookupUIntMapKey(&(m)->EffectMap, (k)))
623 #define LookupFilter(m, k) ((struct ALfilter*)LookupUIntMapKey(&(m)->FilterMap, (k)))
624 #define RemoveBuffer(m, k) ((struct ALbuffer*)RemoveUIntMapKey(&(m)->BufferMap, (k)))
625 #define RemoveEffect(m, k) ((struct ALeffect*)RemoveUIntMapKey(&(m)->EffectMap, (k)))
626 #define RemoveFilter(m, k) ((struct ALfilter*)RemoveUIntMapKey(&(m)->FilterMap, (k)))
629 struct ALCcontext_struct
631 volatile RefCount ref;
633 ALlistener Listener;
635 UIntMap SourceMap;
636 UIntMap EffectSlotMap;
638 ALenum LastError;
640 volatile ALenum UpdateSources;
642 volatile enum DistanceModel DistanceModel;
643 volatile ALboolean SourceDistanceModel;
645 volatile ALfloat DopplerFactor;
646 volatile ALfloat DopplerVelocity;
647 volatile ALfloat SpeedOfSound;
648 volatile ALenum DeferUpdates;
650 struct ALsource **ActiveSources;
651 ALsizei ActiveSourceCount;
652 ALsizei MaxActiveSources;
654 struct ALeffectslot **ActiveEffectSlots;
655 ALsizei ActiveEffectSlotCount;
656 ALsizei MaxActiveEffectSlots;
658 ALCdevice *Device;
659 const ALCchar *ExtensionList;
661 ALCcontext *volatile next;
664 #define LookupSource(m, k) ((struct ALsource*)LookupUIntMapKey(&(m)->SourceMap, (k)))
665 #define LookupEffectSlot(m, k) ((struct ALeffectslot*)LookupUIntMapKey(&(m)->EffectSlotMap, (k)))
666 #define RemoveSource(m, k) ((struct ALsource*)RemoveUIntMapKey(&(m)->SourceMap, (k)))
667 #define RemoveEffectSlot(m, k) ((struct ALeffectslot*)RemoveUIntMapKey(&(m)->EffectSlotMap, (k)))
669 ALCcontext *GetContextRef(void);
671 void ALCcontext_IncRef(ALCcontext *context);
672 void ALCcontext_DecRef(ALCcontext *context);
674 void AppendAllDevicesList(const ALCchar *name);
675 void AppendCaptureDeviceList(const ALCchar *name);
677 static __inline void LockDevice(ALCdevice *device)
678 { EnterCriticalSection(&device->Mutex); }
679 static __inline void UnlockDevice(ALCdevice *device)
680 { LeaveCriticalSection(&device->Mutex); }
682 static __inline void LockContext(ALCcontext *context)
683 { LockDevice(context->Device); }
684 static __inline void UnlockContext(ALCcontext *context)
685 { UnlockDevice(context->Device); }
688 ALvoid *StartThread(ALuint (*func)(ALvoid*), ALvoid *ptr);
689 ALuint StopThread(ALvoid *thread);
691 typedef struct RingBuffer RingBuffer;
692 RingBuffer *CreateRingBuffer(ALsizei frame_size, ALsizei length);
693 void DestroyRingBuffer(RingBuffer *ring);
694 ALsizei RingBufferSize(RingBuffer *ring);
695 void WriteRingBuffer(RingBuffer *ring, const ALubyte *data, ALsizei len);
696 void ReadRingBuffer(RingBuffer *ring, ALubyte *data, ALsizei len);
698 void ReadALConfig(void);
699 void FreeALConfig(void);
700 int ConfigValueExists(const char *blockName, const char *keyName);
701 const char *GetConfigValue(const char *blockName, const char *keyName, const char *def);
702 int GetConfigValueBool(const char *blockName, const char *keyName, int def);
703 int ConfigValueStr(const char *blockName, const char *keyName, const char **ret);
704 int ConfigValueInt(const char *blockName, const char *keyName, int *ret);
705 int ConfigValueUInt(const char *blockName, const char *keyName, unsigned int *ret);
706 int ConfigValueFloat(const char *blockName, const char *keyName, float *ret);
708 void SetRTPriority(void);
710 void SetDefaultChannelOrder(ALCdevice *device);
711 void SetDefaultWFXChannelOrder(ALCdevice *device);
713 const ALCchar *DevFmtTypeString(enum DevFmtType type);
714 const ALCchar *DevFmtChannelsString(enum DevFmtChannels chans);
716 #define HRIR_BITS (5)
717 #define HRIR_LENGTH (1<<HRIR_BITS)
718 #define HRIR_MASK (HRIR_LENGTH-1)
719 #define HRTFDELAY_BITS (20)
720 #define HRTFDELAY_FRACONE (1<<HRTFDELAY_BITS)
721 #define HRTFDELAY_MASK (HRTFDELAY_FRACONE-1)
722 void InitHrtf(void);
723 void FreeHrtf(void);
724 const struct Hrtf *GetHrtf(ALCdevice *device);
725 ALfloat CalcHrtfDelta(ALfloat oldGain, ALfloat newGain, const ALfloat olddir[3], const ALfloat newdir[3]);
726 void GetLerpedHrtfCoeffs(const struct Hrtf *Hrtf, ALfloat elevation, ALfloat azimuth, ALfloat gain, ALfloat (*coeffs)[2], ALuint *delays);
727 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);
729 void al_print(const char *func, const char *fmt, ...) PRINTF_STYLE(2,3);
730 #define AL_PRINT(...) al_print(__FUNCTION__, __VA_ARGS__)
732 extern FILE *LogFile;
733 enum LogLevel {
734 NoLog,
735 LogError,
736 LogWarning,
737 LogTrace,
738 LogRef
740 extern enum LogLevel LogLevel;
742 #define TRACEREF(...) do { \
743 if(LogLevel >= LogRef) \
744 AL_PRINT(__VA_ARGS__); \
745 } while(0)
747 #define TRACE(...) do { \
748 if(LogLevel >= LogTrace) \
749 AL_PRINT(__VA_ARGS__); \
750 } while(0)
752 #define WARN(...) do { \
753 if(LogLevel >= LogWarning) \
754 AL_PRINT(__VA_ARGS__); \
755 } while(0)
757 #define ERR(...) do { \
758 if(LogLevel >= LogError) \
759 AL_PRINT(__VA_ARGS__); \
760 } while(0)
763 extern ALint RTPrioLevel;
766 extern ALuint CPUCapFlags;
767 enum {
768 CPU_CAP_SSE = 1<<0,
769 CPU_CAP_NEON = 1<<1,
772 void FillCPUCaps(ALuint capfilter);
776 * Starts a try block. Must not be nested within another try block within the
777 * same function.
779 #define al_try do { \
780 int _al_err=0; \
781 _al_try_label: \
782 if(_al_err == 0)
784 * After a try or another catch block, runs the next block if the given value
785 * was thrown.
787 #define al_catch(val) else if(_al_err == (val))
789 * After a try or catch block, runs the next block for any value thrown and not
790 * caught.
792 #define al_catchany() else
793 /** Marks the end of the final catch (or the try) block. */
794 #define al_endtry } while(0)
797 * The given integer value is "thrown" so as to be caught by a catch block.
798 * Must be called in a try block within the same function. The value must not
799 * be 0.
801 #define al_throw(e) do { \
802 _al_err = (e); \
803 assert(_al_err != 0); \
804 goto _al_try_label; \
805 } while(0)
806 /** Sets an AL error on the given context, before throwing the error code. */
807 #define al_throwerr(ctx, err) do { \
808 alSetError((ctx), (err)); \
809 al_throw((err)); \
810 } while(0)
813 * Throws an AL_INVALID_VALUE error with the given ctx if the given condition
814 * is false.
816 #define CHECK_VALUE(ctx, cond) do { \
817 if(!(cond)) \
818 al_throwerr((ctx), AL_INVALID_VALUE); \
819 } while(0)
821 #ifdef __cplusplus
823 #endif
825 #endif