19 #define _WIN32_WINNT 0x0500
23 typedef DWORD tls_type
;
24 #define tls_create(x) (*(x) = TlsAlloc())
25 #define tls_delete(x) TlsFree((x))
26 #define tls_get(x) TlsGetValue((x))
27 #define tls_set(x, a) TlsSetValue((x), (a))
34 #ifdef HAVE_PTHREAD_NP_H
35 #include <pthread_np.h>
41 #define IsBadWritePtr(a,b) (0)
43 typedef pthread_key_t tls_type
;
44 #define tls_create(x) pthread_key_create((x), NULL)
45 #define tls_delete(x) pthread_key_delete((x))
46 #define tls_get(x) pthread_getspecific((x))
47 #define tls_set(x, a) pthread_setspecific((x), (a))
49 typedef pthread_mutex_t CRITICAL_SECTION
;
50 static inline void EnterCriticalSection(CRITICAL_SECTION
*cs
)
53 ret
= pthread_mutex_lock(cs
);
56 static inline void LeaveCriticalSection(CRITICAL_SECTION
*cs
)
59 ret
= pthread_mutex_unlock(cs
);
62 static inline void InitializeCriticalSection(CRITICAL_SECTION
*cs
)
64 pthread_mutexattr_t attrib
;
67 ret
= pthread_mutexattr_init(&attrib
);
70 ret
= pthread_mutexattr_settype(&attrib
, PTHREAD_MUTEX_RECURSIVE
);
71 #ifdef HAVE_PTHREAD_NP_H
73 ret
= pthread_mutexattr_setkind_np(&attrib
, PTHREAD_MUTEX_RECURSIVE
);
76 ret
= pthread_mutex_init(cs
, &attrib
);
79 pthread_mutexattr_destroy(&attrib
);
82 static inline void DeleteCriticalSection(CRITICAL_SECTION
*cs
)
85 ret
= pthread_mutex_destroy(cs
);
89 /* NOTE: This wrapper isn't quite accurate as it returns an ALuint, as opposed
90 * to the expected DWORD. Both are defined as unsigned 32-bit types, however.
91 * Additionally, Win32 is supposed to measure the time since Windows started,
92 * as opposed to the actual time. */
93 static inline ALuint
timeGetTime(void)
99 ret
= clock_gettime(CLOCK_REALTIME
, &ts
);
102 return ts
.tv_nsec
/1000000 + ts
.tv_sec
*1000;
106 ret
= gettimeofday(&tv
, NULL
);
109 return tv
.tv_usec
/1000 + tv
.tv_sec
*1000;
113 static inline void Sleep(ALuint t
)
115 struct timespec tv
, rem
;
116 tv
.tv_nsec
= (t
*1000000)%1000000000;
119 while(nanosleep(&tv
, &rem
) == -1 && errno
== EINTR
)
122 #define min(x,y) (((x)<(y))?(x):(y))
123 #define max(x,y) (((x)>(y))?(x):(y))
126 #include "alListener.h"
133 static __inline
void al_print(const char *fname
, unsigned int line
, const char *fmt
, ...)
139 fn
= strrchr(fname
, '/');
140 if(!fn
) fn
= strrchr(fname
, '\\');;
144 i
= snprintf(str
, sizeof(str
), "AL lib: %s:%d: ", fn
, line
);
145 if(i
< (int)sizeof(str
) && i
> 0)
149 vsnprintf(str
+i
, sizeof(str
)-i
, fmt
, ap
);
152 str
[sizeof(str
)-1] = 0;
154 fprintf(stderr
, "%s", str
);
156 #define AL_PRINT(...) al_print(__FILE__, __LINE__, __VA_ARGS__)
159 #define SWMIXER_OUTPUT_RATE 44100
161 #define SPEEDOFSOUNDMETRESPERSEC (343.3f)
162 #define AIRABSORBGAINDBHF (-0.05f)
164 #define LOWPASSFREQCUTOFF (5000)
167 // Find the next power-of-2 for non-power-of-2 numbers.
168 static __inline ALuint
NextPowerOf2(ALuint value
)
186 ALCboolean (*OpenPlayback
)(ALCdevice
*, const ALCchar
*);
187 void (*ClosePlayback
)(ALCdevice
*);
188 ALCboolean (*ResetPlayback
)(ALCdevice
*);
189 void (*StopPlayback
)(ALCdevice
*);
191 ALCboolean (*OpenCapture
)(ALCdevice
*, const ALCchar
*);
192 void (*CloseCapture
)(ALCdevice
*);
193 void (*StartCapture
)(ALCdevice
*);
194 void (*StopCapture
)(ALCdevice
*);
195 void (*CaptureSamples
)(ALCdevice
*, void*, ALCuint
);
196 ALCuint (*AvailableSamples
)(ALCdevice
*);
205 void alc_alsa_init(BackendFuncs
*func_list
);
206 void alc_alsa_deinit(void);
207 void alc_alsa_probe(int type
);
208 void alc_oss_init(BackendFuncs
*func_list
);
209 void alc_oss_deinit(void);
210 void alc_oss_probe(int type
);
211 void alc_solaris_init(BackendFuncs
*func_list
);
212 void alc_solaris_deinit(void);
213 void alc_solarise_probe(int type
);
214 void alcDSoundInit(BackendFuncs
*func_list
);
215 void alcDSoundDeinit(void);
216 void alcDSoundProbe(int type
);
217 void alcWinMMInit(BackendFuncs
*FuncList
);
218 void alcWinMMDeinit(void);
219 void alcWinMMProbe(int type
);
220 void alc_pa_init(BackendFuncs
*func_list
);
221 void alc_pa_deinit(void);
222 void alc_pa_probe(int type
);
223 void alc_wave_init(BackendFuncs
*func_list
);
224 void alc_wave_deinit(void);
225 void alc_wave_probe(int type
);
226 void alc_pulse_init(BackendFuncs
*func_list
);
227 void alc_pulse_deinit(void);
228 void alc_pulse_probe(int type
);
231 struct ALCdevice_struct
233 ALCboolean Connected
;
234 ALboolean IsCaptureDevice
;
241 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
*Buffers
;
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
*Databuffers
;
266 ALuint DatabufferCount
;
268 // Stereo-to-binaural filter
272 // Dry path buffer mix
273 float DryBuffer
[BUFFERSIZE
][OUTPUTCHANNELS
];
275 Channel DevChannels
[OUTPUTCHANNELS
];
277 // Contexts created on this device
278 ALCcontext
**Contexts
;
282 void *ExtraData
; // For the backend's use
287 #define ALCdevice_OpenPlayback(a,b) ((a)->Funcs->OpenPlayback((a), (b)))
288 #define ALCdevice_ClosePlayback(a) ((a)->Funcs->ClosePlayback((a)))
289 #define ALCdevice_ResetPlayback(a) ((a)->Funcs->ResetPlayback((a)))
290 #define ALCdevice_StopPlayback(a) ((a)->Funcs->StopPlayback((a)))
291 #define ALCdevice_OpenCapture(a,b) ((a)->Funcs->OpenCapture((a), (b)))
292 #define ALCdevice_CloseCapture(a) ((a)->Funcs->CloseCapture((a)))
293 #define ALCdevice_StartCapture(a) ((a)->Funcs->StartCapture((a)))
294 #define ALCdevice_StopCapture(a) ((a)->Funcs->StopCapture((a)))
295 #define ALCdevice_CaptureSamples(a,b,c) ((a)->Funcs->CaptureSamples((a), (b), (c)))
296 #define ALCdevice_AvailableSamples(a) ((a)->Funcs->AvailableSamples((a)))
298 struct ALCcontext_struct
302 struct ALsource
*Source
;
305 struct ALeffectslot
*AuxiliaryEffectSlot
;
306 ALuint AuxiliaryEffectSlotCount
;
308 struct ALdatabuffer
*SampleSource
;
309 struct ALdatabuffer
*SampleSink
;
314 ALenum DistanceModel
;
315 ALboolean SourceDistanceModel
;
317 ALfloat DopplerFactor
;
318 ALfloat DopplerVelocity
;
319 ALfloat flSpeedOfSound
;
321 ALfloat PanningLUT
[OUTPUTCHANNELS
* LUT_NUM
];
324 ALfloat ChannelMatrix
[OUTPUTCHANNELS
][OUTPUTCHANNELS
];
327 const ALCchar
*ExtensionList
;
332 extern ALint RTPrioLevel
;
334 ALCvoid
ReleaseALC(ALCvoid
);
336 void AppendDeviceList(const ALCchar
*name
);
337 void AppendAllDeviceList(const ALCchar
*name
);
338 void AppendCaptureDeviceList(const ALCchar
*name
);
340 ALCvoid
alcSetError(ALenum errorCode
);
342 ALCvoid
SuspendContext(ALCcontext
*context
);
343 ALCvoid
ProcessContext(ALCcontext
*context
);
345 ALvoid
*StartThread(ALuint (*func
)(ALvoid
*), ALvoid
*ptr
);
346 ALuint
StopThread(ALvoid
*thread
);
348 ALCcontext
*GetContextSuspended(void);
350 typedef struct RingBuffer RingBuffer
;
351 RingBuffer
*CreateRingBuffer(ALsizei frame_size
, ALsizei length
);
352 void DestroyRingBuffer(RingBuffer
*ring
);
353 ALsizei
RingBufferSize(RingBuffer
*ring
);
354 void WriteRingBuffer(RingBuffer
*ring
, const ALubyte
*data
, ALsizei len
);
355 void ReadRingBuffer(RingBuffer
*ring
, ALubyte
*data
, ALsizei len
);
357 void ReadALConfig(void);
358 void FreeALConfig(void);
359 const char *GetConfigValue(const char *blockName
, const char *keyName
, const char *def
);
360 int GetConfigValueInt(const char *blockName
, const char *keyName
, int def
);
361 float GetConfigValueFloat(const char *blockName
, const char *keyName
, float def
);
362 int GetConfigValueBool(const char *blockName
, const char *keyName
, float def
);
364 void EnableRTPrio(ALint level
);
366 ALCboolean ALCAPIENTRY
alcMakeCurrent(ALCcontext
*context
);
367 ALCcontext
* ALCAPIENTRY
alcGetThreadContext(void);
369 // Sets the default channel order used by most non-WaveFormatEx-based APIs
370 static __inline
void SetDefaultChannelOrder(ALCdevice
*device
)
372 switch(aluChannelsFromFormat(device
->Format
))
374 case 1: /* Mono is rendered as stereo; fall-through... */
375 case 2: device
->DevChannels
[0] = FRONT_LEFT
;
376 device
->DevChannels
[1] = FRONT_RIGHT
; break;
378 case 4: device
->DevChannels
[0] = FRONT_LEFT
;
379 device
->DevChannels
[1] = FRONT_RIGHT
;
380 device
->DevChannels
[2] = BACK_LEFT
;
381 device
->DevChannels
[3] = BACK_RIGHT
; break;
383 case 6: device
->DevChannels
[0] = FRONT_LEFT
;
384 device
->DevChannels
[1] = FRONT_RIGHT
;
385 device
->DevChannels
[2] = BACK_LEFT
;
386 device
->DevChannels
[3] = BACK_RIGHT
;
387 device
->DevChannels
[4] = FRONT_CENTER
;
388 device
->DevChannels
[5] = LFE
; break;
390 case 7: device
->DevChannels
[0] = FRONT_LEFT
;
391 device
->DevChannels
[1] = FRONT_RIGHT
;
392 device
->DevChannels
[2] = FRONT_CENTER
;
393 device
->DevChannels
[3] = LFE
;
394 device
->DevChannels
[4] = FRONT_CENTER
;
395 device
->DevChannels
[5] = SIDE_LEFT
;
396 device
->DevChannels
[6] = SIDE_RIGHT
; break;
398 case 8: device
->DevChannels
[0] = FRONT_LEFT
;
399 device
->DevChannels
[1] = FRONT_RIGHT
;
400 device
->DevChannels
[2] = BACK_LEFT
;
401 device
->DevChannels
[3] = BACK_RIGHT
;
402 device
->DevChannels
[4] = FRONT_CENTER
;
403 device
->DevChannels
[5] = LFE
;
404 device
->DevChannels
[6] = SIDE_LEFT
;
405 device
->DevChannels
[7] = SIDE_RIGHT
; break;
408 // Sets the default order used by WaveFormatEx
409 static __inline
void SetDefaultWFXChannelOrder(ALCdevice
*device
)
411 switch(aluChannelsFromFormat(device
->Format
))
413 case 1: /* Mono is rendered as stereo; fall-through... */
414 case 2: device
->DevChannels
[0] = FRONT_LEFT
;
415 device
->DevChannels
[1] = FRONT_RIGHT
; break;
417 case 4: device
->DevChannels
[0] = FRONT_LEFT
;
418 device
->DevChannels
[1] = FRONT_RIGHT
;
419 device
->DevChannels
[2] = BACK_LEFT
;
420 device
->DevChannels
[3] = BACK_RIGHT
; break;
422 case 6: device
->DevChannels
[0] = FRONT_LEFT
;
423 device
->DevChannels
[1] = FRONT_RIGHT
;
424 device
->DevChannels
[2] = FRONT_CENTER
;
425 device
->DevChannels
[3] = LFE
;
426 device
->DevChannels
[4] = BACK_LEFT
;
427 device
->DevChannels
[5] = BACK_RIGHT
; break;
429 case 7: device
->DevChannels
[0] = FRONT_LEFT
;
430 device
->DevChannels
[1] = FRONT_RIGHT
;
431 device
->DevChannels
[2] = FRONT_CENTER
;
432 device
->DevChannels
[3] = LFE
;
433 device
->DevChannels
[4] = FRONT_CENTER
;
434 device
->DevChannels
[5] = SIDE_LEFT
;
435 device
->DevChannels
[6] = SIDE_RIGHT
; break;
437 case 8: device
->DevChannels
[0] = FRONT_LEFT
;
438 device
->DevChannels
[1] = FRONT_RIGHT
;
439 device
->DevChannels
[2] = FRONT_CENTER
;
440 device
->DevChannels
[3] = LFE
;
441 device
->DevChannels
[4] = BACK_LEFT
;
442 device
->DevChannels
[5] = BACK_RIGHT
;
443 device
->DevChannels
[6] = SIDE_LEFT
;
444 device
->DevChannels
[7] = SIDE_RIGHT
; break;