Move extension function declarations to alext.h/efx.h
[openal-soft.git] / OpenAL32 / Include / alMain.h
blob58c5ef6ab5dc2102962abe169fca67c57bc6e2c8
1 #ifndef AL_MAIN_H
2 #define AL_MAIN_H
4 #include <string.h>
5 #include <stdio.h>
6 #include <stdarg.h>
8 #ifdef HAVE_FENV_H
9 #include <fenv.h>
10 #endif
12 #include "AL/al.h"
13 #include "AL/alc.h"
14 #include "AL/alext.h"
16 #if defined(HAVE_STDINT_H)
17 #include <stdint.h>
18 typedef int64_t ALint64;
19 typedef uint64_t ALuint64;
20 #elif defined(HAVE___INT64)
21 typedef __int64 ALint64;
22 typedef unsigned __int64 ALuint64;
23 #elif (SIZEOF_LONG == 8)
24 typedef long ALint64;
25 typedef unsigned long ALuint64;
26 #elif (SIZEOF_LONG_LONG == 8)
27 typedef long long ALint64;
28 typedef unsigned long long ALuint64;
29 #endif
31 #ifdef HAVE_GCC_FORMAT
32 #define PRINTF_STYLE(x, y) __attribute__((format(printf, (x), (y))))
33 #else
34 #define PRINTF_STYLE(x, y)
35 #endif
37 #ifdef _WIN32
39 #ifndef _WIN32_WINNT
40 #define _WIN32_WINNT 0x0500
41 #endif
42 #include <windows.h>
44 typedef DWORD tls_type;
45 #define tls_create(x) (*(x) = TlsAlloc())
46 #define tls_delete(x) TlsFree((x))
47 #define tls_get(x) TlsGetValue((x))
48 #define tls_set(x, a) TlsSetValue((x), (a))
50 #else
52 #include <unistd.h>
53 #include <assert.h>
54 #include <pthread.h>
55 #ifdef HAVE_PTHREAD_NP_H
56 #include <pthread_np.h>
57 #endif
58 #include <sys/time.h>
59 #include <time.h>
60 #include <errno.h>
62 #define IsBadWritePtr(a,b) ((a) == NULL && (b) != 0)
64 typedef pthread_key_t tls_type;
65 #define tls_create(x) pthread_key_create((x), NULL)
66 #define tls_delete(x) pthread_key_delete((x))
67 #define tls_get(x) pthread_getspecific((x))
68 #define tls_set(x, a) pthread_setspecific((x), (a))
70 typedef pthread_mutex_t CRITICAL_SECTION;
71 static inline void EnterCriticalSection(CRITICAL_SECTION *cs)
73 int ret;
74 ret = pthread_mutex_lock(cs);
75 assert(ret == 0);
77 static inline void LeaveCriticalSection(CRITICAL_SECTION *cs)
79 int ret;
80 ret = pthread_mutex_unlock(cs);
81 assert(ret == 0);
83 static inline void InitializeCriticalSection(CRITICAL_SECTION *cs)
85 pthread_mutexattr_t attrib;
86 int ret;
88 ret = pthread_mutexattr_init(&attrib);
89 assert(ret == 0);
91 ret = pthread_mutexattr_settype(&attrib, PTHREAD_MUTEX_RECURSIVE);
92 #ifdef HAVE_PTHREAD_NP_H
93 if(ret != 0)
94 ret = pthread_mutexattr_setkind_np(&attrib, PTHREAD_MUTEX_RECURSIVE);
95 #endif
96 assert(ret == 0);
97 ret = pthread_mutex_init(cs, &attrib);
98 assert(ret == 0);
100 pthread_mutexattr_destroy(&attrib);
103 static inline void DeleteCriticalSection(CRITICAL_SECTION *cs)
105 int ret;
106 ret = pthread_mutex_destroy(cs);
107 assert(ret == 0);
110 /* NOTE: This wrapper isn't quite accurate as it returns an ALuint, as opposed
111 * to the expected DWORD. Both are defined as unsigned 32-bit types, however.
112 * Additionally, Win32 is supposed to measure the time since Windows started,
113 * as opposed to the actual time. */
114 static inline ALuint timeGetTime(void)
116 int ret;
117 #if _POSIX_TIMERS > 0
118 struct timespec ts;
120 ret = clock_gettime(CLOCK_REALTIME, &ts);
121 assert(ret == 0);
123 return ts.tv_nsec/1000000 + ts.tv_sec*1000;
124 #else
125 struct timeval tv;
127 ret = gettimeofday(&tv, NULL);
128 assert(ret == 0);
130 return tv.tv_usec/1000 + tv.tv_sec*1000;
131 #endif
134 static inline void Sleep(ALuint t)
136 struct timespec tv, rem;
137 tv.tv_nsec = (t*1000000)%1000000000;
138 tv.tv_sec = t/1000;
140 while(nanosleep(&tv, &rem) == -1 && errno == EINTR)
141 tv = rem;
143 #define min(x,y) (((x)<(y))?(x):(y))
144 #define max(x,y) (((x)>(y))?(x):(y))
145 #endif
147 #include "alListener.h"
148 #include "alu.h"
150 #ifdef __cplusplus
151 extern "C" {
152 #endif
155 #define SWMIXER_OUTPUT_RATE 44100
157 #define SPEEDOFSOUNDMETRESPERSEC (343.3f)
158 #define AIRABSORBGAINDBHF (-0.05f)
160 #define LOWPASSFREQCUTOFF (5000)
162 #define DEFAULT_HEAD_DAMPEN (0.25f)
165 // Find the next power-of-2 for non-power-of-2 numbers.
166 static __inline ALuint NextPowerOf2(ALuint value)
168 ALuint powerOf2 = 1;
170 if(value)
172 value--;
173 while(value)
175 value >>= 1;
176 powerOf2 <<= 1;
179 return powerOf2;
183 typedef struct {
184 ALCboolean (*OpenPlayback)(ALCdevice*, const ALCchar*);
185 void (*ClosePlayback)(ALCdevice*);
186 ALCboolean (*ResetPlayback)(ALCdevice*);
187 void (*StopPlayback)(ALCdevice*);
189 ALCboolean (*OpenCapture)(ALCdevice*, const ALCchar*);
190 void (*CloseCapture)(ALCdevice*);
191 void (*StartCapture)(ALCdevice*);
192 void (*StopCapture)(ALCdevice*);
193 void (*CaptureSamples)(ALCdevice*, void*, ALCuint);
194 ALCuint (*AvailableSamples)(ALCdevice*);
195 } BackendFuncs;
197 enum {
198 DEVICE_PROBE,
199 ALL_DEVICE_PROBE,
200 CAPTURE_DEVICE_PROBE
203 void alc_alsa_init(BackendFuncs *func_list);
204 void alc_alsa_deinit(void);
205 void alc_alsa_probe(int type);
206 void alc_oss_init(BackendFuncs *func_list);
207 void alc_oss_deinit(void);
208 void alc_oss_probe(int type);
209 void alc_solaris_init(BackendFuncs *func_list);
210 void alc_solaris_deinit(void);
211 void alc_solaris_probe(int type);
212 void alcDSoundInit(BackendFuncs *func_list);
213 void alcDSoundDeinit(void);
214 void alcDSoundProbe(int type);
215 void alcWinMMInit(BackendFuncs *FuncList);
216 void alcWinMMDeinit(void);
217 void alcWinMMProbe(int type);
218 void alc_pa_init(BackendFuncs *func_list);
219 void alc_pa_deinit(void);
220 void alc_pa_probe(int type);
221 void alc_wave_init(BackendFuncs *func_list);
222 void alc_wave_deinit(void);
223 void alc_wave_probe(int type);
224 void alc_pulse_init(BackendFuncs *func_list);
225 void alc_pulse_deinit(void);
226 void alc_pulse_probe(int type);
229 struct ALCdevice_struct
231 ALCboolean Connected;
232 ALboolean IsCaptureDevice;
234 ALuint Frequency;
235 ALuint UpdateSize;
236 ALuint NumUpdates;
237 ALenum Format;
239 ALCchar *szDeviceName;
241 ALCenum LastError;
243 // Maximum number of sources that can be created
244 ALuint MaxNoOfSources;
245 // Maximum number of slots that can be created
246 ALuint AuxiliaryEffectSlotMax;
248 ALint lNumMonoSources;
249 ALint lNumStereoSources;
250 ALuint NumAuxSends;
252 // Linked List of Buffers for this device
253 struct ALbuffer *BufferList;
254 ALuint BufferCount;
256 // Linked List of Effects for this device
257 struct ALeffect *EffectList;
258 ALuint EffectCount;
260 // Linked List of Filters for this device
261 struct ALfilter *FilterList;
262 ALuint FilterCount;
264 // Linked List of Databuffers for this device
265 struct ALdatabuffer *DatabufferList;
266 ALuint DatabufferCount;
268 // Stereo-to-binaural filter
269 struct bs2b *Bs2b;
270 ALCint Bs2bLevel;
272 // Simulated dampening from head occlusion
273 ALfloat HeadDampen;
275 // Dry path buffer mix
276 float DryBuffer[BUFFERSIZE][OUTPUTCHANNELS];
278 Channel DevChannels[OUTPUTCHANNELS];
280 // Contexts created on this device
281 ALCcontext **Contexts;
282 ALuint NumContexts;
284 BackendFuncs *Funcs;
285 void *ExtraData; // For the backend's use
287 ALCdevice *next;
290 #define ALCdevice_OpenPlayback(a,b) ((a)->Funcs->OpenPlayback((a), (b)))
291 #define ALCdevice_ClosePlayback(a) ((a)->Funcs->ClosePlayback((a)))
292 #define ALCdevice_ResetPlayback(a) ((a)->Funcs->ResetPlayback((a)))
293 #define ALCdevice_StopPlayback(a) ((a)->Funcs->StopPlayback((a)))
294 #define ALCdevice_OpenCapture(a,b) ((a)->Funcs->OpenCapture((a), (b)))
295 #define ALCdevice_CloseCapture(a) ((a)->Funcs->CloseCapture((a)))
296 #define ALCdevice_StartCapture(a) ((a)->Funcs->StartCapture((a)))
297 #define ALCdevice_StopCapture(a) ((a)->Funcs->StopCapture((a)))
298 #define ALCdevice_CaptureSamples(a,b,c) ((a)->Funcs->CaptureSamples((a), (b), (c)))
299 #define ALCdevice_AvailableSamples(a) ((a)->Funcs->AvailableSamples((a)))
301 struct ALCcontext_struct
303 ALlistener Listener;
305 struct ALsource *SourceList;
306 ALuint SourceCount;
308 struct ALeffectslot *EffectSlotList;
309 ALuint EffectSlotCount;
311 struct ALdatabuffer *SampleSource;
312 struct ALdatabuffer *SampleSink;
314 ALenum LastError;
315 ALboolean InUse;
317 ALboolean Suspended;
319 ALenum DistanceModel;
320 ALboolean SourceDistanceModel;
322 ALfloat DopplerFactor;
323 ALfloat DopplerVelocity;
324 ALfloat flSpeedOfSound;
326 ALfloat PanningLUT[OUTPUTCHANNELS * LUT_NUM];
327 ALint NumChan;
329 ALfloat ChannelMatrix[OUTPUTCHANNELS][OUTPUTCHANNELS];
331 ALCdevice *Device;
332 const ALCchar *ExtensionList;
334 ALCcontext *next;
337 extern ALint RTPrioLevel;
339 ALCvoid ReleaseALC(ALCvoid);
341 void AppendDeviceList(const ALCchar *name);
342 void AppendAllDeviceList(const ALCchar *name);
343 void AppendCaptureDeviceList(const ALCchar *name);
345 ALCvoid alcSetError(ALCdevice *device, ALenum errorCode);
347 ALCvoid SuspendContext(ALCcontext *context);
348 ALCvoid ProcessContext(ALCcontext *context);
350 ALvoid *StartThread(ALuint (*func)(ALvoid*), ALvoid *ptr);
351 ALuint StopThread(ALvoid *thread);
353 ALCcontext *GetContextSuspended(void);
355 typedef struct RingBuffer RingBuffer;
356 RingBuffer *CreateRingBuffer(ALsizei frame_size, ALsizei length);
357 void DestroyRingBuffer(RingBuffer *ring);
358 ALsizei RingBufferSize(RingBuffer *ring);
359 void WriteRingBuffer(RingBuffer *ring, const ALubyte *data, ALsizei len);
360 void ReadRingBuffer(RingBuffer *ring, ALubyte *data, ALsizei len);
362 void ReadALConfig(void);
363 void FreeALConfig(void);
364 int ConfigValueExists(const char *blockName, const char *keyName);
365 const char *GetConfigValue(const char *blockName, const char *keyName, const char *def);
366 int GetConfigValueInt(const char *blockName, const char *keyName, int def);
367 float GetConfigValueFloat(const char *blockName, const char *keyName, float def);
368 int GetConfigValueBool(const char *blockName, const char *keyName, int def);
370 void EnableRTPrio(ALint level);
372 void SetDefaultChannelOrder(ALCdevice *device);
373 void SetDefaultWFXChannelOrder(ALCdevice *device);
375 void al_print(const char *fname, unsigned int line, const char *fmt, ...)
376 PRINTF_STYLE(3,4);
377 #define AL_PRINT(...) al_print(__FILE__, __LINE__, __VA_ARGS__)
379 #define DECL_VERIFIER(name, type, field) \
380 static type* Verify##name(type *list, ALuint id) \
382 while(list && list->field != id) \
383 list = list->next; \
384 return list; \
387 #ifdef __cplusplus
389 #endif
391 #endif