Mercurial > audio-send
view OpenAL32/Include/alMain.h @ 22:616215c81d23
added footnote
author | Robert McIntyre <rlm@mit.edu> |
---|---|
date | Thu, 03 Nov 2011 15:14:44 -0700 |
parents | 96298d83959c |
children |
line wrap: on
line source
1 #ifndef AL_MAIN_H2 #define AL_MAIN_H4 #include <string.h>5 #include <stdio.h>6 #include <stdarg.h>8 #ifdef HAVE_FENV_H9 #include <fenv.h>10 #endif12 #include "AL/al.h"13 #include "AL/alc.h"14 #include "AL/alext.h"16 #ifndef ALC_SOFT_device_loopback17 #define ALC_SOFT_device_loopback 118 #define ALC_FORMAT_CHANNELS_SOFT 0x199019 #define ALC_FORMAT_TYPE_SOFT 0x199121 /* Sample types */22 #define ALC_BYTE 0x140023 #define ALC_UNSIGNED_BYTE 0x140124 #define ALC_SHORT 0x140225 #define ALC_UNSIGNED_SHORT 0x140326 #define ALC_INT 0x140427 #define ALC_UNSIGNED_INT 0x140528 #define ALC_FLOAT 0x140630 /* Channel configurations */31 #define ALC_MONO 0x150032 #define ALC_STEREO 0x150133 #define ALC_QUAD 0x150334 #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_PROTOTYPES42 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 #endif46 #endif48 #ifndef AL_SOFT_buffer_samples49 #define AL_SOFT_buffer_samples 150 /* Sample types */51 #define AL_BYTE 0x140052 #define AL_UNSIGNED_BYTE 0x140153 #define AL_SHORT 0x140254 #define AL_UNSIGNED_SHORT 0x140355 #define AL_INT 0x140456 #define AL_UNSIGNED_INT 0x140557 #define AL_FLOAT 0x140658 #define AL_DOUBLE 0x140759 #define AL_BYTE3 0x140860 #define AL_UNSIGNED_BYTE3 0x140961 #define AL_MULAW 0x141062 #define AL_IMA4 0x141164 /* Channel configurations */65 #define AL_MONO 0x150066 #define AL_STEREO 0x150167 #define AL_REAR 0x150268 #define AL_QUAD 0x150369 #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 0x110075 #define AL_MONO16 0x110176 #define AL_MONO32F 0x1001077 #define AL_STEREO8 0x110278 #define AL_STEREO16 0x110379 #define AL_STEREO32F 0x1001180 #define AL_QUAD8 0x120481 #define AL_QUAD16 0x120582 #define AL_QUAD32F 0x120683 #define AL_REAR8 0x120784 #define AL_REAR16 0x120885 #define AL_REAR32F 0x120986 #define AL_5POINT1_8 0x120A87 #define AL_5POINT1_16 0x120B88 #define AL_5POINT1_32F 0x120C89 #define AL_6POINT1_8 0x120D90 #define AL_6POINT1_16 0x120E91 #define AL_6POINT1_32F 0x120F92 #define AL_7POINT1_8 0x121093 #define AL_7POINT1_16 0x121194 #define AL_7POINT1_32F 0x121296 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_PROTOTYPES101 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 #endif112 #endif114 #ifndef AL_SOFT_non_virtual_channels115 #define AL_SOFT_non_virtual_channels 1116 #define AL_VIRTUAL_CHANNELS_SOFT 0x1033117 #endif119 #ifndef AL_SOFT_deferred_updates120 #define AL_SOFT_deferred_updates 1121 #define AL_DEFERRED_UPDATES_SOFT 0xC002122 typedef ALvoid (AL_APIENTRY*LPALDEFERUPDATESSOFT)(void);123 typedef ALvoid (AL_APIENTRY*LPALPROCESSUPDATESSOFT)(void);124 #ifdef AL_ALEXT_PROTOTYPES125 AL_API ALvoid AL_APIENTRY alDeferUpdatesSOFT(void);126 AL_API ALvoid AL_APIENTRY alProcessUpdatesSOFT(void);127 #endif128 #endif131 #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 #endif146 typedef ptrdiff_t ALintptrEXT;147 typedef ptrdiff_t ALsizeiptrEXT;149 #ifdef HAVE_GCC_FORMAT150 #define PRINTF_STYLE(x, y) __attribute__((format(printf, (x), (y))))151 #else152 #define PRINTF_STYLE(x, y)153 #endif155 #if defined(HAVE_RESTRICT)156 #define RESTRICT restrict157 #elif defined(HAVE___RESTRICT)158 #define RESTRICT __restrict159 #else160 #define RESTRICT161 #endif163 #ifdef _WIN32165 #ifndef _WIN32_WINNT166 #define _WIN32_WINNT 0x0500167 #endif168 #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 1177 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 0183 void pthread_once(pthread_once_t *once, void (*callback)(void));185 #else187 #include <unistd.h>188 #include <assert.h>189 #include <pthread.h>190 #ifdef HAVE_PTHREAD_NP_H191 #include <pthread_np.h>192 #endif193 #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 1225 void *LoadLib(const char *name);226 void CloseLib(void *handle);227 void *GetSymbol(void *handle, const char *name);228 #endif230 #endif232 #include "alListener.h"233 #include "alu.h"235 #ifdef __cplusplus236 extern "C" {237 #endif240 #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_PROBE270 };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 insertion303 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_FLOAT330 };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_5POINT1341 };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_struct361 {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 created379 ALuint MaxNoOfSources;380 // Maximum number of slots that can be created381 ALuint AuxiliaryEffectSlotMax;383 ALCuint NumMonoSources;384 ALCuint NumStereoSources;385 ALuint NumAuxSends;387 // Map of Buffers for this device388 UIntMap BufferMap;390 // Map of Effects for this device391 UIntMap EffectMap;393 // Map of Filters for this device394 UIntMap FilterMap;396 // Stereo-to-binaural filter397 struct bs2b *Bs2b;398 ALCint Bs2bLevel;400 // Device flags401 ALuint Flags;403 // Dry path buffer mix404 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 device416 ALCcontext **Contexts;417 ALuint NumContexts;419 BackendFuncs *Funcs;420 void *ExtraData; // For the backend's use422 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 channels437 #define DEVICE_DUPLICATE_STEREO (1<<0)438 // Use HRTF filters for mixing sounds439 #define DEVICE_USE_HRTF (1<<1)440 // Frequency was requested by the app or config file441 #define DEVICE_FREQUENCY_REQUEST (1<<2)442 // Channel configuration was requested by the config file443 #define DEVICE_CHANNELS_REQUEST (1<<3)445 // Specifies if the device is currently running446 #define DEVICE_RUNNING (1<<31)448 struct ALCcontext_struct449 {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 LogTrace535 };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 __cplusplus560 }561 #endif563 #endif