16 #if defined(HAVE_STDINT_H)
18 typedef int64_t ALint64
;
19 typedef uint64_t ALuint64
;
20 #elif defined(HAVE___INT64)
21 typedef __int64 ALint64
;
22 typedef unsigned __int64 ALuint64
;
23 #elif (SIZEOF_LONG == 8)
25 typedef unsigned long ALuint64
;
26 #elif (SIZEOF_LONG_LONG == 8)
27 typedef long long ALint64
;
28 typedef unsigned long long ALuint64
;
31 #ifdef HAVE_GCC_FORMAT
32 #define PRINTF_STYLE(x, y) __attribute__((format(printf, (x), (y))))
34 #define PRINTF_STYLE(x, y)
40 #define _WIN32_WINNT 0x0500
44 typedef DWORD tls_type
;
45 #define tls_create(x) (*(x) = TlsAlloc())
46 #define tls_delete(x) TlsFree((x))
47 #define tls_get(x) TlsGetValue((x))
48 #define tls_set(x, a) TlsSetValue((x), (a))
55 #ifdef HAVE_PTHREAD_NP_H
56 #include <pthread_np.h>
62 #define IsBadWritePtr(a,b) ((a) == NULL && (b) != 0)
64 typedef pthread_key_t tls_type
;
65 #define tls_create(x) pthread_key_create((x), NULL)
66 #define tls_delete(x) pthread_key_delete((x))
67 #define tls_get(x) pthread_getspecific((x))
68 #define tls_set(x, a) pthread_setspecific((x), (a))
70 typedef pthread_mutex_t CRITICAL_SECTION
;
71 static inline void EnterCriticalSection(CRITICAL_SECTION
*cs
)
74 ret
= pthread_mutex_lock(cs
);
77 static inline void LeaveCriticalSection(CRITICAL_SECTION
*cs
)
80 ret
= pthread_mutex_unlock(cs
);
83 static inline void InitializeCriticalSection(CRITICAL_SECTION
*cs
)
85 pthread_mutexattr_t attrib
;
88 ret
= pthread_mutexattr_init(&attrib
);
91 ret
= pthread_mutexattr_settype(&attrib
, PTHREAD_MUTEX_RECURSIVE
);
92 #ifdef HAVE_PTHREAD_NP_H
94 ret
= pthread_mutexattr_setkind_np(&attrib
, PTHREAD_MUTEX_RECURSIVE
);
97 ret
= pthread_mutex_init(cs
, &attrib
);
100 pthread_mutexattr_destroy(&attrib
);
103 static inline void DeleteCriticalSection(CRITICAL_SECTION
*cs
)
106 ret
= pthread_mutex_destroy(cs
);
110 /* NOTE: This wrapper isn't quite accurate as it returns an ALuint, as opposed
111 * to the expected DWORD. Both are defined as unsigned 32-bit types, however.
112 * Additionally, Win32 is supposed to measure the time since Windows started,
113 * as opposed to the actual time. */
114 static inline ALuint
timeGetTime(void)
117 #if _POSIX_TIMERS > 0
120 ret
= clock_gettime(CLOCK_REALTIME
, &ts
);
123 return ts
.tv_nsec
/1000000 + ts
.tv_sec
*1000;
127 ret
= gettimeofday(&tv
, NULL
);
130 return tv
.tv_usec
/1000 + tv
.tv_sec
*1000;
134 static inline void Sleep(ALuint t
)
136 struct timespec tv
, rem
;
137 tv
.tv_nsec
= (t
*1000000)%1000000000;
140 while(nanosleep(&tv
, &rem
) == -1 && errno
== EINTR
)
143 #define min(x,y) (((x)<(y))?(x):(y))
144 #define max(x,y) (((x)>(y))?(x):(y))
147 #include "alListener.h"
155 #define SWMIXER_OUTPUT_RATE 44100
157 #define SPEEDOFSOUNDMETRESPERSEC (343.3f)
158 #define AIRABSORBGAINDBHF (-0.05f)
160 #define LOWPASSFREQCUTOFF (5000)
162 #define DEFAULT_HEAD_DAMPEN (0.25f)
165 // Find the next power-of-2 for non-power-of-2 numbers.
166 static __inline ALuint
NextPowerOf2(ALuint value
)
184 ALCboolean (*OpenPlayback
)(ALCdevice
*, const ALCchar
*);
185 void (*ClosePlayback
)(ALCdevice
*);
186 ALCboolean (*ResetPlayback
)(ALCdevice
*);
187 void (*StopPlayback
)(ALCdevice
*);
189 ALCboolean (*OpenCapture
)(ALCdevice
*, const ALCchar
*);
190 void (*CloseCapture
)(ALCdevice
*);
191 void (*StartCapture
)(ALCdevice
*);
192 void (*StopCapture
)(ALCdevice
*);
193 void (*CaptureSamples
)(ALCdevice
*, void*, ALCuint
);
194 ALCuint (*AvailableSamples
)(ALCdevice
*);
203 void alc_alsa_init(BackendFuncs
*func_list
);
204 void alc_alsa_deinit(void);
205 void alc_alsa_probe(int type
);
206 void alc_oss_init(BackendFuncs
*func_list
);
207 void alc_oss_deinit(void);
208 void alc_oss_probe(int type
);
209 void alc_solaris_init(BackendFuncs
*func_list
);
210 void alc_solaris_deinit(void);
211 void alc_solaris_probe(int type
);
212 void alcDSoundInit(BackendFuncs
*func_list
);
213 void alcDSoundDeinit(void);
214 void alcDSoundProbe(int type
);
215 void alcWinMMInit(BackendFuncs
*FuncList
);
216 void alcWinMMDeinit(void);
217 void alcWinMMProbe(int type
);
218 void alc_pa_init(BackendFuncs
*func_list
);
219 void alc_pa_deinit(void);
220 void alc_pa_probe(int type
);
221 void alc_wave_init(BackendFuncs
*func_list
);
222 void alc_wave_deinit(void);
223 void alc_wave_probe(int type
);
224 void alc_pulse_init(BackendFuncs
*func_list
);
225 void alc_pulse_deinit(void);
226 void alc_pulse_probe(int type
);
229 struct ALCdevice_struct
231 ALCboolean Connected
;
232 ALboolean IsCaptureDevice
;
239 ALCchar
*szDeviceName
;
243 // Maximum number of sources that can be created
244 ALuint MaxNoOfSources
;
245 // Maximum number of slots that can be created
246 ALuint AuxiliaryEffectSlotMax
;
248 ALint lNumMonoSources
;
249 ALint lNumStereoSources
;
252 // Linked List of Buffers for this device
253 struct ALbuffer
*BufferList
;
256 // Linked List of Effects for this device
257 struct ALeffect
*EffectList
;
260 // Linked List of Filters for this device
261 struct ALfilter
*FilterList
;
264 // Linked List of Databuffers for this device
265 struct ALdatabuffer
*DatabufferList
;
266 ALuint DatabufferCount
;
268 // Stereo-to-binaural filter
272 // Simulated dampening from head occlusion
275 // Dry path buffer mix
276 float DryBuffer
[BUFFERSIZE
][OUTPUTCHANNELS
];
278 Channel DevChannels
[OUTPUTCHANNELS
];
280 // Contexts created on this device
281 ALCcontext
**Contexts
;
285 void *ExtraData
; // For the backend's use
290 #define ALCdevice_OpenPlayback(a,b) ((a)->Funcs->OpenPlayback((a), (b)))
291 #define ALCdevice_ClosePlayback(a) ((a)->Funcs->ClosePlayback((a)))
292 #define ALCdevice_ResetPlayback(a) ((a)->Funcs->ResetPlayback((a)))
293 #define ALCdevice_StopPlayback(a) ((a)->Funcs->StopPlayback((a)))
294 #define ALCdevice_OpenCapture(a,b) ((a)->Funcs->OpenCapture((a), (b)))
295 #define ALCdevice_CloseCapture(a) ((a)->Funcs->CloseCapture((a)))
296 #define ALCdevice_StartCapture(a) ((a)->Funcs->StartCapture((a)))
297 #define ALCdevice_StopCapture(a) ((a)->Funcs->StopCapture((a)))
298 #define ALCdevice_CaptureSamples(a,b,c) ((a)->Funcs->CaptureSamples((a), (b), (c)))
299 #define ALCdevice_AvailableSamples(a) ((a)->Funcs->AvailableSamples((a)))
301 struct ALCcontext_struct
305 struct ALsource
*SourceList
;
308 struct ALeffectslot
*EffectSlotList
;
309 ALuint EffectSlotCount
;
311 struct ALdatabuffer
*SampleSource
;
312 struct ALdatabuffer
*SampleSink
;
319 ALenum DistanceModel
;
320 ALboolean SourceDistanceModel
;
322 ALfloat DopplerFactor
;
323 ALfloat DopplerVelocity
;
324 ALfloat flSpeedOfSound
;
326 ALfloat PanningLUT
[OUTPUTCHANNELS
* LUT_NUM
];
329 ALfloat ChannelMatrix
[OUTPUTCHANNELS
][OUTPUTCHANNELS
];
332 const ALCchar
*ExtensionList
;
337 extern ALint RTPrioLevel
;
339 ALCvoid
ReleaseALC(ALCvoid
);
341 void AppendDeviceList(const ALCchar
*name
);
342 void AppendAllDeviceList(const ALCchar
*name
);
343 void AppendCaptureDeviceList(const ALCchar
*name
);
345 ALCvoid
alcSetError(ALCdevice
*device
, ALenum errorCode
);
347 ALCvoid
SuspendContext(ALCcontext
*context
);
348 ALCvoid
ProcessContext(ALCcontext
*context
);
350 ALvoid
*StartThread(ALuint (*func
)(ALvoid
*), ALvoid
*ptr
);
351 ALuint
StopThread(ALvoid
*thread
);
353 ALCcontext
*GetContextSuspended(void);
355 typedef struct RingBuffer RingBuffer
;
356 RingBuffer
*CreateRingBuffer(ALsizei frame_size
, ALsizei length
);
357 void DestroyRingBuffer(RingBuffer
*ring
);
358 ALsizei
RingBufferSize(RingBuffer
*ring
);
359 void WriteRingBuffer(RingBuffer
*ring
, const ALubyte
*data
, ALsizei len
);
360 void ReadRingBuffer(RingBuffer
*ring
, ALubyte
*data
, ALsizei len
);
362 void ReadALConfig(void);
363 void FreeALConfig(void);
364 int ConfigValueExists(const char *blockName
, const char *keyName
);
365 const char *GetConfigValue(const char *blockName
, const char *keyName
, const char *def
);
366 int GetConfigValueInt(const char *blockName
, const char *keyName
, int def
);
367 float GetConfigValueFloat(const char *blockName
, const char *keyName
, float def
);
368 int GetConfigValueBool(const char *blockName
, const char *keyName
, int def
);
370 void EnableRTPrio(ALint level
);
372 void SetDefaultChannelOrder(ALCdevice
*device
);
373 void SetDefaultWFXChannelOrder(ALCdevice
*device
);
375 void al_print(const char *fname
, unsigned int line
, const char *fmt
, ...)
377 #define AL_PRINT(...) al_print(__FILE__, __LINE__, __VA_ARGS__)
379 ALCboolean ALCAPIENTRY
alcMakeCurrent(ALCcontext
*context
);
380 ALCcontext
* ALCAPIENTRY
alcGetThreadContext(void);
382 #define DECL_VERIFIER(name, type, field) \
383 static type* Verify##name(type *list, ALuint id) \
387 if(list->field == id) \