Removed duplicate file in Android.mk file list.
[openal-soft/android.git] / OpenAL32 / Include / alMain.h
blob2c5c6fd16b8c577d5dbf252fbd32541303a935dc
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)(void);
43 typedef ALCboolean (ALC_APIENTRY*LPALCISRENDERFORMATSUPPORTEDSOFT)(ALCdevice *device, ALCsizei freq, ALCenum channels, ALCenum type);
44 typedef void (ALC_APIENTRY*LPALCRENDERSAMPLESSOFT)(ALCdevice *device, ALCvoid *buffer, ALCsizei samples);
45 #ifdef AL_ALEXT_PROTOTYPES
46 ALC_API ALCdevice* ALC_APIENTRY alcLoopbackOpenDeviceSOFT(void);
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_non_virtual_channels
53 #define AL_SOFT_non_virtual_channels 1
54 #define AL_VIRTUAL_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 #ifdef _WIN32
104 #include <windows.h>
106 typedef DWORD pthread_key_t;
107 int pthread_key_create(pthread_key_t *key, void (*callback)(void*));
108 int pthread_key_delete(pthread_key_t key);
109 void *pthread_getspecific(pthread_key_t key);
110 int pthread_setspecific(pthread_key_t key, void *val);
112 #define HAVE_DYNLOAD 1
113 void *LoadLib(const char *name);
114 void CloseLib(void *handle);
115 void *GetSymbol(void *handle, const char *name);
117 typedef LONG pthread_once_t;
118 #define PTHREAD_ONCE_INIT 0
119 void pthread_once(pthread_once_t *once, void (*callback)(void));
121 static __inline int sched_yield(void)
122 { SwitchToThread(); return 0; }
124 #else
126 #include <unistd.h>
127 #include <assert.h>
128 #include <pthread.h>
129 #ifdef HAVE_PTHREAD_NP_H
130 #include <pthread_np.h>
131 #endif
132 #include <sys/time.h>
133 #include <time.h>
134 #include <errno.h>
136 #define IsBadWritePtr(a,b) ((a) == NULL && (b) != 0)
138 typedef pthread_mutex_t CRITICAL_SECTION;
139 void InitializeCriticalSection(CRITICAL_SECTION *cs);
140 void DeleteCriticalSection(CRITICAL_SECTION *cs);
141 void EnterCriticalSection(CRITICAL_SECTION *cs);
142 void LeaveCriticalSection(CRITICAL_SECTION *cs);
144 ALuint timeGetTime(void);
145 void Sleep(ALuint t);
147 #if defined(HAVE_DLFCN_H)
148 #define HAVE_DYNLOAD 1
149 void *LoadLib(const char *name);
150 void CloseLib(void *handle);
151 void *GetSymbol(void *handle, const char *name);
152 #endif
154 #endif
156 typedef void *volatile XchgPtr;
158 #if defined(__GNUC__) && (__GNUC__ > 4 || (__GNUC__ == 4 && __GNUC_MINOR__ >= 1))
159 typedef ALuint RefCount;
160 static __inline RefCount IncrementRef(volatile RefCount *ptr)
161 { return __sync_add_and_fetch(ptr, 1); }
162 static __inline RefCount DecrementRef(volatile RefCount *ptr)
163 { return __sync_sub_and_fetch(ptr, 1); }
165 static __inline int ExchangeInt(volatile int *ptr, int newval)
167 return __sync_lock_test_and_set(ptr, newval);
169 static __inline void *ExchangePtr(XchgPtr *ptr, void *newval)
171 return __sync_lock_test_and_set(ptr, newval);
173 static __inline ALboolean CompExchangeInt(volatile int *ptr, int oldval, int newval)
175 return __sync_bool_compare_and_swap(ptr, oldval, newval);
177 static __inline ALboolean CompExchangePtr(XchgPtr *ptr, void *oldval, void *newval)
179 return __sync_bool_compare_and_swap(ptr, oldval, newval);
182 #elif defined(__GNUC__) && (defined(__i386__) || defined(__x86_64__))
184 static __inline int xaddl(volatile int *dest, int incr)
186 int ret;
187 __asm__ __volatile__("lock; xaddl %0,(%1)"
188 : "=r" (ret)
189 : "r" (dest), "0" (incr)
190 : "memory");
191 return ret;
194 typedef int RefCount;
195 static __inline RefCount IncrementRef(volatile RefCount *ptr)
196 { return xaddl(ptr, 1)+1; }
197 static __inline RefCount DecrementRef(volatile RefCount *ptr)
198 { return xaddl(ptr, -1)-1; }
200 static __inline int ExchangeInt(volatile int *dest, int newval)
202 int ret;
203 __asm__ __volatile__("lock; xchgl %0,(%1)"
204 : "=r" (ret)
205 : "r" (dest), "0" (newval)
206 : "memory");
207 return ret;
210 static __inline ALboolean CompExchangeInt(volatile int *dest, int oldval, int newval)
212 int ret;
213 __asm__ __volatile__("lock; cmpxchgl %2,(%1)"
214 : "=a" (ret)
215 : "r" (dest), "r" (newval), "0" (oldval)
216 : "memory");
217 return ret == oldval;
220 static __inline void *ExchangePtr(XchgPtr *dest, void *newval)
222 void *ret;
223 __asm__ __volatile__(
224 #ifdef __i386__
225 "lock; xchgl %0,(%1)"
226 #else
227 "lock; xchgq %0,(%1)"
228 #endif
229 : "=r" (ret)
230 : "r" (dest), "0" (newval)
231 : "memory"
233 return ret;
236 static __inline ALboolean CompExchangePtr(XchgPtr *dest, void *oldval, void *newval)
238 void *ret;
239 __asm__ __volatile__(
240 #ifdef __i386__
241 "lock; cmpxchgl %2,(%1)"
242 #else
243 "lock; cmpxchgq %2,(%1)"
244 #endif
245 : "=a" (ret)
246 : "r" (dest), "r" (newval), "0" (oldval)
247 : "memory"
249 return ret == oldval;
252 #elif defined(_WIN32)
254 typedef LONG RefCount;
255 static __inline RefCount IncrementRef(volatile RefCount *ptr)
256 { return InterlockedIncrement(ptr); }
257 static __inline RefCount DecrementRef(volatile RefCount *ptr)
258 { return InterlockedDecrement(ptr); }
260 extern ALbyte LONG_size_does_not_match_int[(sizeof(LONG)==sizeof(int))?1:-1];
262 static __inline int ExchangeInt(volatile int *ptr, int newval)
264 union {
265 volatile int *i;
266 volatile LONG *l;
267 } u = { ptr };
268 return InterlockedExchange(u.l, newval);
270 static __inline void *ExchangePtr(XchgPtr *ptr, void *newval)
272 return InterlockedExchangePointer(ptr, newval);
274 static __inline ALboolean CompExchangeInt(volatile int *ptr, int oldval, int newval)
276 union {
277 volatile int *i;
278 volatile LONG *l;
279 } u = { ptr };
280 return InterlockedCompareExchange(u.l, newval, oldval) == oldval;
282 static __inline ALboolean CompExchangePtr(XchgPtr *ptr, void *oldval, void *newval)
284 return InterlockedCompareExchangePointer(ptr, newval, oldval) == oldval;
287 #elif defined(__APPLE__)
289 #include <libkern/OSAtomic.h>
291 typedef int32_t RefCount;
292 static __inline RefCount IncrementRef(volatile RefCount *ptr)
293 { return OSAtomicIncrement32Barrier(ptr); }
294 static __inline RefCount DecrementRef(volatile RefCount *ptr)
295 { return OSAtomicDecrement32Barrier(ptr); }
297 static __inline int ExchangeInt(volatile int *ptr, int newval)
299 /* Really? No regular old atomic swap? */
300 int oldval;
301 do {
302 oldval = *ptr;
303 } while(!OSAtomicCompareAndSwap32Barrier(oldval, newval, ptr));
304 return oldval;
306 static __inline void *ExchangePtr(XchgPtr *ptr, void *newval)
308 void *oldval;
309 do {
310 oldval = *ptr;
311 } while(!OSAtomicCompareAndSwapPtrBarrier(oldval, newval, ptr));
312 return oldval;
314 static __inline ALboolean CompExchangeInt(volatile int *ptr, int oldval, int newval)
316 return OSAtomicCompareAndSwap32Barrier(oldval, newval, ptr);
318 static __inline ALboolean CompExchangePtr(XchgPtr *ptr, void *oldval, void *newval)
320 return OSAtomicCompareAndSwapPtrBarrier(oldval, newval, ptr);
323 #else
324 #error "No atomic functions available on this platform!"
325 typedef ALuint RefCount;
326 #endif
329 typedef struct {
330 volatile RefCount read_count;
331 volatile RefCount write_count;
332 volatile ALenum read_lock;
333 volatile ALenum read_entry_lock;
334 volatile ALenum write_lock;
335 } RWLock;
337 void RWLockInit(RWLock *lock);
338 void ReadLock(RWLock *lock);
339 void ReadUnlock(RWLock *lock);
340 void WriteLock(RWLock *lock);
341 void WriteUnlock(RWLock *lock);
344 typedef struct UIntMap {
345 struct {
346 ALuint key;
347 ALvoid *value;
348 } *array;
349 ALsizei size;
350 ALsizei maxsize;
351 ALsizei limit;
352 RWLock lock;
353 } UIntMap;
354 extern UIntMap TlsDestructor;
356 void InitUIntMap(UIntMap *map, ALsizei limit);
357 void ResetUIntMap(UIntMap *map);
358 ALenum InsertUIntMapEntry(UIntMap *map, ALuint key, ALvoid *value);
359 ALvoid *RemoveUIntMapKey(UIntMap *map, ALuint key);
360 ALvoid *LookupUIntMapKey(UIntMap *map, ALuint key);
362 static __inline void LockUIntMapRead(UIntMap *map)
363 { ReadLock(&map->lock); }
364 static __inline void UnlockUIntMapRead(UIntMap *map)
365 { ReadUnlock(&map->lock); }
366 static __inline void LockUIntMapWrite(UIntMap *map)
367 { WriteLock(&map->lock); }
368 static __inline void UnlockUIntMapWrite(UIntMap *map)
369 { WriteUnlock(&map->lock); }
371 #include "alListener.h"
372 #include "alu.h"
374 #ifdef __cplusplus
375 extern "C" {
376 #endif
379 #define DEFAULT_OUTPUT_RATE (44100)
381 #define SPEEDOFSOUNDMETRESPERSEC (343.3f)
382 #define AIRABSORBGAINHF (0.99426f) /* -0.05dB */
384 #define LOWPASSFREQREF (5000)
387 struct Hrtf;
390 // Find the next power-of-2 for non-power-of-2 numbers.
391 static __inline ALuint NextPowerOf2(ALuint value)
393 ALuint powerOf2 = 1;
395 if(value)
397 value--;
398 while(value)
400 value >>= 1;
401 powerOf2 <<= 1;
404 return powerOf2;
407 /* Fast float-to-int conversion. Assumes the FPU is already in round-to-zero
408 * mode. */
409 static __inline ALint fastf2i(ALfloat f)
411 ALint i;
412 #if defined(_MSC_VER) && !defined(_WIN64)
413 __asm fld f
414 __asm fistp i
415 #elif defined(__GNUC__) && defined(__i386__)
416 __asm__ __volatile__("flds %1\n\t"
417 "fistpl %0\n\t"
418 : "=m" (i)
419 : "m" (f));
420 #else
421 i = (ALint)f;
422 #endif
423 return i;
426 /* Fast float-to-uint conversion. Assumes the FPU is already in round-to-zero
427 * mode. */
428 static __inline ALuint fastf2u(ALfloat f)
429 { return fastf2i(f); }
432 enum DevProbe {
433 DEVICE_PROBE,
434 ALL_DEVICE_PROBE,
435 CAPTURE_DEVICE_PROBE
438 typedef struct {
439 ALCenum (*OpenPlayback)(ALCdevice*, const ALCchar*);
440 void (*ClosePlayback)(ALCdevice*);
441 ALCboolean (*ResetPlayback)(ALCdevice*);
442 void (*StopPlayback)(ALCdevice*);
444 ALCenum (*OpenCapture)(ALCdevice*, const ALCchar*);
445 void (*CloseCapture)(ALCdevice*);
446 void (*StartCapture)(ALCdevice*);
447 void (*StopCapture)(ALCdevice*);
448 ALCenum (*CaptureSamples)(ALCdevice*, void*, ALCuint);
449 ALCuint (*AvailableSamples)(ALCdevice*);
450 } BackendFuncs;
452 struct BackendInfo {
453 const char *name;
454 ALCboolean (*Init)(BackendFuncs*);
455 void (*Deinit)(void);
456 void (*Probe)(enum DevProbe);
457 BackendFuncs Funcs;
460 ALCboolean alc_alsa_init(BackendFuncs *func_list);
461 void alc_alsa_deinit(void);
462 void alc_alsa_probe(enum DevProbe type);
463 ALCboolean alc_oss_init(BackendFuncs *func_list);
464 void alc_oss_deinit(void);
465 void alc_oss_probe(enum DevProbe type);
466 ALCboolean alc_solaris_init(BackendFuncs *func_list);
467 void alc_solaris_deinit(void);
468 void alc_solaris_probe(enum DevProbe type);
469 ALCboolean alc_sndio_init(BackendFuncs *func_list);
470 void alc_sndio_deinit(void);
471 void alc_sndio_probe(enum DevProbe type);
472 ALCboolean alcMMDevApiInit(BackendFuncs *func_list);
473 void alcMMDevApiDeinit(void);
474 void alcMMDevApiProbe(enum DevProbe type);
475 ALCboolean alcDSoundInit(BackendFuncs *func_list);
476 void alcDSoundDeinit(void);
477 void alcDSoundProbe(enum DevProbe type);
478 ALCboolean alcWinMMInit(BackendFuncs *FuncList);
479 void alcWinMMDeinit(void);
480 void alcWinMMProbe(enum DevProbe type);
481 ALCboolean alc_pa_init(BackendFuncs *func_list);
482 void alc_pa_deinit(void);
483 void alc_pa_probe(enum DevProbe type);
484 ALCboolean alc_wave_init(BackendFuncs *func_list);
485 void alc_wave_deinit(void);
486 void alc_wave_probe(enum DevProbe type);
487 ALCboolean alc_pulse_init(BackendFuncs *func_list);
488 void alc_pulse_deinit(void);
489 void alc_pulse_probe(enum DevProbe type);
490 ALCboolean alc_ca_init(BackendFuncs *func_list);
491 void alc_ca_deinit(void);
492 void alc_ca_probe(enum DevProbe type);
493 ALCboolean alc_opensl_init(BackendFuncs *func_list);
494 void alc_opensl_deinit(void);
495 void alc_opensl_probe(enum DevProbe type);
496 ALCboolean alc_null_init(BackendFuncs *func_list);
497 void alc_null_deinit(void);
498 void alc_null_probe(enum DevProbe type);
499 ALCboolean alc_loopback_init(BackendFuncs *func_list);
500 void alc_loopback_deinit(void);
501 void alc_loopback_probe(enum DevProbe type);
502 void alc_android_init(BackendFuncs *func_list);
503 void alc_android_deinit(void);
504 void alc_android_probe(int type);
506 /* Device formats */
507 enum DevFmtType {
508 DevFmtByte = ALC_BYTE_SOFT,
509 DevFmtUByte = ALC_UNSIGNED_BYTE_SOFT,
510 DevFmtShort = ALC_SHORT_SOFT,
511 DevFmtUShort = ALC_UNSIGNED_SHORT_SOFT,
512 DevFmtFloat = ALC_FLOAT_SOFT
514 enum DevFmtChannels {
515 DevFmtMono = ALC_MONO_SOFT,
516 DevFmtStereo = ALC_STEREO_SOFT,
517 DevFmtQuad = ALC_QUAD_SOFT,
518 DevFmtX51 = ALC_5POINT1_SOFT,
519 DevFmtX61 = ALC_6POINT1_SOFT,
520 DevFmtX71 = ALC_7POINT1_SOFT,
522 /* Similar to 5.1, except using the side channels instead of back */
523 DevFmtX51Side = 0x80000000 | ALC_5POINT1_SOFT
526 ALuint BytesFromDevFmt(enum DevFmtType type);
527 ALuint ChannelsFromDevFmt(enum DevFmtChannels chans);
528 static __inline ALuint FrameSizeFromDevFmt(enum DevFmtChannels chans,
529 enum DevFmtType type)
531 return ChannelsFromDevFmt(chans) * BytesFromDevFmt(type);
535 extern const struct EffectList {
536 const char *name;
537 int type;
538 const char *ename;
539 ALenum val;
540 } EffectList[];
543 struct ALCdevice_struct
545 volatile RefCount ref;
547 ALCboolean Connected;
548 ALboolean IsCaptureDevice;
549 ALboolean IsLoopbackDevice;
551 CRITICAL_SECTION Mutex;
553 ALuint Frequency;
554 ALuint UpdateSize;
555 ALuint NumUpdates;
556 enum DevFmtChannels FmtChans;
557 enum DevFmtType FmtType;
559 ALCchar *szDeviceName;
561 volatile ALCenum LastError;
563 // Maximum number of sources that can be created
564 ALuint MaxNoOfSources;
565 // Maximum number of slots that can be created
566 ALuint AuxiliaryEffectSlotMax;
568 ALCuint NumMonoSources;
569 ALCuint NumStereoSources;
570 ALuint NumAuxSends;
572 // Map of Buffers for this device
573 UIntMap BufferMap;
575 // Map of Effects for this device
576 UIntMap EffectMap;
578 // Map of Filters for this device
579 UIntMap FilterMap;
581 /* HRTF filter tables */
582 const struct Hrtf *Hrtf;
584 // Stereo-to-binaural filter
585 struct bs2b *Bs2b;
586 ALCint Bs2bLevel;
588 // Device flags
589 ALuint Flags;
591 // Dry path buffer mix
592 ALfloat DryBuffer[BUFFERSIZE][MAXCHANNELS];
594 enum Channel DevChannels[MAXCHANNELS];
596 enum Channel Speaker2Chan[MAXCHANNELS];
597 ALfloat PanningLUT[LUT_NUM][MAXCHANNELS];
598 ALuint NumChan;
600 ALfloat ClickRemoval[MAXCHANNELS];
601 ALfloat PendingClicks[MAXCHANNELS];
603 /* Default effect slot */
604 struct ALeffectslot *DefaultSlot;
606 // Contexts created on this device
607 ALCcontext *volatile ContextList;
609 BackendFuncs *Funcs;
610 void *ExtraData; // For the backend's use
612 ALCdevice *volatile next;
615 #define ALCdevice_OpenPlayback(a,b) ((a)->Funcs->OpenPlayback((a), (b)))
616 #define ALCdevice_ClosePlayback(a) ((a)->Funcs->ClosePlayback((a)))
617 #define ALCdevice_ResetPlayback(a) ((a)->Funcs->ResetPlayback((a)))
618 #define ALCdevice_StopPlayback(a) ((a)->Funcs->StopPlayback((a)))
619 #define ALCdevice_OpenCapture(a,b) ((a)->Funcs->OpenCapture((a), (b)))
620 #define ALCdevice_CloseCapture(a) ((a)->Funcs->CloseCapture((a)))
621 #define ALCdevice_StartCapture(a) ((a)->Funcs->StartCapture((a)))
622 #define ALCdevice_StopCapture(a) ((a)->Funcs->StopCapture((a)))
623 #define ALCdevice_CaptureSamples(a,b,c) ((a)->Funcs->CaptureSamples((a), (b), (c)))
624 #define ALCdevice_AvailableSamples(a) ((a)->Funcs->AvailableSamples((a)))
626 // Duplicate stereo sources on the side/rear channels
627 #define DEVICE_DUPLICATE_STEREO (1<<0)
628 // Frequency was requested by the app or config file
629 #define DEVICE_FREQUENCY_REQUEST (1<<1)
630 // Channel configuration was requested by the config file
631 #define DEVICE_CHANNELS_REQUEST (1<<2)
633 // Specifies if the device is currently running
634 #define DEVICE_RUNNING (1<<31)
636 #define LookupBuffer(m, k) ((struct ALbuffer*)LookupUIntMapKey(&(m)->BufferMap, (k)))
637 #define LookupEffect(m, k) ((struct ALeffect*)LookupUIntMapKey(&(m)->EffectMap, (k)))
638 #define LookupFilter(m, k) ((struct ALfilter*)LookupUIntMapKey(&(m)->FilterMap, (k)))
639 #define RemoveBuffer(m, k) ((struct ALbuffer*)RemoveUIntMapKey(&(m)->BufferMap, (k)))
640 #define RemoveEffect(m, k) ((struct ALeffect*)RemoveUIntMapKey(&(m)->EffectMap, (k)))
641 #define RemoveFilter(m, k) ((struct ALfilter*)RemoveUIntMapKey(&(m)->FilterMap, (k)))
644 struct ALCcontext_struct
646 volatile RefCount ref;
648 ALlistener Listener;
650 UIntMap SourceMap;
651 UIntMap EffectSlotMap;
653 ALenum LastError;
655 volatile ALenum UpdateSources;
657 volatile enum DistanceModel DistanceModel;
658 volatile ALboolean SourceDistanceModel;
660 volatile ALfloat DopplerFactor;
661 volatile ALfloat DopplerVelocity;
662 volatile ALfloat flSpeedOfSound;
663 volatile ALenum DeferUpdates;
665 struct ALsource **ActiveSources;
666 ALsizei ActiveSourceCount;
667 ALsizei MaxActiveSources;
669 struct ALeffectslot **ActiveEffectSlots;
670 ALsizei ActiveEffectSlotCount;
671 ALsizei MaxActiveEffectSlots;
673 ALCdevice *Device;
674 const ALCchar *ExtensionList;
676 ALCcontext *volatile next;
679 #define LookupSource(m, k) ((struct ALsource*)LookupUIntMapKey(&(m)->SourceMap, (k)))
680 #define LookupEffectSlot(m, k) ((struct ALeffectslot*)LookupUIntMapKey(&(m)->EffectSlotMap, (k)))
681 #define RemoveSource(m, k) ((struct ALsource*)RemoveUIntMapKey(&(m)->SourceMap, (k)))
682 #define RemoveEffectSlot(m, k) ((struct ALeffectslot*)RemoveUIntMapKey(&(m)->EffectSlotMap, (k)))
684 ALCcontext *GetContextRef(void);
686 void ALCcontext_IncRef(ALCcontext *context);
687 void ALCcontext_DecRef(ALCcontext *context);
689 void AppendDeviceList(const ALCchar *name);
690 void AppendAllDeviceList(const ALCchar *name);
691 void AppendCaptureDeviceList(const ALCchar *name);
693 static __inline void LockDevice(ALCdevice *device)
694 { EnterCriticalSection(&device->Mutex); }
695 static __inline void UnlockDevice(ALCdevice *device)
696 { LeaveCriticalSection(&device->Mutex); }
698 static __inline void LockContext(ALCcontext *context)
699 { LockDevice(context->Device); }
700 static __inline void UnlockContext(ALCcontext *context)
701 { UnlockDevice(context->Device); }
704 ALvoid *StartThread(ALuint (*func)(ALvoid*), ALvoid *ptr);
705 ALuint StopThread(ALvoid *thread);
707 typedef struct RingBuffer RingBuffer;
708 RingBuffer *CreateRingBuffer(ALsizei frame_size, ALsizei length);
709 void DestroyRingBuffer(RingBuffer *ring);
710 ALsizei RingBufferSize(RingBuffer *ring);
711 void WriteRingBuffer(RingBuffer *ring, const ALubyte *data, ALsizei len);
712 void ReadRingBuffer(RingBuffer *ring, ALubyte *data, ALsizei len);
714 void ReadALConfig(void);
715 void FreeALConfig(void);
716 int ConfigValueExists(const char *blockName, const char *keyName);
717 const char *GetConfigValue(const char *blockName, const char *keyName, const char *def);
718 int GetConfigValueBool(const char *blockName, const char *keyName, int def);
719 int ConfigValueStr(const char *blockName, const char *keyName, const char **ret);
720 int ConfigValueInt(const char *blockName, const char *keyName, int *ret);
721 int ConfigValueUInt(const char *blockName, const char *keyName, unsigned int *ret);
722 int ConfigValueFloat(const char *blockName, const char *keyName, float *ret);
724 void SetRTPriority(void);
726 void SetDefaultChannelOrder(ALCdevice *device);
727 void SetDefaultWFXChannelOrder(ALCdevice *device);
729 const ALCchar *DevFmtTypeString(enum DevFmtType type);
730 const ALCchar *DevFmtChannelsString(enum DevFmtChannels chans);
732 #define HRIR_BITS (5)
733 #define HRIR_LENGTH (1<<HRIR_BITS)
734 #define HRIR_MASK (HRIR_LENGTH-1)
735 void InitHrtf(void);
736 void FreeHrtf(void);
737 const struct Hrtf *GetHrtf(ALCdevice *device);
738 ALfloat CalcHrtfDelta(ALfloat oldGain, ALfloat newGain, const ALfloat olddir[3], const ALfloat newdir[3]);
739 void GetLerpedHrtfCoeffs(const struct Hrtf *Hrtf, ALfloat elevation, ALfloat azimuth, ALfloat gain, ALfloat (*coeffs)[2], ALuint *delays);
740 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);
742 void al_print(const char *func, const char *fmt, ...) PRINTF_STYLE(2,3);
743 #define AL_PRINT(...) al_print(__FUNCTION__, __VA_ARGS__)
745 extern FILE *LogFile;
746 enum LogLevel {
747 NoLog,
748 LogError,
749 LogWarning,
750 LogTrace,
751 LogRef
753 extern enum LogLevel LogLevel;
755 #define TRACEREF(...) do { \
756 if(LogLevel >= LogRef) \
757 AL_PRINT(__VA_ARGS__); \
758 } while(0)
760 #define TRACE(...) do { \
761 if(LogLevel >= LogTrace) \
762 AL_PRINT(__VA_ARGS__); \
763 } while(0)
765 #define WARN(...) do { \
766 if(LogLevel >= LogWarning) \
767 AL_PRINT(__VA_ARGS__); \
768 } while(0)
770 #define ERR(...) do { \
771 if(LogLevel >= LogError) \
772 AL_PRINT(__VA_ARGS__); \
773 } while(0)
776 extern ALint RTPrioLevel;
778 #ifdef __cplusplus
780 #endif
782 #endif