19 #define _WIN32_WINNT 0x0500
27 #ifdef HAVE_PTHREAD_NP_H
28 #include <pthread_np.h>
34 #define IsBadWritePtr(a,b) (0)
36 typedef pthread_mutex_t CRITICAL_SECTION
;
37 static inline void EnterCriticalSection(CRITICAL_SECTION
*cs
)
40 ret
= pthread_mutex_lock(cs
);
43 static inline void LeaveCriticalSection(CRITICAL_SECTION
*cs
)
46 ret
= pthread_mutex_unlock(cs
);
49 static inline void InitializeCriticalSection(CRITICAL_SECTION
*cs
)
51 pthread_mutexattr_t attrib
;
54 ret
= pthread_mutexattr_init(&attrib
);
57 ret
= pthread_mutexattr_settype(&attrib
, PTHREAD_MUTEX_RECURSIVE
);
58 #ifdef HAVE_PTHREAD_NP_H
60 ret
= pthread_mutexattr_setkind_np(&attrib
, PTHREAD_MUTEX_RECURSIVE
);
63 ret
= pthread_mutex_init(cs
, &attrib
);
66 pthread_mutexattr_destroy(&attrib
);
69 static inline void DeleteCriticalSection(CRITICAL_SECTION
*cs
)
72 ret
= pthread_mutex_destroy(cs
);
76 /* NOTE: This wrapper isn't quite accurate as it returns an ALuint, as opposed
77 * to the expected DWORD. Both are defined as unsigned 32-bit types, however.
78 * Additionally, Win32 is supposed to measure the time since Windows started,
79 * as opposed to the actual time. */
80 static inline ALuint
timeGetTime(void)
85 ret
= gettimeofday(&tv
, NULL
);
88 return tv
.tv_usec
/1000 + tv
.tv_sec
*1000;
91 static inline void Sleep(ALuint t
)
93 struct timespec tv
, rem
;
94 tv
.tv_nsec
= (t
*1000000)%1000000000;
97 while(nanosleep(&tv
, &rem
) == -1 && errno
== EINTR
)
100 #define min(x,y) (((x)<(y))?(x):(y))
101 #define max(x,y) (((x)>(y))?(x):(y))
104 #include "alListener.h"
111 static __inline
void al_print(const char *fname
, unsigned int line
, const char *fmt
, ...)
117 fn
= strrchr(fname
, '/');
118 if(!fn
) fn
= strrchr(fname
, '\\');;
122 i
= snprintf(str
, sizeof(str
), "AL lib: %s:%d: ", fn
, line
);
123 if(i
< (int)sizeof(str
) && i
> 0)
127 vsnprintf(str
+i
, sizeof(str
)-i
, fmt
, ap
);
130 str
[sizeof(str
)-1] = 0;
132 fprintf(stderr
, "%s", str
);
134 #define AL_PRINT(...) al_print(__FILE__, __LINE__, __VA_ARGS__)
137 #define SWMIXER_OUTPUT_RATE 44100
139 #define SPEEDOFSOUNDMETRESPERSEC (343.3f)
140 #define AIRABSORBGAINDBHF (-0.05f)
142 #define LOWPASSFREQCUTOFF (5000)
144 #define QUADRANT_NUM 128
145 #define LUT_NUM (4 * QUADRANT_NUM)
149 ALCboolean (*OpenPlayback
)(ALCdevice
*, const ALCchar
*);
150 void (*ClosePlayback
)(ALCdevice
*);
151 ALCboolean (*StartContext
)(ALCdevice
*, ALCcontext
*);
152 void (*StopContext
)(ALCdevice
*, ALCcontext
*);
154 ALCboolean (*OpenCapture
)(ALCdevice
*, const ALCchar
*);
155 void (*CloseCapture
)(ALCdevice
*);
156 void (*StartCapture
)(ALCdevice
*);
157 void (*StopCapture
)(ALCdevice
*);
158 void (*CaptureSamples
)(ALCdevice
*, void*, ALCuint
);
159 ALCuint (*AvailableSamples
)(ALCdevice
*);
162 void alc_alsa_init(BackendFuncs
*func_list
);
163 void alc_oss_init(BackendFuncs
*func_list
);
164 void alc_solaris_init(BackendFuncs
*func_list
);
165 void alcDSoundInit(BackendFuncs
*func_list
);
166 void alcWinMMInit(BackendFuncs
*FuncList
);
167 void alc_pa_init(BackendFuncs
*func_list
);
168 void alc_wave_init(BackendFuncs
*func_list
);
169 void alc_pulse_init(BackendFuncs
*func_list
);
172 struct ALCdevice_struct
174 ALboolean IsCaptureDevice
;
181 ALCchar
*szDeviceName
;
183 // Maximum number of sources that can be created
184 ALuint MaxNoOfSources
;
185 // Maximum number of slots that can be created
186 ALuint AuxiliaryEffectSlotMax
;
188 ALint lNumMonoSources
;
189 ALint lNumStereoSources
;
192 // Linked List of Buffers for this device
193 struct ALbuffer
*Buffers
;
196 // Context created on this device
200 void *ExtraData
; // For the backend's use
205 #define ALCdevice_OpenPlayback(a,b) ((a)->Funcs->OpenPlayback((a), (b)))
206 #define ALCdevice_ClosePlayback(a) ((a)->Funcs->ClosePlayback((a)))
207 #define ALCdevice_StartContext(a,b) ((a)->Funcs->StartContext((a), (b)))
208 #define ALCdevice_StopContext(a,b) ((a)->Funcs->StopContext((a), (b)))
209 #define ALCdevice_OpenCapture(a,b) ((a)->Funcs->OpenCapture((a), (b)))
210 #define ALCdevice_CloseCapture(a) ((a)->Funcs->CloseCapture((a)))
211 #define ALCdevice_StartCapture(a) ((a)->Funcs->StartCapture((a)))
212 #define ALCdevice_StopCapture(a) ((a)->Funcs->StopCapture((a)))
213 #define ALCdevice_CaptureSamples(a,b,c) ((a)->Funcs->CaptureSamples((a), (b), (c)))
214 #define ALCdevice_AvailableSamples(a) ((a)->Funcs->AvailableSamples((a)))
216 struct ALCcontext_struct
220 struct ALsource
*Source
;
223 struct ALeffectslot
*AuxiliaryEffectSlot
;
224 ALuint AuxiliaryEffectSlotCount
;
231 ALenum DistanceModel
;
233 ALfloat DopplerFactor
;
234 ALfloat DopplerVelocity
;
235 ALfloat flSpeedOfSound
;
237 ALfloat PanningLUT
[OUTPUTCHANNELS
* LUT_NUM
];
240 ALfloat ChannelMatrix
[OUTPUTCHANNELS
][OUTPUTCHANNELS
];
243 const ALCchar
*ExtensionList
;
250 ALCvoid
ReleaseALC(ALCvoid
);
252 ALCchar
*AppendDeviceList(char *name
);
253 ALCchar
*AppendAllDeviceList(char *name
);
254 ALCchar
*AppendCaptureDeviceList(char *name
);
256 ALCvoid
SetALCError(ALenum errorCode
);
258 ALCvoid
SuspendContext(ALCcontext
*context
);
259 ALCvoid
ProcessContext(ALCcontext
*context
);
261 ALvoid
*StartThread(ALuint (*func
)(ALvoid
*), ALvoid
*ptr
);
262 ALuint
StopThread(ALvoid
*thread
);
264 typedef struct RingBuffer RingBuffer
;
265 RingBuffer
*CreateRingBuffer(ALsizei frame_size
, ALsizei length
);
266 void DestroyRingBuffer(RingBuffer
*ring
);
267 ALsizei
RingBufferSize(RingBuffer
*ring
);
268 void WriteRingBuffer(RingBuffer
*ring
, const ALubyte
*data
, ALsizei len
);
269 void ReadRingBuffer(RingBuffer
*ring
, ALubyte
*data
, ALsizei len
);
271 void ReadALConfig(void);
272 void FreeALConfig(void);
273 const char *GetConfigValue(const char *blockName
, const char *keyName
, const char *def
);
274 int GetConfigValueInt(const char *blockName
, const char *keyName
, int def
);
275 float GetConfigValueFloat(const char *blockName
, const char *keyName
, float def
);