Append _SOFT to the ALC loopback format enums
[openal-soft.git] / OpenAL32 / Include / alMain.h
blob0d8f14dc5b795a67072d58fd6a1cd00e9ffa0024
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_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_ALAW 0x1411
67 #define AL_IMA4 0x1412
69 /* Channel configurations */
70 #define AL_MONO 0x1500
71 #define AL_STEREO 0x1501
72 #define AL_REAR 0x1502
73 #define AL_QUAD 0x1503
74 #define AL_5POINT1 0x1504 /* (WFX order) */
75 #define AL_6POINT1 0x1505 /* (WFX order) */
76 #define AL_7POINT1 0x1506 /* (WFX order) */
78 /* Storage formats */
79 #define AL_MONO8 0x1100
80 #define AL_MONO16 0x1101
81 #define AL_MONO32F 0x10010
82 #define AL_STEREO8 0x1102
83 #define AL_STEREO16 0x1103
84 #define AL_STEREO32F 0x10011
85 #define AL_QUAD8 0x1204
86 #define AL_QUAD16 0x1205
87 #define AL_QUAD32F 0x1206
88 #define AL_REAR8 0x1207
89 #define AL_REAR16 0x1208
90 #define AL_REAR32F 0x1209
91 #define AL_5POINT1_8 0x120A
92 #define AL_5POINT1_16 0x120B
93 #define AL_5POINT1_32F 0x120C
94 #define AL_6POINT1_8 0x120D
95 #define AL_6POINT1_16 0x120E
96 #define AL_6POINT1_32F 0x120F
97 #define AL_7POINT1_8 0x1210
98 #define AL_7POINT1_16 0x1211
99 #define AL_7POINT1_32F 0x1212
101 /* Buffer attributes */
102 #define AL_INTERNAL_FORMAT 0x2008
103 #define AL_BYTE_LENGTH 0x2009
104 #define AL_SAMPLE_LENGTH 0x200A
105 #define AL_SEC_LENGTH 0x200B
107 typedef void (AL_APIENTRY*LPALBUFFERSAMPLESSOFT)(ALuint,ALuint,ALenum,ALsizei,ALenum,ALenum,const ALvoid*);
108 typedef void (AL_APIENTRY*LPALBUFFERSUBSAMPLESSOFT)(ALuint,ALsizei,ALsizei,ALenum,ALenum,const ALvoid*);
109 typedef void (AL_APIENTRY*LPALGETBUFFERSAMPLESSOFT)(ALuint,ALsizei,ALsizei,ALenum,ALenum,ALvoid*);
110 typedef ALboolean (AL_APIENTRY*LPALISBUFFERFORMATSUPPORTEDSOFT)(ALenum);
111 #ifdef AL_ALEXT_PROTOTYPES
112 AL_API void AL_APIENTRY alBufferSamplesSOFT(ALuint buffer,
113 ALuint samplerate, ALenum internalformat, ALsizei samples,
114 ALenum channels, ALenum type, const ALvoid *data);
115 AL_API void AL_APIENTRY alBufferSubSamplesSOFT(ALuint buffer,
116 ALsizei offset, ALsizei samples,
117 ALenum channels, ALenum type, const ALvoid *data);
118 AL_API void AL_APIENTRY alGetBufferSamplesSOFT(ALuint buffer,
119 ALsizei offset, ALsizei samples,
120 ALenum channels, ALenum type, ALvoid *data);
121 AL_API ALboolean AL_APIENTRY alIsBufferFormatSupportedSOFT(ALenum format);
122 #endif
123 #endif
125 #ifndef AL_SOFT_non_virtual_channels
126 #define AL_SOFT_non_virtual_channels 1
127 #define AL_VIRTUAL_CHANNELS_SOFT 0x1033
128 #endif
130 #ifndef AL_SOFT_deferred_updates
131 #define AL_SOFT_deferred_updates 1
132 #define AL_DEFERRED_UPDATES_SOFT 0xC002
133 typedef ALvoid (AL_APIENTRY*LPALDEFERUPDATESSOFT)(void);
134 typedef ALvoid (AL_APIENTRY*LPALPROCESSUPDATESSOFT)(void);
135 #ifdef AL_ALEXT_PROTOTYPES
136 AL_API ALvoid AL_APIENTRY alDeferUpdatesSOFT(void);
137 AL_API ALvoid AL_APIENTRY alProcessUpdatesSOFT(void);
138 #endif
139 #endif
142 #if defined(HAVE_STDINT_H)
143 #include <stdint.h>
144 typedef int64_t ALint64;
145 typedef uint64_t ALuint64;
146 #elif defined(HAVE___INT64)
147 typedef __int64 ALint64;
148 typedef unsigned __int64 ALuint64;
149 #elif (SIZEOF_LONG == 8)
150 typedef long ALint64;
151 typedef unsigned long ALuint64;
152 #elif (SIZEOF_LONG_LONG == 8)
153 typedef long long ALint64;
154 typedef unsigned long long ALuint64;
155 #endif
157 typedef ptrdiff_t ALintptrEXT;
158 typedef ptrdiff_t ALsizeiptrEXT;
160 #ifdef HAVE_GCC_FORMAT
161 #define PRINTF_STYLE(x, y) __attribute__((format(printf, (x), (y))))
162 #else
163 #define PRINTF_STYLE(x, y)
164 #endif
166 #if defined(HAVE_RESTRICT)
167 #define RESTRICT restrict
168 #elif defined(HAVE___RESTRICT)
169 #define RESTRICT __restrict
170 #else
171 #define RESTRICT
172 #endif
175 #ifdef _WIN32
177 #include <windows.h>
179 typedef DWORD pthread_key_t;
180 int pthread_key_create(pthread_key_t *key, void (*callback)(void*));
181 int pthread_key_delete(pthread_key_t key);
182 void *pthread_getspecific(pthread_key_t key);
183 int pthread_setspecific(pthread_key_t key, void *val);
185 #define HAVE_DYNLOAD 1
186 void *LoadLib(const char *name);
187 void CloseLib(void *handle);
188 void *GetSymbol(void *handle, const char *name);
190 typedef LONG pthread_once_t;
191 #define PTHREAD_ONCE_INIT 0
192 void pthread_once(pthread_once_t *once, void (*callback)(void));
194 static __inline int sched_yield(void)
195 { SwitchToThread(); return 0; }
197 #else
199 #include <unistd.h>
200 #include <assert.h>
201 #include <pthread.h>
202 #ifdef HAVE_PTHREAD_NP_H
203 #include <pthread_np.h>
204 #endif
205 #include <sys/time.h>
206 #include <time.h>
207 #include <errno.h>
209 #define IsBadWritePtr(a,b) ((a) == NULL && (b) != 0)
211 typedef pthread_mutex_t CRITICAL_SECTION;
212 void InitializeCriticalSection(CRITICAL_SECTION *cs);
213 void DeleteCriticalSection(CRITICAL_SECTION *cs);
214 void EnterCriticalSection(CRITICAL_SECTION *cs);
215 void LeaveCriticalSection(CRITICAL_SECTION *cs);
217 ALuint timeGetTime(void);
218 void Sleep(ALuint t);
220 #if defined(HAVE_DLFCN_H)
221 #define HAVE_DYNLOAD 1
222 void *LoadLib(const char *name);
223 void CloseLib(void *handle);
224 void *GetSymbol(void *handle, const char *name);
225 #endif
227 #endif
229 #if defined(__GNUC__) && (__GNUC__ > 4 || (__GNUC__ == 4 && __GNUC_MINOR__ >= 1))
230 typedef ALuint RefCount;
231 static __inline RefCount IncrementRef(volatile RefCount *ptr)
232 { return __sync_add_and_fetch(ptr, 1); }
233 static __inline RefCount DecrementRef(volatile RefCount *ptr)
234 { return __sync_sub_and_fetch(ptr, 1); }
236 static __inline int ExchangeInt(volatile int *ptr, int newval)
238 return __sync_lock_test_and_set(ptr, newval);
240 static __inline void *ExchangePtr(void *volatile*ptr, void *newval)
242 return __sync_lock_test_and_set(ptr, newval);
244 static __inline ALboolean CompExchangeInt(volatile int *ptr, int oldval, int newval)
246 return __sync_bool_compare_and_swap(ptr, oldval, newval);
248 static __inline ALboolean CompExchangePtr(void *volatile*ptr, void *oldval, void *newval)
250 return __sync_bool_compare_and_swap(ptr, oldval, newval);
253 #elif defined(__GNUC__) && (defined(__i386__) || defined(__x86_64__))
255 static __inline int xaddl(volatile int *dest, int incr)
257 int ret;
258 __asm__ __volatile__("lock; xaddl %0,(%1)"
259 : "=r" (ret)
260 : "r" (dest), "0" (incr)
261 : "memory");
262 return ret;
265 typedef int RefCount;
266 static __inline RefCount IncrementRef(volatile RefCount *ptr)
267 { return xaddl(ptr, 1)+1; }
268 static __inline RefCount DecrementRef(volatile RefCount *ptr)
269 { return xaddl(ptr, -1)-1; }
271 static __inline int ExchangeInt(volatile int *dest, int newval)
273 int ret;
274 __asm__ __volatile__("lock; xchgl %0,(%1)"
275 : "=r" (ret)
276 : "r" (dest), "0" (newval)
277 : "memory");
278 return ret;
281 static __inline ALboolean CompExchangeInt(volatile int *dest, int oldval, int newval)
283 int ret;
284 __asm__ __volatile__("lock; cmpxchgl %2,(%1)"
285 : "=a" (ret)
286 : "r" (dest), "r" (newval), "0" (oldval)
287 : "memory");
288 return ret == oldval;
291 static __inline void *ExchangePtr(void *volatile*dest, void *newval)
293 void *ret;
294 __asm__ __volatile__(
295 #ifdef __i386__
296 "lock; xchgl %0,(%1)"
297 #else
298 "lock; xchgq %0,(%1)"
299 #endif
300 : "=r" (ret)
301 : "r" (dest), "0" (newval)
302 : "memory"
304 return ret;
307 static __inline ALboolean CompExchangePtr(void *volatile*dest, void *oldval, void *newval)
309 void *ret;
310 __asm__ __volatile__(
311 #ifdef __i386__
312 "lock; cmpxchgl %2,(%1)"
313 #else
314 "lock; cmpxchgq %2,(%1)"
315 #endif
316 : "=a" (ret)
317 : "r" (dest), "r" (newval), "0" (oldval)
318 : "memory"
320 return ret == oldval;
323 #elif defined(_WIN32)
325 typedef LONG RefCount;
326 static __inline RefCount IncrementRef(volatile RefCount *ptr)
327 { return InterlockedIncrement(ptr); }
328 static __inline RefCount DecrementRef(volatile RefCount *ptr)
329 { return InterlockedDecrement(ptr); }
331 extern ALbyte LONG_size_does_not_match_int[(sizeof(LONG)==sizeof(int))?1:-1];
333 static __inline int ExchangeInt(volatile int *ptr, int newval)
335 union {
336 volatile int *i;
337 volatile LONG *l;
338 } u = { ptr };
339 return InterlockedExchange(u.l, newval);
341 static __inline void *ExchangePtr(void *volatile*ptr, void *newval)
343 return InterlockedExchangePointer(ptr, newval);
345 static __inline ALboolean CompExchangeInt(volatile int *ptr, int oldval, int newval)
347 union {
348 volatile int *i;
349 volatile LONG *l;
350 } u = { ptr };
351 return InterlockedCompareExchange(u.l, newval, oldval) == oldval;
353 static __inline ALboolean CompExchangePtr(void *volatile*ptr, void *oldval, void *newval)
355 return InterlockedCompareExchangePointer(ptr, newval, oldval) == oldval;
358 #elif defined(__APPLE__)
360 #include <libkern/OSAtomic.h>
362 typedef int32_t RefCount;
363 static __inline RefCount IncrementRef(volatile RefCount *ptr)
364 { return OSAtomicIncrement32Barrier(ptr); }
365 static __inline RefCount DecrementRef(volatile RefCount *ptr)
366 { return OSAtomicDecrement32Barrier(ptr); }
368 static __inline int ExchangeInt(volatile int *ptr, int newval)
370 /* Really? No regular old atomic swap? */
371 int oldval;
372 do {
373 oldval = *ptr;
374 } while(!OSAtomicCompareAndSwap32Barrier(oldval, newval, ptr));
375 return oldval;
377 static __inline void *ExchangePtr(void *volatile*ptr, void *newval)
379 void *oldval;
380 do {
381 oldval = *ptr;
382 } while(!OSAtomicCompareAndSwapPtrBarrier(oldval, newval, ptr));
383 return oldval;
385 static __inline ALboolean CompExchangeInt(volatile int *ptr, int oldval, int newval)
387 return OSAtomicCompareAndSwap32Barrier(oldval, newval, ptr);
389 static __inline ALboolean CompExchangePtr(void *volatile*ptr, void *oldval, void *newval)
391 return OSAtomicCompareAndSwapPtrBarrier(oldval, newval, ptr);
394 #else
395 #error "No atomic functions available on this platform!"
396 typedef ALuint RefCount;
397 #endif
400 typedef struct {
401 volatile RefCount read_count;
402 volatile RefCount write_count;
403 volatile ALenum read_lock;
404 volatile ALenum read_entry_lock;
405 volatile ALenum write_lock;
406 } RWLock;
408 void RWLockInit(RWLock *lock);
409 void ReadLock(RWLock *lock);
410 void ReadUnlock(RWLock *lock);
411 void WriteLock(RWLock *lock);
412 void WriteUnlock(RWLock *lock);
415 typedef struct UIntMap {
416 struct {
417 ALuint key;
418 ALvoid *value;
419 } *array;
420 ALsizei size;
421 ALsizei maxsize;
422 ALsizei limit;
423 RWLock lock;
424 } UIntMap;
425 extern UIntMap TlsDestructor;
427 void InitUIntMap(UIntMap *map, ALsizei limit);
428 void ResetUIntMap(UIntMap *map);
429 ALenum InsertUIntMapEntry(UIntMap *map, ALuint key, ALvoid *value);
430 ALvoid *RemoveUIntMapKey(UIntMap *map, ALuint key);
431 ALvoid *LookupUIntMapKey(UIntMap *map, ALuint key);
433 static __inline void LockUIntMapRead(UIntMap *map)
434 { ReadLock(&map->lock); }
435 static __inline void UnlockUIntMapRead(UIntMap *map)
436 { ReadUnlock(&map->lock); }
437 static __inline void LockUIntMapWrite(UIntMap *map)
438 { WriteLock(&map->lock); }
439 static __inline void UnlockUIntMapWrite(UIntMap *map)
440 { WriteUnlock(&map->lock); }
442 #include "alListener.h"
443 #include "alu.h"
445 #ifdef __cplusplus
446 extern "C" {
447 #endif
450 #define DEFAULT_OUTPUT_RATE (44100)
452 #define SPEEDOFSOUNDMETRESPERSEC (343.3f)
453 #define AIRABSORBGAINHF (0.99426f) /* -0.05dB */
455 #define LOWPASSFREQREF (5000)
458 struct Hrtf;
461 // Find the next power-of-2 for non-power-of-2 numbers.
462 static __inline ALuint NextPowerOf2(ALuint value)
464 ALuint powerOf2 = 1;
466 if(value)
468 value--;
469 while(value)
471 value >>= 1;
472 powerOf2 <<= 1;
475 return powerOf2;
478 /* Fast float-to-int conversion. Assumes the FPU is already in round-to-zero
479 * mode. */
480 static __inline ALint fastf2i(ALfloat f)
482 ALint i;
483 #if defined(_MSC_VER) && !defined(_WIN64)
484 __asm fld f
485 __asm fistp i
486 #elif defined(__GNUC__)
487 __asm__ __volatile__("flds %1\n\t"
488 "fistpl %0\n\t"
489 : "=m" (i)
490 : "m" (f));
491 #else
492 i = (ALint)f;
493 #endif
494 return i;
497 /* Fast float-to-uint conversion. Assumes the FPU is already in round-to-zero
498 * mode. */
499 static __inline ALuint fastf2u(ALfloat f)
500 { return fastf2i(f); }
503 enum DevProbe {
504 DEVICE_PROBE,
505 ALL_DEVICE_PROBE,
506 CAPTURE_DEVICE_PROBE
509 typedef struct {
510 ALCenum (*OpenPlayback)(ALCdevice*, const ALCchar*);
511 void (*ClosePlayback)(ALCdevice*);
512 ALCboolean (*ResetPlayback)(ALCdevice*);
513 void (*StopPlayback)(ALCdevice*);
515 ALCenum (*OpenCapture)(ALCdevice*, const ALCchar*);
516 void (*CloseCapture)(ALCdevice*);
517 void (*StartCapture)(ALCdevice*);
518 void (*StopCapture)(ALCdevice*);
519 ALCenum (*CaptureSamples)(ALCdevice*, void*, ALCuint);
520 ALCuint (*AvailableSamples)(ALCdevice*);
521 } BackendFuncs;
523 struct BackendInfo {
524 const char *name;
525 ALCboolean (*Init)(BackendFuncs*);
526 void (*Deinit)(void);
527 void (*Probe)(enum DevProbe);
528 BackendFuncs Funcs;
531 ALCboolean alc_alsa_init(BackendFuncs *func_list);
532 void alc_alsa_deinit(void);
533 void alc_alsa_probe(enum DevProbe type);
534 ALCboolean alc_oss_init(BackendFuncs *func_list);
535 void alc_oss_deinit(void);
536 void alc_oss_probe(enum DevProbe type);
537 ALCboolean alc_solaris_init(BackendFuncs *func_list);
538 void alc_solaris_deinit(void);
539 void alc_solaris_probe(enum DevProbe type);
540 ALCboolean alc_sndio_init(BackendFuncs *func_list);
541 void alc_sndio_deinit(void);
542 void alc_sndio_probe(enum DevProbe type);
543 ALCboolean alcMMDevApiInit(BackendFuncs *func_list);
544 void alcMMDevApiDeinit(void);
545 void alcMMDevApiProbe(enum DevProbe type);
546 ALCboolean alcDSoundInit(BackendFuncs *func_list);
547 void alcDSoundDeinit(void);
548 void alcDSoundProbe(enum DevProbe type);
549 ALCboolean alcWinMMInit(BackendFuncs *FuncList);
550 void alcWinMMDeinit(void);
551 void alcWinMMProbe(enum DevProbe type);
552 ALCboolean alc_pa_init(BackendFuncs *func_list);
553 void alc_pa_deinit(void);
554 void alc_pa_probe(enum DevProbe type);
555 ALCboolean alc_wave_init(BackendFuncs *func_list);
556 void alc_wave_deinit(void);
557 void alc_wave_probe(enum DevProbe type);
558 ALCboolean alc_pulse_init(BackendFuncs *func_list);
559 void alc_pulse_deinit(void);
560 void alc_pulse_probe(enum DevProbe type);
561 ALCboolean alc_ca_init(BackendFuncs *func_list);
562 void alc_ca_deinit(void);
563 void alc_ca_probe(enum DevProbe type);
564 ALCboolean alc_opensl_init(BackendFuncs *func_list);
565 void alc_opensl_deinit(void);
566 void alc_opensl_probe(enum DevProbe type);
567 ALCboolean alc_null_init(BackendFuncs *func_list);
568 void alc_null_deinit(void);
569 void alc_null_probe(enum DevProbe type);
570 ALCboolean alc_loopback_init(BackendFuncs *func_list);
571 void alc_loopback_deinit(void);
572 void alc_loopback_probe(enum DevProbe type);
575 /* Device formats */
576 enum DevFmtType {
577 DevFmtByte = ALC_BYTE_SOFT,
578 DevFmtUByte = ALC_UNSIGNED_BYTE_SOFT,
579 DevFmtShort = ALC_SHORT_SOFT,
580 DevFmtUShort = ALC_UNSIGNED_SHORT_SOFT,
581 DevFmtFloat = ALC_FLOAT_SOFT
583 enum DevFmtChannels {
584 DevFmtMono = ALC_MONO_SOFT,
585 DevFmtStereo = ALC_STEREO_SOFT,
586 DevFmtQuad = ALC_QUAD_SOFT,
587 DevFmtX51 = ALC_5POINT1_SOFT,
588 DevFmtX61 = ALC_6POINT1_SOFT,
589 DevFmtX71 = ALC_7POINT1_SOFT,
591 /* Similar to 5.1, except using the side channels instead of back */
592 DevFmtX51Side = 0x80000000 | ALC_5POINT1_SOFT
595 ALuint BytesFromDevFmt(enum DevFmtType type);
596 ALuint ChannelsFromDevFmt(enum DevFmtChannels chans);
597 static __inline ALuint FrameSizeFromDevFmt(enum DevFmtChannels chans,
598 enum DevFmtType type)
600 return ChannelsFromDevFmt(chans) * BytesFromDevFmt(type);
604 extern const struct EffectList {
605 const char *name;
606 int type;
607 const char *ename;
608 ALenum val;
609 } EffectList[];
612 struct ALCdevice_struct
614 volatile RefCount ref;
616 ALCboolean Connected;
617 ALboolean IsCaptureDevice;
618 ALboolean IsLoopbackDevice;
620 CRITICAL_SECTION Mutex;
622 ALuint Frequency;
623 ALuint UpdateSize;
624 ALuint NumUpdates;
625 enum DevFmtChannels FmtChans;
626 enum DevFmtType FmtType;
628 ALCchar *szDeviceName;
630 volatile ALCenum LastError;
632 // Maximum number of sources that can be created
633 ALuint MaxNoOfSources;
634 // Maximum number of slots that can be created
635 ALuint AuxiliaryEffectSlotMax;
637 ALCuint NumMonoSources;
638 ALCuint NumStereoSources;
639 ALuint NumAuxSends;
641 // Map of Buffers for this device
642 UIntMap BufferMap;
644 // Map of Effects for this device
645 UIntMap EffectMap;
647 // Map of Filters for this device
648 UIntMap FilterMap;
650 /* HRTF filter tables */
651 const struct Hrtf *Hrtf;
653 // Stereo-to-binaural filter
654 struct bs2b *Bs2b;
655 ALCint Bs2bLevel;
657 // Device flags
658 ALuint Flags;
660 // Dry path buffer mix
661 ALfloat DryBuffer[BUFFERSIZE][MAXCHANNELS];
663 enum Channel DevChannels[MAXCHANNELS];
665 enum Channel Speaker2Chan[MAXCHANNELS];
666 ALfloat PanningLUT[LUT_NUM][MAXCHANNELS];
667 ALuint NumChan;
669 ALfloat ClickRemoval[MAXCHANNELS];
670 ALfloat PendingClicks[MAXCHANNELS];
672 // Contexts created on this device
673 ALCcontext *volatile ContextList;
675 BackendFuncs *Funcs;
676 void *ExtraData; // For the backend's use
678 ALCdevice *volatile next;
681 #define ALCdevice_OpenPlayback(a,b) ((a)->Funcs->OpenPlayback((a), (b)))
682 #define ALCdevice_ClosePlayback(a) ((a)->Funcs->ClosePlayback((a)))
683 #define ALCdevice_ResetPlayback(a) ((a)->Funcs->ResetPlayback((a)))
684 #define ALCdevice_StopPlayback(a) ((a)->Funcs->StopPlayback((a)))
685 #define ALCdevice_OpenCapture(a,b) ((a)->Funcs->OpenCapture((a), (b)))
686 #define ALCdevice_CloseCapture(a) ((a)->Funcs->CloseCapture((a)))
687 #define ALCdevice_StartCapture(a) ((a)->Funcs->StartCapture((a)))
688 #define ALCdevice_StopCapture(a) ((a)->Funcs->StopCapture((a)))
689 #define ALCdevice_CaptureSamples(a,b,c) ((a)->Funcs->CaptureSamples((a), (b), (c)))
690 #define ALCdevice_AvailableSamples(a) ((a)->Funcs->AvailableSamples((a)))
692 // Duplicate stereo sources on the side/rear channels
693 #define DEVICE_DUPLICATE_STEREO (1<<0)
694 // Frequency was requested by the app or config file
695 #define DEVICE_FREQUENCY_REQUEST (1<<1)
696 // Channel configuration was requested by the config file
697 #define DEVICE_CHANNELS_REQUEST (1<<2)
699 // Specifies if the device is currently running
700 #define DEVICE_RUNNING (1<<31)
702 #define LookupBuffer(m, k) ((struct ALbuffer*)LookupUIntMapKey(&(m)->BufferMap, (k)))
703 #define LookupEffect(m, k) ((struct ALeffect*)LookupUIntMapKey(&(m)->EffectMap, (k)))
704 #define LookupFilter(m, k) ((struct ALfilter*)LookupUIntMapKey(&(m)->FilterMap, (k)))
705 #define RemoveBuffer(m, k) ((struct ALbuffer*)RemoveUIntMapKey(&(m)->BufferMap, (k)))
706 #define RemoveEffect(m, k) ((struct ALeffect*)RemoveUIntMapKey(&(m)->EffectMap, (k)))
707 #define RemoveFilter(m, k) ((struct ALfilter*)RemoveUIntMapKey(&(m)->FilterMap, (k)))
710 struct ALCcontext_struct
712 volatile RefCount ref;
714 ALlistener Listener;
716 UIntMap SourceMap;
717 UIntMap EffectSlotMap;
719 ALenum LastError;
721 volatile ALenum UpdateSources;
723 volatile enum DistanceModel DistanceModel;
724 volatile ALboolean SourceDistanceModel;
726 volatile ALfloat DopplerFactor;
727 volatile ALfloat DopplerVelocity;
728 volatile ALfloat flSpeedOfSound;
729 volatile ALenum DeferUpdates;
731 struct ALsource **ActiveSources;
732 ALsizei ActiveSourceCount;
733 ALsizei MaxActiveSources;
735 struct ALeffectslot **ActiveEffectSlots;
736 ALsizei ActiveEffectSlotCount;
737 ALsizei MaxActiveEffectSlots;
739 ALCdevice *Device;
740 const ALCchar *ExtensionList;
742 ALCcontext *volatile next;
745 #define LookupSource(m, k) ((struct ALsource*)LookupUIntMapKey(&(m)->SourceMap, (k)))
746 #define LookupEffectSlot(m, k) ((struct ALeffectslot*)LookupUIntMapKey(&(m)->EffectSlotMap, (k)))
747 #define RemoveSource(m, k) ((struct ALsource*)RemoveUIntMapKey(&(m)->SourceMap, (k)))
748 #define RemoveEffectSlot(m, k) ((struct ALeffectslot*)RemoveUIntMapKey(&(m)->EffectSlotMap, (k)))
750 ALCcontext *GetContextRef(void);
752 void ALCcontext_IncRef(ALCcontext *context);
753 void ALCcontext_DecRef(ALCcontext *context);
755 void AppendDeviceList(const ALCchar *name);
756 void AppendAllDeviceList(const ALCchar *name);
757 void AppendCaptureDeviceList(const ALCchar *name);
759 ALCvoid LockDevice(ALCdevice *device);
760 ALCvoid UnlockDevice(ALCdevice *device);
761 ALCvoid LockContext(ALCcontext *context);
762 ALCvoid UnlockContext(ALCcontext *context);
764 ALvoid *StartThread(ALuint (*func)(ALvoid*), ALvoid *ptr);
765 ALuint StopThread(ALvoid *thread);
767 typedef struct RingBuffer RingBuffer;
768 RingBuffer *CreateRingBuffer(ALsizei frame_size, ALsizei length);
769 void DestroyRingBuffer(RingBuffer *ring);
770 ALsizei RingBufferSize(RingBuffer *ring);
771 void WriteRingBuffer(RingBuffer *ring, const ALubyte *data, ALsizei len);
772 void ReadRingBuffer(RingBuffer *ring, ALubyte *data, ALsizei len);
774 void ReadALConfig(void);
775 void FreeALConfig(void);
776 int ConfigValueExists(const char *blockName, const char *keyName);
777 const char *GetConfigValue(const char *blockName, const char *keyName, const char *def);
778 int GetConfigValueBool(const char *blockName, const char *keyName, int def);
779 int ConfigValueStr(const char *blockName, const char *keyName, const char **ret);
780 int ConfigValueInt(const char *blockName, const char *keyName, int *ret);
781 int ConfigValueUInt(const char *blockName, const char *keyName, unsigned int *ret);
782 int ConfigValueFloat(const char *blockName, const char *keyName, float *ret);
784 void SetRTPriority(void);
786 void SetDefaultChannelOrder(ALCdevice *device);
787 void SetDefaultWFXChannelOrder(ALCdevice *device);
789 const ALCchar *DevFmtTypeString(enum DevFmtType type);
790 const ALCchar *DevFmtChannelsString(enum DevFmtChannels chans);
792 #define HRIR_BITS (5)
793 #define HRIR_LENGTH (1<<HRIR_BITS)
794 #define HRIR_MASK (HRIR_LENGTH-1)
795 void InitHrtf(void);
796 void FreeHrtf(void);
797 const struct Hrtf *GetHrtf(ALCdevice *device);
798 ALfloat CalcHrtfDelta(ALfloat oldGain, ALfloat newGain, const ALfloat olddir[3], const ALfloat newdir[3]);
799 void GetLerpedHrtfCoeffs(const struct Hrtf *Hrtf, ALfloat elevation, ALfloat azimuth, ALfloat gain, ALfloat (*coeffs)[2], ALuint *delays);
800 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);
802 void al_print(const char *func, const char *fmt, ...) PRINTF_STYLE(2,3);
803 #define AL_PRINT(...) al_print(__FUNCTION__, __VA_ARGS__)
805 extern FILE *LogFile;
806 enum LogLevel {
807 NoLog,
808 LogError,
809 LogWarning,
810 LogTrace,
811 LogRef
813 extern enum LogLevel LogLevel;
815 #define TRACEREF(...) do { \
816 if(LogLevel >= LogRef) \
817 AL_PRINT(__VA_ARGS__); \
818 } while(0)
820 #define TRACE(...) do { \
821 if(LogLevel >= LogTrace) \
822 AL_PRINT(__VA_ARGS__); \
823 } while(0)
825 #define WARN(...) do { \
826 if(LogLevel >= LogWarning) \
827 AL_PRINT(__VA_ARGS__); \
828 } while(0)
830 #define ERR(...) do { \
831 if(LogLevel >= LogError) \
832 AL_PRINT(__VA_ARGS__); \
833 } while(0)
836 extern ALint RTPrioLevel;
838 #ifdef __cplusplus
840 #endif
842 #endif