Remove the stereodup option
[openal-soft/openal-hmr.git] / OpenAL32 / Include / alMain.h
blob54fbcdf59507e7688059812a08c967645920344b
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 #ifdef HAVE_PTHREAD_NP_H
104 #include <pthread_np.h>
105 #endif
106 #include <sys/time.h>
107 #include <time.h>
108 #include <errno.h>
110 #define IsBadWritePtr(a,b) ((a) == NULL && (b) != 0)
112 typedef pthread_mutex_t CRITICAL_SECTION;
113 void InitializeCriticalSection(CRITICAL_SECTION *cs);
114 void DeleteCriticalSection(CRITICAL_SECTION *cs);
115 void EnterCriticalSection(CRITICAL_SECTION *cs);
116 void LeaveCriticalSection(CRITICAL_SECTION *cs);
118 ALuint timeGetTime(void);
119 void Sleep(ALuint t);
121 #if defined(HAVE_DLFCN_H)
122 #define HAVE_DYNLOAD 1
123 void *LoadLib(const char *name);
124 void CloseLib(void *handle);
125 void *GetSymbol(void *handle, const char *name);
126 #endif
128 #endif
130 typedef void *volatile XchgPtr;
132 #if defined(__GNUC__) && (__GNUC__ > 4 || (__GNUC__ == 4 && __GNUC_MINOR__ >= 1))
133 typedef ALuint RefCount;
134 static __inline RefCount IncrementRef(volatile RefCount *ptr)
135 { return __sync_add_and_fetch(ptr, 1); }
136 static __inline RefCount DecrementRef(volatile RefCount *ptr)
137 { return __sync_sub_and_fetch(ptr, 1); }
139 static __inline int ExchangeInt(volatile int *ptr, int newval)
141 return __sync_lock_test_and_set(ptr, newval);
143 static __inline void *ExchangePtr(XchgPtr *ptr, void *newval)
145 return __sync_lock_test_and_set(ptr, newval);
147 static __inline ALboolean CompExchangeInt(volatile int *ptr, int oldval, int newval)
149 return __sync_bool_compare_and_swap(ptr, oldval, newval);
151 static __inline ALboolean CompExchangePtr(XchgPtr *ptr, void *oldval, void *newval)
153 return __sync_bool_compare_and_swap(ptr, oldval, newval);
156 #elif defined(__GNUC__) && (defined(__i386__) || defined(__x86_64__))
158 static __inline int xaddl(volatile int *dest, int incr)
160 int ret;
161 __asm__ __volatile__("lock; xaddl %0,(%1)"
162 : "=r" (ret)
163 : "r" (dest), "0" (incr)
164 : "memory");
165 return ret;
168 typedef int RefCount;
169 static __inline RefCount IncrementRef(volatile RefCount *ptr)
170 { return xaddl(ptr, 1)+1; }
171 static __inline RefCount DecrementRef(volatile RefCount *ptr)
172 { return xaddl(ptr, -1)-1; }
174 static __inline int ExchangeInt(volatile int *dest, int newval)
176 int ret;
177 __asm__ __volatile__("lock; xchgl %0,(%1)"
178 : "=r" (ret)
179 : "r" (dest), "0" (newval)
180 : "memory");
181 return ret;
184 static __inline ALboolean CompExchangeInt(volatile int *dest, int oldval, int newval)
186 int ret;
187 __asm__ __volatile__("lock; cmpxchgl %2,(%1)"
188 : "=a" (ret)
189 : "r" (dest), "r" (newval), "0" (oldval)
190 : "memory");
191 return ret == oldval;
194 static __inline void *ExchangePtr(XchgPtr *dest, void *newval)
196 void *ret;
197 __asm__ __volatile__(
198 #ifdef __i386__
199 "lock; xchgl %0,(%1)"
200 #else
201 "lock; xchgq %0,(%1)"
202 #endif
203 : "=r" (ret)
204 : "r" (dest), "0" (newval)
205 : "memory"
207 return ret;
210 static __inline ALboolean CompExchangePtr(XchgPtr *dest, void *oldval, void *newval)
212 void *ret;
213 __asm__ __volatile__(
214 #ifdef __i386__
215 "lock; cmpxchgl %2,(%1)"
216 #else
217 "lock; cmpxchgq %2,(%1)"
218 #endif
219 : "=a" (ret)
220 : "r" (dest), "r" (newval), "0" (oldval)
221 : "memory"
223 return ret == oldval;
226 #elif defined(_WIN32)
228 typedef LONG RefCount;
229 static __inline RefCount IncrementRef(volatile RefCount *ptr)
230 { return InterlockedIncrement(ptr); }
231 static __inline RefCount DecrementRef(volatile RefCount *ptr)
232 { return InterlockedDecrement(ptr); }
234 extern ALbyte LONG_size_does_not_match_int[(sizeof(LONG)==sizeof(int))?1:-1];
236 static __inline int ExchangeInt(volatile int *ptr, int newval)
238 union {
239 volatile int *i;
240 volatile LONG *l;
241 } u = { ptr };
242 return InterlockedExchange(u.l, newval);
244 static __inline void *ExchangePtr(XchgPtr *ptr, void *newval)
246 return InterlockedExchangePointer(ptr, newval);
248 static __inline ALboolean CompExchangeInt(volatile int *ptr, int oldval, int newval)
250 union {
251 volatile int *i;
252 volatile LONG *l;
253 } u = { ptr };
254 return InterlockedCompareExchange(u.l, newval, oldval) == oldval;
256 static __inline ALboolean CompExchangePtr(XchgPtr *ptr, void *oldval, void *newval)
258 return InterlockedCompareExchangePointer(ptr, newval, oldval) == oldval;
261 #elif defined(__APPLE__)
263 #include <libkern/OSAtomic.h>
265 typedef int32_t RefCount;
266 static __inline RefCount IncrementRef(volatile RefCount *ptr)
267 { return OSAtomicIncrement32Barrier(ptr); }
268 static __inline RefCount DecrementRef(volatile RefCount *ptr)
269 { return OSAtomicDecrement32Barrier(ptr); }
271 static __inline int ExchangeInt(volatile int *ptr, int newval)
273 /* Really? No regular old atomic swap? */
274 int oldval;
275 do {
276 oldval = *ptr;
277 } while(!OSAtomicCompareAndSwap32Barrier(oldval, newval, ptr));
278 return oldval;
280 static __inline void *ExchangePtr(XchgPtr *ptr, void *newval)
282 void *oldval;
283 do {
284 oldval = *ptr;
285 } while(!OSAtomicCompareAndSwapPtrBarrier(oldval, newval, ptr));
286 return oldval;
288 static __inline ALboolean CompExchangeInt(volatile int *ptr, int oldval, int newval)
290 return OSAtomicCompareAndSwap32Barrier(oldval, newval, ptr);
292 static __inline ALboolean CompExchangePtr(XchgPtr *ptr, void *oldval, void *newval)
294 return OSAtomicCompareAndSwapPtrBarrier(oldval, newval, ptr);
297 #else
298 #error "No atomic functions available on this platform!"
299 typedef ALuint RefCount;
300 #endif
303 typedef struct {
304 volatile RefCount read_count;
305 volatile RefCount write_count;
306 volatile ALenum read_lock;
307 volatile ALenum read_entry_lock;
308 volatile ALenum write_lock;
309 } RWLock;
311 void RWLockInit(RWLock *lock);
312 void ReadLock(RWLock *lock);
313 void ReadUnlock(RWLock *lock);
314 void WriteLock(RWLock *lock);
315 void WriteUnlock(RWLock *lock);
318 typedef struct UIntMap {
319 struct {
320 ALuint key;
321 ALvoid *value;
322 } *array;
323 ALsizei size;
324 ALsizei maxsize;
325 ALsizei limit;
326 RWLock lock;
327 } UIntMap;
328 extern UIntMap TlsDestructor;
330 void InitUIntMap(UIntMap *map, ALsizei limit);
331 void ResetUIntMap(UIntMap *map);
332 ALenum InsertUIntMapEntry(UIntMap *map, ALuint key, ALvoid *value);
333 ALvoid *RemoveUIntMapKey(UIntMap *map, ALuint key);
334 ALvoid *LookupUIntMapKey(UIntMap *map, ALuint key);
336 static __inline void LockUIntMapRead(UIntMap *map)
337 { ReadLock(&map->lock); }
338 static __inline void UnlockUIntMapRead(UIntMap *map)
339 { ReadUnlock(&map->lock); }
340 static __inline void LockUIntMapWrite(UIntMap *map)
341 { WriteLock(&map->lock); }
342 static __inline void UnlockUIntMapWrite(UIntMap *map)
343 { WriteUnlock(&map->lock); }
345 #include "alListener.h"
346 #include "alu.h"
348 #ifdef __cplusplus
349 extern "C" {
350 #endif
353 #define DEFAULT_OUTPUT_RATE (44100)
354 #define MIN_OUTPUT_RATE (8000)
356 #define SPEEDOFSOUNDMETRESPERSEC (343.3f)
357 #define AIRABSORBGAINHF (0.99426f) /* -0.05dB */
359 #define LOWPASSFREQREF (5000)
362 struct Hrtf;
365 // Find the next power-of-2 for non-power-of-2 numbers.
366 static __inline ALuint NextPowerOf2(ALuint value)
368 ALuint powerOf2 = 1;
370 if(value)
372 value--;
373 while(value)
375 value >>= 1;
376 powerOf2 <<= 1;
379 return powerOf2;
382 /* Fast float-to-int conversion. Assumes the FPU is already in round-to-zero
383 * mode. */
384 static __inline ALint fastf2i(ALfloat f)
386 ALint i;
387 #if defined(_MSC_VER) && defined(_M_IX86)
388 __asm fld f
389 __asm fistp i
390 #elif defined(__GNUC__) && (defined(__i386__) || defined(__x86_64__))
391 __asm__ __volatile__("flds %1\n\t"
392 "fistpl %0\n\t"
393 : "=m" (i)
394 : "m" (f));
395 #else
396 i = (ALint)f;
397 #endif
398 return i;
401 /* Fast float-to-uint conversion. Assumes the FPU is already in round-to-zero
402 * mode. */
403 static __inline ALuint fastf2u(ALfloat f)
404 { return fastf2i(f); }
407 enum DevProbe {
408 ALL_DEVICE_PROBE,
409 CAPTURE_DEVICE_PROBE
412 typedef struct {
413 ALCenum (*OpenPlayback)(ALCdevice*, const ALCchar*);
414 void (*ClosePlayback)(ALCdevice*);
415 ALCboolean (*ResetPlayback)(ALCdevice*);
416 ALCboolean (*StartPlayback)(ALCdevice*);
417 void (*StopPlayback)(ALCdevice*);
419 ALCenum (*OpenCapture)(ALCdevice*, const ALCchar*);
420 void (*CloseCapture)(ALCdevice*);
421 void (*StartCapture)(ALCdevice*);
422 void (*StopCapture)(ALCdevice*);
423 ALCenum (*CaptureSamples)(ALCdevice*, void*, ALCuint);
424 ALCuint (*AvailableSamples)(ALCdevice*);
425 } BackendFuncs;
427 struct BackendInfo {
428 const char *name;
429 ALCboolean (*Init)(BackendFuncs*);
430 void (*Deinit)(void);
431 void (*Probe)(enum DevProbe);
432 BackendFuncs Funcs;
435 ALCboolean alc_alsa_init(BackendFuncs *func_list);
436 void alc_alsa_deinit(void);
437 void alc_alsa_probe(enum DevProbe type);
438 ALCboolean alc_oss_init(BackendFuncs *func_list);
439 void alc_oss_deinit(void);
440 void alc_oss_probe(enum DevProbe type);
441 ALCboolean alc_solaris_init(BackendFuncs *func_list);
442 void alc_solaris_deinit(void);
443 void alc_solaris_probe(enum DevProbe type);
444 ALCboolean alc_sndio_init(BackendFuncs *func_list);
445 void alc_sndio_deinit(void);
446 void alc_sndio_probe(enum DevProbe type);
447 ALCboolean alcMMDevApiInit(BackendFuncs *func_list);
448 void alcMMDevApiDeinit(void);
449 void alcMMDevApiProbe(enum DevProbe type);
450 ALCboolean alcDSoundInit(BackendFuncs *func_list);
451 void alcDSoundDeinit(void);
452 void alcDSoundProbe(enum DevProbe type);
453 ALCboolean alcWinMMInit(BackendFuncs *FuncList);
454 void alcWinMMDeinit(void);
455 void alcWinMMProbe(enum DevProbe type);
456 ALCboolean alc_pa_init(BackendFuncs *func_list);
457 void alc_pa_deinit(void);
458 void alc_pa_probe(enum DevProbe type);
459 ALCboolean alc_wave_init(BackendFuncs *func_list);
460 void alc_wave_deinit(void);
461 void alc_wave_probe(enum DevProbe type);
462 ALCboolean alc_pulse_init(BackendFuncs *func_list);
463 void alc_pulse_deinit(void);
464 void alc_pulse_probe(enum DevProbe type);
465 ALCboolean alc_ca_init(BackendFuncs *func_list);
466 void alc_ca_deinit(void);
467 void alc_ca_probe(enum DevProbe type);
468 ALCboolean alc_opensl_init(BackendFuncs *func_list);
469 void alc_opensl_deinit(void);
470 void alc_opensl_probe(enum DevProbe type);
471 ALCboolean alc_null_init(BackendFuncs *func_list);
472 void alc_null_deinit(void);
473 void alc_null_probe(enum DevProbe type);
474 ALCboolean alc_loopback_init(BackendFuncs *func_list);
475 void alc_loopback_deinit(void);
476 void alc_loopback_probe(enum DevProbe type);
479 /* Device formats */
480 enum DevFmtType {
481 DevFmtByte = ALC_BYTE_SOFT,
482 DevFmtUByte = ALC_UNSIGNED_BYTE_SOFT,
483 DevFmtShort = ALC_SHORT_SOFT,
484 DevFmtUShort = ALC_UNSIGNED_SHORT_SOFT,
485 DevFmtInt = ALC_INT_SOFT,
486 DevFmtUInt = ALC_UNSIGNED_INT_SOFT,
487 DevFmtFloat = ALC_FLOAT_SOFT,
489 DevFmtTypeDefault = DevFmtFloat
491 enum DevFmtChannels {
492 DevFmtMono = ALC_MONO_SOFT,
493 DevFmtStereo = ALC_STEREO_SOFT,
494 DevFmtQuad = ALC_QUAD_SOFT,
495 DevFmtX51 = ALC_5POINT1_SOFT,
496 DevFmtX61 = ALC_6POINT1_SOFT,
497 DevFmtX71 = ALC_7POINT1_SOFT,
499 /* Similar to 5.1, except using the side channels instead of back */
500 DevFmtX51Side = 0x80000000,
502 DevFmtChannelsDefault = DevFmtStereo
505 ALuint BytesFromDevFmt(enum DevFmtType type);
506 ALuint ChannelsFromDevFmt(enum DevFmtChannels chans);
507 static __inline ALuint FrameSizeFromDevFmt(enum DevFmtChannels chans,
508 enum DevFmtType type)
510 return ChannelsFromDevFmt(chans) * BytesFromDevFmt(type);
514 extern const struct EffectList {
515 const char *name;
516 int type;
517 const char *ename;
518 ALenum val;
519 } EffectList[];
522 enum DeviceType {
523 Playback,
524 Capture,
525 Loopback
528 struct ALCdevice_struct
530 volatile RefCount ref;
532 ALCboolean Connected;
533 enum DeviceType Type;
535 CRITICAL_SECTION Mutex;
537 ALuint Frequency;
538 ALuint UpdateSize;
539 ALuint NumUpdates;
540 enum DevFmtChannels FmtChans;
541 enum DevFmtType FmtType;
543 ALCchar *DeviceName;
545 volatile ALCenum LastError;
547 // Maximum number of sources that can be created
548 ALuint MaxNoOfSources;
549 // Maximum number of slots that can be created
550 ALuint AuxiliaryEffectSlotMax;
552 ALCuint NumMonoSources;
553 ALCuint NumStereoSources;
554 ALuint NumAuxSends;
556 // Map of Buffers for this device
557 UIntMap BufferMap;
559 // Map of Effects for this device
560 UIntMap EffectMap;
562 // Map of Filters for this device
563 UIntMap FilterMap;
565 /* HRTF filter tables */
566 const struct Hrtf *Hrtf;
568 // Stereo-to-binaural filter
569 struct bs2b *Bs2b;
570 ALCint Bs2bLevel;
572 // Device flags
573 ALuint Flags;
575 // Dry path buffer mix
576 ALfloat DryBuffer[BUFFERSIZE][MAXCHANNELS];
578 enum Channel DevChannels[MAXCHANNELS];
580 enum Channel Speaker2Chan[MAXCHANNELS];
581 ALfloat SpeakerAngle[MAXCHANNELS];
582 ALfloat PanningLUT[LUT_NUM][MAXCHANNELS];
583 ALuint NumChan;
585 ALfloat ClickRemoval[MAXCHANNELS];
586 ALfloat PendingClicks[MAXCHANNELS];
588 /* Default effect slot */
589 struct ALeffectslot *DefaultSlot;
591 // Contexts created on this device
592 ALCcontext *volatile ContextList;
594 BackendFuncs *Funcs;
595 void *ExtraData; // For the backend's use
597 ALCdevice *volatile next;
600 #define ALCdevice_OpenPlayback(a,b) ((a)->Funcs->OpenPlayback((a), (b)))
601 #define ALCdevice_ClosePlayback(a) ((a)->Funcs->ClosePlayback((a)))
602 #define ALCdevice_ResetPlayback(a) ((a)->Funcs->ResetPlayback((a)))
603 #define ALCdevice_StartPlayback(a) ((a)->Funcs->StartPlayback((a)))
604 #define ALCdevice_StopPlayback(a) ((a)->Funcs->StopPlayback((a)))
605 #define ALCdevice_OpenCapture(a,b) ((a)->Funcs->OpenCapture((a), (b)))
606 #define ALCdevice_CloseCapture(a) ((a)->Funcs->CloseCapture((a)))
607 #define ALCdevice_StartCapture(a) ((a)->Funcs->StartCapture((a)))
608 #define ALCdevice_StopCapture(a) ((a)->Funcs->StopCapture((a)))
609 #define ALCdevice_CaptureSamples(a,b,c) ((a)->Funcs->CaptureSamples((a), (b), (c)))
610 #define ALCdevice_AvailableSamples(a) ((a)->Funcs->AvailableSamples((a)))
612 // Frequency was requested by the app or config file
613 #define DEVICE_FREQUENCY_REQUEST (1<<1)
614 // Channel configuration was requested by the config file
615 #define DEVICE_CHANNELS_REQUEST (1<<2)
616 // Sample type was requested by the config file
617 #define DEVICE_SAMPLE_TYPE_REQUEST (1<<3)
619 // Specifies if the device is currently running
620 #define DEVICE_RUNNING (1<<31)
622 #define LookupBuffer(m, k) ((struct ALbuffer*)LookupUIntMapKey(&(m)->BufferMap, (k)))
623 #define LookupEffect(m, k) ((struct ALeffect*)LookupUIntMapKey(&(m)->EffectMap, (k)))
624 #define LookupFilter(m, k) ((struct ALfilter*)LookupUIntMapKey(&(m)->FilterMap, (k)))
625 #define RemoveBuffer(m, k) ((struct ALbuffer*)RemoveUIntMapKey(&(m)->BufferMap, (k)))
626 #define RemoveEffect(m, k) ((struct ALeffect*)RemoveUIntMapKey(&(m)->EffectMap, (k)))
627 #define RemoveFilter(m, k) ((struct ALfilter*)RemoveUIntMapKey(&(m)->FilterMap, (k)))
630 struct ALCcontext_struct
632 volatile RefCount ref;
634 ALlistener Listener;
636 UIntMap SourceMap;
637 UIntMap EffectSlotMap;
639 ALenum LastError;
641 volatile ALenum UpdateSources;
643 volatile enum DistanceModel DistanceModel;
644 volatile ALboolean SourceDistanceModel;
646 volatile ALfloat DopplerFactor;
647 volatile ALfloat DopplerVelocity;
648 volatile ALfloat SpeedOfSound;
649 volatile ALenum DeferUpdates;
651 struct ALsource **ActiveSources;
652 ALsizei ActiveSourceCount;
653 ALsizei MaxActiveSources;
655 struct ALeffectslot **ActiveEffectSlots;
656 ALsizei ActiveEffectSlotCount;
657 ALsizei MaxActiveEffectSlots;
659 ALCdevice *Device;
660 const ALCchar *ExtensionList;
662 ALCcontext *volatile next;
665 #define LookupSource(m, k) ((struct ALsource*)LookupUIntMapKey(&(m)->SourceMap, (k)))
666 #define LookupEffectSlot(m, k) ((struct ALeffectslot*)LookupUIntMapKey(&(m)->EffectSlotMap, (k)))
667 #define RemoveSource(m, k) ((struct ALsource*)RemoveUIntMapKey(&(m)->SourceMap, (k)))
668 #define RemoveEffectSlot(m, k) ((struct ALeffectslot*)RemoveUIntMapKey(&(m)->EffectSlotMap, (k)))
670 ALCcontext *GetContextRef(void);
672 void ALCcontext_IncRef(ALCcontext *context);
673 void ALCcontext_DecRef(ALCcontext *context);
675 void AppendAllDeviceList(const ALCchar *name);
676 void AppendCaptureDeviceList(const ALCchar *name);
678 static __inline void LockDevice(ALCdevice *device)
679 { EnterCriticalSection(&device->Mutex); }
680 static __inline void UnlockDevice(ALCdevice *device)
681 { LeaveCriticalSection(&device->Mutex); }
683 static __inline void LockContext(ALCcontext *context)
684 { LockDevice(context->Device); }
685 static __inline void UnlockContext(ALCcontext *context)
686 { UnlockDevice(context->Device); }
689 ALvoid *StartThread(ALuint (*func)(ALvoid*), ALvoid *ptr);
690 ALuint StopThread(ALvoid *thread);
692 typedef struct RingBuffer RingBuffer;
693 RingBuffer *CreateRingBuffer(ALsizei frame_size, ALsizei length);
694 void DestroyRingBuffer(RingBuffer *ring);
695 ALsizei RingBufferSize(RingBuffer *ring);
696 void WriteRingBuffer(RingBuffer *ring, const ALubyte *data, ALsizei len);
697 void ReadRingBuffer(RingBuffer *ring, ALubyte *data, ALsizei len);
699 void ReadALConfig(void);
700 void FreeALConfig(void);
701 int ConfigValueExists(const char *blockName, const char *keyName);
702 const char *GetConfigValue(const char *blockName, const char *keyName, const char *def);
703 int GetConfigValueBool(const char *blockName, const char *keyName, int def);
704 int ConfigValueStr(const char *blockName, const char *keyName, const char **ret);
705 int ConfigValueInt(const char *blockName, const char *keyName, int *ret);
706 int ConfigValueUInt(const char *blockName, const char *keyName, unsigned int *ret);
707 int ConfigValueFloat(const char *blockName, const char *keyName, float *ret);
709 void SetRTPriority(void);
711 void SetDefaultChannelOrder(ALCdevice *device);
712 void SetDefaultWFXChannelOrder(ALCdevice *device);
714 const ALCchar *DevFmtTypeString(enum DevFmtType type);
715 const ALCchar *DevFmtChannelsString(enum DevFmtChannels chans);
717 #define HRIR_BITS (5)
718 #define HRIR_LENGTH (1<<HRIR_BITS)
719 #define HRIR_MASK (HRIR_LENGTH-1)
720 void InitHrtf(void);
721 void FreeHrtf(void);
722 const struct Hrtf *GetHrtf(ALCdevice *device);
723 ALfloat CalcHrtfDelta(ALfloat oldGain, ALfloat newGain, const ALfloat olddir[3], const ALfloat newdir[3]);
724 void GetLerpedHrtfCoeffs(const struct Hrtf *Hrtf, ALfloat elevation, ALfloat azimuth, ALfloat gain, ALfloat (*coeffs)[2], ALuint *delays);
725 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);
727 void al_print(const char *func, const char *fmt, ...) PRINTF_STYLE(2,3);
728 #define AL_PRINT(...) al_print(__FUNCTION__, __VA_ARGS__)
730 extern FILE *LogFile;
731 enum LogLevel {
732 NoLog,
733 LogError,
734 LogWarning,
735 LogTrace,
736 LogRef
738 extern enum LogLevel LogLevel;
740 #define TRACEREF(...) do { \
741 if(LogLevel >= LogRef) \
742 AL_PRINT(__VA_ARGS__); \
743 } while(0)
745 #define TRACE(...) do { \
746 if(LogLevel >= LogTrace) \
747 AL_PRINT(__VA_ARGS__); \
748 } while(0)
750 #define WARN(...) do { \
751 if(LogLevel >= LogWarning) \
752 AL_PRINT(__VA_ARGS__); \
753 } while(0)
755 #define ERR(...) do { \
756 if(LogLevel >= LogError) \
757 AL_PRINT(__VA_ARGS__); \
758 } while(0)
761 extern ALint RTPrioLevel;
764 * Starts a try block. Must not be nested within another try block within the
765 * same function.
767 #define al_try do { \
768 int _al_err=0; \
769 _al_try_label: \
770 if(_al_err == 0)
772 * After a try or another catch block, runs the next block if the given value
773 * was thrown.
775 #define al_catch(val) else if(_al_err == (val))
777 * After a try or catch block, runs the next block for any value thrown and not
778 * caught.
780 #define al_catchany() else
781 /** Marks the end of the final catch (or the try) block. */
782 #define al_endtry } while(0)
785 * The given integer value is "thrown" so as to be caught by a catch block.
786 * Must be called in a try block within the same function. The value must not
787 * be 0.
789 #define al_throw(e) do { \
790 _al_err = (e); \
791 assert(_al_err != 0); \
792 goto _al_try_label; \
793 } while(0)
794 /** Sets an AL error on the given context, before throwing the error code. */
795 #define al_throwerr(ctx, err) do { \
796 alSetError((ctx), (err)); \
797 al_throw((err)); \
798 } while(0)
801 * Throws an AL_INVALID_VALUE error with the given ctx if the given condition
802 * is false.
804 #define CHECK_VALUE(ctx, cond) do { \
805 if(!(cond)) \
806 al_throwerr((ctx), AL_INVALID_VALUE); \
807 } while(0)
809 #ifdef __cplusplus
811 #endif
813 #endif