Don't use GUIDs to ID mmdevapi devices, and don't enumerate if not needed
[openal-soft.git] / OpenAL32 / Include / alMain.h
blob85807f6a17356d6e514261c2c4fbb02ce312b9f4
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 WCHAR *strdupW(const WCHAR *str);
127 typedef LONG pthread_once_t;
128 #define PTHREAD_ONCE_INIT 0
129 void pthread_once(pthread_once_t *once, void (*callback)(void));
131 static __inline int sched_yield(void)
132 { SwitchToThread(); return 0; }
134 #else
136 #include <unistd.h>
137 #include <assert.h>
138 #include <pthread.h>
139 #ifdef HAVE_PTHREAD_NP_H
140 #include <pthread_np.h>
141 #endif
142 #include <sys/time.h>
143 #include <time.h>
144 #include <errno.h>
146 #define IsBadWritePtr(a,b) ((a) == NULL && (b) != 0)
148 typedef pthread_mutex_t CRITICAL_SECTION;
149 void InitializeCriticalSection(CRITICAL_SECTION *cs);
150 void DeleteCriticalSection(CRITICAL_SECTION *cs);
151 void EnterCriticalSection(CRITICAL_SECTION *cs);
152 void LeaveCriticalSection(CRITICAL_SECTION *cs);
154 ALuint timeGetTime(void);
155 void Sleep(ALuint t);
157 #if defined(HAVE_DLFCN_H)
158 #define HAVE_DYNLOAD 1
159 void *LoadLib(const char *name);
160 void CloseLib(void *handle);
161 void *GetSymbol(void *handle, const char *name);
162 #endif
164 #endif
166 typedef void *volatile XchgPtr;
168 #if defined(__GNUC__) && (__GNUC__ > 4 || (__GNUC__ == 4 && __GNUC_MINOR__ >= 1))
169 typedef ALuint RefCount;
170 static __inline RefCount IncrementRef(volatile RefCount *ptr)
171 { return __sync_add_and_fetch(ptr, 1); }
172 static __inline RefCount DecrementRef(volatile RefCount *ptr)
173 { return __sync_sub_and_fetch(ptr, 1); }
175 static __inline int ExchangeInt(volatile int *ptr, int newval)
177 return __sync_lock_test_and_set(ptr, newval);
179 static __inline void *ExchangePtr(XchgPtr *ptr, void *newval)
181 return __sync_lock_test_and_set(ptr, newval);
183 static __inline ALboolean CompExchangeInt(volatile int *ptr, int oldval, int newval)
185 return __sync_bool_compare_and_swap(ptr, oldval, newval);
187 static __inline ALboolean CompExchangePtr(XchgPtr *ptr, void *oldval, void *newval)
189 return __sync_bool_compare_and_swap(ptr, oldval, newval);
192 #elif defined(__GNUC__) && (defined(__i386__) || defined(__x86_64__))
194 static __inline int xaddl(volatile int *dest, int incr)
196 int ret;
197 __asm__ __volatile__("lock; xaddl %0,(%1)"
198 : "=r" (ret)
199 : "r" (dest), "0" (incr)
200 : "memory");
201 return ret;
204 typedef int RefCount;
205 static __inline RefCount IncrementRef(volatile RefCount *ptr)
206 { return xaddl(ptr, 1)+1; }
207 static __inline RefCount DecrementRef(volatile RefCount *ptr)
208 { return xaddl(ptr, -1)-1; }
210 static __inline int ExchangeInt(volatile int *dest, int newval)
212 int ret;
213 __asm__ __volatile__("lock; xchgl %0,(%1)"
214 : "=r" (ret)
215 : "r" (dest), "0" (newval)
216 : "memory");
217 return ret;
220 static __inline ALboolean CompExchangeInt(volatile int *dest, int oldval, int newval)
222 int ret;
223 __asm__ __volatile__("lock; cmpxchgl %2,(%1)"
224 : "=a" (ret)
225 : "r" (dest), "r" (newval), "0" (oldval)
226 : "memory");
227 return ret == oldval;
230 static __inline void *ExchangePtr(XchgPtr *dest, void *newval)
232 void *ret;
233 __asm__ __volatile__(
234 #ifdef __i386__
235 "lock; xchgl %0,(%1)"
236 #else
237 "lock; xchgq %0,(%1)"
238 #endif
239 : "=r" (ret)
240 : "r" (dest), "0" (newval)
241 : "memory"
243 return ret;
246 static __inline ALboolean CompExchangePtr(XchgPtr *dest, void *oldval, void *newval)
248 void *ret;
249 __asm__ __volatile__(
250 #ifdef __i386__
251 "lock; cmpxchgl %2,(%1)"
252 #else
253 "lock; cmpxchgq %2,(%1)"
254 #endif
255 : "=a" (ret)
256 : "r" (dest), "r" (newval), "0" (oldval)
257 : "memory"
259 return ret == oldval;
262 #elif defined(_WIN32)
264 typedef LONG RefCount;
265 static __inline RefCount IncrementRef(volatile RefCount *ptr)
266 { return InterlockedIncrement(ptr); }
267 static __inline RefCount DecrementRef(volatile RefCount *ptr)
268 { return InterlockedDecrement(ptr); }
270 extern ALbyte LONG_size_does_not_match_int[(sizeof(LONG)==sizeof(int))?1:-1];
272 static __inline int ExchangeInt(volatile int *ptr, int newval)
274 union {
275 volatile int *i;
276 volatile LONG *l;
277 } u = { ptr };
278 return InterlockedExchange(u.l, newval);
280 static __inline void *ExchangePtr(XchgPtr *ptr, void *newval)
282 return InterlockedExchangePointer(ptr, newval);
284 static __inline ALboolean CompExchangeInt(volatile int *ptr, int oldval, int newval)
286 union {
287 volatile int *i;
288 volatile LONG *l;
289 } u = { ptr };
290 return InterlockedCompareExchange(u.l, newval, oldval) == oldval;
292 static __inline ALboolean CompExchangePtr(XchgPtr *ptr, void *oldval, void *newval)
294 return InterlockedCompareExchangePointer(ptr, newval, oldval) == oldval;
297 #elif defined(__APPLE__)
299 #include <libkern/OSAtomic.h>
301 typedef int32_t RefCount;
302 static __inline RefCount IncrementRef(volatile RefCount *ptr)
303 { return OSAtomicIncrement32Barrier(ptr); }
304 static __inline RefCount DecrementRef(volatile RefCount *ptr)
305 { return OSAtomicDecrement32Barrier(ptr); }
307 static __inline int ExchangeInt(volatile int *ptr, int newval)
309 /* Really? No regular old atomic swap? */
310 int oldval;
311 do {
312 oldval = *ptr;
313 } while(!OSAtomicCompareAndSwap32Barrier(oldval, newval, ptr));
314 return oldval;
316 static __inline void *ExchangePtr(XchgPtr *ptr, void *newval)
318 void *oldval;
319 do {
320 oldval = *ptr;
321 } while(!OSAtomicCompareAndSwapPtrBarrier(oldval, newval, ptr));
322 return oldval;
324 static __inline ALboolean CompExchangeInt(volatile int *ptr, int oldval, int newval)
326 return OSAtomicCompareAndSwap32Barrier(oldval, newval, ptr);
328 static __inline ALboolean CompExchangePtr(XchgPtr *ptr, void *oldval, void *newval)
330 return OSAtomicCompareAndSwapPtrBarrier(oldval, newval, ptr);
333 #else
334 #error "No atomic functions available on this platform!"
335 typedef ALuint RefCount;
336 #endif
339 typedef struct {
340 volatile RefCount read_count;
341 volatile RefCount write_count;
342 volatile ALenum read_lock;
343 volatile ALenum read_entry_lock;
344 volatile ALenum write_lock;
345 } RWLock;
347 void RWLockInit(RWLock *lock);
348 void ReadLock(RWLock *lock);
349 void ReadUnlock(RWLock *lock);
350 void WriteLock(RWLock *lock);
351 void WriteUnlock(RWLock *lock);
354 typedef struct UIntMap {
355 struct {
356 ALuint key;
357 ALvoid *value;
358 } *array;
359 ALsizei size;
360 ALsizei maxsize;
361 ALsizei limit;
362 RWLock lock;
363 } UIntMap;
364 extern UIntMap TlsDestructor;
366 void InitUIntMap(UIntMap *map, ALsizei limit);
367 void ResetUIntMap(UIntMap *map);
368 ALenum InsertUIntMapEntry(UIntMap *map, ALuint key, ALvoid *value);
369 ALvoid *RemoveUIntMapKey(UIntMap *map, ALuint key);
370 ALvoid *LookupUIntMapKey(UIntMap *map, ALuint key);
372 static __inline void LockUIntMapRead(UIntMap *map)
373 { ReadLock(&map->lock); }
374 static __inline void UnlockUIntMapRead(UIntMap *map)
375 { ReadUnlock(&map->lock); }
376 static __inline void LockUIntMapWrite(UIntMap *map)
377 { WriteLock(&map->lock); }
378 static __inline void UnlockUIntMapWrite(UIntMap *map)
379 { WriteUnlock(&map->lock); }
381 #include "alListener.h"
382 #include "alu.h"
384 #ifdef __cplusplus
385 extern "C" {
386 #endif
389 #define DEFAULT_OUTPUT_RATE (44100)
390 #define MIN_OUTPUT_RATE (8000)
392 #define SPEEDOFSOUNDMETRESPERSEC (343.3f)
393 #define AIRABSORBGAINHF (0.99426f) /* -0.05dB */
395 #define LOWPASSFREQREF (5000)
398 struct Hrtf;
401 // Find the next power-of-2 for non-power-of-2 numbers.
402 static __inline ALuint NextPowerOf2(ALuint value)
404 ALuint powerOf2 = 1;
406 if(value)
408 value--;
409 while(value)
411 value >>= 1;
412 powerOf2 <<= 1;
415 return powerOf2;
418 /* Fast float-to-int conversion. Assumes the FPU is already in round-to-zero
419 * mode. */
420 static __inline ALint fastf2i(ALfloat f)
422 ALint i;
423 #if defined(_MSC_VER) && defined(_M_IX86)
424 __asm fld f
425 __asm fistp i
426 #elif defined(__GNUC__) && (defined(__i386__) || defined(__x86_64__))
427 __asm__ __volatile__("flds %1\n\t"
428 "fistpl %0\n\t"
429 : "=m" (i)
430 : "m" (f));
431 #else
432 i = (ALint)f;
433 #endif
434 return i;
437 /* Fast float-to-uint conversion. Assumes the FPU is already in round-to-zero
438 * mode. */
439 static __inline ALuint fastf2u(ALfloat f)
440 { return fastf2i(f); }
443 enum DevProbe {
444 ALL_DEVICE_PROBE,
445 CAPTURE_DEVICE_PROBE
448 typedef struct {
449 ALCenum (*OpenPlayback)(ALCdevice*, const ALCchar*);
450 void (*ClosePlayback)(ALCdevice*);
451 ALCboolean (*ResetPlayback)(ALCdevice*);
452 void (*StopPlayback)(ALCdevice*);
454 ALCenum (*OpenCapture)(ALCdevice*, const ALCchar*);
455 void (*CloseCapture)(ALCdevice*);
456 void (*StartCapture)(ALCdevice*);
457 void (*StopCapture)(ALCdevice*);
458 ALCenum (*CaptureSamples)(ALCdevice*, void*, ALCuint);
459 ALCuint (*AvailableSamples)(ALCdevice*);
460 } BackendFuncs;
462 struct BackendInfo {
463 const char *name;
464 ALCboolean (*Init)(BackendFuncs*);
465 void (*Deinit)(void);
466 void (*Probe)(enum DevProbe);
467 BackendFuncs Funcs;
470 ALCboolean alc_alsa_init(BackendFuncs *func_list);
471 void alc_alsa_deinit(void);
472 void alc_alsa_probe(enum DevProbe type);
473 ALCboolean alc_oss_init(BackendFuncs *func_list);
474 void alc_oss_deinit(void);
475 void alc_oss_probe(enum DevProbe type);
476 ALCboolean alc_solaris_init(BackendFuncs *func_list);
477 void alc_solaris_deinit(void);
478 void alc_solaris_probe(enum DevProbe type);
479 ALCboolean alc_sndio_init(BackendFuncs *func_list);
480 void alc_sndio_deinit(void);
481 void alc_sndio_probe(enum DevProbe type);
482 ALCboolean alcMMDevApiInit(BackendFuncs *func_list);
483 void alcMMDevApiDeinit(void);
484 void alcMMDevApiProbe(enum DevProbe type);
485 ALCboolean alcDSoundInit(BackendFuncs *func_list);
486 void alcDSoundDeinit(void);
487 void alcDSoundProbe(enum DevProbe type);
488 ALCboolean alcWinMMInit(BackendFuncs *FuncList);
489 void alcWinMMDeinit(void);
490 void alcWinMMProbe(enum DevProbe type);
491 ALCboolean alc_pa_init(BackendFuncs *func_list);
492 void alc_pa_deinit(void);
493 void alc_pa_probe(enum DevProbe type);
494 ALCboolean alc_wave_init(BackendFuncs *func_list);
495 void alc_wave_deinit(void);
496 void alc_wave_probe(enum DevProbe type);
497 ALCboolean alc_pulse_init(BackendFuncs *func_list);
498 void alc_pulse_deinit(void);
499 void alc_pulse_probe(enum DevProbe type);
500 ALCboolean alc_ca_init(BackendFuncs *func_list);
501 void alc_ca_deinit(void);
502 void alc_ca_probe(enum DevProbe type);
503 ALCboolean alc_opensl_init(BackendFuncs *func_list);
504 void alc_opensl_deinit(void);
505 void alc_opensl_probe(enum DevProbe type);
506 ALCboolean alc_null_init(BackendFuncs *func_list);
507 void alc_null_deinit(void);
508 void alc_null_probe(enum DevProbe type);
509 ALCboolean alc_loopback_init(BackendFuncs *func_list);
510 void alc_loopback_deinit(void);
511 void alc_loopback_probe(enum DevProbe type);
514 /* Device formats */
515 enum DevFmtType {
516 DevFmtByte = ALC_BYTE_SOFT,
517 DevFmtUByte = ALC_UNSIGNED_BYTE_SOFT,
518 DevFmtShort = ALC_SHORT_SOFT,
519 DevFmtUShort = ALC_UNSIGNED_SHORT_SOFT,
520 DevFmtInt = ALC_INT_SOFT,
521 DevFmtUInt = ALC_UNSIGNED_INT_SOFT,
522 DevFmtFloat = ALC_FLOAT_SOFT
524 enum DevFmtChannels {
525 DevFmtMono = ALC_MONO_SOFT,
526 DevFmtStereo = ALC_STEREO_SOFT,
527 DevFmtQuad = ALC_QUAD_SOFT,
528 DevFmtX51 = ALC_5POINT1_SOFT,
529 DevFmtX61 = ALC_6POINT1_SOFT,
530 DevFmtX71 = ALC_7POINT1_SOFT,
532 /* Similar to 5.1, except using the side channels instead of back */
533 DevFmtX51Side = 0x80000000 | ALC_5POINT1_SOFT
536 ALuint BytesFromDevFmt(enum DevFmtType type);
537 ALuint ChannelsFromDevFmt(enum DevFmtChannels chans);
538 static __inline ALuint FrameSizeFromDevFmt(enum DevFmtChannels chans,
539 enum DevFmtType type)
541 return ChannelsFromDevFmt(chans) * BytesFromDevFmt(type);
545 extern const struct EffectList {
546 const char *name;
547 int type;
548 const char *ename;
549 ALenum val;
550 } EffectList[];
553 enum DeviceType {
554 Playback,
555 Capture,
556 Loopback
559 struct ALCdevice_struct
561 volatile RefCount ref;
563 ALCboolean Connected;
564 enum DeviceType Type;
566 CRITICAL_SECTION Mutex;
568 ALuint Frequency;
569 ALuint UpdateSize;
570 ALuint NumUpdates;
571 enum DevFmtChannels FmtChans;
572 enum DevFmtType FmtType;
574 ALCchar *szDeviceName;
576 volatile ALCenum LastError;
578 // Maximum number of sources that can be created
579 ALuint MaxNoOfSources;
580 // Maximum number of slots that can be created
581 ALuint AuxiliaryEffectSlotMax;
583 ALCuint NumMonoSources;
584 ALCuint NumStereoSources;
585 ALuint NumAuxSends;
587 // Map of Buffers for this device
588 UIntMap BufferMap;
590 // Map of Effects for this device
591 UIntMap EffectMap;
593 // Map of Filters for this device
594 UIntMap FilterMap;
596 /* HRTF filter tables */
597 const struct Hrtf *Hrtf;
599 // Stereo-to-binaural filter
600 struct bs2b *Bs2b;
601 ALCint Bs2bLevel;
603 // Device flags
604 ALuint Flags;
606 // Dry path buffer mix
607 ALfloat DryBuffer[BUFFERSIZE][MAXCHANNELS];
609 enum Channel DevChannels[MAXCHANNELS];
611 enum Channel Speaker2Chan[MAXCHANNELS];
612 ALfloat PanningLUT[LUT_NUM][MAXCHANNELS];
613 ALuint NumChan;
615 ALfloat ClickRemoval[MAXCHANNELS];
616 ALfloat PendingClicks[MAXCHANNELS];
618 /* Default effect slot */
619 struct ALeffectslot *DefaultSlot;
621 // Contexts created on this device
622 ALCcontext *volatile ContextList;
624 BackendFuncs *Funcs;
625 void *ExtraData; // For the backend's use
627 ALCdevice *volatile next;
630 #define ALCdevice_OpenPlayback(a,b) ((a)->Funcs->OpenPlayback((a), (b)))
631 #define ALCdevice_ClosePlayback(a) ((a)->Funcs->ClosePlayback((a)))
632 #define ALCdevice_ResetPlayback(a) ((a)->Funcs->ResetPlayback((a)))
633 #define ALCdevice_StopPlayback(a) ((a)->Funcs->StopPlayback((a)))
634 #define ALCdevice_OpenCapture(a,b) ((a)->Funcs->OpenCapture((a), (b)))
635 #define ALCdevice_CloseCapture(a) ((a)->Funcs->CloseCapture((a)))
636 #define ALCdevice_StartCapture(a) ((a)->Funcs->StartCapture((a)))
637 #define ALCdevice_StopCapture(a) ((a)->Funcs->StopCapture((a)))
638 #define ALCdevice_CaptureSamples(a,b,c) ((a)->Funcs->CaptureSamples((a), (b), (c)))
639 #define ALCdevice_AvailableSamples(a) ((a)->Funcs->AvailableSamples((a)))
641 // Duplicate stereo sources on the side/rear channels
642 #define DEVICE_DUPLICATE_STEREO (1<<0)
643 // Frequency was requested by the app or config file
644 #define DEVICE_FREQUENCY_REQUEST (1<<1)
645 // Channel configuration was requested by the config file
646 #define DEVICE_CHANNELS_REQUEST (1<<2)
647 // Sample type was requested by the config file
648 #define DEVICE_SAMPLE_TYPE_REQUEST (1<<3)
650 // Specifies if the device is currently running
651 #define DEVICE_RUNNING (1<<31)
653 #define LookupBuffer(m, k) ((struct ALbuffer*)LookupUIntMapKey(&(m)->BufferMap, (k)))
654 #define LookupEffect(m, k) ((struct ALeffect*)LookupUIntMapKey(&(m)->EffectMap, (k)))
655 #define LookupFilter(m, k) ((struct ALfilter*)LookupUIntMapKey(&(m)->FilterMap, (k)))
656 #define RemoveBuffer(m, k) ((struct ALbuffer*)RemoveUIntMapKey(&(m)->BufferMap, (k)))
657 #define RemoveEffect(m, k) ((struct ALeffect*)RemoveUIntMapKey(&(m)->EffectMap, (k)))
658 #define RemoveFilter(m, k) ((struct ALfilter*)RemoveUIntMapKey(&(m)->FilterMap, (k)))
661 struct ALCcontext_struct
663 volatile RefCount ref;
665 ALlistener Listener;
667 UIntMap SourceMap;
668 UIntMap EffectSlotMap;
670 ALenum LastError;
672 volatile ALenum UpdateSources;
674 volatile enum DistanceModel DistanceModel;
675 volatile ALboolean SourceDistanceModel;
677 volatile ALfloat DopplerFactor;
678 volatile ALfloat DopplerVelocity;
679 volatile ALfloat flSpeedOfSound;
680 volatile ALenum DeferUpdates;
682 struct ALsource **ActiveSources;
683 ALsizei ActiveSourceCount;
684 ALsizei MaxActiveSources;
686 struct ALeffectslot **ActiveEffectSlots;
687 ALsizei ActiveEffectSlotCount;
688 ALsizei MaxActiveEffectSlots;
690 ALCdevice *Device;
691 const ALCchar *ExtensionList;
693 ALCcontext *volatile next;
696 #define LookupSource(m, k) ((struct ALsource*)LookupUIntMapKey(&(m)->SourceMap, (k)))
697 #define LookupEffectSlot(m, k) ((struct ALeffectslot*)LookupUIntMapKey(&(m)->EffectSlotMap, (k)))
698 #define RemoveSource(m, k) ((struct ALsource*)RemoveUIntMapKey(&(m)->SourceMap, (k)))
699 #define RemoveEffectSlot(m, k) ((struct ALeffectslot*)RemoveUIntMapKey(&(m)->EffectSlotMap, (k)))
701 ALCcontext *GetContextRef(void);
703 void ALCcontext_IncRef(ALCcontext *context);
704 void ALCcontext_DecRef(ALCcontext *context);
706 void AppendAllDeviceList(const ALCchar *name);
707 void AppendCaptureDeviceList(const ALCchar *name);
709 static __inline void LockDevice(ALCdevice *device)
710 { EnterCriticalSection(&device->Mutex); }
711 static __inline void UnlockDevice(ALCdevice *device)
712 { LeaveCriticalSection(&device->Mutex); }
714 static __inline void LockContext(ALCcontext *context)
715 { LockDevice(context->Device); }
716 static __inline void UnlockContext(ALCcontext *context)
717 { UnlockDevice(context->Device); }
720 ALvoid *StartThread(ALuint (*func)(ALvoid*), ALvoid *ptr);
721 ALuint StopThread(ALvoid *thread);
723 typedef struct RingBuffer RingBuffer;
724 RingBuffer *CreateRingBuffer(ALsizei frame_size, ALsizei length);
725 void DestroyRingBuffer(RingBuffer *ring);
726 ALsizei RingBufferSize(RingBuffer *ring);
727 void WriteRingBuffer(RingBuffer *ring, const ALubyte *data, ALsizei len);
728 void ReadRingBuffer(RingBuffer *ring, ALubyte *data, ALsizei len);
730 void ReadALConfig(void);
731 void FreeALConfig(void);
732 int ConfigValueExists(const char *blockName, const char *keyName);
733 const char *GetConfigValue(const char *blockName, const char *keyName, const char *def);
734 int GetConfigValueBool(const char *blockName, const char *keyName, int def);
735 int ConfigValueStr(const char *blockName, const char *keyName, const char **ret);
736 int ConfigValueInt(const char *blockName, const char *keyName, int *ret);
737 int ConfigValueUInt(const char *blockName, const char *keyName, unsigned int *ret);
738 int ConfigValueFloat(const char *blockName, const char *keyName, float *ret);
740 void SetRTPriority(void);
742 void SetDefaultChannelOrder(ALCdevice *device);
743 void SetDefaultWFXChannelOrder(ALCdevice *device);
745 const ALCchar *DevFmtTypeString(enum DevFmtType type);
746 const ALCchar *DevFmtChannelsString(enum DevFmtChannels chans);
748 #define HRIR_BITS (5)
749 #define HRIR_LENGTH (1<<HRIR_BITS)
750 #define HRIR_MASK (HRIR_LENGTH-1)
751 void InitHrtf(void);
752 void FreeHrtf(void);
753 const struct Hrtf *GetHrtf(ALCdevice *device);
754 ALfloat CalcHrtfDelta(ALfloat oldGain, ALfloat newGain, const ALfloat olddir[3], const ALfloat newdir[3]);
755 void GetLerpedHrtfCoeffs(const struct Hrtf *Hrtf, ALfloat elevation, ALfloat azimuth, ALfloat gain, ALfloat (*coeffs)[2], ALuint *delays);
756 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);
758 void al_print(const char *func, const char *fmt, ...) PRINTF_STYLE(2,3);
759 #define AL_PRINT(...) al_print(__FUNCTION__, __VA_ARGS__)
761 extern FILE *LogFile;
762 enum LogLevel {
763 NoLog,
764 LogError,
765 LogWarning,
766 LogTrace,
767 LogRef
769 extern enum LogLevel LogLevel;
771 #define TRACEREF(...) do { \
772 if(LogLevel >= LogRef) \
773 AL_PRINT(__VA_ARGS__); \
774 } while(0)
776 #define TRACE(...) do { \
777 if(LogLevel >= LogTrace) \
778 AL_PRINT(__VA_ARGS__); \
779 } while(0)
781 #define WARN(...) do { \
782 if(LogLevel >= LogWarning) \
783 AL_PRINT(__VA_ARGS__); \
784 } while(0)
786 #define ERR(...) do { \
787 if(LogLevel >= LogError) \
788 AL_PRINT(__VA_ARGS__); \
789 } while(0)
792 extern ALint RTPrioLevel;
794 #ifdef __cplusplus
796 #endif
798 #endif