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
);
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
);
82 #ifndef AL_EXT_loop_points
83 #define AL_EXT_loop_points 1
84 #define AL_LOOP_POINTS 0x2015
87 #if defined(HAVE_STDINT_H)
89 typedef int64_t ALint64
;
90 typedef uint64_t ALuint64
;
91 #elif defined(HAVE___INT64)
92 typedef __int64 ALint64
;
93 typedef unsigned __int64 ALuint64
;
94 #elif (SIZEOF_LONG == 8)
96 typedef unsigned long ALuint64
;
97 #elif (SIZEOF_LONG_LONG == 8)
98 typedef long long ALint64
;
99 typedef unsigned long long ALuint64
;
102 #ifdef HAVE_GCC_FORMAT
103 #define PRINTF_STYLE(x, y) __attribute__((format(printf, (x), (y))))
105 #define PRINTF_STYLE(x, y)
111 #define _WIN32_WINNT 0x0500
115 typedef DWORD tls_type
;
116 #define tls_create(x) (*(x) = TlsAlloc())
117 #define tls_delete(x) TlsFree((x))
118 #define tls_get(x) TlsGetValue((x))
119 #define tls_set(x, a) TlsSetValue((x), (a))
126 #ifdef HAVE_PTHREAD_NP_H
127 #include <pthread_np.h>
129 #include <sys/time.h>
133 #define IsBadWritePtr(a,b) ((a) == NULL && (b) != 0)
135 typedef pthread_key_t tls_type
;
136 #define tls_create(x) pthread_key_create((x), NULL)
137 #define tls_delete(x) pthread_key_delete((x))
138 #define tls_get(x) pthread_getspecific((x))
139 #define tls_set(x, a) pthread_setspecific((x), (a))
141 typedef pthread_mutex_t CRITICAL_SECTION
;
142 static inline void EnterCriticalSection(CRITICAL_SECTION
*cs
)
145 ret
= pthread_mutex_lock(cs
);
148 static inline void LeaveCriticalSection(CRITICAL_SECTION
*cs
)
151 ret
= pthread_mutex_unlock(cs
);
154 static inline void InitializeCriticalSection(CRITICAL_SECTION
*cs
)
156 pthread_mutexattr_t attrib
;
159 ret
= pthread_mutexattr_init(&attrib
);
162 ret
= pthread_mutexattr_settype(&attrib
, PTHREAD_MUTEX_RECURSIVE
);
163 #ifdef HAVE_PTHREAD_NP_H
165 ret
= pthread_mutexattr_setkind_np(&attrib
, PTHREAD_MUTEX_RECURSIVE
);
168 ret
= pthread_mutex_init(cs
, &attrib
);
171 pthread_mutexattr_destroy(&attrib
);
174 static inline void DeleteCriticalSection(CRITICAL_SECTION
*cs
)
177 ret
= pthread_mutex_destroy(cs
);
181 /* NOTE: This wrapper isn't quite accurate as it returns an ALuint, as opposed
182 * to the expected DWORD. Both are defined as unsigned 32-bit types, however.
183 * Additionally, Win32 is supposed to measure the time since Windows started,
184 * as opposed to the actual time. */
185 static inline ALuint
timeGetTime(void)
188 #if _POSIX_TIMERS > 0
191 ret
= clock_gettime(CLOCK_REALTIME
, &ts
);
194 return ts
.tv_nsec
/1000000 + ts
.tv_sec
*1000;
198 ret
= gettimeofday(&tv
, NULL
);
201 return tv
.tv_usec
/1000 + tv
.tv_sec
*1000;
205 static inline void Sleep(ALuint t
)
207 struct timespec tv
, rem
;
208 tv
.tv_nsec
= (t
*1000000)%1000000000;
211 while(nanosleep(&tv
, &rem
) == -1 && errno
== EINTR
)
214 #define min(x,y) (((x)<(y))?(x):(y))
215 #define max(x,y) (((x)>(y))?(x):(y))
218 #include "alListener.h"
226 #define SWMIXER_OUTPUT_RATE 44100
228 #define SPEEDOFSOUNDMETRESPERSEC (343.3f)
229 #define AIRABSORBGAINDBHF (-0.05f)
231 #define LOWPASSFREQCUTOFF (5000)
233 #define DEFAULT_HEAD_DAMPEN (0.25f)
236 // Find the next power-of-2 for non-power-of-2 numbers.
237 static __inline ALuint
NextPowerOf2(ALuint value
)
255 ALCboolean (*OpenPlayback
)(ALCdevice
*, const ALCchar
*);
256 void (*ClosePlayback
)(ALCdevice
*);
257 ALCboolean (*ResetPlayback
)(ALCdevice
*);
258 void (*StopPlayback
)(ALCdevice
*);
260 ALCboolean (*OpenCapture
)(ALCdevice
*, const ALCchar
*);
261 void (*CloseCapture
)(ALCdevice
*);
262 void (*StartCapture
)(ALCdevice
*);
263 void (*StopCapture
)(ALCdevice
*);
264 void (*CaptureSamples
)(ALCdevice
*, void*, ALCuint
);
265 ALCuint (*AvailableSamples
)(ALCdevice
*);
274 void alc_alsa_init(BackendFuncs
*func_list
);
275 void alc_alsa_deinit(void);
276 void alc_alsa_probe(int type
);
277 void alc_oss_init(BackendFuncs
*func_list
);
278 void alc_oss_deinit(void);
279 void alc_oss_probe(int type
);
280 void alc_solaris_init(BackendFuncs
*func_list
);
281 void alc_solaris_deinit(void);
282 void alc_solaris_probe(int type
);
283 void alcDSoundInit(BackendFuncs
*func_list
);
284 void alcDSoundDeinit(void);
285 void alcDSoundProbe(int type
);
286 void alcWinMMInit(BackendFuncs
*FuncList
);
287 void alcWinMMDeinit(void);
288 void alcWinMMProbe(int type
);
289 void alc_pa_init(BackendFuncs
*func_list
);
290 void alc_pa_deinit(void);
291 void alc_pa_probe(int type
);
292 void alc_wave_init(BackendFuncs
*func_list
);
293 void alc_wave_deinit(void);
294 void alc_wave_probe(int type
);
295 void alc_pulse_init(BackendFuncs
*func_list
);
296 void alc_pulse_deinit(void);
297 void alc_pulse_probe(int type
);
300 typedef struct UIntMap
{
309 void InitUIntMap(UIntMap
*map
);
310 void ResetUIntMap(UIntMap
*map
);
311 ALenum
InsertUIntMapEntry(UIntMap
*map
, ALuint key
, ALvoid
*value
);
312 void RemoveUIntMapKey(UIntMap
*map
, ALuint key
);
314 static inline ALvoid
*LookupUIntMapKey(UIntMap
*map
, ALuint key
)
319 ALsizei high
= map
->size
- 1;
322 ALsizei mid
= low
+ (high
-low
)/2;
323 if(map
->array
[mid
].key
< key
)
328 if(map
->array
[low
].key
== key
)
329 return map
->array
[low
].value
;
335 struct ALCdevice_struct
337 ALCboolean Connected
;
338 ALboolean IsCaptureDevice
;
345 ALCchar
*szDeviceName
;
349 // Maximum number of sources that can be created
350 ALuint MaxNoOfSources
;
351 // Maximum number of slots that can be created
352 ALuint AuxiliaryEffectSlotMax
;
354 ALCuint NumMonoSources
;
355 ALCuint NumStereoSources
;
358 // Map of Buffers for this device
361 // Linked List of Effects for this device
362 struct ALeffect
*EffectList
;
365 // Linked List of Filters for this device
366 struct ALfilter
*FilterList
;
369 // Linked List of Databuffers for this device
370 struct ALdatabuffer
*DatabufferList
;
371 ALuint DatabufferCount
;
373 // Stereo-to-binaural filter
377 // Simulated dampening from head occlusion
380 // Duplicate stereo sources on the side/rear channels
381 ALboolean DuplicateStereo
;
383 // Dry path buffer mix
384 float DryBuffer
[BUFFERSIZE
][OUTPUTCHANNELS
];
386 ALuint DevChannels
[OUTPUTCHANNELS
];
388 ALfloat ChannelMatrix
[OUTPUTCHANNELS
][OUTPUTCHANNELS
];
390 Channel Speaker2Chan
[OUTPUTCHANNELS
];
391 ALfloat PanningLUT
[OUTPUTCHANNELS
* LUT_NUM
];
394 // Contexts created on this device
395 ALCcontext
**Contexts
;
399 void *ExtraData
; // For the backend's use
404 #define ALCdevice_OpenPlayback(a,b) ((a)->Funcs->OpenPlayback((a), (b)))
405 #define ALCdevice_ClosePlayback(a) ((a)->Funcs->ClosePlayback((a)))
406 #define ALCdevice_ResetPlayback(a) ((a)->Funcs->ResetPlayback((a)))
407 #define ALCdevice_StopPlayback(a) ((a)->Funcs->StopPlayback((a)))
408 #define ALCdevice_OpenCapture(a,b) ((a)->Funcs->OpenCapture((a), (b)))
409 #define ALCdevice_CloseCapture(a) ((a)->Funcs->CloseCapture((a)))
410 #define ALCdevice_StartCapture(a) ((a)->Funcs->StartCapture((a)))
411 #define ALCdevice_StopCapture(a) ((a)->Funcs->StopCapture((a)))
412 #define ALCdevice_CaptureSamples(a,b,c) ((a)->Funcs->CaptureSamples((a), (b), (c)))
413 #define ALCdevice_AvailableSamples(a) ((a)->Funcs->AvailableSamples((a)))
415 struct ALCcontext_struct
420 UIntMap EffectSlotMap
;
422 struct ALdatabuffer
*SampleSource
;
423 struct ALdatabuffer
*SampleSink
;
429 ALenum DistanceModel
;
430 ALboolean SourceDistanceModel
;
432 ALfloat DopplerFactor
;
433 ALfloat DopplerVelocity
;
434 ALfloat flSpeedOfSound
;
437 const ALCchar
*ExtensionList
;
442 ALCvoid
ReleaseALC(ALCvoid
);
444 void AppendDeviceList(const ALCchar
*name
);
445 void AppendAllDeviceList(const ALCchar
*name
);
446 void AppendCaptureDeviceList(const ALCchar
*name
);
448 ALCvoid
alcSetError(ALCdevice
*device
, ALenum errorCode
);
450 ALCvoid
SuspendContext(ALCcontext
*context
);
451 ALCvoid
ProcessContext(ALCcontext
*context
);
453 ALvoid
*StartThread(ALuint (*func
)(ALvoid
*), ALvoid
*ptr
);
454 ALuint
StopThread(ALvoid
*thread
);
456 ALCcontext
*GetContextSuspended(void);
458 typedef struct RingBuffer RingBuffer
;
459 RingBuffer
*CreateRingBuffer(ALsizei frame_size
, ALsizei length
);
460 void DestroyRingBuffer(RingBuffer
*ring
);
461 ALsizei
RingBufferSize(RingBuffer
*ring
);
462 void WriteRingBuffer(RingBuffer
*ring
, const ALubyte
*data
, ALsizei len
);
463 void ReadRingBuffer(RingBuffer
*ring
, ALubyte
*data
, ALsizei len
);
465 void ReadALConfig(void);
466 void FreeALConfig(void);
467 int ConfigValueExists(const char *blockName
, const char *keyName
);
468 const char *GetConfigValue(const char *blockName
, const char *keyName
, const char *def
);
469 int GetConfigValueInt(const char *blockName
, const char *keyName
, int def
);
470 float GetConfigValueFloat(const char *blockName
, const char *keyName
, float def
);
471 int GetConfigValueBool(const char *blockName
, const char *keyName
, int def
);
473 void SetRTPriority(void);
475 void SetDefaultChannelOrder(ALCdevice
*device
);
476 void SetDefaultWFXChannelOrder(ALCdevice
*device
);
478 void al_print(const char *fname
, unsigned int line
, const char *fmt
, ...)
480 #define AL_PRINT(...) al_print(__FILE__, __LINE__, __VA_ARGS__)
482 #define DECL_VERIFIER(name, type, field) \
483 static type* Verify##name(type *list, ALuint id) \
485 while(list && list->field != id) \