12 #define _WIN32_WINNT 0x0500
20 #ifdef HAVE_PTHREAD_NP_H
21 #include <pthread_np.h>
27 #define IsBadWritePtr(a,b) (0)
29 typedef pthread_mutex_t CRITICAL_SECTION
;
30 static inline void EnterCriticalSection(CRITICAL_SECTION
*cs
)
33 ret
= pthread_mutex_lock(cs
);
36 static inline void LeaveCriticalSection(CRITICAL_SECTION
*cs
)
39 ret
= pthread_mutex_unlock(cs
);
42 static inline void InitializeCriticalSection(CRITICAL_SECTION
*cs
)
44 pthread_mutexattr_t attrib
;
47 ret
= pthread_mutexattr_init(&attrib
);
50 ret
= pthread_mutexattr_settype(&attrib
, PTHREAD_MUTEX_RECURSIVE
);
51 #ifdef HAVE_PTHREAD_NP_H
53 ret
= pthread_mutexattr_setkind_np(&attrib
, PTHREAD_MUTEX_RECURSIVE
);
56 ret
= pthread_mutex_init(cs
, &attrib
);
59 pthread_mutexattr_destroy(&attrib
);
62 static inline void DeleteCriticalSection(CRITICAL_SECTION
*cs
)
65 ret
= pthread_mutex_destroy(cs
);
69 /* NOTE: This wrapper isn't quite accurate as it returns an ALuint, as opposed
70 * to the expected DWORD. Both are defined as unsigned 32-bit types, however.
71 * Additionally, Win32 is supposed to measure the time since Windows started,
72 * as opposed to the actual time. */
73 static inline ALuint
timeGetTime(void)
78 ret
= gettimeofday(&tv
, NULL
);
81 return tv
.tv_usec
/1000 + tv
.tv_sec
*1000;
84 static inline void Sleep(ALuint t
)
86 struct timespec tv
, rem
;
87 tv
.tv_nsec
= (t
*1000000)%1000000000;
90 while(nanosleep(&tv
, &rem
) == -1 && errno
== EINTR
)
93 #define min(x,y) (((x)<(y))?(x):(y))
94 #define max(x,y) (((x)>(y))?(x):(y))
100 #include "alListener.h"
106 extern CRITICAL_SECTION _alMutex
;
108 extern char _alDebug
[256];
110 #define AL_PRINT(...) do { \
112 const char *_al_print_fn = strrchr(__FILE__, '/'); \
113 if(!_al_print_fn) _al_print_fn = __FILE__; \
114 else _al_print_fn += 1; \
115 _al_print_i = snprintf(_alDebug, sizeof(_alDebug), "AL lib: %s:%d: ", _al_print_fn, __LINE__); \
116 if(_al_print_i < (int)sizeof(_alDebug) && _al_print_i > 0) \
117 snprintf(_alDebug+_al_print_i, sizeof(_alDebug)-_al_print_i, __VA_ARGS__); \
118 _alDebug[sizeof(_alDebug)-1] = 0; \
119 fprintf(stderr, "%s", _alDebug); \
123 #define SWMIXER_OUTPUT_RATE 44100
125 #define SPEEDOFSOUNDMETRESPERSEC (343.3f)
126 #define AIRABSORBGAINHF (0.994f)
129 ALCboolean (*OpenPlayback
)(ALCdevice
*, const ALCchar
*);
130 void (*ClosePlayback
)(ALCdevice
*);
132 ALCboolean (*OpenCapture
)(ALCdevice
*, const ALCchar
*, ALCuint
, ALCenum
, ALCsizei
);
133 void (*CloseCapture
)(ALCdevice
*);
134 void (*StartCapture
)(ALCdevice
*);
135 void (*StopCapture
)(ALCdevice
*);
136 void (*CaptureSamples
)(ALCdevice
*, void*, ALCuint
);
137 ALCuint (*AvailableSamples
)(ALCdevice
*);
140 void alc_alsa_init(BackendFuncs
*func_list
);
141 void alc_oss_init(BackendFuncs
*func_list
);
142 void alcDSoundInit(BackendFuncs
*func_list
);
143 void alcWinMMInit(BackendFuncs
*FuncList
);
144 void alc_wave_init(BackendFuncs
*func_list
);
147 struct ALCdevice_struct
149 ALboolean IsCaptureDevice
;
155 ALCchar
*szDeviceName
;
157 // Maximum number of sources that can be created
158 ALuint MaxNoOfSources
;
160 // Context created on this device
164 void *ExtraData
; // For the backend's use
169 #define ALCdevice_OpenPlayback(a,b) ((a)->Funcs->OpenPlayback((a), (b)))
170 #define ALCdevice_ClosePlayback(a) ((a)->Funcs->ClosePlayback((a)))
171 #define ALCdevice_OpenCapture(a,b,c,d,e) ((a)->Funcs->OpenCapture((a), (b), (c), (d), (e)))
172 #define ALCdevice_CloseCapture(a) ((a)->Funcs->CloseCapture((a)))
173 #define ALCdevice_StartCapture(a) ((a)->Funcs->StartCapture((a)))
174 #define ALCdevice_StopCapture(a) ((a)->Funcs->StopCapture((a)))
175 #define ALCdevice_CaptureSamples(a,b,c) ((a)->Funcs->CaptureSamples((a), (b), (c)))
176 #define ALCdevice_AvailableSamples(a) ((a)->Funcs->AvailableSamples((a)))
178 struct ALCcontext_struct
182 struct ALsource
*Source
;
185 struct ALeffectslot
*AuxiliaryEffectSlot
;
186 ALuint AuxiliaryEffectSlotCount
;
193 ALenum DistanceModel
;
195 ALfloat DopplerFactor
;
196 ALfloat DopplerVelocity
;
197 ALfloat flSpeedOfSound
;
199 ALint lNumMonoSources
;
200 ALint lNumStereoSources
;
203 ALCchar ExtensionList
[1024];
210 ALCvoid
ReleaseALC(ALCvoid
);
212 ALCchar
*AppendDeviceList(char *name
);
213 ALCchar
*AppendAllDeviceList(char *name
);
214 ALCchar
*AppendCaptureDeviceList(char *name
);
216 ALCvoid
SetALCError(ALenum errorCode
);
218 ALCvoid
SuspendContext(ALCcontext
*context
);
219 ALCvoid
ProcessContext(ALCcontext
*context
);
221 ALvoid
*StartThread(ALuint (*func
)(ALvoid
*), ALvoid
*ptr
);
222 ALuint
StopThread(ALvoid
*thread
);
224 typedef struct RingBuffer RingBuffer
;
225 RingBuffer
*CreateRingBuffer(ALsizei frame_size
, ALsizei length
);
226 void DestroyRingBuffer(RingBuffer
*ring
);
227 ALsizei
RingBufferSize(RingBuffer
*ring
);
228 void WriteRingBuffer(RingBuffer
*ring
, const ALubyte
*data
, ALsizei len
);
229 void ReadRingBuffer(RingBuffer
*ring
, ALubyte
*data
, ALsizei len
);
231 void ReadALConfig(void);
232 void FreeALConfig(void);
233 const char *GetConfigValue(const char *blockName
, const char *keyName
, const char *def
);
234 int GetConfigValueInt(const char *blockName
, const char *keyName
, int def
);
235 float GetConfigValueFloat(const char *blockName
, const char *keyName
, float def
);