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 ALCuint NumMonoSources
;
249 ALCuint NumStereoSources
;
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 // Duplicate stereo sources on the side/rear channels
276 ALboolean DuplicateStereo
;
278 // Dry path buffer mix
279 float DryBuffer
[BUFFERSIZE
][OUTPUTCHANNELS
];
281 ALuint DevChannels
[OUTPUTCHANNELS
];
283 ALfloat ChannelMatrix
[OUTPUTCHANNELS
][OUTPUTCHANNELS
];
285 Channel Speaker2Chan
[OUTPUTCHANNELS
];
286 ALfloat PanningLUT
[OUTPUTCHANNELS
* LUT_NUM
];
289 // Contexts created on this device
290 ALCcontext
**Contexts
;
294 void *ExtraData
; // For the backend's use
299 #define ALCdevice_OpenPlayback(a,b) ((a)->Funcs->OpenPlayback((a), (b)))
300 #define ALCdevice_ClosePlayback(a) ((a)->Funcs->ClosePlayback((a)))
301 #define ALCdevice_ResetPlayback(a) ((a)->Funcs->ResetPlayback((a)))
302 #define ALCdevice_StopPlayback(a) ((a)->Funcs->StopPlayback((a)))
303 #define ALCdevice_OpenCapture(a,b) ((a)->Funcs->OpenCapture((a), (b)))
304 #define ALCdevice_CloseCapture(a) ((a)->Funcs->CloseCapture((a)))
305 #define ALCdevice_StartCapture(a) ((a)->Funcs->StartCapture((a)))
306 #define ALCdevice_StopCapture(a) ((a)->Funcs->StopCapture((a)))
307 #define ALCdevice_CaptureSamples(a,b,c) ((a)->Funcs->CaptureSamples((a), (b), (c)))
308 #define ALCdevice_AvailableSamples(a) ((a)->Funcs->AvailableSamples((a)))
310 struct ALCcontext_struct
314 struct ALsource
*SourceList
;
317 struct ALeffectslot
*EffectSlotList
;
318 ALuint EffectSlotCount
;
320 struct ALdatabuffer
*SampleSource
;
321 struct ALdatabuffer
*SampleSink
;
327 ALenum DistanceModel
;
328 ALboolean SourceDistanceModel
;
330 ALfloat DopplerFactor
;
331 ALfloat DopplerVelocity
;
332 ALfloat flSpeedOfSound
;
335 const ALCchar
*ExtensionList
;
340 extern ALint RTPrioLevel
;
342 ALCvoid
ReleaseALC(ALCvoid
);
344 void AppendDeviceList(const ALCchar
*name
);
345 void AppendAllDeviceList(const ALCchar
*name
);
346 void AppendCaptureDeviceList(const ALCchar
*name
);
348 ALCvoid
alcSetError(ALCdevice
*device
, ALenum errorCode
);
350 ALCvoid
SuspendContext(ALCcontext
*context
);
351 ALCvoid
ProcessContext(ALCcontext
*context
);
353 ALvoid
*StartThread(ALuint (*func
)(ALvoid
*), ALvoid
*ptr
);
354 ALuint
StopThread(ALvoid
*thread
);
356 ALCcontext
*GetContextSuspended(void);
358 typedef struct RingBuffer RingBuffer
;
359 RingBuffer
*CreateRingBuffer(ALsizei frame_size
, ALsizei length
);
360 void DestroyRingBuffer(RingBuffer
*ring
);
361 ALsizei
RingBufferSize(RingBuffer
*ring
);
362 void WriteRingBuffer(RingBuffer
*ring
, const ALubyte
*data
, ALsizei len
);
363 void ReadRingBuffer(RingBuffer
*ring
, ALubyte
*data
, ALsizei len
);
365 void ReadALConfig(void);
366 void FreeALConfig(void);
367 int ConfigValueExists(const char *blockName
, const char *keyName
);
368 const char *GetConfigValue(const char *blockName
, const char *keyName
, const char *def
);
369 int GetConfigValueInt(const char *blockName
, const char *keyName
, int def
);
370 float GetConfigValueFloat(const char *blockName
, const char *keyName
, float def
);
371 int GetConfigValueBool(const char *blockName
, const char *keyName
, int def
);
373 void EnableRTPrio(ALint level
);
375 void SetDefaultChannelOrder(ALCdevice
*device
);
376 void SetDefaultWFXChannelOrder(ALCdevice
*device
);
378 void al_print(const char *fname
, unsigned int line
, const char *fmt
, ...)
380 #define AL_PRINT(...) al_print(__FILE__, __LINE__, __VA_ARGS__)
382 #define DECL_VERIFIER(name, type, field) \
383 static type* Verify##name(type *list, ALuint id) \
385 while(list && list->field != id) \