18 /* Define int64_t and uint64_t types */
19 #if defined(__STDC_VERSION__) && __STDC_VERSION__ >= 199901L
21 #elif defined(_WIN32) && defined(__GNUC__)
24 typedef __int64
int64_t;
25 typedef unsigned __int64
uint64_t;
27 /* Fallback if nothing above works */
31 #ifndef AL_SOFT_deferred_updates
32 #define AL_SOFT_deferred_updates 1
33 #define AL_DEFERRED_UPDATES_SOFT 0xC002
34 typedef ALvoid (AL_APIENTRY
*LPALDEFERUPDATESSOFT
)(void);
35 typedef ALvoid (AL_APIENTRY
*LPALPROCESSUPDATESSOFT
)(void);
36 #ifdef AL_ALEXT_PROTOTYPES
37 AL_API ALvoid AL_APIENTRY
alDeferUpdatesSOFT(void);
38 AL_API ALvoid AL_APIENTRY
alProcessUpdatesSOFT(void);
42 #ifndef AL_SOFT_source_latency
43 #define AL_SOFT_source_latency 1
44 #define AL_SAMPLE_OFFSET_LATENCY_SOFT 0x1200
45 #define AL_SEC_OFFSET_LATENCY_SOFT 0x1201
46 typedef int64_t ALint64SOFT
;
47 typedef uint64_t ALuint64SOFT
;
48 typedef void (AL_APIENTRY
*LPALGETSOURCEDSOFT
)(ALuint
,ALenum
,ALdouble
*);
49 typedef void (AL_APIENTRY
*LPALGETSOURCE3DSOFT
)(ALuint
,ALenum
,ALdouble
*,ALdouble
*,ALdouble
*);
50 typedef void (AL_APIENTRY
*LPALGETSOURCEDVSOFT
)(ALuint
,ALenum
,ALdouble
*);
51 typedef void (AL_APIENTRY
*LPALGETSOURCEI64SOFT
)(ALuint
,ALenum
,ALint64SOFT
*);
52 typedef void (AL_APIENTRY
*LPALGETSOURCE3I64SOFT
)(ALuint
,ALenum
,ALint64SOFT
*,ALint64SOFT
*,ALint64SOFT
*);
53 typedef void (AL_APIENTRY
*LPALGETSOURCEI64VSOFT
)(ALuint
,ALenum
,ALint64SOFT
*);
54 #ifdef AL_ALEXT_PROTOTYPES
55 AL_API
void AL_APIENTRY
alGetSourcedSOFT(ALuint source
, ALenum param
, ALdouble
*value
);
56 AL_API
void AL_APIENTRY
alGetSource3dSOFT(ALuint source
, ALenum param
, ALdouble
*value1
, ALdouble
*value2
, ALdouble
*value3
);
57 AL_API
void AL_APIENTRY
alGetSourcedvSOFT(ALuint source
, ALenum param
, ALdouble
*values
);
58 AL_API
void AL_APIENTRY
alGetSourcei64SOFT(ALuint source
, ALenum param
, ALint64SOFT
*value
);
59 AL_API
void AL_APIENTRY
alGetSource3i64SOFT(ALuint source
, ALenum param
, ALint64SOFT
*value1
, ALint64SOFT
*value2
, ALint64SOFT
*value3
);
60 AL_API
void AL_APIENTRY
alGetSourcei64vSOFT(ALuint source
, ALenum param
, ALint64SOFT
*values
);
65 #if defined(HAVE_STDINT_H)
67 typedef int64_t ALint64
;
68 typedef uint64_t ALuint64
;
69 #elif defined(HAVE___INT64)
70 typedef __int64 ALint64
;
71 typedef unsigned __int64 ALuint64
;
72 #elif (SIZEOF_LONG == 8)
74 typedef unsigned long ALuint64
;
75 #elif (SIZEOF_LONG_LONG == 8)
76 typedef long long ALint64
;
77 typedef unsigned long long ALuint64
;
80 typedef ptrdiff_t ALintptrEXT
;
81 typedef ptrdiff_t ALsizeiptrEXT
;
83 #define MAKEU64(x,y) (((ALuint64)(x)<<32)|(ALuint64)(y))
85 #ifdef HAVE_GCC_FORMAT
86 #define PRINTF_STYLE(x, y) __attribute__((format(printf, (x), (y))))
88 #define PRINTF_STYLE(x, y)
91 #if defined(HAVE_RESTRICT)
92 #define RESTRICT restrict
93 #elif defined(HAVE___RESTRICT)
94 #define RESTRICT __restrict
102 ALubyte b
[sizeof(ALuint
)];
103 } EndianTest
= { 1 };
104 #define IS_LITTLE_ENDIAN (EndianTest.b[0] == 1)
106 #define COUNTOF(x) (sizeof((x))/sizeof((x)[0]))
110 #define WIN32_LEAN_AND_MEAN
113 typedef DWORD pthread_key_t
;
114 int pthread_key_create(pthread_key_t
*key
, void (*callback
)(void*));
115 int pthread_key_delete(pthread_key_t key
);
116 void *pthread_getspecific(pthread_key_t key
);
117 int pthread_setspecific(pthread_key_t key
, void *val
);
119 #define HAVE_DYNLOAD 1
120 void *LoadLib(const char *name
);
121 void CloseLib(void *handle
);
122 void *GetSymbol(void *handle
, const char *name
);
124 WCHAR
*strdupW(const WCHAR
*str
);
126 typedef LONG pthread_once_t
;
127 #define PTHREAD_ONCE_INIT 0
128 void pthread_once(pthread_once_t
*once
, void (*callback
)(void));
130 static __inline
int sched_yield(void)
131 { SwitchToThread(); return 0; }
138 #include <sys/time.h>
142 #define IsBadWritePtr(a,b) ((a) == NULL && (b) != 0)
144 typedef pthread_mutex_t CRITICAL_SECTION
;
145 void InitializeCriticalSection(CRITICAL_SECTION
*cs
);
146 void DeleteCriticalSection(CRITICAL_SECTION
*cs
);
147 void EnterCriticalSection(CRITICAL_SECTION
*cs
);
148 void LeaveCriticalSection(CRITICAL_SECTION
*cs
);
150 ALuint
timeGetTime(void);
151 void Sleep(ALuint t
);
153 #if defined(HAVE_DLFCN_H)
154 #define HAVE_DYNLOAD 1
155 void *LoadLib(const char *name
);
156 void CloseLib(void *handle
);
157 void *GetSymbol(void *handle
, const char *name
);
162 typedef void *volatile XchgPtr
;
164 #if defined(__GNUC__) && (__GNUC__ > 4 || (__GNUC__ == 4 && __GNUC_MINOR__ >= 1))
165 typedef ALuint RefCount
;
166 static __inline RefCount
IncrementRef(volatile RefCount
*ptr
)
167 { return __sync_add_and_fetch(ptr
, 1); }
168 static __inline RefCount
DecrementRef(volatile RefCount
*ptr
)
169 { return __sync_sub_and_fetch(ptr
, 1); }
171 static __inline
int ExchangeInt(volatile int *ptr
, int newval
)
173 return __sync_lock_test_and_set(ptr
, newval
);
175 static __inline
void *ExchangePtr(XchgPtr
*ptr
, void *newval
)
177 return __sync_lock_test_and_set(ptr
, newval
);
179 static __inline ALboolean
CompExchangeInt(volatile int *ptr
, int oldval
, int newval
)
181 return __sync_bool_compare_and_swap(ptr
, oldval
, newval
);
183 static __inline ALboolean
CompExchangePtr(XchgPtr
*ptr
, void *oldval
, void *newval
)
185 return __sync_bool_compare_and_swap(ptr
, oldval
, newval
);
188 #elif defined(__GNUC__) && (defined(__i386__) || defined(__x86_64__))
190 static __inline
int xaddl(volatile int *dest
, int incr
)
193 __asm__
__volatile__("lock; xaddl %0,(%1)"
195 : "r" (dest
), "0" (incr
)
200 typedef int RefCount
;
201 static __inline RefCount
IncrementRef(volatile RefCount
*ptr
)
202 { return xaddl(ptr
, 1)+1; }
203 static __inline RefCount
DecrementRef(volatile RefCount
*ptr
)
204 { return xaddl(ptr
, -1)-1; }
206 static __inline
int ExchangeInt(volatile int *dest
, int newval
)
209 __asm__
__volatile__("lock; xchgl %0,(%1)"
211 : "r" (dest
), "0" (newval
)
216 static __inline ALboolean
CompExchangeInt(volatile int *dest
, int oldval
, int newval
)
219 __asm__
__volatile__("lock; cmpxchgl %2,(%1)"
221 : "r" (dest
), "r" (newval
), "0" (oldval
)
223 return ret
== oldval
;
226 static __inline
void *ExchangePtr(XchgPtr
*dest
, void *newval
)
229 __asm__
__volatile__(
231 "lock; xchgl %0,(%1)"
233 "lock; xchgq %0,(%1)"
236 : "r" (dest
), "0" (newval
)
242 static __inline ALboolean
CompExchangePtr(XchgPtr
*dest
, void *oldval
, void *newval
)
245 __asm__
__volatile__(
247 "lock; cmpxchgl %2,(%1)"
249 "lock; cmpxchgq %2,(%1)"
252 : "r" (dest
), "r" (newval
), "0" (oldval
)
255 return ret
== oldval
;
258 #elif defined(_WIN32)
260 typedef LONG RefCount
;
261 static __inline RefCount
IncrementRef(volatile RefCount
*ptr
)
262 { return InterlockedIncrement(ptr
); }
263 static __inline RefCount
DecrementRef(volatile RefCount
*ptr
)
264 { return InterlockedDecrement(ptr
); }
266 extern ALbyte LONG_size_does_not_match_int
[(sizeof(LONG
)==sizeof(int))?1:-1];
268 static __inline
int ExchangeInt(volatile int *ptr
, int newval
)
274 return InterlockedExchange(u
.l
, newval
);
276 static __inline
void *ExchangePtr(XchgPtr
*ptr
, void *newval
)
278 return InterlockedExchangePointer(ptr
, newval
);
280 static __inline ALboolean
CompExchangeInt(volatile int *ptr
, int oldval
, int newval
)
286 return InterlockedCompareExchange(u
.l
, newval
, oldval
) == oldval
;
288 static __inline ALboolean
CompExchangePtr(XchgPtr
*ptr
, void *oldval
, void *newval
)
290 return InterlockedCompareExchangePointer(ptr
, newval
, oldval
) == oldval
;
293 #elif defined(__APPLE__)
295 #include <libkern/OSAtomic.h>
297 typedef int32_t RefCount
;
298 static __inline RefCount
IncrementRef(volatile RefCount
*ptr
)
299 { return OSAtomicIncrement32Barrier(ptr
); }
300 static __inline RefCount
DecrementRef(volatile RefCount
*ptr
)
301 { return OSAtomicDecrement32Barrier(ptr
); }
303 static __inline
int ExchangeInt(volatile int *ptr
, int newval
)
305 /* Really? No regular old atomic swap? */
309 } while(!OSAtomicCompareAndSwap32Barrier(oldval
, newval
, ptr
));
312 static __inline
void *ExchangePtr(XchgPtr
*ptr
, void *newval
)
317 } while(!OSAtomicCompareAndSwapPtrBarrier(oldval
, newval
, ptr
));
320 static __inline ALboolean
CompExchangeInt(volatile int *ptr
, int oldval
, int newval
)
322 return OSAtomicCompareAndSwap32Barrier(oldval
, newval
, ptr
);
324 static __inline ALboolean
CompExchangePtr(XchgPtr
*ptr
, void *oldval
, void *newval
)
326 return OSAtomicCompareAndSwapPtrBarrier(oldval
, newval
, ptr
);
330 #error "No atomic functions available on this platform!"
331 typedef ALuint RefCount
;
336 volatile RefCount read_count
;
337 volatile RefCount write_count
;
338 volatile ALenum read_lock
;
339 volatile ALenum read_entry_lock
;
340 volatile ALenum write_lock
;
343 void RWLockInit(RWLock
*lock
);
344 void ReadLock(RWLock
*lock
);
345 void ReadUnlock(RWLock
*lock
);
346 void WriteLock(RWLock
*lock
);
347 void WriteUnlock(RWLock
*lock
);
350 typedef struct UIntMap
{
360 extern UIntMap TlsDestructor
;
362 void InitUIntMap(UIntMap
*map
, ALsizei limit
);
363 void ResetUIntMap(UIntMap
*map
);
364 ALenum
InsertUIntMapEntry(UIntMap
*map
, ALuint key
, ALvoid
*value
);
365 ALvoid
*RemoveUIntMapKey(UIntMap
*map
, ALuint key
);
366 ALvoid
*LookupUIntMapKey(UIntMap
*map
, ALuint key
);
368 static __inline
void LockUIntMapRead(UIntMap
*map
)
369 { ReadLock(&map
->lock
); }
370 static __inline
void UnlockUIntMapRead(UIntMap
*map
)
371 { ReadUnlock(&map
->lock
); }
372 static __inline
void LockUIntMapWrite(UIntMap
*map
)
373 { WriteLock(&map
->lock
); }
374 static __inline
void UnlockUIntMapWrite(UIntMap
*map
)
375 { WriteUnlock(&map
->lock
); }
377 #include "alListener.h"
386 #define DEFAULT_OUTPUT_RATE (44100)
387 #define MIN_OUTPUT_RATE (8000)
390 // Find the next power-of-2 for non-power-of-2 numbers.
391 static __inline ALuint
NextPowerOf2(ALuint value
)
407 /* Fast float-to-int conversion. Assumes the FPU is already in round-to-zero
409 static __inline ALint
fastf2i(ALfloat f
)
413 #elif defined(_MSC_VER) && defined(_M_IX86)
422 /* Fast float-to-uint conversion. Assumes the FPU is already in round-to-zero
424 static __inline ALuint
fastf2u(ALfloat f
)
425 { return fastf2i(f
); }
434 ALCenum (*OpenPlayback
)(ALCdevice
*, const ALCchar
*);
435 void (*ClosePlayback
)(ALCdevice
*);
436 ALCboolean (*ResetPlayback
)(ALCdevice
*);
437 ALCboolean (*StartPlayback
)(ALCdevice
*);
438 void (*StopPlayback
)(ALCdevice
*);
440 ALCenum (*OpenCapture
)(ALCdevice
*, const ALCchar
*);
441 void (*CloseCapture
)(ALCdevice
*);
442 void (*StartCapture
)(ALCdevice
*);
443 void (*StopCapture
)(ALCdevice
*);
444 ALCenum (*CaptureSamples
)(ALCdevice
*, void*, ALCuint
);
445 ALCuint (*AvailableSamples
)(ALCdevice
*);
447 void (*Lock
)(ALCdevice
*);
448 void (*Unlock
)(ALCdevice
*);
450 ALint64 (*GetLatency
)(ALCdevice
*);
455 ALCboolean (*Init
)(BackendFuncs
*);
456 void (*Deinit
)(void);
457 void (*Probe
)(enum DevProbe
);
461 ALCboolean
alc_alsa_init(BackendFuncs
*func_list
);
462 void alc_alsa_deinit(void);
463 void alc_alsa_probe(enum DevProbe type
);
464 ALCboolean
alc_oss_init(BackendFuncs
*func_list
);
465 void alc_oss_deinit(void);
466 void alc_oss_probe(enum DevProbe type
);
467 ALCboolean
alc_solaris_init(BackendFuncs
*func_list
);
468 void alc_solaris_deinit(void);
469 void alc_solaris_probe(enum DevProbe type
);
470 ALCboolean
alc_sndio_init(BackendFuncs
*func_list
);
471 void alc_sndio_deinit(void);
472 void alc_sndio_probe(enum DevProbe type
);
473 ALCboolean
alcMMDevApiInit(BackendFuncs
*func_list
);
474 void alcMMDevApiDeinit(void);
475 void alcMMDevApiProbe(enum DevProbe type
);
476 ALCboolean
alcDSoundInit(BackendFuncs
*func_list
);
477 void alcDSoundDeinit(void);
478 void alcDSoundProbe(enum DevProbe type
);
479 ALCboolean
alcWinMMInit(BackendFuncs
*FuncList
);
480 void alcWinMMDeinit(void);
481 void alcWinMMProbe(enum DevProbe type
);
482 ALCboolean
alc_pa_init(BackendFuncs
*func_list
);
483 void alc_pa_deinit(void);
484 void alc_pa_probe(enum DevProbe type
);
485 ALCboolean
alc_wave_init(BackendFuncs
*func_list
);
486 void alc_wave_deinit(void);
487 void alc_wave_probe(enum DevProbe type
);
488 ALCboolean
alc_pulse_init(BackendFuncs
*func_list
);
489 void alc_pulse_deinit(void);
490 void alc_pulse_probe(enum DevProbe type
);
491 ALCboolean
alc_ca_init(BackendFuncs
*func_list
);
492 void alc_ca_deinit(void);
493 void alc_ca_probe(enum DevProbe type
);
494 ALCboolean
alc_opensl_init(BackendFuncs
*func_list
);
495 void alc_opensl_deinit(void);
496 void alc_opensl_probe(enum DevProbe type
);
497 ALCboolean
alc_null_init(BackendFuncs
*func_list
);
498 void alc_null_deinit(void);
499 void alc_null_probe(enum DevProbe type
);
500 ALCboolean
alc_loopback_init(BackendFuncs
*func_list
);
501 void alc_loopback_deinit(void);
502 void alc_loopback_probe(enum DevProbe type
);
506 InverseDistanceClamped
= AL_INVERSE_DISTANCE_CLAMPED
,
507 LinearDistanceClamped
= AL_LINEAR_DISTANCE_CLAMPED
,
508 ExponentDistanceClamped
= AL_EXPONENT_DISTANCE_CLAMPED
,
509 InverseDistance
= AL_INVERSE_DISTANCE
,
510 LinearDistance
= AL_LINEAR_DISTANCE
,
511 ExponentDistance
= AL_EXPONENT_DISTANCE
,
512 DisableDistance
= AL_NONE
,
514 DefaultDistanceModel
= InverseDistanceClamped
542 DevFmtByte
= ALC_BYTE_SOFT
,
543 DevFmtUByte
= ALC_UNSIGNED_BYTE_SOFT
,
544 DevFmtShort
= ALC_SHORT_SOFT
,
545 DevFmtUShort
= ALC_UNSIGNED_SHORT_SOFT
,
546 DevFmtInt
= ALC_INT_SOFT
,
547 DevFmtUInt
= ALC_UNSIGNED_INT_SOFT
,
548 DevFmtFloat
= ALC_FLOAT_SOFT
,
550 DevFmtTypeDefault
= DevFmtFloat
552 enum DevFmtChannels
{
553 DevFmtMono
= ALC_MONO_SOFT
,
554 DevFmtStereo
= ALC_STEREO_SOFT
,
555 DevFmtQuad
= ALC_QUAD_SOFT
,
556 DevFmtX51
= ALC_5POINT1_SOFT
,
557 DevFmtX61
= ALC_6POINT1_SOFT
,
558 DevFmtX71
= ALC_7POINT1_SOFT
,
560 /* Similar to 5.1, except using the side channels instead of back */
561 DevFmtX51Side
= 0x80000000,
563 DevFmtChannelsDefault
= DevFmtStereo
566 ALuint
BytesFromDevFmt(enum DevFmtType type
);
567 ALuint
ChannelsFromDevFmt(enum DevFmtChannels chans
);
568 static __inline ALuint
FrameSizeFromDevFmt(enum DevFmtChannels chans
,
569 enum DevFmtType type
)
571 return ChannelsFromDevFmt(chans
) * BytesFromDevFmt(type
);
575 extern const struct EffectList
{
590 /* Size for temporary storage of buffer data, in ALfloats. Larger values need
591 * more memory, while smaller values may need more iterations. The value needs
592 * to be a sensible size, however, as it constrains the max stepping value used
593 * for mixing, as well as the maximum number of samples per mixing iteration.
595 * The mixer requires being able to do two samplings per mixing loop. With the
596 * cubic resampler (which requires 3 padding samples), this limits a 2048
597 * buffer size to about 2044. This means that buffer_freq*source_pitch cannot
598 * exceed device_freq*2044 for a 32-bit buffer.
601 #define BUFFERSIZE 2048
605 struct ALCdevice_struct
607 volatile RefCount ref
;
609 ALCboolean Connected
;
610 enum DeviceType Type
;
612 CRITICAL_SECTION Mutex
;
617 enum DevFmtChannels FmtChans
;
618 enum DevFmtType FmtType
;
622 volatile ALCenum LastError
;
624 // Maximum number of sources that can be created
625 ALuint MaxNoOfSources
;
626 // Maximum number of slots that can be created
627 ALuint AuxiliaryEffectSlotMax
;
629 ALCuint NumMonoSources
;
630 ALCuint NumStereoSources
;
633 // Map of Buffers for this device
636 // Map of Effects for this device
639 // Map of Filters for this device
642 /* HRTF filter tables */
643 const struct Hrtf
*Hrtf
;
645 // Stereo-to-binaural filter
652 enum Channel DevChannels
[MaxChannels
];
654 enum Channel Speaker2Chan
[MaxChannels
];
655 ALfloat SpeakerAngle
[MaxChannels
];
658 /* Temp storage used for mixing. +1 for the predictive sample. */
659 ALIGN(16) ALfloat SampleData1
[BUFFERSIZE
+1];
660 ALIGN(16) ALfloat SampleData2
[BUFFERSIZE
+1];
662 // Dry path buffer mix
663 ALIGN(16) ALfloat DryBuffer
[MaxChannels
][BUFFERSIZE
];
665 ALIGN(16) ALfloat ClickRemoval
[MaxChannels
];
666 ALIGN(16) ALfloat PendingClicks
[MaxChannels
];
668 /* Default effect slot */
669 struct ALeffectslot
*DefaultSlot
;
671 // Contexts created on this device
672 ALCcontext
*volatile ContextList
;
675 void *ExtraData
; // For the backend's use
677 ALCdevice
*volatile next
;
680 #define ALCdevice_OpenPlayback(a,b) ((a)->Funcs->OpenPlayback((a), (b)))
681 #define ALCdevice_ClosePlayback(a) ((a)->Funcs->ClosePlayback((a)))
682 #define ALCdevice_ResetPlayback(a) ((a)->Funcs->ResetPlayback((a)))
683 #define ALCdevice_StartPlayback(a) ((a)->Funcs->StartPlayback((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)))
691 #define ALCdevice_Lock(a) ((a)->Funcs->Lock((a)))
692 #define ALCdevice_Unlock(a) ((a)->Funcs->Unlock((a)))
693 #define ALCdevice_GetLatency(a) ((a)->Funcs->GetLatency((a)))
695 // Frequency was requested by the app or config file
696 #define DEVICE_FREQUENCY_REQUEST (1<<1)
697 // Channel configuration was requested by the config file
698 #define DEVICE_CHANNELS_REQUEST (1<<2)
699 // Sample type was requested by the config file
700 #define DEVICE_SAMPLE_TYPE_REQUEST (1<<3)
702 // Stereo sources cover 120-degree angles around +/-90
703 #define DEVICE_WIDE_STEREO (1<<16)
705 // Specifies if the device is currently running
706 #define DEVICE_RUNNING (1<<31)
708 #define LookupBuffer(m, k) ((struct ALbuffer*)LookupUIntMapKey(&(m)->BufferMap, (k)))
709 #define LookupEffect(m, k) ((struct ALeffect*)LookupUIntMapKey(&(m)->EffectMap, (k)))
710 #define LookupFilter(m, k) ((struct ALfilter*)LookupUIntMapKey(&(m)->FilterMap, (k)))
711 #define RemoveBuffer(m, k) ((struct ALbuffer*)RemoveUIntMapKey(&(m)->BufferMap, (k)))
712 #define RemoveEffect(m, k) ((struct ALeffect*)RemoveUIntMapKey(&(m)->EffectMap, (k)))
713 #define RemoveFilter(m, k) ((struct ALfilter*)RemoveUIntMapKey(&(m)->FilterMap, (k)))
716 struct ALCcontext_struct
718 volatile RefCount ref
;
723 UIntMap EffectSlotMap
;
727 volatile ALenum UpdateSources
;
729 volatile enum DistanceModel DistanceModel
;
730 volatile ALboolean SourceDistanceModel
;
732 volatile ALfloat DopplerFactor
;
733 volatile ALfloat DopplerVelocity
;
734 volatile ALfloat SpeedOfSound
;
735 volatile ALenum DeferUpdates
;
737 struct ALsource
**ActiveSources
;
738 ALsizei ActiveSourceCount
;
739 ALsizei MaxActiveSources
;
741 struct ALeffectslot
**ActiveEffectSlots
;
742 ALsizei ActiveEffectSlotCount
;
743 ALsizei MaxActiveEffectSlots
;
746 const ALCchar
*ExtensionList
;
748 ALCcontext
*volatile next
;
751 #define LookupSource(m, k) ((struct ALsource*)LookupUIntMapKey(&(m)->SourceMap, (k)))
752 #define LookupEffectSlot(m, k) ((struct ALeffectslot*)LookupUIntMapKey(&(m)->EffectSlotMap, (k)))
753 #define RemoveSource(m, k) ((struct ALsource*)RemoveUIntMapKey(&(m)->SourceMap, (k)))
754 #define RemoveEffectSlot(m, k) ((struct ALeffectslot*)RemoveUIntMapKey(&(m)->EffectSlotMap, (k)))
757 ALCcontext
*GetContextRef(void);
759 void ALCcontext_IncRef(ALCcontext
*context
);
760 void ALCcontext_DecRef(ALCcontext
*context
);
762 void AppendAllDevicesList(const ALCchar
*name
);
763 void AppendCaptureDeviceList(const ALCchar
*name
);
765 void ALCdevice_LockDefault(ALCdevice
*device
);
766 void ALCdevice_UnlockDefault(ALCdevice
*device
);
767 ALint64
ALCdevice_GetLatencyDefault(ALCdevice
*device
);
769 static __inline
void LockContext(ALCcontext
*context
)
770 { ALCdevice_Lock(context
->Device
); }
771 static __inline
void UnlockContext(ALCcontext
*context
)
772 { ALCdevice_Unlock(context
->Device
); }
775 void *al_malloc(size_t alignment
, size_t size
);
776 void *al_calloc(size_t alignment
, size_t size
);
777 void al_free(void *ptr
);
785 void SetMixerFPUMode(FPUCtl
*ctl
);
786 void RestoreFPUMode(const FPUCtl
*ctl
);
788 ALvoid
*StartThread(ALuint (*func
)(ALvoid
*), ALvoid
*ptr
);
789 ALuint
StopThread(ALvoid
*thread
);
791 typedef struct RingBuffer RingBuffer
;
792 RingBuffer
*CreateRingBuffer(ALsizei frame_size
, ALsizei length
);
793 void DestroyRingBuffer(RingBuffer
*ring
);
794 ALsizei
RingBufferSize(RingBuffer
*ring
);
795 void WriteRingBuffer(RingBuffer
*ring
, const ALubyte
*data
, ALsizei len
);
796 void ReadRingBuffer(RingBuffer
*ring
, ALubyte
*data
, ALsizei len
);
798 void ReadALConfig(void);
799 void FreeALConfig(void);
800 int ConfigValueExists(const char *blockName
, const char *keyName
);
801 const char *GetConfigValue(const char *blockName
, const char *keyName
, const char *def
);
802 int GetConfigValueBool(const char *blockName
, const char *keyName
, int def
);
803 int ConfigValueStr(const char *blockName
, const char *keyName
, const char **ret
);
804 int ConfigValueInt(const char *blockName
, const char *keyName
, int *ret
);
805 int ConfigValueUInt(const char *blockName
, const char *keyName
, unsigned int *ret
);
806 int ConfigValueFloat(const char *blockName
, const char *keyName
, float *ret
);
808 void SetRTPriority(void);
810 void SetDefaultChannelOrder(ALCdevice
*device
);
811 void SetDefaultWFXChannelOrder(ALCdevice
*device
);
813 const ALCchar
*DevFmtTypeString(enum DevFmtType type
);
814 const ALCchar
*DevFmtChannelsString(enum DevFmtChannels chans
);
816 #define HRIR_BITS (7)
817 #define HRIR_LENGTH (1<<HRIR_BITS)
818 #define HRIR_MASK (HRIR_LENGTH-1)
819 #define HRTFDELAY_BITS (20)
820 #define HRTFDELAY_FRACONE (1<<HRTFDELAY_BITS)
821 #define HRTFDELAY_MASK (HRTFDELAY_FRACONE-1)
822 const struct Hrtf
*GetHrtf(ALCdevice
*device
);
823 void FreeHrtfs(void);
824 ALuint
GetHrtfIrSize (const struct Hrtf
*Hrtf
);
825 ALfloat
CalcHrtfDelta(ALfloat oldGain
, ALfloat newGain
, const ALfloat olddir
[3], const ALfloat newdir
[3]);
826 void GetLerpedHrtfCoeffs(const struct Hrtf
*Hrtf
, ALfloat elevation
, ALfloat azimuth
, ALfloat gain
, ALfloat (*coeffs
)[2], ALuint
*delays
);
827 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
);
829 void al_print(const char *type
, const char *func
, const char *fmt
, ...) PRINTF_STYLE(3,4);
830 #define AL_PRINT(T, ...) al_print((T), __FUNCTION__, __VA_ARGS__)
832 extern FILE *LogFile
;
840 extern enum LogLevel LogLevel
;
842 #define TRACEREF(...) do { \
843 if(LogLevel >= LogRef) \
844 AL_PRINT("(--)", __VA_ARGS__); \
847 #define TRACE(...) do { \
848 if(LogLevel >= LogTrace) \
849 AL_PRINT("(II)", __VA_ARGS__); \
852 #define WARN(...) do { \
853 if(LogLevel >= LogWarning) \
854 AL_PRINT("(WW)", __VA_ARGS__); \
857 #define ERR(...) do { \
858 if(LogLevel >= LogError) \
859 AL_PRINT("(EE)", __VA_ARGS__); \
863 extern ALint RTPrioLevel
;
866 extern ALuint CPUCapFlags
;
872 void FillCPUCaps(ALuint capfilter
);
876 * Starts a try block. Must not be nested within another try block within the
879 #define al_try do { \
884 * After a try or another catch block, runs the next block if the given value
887 #define al_catch(val) else if(_al_err == (val))
889 * After a try or catch block, runs the next block for any value thrown and not
892 #define al_catchany() else
893 /** Marks the end of the final catch (or the try) block. */
894 #define al_endtry } while(0)
897 * The given integer value is "thrown" so as to be caught by a catch block.
898 * Must be called in a try block within the same function. The value must not
901 #define al_throw(e) do { \
903 assert(_al_err != 0); \
904 goto _al_try_label; \
906 /** Sets an AL error on the given context, before throwing the error code. */
907 #define al_throwerr(ctx, err) do { \
908 alSetError((ctx), (err)); \
913 * Throws an AL_INVALID_VALUE error with the given ctx if the given condition
916 #define CHECK_VALUE(ctx, cond) do { \
918 al_throwerr((ctx), AL_INVALID_VALUE); \