Always use "OpenAL Soft" for the short device enumeration list
[openal-soft.git] / OpenAL32 / Include / alMain.h
blobddb93c840eb920b5f518f11a92bdf8aa7cd3375b
1 #ifndef AL_MAIN_H
2 #define AL_MAIN_H
4 #include <string.h>
5 #include <stdio.h>
6 #include <stdarg.h>
8 #ifdef HAVE_FENV_H
9 #include <fenv.h>
10 #endif
12 #ifdef HAVE_FPU_CONTROL_H
13 #include <fpu_control.h>
14 #endif
16 #include "AL/al.h"
17 #include "AL/alc.h"
18 #include "AL/alext.h"
20 #ifndef ALC_SOFT_device_loopback
21 #define ALC_SOFT_device_loopback 1
22 #define ALC_FORMAT_CHANNELS_SOFT 0x1990
23 #define ALC_FORMAT_TYPE_SOFT 0x1991
25 /* Sample types */
26 #define ALC_BYTE_SOFT 0x1400
27 #define ALC_UNSIGNED_BYTE_SOFT 0x1401
28 #define ALC_SHORT_SOFT 0x1402
29 #define ALC_UNSIGNED_SHORT_SOFT 0x1403
30 #define ALC_INT_SOFT 0x1404
31 #define ALC_UNSIGNED_INT_SOFT 0x1405
32 #define ALC_FLOAT_SOFT 0x1406
34 /* Channel configurations */
35 #define ALC_MONO_SOFT 0x1500
36 #define ALC_STEREO_SOFT 0x1501
37 #define ALC_QUAD_SOFT 0x1503
38 #define ALC_5POINT1_SOFT 0x1504 /* (WFX order) */
39 #define ALC_6POINT1_SOFT 0x1505 /* (WFX order) */
40 #define ALC_7POINT1_SOFT 0x1506 /* (WFX order) */
42 typedef ALCdevice* (ALC_APIENTRY*LPALCLOOPBACKOPENDEVICESOFT)(ALCdevice*);
43 typedef ALCboolean (ALC_APIENTRY*LPALCISRENDERFORMATSUPPORTEDSOFT)(ALCdevice*,ALCsizei,ALCenum,ALCenum);
44 typedef void (ALC_APIENTRY*LPALCRENDERSAMPLESSOFT)(ALCdevice*,ALCvoid*,ALCsizei);
45 #ifdef AL_ALEXT_PROTOTYPES
46 ALC_API ALCdevice* ALC_APIENTRY alcLoopbackOpenDeviceSOFT(ALCdevice *device);
47 ALC_API ALCboolean ALC_APIENTRY alcIsRenderFormatSupportedSOFT(ALCdevice *device, ALCsizei freq, ALCenum channels, ALCenum type);
48 ALC_API void ALC_APIENTRY alcRenderSamplesSOFT(ALCdevice *device, ALCvoid *buffer, ALCsizei samples);
49 #endif
50 #endif
52 #ifndef AL_SOFT_direct_channels
53 #define AL_SOFT_direct_channels 1
54 #define AL_DIRECT_CHANNELS_SOFT 0x1033
55 #endif
57 #ifndef AL_SOFT_deferred_updates
58 #define AL_SOFT_deferred_updates 1
59 #define AL_DEFERRED_UPDATES_SOFT 0xC002
60 typedef ALvoid (AL_APIENTRY*LPALDEFERUPDATESSOFT)(void);
61 typedef ALvoid (AL_APIENTRY*LPALPROCESSUPDATESSOFT)(void);
62 #ifdef AL_ALEXT_PROTOTYPES
63 AL_API ALvoid AL_APIENTRY alDeferUpdatesSOFT(void);
64 AL_API ALvoid AL_APIENTRY alProcessUpdatesSOFT(void);
65 #endif
66 #endif
69 #if defined(HAVE_STDINT_H)
70 #include <stdint.h>
71 typedef int64_t ALint64;
72 typedef uint64_t ALuint64;
73 #elif defined(HAVE___INT64)
74 typedef __int64 ALint64;
75 typedef unsigned __int64 ALuint64;
76 #elif (SIZEOF_LONG == 8)
77 typedef long ALint64;
78 typedef unsigned long ALuint64;
79 #elif (SIZEOF_LONG_LONG == 8)
80 typedef long long ALint64;
81 typedef unsigned long long ALuint64;
82 #endif
84 typedef ptrdiff_t ALintptrEXT;
85 typedef ptrdiff_t ALsizeiptrEXT;
87 #ifdef HAVE_GCC_FORMAT
88 #define PRINTF_STYLE(x, y) __attribute__((format(printf, (x), (y))))
89 #else
90 #define PRINTF_STYLE(x, y)
91 #endif
93 #if defined(HAVE_RESTRICT)
94 #define RESTRICT restrict
95 #elif defined(HAVE___RESTRICT)
96 #define RESTRICT __restrict
97 #else
98 #define RESTRICT
99 #endif
102 static const union {
103 ALuint u;
104 ALubyte b[sizeof(ALuint)];
105 } EndianTest = { 1 };
106 #define IS_LITTLE_ENDIAN (EndianTest.b[0] == 1)
108 #define COUNTOF(x) (sizeof((x))/sizeof((x)[0]))
110 #ifdef _WIN32
112 #include <windows.h>
114 typedef DWORD pthread_key_t;
115 int pthread_key_create(pthread_key_t *key, void (*callback)(void*));
116 int pthread_key_delete(pthread_key_t key);
117 void *pthread_getspecific(pthread_key_t key);
118 int pthread_setspecific(pthread_key_t key, void *val);
120 #define HAVE_DYNLOAD 1
121 void *LoadLib(const char *name);
122 void CloseLib(void *handle);
123 void *GetSymbol(void *handle, const char *name);
125 typedef LONG pthread_once_t;
126 #define PTHREAD_ONCE_INIT 0
127 void pthread_once(pthread_once_t *once, void (*callback)(void));
129 static __inline int sched_yield(void)
130 { SwitchToThread(); return 0; }
132 #else
134 #include <unistd.h>
135 #include <assert.h>
136 #include <pthread.h>
137 #ifdef HAVE_PTHREAD_NP_H
138 #include <pthread_np.h>
139 #endif
140 #include <sys/time.h>
141 #include <time.h>
142 #include <errno.h>
144 #define IsBadWritePtr(a,b) ((a) == NULL && (b) != 0)
146 typedef pthread_mutex_t CRITICAL_SECTION;
147 void InitializeCriticalSection(CRITICAL_SECTION *cs);
148 void DeleteCriticalSection(CRITICAL_SECTION *cs);
149 void EnterCriticalSection(CRITICAL_SECTION *cs);
150 void LeaveCriticalSection(CRITICAL_SECTION *cs);
152 ALuint timeGetTime(void);
153 void Sleep(ALuint t);
155 #if defined(HAVE_DLFCN_H)
156 #define HAVE_DYNLOAD 1
157 void *LoadLib(const char *name);
158 void CloseLib(void *handle);
159 void *GetSymbol(void *handle, const char *name);
160 #endif
162 #endif
164 typedef void *volatile XchgPtr;
166 #if defined(__GNUC__) && (__GNUC__ > 4 || (__GNUC__ == 4 && __GNUC_MINOR__ >= 1))
167 typedef ALuint RefCount;
168 static __inline RefCount IncrementRef(volatile RefCount *ptr)
169 { return __sync_add_and_fetch(ptr, 1); }
170 static __inline RefCount DecrementRef(volatile RefCount *ptr)
171 { return __sync_sub_and_fetch(ptr, 1); }
173 static __inline int ExchangeInt(volatile int *ptr, int newval)
175 return __sync_lock_test_and_set(ptr, newval);
177 static __inline void *ExchangePtr(XchgPtr *ptr, void *newval)
179 return __sync_lock_test_and_set(ptr, newval);
181 static __inline ALboolean CompExchangeInt(volatile int *ptr, int oldval, int newval)
183 return __sync_bool_compare_and_swap(ptr, oldval, newval);
185 static __inline ALboolean CompExchangePtr(XchgPtr *ptr, void *oldval, void *newval)
187 return __sync_bool_compare_and_swap(ptr, oldval, newval);
190 #elif defined(__GNUC__) && (defined(__i386__) || defined(__x86_64__))
192 static __inline int xaddl(volatile int *dest, int incr)
194 int ret;
195 __asm__ __volatile__("lock; xaddl %0,(%1)"
196 : "=r" (ret)
197 : "r" (dest), "0" (incr)
198 : "memory");
199 return ret;
202 typedef int RefCount;
203 static __inline RefCount IncrementRef(volatile RefCount *ptr)
204 { return xaddl(ptr, 1)+1; }
205 static __inline RefCount DecrementRef(volatile RefCount *ptr)
206 { return xaddl(ptr, -1)-1; }
208 static __inline int ExchangeInt(volatile int *dest, int newval)
210 int ret;
211 __asm__ __volatile__("lock; xchgl %0,(%1)"
212 : "=r" (ret)
213 : "r" (dest), "0" (newval)
214 : "memory");
215 return ret;
218 static __inline ALboolean CompExchangeInt(volatile int *dest, int oldval, int newval)
220 int ret;
221 __asm__ __volatile__("lock; cmpxchgl %2,(%1)"
222 : "=a" (ret)
223 : "r" (dest), "r" (newval), "0" (oldval)
224 : "memory");
225 return ret == oldval;
228 static __inline void *ExchangePtr(XchgPtr *dest, void *newval)
230 void *ret;
231 __asm__ __volatile__(
232 #ifdef __i386__
233 "lock; xchgl %0,(%1)"
234 #else
235 "lock; xchgq %0,(%1)"
236 #endif
237 : "=r" (ret)
238 : "r" (dest), "0" (newval)
239 : "memory"
241 return ret;
244 static __inline ALboolean CompExchangePtr(XchgPtr *dest, void *oldval, void *newval)
246 void *ret;
247 __asm__ __volatile__(
248 #ifdef __i386__
249 "lock; cmpxchgl %2,(%1)"
250 #else
251 "lock; cmpxchgq %2,(%1)"
252 #endif
253 : "=a" (ret)
254 : "r" (dest), "r" (newval), "0" (oldval)
255 : "memory"
257 return ret == oldval;
260 #elif defined(_WIN32)
262 typedef LONG RefCount;
263 static __inline RefCount IncrementRef(volatile RefCount *ptr)
264 { return InterlockedIncrement(ptr); }
265 static __inline RefCount DecrementRef(volatile RefCount *ptr)
266 { return InterlockedDecrement(ptr); }
268 extern ALbyte LONG_size_does_not_match_int[(sizeof(LONG)==sizeof(int))?1:-1];
270 static __inline int ExchangeInt(volatile int *ptr, int newval)
272 union {
273 volatile int *i;
274 volatile LONG *l;
275 } u = { ptr };
276 return InterlockedExchange(u.l, newval);
278 static __inline void *ExchangePtr(XchgPtr *ptr, void *newval)
280 return InterlockedExchangePointer(ptr, newval);
282 static __inline ALboolean CompExchangeInt(volatile int *ptr, int oldval, int newval)
284 union {
285 volatile int *i;
286 volatile LONG *l;
287 } u = { ptr };
288 return InterlockedCompareExchange(u.l, newval, oldval) == oldval;
290 static __inline ALboolean CompExchangePtr(XchgPtr *ptr, void *oldval, void *newval)
292 return InterlockedCompareExchangePointer(ptr, newval, oldval) == oldval;
295 #elif defined(__APPLE__)
297 #include <libkern/OSAtomic.h>
299 typedef int32_t RefCount;
300 static __inline RefCount IncrementRef(volatile RefCount *ptr)
301 { return OSAtomicIncrement32Barrier(ptr); }
302 static __inline RefCount DecrementRef(volatile RefCount *ptr)
303 { return OSAtomicDecrement32Barrier(ptr); }
305 static __inline int ExchangeInt(volatile int *ptr, int newval)
307 /* Really? No regular old atomic swap? */
308 int oldval;
309 do {
310 oldval = *ptr;
311 } while(!OSAtomicCompareAndSwap32Barrier(oldval, newval, ptr));
312 return oldval;
314 static __inline void *ExchangePtr(XchgPtr *ptr, void *newval)
316 void *oldval;
317 do {
318 oldval = *ptr;
319 } while(!OSAtomicCompareAndSwapPtrBarrier(oldval, newval, ptr));
320 return oldval;
322 static __inline ALboolean CompExchangeInt(volatile int *ptr, int oldval, int newval)
324 return OSAtomicCompareAndSwap32Barrier(oldval, newval, ptr);
326 static __inline ALboolean CompExchangePtr(XchgPtr *ptr, void *oldval, void *newval)
328 return OSAtomicCompareAndSwapPtrBarrier(oldval, newval, ptr);
331 #else
332 #error "No atomic functions available on this platform!"
333 typedef ALuint RefCount;
334 #endif
337 typedef struct {
338 volatile RefCount read_count;
339 volatile RefCount write_count;
340 volatile ALenum read_lock;
341 volatile ALenum read_entry_lock;
342 volatile ALenum write_lock;
343 } RWLock;
345 void RWLockInit(RWLock *lock);
346 void ReadLock(RWLock *lock);
347 void ReadUnlock(RWLock *lock);
348 void WriteLock(RWLock *lock);
349 void WriteUnlock(RWLock *lock);
352 typedef struct UIntMap {
353 struct {
354 ALuint key;
355 ALvoid *value;
356 } *array;
357 ALsizei size;
358 ALsizei maxsize;
359 ALsizei limit;
360 RWLock lock;
361 } UIntMap;
362 extern UIntMap TlsDestructor;
364 void InitUIntMap(UIntMap *map, ALsizei limit);
365 void ResetUIntMap(UIntMap *map);
366 ALenum InsertUIntMapEntry(UIntMap *map, ALuint key, ALvoid *value);
367 ALvoid *RemoveUIntMapKey(UIntMap *map, ALuint key);
368 ALvoid *LookupUIntMapKey(UIntMap *map, ALuint key);
370 static __inline void LockUIntMapRead(UIntMap *map)
371 { ReadLock(&map->lock); }
372 static __inline void UnlockUIntMapRead(UIntMap *map)
373 { ReadUnlock(&map->lock); }
374 static __inline void LockUIntMapWrite(UIntMap *map)
375 { WriteLock(&map->lock); }
376 static __inline void UnlockUIntMapWrite(UIntMap *map)
377 { WriteUnlock(&map->lock); }
379 #include "alListener.h"
380 #include "alu.h"
382 #ifdef __cplusplus
383 extern "C" {
384 #endif
387 #define DEFAULT_OUTPUT_RATE (44100)
388 #define MIN_OUTPUT_RATE (8000)
390 #define SPEEDOFSOUNDMETRESPERSEC (343.3f)
391 #define AIRABSORBGAINHF (0.99426f) /* -0.05dB */
393 #define LOWPASSFREQREF (5000)
396 struct Hrtf;
399 // Find the next power-of-2 for non-power-of-2 numbers.
400 static __inline ALuint NextPowerOf2(ALuint value)
402 ALuint powerOf2 = 1;
404 if(value)
406 value--;
407 while(value)
409 value >>= 1;
410 powerOf2 <<= 1;
413 return powerOf2;
416 /* Fast float-to-int conversion. Assumes the FPU is already in round-to-zero
417 * mode. */
418 static __inline ALint fastf2i(ALfloat f)
420 ALint i;
421 #if defined(_MSC_VER) && defined(_M_IX86)
422 __asm fld f
423 __asm fistp i
424 #elif defined(__GNUC__) && (defined(__i386__) || defined(__x86_64__))
425 __asm__ __volatile__("flds %1\n\t"
426 "fistpl %0\n\t"
427 : "=m" (i)
428 : "m" (f));
429 #else
430 i = (ALint)f;
431 #endif
432 return i;
435 /* Fast float-to-uint conversion. Assumes the FPU is already in round-to-zero
436 * mode. */
437 static __inline ALuint fastf2u(ALfloat f)
438 { return fastf2i(f); }
441 enum DevProbe {
442 ALL_DEVICE_PROBE,
443 CAPTURE_DEVICE_PROBE
446 typedef struct {
447 ALCenum (*OpenPlayback)(ALCdevice*, const ALCchar*);
448 void (*ClosePlayback)(ALCdevice*);
449 ALCboolean (*ResetPlayback)(ALCdevice*);
450 void (*StopPlayback)(ALCdevice*);
452 ALCenum (*OpenCapture)(ALCdevice*, const ALCchar*);
453 void (*CloseCapture)(ALCdevice*);
454 void (*StartCapture)(ALCdevice*);
455 void (*StopCapture)(ALCdevice*);
456 ALCenum (*CaptureSamples)(ALCdevice*, void*, ALCuint);
457 ALCuint (*AvailableSamples)(ALCdevice*);
458 } BackendFuncs;
460 struct BackendInfo {
461 const char *name;
462 ALCboolean (*Init)(BackendFuncs*);
463 void (*Deinit)(void);
464 void (*Probe)(enum DevProbe);
465 BackendFuncs Funcs;
468 ALCboolean alc_alsa_init(BackendFuncs *func_list);
469 void alc_alsa_deinit(void);
470 void alc_alsa_probe(enum DevProbe type);
471 ALCboolean alc_oss_init(BackendFuncs *func_list);
472 void alc_oss_deinit(void);
473 void alc_oss_probe(enum DevProbe type);
474 ALCboolean alc_solaris_init(BackendFuncs *func_list);
475 void alc_solaris_deinit(void);
476 void alc_solaris_probe(enum DevProbe type);
477 ALCboolean alc_sndio_init(BackendFuncs *func_list);
478 void alc_sndio_deinit(void);
479 void alc_sndio_probe(enum DevProbe type);
480 ALCboolean alcMMDevApiInit(BackendFuncs *func_list);
481 void alcMMDevApiDeinit(void);
482 void alcMMDevApiProbe(enum DevProbe type);
483 ALCboolean alcDSoundInit(BackendFuncs *func_list);
484 void alcDSoundDeinit(void);
485 void alcDSoundProbe(enum DevProbe type);
486 ALCboolean alcWinMMInit(BackendFuncs *FuncList);
487 void alcWinMMDeinit(void);
488 void alcWinMMProbe(enum DevProbe type);
489 ALCboolean alc_pa_init(BackendFuncs *func_list);
490 void alc_pa_deinit(void);
491 void alc_pa_probe(enum DevProbe type);
492 ALCboolean alc_wave_init(BackendFuncs *func_list);
493 void alc_wave_deinit(void);
494 void alc_wave_probe(enum DevProbe type);
495 ALCboolean alc_pulse_init(BackendFuncs *func_list);
496 void alc_pulse_deinit(void);
497 void alc_pulse_probe(enum DevProbe type);
498 ALCboolean alc_ca_init(BackendFuncs *func_list);
499 void alc_ca_deinit(void);
500 void alc_ca_probe(enum DevProbe type);
501 ALCboolean alc_opensl_init(BackendFuncs *func_list);
502 void alc_opensl_deinit(void);
503 void alc_opensl_probe(enum DevProbe type);
504 ALCboolean alc_null_init(BackendFuncs *func_list);
505 void alc_null_deinit(void);
506 void alc_null_probe(enum DevProbe type);
507 ALCboolean alc_loopback_init(BackendFuncs *func_list);
508 void alc_loopback_deinit(void);
509 void alc_loopback_probe(enum DevProbe type);
512 /* Device formats */
513 enum DevFmtType {
514 DevFmtByte = ALC_BYTE_SOFT,
515 DevFmtUByte = ALC_UNSIGNED_BYTE_SOFT,
516 DevFmtShort = ALC_SHORT_SOFT,
517 DevFmtUShort = ALC_UNSIGNED_SHORT_SOFT,
518 DevFmtInt = ALC_INT_SOFT,
519 DevFmtUInt = ALC_UNSIGNED_INT_SOFT,
520 DevFmtFloat = ALC_FLOAT_SOFT
522 enum DevFmtChannels {
523 DevFmtMono = ALC_MONO_SOFT,
524 DevFmtStereo = ALC_STEREO_SOFT,
525 DevFmtQuad = ALC_QUAD_SOFT,
526 DevFmtX51 = ALC_5POINT1_SOFT,
527 DevFmtX61 = ALC_6POINT1_SOFT,
528 DevFmtX71 = ALC_7POINT1_SOFT,
530 /* Similar to 5.1, except using the side channels instead of back */
531 DevFmtX51Side = 0x80000000 | ALC_5POINT1_SOFT
534 ALuint BytesFromDevFmt(enum DevFmtType type);
535 ALuint ChannelsFromDevFmt(enum DevFmtChannels chans);
536 static __inline ALuint FrameSizeFromDevFmt(enum DevFmtChannels chans,
537 enum DevFmtType type)
539 return ChannelsFromDevFmt(chans) * BytesFromDevFmt(type);
543 extern const struct EffectList {
544 const char *name;
545 int type;
546 const char *ename;
547 ALenum val;
548 } EffectList[];
551 struct ALCdevice_struct
553 volatile RefCount ref;
555 ALCboolean Connected;
556 ALboolean IsCaptureDevice;
557 ALboolean IsLoopbackDevice;
559 CRITICAL_SECTION Mutex;
561 ALuint Frequency;
562 ALuint UpdateSize;
563 ALuint NumUpdates;
564 enum DevFmtChannels FmtChans;
565 enum DevFmtType FmtType;
567 ALCchar *szDeviceName;
569 volatile ALCenum LastError;
571 // Maximum number of sources that can be created
572 ALuint MaxNoOfSources;
573 // Maximum number of slots that can be created
574 ALuint AuxiliaryEffectSlotMax;
576 ALCuint NumMonoSources;
577 ALCuint NumStereoSources;
578 ALuint NumAuxSends;
580 // Map of Buffers for this device
581 UIntMap BufferMap;
583 // Map of Effects for this device
584 UIntMap EffectMap;
586 // Map of Filters for this device
587 UIntMap FilterMap;
589 /* HRTF filter tables */
590 const struct Hrtf *Hrtf;
592 // Stereo-to-binaural filter
593 struct bs2b *Bs2b;
594 ALCint Bs2bLevel;
596 // Device flags
597 ALuint Flags;
599 // Dry path buffer mix
600 ALfloat DryBuffer[BUFFERSIZE][MAXCHANNELS];
602 enum Channel DevChannels[MAXCHANNELS];
604 enum Channel Speaker2Chan[MAXCHANNELS];
605 ALfloat PanningLUT[LUT_NUM][MAXCHANNELS];
606 ALuint NumChan;
608 ALfloat ClickRemoval[MAXCHANNELS];
609 ALfloat PendingClicks[MAXCHANNELS];
611 /* Default effect slot */
612 struct ALeffectslot *DefaultSlot;
614 // Contexts created on this device
615 ALCcontext *volatile ContextList;
617 BackendFuncs *Funcs;
618 void *ExtraData; // For the backend's use
620 ALCdevice *volatile next;
623 #define ALCdevice_OpenPlayback(a,b) ((a)->Funcs->OpenPlayback((a), (b)))
624 #define ALCdevice_ClosePlayback(a) ((a)->Funcs->ClosePlayback((a)))
625 #define ALCdevice_ResetPlayback(a) ((a)->Funcs->ResetPlayback((a)))
626 #define ALCdevice_StopPlayback(a) ((a)->Funcs->StopPlayback((a)))
627 #define ALCdevice_OpenCapture(a,b) ((a)->Funcs->OpenCapture((a), (b)))
628 #define ALCdevice_CloseCapture(a) ((a)->Funcs->CloseCapture((a)))
629 #define ALCdevice_StartCapture(a) ((a)->Funcs->StartCapture((a)))
630 #define ALCdevice_StopCapture(a) ((a)->Funcs->StopCapture((a)))
631 #define ALCdevice_CaptureSamples(a,b,c) ((a)->Funcs->CaptureSamples((a), (b), (c)))
632 #define ALCdevice_AvailableSamples(a) ((a)->Funcs->AvailableSamples((a)))
634 // Duplicate stereo sources on the side/rear channels
635 #define DEVICE_DUPLICATE_STEREO (1<<0)
636 // Frequency was requested by the app or config file
637 #define DEVICE_FREQUENCY_REQUEST (1<<1)
638 // Channel configuration was requested by the config file
639 #define DEVICE_CHANNELS_REQUEST (1<<2)
640 // Sample type was requested by the config file
641 #define DEVICE_SAMPLE_TYPE_REQUEST (1<<3)
643 // Specifies if the device is currently running
644 #define DEVICE_RUNNING (1<<31)
646 #define LookupBuffer(m, k) ((struct ALbuffer*)LookupUIntMapKey(&(m)->BufferMap, (k)))
647 #define LookupEffect(m, k) ((struct ALeffect*)LookupUIntMapKey(&(m)->EffectMap, (k)))
648 #define LookupFilter(m, k) ((struct ALfilter*)LookupUIntMapKey(&(m)->FilterMap, (k)))
649 #define RemoveBuffer(m, k) ((struct ALbuffer*)RemoveUIntMapKey(&(m)->BufferMap, (k)))
650 #define RemoveEffect(m, k) ((struct ALeffect*)RemoveUIntMapKey(&(m)->EffectMap, (k)))
651 #define RemoveFilter(m, k) ((struct ALfilter*)RemoveUIntMapKey(&(m)->FilterMap, (k)))
654 struct ALCcontext_struct
656 volatile RefCount ref;
658 ALlistener Listener;
660 UIntMap SourceMap;
661 UIntMap EffectSlotMap;
663 ALenum LastError;
665 volatile ALenum UpdateSources;
667 volatile enum DistanceModel DistanceModel;
668 volatile ALboolean SourceDistanceModel;
670 volatile ALfloat DopplerFactor;
671 volatile ALfloat DopplerVelocity;
672 volatile ALfloat flSpeedOfSound;
673 volatile ALenum DeferUpdates;
675 struct ALsource **ActiveSources;
676 ALsizei ActiveSourceCount;
677 ALsizei MaxActiveSources;
679 struct ALeffectslot **ActiveEffectSlots;
680 ALsizei ActiveEffectSlotCount;
681 ALsizei MaxActiveEffectSlots;
683 ALCdevice *Device;
684 const ALCchar *ExtensionList;
686 ALCcontext *volatile next;
689 #define LookupSource(m, k) ((struct ALsource*)LookupUIntMapKey(&(m)->SourceMap, (k)))
690 #define LookupEffectSlot(m, k) ((struct ALeffectslot*)LookupUIntMapKey(&(m)->EffectSlotMap, (k)))
691 #define RemoveSource(m, k) ((struct ALsource*)RemoveUIntMapKey(&(m)->SourceMap, (k)))
692 #define RemoveEffectSlot(m, k) ((struct ALeffectslot*)RemoveUIntMapKey(&(m)->EffectSlotMap, (k)))
694 ALCcontext *GetContextRef(void);
696 void ALCcontext_IncRef(ALCcontext *context);
697 void ALCcontext_DecRef(ALCcontext *context);
699 void AppendAllDeviceList(const ALCchar *name);
700 void AppendCaptureDeviceList(const ALCchar *name);
702 static __inline void LockDevice(ALCdevice *device)
703 { EnterCriticalSection(&device->Mutex); }
704 static __inline void UnlockDevice(ALCdevice *device)
705 { LeaveCriticalSection(&device->Mutex); }
707 static __inline void LockContext(ALCcontext *context)
708 { LockDevice(context->Device); }
709 static __inline void UnlockContext(ALCcontext *context)
710 { UnlockDevice(context->Device); }
713 ALvoid *StartThread(ALuint (*func)(ALvoid*), ALvoid *ptr);
714 ALuint StopThread(ALvoid *thread);
716 typedef struct RingBuffer RingBuffer;
717 RingBuffer *CreateRingBuffer(ALsizei frame_size, ALsizei length);
718 void DestroyRingBuffer(RingBuffer *ring);
719 ALsizei RingBufferSize(RingBuffer *ring);
720 void WriteRingBuffer(RingBuffer *ring, const ALubyte *data, ALsizei len);
721 void ReadRingBuffer(RingBuffer *ring, ALubyte *data, ALsizei len);
723 void ReadALConfig(void);
724 void FreeALConfig(void);
725 int ConfigValueExists(const char *blockName, const char *keyName);
726 const char *GetConfigValue(const char *blockName, const char *keyName, const char *def);
727 int GetConfigValueBool(const char *blockName, const char *keyName, int def);
728 int ConfigValueStr(const char *blockName, const char *keyName, const char **ret);
729 int ConfigValueInt(const char *blockName, const char *keyName, int *ret);
730 int ConfigValueUInt(const char *blockName, const char *keyName, unsigned int *ret);
731 int ConfigValueFloat(const char *blockName, const char *keyName, float *ret);
733 void SetRTPriority(void);
735 void SetDefaultChannelOrder(ALCdevice *device);
736 void SetDefaultWFXChannelOrder(ALCdevice *device);
738 const ALCchar *DevFmtTypeString(enum DevFmtType type);
739 const ALCchar *DevFmtChannelsString(enum DevFmtChannels chans);
741 #define HRIR_BITS (5)
742 #define HRIR_LENGTH (1<<HRIR_BITS)
743 #define HRIR_MASK (HRIR_LENGTH-1)
744 void InitHrtf(void);
745 void FreeHrtf(void);
746 const struct Hrtf *GetHrtf(ALCdevice *device);
747 ALfloat CalcHrtfDelta(ALfloat oldGain, ALfloat newGain, const ALfloat olddir[3], const ALfloat newdir[3]);
748 void GetLerpedHrtfCoeffs(const struct Hrtf *Hrtf, ALfloat elevation, ALfloat azimuth, ALfloat gain, ALfloat (*coeffs)[2], ALuint *delays);
749 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);
751 void al_print(const char *func, const char *fmt, ...) PRINTF_STYLE(2,3);
752 #define AL_PRINT(...) al_print(__FUNCTION__, __VA_ARGS__)
754 extern FILE *LogFile;
755 enum LogLevel {
756 NoLog,
757 LogError,
758 LogWarning,
759 LogTrace,
760 LogRef
762 extern enum LogLevel LogLevel;
764 #define TRACEREF(...) do { \
765 if(LogLevel >= LogRef) \
766 AL_PRINT(__VA_ARGS__); \
767 } while(0)
769 #define TRACE(...) do { \
770 if(LogLevel >= LogTrace) \
771 AL_PRINT(__VA_ARGS__); \
772 } while(0)
774 #define WARN(...) do { \
775 if(LogLevel >= LogWarning) \
776 AL_PRINT(__VA_ARGS__); \
777 } while(0)
779 #define ERR(...) do { \
780 if(LogLevel >= LogError) \
781 AL_PRINT(__VA_ARGS__); \
782 } while(0)
785 extern ALint RTPrioLevel;
787 #ifdef __cplusplus
789 #endif
791 #endif