13 #ifdef HAVE_FPU_CONTROL_H
14 #include <fpu_control.h>
21 /* Define int64_t and uint64_t types */
22 #if defined(__STDC_VERSION__) && __STDC_VERSION__ >= 199901L
24 #elif defined(_WIN32) && defined(__GNUC__)
27 typedef __int64
int64_t;
28 typedef unsigned __int64
uint64_t;
30 /* Fallback if nothing above works */
34 #ifndef AL_SOFT_deferred_updates
35 #define AL_SOFT_deferred_updates 1
36 #define AL_DEFERRED_UPDATES_SOFT 0xC002
37 typedef ALvoid (AL_APIENTRY
*LPALDEFERUPDATESSOFT
)(void);
38 typedef ALvoid (AL_APIENTRY
*LPALPROCESSUPDATESSOFT
)(void);
39 #ifdef AL_ALEXT_PROTOTYPES
40 AL_API ALvoid AL_APIENTRY
alDeferUpdatesSOFT(void);
41 AL_API ALvoid AL_APIENTRY
alProcessUpdatesSOFT(void);
45 #ifndef AL_SOFT_source_latency
46 #define AL_SOFT_source_latency 1
47 #define AL_SAMPLE_OFFSET_LATENCY_SOFT 0x1200
48 #define AL_SEC_OFFSET_LATENCY_SOFT 0x1201
49 typedef int64_t ALint64SOFT
;
50 typedef uint64_t ALuint64SOFT
;
51 typedef void (AL_APIENTRY
*LPALGETSOURCEDSOFT
)(ALuint
,ALenum
,ALdouble
*);
52 typedef void (AL_APIENTRY
*LPALGETSOURCE3DSOFT
)(ALuint
,ALenum
,ALdouble
*,ALdouble
*,ALdouble
*);
53 typedef void (AL_APIENTRY
*LPALGETSOURCEDVSOFT
)(ALuint
,ALenum
,ALdouble
*);
54 typedef void (AL_APIENTRY
*LPALGETSOURCEI64SOFT
)(ALuint
,ALenum
,ALint64SOFT
*);
55 typedef void (AL_APIENTRY
*LPALGETSOURCE3I64SOFT
)(ALuint
,ALenum
,ALint64SOFT
*,ALint64SOFT
*,ALint64SOFT
*);
56 typedef void (AL_APIENTRY
*LPALGETSOURCEI64VSOFT
)(ALuint
,ALenum
,ALint64SOFT
*);
57 #ifdef AL_ALEXT_PROTOTYPES
58 AL_API
void AL_APIENTRY
alGetSourcedSOFT(ALuint source
, ALenum param
, ALdouble
*value
);
59 AL_API
void AL_APIENTRY
alGetSource3dSOFT(ALuint source
, ALenum param
, ALdouble
*value1
, ALdouble
*value2
, ALdouble
*value3
);
60 AL_API
void AL_APIENTRY
alGetSourcedvSOFT(ALuint source
, ALenum param
, ALdouble
*values
);
61 AL_API
void AL_APIENTRY
alGetSourcei64SOFT(ALuint source
, ALenum param
, ALint64SOFT
*value
);
62 AL_API
void AL_APIENTRY
alGetSource3i64SOFT(ALuint source
, ALenum param
, ALint64SOFT
*value1
, ALint64SOFT
*value2
, ALint64SOFT
*value3
);
63 AL_API
void AL_APIENTRY
alGetSourcei64vSOFT(ALuint source
, ALenum param
, ALint64SOFT
*values
);
68 #if defined(HAVE_STDINT_H)
70 typedef int64_t ALint64
;
71 typedef uint64_t ALuint64
;
72 #elif defined(HAVE___INT64)
73 typedef __int64 ALint64
;
74 typedef unsigned __int64 ALuint64
;
75 #elif (SIZEOF_LONG == 8)
77 typedef unsigned long ALuint64
;
78 #elif (SIZEOF_LONG_LONG == 8)
79 typedef long long ALint64
;
80 typedef unsigned long long ALuint64
;
83 typedef ptrdiff_t ALintptrEXT
;
84 typedef ptrdiff_t ALsizeiptrEXT
;
86 #define MAKEU64(x,y) (((ALuint64)(x)<<32)|(ALuint64)(y))
88 #ifdef HAVE_GCC_FORMAT
89 #define PRINTF_STYLE(x, y) __attribute__((format(printf, (x), (y))))
91 #define PRINTF_STYLE(x, y)
94 #if defined(HAVE_RESTRICT)
95 #define RESTRICT restrict
96 #elif defined(HAVE___RESTRICT)
97 #define RESTRICT __restrict
105 ALubyte b
[sizeof(ALuint
)];
106 } EndianTest
= { 1 };
107 #define IS_LITTLE_ENDIAN (EndianTest.b[0] == 1)
109 #define COUNTOF(x) (sizeof((x))/sizeof((x)[0]))
115 typedef DWORD pthread_key_t
;
116 int pthread_key_create(pthread_key_t
*key
, void (*callback
)(void*));
117 int pthread_key_delete(pthread_key_t key
);
118 void *pthread_getspecific(pthread_key_t key
);
119 int pthread_setspecific(pthread_key_t key
, void *val
);
121 #define HAVE_DYNLOAD 1
122 void *LoadLib(const char *name
);
123 void CloseLib(void *handle
);
124 void *GetSymbol(void *handle
, const char *name
);
126 WCHAR
*strdupW(const WCHAR
*str
);
128 typedef LONG pthread_once_t
;
129 #define PTHREAD_ONCE_INIT 0
130 void pthread_once(pthread_once_t
*once
, void (*callback
)(void));
132 static __inline
int sched_yield(void)
133 { SwitchToThread(); return 0; }
140 #include <sys/time.h>
144 #define IsBadWritePtr(a,b) ((a) == NULL && (b) != 0)
146 typedef pthread_mutex_t CRITICAL_SECTION
;
147 void InitializeCriticalSection(CRITICAL_SECTION
*cs
);
148 void DeleteCriticalSection(CRITICAL_SECTION
*cs
);
149 void EnterCriticalSection(CRITICAL_SECTION
*cs
);
150 void LeaveCriticalSection(CRITICAL_SECTION
*cs
);
152 ALuint
timeGetTime(void);
153 void Sleep(ALuint t
);
155 #if defined(HAVE_DLFCN_H)
156 #define HAVE_DYNLOAD 1
157 void *LoadLib(const char *name
);
158 void CloseLib(void *handle
);
159 void *GetSymbol(void *handle
, const char *name
);
164 typedef void *volatile XchgPtr
;
166 #if defined(__GNUC__) && (__GNUC__ > 4 || (__GNUC__ == 4 && __GNUC_MINOR__ >= 1))
167 typedef ALuint RefCount
;
168 static __inline RefCount
IncrementRef(volatile RefCount
*ptr
)
169 { return __sync_add_and_fetch(ptr
, 1); }
170 static __inline RefCount
DecrementRef(volatile RefCount
*ptr
)
171 { return __sync_sub_and_fetch(ptr
, 1); }
173 static __inline
int ExchangeInt(volatile int *ptr
, int newval
)
175 return __sync_lock_test_and_set(ptr
, newval
);
177 static __inline
void *ExchangePtr(XchgPtr
*ptr
, void *newval
)
179 return __sync_lock_test_and_set(ptr
, newval
);
181 static __inline ALboolean
CompExchangeInt(volatile int *ptr
, int oldval
, int newval
)
183 return __sync_bool_compare_and_swap(ptr
, oldval
, newval
);
185 static __inline ALboolean
CompExchangePtr(XchgPtr
*ptr
, void *oldval
, void *newval
)
187 return __sync_bool_compare_and_swap(ptr
, oldval
, newval
);
190 #elif defined(__GNUC__) && (defined(__i386__) || defined(__x86_64__))
192 static __inline
int xaddl(volatile int *dest
, int incr
)
195 __asm__
__volatile__("lock; xaddl %0,(%1)"
197 : "r" (dest
), "0" (incr
)
202 typedef int RefCount
;
203 static __inline RefCount
IncrementRef(volatile RefCount
*ptr
)
204 { return xaddl(ptr
, 1)+1; }
205 static __inline RefCount
DecrementRef(volatile RefCount
*ptr
)
206 { return xaddl(ptr
, -1)-1; }
208 static __inline
int ExchangeInt(volatile int *dest
, int newval
)
211 __asm__
__volatile__("lock; xchgl %0,(%1)"
213 : "r" (dest
), "0" (newval
)
218 static __inline ALboolean
CompExchangeInt(volatile int *dest
, int oldval
, int newval
)
221 __asm__
__volatile__("lock; cmpxchgl %2,(%1)"
223 : "r" (dest
), "r" (newval
), "0" (oldval
)
225 return ret
== oldval
;
228 static __inline
void *ExchangePtr(XchgPtr
*dest
, void *newval
)
231 __asm__
__volatile__(
233 "lock; xchgl %0,(%1)"
235 "lock; xchgq %0,(%1)"
238 : "r" (dest
), "0" (newval
)
244 static __inline ALboolean
CompExchangePtr(XchgPtr
*dest
, void *oldval
, void *newval
)
247 __asm__
__volatile__(
249 "lock; cmpxchgl %2,(%1)"
251 "lock; cmpxchgq %2,(%1)"
254 : "r" (dest
), "r" (newval
), "0" (oldval
)
257 return ret
== oldval
;
260 #elif defined(_WIN32)
262 typedef LONG RefCount
;
263 static __inline RefCount
IncrementRef(volatile RefCount
*ptr
)
264 { return InterlockedIncrement(ptr
); }
265 static __inline RefCount
DecrementRef(volatile RefCount
*ptr
)
266 { return InterlockedDecrement(ptr
); }
268 extern ALbyte LONG_size_does_not_match_int
[(sizeof(LONG
)==sizeof(int))?1:-1];
270 static __inline
int ExchangeInt(volatile int *ptr
, int newval
)
276 return InterlockedExchange(u
.l
, newval
);
278 static __inline
void *ExchangePtr(XchgPtr
*ptr
, void *newval
)
280 return InterlockedExchangePointer(ptr
, newval
);
282 static __inline ALboolean
CompExchangeInt(volatile int *ptr
, int oldval
, int newval
)
288 return InterlockedCompareExchange(u
.l
, newval
, oldval
) == oldval
;
290 static __inline ALboolean
CompExchangePtr(XchgPtr
*ptr
, void *oldval
, void *newval
)
292 return InterlockedCompareExchangePointer(ptr
, newval
, oldval
) == oldval
;
295 #elif defined(__APPLE__)
297 #include <libkern/OSAtomic.h>
299 typedef int32_t RefCount
;
300 static __inline RefCount
IncrementRef(volatile RefCount
*ptr
)
301 { return OSAtomicIncrement32Barrier(ptr
); }
302 static __inline RefCount
DecrementRef(volatile RefCount
*ptr
)
303 { return OSAtomicDecrement32Barrier(ptr
); }
305 static __inline
int ExchangeInt(volatile int *ptr
, int newval
)
307 /* Really? No regular old atomic swap? */
311 } while(!OSAtomicCompareAndSwap32Barrier(oldval
, newval
, ptr
));
314 static __inline
void *ExchangePtr(XchgPtr
*ptr
, void *newval
)
319 } while(!OSAtomicCompareAndSwapPtrBarrier(oldval
, newval
, ptr
));
322 static __inline ALboolean
CompExchangeInt(volatile int *ptr
, int oldval
, int newval
)
324 return OSAtomicCompareAndSwap32Barrier(oldval
, newval
, ptr
);
326 static __inline ALboolean
CompExchangePtr(XchgPtr
*ptr
, void *oldval
, void *newval
)
328 return OSAtomicCompareAndSwapPtrBarrier(oldval
, newval
, ptr
);
332 #error "No atomic functions available on this platform!"
333 typedef ALuint RefCount
;
338 volatile RefCount read_count
;
339 volatile RefCount write_count
;
340 volatile ALenum read_lock
;
341 volatile ALenum read_entry_lock
;
342 volatile ALenum write_lock
;
345 void RWLockInit(RWLock
*lock
);
346 void ReadLock(RWLock
*lock
);
347 void ReadUnlock(RWLock
*lock
);
348 void WriteLock(RWLock
*lock
);
349 void WriteUnlock(RWLock
*lock
);
352 typedef struct UIntMap
{
362 extern UIntMap TlsDestructor
;
364 void InitUIntMap(UIntMap
*map
, ALsizei limit
);
365 void ResetUIntMap(UIntMap
*map
);
366 ALenum
InsertUIntMapEntry(UIntMap
*map
, ALuint key
, ALvoid
*value
);
367 ALvoid
*RemoveUIntMapKey(UIntMap
*map
, ALuint key
);
368 ALvoid
*LookupUIntMapKey(UIntMap
*map
, ALuint key
);
370 static __inline
void LockUIntMapRead(UIntMap
*map
)
371 { ReadLock(&map
->lock
); }
372 static __inline
void UnlockUIntMapRead(UIntMap
*map
)
373 { ReadUnlock(&map
->lock
); }
374 static __inline
void LockUIntMapWrite(UIntMap
*map
)
375 { WriteLock(&map
->lock
); }
376 static __inline
void UnlockUIntMapWrite(UIntMap
*map
)
377 { WriteUnlock(&map
->lock
); }
379 #include "alListener.h"
388 #define DEFAULT_OUTPUT_RATE (44100)
389 #define MIN_OUTPUT_RATE (8000)
392 // Find the next power-of-2 for non-power-of-2 numbers.
393 static __inline ALuint
NextPowerOf2(ALuint value
)
409 /* Fast float-to-int conversion. Assumes the FPU is already in round-to-zero
411 static __inline ALint
fastf2i(ALfloat f
)
414 #if defined(_MSC_VER) && defined(_M_IX86)
417 #elif defined(__GNUC__) && (defined(__i386__) || defined(__x86_64__))
418 __asm__
__volatile__("flds %1\n\t"
428 /* Fast float-to-uint conversion. Assumes the FPU is already in round-to-zero
430 static __inline ALuint
fastf2u(ALfloat f
)
431 { return fastf2i(f
); }
440 ALCenum (*OpenPlayback
)(ALCdevice
*, const ALCchar
*);
441 void (*ClosePlayback
)(ALCdevice
*);
442 ALCboolean (*ResetPlayback
)(ALCdevice
*);
443 ALCboolean (*StartPlayback
)(ALCdevice
*);
444 void (*StopPlayback
)(ALCdevice
*);
446 ALCenum (*OpenCapture
)(ALCdevice
*, const ALCchar
*);
447 void (*CloseCapture
)(ALCdevice
*);
448 void (*StartCapture
)(ALCdevice
*);
449 void (*StopCapture
)(ALCdevice
*);
450 ALCenum (*CaptureSamples
)(ALCdevice
*, void*, ALCuint
);
451 ALCuint (*AvailableSamples
)(ALCdevice
*);
453 void (*Lock
)(ALCdevice
*);
454 void (*Unlock
)(ALCdevice
*);
456 ALint64 (*GetLatency
)(ALCdevice
*);
461 ALCboolean (*Init
)(BackendFuncs
*);
462 void (*Deinit
)(void);
463 void (*Probe
)(enum DevProbe
);
467 ALCboolean
alc_alsa_init(BackendFuncs
*func_list
);
468 void alc_alsa_deinit(void);
469 void alc_alsa_probe(enum DevProbe type
);
470 ALCboolean
alc_oss_init(BackendFuncs
*func_list
);
471 void alc_oss_deinit(void);
472 void alc_oss_probe(enum DevProbe type
);
473 ALCboolean
alc_solaris_init(BackendFuncs
*func_list
);
474 void alc_solaris_deinit(void);
475 void alc_solaris_probe(enum DevProbe type
);
476 ALCboolean
alc_sndio_init(BackendFuncs
*func_list
);
477 void alc_sndio_deinit(void);
478 void alc_sndio_probe(enum DevProbe type
);
479 ALCboolean
alcMMDevApiInit(BackendFuncs
*func_list
);
480 void alcMMDevApiDeinit(void);
481 void alcMMDevApiProbe(enum DevProbe type
);
482 ALCboolean
alcDSoundInit(BackendFuncs
*func_list
);
483 void alcDSoundDeinit(void);
484 void alcDSoundProbe(enum DevProbe type
);
485 ALCboolean
alcWinMMInit(BackendFuncs
*FuncList
);
486 void alcWinMMDeinit(void);
487 void alcWinMMProbe(enum DevProbe type
);
488 ALCboolean
alc_pa_init(BackendFuncs
*func_list
);
489 void alc_pa_deinit(void);
490 void alc_pa_probe(enum DevProbe type
);
491 ALCboolean
alc_wave_init(BackendFuncs
*func_list
);
492 void alc_wave_deinit(void);
493 void alc_wave_probe(enum DevProbe type
);
494 ALCboolean
alc_pulse_init(BackendFuncs
*func_list
);
495 void alc_pulse_deinit(void);
496 void alc_pulse_probe(enum DevProbe type
);
497 ALCboolean
alc_ca_init(BackendFuncs
*func_list
);
498 void alc_ca_deinit(void);
499 void alc_ca_probe(enum DevProbe type
);
500 ALCboolean
alc_opensl_init(BackendFuncs
*func_list
);
501 void alc_opensl_deinit(void);
502 void alc_opensl_probe(enum DevProbe type
);
503 ALCboolean
alc_null_init(BackendFuncs
*func_list
);
504 void alc_null_deinit(void);
505 void alc_null_probe(enum DevProbe type
);
506 ALCboolean
alc_loopback_init(BackendFuncs
*func_list
);
507 void alc_loopback_deinit(void);
508 void alc_loopback_probe(enum DevProbe type
);
512 InverseDistanceClamped
= AL_INVERSE_DISTANCE_CLAMPED
,
513 LinearDistanceClamped
= AL_LINEAR_DISTANCE_CLAMPED
,
514 ExponentDistanceClamped
= AL_EXPONENT_DISTANCE_CLAMPED
,
515 InverseDistance
= AL_INVERSE_DISTANCE
,
516 LinearDistance
= AL_LINEAR_DISTANCE
,
517 ExponentDistance
= AL_EXPONENT_DISTANCE
,
518 DisableDistance
= AL_NONE
,
520 DefaultDistanceModel
= InverseDistanceClamped
548 DevFmtByte
= ALC_BYTE_SOFT
,
549 DevFmtUByte
= ALC_UNSIGNED_BYTE_SOFT
,
550 DevFmtShort
= ALC_SHORT_SOFT
,
551 DevFmtUShort
= ALC_UNSIGNED_SHORT_SOFT
,
552 DevFmtInt
= ALC_INT_SOFT
,
553 DevFmtUInt
= ALC_UNSIGNED_INT_SOFT
,
554 DevFmtFloat
= ALC_FLOAT_SOFT
,
556 DevFmtTypeDefault
= DevFmtFloat
558 enum DevFmtChannels
{
559 DevFmtMono
= ALC_MONO_SOFT
,
560 DevFmtStereo
= ALC_STEREO_SOFT
,
561 DevFmtQuad
= ALC_QUAD_SOFT
,
562 DevFmtX51
= ALC_5POINT1_SOFT
,
563 DevFmtX61
= ALC_6POINT1_SOFT
,
564 DevFmtX71
= ALC_7POINT1_SOFT
,
566 /* Similar to 5.1, except using the side channels instead of back */
567 DevFmtX51Side
= 0x80000000,
569 DevFmtChannelsDefault
= DevFmtStereo
572 ALuint
BytesFromDevFmt(enum DevFmtType type
);
573 ALuint
ChannelsFromDevFmt(enum DevFmtChannels chans
);
574 static __inline ALuint
FrameSizeFromDevFmt(enum DevFmtChannels chans
,
575 enum DevFmtType type
)
577 return ChannelsFromDevFmt(chans
) * BytesFromDevFmt(type
);
581 extern const struct EffectList
{
596 /* Size for temporary storage of buffer data, in ALfloats. Larger values need
597 * more stack, while smaller values may need more iterations. The value needs
598 * to be a sensible size, however, as it constrains the max stepping value used
599 * for mixing, as well as the maximum number of samples per mixing iteration.
600 * The mixer requires being able to do two samplings per mixing loop. A 16KB
601 * buffer can hold 512 sample frames for a 7.1 float buffer. With the cubic
602 * resampler (which requires 3 padding sample frames), this limits the maximum
603 * step to about 508. This means that buffer_freq*source_pitch cannot exceed
604 * device_freq*508 for an 8-channel 32-bit buffer.
607 #define BUFFERSIZE 4096
611 struct ALCdevice_struct
613 volatile RefCount ref
;
615 ALCboolean Connected
;
616 enum DeviceType Type
;
618 CRITICAL_SECTION Mutex
;
623 enum DevFmtChannels FmtChans
;
624 enum DevFmtType FmtType
;
628 volatile ALCenum LastError
;
630 // Maximum number of sources that can be created
631 ALuint MaxNoOfSources
;
632 // Maximum number of slots that can be created
633 ALuint AuxiliaryEffectSlotMax
;
635 ALCuint NumMonoSources
;
636 ALCuint NumStereoSources
;
639 // Map of Buffers for this device
642 // Map of Effects for this device
645 // Map of Filters for this device
648 /* HRTF filter tables */
649 const struct Hrtf
*Hrtf
;
651 // Stereo-to-binaural filter
658 enum Channel DevChannels
[MaxChannels
];
660 enum Channel Speaker2Chan
[MaxChannels
];
661 ALfloat SpeakerAngle
[MaxChannels
];
664 // Dry path buffer mix
665 ALIGN(16) ALfloat DryBuffer
[MaxChannels
][BUFFERSIZE
];
667 ALIGN(16) ALfloat ClickRemoval
[MaxChannels
];
668 ALIGN(16) ALfloat PendingClicks
[MaxChannels
];
670 /* Default effect slot */
671 struct ALeffectslot
*DefaultSlot
;
673 // Contexts created on this device
674 ALCcontext
*volatile ContextList
;
677 void *ExtraData
; // For the backend's use
679 ALCdevice
*volatile next
;
682 #define ALCdevice_OpenPlayback(a,b) ((a)->Funcs->OpenPlayback((a), (b)))
683 #define ALCdevice_ClosePlayback(a) ((a)->Funcs->ClosePlayback((a)))
684 #define ALCdevice_ResetPlayback(a) ((a)->Funcs->ResetPlayback((a)))
685 #define ALCdevice_StartPlayback(a) ((a)->Funcs->StartPlayback((a)))
686 #define ALCdevice_StopPlayback(a) ((a)->Funcs->StopPlayback((a)))
687 #define ALCdevice_OpenCapture(a,b) ((a)->Funcs->OpenCapture((a), (b)))
688 #define ALCdevice_CloseCapture(a) ((a)->Funcs->CloseCapture((a)))
689 #define ALCdevice_StartCapture(a) ((a)->Funcs->StartCapture((a)))
690 #define ALCdevice_StopCapture(a) ((a)->Funcs->StopCapture((a)))
691 #define ALCdevice_CaptureSamples(a,b,c) ((a)->Funcs->CaptureSamples((a), (b), (c)))
692 #define ALCdevice_AvailableSamples(a) ((a)->Funcs->AvailableSamples((a)))
693 #define ALCdevice_Lock(a) ((a)->Funcs->Lock((a)))
694 #define ALCdevice_Unlock(a) ((a)->Funcs->Unlock((a)))
695 #define ALCdevice_GetLatency(a) ((a)->Funcs->GetLatency((a)))
697 // Frequency was requested by the app or config file
698 #define DEVICE_FREQUENCY_REQUEST (1<<1)
699 // Channel configuration was requested by the config file
700 #define DEVICE_CHANNELS_REQUEST (1<<2)
701 // Sample type was requested by the config file
702 #define DEVICE_SAMPLE_TYPE_REQUEST (1<<3)
704 // Stereo sources cover 120-degree angles around +/-90
705 #define DEVICE_WIDE_STEREO (1<<16)
707 // Specifies if the device is currently running
708 #define DEVICE_RUNNING (1<<31)
710 #define LookupBuffer(m, k) ((struct ALbuffer*)LookupUIntMapKey(&(m)->BufferMap, (k)))
711 #define LookupEffect(m, k) ((struct ALeffect*)LookupUIntMapKey(&(m)->EffectMap, (k)))
712 #define LookupFilter(m, k) ((struct ALfilter*)LookupUIntMapKey(&(m)->FilterMap, (k)))
713 #define RemoveBuffer(m, k) ((struct ALbuffer*)RemoveUIntMapKey(&(m)->BufferMap, (k)))
714 #define RemoveEffect(m, k) ((struct ALeffect*)RemoveUIntMapKey(&(m)->EffectMap, (k)))
715 #define RemoveFilter(m, k) ((struct ALfilter*)RemoveUIntMapKey(&(m)->FilterMap, (k)))
718 struct ALCcontext_struct
720 volatile RefCount ref
;
725 UIntMap EffectSlotMap
;
729 volatile ALenum UpdateSources
;
731 volatile enum DistanceModel DistanceModel
;
732 volatile ALboolean SourceDistanceModel
;
734 volatile ALfloat DopplerFactor
;
735 volatile ALfloat DopplerVelocity
;
736 volatile ALfloat SpeedOfSound
;
737 volatile ALenum DeferUpdates
;
739 struct ALsource
**ActiveSources
;
740 ALsizei ActiveSourceCount
;
741 ALsizei MaxActiveSources
;
743 struct ALeffectslot
**ActiveEffectSlots
;
744 ALsizei ActiveEffectSlotCount
;
745 ALsizei MaxActiveEffectSlots
;
748 const ALCchar
*ExtensionList
;
750 ALCcontext
*volatile next
;
753 #define LookupSource(m, k) ((struct ALsource*)LookupUIntMapKey(&(m)->SourceMap, (k)))
754 #define LookupEffectSlot(m, k) ((struct ALeffectslot*)LookupUIntMapKey(&(m)->EffectSlotMap, (k)))
755 #define RemoveSource(m, k) ((struct ALsource*)RemoveUIntMapKey(&(m)->SourceMap, (k)))
756 #define RemoveEffectSlot(m, k) ((struct ALeffectslot*)RemoveUIntMapKey(&(m)->EffectSlotMap, (k)))
759 ALCcontext
*GetContextRef(void);
761 void ALCcontext_IncRef(ALCcontext
*context
);
762 void ALCcontext_DecRef(ALCcontext
*context
);
764 void AppendAllDevicesList(const ALCchar
*name
);
765 void AppendCaptureDeviceList(const ALCchar
*name
);
767 void ALCdevice_LockDefault(ALCdevice
*device
);
768 void ALCdevice_UnlockDefault(ALCdevice
*device
);
769 ALint64
ALCdevice_GetLatencyDefault(ALCdevice
*device
);
771 static __inline
void LockContext(ALCcontext
*context
)
772 { ALCdevice_Lock(context
->Device
); }
773 static __inline
void UnlockContext(ALCcontext
*context
)
774 { ALCdevice_Unlock(context
->Device
); }
777 void *al_malloc(size_t alignment
, size_t size
);
778 void *al_calloc(size_t alignment
, size_t size
);
779 void al_free(void *ptr
);
784 void SetMixerFPUMode(FPUCtl
*ctl
);
785 void RestoreFPUMode(const FPUCtl
*ctl
);
787 ALvoid
*StartThread(ALuint (*func
)(ALvoid
*), ALvoid
*ptr
);
788 ALuint
StopThread(ALvoid
*thread
);
790 typedef struct RingBuffer RingBuffer
;
791 RingBuffer
*CreateRingBuffer(ALsizei frame_size
, ALsizei length
);
792 void DestroyRingBuffer(RingBuffer
*ring
);
793 ALsizei
RingBufferSize(RingBuffer
*ring
);
794 void WriteRingBuffer(RingBuffer
*ring
, const ALubyte
*data
, ALsizei len
);
795 void ReadRingBuffer(RingBuffer
*ring
, ALubyte
*data
, ALsizei len
);
797 void ReadALConfig(void);
798 void FreeALConfig(void);
799 int ConfigValueExists(const char *blockName
, const char *keyName
);
800 const char *GetConfigValue(const char *blockName
, const char *keyName
, const char *def
);
801 int GetConfigValueBool(const char *blockName
, const char *keyName
, int def
);
802 int ConfigValueStr(const char *blockName
, const char *keyName
, const char **ret
);
803 int ConfigValueInt(const char *blockName
, const char *keyName
, int *ret
);
804 int ConfigValueUInt(const char *blockName
, const char *keyName
, unsigned int *ret
);
805 int ConfigValueFloat(const char *blockName
, const char *keyName
, float *ret
);
807 void SetRTPriority(void);
809 void SetDefaultChannelOrder(ALCdevice
*device
);
810 void SetDefaultWFXChannelOrder(ALCdevice
*device
);
812 const ALCchar
*DevFmtTypeString(enum DevFmtType type
);
813 const ALCchar
*DevFmtChannelsString(enum DevFmtChannels chans
);
815 #define HRIR_BITS (7)
816 #define HRIR_LENGTH (1<<HRIR_BITS)
817 #define HRIR_MASK (HRIR_LENGTH-1)
818 #define HRTFDELAY_BITS (20)
819 #define HRTFDELAY_FRACONE (1<<HRTFDELAY_BITS)
820 #define HRTFDELAY_MASK (HRTFDELAY_FRACONE-1)
821 const struct Hrtf
*GetHrtf(ALCdevice
*device
);
822 void FreeHrtfs(void);
823 ALuint
GetHrtfIrSize (const struct Hrtf
*Hrtf
);
824 ALfloat
CalcHrtfDelta(ALfloat oldGain
, ALfloat newGain
, const ALfloat olddir
[3], const ALfloat newdir
[3]);
825 void GetLerpedHrtfCoeffs(const struct Hrtf
*Hrtf
, ALfloat elevation
, ALfloat azimuth
, ALfloat gain
, ALfloat (*coeffs
)[2], ALuint
*delays
);
826 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
);
828 void al_print(const char *func
, const char *fmt
, ...) PRINTF_STYLE(2,3);
829 #define AL_PRINT(...) al_print(__FUNCTION__, __VA_ARGS__)
831 extern FILE *LogFile
;
839 extern enum LogLevel LogLevel
;
841 #define TRACEREF(...) do { \
842 if(LogLevel >= LogRef) \
843 AL_PRINT(__VA_ARGS__); \
846 #define TRACE(...) do { \
847 if(LogLevel >= LogTrace) \
848 AL_PRINT(__VA_ARGS__); \
851 #define WARN(...) do { \
852 if(LogLevel >= LogWarning) \
853 AL_PRINT(__VA_ARGS__); \
856 #define ERR(...) do { \
857 if(LogLevel >= LogError) \
858 AL_PRINT(__VA_ARGS__); \
862 extern ALint RTPrioLevel
;
865 extern ALuint CPUCapFlags
;
871 void FillCPUCaps(ALuint capfilter
);
875 * Starts a try block. Must not be nested within another try block within the
878 #define al_try do { \
883 * After a try or another catch block, runs the next block if the given value
886 #define al_catch(val) else if(_al_err == (val))
888 * After a try or catch block, runs the next block for any value thrown and not
891 #define al_catchany() else
892 /** Marks the end of the final catch (or the try) block. */
893 #define al_endtry } while(0)
896 * The given integer value is "thrown" so as to be caught by a catch block.
897 * Must be called in a try block within the same function. The value must not
900 #define al_throw(e) do { \
902 assert(_al_err != 0); \
903 goto _al_try_label; \
905 /** Sets an AL error on the given context, before throwing the error code. */
906 #define al_throwerr(ctx, err) do { \
907 alSetError((ctx), (err)); \
912 * Throws an AL_INVALID_VALUE error with the given ctx if the given condition
915 #define CHECK_VALUE(ctx, cond) do { \
917 al_throwerr((ctx), AL_INVALID_VALUE); \