Finalize AL_SOFT_buffer_samples
[openal-soft/android.git] / OpenAL32 / Include / alMain.h
blobc0ffbe5ae2cd33ac147f271a538318eb36d54b8c
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__)
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);
504 /* Device formats */
505 enum DevFmtType {
506 DevFmtByte = ALC_BYTE_SOFT,
507 DevFmtUByte = ALC_UNSIGNED_BYTE_SOFT,
508 DevFmtShort = ALC_SHORT_SOFT,
509 DevFmtUShort = ALC_UNSIGNED_SHORT_SOFT,
510 DevFmtFloat = ALC_FLOAT_SOFT
512 enum DevFmtChannels {
513 DevFmtMono = ALC_MONO_SOFT,
514 DevFmtStereo = ALC_STEREO_SOFT,
515 DevFmtQuad = ALC_QUAD_SOFT,
516 DevFmtX51 = ALC_5POINT1_SOFT,
517 DevFmtX61 = ALC_6POINT1_SOFT,
518 DevFmtX71 = ALC_7POINT1_SOFT,
520 /* Similar to 5.1, except using the side channels instead of back */
521 DevFmtX51Side = 0x80000000 | ALC_5POINT1_SOFT
524 ALuint BytesFromDevFmt(enum DevFmtType type);
525 ALuint ChannelsFromDevFmt(enum DevFmtChannels chans);
526 static __inline ALuint FrameSizeFromDevFmt(enum DevFmtChannels chans,
527 enum DevFmtType type)
529 return ChannelsFromDevFmt(chans) * BytesFromDevFmt(type);
533 extern const struct EffectList {
534 const char *name;
535 int type;
536 const char *ename;
537 ALenum val;
538 } EffectList[];
541 struct ALCdevice_struct
543 volatile RefCount ref;
545 ALCboolean Connected;
546 ALboolean IsCaptureDevice;
547 ALboolean IsLoopbackDevice;
549 CRITICAL_SECTION Mutex;
551 ALuint Frequency;
552 ALuint UpdateSize;
553 ALuint NumUpdates;
554 enum DevFmtChannels FmtChans;
555 enum DevFmtType FmtType;
557 ALCchar *szDeviceName;
559 volatile ALCenum LastError;
561 // Maximum number of sources that can be created
562 ALuint MaxNoOfSources;
563 // Maximum number of slots that can be created
564 ALuint AuxiliaryEffectSlotMax;
566 ALCuint NumMonoSources;
567 ALCuint NumStereoSources;
568 ALuint NumAuxSends;
570 // Map of Buffers for this device
571 UIntMap BufferMap;
573 // Map of Effects for this device
574 UIntMap EffectMap;
576 // Map of Filters for this device
577 UIntMap FilterMap;
579 /* HRTF filter tables */
580 const struct Hrtf *Hrtf;
582 // Stereo-to-binaural filter
583 struct bs2b *Bs2b;
584 ALCint Bs2bLevel;
586 // Device flags
587 ALuint Flags;
589 // Dry path buffer mix
590 ALfloat DryBuffer[BUFFERSIZE][MAXCHANNELS];
592 enum Channel DevChannels[MAXCHANNELS];
594 enum Channel Speaker2Chan[MAXCHANNELS];
595 ALfloat PanningLUT[LUT_NUM][MAXCHANNELS];
596 ALuint NumChan;
598 ALfloat ClickRemoval[MAXCHANNELS];
599 ALfloat PendingClicks[MAXCHANNELS];
601 // Contexts created on this device
602 ALCcontext *volatile ContextList;
604 BackendFuncs *Funcs;
605 void *ExtraData; // For the backend's use
607 ALCdevice *volatile next;
610 #define ALCdevice_OpenPlayback(a,b) ((a)->Funcs->OpenPlayback((a), (b)))
611 #define ALCdevice_ClosePlayback(a) ((a)->Funcs->ClosePlayback((a)))
612 #define ALCdevice_ResetPlayback(a) ((a)->Funcs->ResetPlayback((a)))
613 #define ALCdevice_StopPlayback(a) ((a)->Funcs->StopPlayback((a)))
614 #define ALCdevice_OpenCapture(a,b) ((a)->Funcs->OpenCapture((a), (b)))
615 #define ALCdevice_CloseCapture(a) ((a)->Funcs->CloseCapture((a)))
616 #define ALCdevice_StartCapture(a) ((a)->Funcs->StartCapture((a)))
617 #define ALCdevice_StopCapture(a) ((a)->Funcs->StopCapture((a)))
618 #define ALCdevice_CaptureSamples(a,b,c) ((a)->Funcs->CaptureSamples((a), (b), (c)))
619 #define ALCdevice_AvailableSamples(a) ((a)->Funcs->AvailableSamples((a)))
621 // Duplicate stereo sources on the side/rear channels
622 #define DEVICE_DUPLICATE_STEREO (1<<0)
623 // Frequency was requested by the app or config file
624 #define DEVICE_FREQUENCY_REQUEST (1<<1)
625 // Channel configuration was requested by the config file
626 #define DEVICE_CHANNELS_REQUEST (1<<2)
628 // Specifies if the device is currently running
629 #define DEVICE_RUNNING (1<<31)
631 #define LookupBuffer(m, k) ((struct ALbuffer*)LookupUIntMapKey(&(m)->BufferMap, (k)))
632 #define LookupEffect(m, k) ((struct ALeffect*)LookupUIntMapKey(&(m)->EffectMap, (k)))
633 #define LookupFilter(m, k) ((struct ALfilter*)LookupUIntMapKey(&(m)->FilterMap, (k)))
634 #define RemoveBuffer(m, k) ((struct ALbuffer*)RemoveUIntMapKey(&(m)->BufferMap, (k)))
635 #define RemoveEffect(m, k) ((struct ALeffect*)RemoveUIntMapKey(&(m)->EffectMap, (k)))
636 #define RemoveFilter(m, k) ((struct ALfilter*)RemoveUIntMapKey(&(m)->FilterMap, (k)))
639 struct ALCcontext_struct
641 volatile RefCount ref;
643 ALlistener Listener;
645 UIntMap SourceMap;
646 UIntMap EffectSlotMap;
648 ALenum LastError;
650 volatile ALenum UpdateSources;
652 volatile enum DistanceModel DistanceModel;
653 volatile ALboolean SourceDistanceModel;
655 volatile ALfloat DopplerFactor;
656 volatile ALfloat DopplerVelocity;
657 volatile ALfloat flSpeedOfSound;
658 volatile ALenum DeferUpdates;
660 struct ALsource **ActiveSources;
661 ALsizei ActiveSourceCount;
662 ALsizei MaxActiveSources;
664 struct ALeffectslot **ActiveEffectSlots;
665 ALsizei ActiveEffectSlotCount;
666 ALsizei MaxActiveEffectSlots;
668 ALCdevice *Device;
669 const ALCchar *ExtensionList;
671 ALCcontext *volatile next;
674 #define LookupSource(m, k) ((struct ALsource*)LookupUIntMapKey(&(m)->SourceMap, (k)))
675 #define LookupEffectSlot(m, k) ((struct ALeffectslot*)LookupUIntMapKey(&(m)->EffectSlotMap, (k)))
676 #define RemoveSource(m, k) ((struct ALsource*)RemoveUIntMapKey(&(m)->SourceMap, (k)))
677 #define RemoveEffectSlot(m, k) ((struct ALeffectslot*)RemoveUIntMapKey(&(m)->EffectSlotMap, (k)))
679 ALCcontext *GetContextRef(void);
681 void ALCcontext_IncRef(ALCcontext *context);
682 void ALCcontext_DecRef(ALCcontext *context);
684 void AppendDeviceList(const ALCchar *name);
685 void AppendAllDeviceList(const ALCchar *name);
686 void AppendCaptureDeviceList(const ALCchar *name);
688 static __inline void LockDevice(ALCdevice *device)
689 { EnterCriticalSection(&device->Mutex); }
690 static __inline void UnlockDevice(ALCdevice *device)
691 { LeaveCriticalSection(&device->Mutex); }
693 static __inline void LockContext(ALCcontext *context)
694 { LockDevice(context->Device); }
695 static __inline void UnlockContext(ALCcontext *context)
696 { UnlockDevice(context->Device); }
699 ALvoid *StartThread(ALuint (*func)(ALvoid*), ALvoid *ptr);
700 ALuint StopThread(ALvoid *thread);
702 typedef struct RingBuffer RingBuffer;
703 RingBuffer *CreateRingBuffer(ALsizei frame_size, ALsizei length);
704 void DestroyRingBuffer(RingBuffer *ring);
705 ALsizei RingBufferSize(RingBuffer *ring);
706 void WriteRingBuffer(RingBuffer *ring, const ALubyte *data, ALsizei len);
707 void ReadRingBuffer(RingBuffer *ring, ALubyte *data, ALsizei len);
709 void ReadALConfig(void);
710 void FreeALConfig(void);
711 int ConfigValueExists(const char *blockName, const char *keyName);
712 const char *GetConfigValue(const char *blockName, const char *keyName, const char *def);
713 int GetConfigValueBool(const char *blockName, const char *keyName, int def);
714 int ConfigValueStr(const char *blockName, const char *keyName, const char **ret);
715 int ConfigValueInt(const char *blockName, const char *keyName, int *ret);
716 int ConfigValueUInt(const char *blockName, const char *keyName, unsigned int *ret);
717 int ConfigValueFloat(const char *blockName, const char *keyName, float *ret);
719 void SetRTPriority(void);
721 void SetDefaultChannelOrder(ALCdevice *device);
722 void SetDefaultWFXChannelOrder(ALCdevice *device);
724 const ALCchar *DevFmtTypeString(enum DevFmtType type);
725 const ALCchar *DevFmtChannelsString(enum DevFmtChannels chans);
727 #define HRIR_BITS (5)
728 #define HRIR_LENGTH (1<<HRIR_BITS)
729 #define HRIR_MASK (HRIR_LENGTH-1)
730 void InitHrtf(void);
731 void FreeHrtf(void);
732 const struct Hrtf *GetHrtf(ALCdevice *device);
733 ALfloat CalcHrtfDelta(ALfloat oldGain, ALfloat newGain, const ALfloat olddir[3], const ALfloat newdir[3]);
734 void GetLerpedHrtfCoeffs(const struct Hrtf *Hrtf, ALfloat elevation, ALfloat azimuth, ALfloat gain, ALfloat (*coeffs)[2], ALuint *delays);
735 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);
737 void al_print(const char *func, const char *fmt, ...) PRINTF_STYLE(2,3);
738 #define AL_PRINT(...) al_print(__FUNCTION__, __VA_ARGS__)
740 extern FILE *LogFile;
741 enum LogLevel {
742 NoLog,
743 LogError,
744 LogWarning,
745 LogTrace,
746 LogRef
748 extern enum LogLevel LogLevel;
750 #define TRACEREF(...) do { \
751 if(LogLevel >= LogRef) \
752 AL_PRINT(__VA_ARGS__); \
753 } while(0)
755 #define TRACE(...) do { \
756 if(LogLevel >= LogTrace) \
757 AL_PRINT(__VA_ARGS__); \
758 } while(0)
760 #define WARN(...) do { \
761 if(LogLevel >= LogWarning) \
762 AL_PRINT(__VA_ARGS__); \
763 } while(0)
765 #define ERR(...) do { \
766 if(LogLevel >= LogError) \
767 AL_PRINT(__VA_ARGS__); \
768 } while(0)
771 extern ALint RTPrioLevel;
773 #ifdef __cplusplus
775 #endif
777 #endif