Set the FPU into single-precision mode for mixer updates
[openal-soft/android.git] / OpenAL32 / Include / alMain.h
blobf69ea967a017c96fedcad1b9814cdaf2bc70794b
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 0x1400
27 #define ALC_UNSIGNED_BYTE 0x1401
28 #define ALC_SHORT 0x1402
29 #define ALC_UNSIGNED_SHORT 0x1403
30 #define ALC_INT 0x1404
31 #define ALC_UNSIGNED_INT 0x1405
32 #define ALC_FLOAT 0x1406
34 /* Channel configurations */
35 #define ALC_MONO 0x1500
36 #define ALC_STEREO 0x1501
37 #define ALC_QUAD 0x1503
38 #define ALC_5POINT1 0x1504 /* (WFX order) */
39 #define ALC_6POINT1 0x1505 /* (WFX order) */
40 #define ALC_7POINT1 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_buffer_samples
53 #define AL_SOFT_buffer_samples 1
54 /* Sample types */
55 #define AL_BYTE 0x1400
56 #define AL_UNSIGNED_BYTE 0x1401
57 #define AL_SHORT 0x1402
58 #define AL_UNSIGNED_SHORT 0x1403
59 #define AL_INT 0x1404
60 #define AL_UNSIGNED_INT 0x1405
61 #define AL_FLOAT 0x1406
62 #define AL_DOUBLE 0x1407
63 #define AL_BYTE3 0x1408
64 #define AL_UNSIGNED_BYTE3 0x1409
65 #define AL_MULAW 0x1410
66 #define AL_IMA4 0x1411
68 /* Channel configurations */
69 #define AL_MONO 0x1500
70 #define AL_STEREO 0x1501
71 #define AL_REAR 0x1502
72 #define AL_QUAD 0x1503
73 #define AL_5POINT1 0x1504 /* (WFX order) */
74 #define AL_6POINT1 0x1505 /* (WFX order) */
75 #define AL_7POINT1 0x1506 /* (WFX order) */
77 /* Storage formats */
78 #define AL_MONO8 0x1100
79 #define AL_MONO16 0x1101
80 #define AL_MONO32F 0x10010
81 #define AL_STEREO8 0x1102
82 #define AL_STEREO16 0x1103
83 #define AL_STEREO32F 0x10011
84 #define AL_QUAD8 0x1204
85 #define AL_QUAD16 0x1205
86 #define AL_QUAD32F 0x1206
87 #define AL_REAR8 0x1207
88 #define AL_REAR16 0x1208
89 #define AL_REAR32F 0x1209
90 #define AL_5POINT1_8 0x120A
91 #define AL_5POINT1_16 0x120B
92 #define AL_5POINT1_32F 0x120C
93 #define AL_6POINT1_8 0x120D
94 #define AL_6POINT1_16 0x120E
95 #define AL_6POINT1_32F 0x120F
96 #define AL_7POINT1_8 0x1210
97 #define AL_7POINT1_16 0x1211
98 #define AL_7POINT1_32F 0x1212
100 typedef void (AL_APIENTRY*LPALBUFFERSAMPLESSOFT)(ALuint,ALuint,ALenum,ALsizei,ALenum,ALenum,const ALvoid*);
101 typedef void (AL_APIENTRY*LPALBUFFERSUBSAMPLESSOFT)(ALuint,ALsizei,ALsizei,ALenum,ALenum,const ALvoid*);
102 typedef void (AL_APIENTRY*LPALGETBUFFERSAMPLESSOFT)(ALuint,ALsizei,ALsizei,ALenum,ALenum,ALvoid*);
103 typedef ALboolean (AL_APIENTRY*LPALISBUFFERFORMATSUPPORTEDSOFT)(ALenum);
104 #ifdef AL_ALEXT_PROTOTYPES
105 AL_API void AL_APIENTRY alBufferSamplesSOFT(ALuint buffer,
106 ALuint samplerate, ALenum internalformat, ALsizei frames,
107 ALenum channels, ALenum type, const ALvoid *data);
108 AL_API void AL_APIENTRY alBufferSubSamplesSOFT(ALuint buffer,
109 ALsizei offset, ALsizei frames,
110 ALenum channels, ALenum type, const ALvoid *data);
111 AL_API void AL_APIENTRY alGetBufferSamplesSOFT(ALuint buffer,
112 ALsizei offset, ALsizei frames,
113 ALenum channels, ALenum type, ALvoid *data);
114 AL_API ALboolean AL_APIENTRY alIsBufferFormatSupportedSOFT(ALenum format);
115 #endif
116 #endif
118 #ifndef AL_SOFT_non_virtual_channels
119 #define AL_SOFT_non_virtual_channels 1
120 #define AL_VIRTUAL_CHANNELS_SOFT 0x1033
121 #endif
123 #ifndef AL_SOFT_deferred_updates
124 #define AL_SOFT_deferred_updates 1
125 #define AL_DEFERRED_UPDATES_SOFT 0xC002
126 typedef ALvoid (AL_APIENTRY*LPALDEFERUPDATESSOFT)(void);
127 typedef ALvoid (AL_APIENTRY*LPALPROCESSUPDATESSOFT)(void);
128 #ifdef AL_ALEXT_PROTOTYPES
129 AL_API ALvoid AL_APIENTRY alDeferUpdatesSOFT(void);
130 AL_API ALvoid AL_APIENTRY alProcessUpdatesSOFT(void);
131 #endif
132 #endif
135 #if defined(HAVE_STDINT_H)
136 #include <stdint.h>
137 typedef int64_t ALint64;
138 typedef uint64_t ALuint64;
139 #elif defined(HAVE___INT64)
140 typedef __int64 ALint64;
141 typedef unsigned __int64 ALuint64;
142 #elif (SIZEOF_LONG == 8)
143 typedef long ALint64;
144 typedef unsigned long ALuint64;
145 #elif (SIZEOF_LONG_LONG == 8)
146 typedef long long ALint64;
147 typedef unsigned long long ALuint64;
148 #endif
150 typedef ptrdiff_t ALintptrEXT;
151 typedef ptrdiff_t ALsizeiptrEXT;
153 #ifdef HAVE_GCC_FORMAT
154 #define PRINTF_STYLE(x, y) __attribute__((format(printf, (x), (y))))
155 #else
156 #define PRINTF_STYLE(x, y)
157 #endif
159 #if defined(HAVE_RESTRICT)
160 #define RESTRICT restrict
161 #elif defined(HAVE___RESTRICT)
162 #define RESTRICT __restrict
163 #else
164 #define RESTRICT
165 #endif
168 #ifdef _WIN32
170 #include <windows.h>
172 typedef DWORD pthread_key_t;
173 int pthread_key_create(pthread_key_t *key, void (*callback)(void*));
174 int pthread_key_delete(pthread_key_t key);
175 void *pthread_getspecific(pthread_key_t key);
176 int pthread_setspecific(pthread_key_t key, void *val);
178 #define HAVE_DYNLOAD 1
179 void *LoadLib(const char *name);
180 void CloseLib(void *handle);
181 void *GetSymbol(void *handle, const char *name);
183 typedef LONG pthread_once_t;
184 #define PTHREAD_ONCE_INIT 0
185 void pthread_once(pthread_once_t *once, void (*callback)(void));
187 static __inline int sched_yield(void)
188 { SwitchToThread(); return 0; }
190 #else
192 #include <unistd.h>
193 #include <assert.h>
194 #include <pthread.h>
195 #ifdef HAVE_PTHREAD_NP_H
196 #include <pthread_np.h>
197 #endif
198 #include <sys/time.h>
199 #include <time.h>
200 #include <errno.h>
202 #define IsBadWritePtr(a,b) ((a) == NULL && (b) != 0)
204 typedef pthread_mutex_t CRITICAL_SECTION;
205 void InitializeCriticalSection(CRITICAL_SECTION *cs);
206 void DeleteCriticalSection(CRITICAL_SECTION *cs);
207 void EnterCriticalSection(CRITICAL_SECTION *cs);
208 void LeaveCriticalSection(CRITICAL_SECTION *cs);
210 ALuint timeGetTime(void);
211 void Sleep(ALuint t);
213 #if defined(HAVE_DLFCN_H)
214 #define HAVE_DYNLOAD 1
215 void *LoadLib(const char *name);
216 void CloseLib(void *handle);
217 void *GetSymbol(void *handle, const char *name);
218 #endif
220 #endif
222 #if defined(__GNUC__) && (__GNUC__ > 4 || (__GNUC__ == 4 && __GNUC_MINOR__ >= 1))
223 typedef ALuint RefCount;
224 static __inline RefCount IncrementRef(volatile RefCount *ptr)
225 { return __sync_add_and_fetch(ptr, 1); }
226 static __inline RefCount DecrementRef(volatile RefCount *ptr)
227 { return __sync_sub_and_fetch(ptr, 1); }
229 static __inline int ExchangeInt(volatile int *ptr, int newval)
231 return __sync_lock_test_and_set(ptr, newval);
233 static __inline void *ExchangePtr(void *volatile*ptr, void *newval)
235 return __sync_lock_test_and_set(ptr, newval);
237 static __inline ALboolean CompExchangeInt(volatile int *ptr, int oldval, int newval)
239 return __sync_bool_compare_and_swap(ptr, oldval, newval);
241 static __inline ALboolean CompExchangePtr(void *volatile*ptr, void *oldval, void *newval)
243 return __sync_bool_compare_and_swap(ptr, oldval, newval);
246 #elif defined(__GNUC__) && (defined(__i386__) || defined(__x86_64__))
248 static __inline int xaddl(volatile int *dest, int incr)
250 int ret;
251 __asm__ __volatile__("lock; xaddl %0,(%1)"
252 : "=r" (ret)
253 : "r" (dest), "0" (incr)
254 : "memory");
255 return ret;
258 typedef int RefCount;
259 static __inline RefCount IncrementRef(volatile RefCount *ptr)
260 { return xaddl(ptr, 1)+1; }
261 static __inline RefCount DecrementRef(volatile RefCount *ptr)
262 { return xaddl(ptr, -1)-1; }
264 static __inline int ExchangeInt(volatile int *dest, int newval)
266 int ret;
267 __asm__ __volatile__("lock; xchgl %0,(%1)"
268 : "=r" (ret)
269 : "r" (dest), "0" (newval)
270 : "memory");
271 return ret;
274 static __inline ALboolean CompExchangeInt(volatile int *dest, int oldval, int newval)
276 int ret;
277 __asm__ __volatile__("lock; cmpxchgl %2,(%1)"
278 : "=a" (ret)
279 : "r" (dest), "r" (newval), "0" (oldval)
280 : "memory");
281 return ret == oldval;
284 static __inline void *ExchangePtr(void *volatile*dest, void *newval)
286 void *ret;
287 __asm__ __volatile__(
288 #ifdef __i386__
289 "lock; xchgl %0,(%1)"
290 #else
291 "lock; xchgq %0,(%1)"
292 #endif
293 : "=r" (ret)
294 : "r" (dest), "0" (newval)
295 : "memory"
297 return ret;
300 static __inline ALboolean CompExchangePtr(void *volatile*dest, void *oldval, void *newval)
302 void *ret;
303 __asm__ __volatile__(
304 #ifdef __i386__
305 "lock; cmpxchgl %2,(%1)"
306 #else
307 "lock; cmpxchgq %2,(%1)"
308 #endif
309 : "=a" (ret)
310 : "r" (dest), "r" (newval), "0" (oldval)
311 : "memory"
313 return ret == oldval;
316 #elif defined(_WIN32)
318 typedef LONG RefCount;
319 static __inline RefCount IncrementRef(volatile RefCount *ptr)
320 { return InterlockedIncrement(ptr); }
321 static __inline RefCount DecrementRef(volatile RefCount *ptr)
322 { return InterlockedDecrement(ptr); }
324 extern ALbyte LONG_size_does_not_match_int[(sizeof(LONG)==sizeof(int))?1:-1];
326 static __inline int ExchangeInt(volatile int *ptr, int newval)
328 union {
329 volatile int *i;
330 volatile LONG *l;
331 } u = { ptr };
332 return InterlockedExchange(u.l, newval);
334 static __inline void *ExchangePtr(void *volatile*ptr, void *newval)
336 return InterlockedExchangePointer(ptr, newval);
338 static __inline ALboolean CompExchangeInt(volatile int *ptr, int oldval, int newval)
340 union {
341 volatile int *i;
342 volatile LONG *l;
343 } u = { ptr };
344 return InterlockedCompareExchange(u.l, newval, oldval) == oldval;
346 static __inline ALboolean CompExchangePtr(void *volatile*ptr, void *oldval, void *newval)
348 return InterlockedCompareExchangePointer(ptr, newval, oldval) == oldval;
351 #elif defined(__APPLE__)
353 #include <libkern/OSAtomic.h>
355 typedef int32_t RefCount;
356 static __inline RefCount IncrementRef(volatile RefCount *ptr)
357 { return OSAtomicIncrement32Barrier(ptr); }
358 static __inline RefCount DecrementRef(volatile RefCount *ptr)
359 { return OSAtomicDecrement32Barrier(ptr); }
361 static __inline int ExchangeInt(volatile int *ptr, int newval)
363 /* Really? No regular old atomic swap? */
364 int oldval;
365 do {
366 oldval = *ptr;
367 } while(!OSAtomicCompareAndSwap32Barrier(oldval, newval, ptr));
368 return oldval;
370 static __inline void *ExchangePtr(void *volatile*ptr, void *newval)
372 void *oldval;
373 do {
374 oldval = *ptr;
375 } while(!OSAtomicCompareAndSwapPtrBarrier(oldval, newval, ptr));
376 return oldval;
378 static __inline ALboolean CompExchangeInt(volatile int *ptr, int oldval, int newval)
380 return OSAtomicCompareAndSwap32Barrier(oldval, newval, ptr);
382 static __inline ALboolean CompExchangePtr(void *volatile*ptr, void *oldval, void *newval)
384 return OSAtomicCompareAndSwapPtrBarrier(oldval, newval, ptr);
387 #else
388 #error "No atomic functions available on this platform!"
389 typedef ALuint RefCount;
390 #endif
393 typedef struct {
394 volatile RefCount read_count;
395 volatile RefCount write_count;
396 volatile ALenum read_lock;
397 volatile ALenum read_entry_lock;
398 volatile ALenum write_lock;
399 } RWLock;
401 void RWLockInit(RWLock *lock);
402 void ReadLock(RWLock *lock);
403 void ReadUnlock(RWLock *lock);
404 void WriteLock(RWLock *lock);
405 void WriteUnlock(RWLock *lock);
408 typedef struct UIntMap {
409 struct {
410 ALuint key;
411 ALvoid *value;
412 } *array;
413 ALsizei size;
414 ALsizei maxsize;
415 ALsizei limit;
416 RWLock lock;
417 } UIntMap;
418 extern UIntMap TlsDestructor;
420 void InitUIntMap(UIntMap *map, ALsizei limit);
421 void ResetUIntMap(UIntMap *map);
422 ALenum InsertUIntMapEntry(UIntMap *map, ALuint key, ALvoid *value);
423 void RemoveUIntMapKey(UIntMap *map, ALuint key);
424 ALvoid *LookupUIntMapKey(UIntMap *map, ALuint key);
425 ALvoid *PopUIntMapValue(UIntMap *map, ALuint key);
427 static __inline void LockUIntMapRead(UIntMap *map)
428 { ReadLock(&map->lock); }
429 static __inline void UnlockUIntMapRead(UIntMap *map)
430 { ReadUnlock(&map->lock); }
431 static __inline void LockUIntMapWrite(UIntMap *map)
432 { WriteLock(&map->lock); }
433 static __inline void UnlockUIntMapWrite(UIntMap *map)
434 { WriteUnlock(&map->lock); }
436 #include "alListener.h"
437 #include "alu.h"
439 #ifdef __cplusplus
440 extern "C" {
441 #endif
444 #define DEFAULT_OUTPUT_RATE (44100)
446 #define SPEEDOFSOUNDMETRESPERSEC (343.3f)
447 #define AIRABSORBGAINHF (0.99426f) /* -0.05dB */
449 #define LOWPASSFREQCUTOFF (5000)
452 struct Hrtf;
455 // Find the next power-of-2 for non-power-of-2 numbers.
456 static __inline ALuint NextPowerOf2(ALuint value)
458 ALuint powerOf2 = 1;
460 if(value)
462 value--;
463 while(value)
465 value >>= 1;
466 powerOf2 <<= 1;
469 return powerOf2;
472 /* Fast float-to-int conversion. Assumes the FPU is already in round-to-zero
473 * mode. */
474 static __inline ALint fastf2i(ALfloat f)
476 ALint i;
477 #if defined(_MSC_VER)
478 __asm fld f
479 __asm fistp i
480 #elif defined(__GNUC__)
481 __asm__ __volatile__("flds %1\n\t"
482 "fistpl %0\n\t"
483 : "=m" (i)
484 : "m" (f));
485 #else
486 i = (ALint)f;
487 #endif
488 return i;
491 /* Fast float-to-uint conversion. Assumes the FPU is already in round-to-zero
492 * mode. */
493 static __inline ALuint fastf2u(ALfloat f)
494 { return fastf2i(f); }
497 enum DevProbe {
498 DEVICE_PROBE,
499 ALL_DEVICE_PROBE,
500 CAPTURE_DEVICE_PROBE
503 typedef struct {
504 ALCenum (*OpenPlayback)(ALCdevice*, const ALCchar*);
505 void (*ClosePlayback)(ALCdevice*);
506 ALCboolean (*ResetPlayback)(ALCdevice*);
507 void (*StopPlayback)(ALCdevice*);
509 ALCenum (*OpenCapture)(ALCdevice*, const ALCchar*);
510 void (*CloseCapture)(ALCdevice*);
511 void (*StartCapture)(ALCdevice*);
512 void (*StopCapture)(ALCdevice*);
513 ALCenum (*CaptureSamples)(ALCdevice*, void*, ALCuint);
514 ALCuint (*AvailableSamples)(ALCdevice*);
515 } BackendFuncs;
517 struct BackendInfo {
518 const char *name;
519 ALCboolean (*Init)(BackendFuncs*);
520 void (*Deinit)(void);
521 void (*Probe)(enum DevProbe);
522 BackendFuncs Funcs;
525 ALCboolean alc_alsa_init(BackendFuncs *func_list);
526 void alc_alsa_deinit(void);
527 void alc_alsa_probe(enum DevProbe type);
528 ALCboolean alc_oss_init(BackendFuncs *func_list);
529 void alc_oss_deinit(void);
530 void alc_oss_probe(enum DevProbe type);
531 ALCboolean alc_solaris_init(BackendFuncs *func_list);
532 void alc_solaris_deinit(void);
533 void alc_solaris_probe(enum DevProbe type);
534 ALCboolean alc_sndio_init(BackendFuncs *func_list);
535 void alc_sndio_deinit(void);
536 void alc_sndio_probe(enum DevProbe type);
537 ALCboolean alcMMDevApiInit(BackendFuncs *func_list);
538 void alcMMDevApiDeinit(void);
539 void alcMMDevApiProbe(enum DevProbe type);
540 ALCboolean alcDSoundInit(BackendFuncs *func_list);
541 void alcDSoundDeinit(void);
542 void alcDSoundProbe(enum DevProbe type);
543 ALCboolean alcWinMMInit(BackendFuncs *FuncList);
544 void alcWinMMDeinit(void);
545 void alcWinMMProbe(enum DevProbe type);
546 ALCboolean alc_pa_init(BackendFuncs *func_list);
547 void alc_pa_deinit(void);
548 void alc_pa_probe(enum DevProbe type);
549 ALCboolean alc_wave_init(BackendFuncs *func_list);
550 void alc_wave_deinit(void);
551 void alc_wave_probe(enum DevProbe type);
552 ALCboolean alc_pulse_init(BackendFuncs *func_list);
553 void alc_pulse_deinit(void);
554 void alc_pulse_probe(enum DevProbe type);
555 ALCboolean alc_ca_init(BackendFuncs *func_list);
556 void alc_ca_deinit(void);
557 void alc_ca_probe(enum DevProbe type);
558 ALCboolean alc_opensl_init(BackendFuncs *func_list);
559 void alc_opensl_deinit(void);
560 void alc_opensl_probe(enum DevProbe type);
561 ALCboolean alc_null_init(BackendFuncs *func_list);
562 void alc_null_deinit(void);
563 void alc_null_probe(enum DevProbe type);
564 ALCboolean alc_loopback_init(BackendFuncs *func_list);
565 void alc_loopback_deinit(void);
566 void alc_loopback_probe(enum DevProbe type);
569 /* Device formats */
570 enum DevFmtType {
571 DevFmtByte = ALC_BYTE,
572 DevFmtUByte = ALC_UNSIGNED_BYTE,
573 DevFmtShort = ALC_SHORT,
574 DevFmtUShort = ALC_UNSIGNED_SHORT,
575 DevFmtFloat = ALC_FLOAT
577 enum DevFmtChannels {
578 DevFmtMono = ALC_MONO,
579 DevFmtStereo = ALC_STEREO,
580 DevFmtQuad = ALC_QUAD,
581 DevFmtX51 = ALC_5POINT1,
582 DevFmtX61 = ALC_6POINT1,
583 DevFmtX71 = ALC_7POINT1,
585 /* Similar to 5.1, except using the side channels instead of back */
586 DevFmtX51Side = 0x80000000 | ALC_5POINT1
589 ALuint BytesFromDevFmt(enum DevFmtType type);
590 ALuint ChannelsFromDevFmt(enum DevFmtChannels chans);
591 static __inline ALuint FrameSizeFromDevFmt(enum DevFmtChannels chans,
592 enum DevFmtType type)
594 return ChannelsFromDevFmt(chans) * BytesFromDevFmt(type);
598 extern const struct EffectList {
599 const char *name;
600 int type;
601 const char *ename;
602 ALenum val;
603 } EffectList[];
606 struct ALCdevice_struct
608 volatile RefCount ref;
610 ALCboolean Connected;
611 ALboolean IsCaptureDevice;
612 ALboolean IsLoopbackDevice;
614 CRITICAL_SECTION Mutex;
616 ALuint Frequency;
617 ALuint UpdateSize;
618 ALuint NumUpdates;
619 enum DevFmtChannels FmtChans;
620 enum DevFmtType FmtType;
622 ALCchar *szDeviceName;
624 volatile ALCenum LastError;
626 // Maximum number of sources that can be created
627 ALuint MaxNoOfSources;
628 // Maximum number of slots that can be created
629 ALuint AuxiliaryEffectSlotMax;
631 ALCuint NumMonoSources;
632 ALCuint NumStereoSources;
633 ALuint NumAuxSends;
635 // Map of Buffers for this device
636 UIntMap BufferMap;
638 // Map of Effects for this device
639 UIntMap EffectMap;
641 // Map of Filters for this device
642 UIntMap FilterMap;
644 /* HRTF filter tables */
645 const struct Hrtf *Hrtf;
647 // Stereo-to-binaural filter
648 struct bs2b *Bs2b;
649 ALCint Bs2bLevel;
651 // Device flags
652 ALuint Flags;
654 // Dry path buffer mix
655 ALfloat DryBuffer[BUFFERSIZE][MAXCHANNELS];
657 enum Channel DevChannels[MAXCHANNELS];
659 enum Channel Speaker2Chan[MAXCHANNELS];
660 ALfloat PanningLUT[LUT_NUM][MAXCHANNELS];
661 ALuint NumChan;
663 ALfloat ClickRemoval[MAXCHANNELS];
664 ALfloat PendingClicks[MAXCHANNELS];
666 // Contexts created on this device
667 ALCcontext *volatile ContextList;
669 BackendFuncs *Funcs;
670 void *ExtraData; // For the backend's use
672 ALCdevice *volatile next;
675 #define ALCdevice_OpenPlayback(a,b) ((a)->Funcs->OpenPlayback((a), (b)))
676 #define ALCdevice_ClosePlayback(a) ((a)->Funcs->ClosePlayback((a)))
677 #define ALCdevice_ResetPlayback(a) ((a)->Funcs->ResetPlayback((a)))
678 #define ALCdevice_StopPlayback(a) ((a)->Funcs->StopPlayback((a)))
679 #define ALCdevice_OpenCapture(a,b) ((a)->Funcs->OpenCapture((a), (b)))
680 #define ALCdevice_CloseCapture(a) ((a)->Funcs->CloseCapture((a)))
681 #define ALCdevice_StartCapture(a) ((a)->Funcs->StartCapture((a)))
682 #define ALCdevice_StopCapture(a) ((a)->Funcs->StopCapture((a)))
683 #define ALCdevice_CaptureSamples(a,b,c) ((a)->Funcs->CaptureSamples((a), (b), (c)))
684 #define ALCdevice_AvailableSamples(a) ((a)->Funcs->AvailableSamples((a)))
686 // Duplicate stereo sources on the side/rear channels
687 #define DEVICE_DUPLICATE_STEREO (1<<0)
688 // Use HRTF filters for mixing sounds
689 #define DEVICE_USE_HRTF (1<<1)
690 // Frequency was requested by the app or config file
691 #define DEVICE_FREQUENCY_REQUEST (1<<2)
692 // Channel configuration was requested by the config file
693 #define DEVICE_CHANNELS_REQUEST (1<<3)
695 // Specifies if the device is currently running
696 #define DEVICE_RUNNING (1<<31)
698 #define LookupBuffer(m, k) ((struct ALbuffer*)LookupUIntMapKey(&(m)->BufferMap, (k)))
699 #define LookupEffect(m, k) ((struct ALeffect*)LookupUIntMapKey(&(m)->EffectMap, (k)))
700 #define LookupFilter(m, k) ((struct ALfilter*)LookupUIntMapKey(&(m)->FilterMap, (k)))
701 #define RemoveBuffer(m, k) ((struct ALbuffer*)PopUIntMapValue(&(m)->BufferMap, (k)))
702 #define RemoveEffect(m, k) ((struct ALeffect*)PopUIntMapValue(&(m)->EffectMap, (k)))
703 #define RemoveFilter(m, k) ((struct ALfilter*)PopUIntMapValue(&(m)->FilterMap, (k)))
706 struct ALCcontext_struct
708 volatile RefCount ref;
710 ALlistener Listener;
712 UIntMap SourceMap;
713 UIntMap EffectSlotMap;
715 ALenum LastError;
717 volatile ALenum UpdateSources;
719 volatile enum DistanceModel DistanceModel;
720 volatile ALboolean SourceDistanceModel;
722 volatile ALfloat DopplerFactor;
723 volatile ALfloat DopplerVelocity;
724 volatile ALfloat flSpeedOfSound;
725 volatile ALenum DeferUpdates;
727 struct ALsource **ActiveSources;
728 ALsizei ActiveSourceCount;
729 ALsizei MaxActiveSources;
731 struct ALeffectslot **ActiveEffectSlots;
732 ALsizei ActiveEffectSlotCount;
733 ALsizei MaxActiveEffectSlots;
735 ALCdevice *Device;
736 const ALCchar *ExtensionList;
738 ALCcontext *volatile next;
741 #define LookupSource(m, k) ((struct ALsource*)LookupUIntMapKey(&(m)->SourceMap, (k)))
742 #define LookupEffectSlot(m, k) ((struct ALeffectslot*)LookupUIntMapKey(&(m)->EffectSlotMap, (k)))
743 #define RemoveSource(m, k) ((struct ALsource*)PopUIntMapValue(&(m)->SourceMap, (k)))
744 #define RemoveEffectSlot(m, k) ((struct ALeffectslot*)PopUIntMapValue(&(m)->EffectSlotMap, (k)))
746 ALCcontext *GetContextRef(void);
748 void ALCcontext_IncRef(ALCcontext *context);
749 void ALCcontext_DecRef(ALCcontext *context);
751 void AppendDeviceList(const ALCchar *name);
752 void AppendAllDeviceList(const ALCchar *name);
753 void AppendCaptureDeviceList(const ALCchar *name);
755 ALCvoid LockDevice(ALCdevice *device);
756 ALCvoid UnlockDevice(ALCdevice *device);
757 ALCvoid LockContext(ALCcontext *context);
758 ALCvoid UnlockContext(ALCcontext *context);
760 ALvoid *StartThread(ALuint (*func)(ALvoid*), ALvoid *ptr);
761 ALuint StopThread(ALvoid *thread);
763 typedef struct RingBuffer RingBuffer;
764 RingBuffer *CreateRingBuffer(ALsizei frame_size, ALsizei length);
765 void DestroyRingBuffer(RingBuffer *ring);
766 ALsizei RingBufferSize(RingBuffer *ring);
767 void WriteRingBuffer(RingBuffer *ring, const ALubyte *data, ALsizei len);
768 void ReadRingBuffer(RingBuffer *ring, ALubyte *data, ALsizei len);
770 void ReadALConfig(void);
771 void FreeALConfig(void);
772 int ConfigValueExists(const char *blockName, const char *keyName);
773 const char *GetConfigValue(const char *blockName, const char *keyName, const char *def);
774 int GetConfigValueBool(const char *blockName, const char *keyName, int def);
775 int ConfigValueStr(const char *blockName, const char *keyName, const char **ret);
776 int ConfigValueInt(const char *blockName, const char *keyName, int *ret);
777 int ConfigValueUInt(const char *blockName, const char *keyName, unsigned int *ret);
778 int ConfigValueFloat(const char *blockName, const char *keyName, float *ret);
780 void SetRTPriority(void);
782 void SetDefaultChannelOrder(ALCdevice *device);
783 void SetDefaultWFXChannelOrder(ALCdevice *device);
785 const ALCchar *DevFmtTypeString(enum DevFmtType type);
786 const ALCchar *DevFmtChannelsString(enum DevFmtChannels chans);
788 #define HRIR_BITS (5)
789 #define HRIR_LENGTH (1<<HRIR_BITS)
790 #define HRIR_MASK (HRIR_LENGTH-1)
791 void InitHrtf(void);
792 void FreeHrtf(void);
793 const struct Hrtf *GetHrtf(ALCdevice *device);
794 ALfloat CalcHrtfDelta(ALfloat oldGain, ALfloat newGain, const ALfloat olddir[3], const ALfloat newdir[3]);
795 void GetLerpedHrtfCoeffs(const struct Hrtf *Hrtf, ALfloat elevation, ALfloat azimuth, ALfloat gain, ALfloat (*coeffs)[2], ALuint *delays);
796 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);
798 void al_print(const char *func, const char *fmt, ...) PRINTF_STYLE(2,3);
799 #define AL_PRINT(...) al_print(__FUNCTION__, __VA_ARGS__)
801 extern FILE *LogFile;
802 enum LogLevel {
803 NoLog,
804 LogError,
805 LogWarning,
806 LogTrace,
807 LogRef
809 extern enum LogLevel LogLevel;
811 #define TRACEREF(...) do { \
812 if(LogLevel >= LogRef) \
813 AL_PRINT(__VA_ARGS__); \
814 } while(0)
816 #define TRACE(...) do { \
817 if(LogLevel >= LogTrace) \
818 AL_PRINT(__VA_ARGS__); \
819 } while(0)
821 #define WARN(...) do { \
822 if(LogLevel >= LogWarning) \
823 AL_PRINT(__VA_ARGS__); \
824 } while(0)
826 #define ERR(...) do { \
827 if(LogLevel >= LogError) \
828 AL_PRINT(__VA_ARGS__); \
829 } while(0)
832 extern ALint RTPrioLevel;
834 #ifdef __cplusplus
836 #endif
838 #endif