view OpenAL32/Include/alMain.h @ 32:b8bc24918d63

moved ear.org into cortex
author Robert McIntyre <rlm@mit.edu>
date Sat, 04 Feb 2012 01:43:33 -0700
parents 96298d83959c
children
line wrap: on
line source
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 ALC_SOFT_device_loopback
17 #define ALC_SOFT_device_loopback 1
18 #define ALC_FORMAT_CHANNELS_SOFT 0x1990
19 #define ALC_FORMAT_TYPE_SOFT 0x1991
21 /* Sample types */
22 #define ALC_BYTE 0x1400
23 #define ALC_UNSIGNED_BYTE 0x1401
24 #define ALC_SHORT 0x1402
25 #define ALC_UNSIGNED_SHORT 0x1403
26 #define ALC_INT 0x1404
27 #define ALC_UNSIGNED_INT 0x1405
28 #define ALC_FLOAT 0x1406
30 /* Channel configurations */
31 #define ALC_MONO 0x1500
32 #define ALC_STEREO 0x1501
33 #define ALC_QUAD 0x1503
34 #define ALC_5POINT1 0x1504 /* (WFX order) */
35 #define ALC_6POINT1 0x1505 /* (WFX order) */
36 #define ALC_7POINT1 0x1506 /* (WFX order) */
38 typedef ALCdevice* (ALC_APIENTRY*LPALCLOOPBACKOPENDEVICESOFT)(void);
39 typedef ALCboolean (ALC_APIENTRY*LPALCISRENDERFORMATSUPPORTEDSOFT)(ALCdevice *device, ALCsizei freq, ALCenum channels, ALCenum type);
40 typedef void (ALC_APIENTRY*LPALCRENDERSAMPLESSOFT)(ALCdevice *device, ALCvoid *buffer, ALCsizei samples);
41 #ifdef AL_ALEXT_PROTOTYPES
42 ALC_API ALCdevice* ALC_APIENTRY alcLoopbackOpenDeviceSOFT(void);
43 ALC_API ALCboolean ALC_APIENTRY alcIsRenderFormatSupportedSOFT(ALCdevice *device, ALCsizei freq, ALCenum channels, ALCenum type);
44 ALC_API void ALC_APIENTRY alcRenderSamplesSOFT(ALCdevice *device, ALCvoid *buffer, ALCsizei samples);
45 #endif
46 #endif
48 #ifndef AL_SOFT_buffer_samples
49 #define AL_SOFT_buffer_samples 1
50 /* Sample types */
51 #define AL_BYTE 0x1400
52 #define AL_UNSIGNED_BYTE 0x1401
53 #define AL_SHORT 0x1402
54 #define AL_UNSIGNED_SHORT 0x1403
55 #define AL_INT 0x1404
56 #define AL_UNSIGNED_INT 0x1405
57 #define AL_FLOAT 0x1406
58 #define AL_DOUBLE 0x1407
59 #define AL_BYTE3 0x1408
60 #define AL_UNSIGNED_BYTE3 0x1409
61 #define AL_MULAW 0x1410
62 #define AL_IMA4 0x1411
64 /* Channel configurations */
65 #define AL_MONO 0x1500
66 #define AL_STEREO 0x1501
67 #define AL_REAR 0x1502
68 #define AL_QUAD 0x1503
69 #define AL_5POINT1 0x1504 /* (WFX order) */
70 #define AL_6POINT1 0x1505 /* (WFX order) */
71 #define AL_7POINT1 0x1506 /* (WFX order) */
73 /* Storage formats */
74 #define AL_MONO8 0x1100
75 #define AL_MONO16 0x1101
76 #define AL_MONO32F 0x10010
77 #define AL_STEREO8 0x1102
78 #define AL_STEREO16 0x1103
79 #define AL_STEREO32F 0x10011
80 #define AL_QUAD8 0x1204
81 #define AL_QUAD16 0x1205
82 #define AL_QUAD32F 0x1206
83 #define AL_REAR8 0x1207
84 #define AL_REAR16 0x1208
85 #define AL_REAR32F 0x1209
86 #define AL_5POINT1_8 0x120A
87 #define AL_5POINT1_16 0x120B
88 #define AL_5POINT1_32F 0x120C
89 #define AL_6POINT1_8 0x120D
90 #define AL_6POINT1_16 0x120E
91 #define AL_6POINT1_32F 0x120F
92 #define AL_7POINT1_8 0x1210
93 #define AL_7POINT1_16 0x1211
94 #define AL_7POINT1_32F 0x1212
96 typedef void (AL_APIENTRY*LPALBUFFERSAMPLESSOFT)(ALuint,ALuint,ALenum,ALsizei,ALenum,ALenum,const ALvoid*);
97 typedef void (AL_APIENTRY*LPALBUFFERSUBSAMPLESSOFT)(ALuint,ALsizei,ALsizei,ALenum,ALenum,const ALvoid*);
98 typedef void (AL_APIENTRY*LPALGETBUFFERSAMPLESSOFT)(ALuint,ALsizei,ALsizei,ALenum,ALenum,ALvoid*);
99 typedef ALboolean (AL_APIENTRY*LPALISBUFFERFORMATSUPPORTEDSOFT)(ALenum);
100 #ifdef AL_ALEXT_PROTOTYPES
101 AL_API void AL_APIENTRY alBufferSamplesSOFT(ALuint buffer,
102 ALuint samplerate, ALenum internalformat, ALsizei frames,
103 ALenum channels, ALenum type, const ALvoid *data);
104 AL_API void AL_APIENTRY alBufferSubSamplesSOFT(ALuint buffer,
105 ALsizei offset, ALsizei frames,
106 ALenum channels, ALenum type, const ALvoid *data);
107 AL_API void AL_APIENTRY alGetBufferSamplesSOFT(ALuint buffer,
108 ALsizei offset, ALsizei frames,
109 ALenum channels, ALenum type, ALvoid *data);
110 AL_API ALboolean AL_APIENTRY alIsBufferFormatSupportedSOFT(ALenum format);
111 #endif
112 #endif
114 #ifndef AL_SOFT_non_virtual_channels
115 #define AL_SOFT_non_virtual_channels 1
116 #define AL_VIRTUAL_CHANNELS_SOFT 0x1033
117 #endif
119 #ifndef AL_SOFT_deferred_updates
120 #define AL_SOFT_deferred_updates 1
121 #define AL_DEFERRED_UPDATES_SOFT 0xC002
122 typedef ALvoid (AL_APIENTRY*LPALDEFERUPDATESSOFT)(void);
123 typedef ALvoid (AL_APIENTRY*LPALPROCESSUPDATESSOFT)(void);
124 #ifdef AL_ALEXT_PROTOTYPES
125 AL_API ALvoid AL_APIENTRY alDeferUpdatesSOFT(void);
126 AL_API ALvoid AL_APIENTRY alProcessUpdatesSOFT(void);
127 #endif
128 #endif
131 #if defined(HAVE_STDINT_H)
132 #include <stdint.h>
133 typedef int64_t ALint64;
134 typedef uint64_t ALuint64;
135 #elif defined(HAVE___INT64)
136 typedef __int64 ALint64;
137 typedef unsigned __int64 ALuint64;
138 #elif (SIZEOF_LONG == 8)
139 typedef long ALint64;
140 typedef unsigned long ALuint64;
141 #elif (SIZEOF_LONG_LONG == 8)
142 typedef long long ALint64;
143 typedef unsigned long long ALuint64;
144 #endif
146 typedef ptrdiff_t ALintptrEXT;
147 typedef ptrdiff_t ALsizeiptrEXT;
149 #ifdef HAVE_GCC_FORMAT
150 #define PRINTF_STYLE(x, y) __attribute__((format(printf, (x), (y))))
151 #else
152 #define PRINTF_STYLE(x, y)
153 #endif
155 #if defined(HAVE_RESTRICT)
156 #define RESTRICT restrict
157 #elif defined(HAVE___RESTRICT)
158 #define RESTRICT __restrict
159 #else
160 #define RESTRICT
161 #endif
163 #ifdef _WIN32
165 #ifndef _WIN32_WINNT
166 #define _WIN32_WINNT 0x0500
167 #endif
168 #include <windows.h>
170 typedef DWORD tls_type;
171 #define tls_create(x) (*(x) = TlsAlloc())
172 #define tls_delete(x) TlsFree((x))
173 #define tls_get(x) TlsGetValue((x))
174 #define tls_set(x, a) TlsSetValue((x), (a))
176 #define HAVE_DYNLOAD 1
177 void *LoadLib(const char *name);
178 void CloseLib(void *handle);
179 void *GetSymbol(void *handle, const char *name);
181 typedef LONG pthread_once_t;
182 #define PTHREAD_ONCE_INIT 0
183 void pthread_once(pthread_once_t *once, void (*callback)(void));
185 #else
187 #include <unistd.h>
188 #include <assert.h>
189 #include <pthread.h>
190 #ifdef HAVE_PTHREAD_NP_H
191 #include <pthread_np.h>
192 #endif
193 #include <sys/time.h>
194 #include <time.h>
195 #include <errno.h>
197 #define IsBadWritePtr(a,b) ((a) == NULL && (b) != 0)
199 typedef pthread_key_t tls_type;
200 #define tls_create(x) pthread_key_create((x), NULL)
201 #define tls_delete(x) pthread_key_delete((x))
202 #define tls_get(x) pthread_getspecific((x))
203 #define tls_set(x, a) pthread_setspecific((x), (a))
205 typedef pthread_mutex_t CRITICAL_SECTION;
206 void InitializeCriticalSection(CRITICAL_SECTION *cs);
207 void DeleteCriticalSection(CRITICAL_SECTION *cs);
208 void EnterCriticalSection(CRITICAL_SECTION *cs);
209 void LeaveCriticalSection(CRITICAL_SECTION *cs);
211 ALuint timeGetTime(void);
213 static __inline void Sleep(ALuint t)
214 {
215 struct timespec tv, rem;
216 tv.tv_nsec = (t*1000000)%1000000000;
217 tv.tv_sec = t/1000;
219 while(nanosleep(&tv, &rem) == -1 && errno == EINTR)
220 tv = rem;
221 }
223 #if defined(HAVE_DLFCN_H)
224 #define HAVE_DYNLOAD 1
225 void *LoadLib(const char *name);
226 void CloseLib(void *handle);
227 void *GetSymbol(void *handle, const char *name);
228 #endif
230 #endif
232 #include "alListener.h"
233 #include "alu.h"
235 #ifdef __cplusplus
236 extern "C" {
237 #endif
240 #define DEFAULT_OUTPUT_RATE (44100)
242 #define SPEEDOFSOUNDMETRESPERSEC (343.3f)
243 #define AIRABSORBGAINHF (0.99426) /* -0.05dB */
245 #define LOWPASSFREQCUTOFF (5000)
248 // Find the next power-of-2 for non-power-of-2 numbers.
249 static __inline ALuint NextPowerOf2(ALuint value)
250 {
251 ALuint powerOf2 = 1;
253 if(value)
254 {
255 value--;
256 while(value)
257 {
258 value >>= 1;
259 powerOf2 <<= 1;
260 }
261 }
262 return powerOf2;
263 }
266 enum DevProbe {
267 DEVICE_PROBE,
268 ALL_DEVICE_PROBE,
269 CAPTURE_DEVICE_PROBE
270 };
272 typedef struct {
273 ALCboolean (*OpenPlayback)(ALCdevice*, const ALCchar*);
274 void (*ClosePlayback)(ALCdevice*);
275 ALCboolean (*ResetPlayback)(ALCdevice*);
276 void (*StopPlayback)(ALCdevice*);
278 ALCboolean (*OpenCapture)(ALCdevice*, const ALCchar*);
279 void (*CloseCapture)(ALCdevice*);
280 void (*StartCapture)(ALCdevice*);
281 void (*StopCapture)(ALCdevice*);
282 void (*CaptureSamples)(ALCdevice*, void*, ALCuint);
283 ALCuint (*AvailableSamples)(ALCdevice*);
284 } BackendFuncs;
286 struct BackendInfo {
287 const char *name;
288 ALCboolean (*Init)(BackendFuncs*);
289 void (*Deinit)(void);
290 void (*Probe)(enum DevProbe);
291 BackendFuncs Funcs;
292 };
295 ALCboolean alc_null_init(BackendFuncs *func_list);
296 void alc_null_deinit(void);
297 void alc_null_probe(enum DevProbe type);
298 ALCboolean alc_loopback_init(BackendFuncs *func_list);
299 void alc_loopback_deinit(void);
300 void alc_loopback_probe(enum DevProbe type);
302 //RLM: aurellem send device insertion
303 ALCboolean alc_send_init(BackendFuncs *func_list);
304 void alc_send_deinit(void);
305 void alc_send_probe(enum DevProbe type);
308 typedef struct UIntMap {
309 struct {
310 ALuint key;
311 ALvoid *value;
312 } *array;
313 ALsizei size;
314 ALsizei maxsize;
315 } UIntMap;
317 void InitUIntMap(UIntMap *map);
318 void ResetUIntMap(UIntMap *map);
319 ALenum InsertUIntMapEntry(UIntMap *map, ALuint key, ALvoid *value);
320 void RemoveUIntMapKey(UIntMap *map, ALuint key);
321 ALvoid *LookupUIntMapKey(UIntMap *map, ALuint key);
323 /* Device formats */
324 enum DevFmtType {
325 DevFmtByte = AL_BYTE,
326 DevFmtUByte = AL_UNSIGNED_BYTE,
327 DevFmtShort = AL_SHORT,
328 DevFmtUShort = AL_UNSIGNED_SHORT,
329 DevFmtFloat = AL_FLOAT
330 };
331 enum DevFmtChannels {
332 DevFmtMono = AL_MONO,
333 DevFmtStereo = AL_STEREO,
334 DevFmtQuad = AL_QUAD,
335 DevFmtX51 = AL_5POINT1,
336 DevFmtX61 = AL_6POINT1,
337 DevFmtX71 = AL_7POINT1,
339 /* Similar to 5.1, except using the side channels instead of back */
340 DevFmtX51Side = 0x80000000 | AL_5POINT1
341 };
343 ALuint BytesFromDevFmt(enum DevFmtType type);
344 ALuint ChannelsFromDevFmt(enum DevFmtChannels chans);
345 static __inline ALuint FrameSizeFromDevFmt(enum DevFmtChannels chans,
346 enum DevFmtType type)
347 {
348 return ChannelsFromDevFmt(chans) * BytesFromDevFmt(type);
349 }
352 extern const struct EffectList {
353 const char *name;
354 int type;
355 const char *ename;
356 ALenum val;
357 } EffectList[];
360 struct ALCdevice_struct
361 {
362 ALCboolean Connected;
363 ALboolean IsCaptureDevice;
364 ALboolean IsLoopbackDevice;
366 CRITICAL_SECTION Mutex;
368 ALuint Frequency;
369 ALuint UpdateSize;
370 ALuint NumUpdates;
371 enum DevFmtChannels FmtChans;
372 enum DevFmtType FmtType;
374 ALCchar *szDeviceName;
376 ALCenum LastError;
378 // Maximum number of sources that can be created
379 ALuint MaxNoOfSources;
380 // Maximum number of slots that can be created
381 ALuint AuxiliaryEffectSlotMax;
383 ALCuint NumMonoSources;
384 ALCuint NumStereoSources;
385 ALuint NumAuxSends;
387 // Map of Buffers for this device
388 UIntMap BufferMap;
390 // Map of Effects for this device
391 UIntMap EffectMap;
393 // Map of Filters for this device
394 UIntMap FilterMap;
396 // Stereo-to-binaural filter
397 struct bs2b *Bs2b;
398 ALCint Bs2bLevel;
400 // Device flags
401 ALuint Flags;
403 // Dry path buffer mix
404 ALfloat DryBuffer[BUFFERSIZE][MAXCHANNELS];
406 enum Channel DevChannels[MAXCHANNELS];
408 enum Channel Speaker2Chan[MAXCHANNELS];
409 ALfloat PanningLUT[LUT_NUM][MAXCHANNELS];
410 ALuint NumChan;
412 ALfloat ClickRemoval[MAXCHANNELS];
413 ALfloat PendingClicks[MAXCHANNELS];
415 // Contexts created on this device
416 ALCcontext **Contexts;
417 ALuint NumContexts;
419 BackendFuncs *Funcs;
420 void *ExtraData; // For the backend's use
422 ALCdevice *next;
423 };
425 #define ALCdevice_OpenPlayback(a,b) ((a)->Funcs->OpenPlayback((a), (b)))
426 #define ALCdevice_ClosePlayback(a) ((a)->Funcs->ClosePlayback((a)))
427 #define ALCdevice_ResetPlayback(a) ((a)->Funcs->ResetPlayback((a)))
428 #define ALCdevice_StopPlayback(a) ((a)->Funcs->StopPlayback((a)))
429 #define ALCdevice_OpenCapture(a,b) ((a)->Funcs->OpenCapture((a), (b)))
430 #define ALCdevice_CloseCapture(a) ((a)->Funcs->CloseCapture((a)))
431 #define ALCdevice_StartCapture(a) ((a)->Funcs->StartCapture((a)))
432 #define ALCdevice_StopCapture(a) ((a)->Funcs->StopCapture((a)))
433 #define ALCdevice_CaptureSamples(a,b,c) ((a)->Funcs->CaptureSamples((a), (b), (c)))
434 #define ALCdevice_AvailableSamples(a) ((a)->Funcs->AvailableSamples((a)))
436 // Duplicate stereo sources on the side/rear channels
437 #define DEVICE_DUPLICATE_STEREO (1<<0)
438 // Use HRTF filters for mixing sounds
439 #define DEVICE_USE_HRTF (1<<1)
440 // Frequency was requested by the app or config file
441 #define DEVICE_FREQUENCY_REQUEST (1<<2)
442 // Channel configuration was requested by the config file
443 #define DEVICE_CHANNELS_REQUEST (1<<3)
445 // Specifies if the device is currently running
446 #define DEVICE_RUNNING (1<<31)
448 struct ALCcontext_struct
449 {
450 ALlistener Listener;
452 UIntMap SourceMap;
453 UIntMap EffectSlotMap;
455 ALenum LastError;
457 ALboolean UpdateSources;
459 enum DistanceModel DistanceModel;
460 ALboolean SourceDistanceModel;
462 ALfloat DopplerFactor;
463 ALfloat DopplerVelocity;
464 ALfloat flSpeedOfSound;
465 ALboolean DeferUpdates;
467 struct ALsource **ActiveSources;
468 ALsizei ActiveSourceCount;
469 ALsizei MaxActiveSources;
471 ALCdevice *Device;
472 const ALCchar *ExtensionList;
474 ALCcontext *next;
475 };
477 void AppendDeviceList(const ALCchar *name);
478 void AppendAllDeviceList(const ALCchar *name);
479 void AppendCaptureDeviceList(const ALCchar *name);
481 ALCvoid alcSetError(ALCdevice *device, ALenum errorCode);
483 ALCvoid LockDevice(ALCdevice *device);
484 ALCvoid UnlockDevice(ALCdevice *device);
485 ALCvoid LockContext(ALCcontext *context);
486 ALCvoid UnlockContext(ALCcontext *context);
488 ALvoid *StartThread(ALuint (*func)(ALvoid*), ALvoid *ptr);
489 ALuint StopThread(ALvoid *thread);
491 ALCcontext *GetLockedContext(void);
493 typedef struct RingBuffer RingBuffer;
494 RingBuffer *CreateRingBuffer(ALsizei frame_size, ALsizei length);
495 void DestroyRingBuffer(RingBuffer *ring);
496 ALsizei RingBufferSize(RingBuffer *ring);
497 void WriteRingBuffer(RingBuffer *ring, const ALubyte *data, ALsizei len);
498 void ReadRingBuffer(RingBuffer *ring, ALubyte *data, ALsizei len);
500 void ReadALConfig(void);
501 void FreeALConfig(void);
502 int ConfigValueExists(const char *blockName, const char *keyName);
503 const char *GetConfigValue(const char *blockName, const char *keyName, const char *def);
504 int GetConfigValueInt(const char *blockName, const char *keyName, int def);
505 float GetConfigValueFloat(const char *blockName, const char *keyName, float def);
506 int GetConfigValueBool(const char *blockName, const char *keyName, int def);
508 void SetRTPriority(void);
510 void SetDefaultChannelOrder(ALCdevice *device);
511 void SetDefaultWFXChannelOrder(ALCdevice *device);
513 const ALCchar *DevFmtTypeString(enum DevFmtType type);
514 const ALCchar *DevFmtChannelsString(enum DevFmtChannels chans);
516 #define HRIR_BITS (5)
517 #define HRIR_LENGTH (1<<HRIR_BITS)
518 #define HRIR_MASK (HRIR_LENGTH-1)
519 void InitHrtf(void);
520 ALCboolean IsHrtfCompatible(ALCdevice *device);
521 ALfloat CalcHrtfDelta(ALfloat oldGain, ALfloat newGain, const ALfloat olddir[3], const ALfloat newdir[3]);
522 void GetLerpedHrtfCoeffs(ALfloat elevation, ALfloat azimuth, ALfloat gain, ALfloat (*coeffs)[2], ALuint *delays);
523 ALuint GetMovingHrtfCoeffs(ALfloat elevation, ALfloat azimuth, ALfloat gain, ALfloat delta, ALint counter, ALfloat (*coeffs)[2], ALuint *delays, ALfloat (*coeffStep)[2], ALint *delayStep);
525 void al_print(const char *fname, unsigned int line, const char *fmt, ...)
526 PRINTF_STYLE(3,4);
527 #define AL_PRINT(...) al_print(__FILE__, __LINE__, __VA_ARGS__)
529 extern FILE *LogFile;
530 enum LogLevel {
531 NoLog,
532 LogError,
533 LogWarning,
534 LogTrace
535 };
536 extern enum LogLevel LogLevel;
538 #define TRACE(...) do { \
539 if(LogLevel >= LogTrace) \
540 AL_PRINT(__VA_ARGS__); \
541 } while(0)
543 #define WARN(...) do { \
544 if(LogLevel >= LogWarning) \
545 AL_PRINT(__VA_ARGS__); \
546 } while(0)
548 #define ERR(...) do { \
549 if(LogLevel >= LogError) \
550 AL_PRINT(__VA_ARGS__); \
551 } while(0)
554 extern ALdouble ConeScale;
555 extern ALdouble ZScale;
557 extern ALint RTPrioLevel;
559 #ifdef __cplusplus
560 }
561 #endif
563 #endif