Remove unused macro
[openal-soft.git] / OpenAL32 / Include / alMain.h
blobdbf3ef90082b8281632f9b88ebfd8c85ec8f7a52
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 #ifndef AL_EXT_buffer_sub_data
17 #define AL_EXT_buffer_sub_data 1
18 #define AL_BYTE_RW_OFFSETS_EXT 0x1031
19 #define AL_SAMPLE_RW_OFFSETS_EXT 0x1032
20 typedef ALvoid (AL_APIENTRY*PFNALBUFFERSUBDATAEXTPROC)(ALuint,ALenum,const ALvoid*,ALsizei,ALsizei);
21 #ifdef AL_ALEXT_PROTOTYPES
22 AL_API ALvoid AL_APIENTRY alBufferSubDataEXT(ALuint buffer,ALenum format,const ALvoid *data,ALsizei offset,ALsizei length);
23 #endif
24 #endif
26 #ifndef AL_EXT_sample_buffer_object
27 #define AL_EXT_sample_buffer_object 1
28 typedef ptrdiff_t ALintptrEXT;
29 typedef ptrdiff_t ALsizeiptrEXT;
30 #define AL_SAMPLE_SOURCE_EXT 0x1040
31 #define AL_SAMPLE_SINK_EXT 0x1041
32 #define AL_READ_ONLY_EXT 0x1042
33 #define AL_WRITE_ONLY_EXT 0x1043
34 #define AL_READ_WRITE_EXT 0x1044
35 #define AL_STREAM_WRITE_EXT 0x1045
36 #define AL_STREAM_READ_EXT 0x1046
37 #define AL_STREAM_COPY_EXT 0x1047
38 #define AL_STATIC_WRITE_EXT 0x1048
39 #define AL_STATIC_READ_EXT 0x1049
40 #define AL_STATIC_COPY_EXT 0x104A
41 #define AL_DYNAMIC_WRITE_EXT 0x104B
42 #define AL_DYNAMIC_READ_EXT 0x104C
43 #define AL_DYNAMIC_COPY_EXT 0x104D
44 typedef ALvoid (AL_APIENTRY*PFNALGENDATABUFFERSEXTPROC)(ALsizei n,ALuint *puiBuffers);
45 typedef ALvoid (AL_APIENTRY*PFNALDELETEDATABUFFERSEXTPROC)(ALsizei n, const ALuint *puiBuffers);
46 typedef ALboolean (AL_APIENTRY*PFNALISDATABUFFEREXTPROC)(ALuint uiBuffer);
47 typedef ALvoid (AL_APIENTRY*PFNALDATABUFFERDATAEXTPROC)(ALuint buffer,const ALvoid *data,ALsizeiptrEXT size,ALenum usage);
48 typedef ALvoid (AL_APIENTRY*PFNALDATABUFFERSUBDATAEXTPROC)(ALuint buffer, ALintptrEXT start, ALsizeiptrEXT length, const ALvoid *);
49 typedef ALvoid (AL_APIENTRY*PFNALGETDATABUFFERSUBDATAEXTPROC)(ALuint buffer, ALintptrEXT start, ALsizeiptrEXT length, ALvoid *);
50 typedef ALvoid (AL_APIENTRY*PFNALDATABUFFERFEXTPROC)(ALuint buffer, ALenum eParam, ALfloat flValue);
51 typedef ALvoid (AL_APIENTRY*PFNALDATABUFFERFVEXTPROC)(ALuint buffer, ALenum eParam, const ALfloat* flValues);
52 typedef ALvoid (AL_APIENTRY*PFNALDATABUFFERIEXTPROC)(ALuint buffer, ALenum eParam, ALint lValue);
53 typedef ALvoid (AL_APIENTRY*PFNALDATABUFFERIVEXTPROC)(ALuint buffer, ALenum eParam, const ALint* plValues);
54 typedef ALvoid (AL_APIENTRY*PFNALGETDATABUFFERFEXTPROC)(ALuint buffer, ALenum eParam, ALfloat *pflValue);
55 typedef ALvoid (AL_APIENTRY*PFNALGETDATABUFFERFVEXTPROC)(ALuint buffer, ALenum eParam, ALfloat* pflValues);
56 typedef ALvoid (AL_APIENTRY*PFNALGETDATABUFFERIEXTPROC)(ALuint buffer, ALenum eParam, ALint *plValue);
57 typedef ALvoid (AL_APIENTRY*PFNALGETDATABUFFERIVEXTPROC)(ALuint buffer, ALenum eParam, ALint* plValues);
58 typedef ALvoid (AL_APIENTRY*PFNALSELECTDATABUFFEREXTPROC)(ALenum target, ALuint uiBuffer);
59 typedef ALvoid* (AL_APIENTRY*PFNALMAPDATABUFFEREXTPROC)(ALuint uiBuffer, ALintptrEXT start, ALsizeiptrEXT length, ALenum access);
60 typedef ALvoid (AL_APIENTRY*PFNALUNMAPDATABUFFEREXTPROC)(ALuint uiBuffer);
61 #ifdef AL_ALEXT_PROTOTYPES
62 AL_API ALvoid AL_APIENTRY alGenDatabuffersEXT(ALsizei n,ALuint *puiBuffers);
63 AL_API ALvoid AL_APIENTRY alDeleteDatabuffersEXT(ALsizei n, const ALuint *puiBuffers);
64 AL_API ALboolean AL_APIENTRY alIsDatabufferEXT(ALuint uiBuffer);
65 AL_API ALvoid AL_APIENTRY alDatabufferDataEXT(ALuint buffer,const ALvoid *data,ALsizeiptrEXT size,ALenum usage);
66 AL_API ALvoid AL_APIENTRY alDatabufferSubDataEXT(ALuint buffer, ALintptrEXT start, ALsizeiptrEXT length, const ALvoid *data);
67 AL_API ALvoid AL_APIENTRY alGetDatabufferSubDataEXT(ALuint buffer, ALintptrEXT start, ALsizeiptrEXT length, ALvoid *data);
68 AL_API ALvoid AL_APIENTRY alDatabufferfEXT(ALuint buffer, ALenum eParam, ALfloat flValue);
69 AL_API ALvoid AL_APIENTRY alDatabufferfvEXT(ALuint buffer, ALenum eParam, const ALfloat* flValues);
70 AL_API ALvoid AL_APIENTRY alDatabufferiEXT(ALuint buffer, ALenum eParam, ALint lValue);
71 AL_API ALvoid AL_APIENTRY alDatabufferivEXT(ALuint buffer, ALenum eParam, const ALint* plValues);
72 AL_API ALvoid AL_APIENTRY alGetDatabufferfEXT(ALuint buffer, ALenum eParam, ALfloat *pflValue);
73 AL_API ALvoid AL_APIENTRY alGetDatabufferfvEXT(ALuint buffer, ALenum eParam, ALfloat* pflValues);
74 AL_API ALvoid AL_APIENTRY alGetDatabufferiEXT(ALuint buffer, ALenum eParam, ALint *plValue);
75 AL_API ALvoid AL_APIENTRY alGetDatabufferivEXT(ALuint buffer, ALenum eParam, ALint* plValues);
76 AL_API ALvoid AL_APIENTRY alSelectDatabufferEXT(ALenum target, ALuint uiBuffer);
77 AL_API ALvoid* AL_APIENTRY alMapDatabufferEXT(ALuint uiBuffer, ALintptrEXT start, ALsizeiptrEXT length, ALenum access);
78 AL_API ALvoid AL_APIENTRY alUnmapDatabufferEXT(ALuint uiBuffer);
79 #endif
80 #endif
82 #ifndef AL_EXT_loop_points
83 #define AL_EXT_loop_points 1
84 #define AL_LOOP_POINTS 0x2015
85 #endif
88 #if defined(HAVE_STDINT_H)
89 #include <stdint.h>
90 typedef int64_t ALint64;
91 typedef uint64_t ALuint64;
92 #elif defined(HAVE___INT64)
93 typedef __int64 ALint64;
94 typedef unsigned __int64 ALuint64;
95 #elif (SIZEOF_LONG == 8)
96 typedef long ALint64;
97 typedef unsigned long ALuint64;
98 #elif (SIZEOF_LONG_LONG == 8)
99 typedef long long ALint64;
100 typedef unsigned long long ALuint64;
101 #endif
103 #ifdef HAVE_GCC_FORMAT
104 #define PRINTF_STYLE(x, y) __attribute__((format(printf, (x), (y))))
105 #else
106 #define PRINTF_STYLE(x, y)
107 #endif
109 #ifdef _WIN32
111 #ifndef _WIN32_WINNT
112 #define _WIN32_WINNT 0x0500
113 #endif
114 #include <windows.h>
116 typedef DWORD tls_type;
117 #define tls_create(x) (*(x) = TlsAlloc())
118 #define tls_delete(x) TlsFree((x))
119 #define tls_get(x) TlsGetValue((x))
120 #define tls_set(x, a) TlsSetValue((x), (a))
122 #else
124 #include <unistd.h>
125 #include <assert.h>
126 #include <pthread.h>
127 #ifdef HAVE_PTHREAD_NP_H
128 #include <pthread_np.h>
129 #endif
130 #include <sys/time.h>
131 #include <time.h>
132 #include <errno.h>
134 #define IsBadWritePtr(a,b) ((a) == NULL && (b) != 0)
136 typedef pthread_key_t tls_type;
137 #define tls_create(x) pthread_key_create((x), NULL)
138 #define tls_delete(x) pthread_key_delete((x))
139 #define tls_get(x) pthread_getspecific((x))
140 #define tls_set(x, a) pthread_setspecific((x), (a))
142 typedef pthread_mutex_t CRITICAL_SECTION;
143 static __inline void EnterCriticalSection(CRITICAL_SECTION *cs)
145 int ret;
146 ret = pthread_mutex_lock(cs);
147 assert(ret == 0);
149 static __inline void LeaveCriticalSection(CRITICAL_SECTION *cs)
151 int ret;
152 ret = pthread_mutex_unlock(cs);
153 assert(ret == 0);
155 static __inline void InitializeCriticalSection(CRITICAL_SECTION *cs)
157 pthread_mutexattr_t attrib;
158 int ret;
160 ret = pthread_mutexattr_init(&attrib);
161 assert(ret == 0);
163 ret = pthread_mutexattr_settype(&attrib, PTHREAD_MUTEX_RECURSIVE);
164 #ifdef HAVE_PTHREAD_NP_H
165 if(ret != 0)
166 ret = pthread_mutexattr_setkind_np(&attrib, PTHREAD_MUTEX_RECURSIVE);
167 #endif
168 assert(ret == 0);
169 ret = pthread_mutex_init(cs, &attrib);
170 assert(ret == 0);
172 pthread_mutexattr_destroy(&attrib);
175 static __inline void DeleteCriticalSection(CRITICAL_SECTION *cs)
177 int ret;
178 ret = pthread_mutex_destroy(cs);
179 assert(ret == 0);
182 /* NOTE: This wrapper isn't quite accurate as it returns an ALuint, as opposed
183 * to the expected DWORD. Both are defined as unsigned 32-bit types, however.
184 * Additionally, Win32 is supposed to measure the time since Windows started,
185 * as opposed to the actual time. */
186 static __inline ALuint timeGetTime(void)
188 #if _POSIX_TIMERS > 0
189 static int hasmono = 0;
190 struct timespec ts;
191 int ret = -1;
193 #if defined(_POSIX_MONOTONIC_CLOCK) && (_POSIX_MONOTONIC_CLOCK >= 0)
194 #if _POSIX_MONOTONIC_CLOCK == 0
195 if(hasmono > 0 || (hasmono == 0 &&
196 (hasmono=sysconf(_SC_MONOTONIC_CLOCK)) > 0))
197 #endif
198 ret = clock_gettime(CLOCK_MONOTONIC, &ts);
199 #endif
200 if(ret != 0)
201 ret = clock_gettime(CLOCK_REALTIME, &ts);
202 assert(ret == 0);
204 return ts.tv_nsec/1000000 + ts.tv_sec*1000;
205 #else
206 struct timeval tv;
207 int ret;
209 ret = gettimeofday(&tv, NULL);
210 assert(ret == 0);
212 return tv.tv_usec/1000 + tv.tv_sec*1000;
213 #endif
216 static __inline void Sleep(ALuint t)
218 struct timespec tv, rem;
219 tv.tv_nsec = (t*1000000)%1000000000;
220 tv.tv_sec = t/1000;
222 while(nanosleep(&tv, &rem) == -1 && errno == EINTR)
223 tv = rem;
225 #define min(x,y) (((x)<(y))?(x):(y))
226 #define max(x,y) (((x)>(y))?(x):(y))
227 #endif
229 #include "alListener.h"
230 #include "alu.h"
232 #ifdef __cplusplus
233 extern "C" {
234 #endif
237 #define SWMIXER_OUTPUT_RATE 44100
239 #define SPEEDOFSOUNDMETRESPERSEC (343.3f)
240 #define AIRABSORBGAINDBHF (-0.05f)
242 #define LOWPASSFREQCUTOFF (5000)
244 #define DEFAULT_HEAD_DAMPEN (0.25f)
247 // Find the next power-of-2 for non-power-of-2 numbers.
248 static __inline ALuint NextPowerOf2(ALuint value)
250 ALuint powerOf2 = 1;
252 if(value)
254 value--;
255 while(value)
257 value >>= 1;
258 powerOf2 <<= 1;
261 return powerOf2;
265 typedef struct {
266 ALCboolean (*OpenPlayback)(ALCdevice*, const ALCchar*);
267 void (*ClosePlayback)(ALCdevice*);
268 ALCboolean (*ResetPlayback)(ALCdevice*);
269 void (*StopPlayback)(ALCdevice*);
271 ALCboolean (*OpenCapture)(ALCdevice*, const ALCchar*);
272 void (*CloseCapture)(ALCdevice*);
273 void (*StartCapture)(ALCdevice*);
274 void (*StopCapture)(ALCdevice*);
275 void (*CaptureSamples)(ALCdevice*, void*, ALCuint);
276 ALCuint (*AvailableSamples)(ALCdevice*);
277 } BackendFuncs;
279 enum {
280 DEVICE_PROBE,
281 ALL_DEVICE_PROBE,
282 CAPTURE_DEVICE_PROBE
285 void alc_alsa_init(BackendFuncs *func_list);
286 void alc_alsa_deinit(void);
287 void alc_alsa_probe(int type);
288 void alc_oss_init(BackendFuncs *func_list);
289 void alc_oss_deinit(void);
290 void alc_oss_probe(int type);
291 void alc_solaris_init(BackendFuncs *func_list);
292 void alc_solaris_deinit(void);
293 void alc_solaris_probe(int type);
294 void alcDSoundInit(BackendFuncs *func_list);
295 void alcDSoundDeinit(void);
296 void alcDSoundProbe(int type);
297 void alcWinMMInit(BackendFuncs *FuncList);
298 void alcWinMMDeinit(void);
299 void alcWinMMProbe(int type);
300 void alc_pa_init(BackendFuncs *func_list);
301 void alc_pa_deinit(void);
302 void alc_pa_probe(int type);
303 void alc_wave_init(BackendFuncs *func_list);
304 void alc_wave_deinit(void);
305 void alc_wave_probe(int type);
306 void alc_pulse_init(BackendFuncs *func_list);
307 void alc_pulse_deinit(void);
308 void alc_pulse_probe(int type);
309 void alc_null_init(BackendFuncs *func_list);
310 void alc_null_deinit(void);
311 void alc_null_probe(int type);
314 typedef struct UIntMap {
315 struct {
316 ALuint key;
317 ALvoid *value;
318 } *array;
319 ALsizei size;
320 ALsizei maxsize;
321 } UIntMap;
323 void InitUIntMap(UIntMap *map);
324 void ResetUIntMap(UIntMap *map);
325 ALenum InsertUIntMapEntry(UIntMap *map, ALuint key, ALvoid *value);
326 void RemoveUIntMapKey(UIntMap *map, ALuint key);
327 ALvoid *LookupUIntMapKey(UIntMap *map, ALuint key);
330 struct ALCdevice_struct
332 ALCboolean Connected;
333 ALboolean IsCaptureDevice;
335 ALuint Frequency;
336 ALuint UpdateSize;
337 ALuint NumUpdates;
338 ALenum Format;
340 ALCchar *szDeviceName;
342 ALCenum LastError;
344 // Maximum number of sources that can be created
345 ALuint MaxNoOfSources;
346 // Maximum number of slots that can be created
347 ALuint AuxiliaryEffectSlotMax;
349 ALCuint NumMonoSources;
350 ALCuint NumStereoSources;
351 ALuint NumAuxSends;
353 // Map of Buffers for this device
354 UIntMap BufferMap;
356 // Map of Effects for this device
357 UIntMap EffectMap;
359 // Map of Filters for this device
360 UIntMap FilterMap;
362 // Map of Databuffers for this device
363 UIntMap DatabufferMap;
365 // Stereo-to-binaural filter
366 struct bs2b *Bs2b;
367 ALCint Bs2bLevel;
369 // Simulated dampening from head occlusion
370 ALfloat HeadDampen;
372 // Duplicate stereo sources on the side/rear channels
373 ALboolean DuplicateStereo;
375 // Dry path buffer mix
376 ALfloat DryBuffer[BUFFERSIZE][MAXCHANNELS];
378 ALuint DevChannels[MAXCHANNELS];
380 ALfloat ChannelMatrix[MAXCHANNELS][MAXCHANNELS];
382 Channel Speaker2Chan[MAXCHANNELS];
383 ALfloat PanningLUT[MAXCHANNELS * LUT_NUM];
384 ALuint NumChan;
386 ALfloat ClickRemoval[MAXCHANNELS];
387 ALfloat PendingClicks[MAXCHANNELS];
389 // Contexts created on this device
390 ALCcontext **Contexts;
391 ALuint NumContexts;
393 BackendFuncs *Funcs;
394 void *ExtraData; // For the backend's use
396 ALCdevice *next;
399 #define ALCdevice_OpenPlayback(a,b) ((a)->Funcs->OpenPlayback((a), (b)))
400 #define ALCdevice_ClosePlayback(a) ((a)->Funcs->ClosePlayback((a)))
401 #define ALCdevice_ResetPlayback(a) ((a)->Funcs->ResetPlayback((a)))
402 #define ALCdevice_StopPlayback(a) ((a)->Funcs->StopPlayback((a)))
403 #define ALCdevice_OpenCapture(a,b) ((a)->Funcs->OpenCapture((a), (b)))
404 #define ALCdevice_CloseCapture(a) ((a)->Funcs->CloseCapture((a)))
405 #define ALCdevice_StartCapture(a) ((a)->Funcs->StartCapture((a)))
406 #define ALCdevice_StopCapture(a) ((a)->Funcs->StopCapture((a)))
407 #define ALCdevice_CaptureSamples(a,b,c) ((a)->Funcs->CaptureSamples((a), (b), (c)))
408 #define ALCdevice_AvailableSamples(a) ((a)->Funcs->AvailableSamples((a)))
410 struct ALCcontext_struct
412 ALlistener Listener;
414 UIntMap SourceMap;
415 UIntMap EffectSlotMap;
417 struct ALdatabuffer *SampleSource;
418 struct ALdatabuffer *SampleSink;
420 ALenum LastError;
422 ALboolean Suspended;
424 ALenum DistanceModel;
425 ALboolean SourceDistanceModel;
427 ALfloat DopplerFactor;
428 ALfloat DopplerVelocity;
429 ALfloat flSpeedOfSound;
431 struct ALsource **ActiveSources;
432 ALsizei ActiveSourceCount;
433 ALsizei MaxActiveSources;
435 ALCdevice *Device;
436 const ALCchar *ExtensionList;
438 ALCcontext *next;
441 ALCvoid ReleaseALC(ALCvoid);
443 void AppendDeviceList(const ALCchar *name);
444 void AppendAllDeviceList(const ALCchar *name);
445 void AppendCaptureDeviceList(const ALCchar *name);
447 ALCvoid alcSetError(ALCdevice *device, ALenum errorCode);
449 ALCvoid SuspendContext(ALCcontext *context);
450 ALCvoid ProcessContext(ALCcontext *context);
452 ALvoid *StartThread(ALuint (*func)(ALvoid*), ALvoid *ptr);
453 ALuint StopThread(ALvoid *thread);
455 ALCcontext *GetContextSuspended(void);
457 typedef struct RingBuffer RingBuffer;
458 RingBuffer *CreateRingBuffer(ALsizei frame_size, ALsizei length);
459 void DestroyRingBuffer(RingBuffer *ring);
460 ALsizei RingBufferSize(RingBuffer *ring);
461 void WriteRingBuffer(RingBuffer *ring, const ALubyte *data, ALsizei len);
462 void ReadRingBuffer(RingBuffer *ring, ALubyte *data, ALsizei len);
464 void ReadALConfig(void);
465 void FreeALConfig(void);
466 int ConfigValueExists(const char *blockName, const char *keyName);
467 const char *GetConfigValue(const char *blockName, const char *keyName, const char *def);
468 int GetConfigValueInt(const char *blockName, const char *keyName, int def);
469 float GetConfigValueFloat(const char *blockName, const char *keyName, float def);
470 int GetConfigValueBool(const char *blockName, const char *keyName, int def);
472 void SetRTPriority(void);
474 void SetDefaultChannelOrder(ALCdevice *device);
475 void SetDefaultWFXChannelOrder(ALCdevice *device);
477 void al_print(const char *fname, unsigned int line, const char *fmt, ...)
478 PRINTF_STYLE(3,4);
479 #define AL_PRINT(...) al_print(__FILE__, __LINE__, __VA_ARGS__)
481 #ifdef __cplusplus
483 #endif
485 #endif