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)
166 #define QUADRANT_NUM 128
167 #define LUT_NUM (4 * QUADRANT_NUM)
171 ALCboolean (*OpenPlayback
)(ALCdevice
*, const ALCchar
*);
172 void (*ClosePlayback
)(ALCdevice
*);
173 ALCboolean (*ResetPlayback
)(ALCdevice
*);
174 void (*StopPlayback
)(ALCdevice
*);
176 ALCboolean (*OpenCapture
)(ALCdevice
*, const ALCchar
*);
177 void (*CloseCapture
)(ALCdevice
*);
178 void (*StartCapture
)(ALCdevice
*);
179 void (*StopCapture
)(ALCdevice
*);
180 void (*CaptureSamples
)(ALCdevice
*, void*, ALCuint
);
181 ALCuint (*AvailableSamples
)(ALCdevice
*);
190 void alc_alsa_init(BackendFuncs
*func_list
);
191 void alc_alsa_deinit(void);
192 void alc_alsa_probe(int type
);
193 void alc_oss_init(BackendFuncs
*func_list
);
194 void alc_oss_deinit(void);
195 void alc_oss_probe(int type
);
196 void alc_solaris_init(BackendFuncs
*func_list
);
197 void alc_solaris_deinit(void);
198 void alc_solarise_probe(int type
);
199 void alcDSoundInit(BackendFuncs
*func_list
);
200 void alcDSoundDeinit(void);
201 void alcDSoundProbe(int type
);
202 void alcWinMMInit(BackendFuncs
*FuncList
);
203 void alcWinMMDeinit(void);
204 void alcWinMMProbe(int type
);
205 void alc_pa_init(BackendFuncs
*func_list
);
206 void alc_pa_deinit(void);
207 void alc_pa_probe(int type
);
208 void alc_wave_init(BackendFuncs
*func_list
);
209 void alc_wave_deinit(void);
210 void alc_wave_probe(int type
);
211 void alc_pulse_init(BackendFuncs
*func_list
);
212 void alc_pulse_deinit(void);
213 void alc_pulse_probe(int type
);
216 struct ALCdevice_struct
218 ALCboolean Connected
;
219 ALboolean IsCaptureDevice
;
226 ALCchar
*szDeviceName
;
228 // Maximum number of sources that can be created
229 ALuint MaxNoOfSources
;
230 // Maximum number of slots that can be created
231 ALuint AuxiliaryEffectSlotMax
;
233 ALint lNumMonoSources
;
234 ALint lNumStereoSources
;
237 // Linked List of Buffers for this device
238 struct ALbuffer
*Buffers
;
241 // Linked List of Effects for this device
242 struct ALeffect
*EffectList
;
245 // Linked List of Filters for this device
246 struct ALfilter
*FilterList
;
249 // Linked List of Databuffers for this device
250 struct ALdatabuffer
*Databuffers
;
251 ALuint DatabufferCount
;
253 // Stereo-to-binaural filter
257 // Dry path buffer mix
258 float DryBuffer
[BUFFERSIZE
][OUTPUTCHANNELS
];
260 // Contexts created on this device
261 ALCcontext
**Contexts
;
265 void *ExtraData
; // For the backend's use
270 #define ALCdevice_OpenPlayback(a,b) ((a)->Funcs->OpenPlayback((a), (b)))
271 #define ALCdevice_ClosePlayback(a) ((a)->Funcs->ClosePlayback((a)))
272 #define ALCdevice_ResetPlayback(a) ((a)->Funcs->ResetPlayback((a)))
273 #define ALCdevice_StopPlayback(a) ((a)->Funcs->StopPlayback((a)))
274 #define ALCdevice_OpenCapture(a,b) ((a)->Funcs->OpenCapture((a), (b)))
275 #define ALCdevice_CloseCapture(a) ((a)->Funcs->CloseCapture((a)))
276 #define ALCdevice_StartCapture(a) ((a)->Funcs->StartCapture((a)))
277 #define ALCdevice_StopCapture(a) ((a)->Funcs->StopCapture((a)))
278 #define ALCdevice_CaptureSamples(a,b,c) ((a)->Funcs->CaptureSamples((a), (b), (c)))
279 #define ALCdevice_AvailableSamples(a) ((a)->Funcs->AvailableSamples((a)))
281 struct ALCcontext_struct
285 struct ALsource
*Source
;
288 struct ALeffectslot
*AuxiliaryEffectSlot
;
289 ALuint AuxiliaryEffectSlotCount
;
291 struct ALdatabuffer
*SampleSource
;
292 struct ALdatabuffer
*SampleSink
;
297 ALenum DistanceModel
;
299 ALfloat DopplerFactor
;
300 ALfloat DopplerVelocity
;
301 ALfloat flSpeedOfSound
;
303 ALfloat PanningLUT
[OUTPUTCHANNELS
* LUT_NUM
];
306 ALfloat ChannelMatrix
[OUTPUTCHANNELS
][OUTPUTCHANNELS
];
309 const ALCchar
*ExtensionList
;
314 ALCvoid
ReleaseALC(ALCvoid
);
316 void AppendDeviceList(const ALCchar
*name
);
317 void AppendAllDeviceList(const ALCchar
*name
);
318 void AppendCaptureDeviceList(const ALCchar
*name
);
320 ALCvoid
alcSetError(ALenum errorCode
);
322 ALCvoid
SuspendContext(ALCcontext
*context
);
323 ALCvoid
ProcessContext(ALCcontext
*context
);
325 ALvoid
*StartThread(ALuint (*func
)(ALvoid
*), ALvoid
*ptr
);
326 ALuint
StopThread(ALvoid
*thread
);
328 ALCcontext
*GetContextSuspended(void);
330 typedef struct RingBuffer RingBuffer
;
331 RingBuffer
*CreateRingBuffer(ALsizei frame_size
, ALsizei length
);
332 void DestroyRingBuffer(RingBuffer
*ring
);
333 ALsizei
RingBufferSize(RingBuffer
*ring
);
334 void WriteRingBuffer(RingBuffer
*ring
, const ALubyte
*data
, ALsizei len
);
335 void ReadRingBuffer(RingBuffer
*ring
, ALubyte
*data
, ALsizei len
);
337 void ReadALConfig(void);
338 void FreeALConfig(void);
339 const char *GetConfigValue(const char *blockName
, const char *keyName
, const char *def
);
340 int GetConfigValueInt(const char *blockName
, const char *keyName
, int def
);
341 float GetConfigValueFloat(const char *blockName
, const char *keyName
, float def
);
342 int GetConfigValueBool(const char *blockName
, const char *keyName
, float def
);
344 ALCboolean ALCAPIENTRY
alcMakeCurrent(ALCcontext
*context
);
345 ALCcontext
* ALCAPIENTRY
alcGetThreadContext(void);