17 /* Define int64_t and uint64_t types */
18 #if defined(__STDC_VERSION__) && __STDC_VERSION__ >= 199901L
20 #elif defined(_WIN32) && defined(__GNUC__)
23 typedef __int64
int64_t;
24 typedef unsigned __int64
uint64_t;
26 /* Fallback if nothing above works */
30 #ifndef AL_SOFT_deferred_updates
31 #define AL_SOFT_deferred_updates 1
32 #define AL_DEFERRED_UPDATES_SOFT 0xC002
33 typedef ALvoid (AL_APIENTRY
*LPALDEFERUPDATESSOFT
)(void);
34 typedef ALvoid (AL_APIENTRY
*LPALPROCESSUPDATESSOFT
)(void);
35 #ifdef AL_ALEXT_PROTOTYPES
36 AL_API ALvoid AL_APIENTRY
alDeferUpdatesSOFT(void);
37 AL_API ALvoid AL_APIENTRY
alProcessUpdatesSOFT(void);
41 #ifndef AL_SOFT_source_latency
42 #define AL_SOFT_source_latency 1
43 #define AL_SAMPLE_OFFSET_LATENCY_SOFT 0x1200
44 #define AL_SEC_OFFSET_LATENCY_SOFT 0x1201
45 typedef int64_t ALint64SOFT
;
46 typedef uint64_t ALuint64SOFT
;
47 typedef void (AL_APIENTRY
*LPALGETSOURCEDSOFT
)(ALuint
,ALenum
,ALdouble
*);
48 typedef void (AL_APIENTRY
*LPALGETSOURCE3DSOFT
)(ALuint
,ALenum
,ALdouble
*,ALdouble
*,ALdouble
*);
49 typedef void (AL_APIENTRY
*LPALGETSOURCEDVSOFT
)(ALuint
,ALenum
,ALdouble
*);
50 typedef void (AL_APIENTRY
*LPALGETSOURCEI64SOFT
)(ALuint
,ALenum
,ALint64SOFT
*);
51 typedef void (AL_APIENTRY
*LPALGETSOURCE3I64SOFT
)(ALuint
,ALenum
,ALint64SOFT
*,ALint64SOFT
*,ALint64SOFT
*);
52 typedef void (AL_APIENTRY
*LPALGETSOURCEI64VSOFT
)(ALuint
,ALenum
,ALint64SOFT
*);
53 #ifdef AL_ALEXT_PROTOTYPES
54 AL_API
void AL_APIENTRY
alGetSourcedSOFT(ALuint source
, ALenum param
, ALdouble
*value
);
55 AL_API
void AL_APIENTRY
alGetSource3dSOFT(ALuint source
, ALenum param
, ALdouble
*value1
, ALdouble
*value2
, ALdouble
*value3
);
56 AL_API
void AL_APIENTRY
alGetSourcedvSOFT(ALuint source
, ALenum param
, ALdouble
*values
);
57 AL_API
void AL_APIENTRY
alGetSourcei64SOFT(ALuint source
, ALenum param
, ALint64SOFT
*value
);
58 AL_API
void AL_APIENTRY
alGetSource3i64SOFT(ALuint source
, ALenum param
, ALint64SOFT
*value1
, ALint64SOFT
*value2
, ALint64SOFT
*value3
);
59 AL_API
void AL_APIENTRY
alGetSourcei64vSOFT(ALuint source
, ALenum param
, ALint64SOFT
*values
);
64 #if defined(HAVE_STDINT_H)
66 typedef int64_t ALint64
;
67 typedef uint64_t ALuint64
;
68 #elif defined(HAVE___INT64)
69 typedef __int64 ALint64
;
70 typedef unsigned __int64 ALuint64
;
71 #elif (SIZEOF_LONG == 8)
73 typedef unsigned long ALuint64
;
74 #elif (SIZEOF_LONG_LONG == 8)
75 typedef long long ALint64
;
76 typedef unsigned long long ALuint64
;
79 typedef ptrdiff_t ALintptrEXT
;
80 typedef ptrdiff_t ALsizeiptrEXT
;
82 #define MAKEU64(x,y) (((ALuint64)(x)<<32)|(ALuint64)(y))
84 #ifdef HAVE_GCC_FORMAT
85 #define PRINTF_STYLE(x, y) __attribute__((format(printf, (x), (y))))
87 #define PRINTF_STYLE(x, y)
90 #if defined(HAVE_RESTRICT)
91 #define RESTRICT restrict
92 #elif defined(HAVE___RESTRICT)
93 #define RESTRICT __restrict
101 ALubyte b
[sizeof(ALuint
)];
102 } EndianTest
= { 1 };
103 #define IS_LITTLE_ENDIAN (EndianTest.b[0] == 1)
105 #define COUNTOF(x) (sizeof((x))/sizeof((x)[0]))
111 typedef DWORD pthread_key_t
;
112 int pthread_key_create(pthread_key_t
*key
, void (*callback
)(void*));
113 int pthread_key_delete(pthread_key_t key
);
114 void *pthread_getspecific(pthread_key_t key
);
115 int pthread_setspecific(pthread_key_t key
, void *val
);
117 #define HAVE_DYNLOAD 1
118 void *LoadLib(const char *name
);
119 void CloseLib(void *handle
);
120 void *GetSymbol(void *handle
, const char *name
);
122 WCHAR
*strdupW(const WCHAR
*str
);
124 typedef LONG pthread_once_t
;
125 #define PTHREAD_ONCE_INIT 0
126 void pthread_once(pthread_once_t
*once
, void (*callback
)(void));
128 static __inline
int sched_yield(void)
129 { SwitchToThread(); return 0; }
136 #include <sys/time.h>
140 #define IsBadWritePtr(a,b) ((a) == NULL && (b) != 0)
142 typedef pthread_mutex_t CRITICAL_SECTION
;
143 void InitializeCriticalSection(CRITICAL_SECTION
*cs
);
144 void DeleteCriticalSection(CRITICAL_SECTION
*cs
);
145 void EnterCriticalSection(CRITICAL_SECTION
*cs
);
146 void LeaveCriticalSection(CRITICAL_SECTION
*cs
);
148 ALuint
timeGetTime(void);
149 void Sleep(ALuint t
);
151 #if defined(HAVE_DLFCN_H)
152 #define HAVE_DYNLOAD 1
153 void *LoadLib(const char *name
);
154 void CloseLib(void *handle
);
155 void *GetSymbol(void *handle
, const char *name
);
160 typedef void *volatile XchgPtr
;
162 #if defined(__GNUC__) && (__GNUC__ > 4 || (__GNUC__ == 4 && __GNUC_MINOR__ >= 1))
163 typedef ALuint RefCount
;
164 static __inline RefCount
IncrementRef(volatile RefCount
*ptr
)
165 { return __sync_add_and_fetch(ptr
, 1); }
166 static __inline RefCount
DecrementRef(volatile RefCount
*ptr
)
167 { return __sync_sub_and_fetch(ptr
, 1); }
169 static __inline
int ExchangeInt(volatile int *ptr
, int newval
)
171 return __sync_lock_test_and_set(ptr
, newval
);
173 static __inline
void *ExchangePtr(XchgPtr
*ptr
, void *newval
)
175 return __sync_lock_test_and_set(ptr
, newval
);
177 static __inline ALboolean
CompExchangeInt(volatile int *ptr
, int oldval
, int newval
)
179 return __sync_bool_compare_and_swap(ptr
, oldval
, newval
);
181 static __inline ALboolean
CompExchangePtr(XchgPtr
*ptr
, void *oldval
, void *newval
)
183 return __sync_bool_compare_and_swap(ptr
, oldval
, newval
);
186 #elif defined(__GNUC__) && (defined(__i386__) || defined(__x86_64__))
188 static __inline
int xaddl(volatile int *dest
, int incr
)
191 __asm__
__volatile__("lock; xaddl %0,(%1)"
193 : "r" (dest
), "0" (incr
)
198 typedef int RefCount
;
199 static __inline RefCount
IncrementRef(volatile RefCount
*ptr
)
200 { return xaddl(ptr
, 1)+1; }
201 static __inline RefCount
DecrementRef(volatile RefCount
*ptr
)
202 { return xaddl(ptr
, -1)-1; }
204 static __inline
int ExchangeInt(volatile int *dest
, int newval
)
207 __asm__
__volatile__("lock; xchgl %0,(%1)"
209 : "r" (dest
), "0" (newval
)
214 static __inline ALboolean
CompExchangeInt(volatile int *dest
, int oldval
, int newval
)
217 __asm__
__volatile__("lock; cmpxchgl %2,(%1)"
219 : "r" (dest
), "r" (newval
), "0" (oldval
)
221 return ret
== oldval
;
224 static __inline
void *ExchangePtr(XchgPtr
*dest
, void *newval
)
227 __asm__
__volatile__(
229 "lock; xchgl %0,(%1)"
231 "lock; xchgq %0,(%1)"
234 : "r" (dest
), "0" (newval
)
240 static __inline ALboolean
CompExchangePtr(XchgPtr
*dest
, void *oldval
, void *newval
)
243 __asm__
__volatile__(
245 "lock; cmpxchgl %2,(%1)"
247 "lock; cmpxchgq %2,(%1)"
250 : "r" (dest
), "r" (newval
), "0" (oldval
)
253 return ret
== oldval
;
256 #elif defined(_WIN32)
258 typedef LONG RefCount
;
259 static __inline RefCount
IncrementRef(volatile RefCount
*ptr
)
260 { return InterlockedIncrement(ptr
); }
261 static __inline RefCount
DecrementRef(volatile RefCount
*ptr
)
262 { return InterlockedDecrement(ptr
); }
264 extern ALbyte LONG_size_does_not_match_int
[(sizeof(LONG
)==sizeof(int))?1:-1];
266 static __inline
int ExchangeInt(volatile int *ptr
, int newval
)
272 return InterlockedExchange(u
.l
, newval
);
274 static __inline
void *ExchangePtr(XchgPtr
*ptr
, void *newval
)
276 return InterlockedExchangePointer(ptr
, newval
);
278 static __inline ALboolean
CompExchangeInt(volatile int *ptr
, int oldval
, int newval
)
284 return InterlockedCompareExchange(u
.l
, newval
, oldval
) == oldval
;
286 static __inline ALboolean
CompExchangePtr(XchgPtr
*ptr
, void *oldval
, void *newval
)
288 return InterlockedCompareExchangePointer(ptr
, newval
, oldval
) == oldval
;
291 #elif defined(__APPLE__)
293 #include <libkern/OSAtomic.h>
295 typedef int32_t RefCount
;
296 static __inline RefCount
IncrementRef(volatile RefCount
*ptr
)
297 { return OSAtomicIncrement32Barrier(ptr
); }
298 static __inline RefCount
DecrementRef(volatile RefCount
*ptr
)
299 { return OSAtomicDecrement32Barrier(ptr
); }
301 static __inline
int ExchangeInt(volatile int *ptr
, int newval
)
303 /* Really? No regular old atomic swap? */
307 } while(!OSAtomicCompareAndSwap32Barrier(oldval
, newval
, ptr
));
310 static __inline
void *ExchangePtr(XchgPtr
*ptr
, void *newval
)
315 } while(!OSAtomicCompareAndSwapPtrBarrier(oldval
, newval
, ptr
));
318 static __inline ALboolean
CompExchangeInt(volatile int *ptr
, int oldval
, int newval
)
320 return OSAtomicCompareAndSwap32Barrier(oldval
, newval
, ptr
);
322 static __inline ALboolean
CompExchangePtr(XchgPtr
*ptr
, void *oldval
, void *newval
)
324 return OSAtomicCompareAndSwapPtrBarrier(oldval
, newval
, ptr
);
328 #error "No atomic functions available on this platform!"
329 typedef ALuint RefCount
;
334 volatile RefCount read_count
;
335 volatile RefCount write_count
;
336 volatile ALenum read_lock
;
337 volatile ALenum read_entry_lock
;
338 volatile ALenum write_lock
;
341 void RWLockInit(RWLock
*lock
);
342 void ReadLock(RWLock
*lock
);
343 void ReadUnlock(RWLock
*lock
);
344 void WriteLock(RWLock
*lock
);
345 void WriteUnlock(RWLock
*lock
);
348 typedef struct UIntMap
{
358 extern UIntMap TlsDestructor
;
360 void InitUIntMap(UIntMap
*map
, ALsizei limit
);
361 void ResetUIntMap(UIntMap
*map
);
362 ALenum
InsertUIntMapEntry(UIntMap
*map
, ALuint key
, ALvoid
*value
);
363 ALvoid
*RemoveUIntMapKey(UIntMap
*map
, ALuint key
);
364 ALvoid
*LookupUIntMapKey(UIntMap
*map
, ALuint key
);
366 static __inline
void LockUIntMapRead(UIntMap
*map
)
367 { ReadLock(&map
->lock
); }
368 static __inline
void UnlockUIntMapRead(UIntMap
*map
)
369 { ReadUnlock(&map
->lock
); }
370 static __inline
void LockUIntMapWrite(UIntMap
*map
)
371 { WriteLock(&map
->lock
); }
372 static __inline
void UnlockUIntMapWrite(UIntMap
*map
)
373 { WriteUnlock(&map
->lock
); }
375 #include "alListener.h"
384 #define DEFAULT_OUTPUT_RATE (44100)
385 #define MIN_OUTPUT_RATE (8000)
388 // Find the next power-of-2 for non-power-of-2 numbers.
389 static __inline ALuint
NextPowerOf2(ALuint value
)
405 /* Fast float-to-int conversion. Assumes the FPU is already in round-to-zero
407 static __inline ALint
fastf2i(ALfloat f
)
410 #if defined(_MSC_VER) && defined(_M_IX86)
413 #elif defined(__GNUC__) && (defined(__i386__) || defined(__x86_64__))
414 __asm__
__volatile__("flds %1\n\t"
424 /* Fast float-to-uint conversion. Assumes the FPU is already in round-to-zero
426 static __inline ALuint
fastf2u(ALfloat f
)
427 { return fastf2i(f
); }
436 ALCenum (*OpenPlayback
)(ALCdevice
*, const ALCchar
*);
437 void (*ClosePlayback
)(ALCdevice
*);
438 ALCboolean (*ResetPlayback
)(ALCdevice
*);
439 ALCboolean (*StartPlayback
)(ALCdevice
*);
440 void (*StopPlayback
)(ALCdevice
*);
442 ALCenum (*OpenCapture
)(ALCdevice
*, const ALCchar
*);
443 void (*CloseCapture
)(ALCdevice
*);
444 void (*StartCapture
)(ALCdevice
*);
445 void (*StopCapture
)(ALCdevice
*);
446 ALCenum (*CaptureSamples
)(ALCdevice
*, void*, ALCuint
);
447 ALCuint (*AvailableSamples
)(ALCdevice
*);
449 void (*Lock
)(ALCdevice
*);
450 void (*Unlock
)(ALCdevice
*);
452 ALint64 (*GetLatency
)(ALCdevice
*);
457 ALCboolean (*Init
)(BackendFuncs
*);
458 void (*Deinit
)(void);
459 void (*Probe
)(enum DevProbe
);
463 ALCboolean
alc_alsa_init(BackendFuncs
*func_list
);
464 void alc_alsa_deinit(void);
465 void alc_alsa_probe(enum DevProbe type
);
466 ALCboolean
alc_oss_init(BackendFuncs
*func_list
);
467 void alc_oss_deinit(void);
468 void alc_oss_probe(enum DevProbe type
);
469 ALCboolean
alc_solaris_init(BackendFuncs
*func_list
);
470 void alc_solaris_deinit(void);
471 void alc_solaris_probe(enum DevProbe type
);
472 ALCboolean
alc_sndio_init(BackendFuncs
*func_list
);
473 void alc_sndio_deinit(void);
474 void alc_sndio_probe(enum DevProbe type
);
475 ALCboolean
alcMMDevApiInit(BackendFuncs
*func_list
);
476 void alcMMDevApiDeinit(void);
477 void alcMMDevApiProbe(enum DevProbe type
);
478 ALCboolean
alcDSoundInit(BackendFuncs
*func_list
);
479 void alcDSoundDeinit(void);
480 void alcDSoundProbe(enum DevProbe type
);
481 ALCboolean
alcWinMMInit(BackendFuncs
*FuncList
);
482 void alcWinMMDeinit(void);
483 void alcWinMMProbe(enum DevProbe type
);
484 ALCboolean
alc_pa_init(BackendFuncs
*func_list
);
485 void alc_pa_deinit(void);
486 void alc_pa_probe(enum DevProbe type
);
487 ALCboolean
alc_wave_init(BackendFuncs
*func_list
);
488 void alc_wave_deinit(void);
489 void alc_wave_probe(enum DevProbe type
);
490 ALCboolean
alc_pulse_init(BackendFuncs
*func_list
);
491 void alc_pulse_deinit(void);
492 void alc_pulse_probe(enum DevProbe type
);
493 ALCboolean
alc_ca_init(BackendFuncs
*func_list
);
494 void alc_ca_deinit(void);
495 void alc_ca_probe(enum DevProbe type
);
496 ALCboolean
alc_opensl_init(BackendFuncs
*func_list
);
497 void alc_opensl_deinit(void);
498 void alc_opensl_probe(enum DevProbe type
);
499 ALCboolean
alc_null_init(BackendFuncs
*func_list
);
500 void alc_null_deinit(void);
501 void alc_null_probe(enum DevProbe type
);
502 ALCboolean
alc_loopback_init(BackendFuncs
*func_list
);
503 void alc_loopback_deinit(void);
504 void alc_loopback_probe(enum DevProbe type
);
508 InverseDistanceClamped
= AL_INVERSE_DISTANCE_CLAMPED
,
509 LinearDistanceClamped
= AL_LINEAR_DISTANCE_CLAMPED
,
510 ExponentDistanceClamped
= AL_EXPONENT_DISTANCE_CLAMPED
,
511 InverseDistance
= AL_INVERSE_DISTANCE
,
512 LinearDistance
= AL_LINEAR_DISTANCE
,
513 ExponentDistance
= AL_EXPONENT_DISTANCE
,
514 DisableDistance
= AL_NONE
,
516 DefaultDistanceModel
= InverseDistanceClamped
544 DevFmtByte
= ALC_BYTE_SOFT
,
545 DevFmtUByte
= ALC_UNSIGNED_BYTE_SOFT
,
546 DevFmtShort
= ALC_SHORT_SOFT
,
547 DevFmtUShort
= ALC_UNSIGNED_SHORT_SOFT
,
548 DevFmtInt
= ALC_INT_SOFT
,
549 DevFmtUInt
= ALC_UNSIGNED_INT_SOFT
,
550 DevFmtFloat
= ALC_FLOAT_SOFT
,
552 DevFmtTypeDefault
= DevFmtFloat
554 enum DevFmtChannels
{
555 DevFmtMono
= ALC_MONO_SOFT
,
556 DevFmtStereo
= ALC_STEREO_SOFT
,
557 DevFmtQuad
= ALC_QUAD_SOFT
,
558 DevFmtX51
= ALC_5POINT1_SOFT
,
559 DevFmtX61
= ALC_6POINT1_SOFT
,
560 DevFmtX71
= ALC_7POINT1_SOFT
,
562 /* Similar to 5.1, except using the side channels instead of back */
563 DevFmtX51Side
= 0x80000000,
565 DevFmtChannelsDefault
= DevFmtStereo
568 ALuint
BytesFromDevFmt(enum DevFmtType type
);
569 ALuint
ChannelsFromDevFmt(enum DevFmtChannels chans
);
570 static __inline ALuint
FrameSizeFromDevFmt(enum DevFmtChannels chans
,
571 enum DevFmtType type
)
573 return ChannelsFromDevFmt(chans
) * BytesFromDevFmt(type
);
577 extern const struct EffectList
{
592 /* Size for temporary storage of buffer data, in ALfloats. Larger values need
593 * more stack, while smaller values may need more iterations. The value needs
594 * to be a sensible size, however, as it constrains the max stepping value used
595 * for mixing, as well as the maximum number of samples per mixing iteration.
596 * The mixer requires being able to do two samplings per mixing loop. A 16KB
597 * buffer can hold 512 sample frames for a 7.1 float buffer. With the cubic
598 * resampler (which requires 3 padding sample frames), this limits the maximum
599 * step to about 508. This means that buffer_freq*source_pitch cannot exceed
600 * device_freq*508 for an 8-channel 32-bit buffer.
603 #define BUFFERSIZE 4096
607 struct ALCdevice_struct
609 volatile RefCount ref
;
611 ALCboolean Connected
;
612 enum DeviceType Type
;
614 CRITICAL_SECTION Mutex
;
619 enum DevFmtChannels FmtChans
;
620 enum DevFmtType FmtType
;
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
;
635 // Map of Buffers for this device
638 // Map of Effects for this device
641 // Map of Filters for this device
644 /* HRTF filter tables */
645 const struct Hrtf
*Hrtf
;
647 // Stereo-to-binaural filter
654 enum Channel DevChannels
[MaxChannels
];
656 enum Channel Speaker2Chan
[MaxChannels
];
657 ALfloat SpeakerAngle
[MaxChannels
];
660 // Dry path buffer mix
661 ALIGN(16) ALfloat DryBuffer
[MaxChannels
][BUFFERSIZE
];
663 ALIGN(16) ALfloat ClickRemoval
[MaxChannels
];
664 ALIGN(16) ALfloat PendingClicks
[MaxChannels
];
666 /* Default effect slot */
667 struct ALeffectslot
*DefaultSlot
;
669 // Contexts created on this device
670 ALCcontext
*volatile ContextList
;
673 void *ExtraData
; // For the backend's use
675 ALCdevice
*volatile next
;
678 #define ALCdevice_OpenPlayback(a,b) ((a)->Funcs->OpenPlayback((a), (b)))
679 #define ALCdevice_ClosePlayback(a) ((a)->Funcs->ClosePlayback((a)))
680 #define ALCdevice_ResetPlayback(a) ((a)->Funcs->ResetPlayback((a)))
681 #define ALCdevice_StartPlayback(a) ((a)->Funcs->StartPlayback((a)))
682 #define ALCdevice_StopPlayback(a) ((a)->Funcs->StopPlayback((a)))
683 #define ALCdevice_OpenCapture(a,b) ((a)->Funcs->OpenCapture((a), (b)))
684 #define ALCdevice_CloseCapture(a) ((a)->Funcs->CloseCapture((a)))
685 #define ALCdevice_StartCapture(a) ((a)->Funcs->StartCapture((a)))
686 #define ALCdevice_StopCapture(a) ((a)->Funcs->StopCapture((a)))
687 #define ALCdevice_CaptureSamples(a,b,c) ((a)->Funcs->CaptureSamples((a), (b), (c)))
688 #define ALCdevice_AvailableSamples(a) ((a)->Funcs->AvailableSamples((a)))
689 #define ALCdevice_Lock(a) ((a)->Funcs->Lock((a)))
690 #define ALCdevice_Unlock(a) ((a)->Funcs->Unlock((a)))
691 #define ALCdevice_GetLatency(a) ((a)->Funcs->GetLatency((a)))
693 // Frequency was requested by the app or config file
694 #define DEVICE_FREQUENCY_REQUEST (1<<1)
695 // Channel configuration was requested by the config file
696 #define DEVICE_CHANNELS_REQUEST (1<<2)
697 // Sample type was requested by the config file
698 #define DEVICE_SAMPLE_TYPE_REQUEST (1<<3)
700 // Stereo sources cover 120-degree angles around +/-90
701 #define DEVICE_WIDE_STEREO (1<<16)
703 // Specifies if the device is currently running
704 #define DEVICE_RUNNING (1<<31)
706 #define LookupBuffer(m, k) ((struct ALbuffer*)LookupUIntMapKey(&(m)->BufferMap, (k)))
707 #define LookupEffect(m, k) ((struct ALeffect*)LookupUIntMapKey(&(m)->EffectMap, (k)))
708 #define LookupFilter(m, k) ((struct ALfilter*)LookupUIntMapKey(&(m)->FilterMap, (k)))
709 #define RemoveBuffer(m, k) ((struct ALbuffer*)RemoveUIntMapKey(&(m)->BufferMap, (k)))
710 #define RemoveEffect(m, k) ((struct ALeffect*)RemoveUIntMapKey(&(m)->EffectMap, (k)))
711 #define RemoveFilter(m, k) ((struct ALfilter*)RemoveUIntMapKey(&(m)->FilterMap, (k)))
714 struct ALCcontext_struct
716 volatile RefCount ref
;
721 UIntMap EffectSlotMap
;
725 volatile ALenum UpdateSources
;
727 volatile enum DistanceModel DistanceModel
;
728 volatile ALboolean SourceDistanceModel
;
730 volatile ALfloat DopplerFactor
;
731 volatile ALfloat DopplerVelocity
;
732 volatile ALfloat SpeedOfSound
;
733 volatile ALenum DeferUpdates
;
735 struct ALsource
**ActiveSources
;
736 ALsizei ActiveSourceCount
;
737 ALsizei MaxActiveSources
;
739 struct ALeffectslot
**ActiveEffectSlots
;
740 ALsizei ActiveEffectSlotCount
;
741 ALsizei MaxActiveEffectSlots
;
744 const ALCchar
*ExtensionList
;
746 ALCcontext
*volatile next
;
749 #define LookupSource(m, k) ((struct ALsource*)LookupUIntMapKey(&(m)->SourceMap, (k)))
750 #define LookupEffectSlot(m, k) ((struct ALeffectslot*)LookupUIntMapKey(&(m)->EffectSlotMap, (k)))
751 #define RemoveSource(m, k) ((struct ALsource*)RemoveUIntMapKey(&(m)->SourceMap, (k)))
752 #define RemoveEffectSlot(m, k) ((struct ALeffectslot*)RemoveUIntMapKey(&(m)->EffectSlotMap, (k)))
755 ALCcontext
*GetContextRef(void);
757 void ALCcontext_IncRef(ALCcontext
*context
);
758 void ALCcontext_DecRef(ALCcontext
*context
);
760 void AppendAllDevicesList(const ALCchar
*name
);
761 void AppendCaptureDeviceList(const ALCchar
*name
);
763 void ALCdevice_LockDefault(ALCdevice
*device
);
764 void ALCdevice_UnlockDefault(ALCdevice
*device
);
765 ALint64
ALCdevice_GetLatencyDefault(ALCdevice
*device
);
767 static __inline
void LockContext(ALCcontext
*context
)
768 { ALCdevice_Lock(context
->Device
); }
769 static __inline
void UnlockContext(ALCcontext
*context
)
770 { ALCdevice_Unlock(context
->Device
); }
773 void *al_malloc(size_t alignment
, size_t size
);
774 void *al_calloc(size_t alignment
, size_t size
);
775 void al_free(void *ptr
);
783 void SetMixerFPUMode(FPUCtl
*ctl
);
784 void RestoreFPUMode(const FPUCtl
*ctl
);
786 ALvoid
*StartThread(ALuint (*func
)(ALvoid
*), ALvoid
*ptr
);
787 ALuint
StopThread(ALvoid
*thread
);
789 typedef struct RingBuffer RingBuffer
;
790 RingBuffer
*CreateRingBuffer(ALsizei frame_size
, ALsizei length
);
791 void DestroyRingBuffer(RingBuffer
*ring
);
792 ALsizei
RingBufferSize(RingBuffer
*ring
);
793 void WriteRingBuffer(RingBuffer
*ring
, const ALubyte
*data
, ALsizei len
);
794 void ReadRingBuffer(RingBuffer
*ring
, ALubyte
*data
, ALsizei len
);
796 void ReadALConfig(void);
797 void FreeALConfig(void);
798 int ConfigValueExists(const char *blockName
, const char *keyName
);
799 const char *GetConfigValue(const char *blockName
, const char *keyName
, const char *def
);
800 int GetConfigValueBool(const char *blockName
, const char *keyName
, int def
);
801 int ConfigValueStr(const char *blockName
, const char *keyName
, const char **ret
);
802 int ConfigValueInt(const char *blockName
, const char *keyName
, int *ret
);
803 int ConfigValueUInt(const char *blockName
, const char *keyName
, unsigned int *ret
);
804 int ConfigValueFloat(const char *blockName
, const char *keyName
, float *ret
);
806 void SetRTPriority(void);
808 void SetDefaultChannelOrder(ALCdevice
*device
);
809 void SetDefaultWFXChannelOrder(ALCdevice
*device
);
811 const ALCchar
*DevFmtTypeString(enum DevFmtType type
);
812 const ALCchar
*DevFmtChannelsString(enum DevFmtChannels chans
);
814 #define HRIR_BITS (7)
815 #define HRIR_LENGTH (1<<HRIR_BITS)
816 #define HRIR_MASK (HRIR_LENGTH-1)
817 #define HRTFDELAY_BITS (20)
818 #define HRTFDELAY_FRACONE (1<<HRTFDELAY_BITS)
819 #define HRTFDELAY_MASK (HRTFDELAY_FRACONE-1)
820 const struct Hrtf
*GetHrtf(ALCdevice
*device
);
821 void FreeHrtfs(void);
822 ALuint
GetHrtfIrSize (const struct Hrtf
*Hrtf
);
823 ALfloat
CalcHrtfDelta(ALfloat oldGain
, ALfloat newGain
, const ALfloat olddir
[3], const ALfloat newdir
[3]);
824 void GetLerpedHrtfCoeffs(const struct Hrtf
*Hrtf
, ALfloat elevation
, ALfloat azimuth
, ALfloat gain
, ALfloat (*coeffs
)[2], ALuint
*delays
);
825 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
);
827 void al_print(const char *func
, const char *fmt
, ...) PRINTF_STYLE(2,3);
828 #define AL_PRINT(...) al_print(__FUNCTION__, __VA_ARGS__)
830 extern FILE *LogFile
;
838 extern enum LogLevel LogLevel
;
840 #define TRACEREF(...) do { \
841 if(LogLevel >= LogRef) \
842 AL_PRINT(__VA_ARGS__); \
845 #define TRACE(...) do { \
846 if(LogLevel >= LogTrace) \
847 AL_PRINT(__VA_ARGS__); \
850 #define WARN(...) do { \
851 if(LogLevel >= LogWarning) \
852 AL_PRINT(__VA_ARGS__); \
855 #define ERR(...) do { \
856 if(LogLevel >= LogError) \
857 AL_PRINT(__VA_ARGS__); \
861 extern ALint RTPrioLevel
;
864 extern ALuint CPUCapFlags
;
870 void FillCPUCaps(ALuint capfilter
);
874 * Starts a try block. Must not be nested within another try block within the
877 #define al_try do { \
882 * After a try or another catch block, runs the next block if the given value
885 #define al_catch(val) else if(_al_err == (val))
887 * After a try or catch block, runs the next block for any value thrown and not
890 #define al_catchany() else
891 /** Marks the end of the final catch (or the try) block. */
892 #define al_endtry } while(0)
895 * The given integer value is "thrown" so as to be caught by a catch block.
896 * Must be called in a try block within the same function. The value must not
899 #define al_throw(e) do { \
901 assert(_al_err != 0); \
902 goto _al_try_label; \
904 /** Sets an AL error on the given context, before throwing the error code. */
905 #define al_throwerr(ctx, err) do { \
906 alSetError((ctx), (err)); \
911 * Throws an AL_INVALID_VALUE error with the given ctx if the given condition
914 #define CHECK_VALUE(ctx, cond) do { \
916 al_throwerr((ctx), AL_INVALID_VALUE); \