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))
33 #ifdef HAVE_PTHREAD_NP_H
34 #include <pthread_np.h>
40 #define IsBadWritePtr(a,b) (0)
42 typedef pthread_key_t tls_type
;
43 #define tls_create(x) pthread_key_create((x), NULL)
44 #define tls_delete(x) pthread_key_delete((x))
45 #define tls_get(x) pthread_getspecific((x))
46 #define tls_set(x, a) pthread_setspecific((x), (a))
48 typedef pthread_mutex_t CRITICAL_SECTION
;
49 static inline void EnterCriticalSection(CRITICAL_SECTION
*cs
)
52 ret
= pthread_mutex_lock(cs
);
55 static inline void LeaveCriticalSection(CRITICAL_SECTION
*cs
)
58 ret
= pthread_mutex_unlock(cs
);
61 static inline void InitializeCriticalSection(CRITICAL_SECTION
*cs
)
63 pthread_mutexattr_t attrib
;
66 ret
= pthread_mutexattr_init(&attrib
);
69 ret
= pthread_mutexattr_settype(&attrib
, PTHREAD_MUTEX_RECURSIVE
);
70 #ifdef HAVE_PTHREAD_NP_H
72 ret
= pthread_mutexattr_setkind_np(&attrib
, PTHREAD_MUTEX_RECURSIVE
);
75 ret
= pthread_mutex_init(cs
, &attrib
);
78 pthread_mutexattr_destroy(&attrib
);
81 static inline void DeleteCriticalSection(CRITICAL_SECTION
*cs
)
84 ret
= pthread_mutex_destroy(cs
);
88 /* NOTE: This wrapper isn't quite accurate as it returns an ALuint, as opposed
89 * to the expected DWORD. Both are defined as unsigned 32-bit types, however.
90 * Additionally, Win32 is supposed to measure the time since Windows started,
91 * as opposed to the actual time. */
92 static inline ALuint
timeGetTime(void)
97 ret
= gettimeofday(&tv
, NULL
);
100 return tv
.tv_usec
/1000 + tv
.tv_sec
*1000;
103 static inline void Sleep(ALuint t
)
105 struct timespec tv
, rem
;
106 tv
.tv_nsec
= (t
*1000000)%1000000000;
109 while(nanosleep(&tv
, &rem
) == -1 && errno
== EINTR
)
112 #define min(x,y) (((x)<(y))?(x):(y))
113 #define max(x,y) (((x)>(y))?(x):(y))
116 #include "alListener.h"
123 static __inline
void al_print(const char *fname
, unsigned int line
, const char *fmt
, ...)
129 fn
= strrchr(fname
, '/');
130 if(!fn
) fn
= strrchr(fname
, '\\');;
134 i
= snprintf(str
, sizeof(str
), "AL lib: %s:%d: ", fn
, line
);
135 if(i
< (int)sizeof(str
) && i
> 0)
139 vsnprintf(str
+i
, sizeof(str
)-i
, fmt
, ap
);
142 str
[sizeof(str
)-1] = 0;
144 fprintf(stderr
, "%s", str
);
146 #define AL_PRINT(...) al_print(__FILE__, __LINE__, __VA_ARGS__)
149 #define SWMIXER_OUTPUT_RATE 44100
151 #define SPEEDOFSOUNDMETRESPERSEC (343.3f)
152 #define AIRABSORBGAINDBHF (-0.05f)
154 #define LOWPASSFREQCUTOFF (5000)
156 #define QUADRANT_NUM 128
157 #define LUT_NUM (4 * QUADRANT_NUM)
161 ALCboolean (*OpenPlayback
)(ALCdevice
*, const ALCchar
*);
162 void (*ClosePlayback
)(ALCdevice
*);
163 ALCboolean (*ResetPlayback
)(ALCdevice
*);
164 void (*StopPlayback
)(ALCdevice
*);
166 ALCboolean (*OpenCapture
)(ALCdevice
*, const ALCchar
*);
167 void (*CloseCapture
)(ALCdevice
*);
168 void (*StartCapture
)(ALCdevice
*);
169 void (*StopCapture
)(ALCdevice
*);
170 void (*CaptureSamples
)(ALCdevice
*, void*, ALCuint
);
171 ALCuint (*AvailableSamples
)(ALCdevice
*);
180 void alc_alsa_init(BackendFuncs
*func_list
);
181 void alc_alsa_deinit(void);
182 void alc_alsa_probe(int type
);
183 void alc_oss_init(BackendFuncs
*func_list
);
184 void alc_oss_deinit(void);
185 void alc_oss_probe(int type
);
186 void alc_solaris_init(BackendFuncs
*func_list
);
187 void alc_solaris_deinit(void);
188 void alc_solarise_probe(int type
);
189 void alcDSoundInit(BackendFuncs
*func_list
);
190 void alcDSoundDeinit(void);
191 void alcDSoundProbe(int type
);
192 void alcWinMMInit(BackendFuncs
*FuncList
);
193 void alcWinMMDeinit(void);
194 void alcWinMMProbe(int type
);
195 void alc_pa_init(BackendFuncs
*func_list
);
196 void alc_pa_deinit(void);
197 void alc_pa_probe(int type
);
198 void alc_wave_init(BackendFuncs
*func_list
);
199 void alc_wave_deinit(void);
200 void alc_wave_probe(int type
);
201 void alc_pulse_init(BackendFuncs
*func_list
);
202 void alc_pulse_deinit(void);
203 void alc_pulse_probe(int type
);
206 struct ALCdevice_struct
208 ALCboolean Connected
;
209 ALboolean IsCaptureDevice
;
216 ALCchar
*szDeviceName
;
218 // Maximum number of sources that can be created
219 ALuint MaxNoOfSources
;
220 // Maximum number of slots that can be created
221 ALuint AuxiliaryEffectSlotMax
;
223 ALint lNumMonoSources
;
224 ALint lNumStereoSources
;
227 // Linked List of Buffers for this device
228 struct ALbuffer
*Buffers
;
231 // Linked List of Effects for this device
232 struct ALeffect
*EffectList
;
235 // Linked List of Filters for this device
236 struct ALfilter
*FilterList
;
239 // Linked List of Databuffers for this device
240 struct ALdatabuffer
*Databuffers
;
241 ALuint DatabufferCount
;
243 // Stereo-to-binaural filter
247 // Dry path buffer mix
248 float DryBuffer
[BUFFERSIZE
][OUTPUTCHANNELS
];
250 // Contexts created on this device
251 ALCcontext
**Contexts
;
255 void *ExtraData
; // For the backend's use
260 #define ALCdevice_OpenPlayback(a,b) ((a)->Funcs->OpenPlayback((a), (b)))
261 #define ALCdevice_ClosePlayback(a) ((a)->Funcs->ClosePlayback((a)))
262 #define ALCdevice_ResetPlayback(a) ((a)->Funcs->ResetPlayback((a)))
263 #define ALCdevice_StopPlayback(a) ((a)->Funcs->StopPlayback((a)))
264 #define ALCdevice_OpenCapture(a,b) ((a)->Funcs->OpenCapture((a), (b)))
265 #define ALCdevice_CloseCapture(a) ((a)->Funcs->CloseCapture((a)))
266 #define ALCdevice_StartCapture(a) ((a)->Funcs->StartCapture((a)))
267 #define ALCdevice_StopCapture(a) ((a)->Funcs->StopCapture((a)))
268 #define ALCdevice_CaptureSamples(a,b,c) ((a)->Funcs->CaptureSamples((a), (b), (c)))
269 #define ALCdevice_AvailableSamples(a) ((a)->Funcs->AvailableSamples((a)))
271 struct ALCcontext_struct
275 struct ALsource
*Source
;
278 struct ALeffectslot
*AuxiliaryEffectSlot
;
279 ALuint AuxiliaryEffectSlotCount
;
281 struct ALdatabuffer
*SampleSource
;
282 struct ALdatabuffer
*SampleSink
;
287 ALenum DistanceModel
;
289 ALfloat DopplerFactor
;
290 ALfloat DopplerVelocity
;
291 ALfloat flSpeedOfSound
;
293 ALfloat PanningLUT
[OUTPUTCHANNELS
* LUT_NUM
];
296 ALfloat ChannelMatrix
[OUTPUTCHANNELS
][OUTPUTCHANNELS
];
299 const ALCchar
*ExtensionList
;
304 ALCvoid
ReleaseALC(ALCvoid
);
306 void AppendDeviceList(const ALCchar
*name
);
307 void AppendAllDeviceList(const ALCchar
*name
);
308 void AppendCaptureDeviceList(const ALCchar
*name
);
310 ALCvoid
alcSetError(ALenum errorCode
);
312 ALCvoid
SuspendContext(ALCcontext
*context
);
313 ALCvoid
ProcessContext(ALCcontext
*context
);
315 ALvoid
*StartThread(ALuint (*func
)(ALvoid
*), ALvoid
*ptr
);
316 ALuint
StopThread(ALvoid
*thread
);
318 ALCcontext
*GetContextSuspended(void);
320 typedef struct RingBuffer RingBuffer
;
321 RingBuffer
*CreateRingBuffer(ALsizei frame_size
, ALsizei length
);
322 void DestroyRingBuffer(RingBuffer
*ring
);
323 ALsizei
RingBufferSize(RingBuffer
*ring
);
324 void WriteRingBuffer(RingBuffer
*ring
, const ALubyte
*data
, ALsizei len
);
325 void ReadRingBuffer(RingBuffer
*ring
, ALubyte
*data
, ALsizei len
);
327 void ReadALConfig(void);
328 void FreeALConfig(void);
329 const char *GetConfigValue(const char *blockName
, const char *keyName
, const char *def
);
330 int GetConfigValueInt(const char *blockName
, const char *keyName
, int def
);
331 float GetConfigValueFloat(const char *blockName
, const char *keyName
, float def
);
332 int GetConfigValueBool(const char *blockName
, const char *keyName
, float def
);
334 ALCboolean ALCAPIENTRY
alcMakeCurrent(ALCcontext
*context
);
335 ALCcontext
* ALCAPIENTRY
alcGetThreadContext(void);