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>
134 #include <android/log.h>
137 #define IsBadWritePtr(a,b) ((a) == NULL && (b) != 0)
139 typedef pthread_key_t tls_type
;
140 #define tls_create(x) pthread_key_create((x), NULL)
141 #define tls_delete(x) pthread_key_delete((x))
142 #define tls_get(x) pthread_getspecific((x))
143 #define tls_set(x, a) pthread_setspecific((x), (a))
145 typedef pthread_mutex_t CRITICAL_SECTION
;
146 static __inline
void EnterCriticalSection(CRITICAL_SECTION
*cs
)
149 ret
= pthread_mutex_lock(cs
);
152 static __inline
void LeaveCriticalSection(CRITICAL_SECTION
*cs
)
155 ret
= pthread_mutex_unlock(cs
);
158 static __inline
void InitializeCriticalSection(CRITICAL_SECTION
*cs
)
160 pthread_mutexattr_t attrib
;
163 ret
= pthread_mutexattr_init(&attrib
);
166 ret
= pthread_mutexattr_settype(&attrib
, PTHREAD_MUTEX_RECURSIVE
);
167 #ifdef HAVE_PTHREAD_NP_H
169 ret
= pthread_mutexattr_setkind_np(&attrib
, PTHREAD_MUTEX_RECURSIVE
);
172 ret
= pthread_mutex_init(cs
, &attrib
);
175 pthread_mutexattr_destroy(&attrib
);
178 static __inline
void DeleteCriticalSection(CRITICAL_SECTION
*cs
)
181 ret
= pthread_mutex_destroy(cs
);
185 /* NOTE: This wrapper isn't quite accurate as it returns an ALuint, as opposed
186 * to the expected DWORD. Both are defined as unsigned 32-bit types, however.
187 * Additionally, Win32 is supposed to measure the time since Windows started,
188 * as opposed to the actual time. */
189 static __inline ALuint
timeGetTime(void)
192 #if _POSIX_TIMERS > 0
195 ret
= clock_gettime(CLOCK_REALTIME
, &ts
);
198 return ts
.tv_nsec
/1000000 + ts
.tv_sec
*1000;
202 ret
= gettimeofday(&tv
, NULL
);
205 return tv
.tv_usec
/1000 + tv
.tv_sec
*1000;
209 static __inline
void Sleep(ALuint t
)
211 struct timespec tv
, rem
;
212 tv
.tv_nsec
= (t
*1000000)%1000000000;
215 while(nanosleep(&tv
, &rem
) == -1 && errno
== EINTR
)
218 #define min(x,y) (((x)<(y))?(x):(y))
219 #define max(x,y) (((x)>(y))?(x):(y))
222 #include "alListener.h"
230 #define SWMIXER_OUTPUT_RATE 44100
232 #define SPEEDOFSOUNDMETRESPERSEC (343.3f)
233 #define AIRABSORBGAINDBHF (-0.05f)
235 #define LOWPASSFREQCUTOFF (5000)
237 #define DEFAULT_HEAD_DAMPEN (0.25f)
240 // Find the next power-of-2 for non-power-of-2 numbers.
241 static __inline ALuint
NextPowerOf2(ALuint value
)
259 ALCboolean (*OpenPlayback
)(ALCdevice
*, const ALCchar
*);
260 void (*ClosePlayback
)(ALCdevice
*);
261 ALCboolean (*ResetPlayback
)(ALCdevice
*);
262 void (*StopPlayback
)(ALCdevice
*);
264 ALCboolean (*OpenCapture
)(ALCdevice
*, const ALCchar
*);
265 void (*CloseCapture
)(ALCdevice
*);
266 void (*StartCapture
)(ALCdevice
*);
267 void (*StopCapture
)(ALCdevice
*);
268 void (*CaptureSamples
)(ALCdevice
*, void*, ALCuint
);
269 ALCuint (*AvailableSamples
)(ALCdevice
*);
278 void alc_alsa_init(BackendFuncs
*func_list
);
279 void alc_alsa_deinit(void);
280 void alc_alsa_probe(int type
);
281 void alc_oss_init(BackendFuncs
*func_list
);
282 void alc_oss_deinit(void);
283 void alc_oss_probe(int type
);
284 void alc_solaris_init(BackendFuncs
*func_list
);
285 void alc_solaris_deinit(void);
286 void alc_solaris_probe(int type
);
287 void alcDSoundInit(BackendFuncs
*func_list
);
288 void alcDSoundDeinit(void);
289 void alcDSoundProbe(int type
);
290 void alcWinMMInit(BackendFuncs
*FuncList
);
291 void alcWinMMDeinit(void);
292 void alcWinMMProbe(int type
);
293 void alc_pa_init(BackendFuncs
*func_list
);
294 void alc_pa_deinit(void);
295 void alc_pa_probe(int type
);
296 void alc_wave_init(BackendFuncs
*func_list
);
297 void alc_wave_deinit(void);
298 void alc_wave_probe(int type
);
299 void alc_pulse_init(BackendFuncs
*func_list
);
300 void alc_pulse_deinit(void);
301 void alc_pulse_probe(int type
);
302 void alc_android_init(BackendFuncs
*func_list
);
303 void alc_android_deinit(void);
304 void alc_android_probe(int type
);
305 void alc_null_init(BackendFuncs
*func_list
);
306 void alc_null_deinit(void);
307 void alc_null_probe(int type
);
310 typedef struct UIntMap
{
319 void InitUIntMap(UIntMap
*map
);
320 void ResetUIntMap(UIntMap
*map
);
321 ALenum
InsertUIntMapEntry(UIntMap
*map
, ALuint key
, ALvoid
*value
);
322 void RemoveUIntMapKey(UIntMap
*map
, ALuint key
);
324 static __inline ALvoid
*LookupUIntMapKey(UIntMap
*map
, ALuint key
)
329 ALsizei high
= map
->size
- 1;
332 ALsizei mid
= low
+ (high
-low
)/2;
333 if(map
->array
[mid
].key
< key
)
338 if(map
->array
[low
].key
== key
)
339 return map
->array
[low
].value
;
345 struct ALCdevice_struct
347 ALCboolean Connected
;
348 ALboolean IsCaptureDevice
;
355 ALCchar
*szDeviceName
;
359 // Maximum number of sources that can be created
360 ALuint MaxNoOfSources
;
361 // Maximum number of slots that can be created
362 ALuint AuxiliaryEffectSlotMax
;
364 ALCuint NumMonoSources
;
365 ALCuint NumStereoSources
;
368 // Map of Buffers for this device
371 // Map of Effects for this device
374 // Map of Filters for this device
377 // Map of Databuffers for this device
378 UIntMap DatabufferMap
;
380 // Stereo-to-binaural filter
384 // Simulated dampening from head occlusion
387 // Duplicate stereo sources on the side/rear channels
388 ALboolean DuplicateStereo
;
390 // Dry path buffer mix
391 float DryBuffer
[BUFFERSIZE
][OUTPUTCHANNELS
];
393 ALuint DevChannels
[OUTPUTCHANNELS
];
395 ALfloat ChannelMatrix
[OUTPUTCHANNELS
][OUTPUTCHANNELS
];
397 Channel Speaker2Chan
[OUTPUTCHANNELS
];
398 ALfloat PanningLUT
[OUTPUTCHANNELS
* LUT_NUM
];
401 // Contexts created on this device
402 ALCcontext
**Contexts
;
406 void *ExtraData
; // For the backend's use
411 #define ALCdevice_OpenPlayback(a,b) ((a)->Funcs->OpenPlayback((a), (b)))
412 #define ALCdevice_ClosePlayback(a) ((a)->Funcs->ClosePlayback((a)))
413 #define ALCdevice_ResetPlayback(a) ((a)->Funcs->ResetPlayback((a)))
414 #define ALCdevice_StopPlayback(a) ((a)->Funcs->StopPlayback((a)))
415 #define ALCdevice_OpenCapture(a,b) ((a)->Funcs->OpenCapture((a), (b)))
416 #define ALCdevice_CloseCapture(a) ((a)->Funcs->CloseCapture((a)))
417 #define ALCdevice_StartCapture(a) ((a)->Funcs->StartCapture((a)))
418 #define ALCdevice_StopCapture(a) ((a)->Funcs->StopCapture((a)))
419 #define ALCdevice_CaptureSamples(a,b,c) ((a)->Funcs->CaptureSamples((a), (b), (c)))
420 #define ALCdevice_AvailableSamples(a) ((a)->Funcs->AvailableSamples((a)))
422 struct ALCcontext_struct
427 UIntMap EffectSlotMap
;
429 struct ALdatabuffer
*SampleSource
;
430 struct ALdatabuffer
*SampleSink
;
436 ALenum DistanceModel
;
437 ALboolean SourceDistanceModel
;
439 ALfloat DopplerFactor
;
440 ALfloat DopplerVelocity
;
441 ALfloat flSpeedOfSound
;
443 struct ALsource
**ActiveSources
;
444 ALsizei ActiveSourceCount
;
445 ALsizei MaxActiveSources
;
448 const ALCchar
*ExtensionList
;
453 ALCvoid
ReleaseALC(ALCvoid
);
455 void AppendDeviceList(const ALCchar
*name
);
456 void AppendAllDeviceList(const ALCchar
*name
);
457 void AppendCaptureDeviceList(const ALCchar
*name
);
459 ALCvoid
alcSetError(ALCdevice
*device
, ALenum errorCode
);
461 ALCvoid
SuspendContext(ALCcontext
*context
);
462 ALCvoid
ProcessContext(ALCcontext
*context
);
464 ALvoid
*StartThread(ALuint (*func
)(ALvoid
*), ALvoid
*ptr
);
465 ALuint
StopThread(ALvoid
*thread
);
467 ALCcontext
*GetContextSuspended(void);
469 typedef struct RingBuffer RingBuffer
;
470 RingBuffer
*CreateRingBuffer(ALsizei frame_size
, ALsizei length
);
471 void DestroyRingBuffer(RingBuffer
*ring
);
472 ALsizei
RingBufferSize(RingBuffer
*ring
);
473 void WriteRingBuffer(RingBuffer
*ring
, const ALubyte
*data
, ALsizei len
);
474 void ReadRingBuffer(RingBuffer
*ring
, ALubyte
*data
, ALsizei len
);
476 void ReadALConfig(void);
477 void FreeALConfig(void);
478 int ConfigValueExists(const char *blockName
, const char *keyName
);
479 const char *GetConfigValue(const char *blockName
, const char *keyName
, const char *def
);
480 int GetConfigValueInt(const char *blockName
, const char *keyName
, int def
);
481 float GetConfigValueFloat(const char *blockName
, const char *keyName
, float def
);
482 int GetConfigValueBool(const char *blockName
, const char *keyName
, int def
);
484 void SetRTPriority(void);
486 void SetDefaultChannelOrder(ALCdevice
*device
);
487 void SetDefaultWFXChannelOrder(ALCdevice
*device
);
489 void al_print(const char *fname
, unsigned int line
, const char *fmt
, ...)
491 #define AL_PRINT(...) al_print(__FILE__, __LINE__, __VA_ARGS__)