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
)
184 static __inline
void EnableRTPrio()
187 SetThreadPriority(GetCurrentThread(), THREAD_PRIORITY_TIME_CRITICAL
);
188 #elif defined(HAVE_PTHREAD_SETSCHEDPARAM)
189 struct sched_param param
;
191 /* Use the minimum real-time priority possible for now (on Linux this
192 * should be 1 for SCHED_RR) */
193 param
.sched_priority
= sched_get_priority_min(SCHED_RR
);
194 pthread_setschedparam(pthread_self(), SCHED_RR
, ¶m
);
196 /* Real-time priority not available */
202 ALCboolean (*OpenPlayback
)(ALCdevice
*, const ALCchar
*);
203 void (*ClosePlayback
)(ALCdevice
*);
204 ALCboolean (*ResetPlayback
)(ALCdevice
*);
205 void (*StopPlayback
)(ALCdevice
*);
207 ALCboolean (*OpenCapture
)(ALCdevice
*, const ALCchar
*);
208 void (*CloseCapture
)(ALCdevice
*);
209 void (*StartCapture
)(ALCdevice
*);
210 void (*StopCapture
)(ALCdevice
*);
211 void (*CaptureSamples
)(ALCdevice
*, void*, ALCuint
);
212 ALCuint (*AvailableSamples
)(ALCdevice
*);
221 void alc_alsa_init(BackendFuncs
*func_list
);
222 void alc_alsa_deinit(void);
223 void alc_alsa_probe(int type
);
224 void alc_oss_init(BackendFuncs
*func_list
);
225 void alc_oss_deinit(void);
226 void alc_oss_probe(int type
);
227 void alc_solaris_init(BackendFuncs
*func_list
);
228 void alc_solaris_deinit(void);
229 void alc_solarise_probe(int type
);
230 void alcDSoundInit(BackendFuncs
*func_list
);
231 void alcDSoundDeinit(void);
232 void alcDSoundProbe(int type
);
233 void alcWinMMInit(BackendFuncs
*FuncList
);
234 void alcWinMMDeinit(void);
235 void alcWinMMProbe(int type
);
236 void alc_pa_init(BackendFuncs
*func_list
);
237 void alc_pa_deinit(void);
238 void alc_pa_probe(int type
);
239 void alc_wave_init(BackendFuncs
*func_list
);
240 void alc_wave_deinit(void);
241 void alc_wave_probe(int type
);
242 void alc_pulse_init(BackendFuncs
*func_list
);
243 void alc_pulse_deinit(void);
244 void alc_pulse_probe(int type
);
247 struct ALCdevice_struct
249 ALCboolean Connected
;
250 ALboolean IsCaptureDevice
;
257 ALCchar
*szDeviceName
;
259 // Maximum number of sources that can be created
260 ALuint MaxNoOfSources
;
261 // Maximum number of slots that can be created
262 ALuint AuxiliaryEffectSlotMax
;
264 ALint lNumMonoSources
;
265 ALint lNumStereoSources
;
268 // Linked List of Buffers for this device
269 struct ALbuffer
*Buffers
;
272 // Linked List of Effects for this device
273 struct ALeffect
*EffectList
;
276 // Linked List of Filters for this device
277 struct ALfilter
*FilterList
;
280 // Linked List of Databuffers for this device
281 struct ALdatabuffer
*Databuffers
;
282 ALuint DatabufferCount
;
284 // Stereo-to-binaural filter
288 // Dry path buffer mix
289 float DryBuffer
[BUFFERSIZE
][OUTPUTCHANNELS
];
291 // Contexts created on this device
292 ALCcontext
**Contexts
;
296 void *ExtraData
; // For the backend's use
301 #define ALCdevice_OpenPlayback(a,b) ((a)->Funcs->OpenPlayback((a), (b)))
302 #define ALCdevice_ClosePlayback(a) ((a)->Funcs->ClosePlayback((a)))
303 #define ALCdevice_ResetPlayback(a) ((a)->Funcs->ResetPlayback((a)))
304 #define ALCdevice_StopPlayback(a) ((a)->Funcs->StopPlayback((a)))
305 #define ALCdevice_OpenCapture(a,b) ((a)->Funcs->OpenCapture((a), (b)))
306 #define ALCdevice_CloseCapture(a) ((a)->Funcs->CloseCapture((a)))
307 #define ALCdevice_StartCapture(a) ((a)->Funcs->StartCapture((a)))
308 #define ALCdevice_StopCapture(a) ((a)->Funcs->StopCapture((a)))
309 #define ALCdevice_CaptureSamples(a,b,c) ((a)->Funcs->CaptureSamples((a), (b), (c)))
310 #define ALCdevice_AvailableSamples(a) ((a)->Funcs->AvailableSamples((a)))
312 struct ALCcontext_struct
316 struct ALsource
*Source
;
319 struct ALeffectslot
*AuxiliaryEffectSlot
;
320 ALuint AuxiliaryEffectSlotCount
;
322 struct ALdatabuffer
*SampleSource
;
323 struct ALdatabuffer
*SampleSink
;
328 ALenum DistanceModel
;
329 ALboolean SourceDistanceModel
;
331 ALfloat DopplerFactor
;
332 ALfloat DopplerVelocity
;
333 ALfloat flSpeedOfSound
;
335 ALfloat PanningLUT
[OUTPUTCHANNELS
* LUT_NUM
];
338 ALfloat ChannelMatrix
[OUTPUTCHANNELS
][OUTPUTCHANNELS
];
341 const ALCchar
*ExtensionList
;
346 ALCvoid
ReleaseALC(ALCvoid
);
348 void AppendDeviceList(const ALCchar
*name
);
349 void AppendAllDeviceList(const ALCchar
*name
);
350 void AppendCaptureDeviceList(const ALCchar
*name
);
352 ALCvoid
alcSetError(ALenum errorCode
);
354 ALCvoid
SuspendContext(ALCcontext
*context
);
355 ALCvoid
ProcessContext(ALCcontext
*context
);
357 ALvoid
*StartThread(ALuint (*func
)(ALvoid
*), ALvoid
*ptr
);
358 ALuint
StopThread(ALvoid
*thread
);
360 ALCcontext
*GetContextSuspended(void);
362 typedef struct RingBuffer RingBuffer
;
363 RingBuffer
*CreateRingBuffer(ALsizei frame_size
, ALsizei length
);
364 void DestroyRingBuffer(RingBuffer
*ring
);
365 ALsizei
RingBufferSize(RingBuffer
*ring
);
366 void WriteRingBuffer(RingBuffer
*ring
, const ALubyte
*data
, ALsizei len
);
367 void ReadRingBuffer(RingBuffer
*ring
, ALubyte
*data
, ALsizei len
);
369 void ReadALConfig(void);
370 void FreeALConfig(void);
371 const char *GetConfigValue(const char *blockName
, const char *keyName
, const char *def
);
372 int GetConfigValueInt(const char *blockName
, const char *keyName
, int def
);
373 float GetConfigValueFloat(const char *blockName
, const char *keyName
, float def
);
374 int GetConfigValueBool(const char *blockName
, const char *keyName
, float def
);
376 ALCboolean ALCAPIENTRY
alcMakeCurrent(ALCcontext
*context
);
377 ALCcontext
* ALCAPIENTRY
alcGetThreadContext(void);