Define _WIN32_WINNT to 0x0500 when including windows.h
[openal-soft.git] / OpenAL32 / Include / alMain.h
blob886168e0a7667f229ff2528c633b5fae2e4328b5
1 #ifndef AL_MAIN_H
2 #define AL_MAIN_H
4 #include <string.h>
5 #include <stdio.h>
7 #include "alu.h"
9 #ifdef _WIN32
11 #ifndef _WIN32_WINNT
12 #define _WIN32_WINNT 0x0500
13 #endif
14 #include <windows.h>
16 #else
18 #include <assert.h>
19 #include <pthread.h>
20 #include <sys/time.h>
21 #include <time.h>
22 #include <errno.h>
24 #define IsBadWritePtr(a,b) (0)
26 typedef pthread_mutex_t CRITICAL_SECTION;
27 static inline void EnterCriticalSection(CRITICAL_SECTION *cs)
29 int ret;
30 ret = pthread_mutex_lock(cs);
31 assert(ret == 0);
33 static inline void LeaveCriticalSection(CRITICAL_SECTION *cs)
35 int ret;
36 ret = pthread_mutex_unlock(cs);
37 assert(ret == 0);
39 static inline void InitializeCriticalSection(CRITICAL_SECTION *cs)
41 pthread_mutexattr_t attrib;
42 int ret;
44 ret = pthread_mutexattr_init(&attrib);
45 assert(ret == 0);
47 ret = pthread_mutexattr_settype(&attrib, PTHREAD_MUTEX_RECURSIVE);
48 assert(ret == 0);
49 ret = pthread_mutex_init(cs, &attrib);
50 assert(ret == 0);
52 pthread_mutexattr_destroy(&attrib);
55 static inline void DeleteCriticalSection(CRITICAL_SECTION *cs)
57 int ret;
58 ret = pthread_mutex_destroy(cs);
59 assert(ret == 0);
62 /* NOTE: This wrapper isn't quite accurate as it returns an ALuint, as opposed
63 * to the expected DWORD. Both are defined as unsigned 32-bit types, however.
64 * Additionally, Win32 is supposed to measure the time since Windows started,
65 * as opposed to the actual time. */
66 static inline ALuint timeGetTime(void)
68 struct timeval tv;
69 int ret;
71 ret = gettimeofday(&tv, NULL);
72 assert(ret == 0);
74 return tv.tv_usec/1000 + tv.tv_sec*1000;
77 static inline void Sleep(ALuint t)
79 struct timespec tv, rem;
80 tv.tv_nsec = (t*1000000)%1000000000;
81 tv.tv_sec = t/1000;
83 while(nanosleep(&tv, &rem) == -1 && errno == EINTR)
84 tv = rem;
86 #define min(x,y) (((x)<(y))?(x):(y))
87 #define max(x,y) (((x)>(y))?(x):(y))
88 #endif
90 #include "AL/al.h"
91 #include "AL/alc.h"
92 #include "AL/alext.h"
93 #include "alListener.h"
95 #ifdef __cplusplus
96 extern "C" {
97 #endif
99 extern CRITICAL_SECTION _alMutex;
101 extern char _alDebug[256];
103 #define AL_PRINT(...) do { \
104 int _al_print_i; \
105 char *_al_print_fn = strrchr(__FILE__, '/'); \
106 if(!_al_print_fn) _al_print_fn = __FILE__; \
107 else _al_print_fn += 1; \
108 _al_print_i = snprintf(_alDebug, sizeof(_alDebug), "AL lib: %s:%d: ", _al_print_fn, __LINE__); \
109 if(_al_print_i < (int)sizeof(_alDebug) && _al_print_i > 0) \
110 snprintf(_alDebug+_al_print_i, sizeof(_alDebug)-_al_print_i, __VA_ARGS__); \
111 _alDebug[sizeof(_alDebug)-1] = 0; \
112 fprintf(stderr, "%s", _alDebug); \
113 } while(0)
116 #define SWMIXER_OUTPUT_RATE 44100
118 #define SPEEDOFSOUNDMETRESPERSEC (343.3f)
119 #define AIRABSORBGAINHF (0.994f)
121 typedef struct {
122 ALCboolean (*OpenPlayback)(ALCdevice*, const ALCchar*);
123 void (*ClosePlayback)(ALCdevice*);
125 ALCboolean (*OpenCapture)(ALCdevice*, const ALCchar*, ALCuint, ALCenum, ALCsizei);
126 void (*CloseCapture)(ALCdevice*);
127 void (*StartCapture)(ALCdevice*);
128 void (*StopCapture)(ALCdevice*);
129 void (*CaptureSamples)(ALCdevice*, void*, ALCuint);
130 ALCuint (*AvailableSamples)(ALCdevice*);
131 } BackendFuncs;
133 void alc_alsa_init(BackendFuncs *func_list);
134 void alc_oss_init(BackendFuncs *func_list);
135 void alcDSoundInit(BackendFuncs *func_list);
136 void alcWinMMInit(BackendFuncs *FuncList);
137 void alc_wave_init(BackendFuncs *func_list);
140 struct ALCdevice_struct
142 ALboolean IsCaptureDevice;
144 ALuint Frequency;
145 ALuint UpdateSize;
146 ALenum Format;
148 ALCchar *szDeviceName;
150 // Maximum number of sources that can be created
151 ALuint MaxNoOfSources;
153 // Context created on this device
154 ALCcontext *Context;
156 BackendFuncs *Funcs;
157 void *ExtraData; // For the backend's use
159 ALCdevice *next;
162 #define ALCdevice_OpenPlayback(a,b) ((a)->Funcs->OpenPlayback((a), (b)))
163 #define ALCdevice_ClosePlayback(a) ((a)->Funcs->ClosePlayback((a)))
164 #define ALCdevice_OpenCapture(a,b,c,d,e) ((a)->Funcs->OpenCapture((a), (b), (c), (d), (e)))
165 #define ALCdevice_CloseCapture(a) ((a)->Funcs->CloseCapture((a)))
166 #define ALCdevice_StartCapture(a) ((a)->Funcs->StartCapture((a)))
167 #define ALCdevice_StopCapture(a) ((a)->Funcs->StopCapture((a)))
168 #define ALCdevice_CaptureSamples(a,b,c) ((a)->Funcs->CaptureSamples((a), (b), (c)))
169 #define ALCdevice_AvailableSamples(a) ((a)->Funcs->AvailableSamples((a)))
171 struct ALCcontext_struct
173 ALlistener Listener;
175 struct ALsource *Source;
176 ALuint SourceCount;
178 struct ALeffectslot *AuxiliaryEffectSlot;
179 ALuint AuxiliaryEffectSlotCount;
181 ALenum LastError;
182 ALboolean InUse;
184 ALuint Frequency;
186 ALenum DistanceModel;
188 ALfloat DopplerFactor;
189 ALfloat DopplerVelocity;
190 ALfloat flSpeedOfSound;
192 ALint lNumMonoSources;
193 ALint lNumStereoSources;
195 ALCdevice *Device;
196 ALCchar ExtensionList[1024];
198 struct bs2b *bs2b;
200 ALCcontext *next;
203 ALCvoid ReleaseALC(ALCvoid);
205 ALCchar *AppendDeviceList(char *name);
206 ALCchar *AppendAllDeviceList(char *name);
207 ALCchar *AppendCaptureDeviceList(char *name);
209 ALCvoid SetALCError(ALenum errorCode);
211 ALCvoid SuspendContext(ALCcontext *context);
212 ALCvoid ProcessContext(ALCcontext *context);
214 ALvoid *StartThread(ALuint (*func)(ALvoid*), ALvoid *ptr);
215 ALuint StopThread(ALvoid *thread);
217 typedef struct RingBuffer RingBuffer;
218 RingBuffer *CreateRingBuffer(ALsizei frame_size, ALsizei length);
219 void DestroyRingBuffer(RingBuffer *ring);
220 ALsizei RingBufferSize(RingBuffer *ring);
221 void WriteRingBuffer(RingBuffer *ring, const ALubyte *data, ALsizei len);
222 void ReadRingBuffer(RingBuffer *ring, ALubyte *data, ALsizei len);
224 void ReadALConfig(void);
225 void FreeALConfig(void);
226 const char *GetConfigValue(const char *blockName, const char *keyName, const char *def);
227 int GetConfigValueInt(const char *blockName, const char *keyName, int def);
228 float GetConfigValueFloat(const char *blockName, const char *keyName, float def);
230 #ifdef __cplusplus
232 #endif
234 #endif