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
88 #if defined(HAVE_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)
97 typedef unsigned long ALuint64
;
98 #elif (SIZEOF_LONG_LONG == 8)
99 typedef long long ALint64
;
100 typedef unsigned long long ALuint64
;
103 #ifdef HAVE_GCC_FORMAT
104 #define PRINTF_STYLE(x, y) __attribute__((format(printf, (x), (y))))
106 #define PRINTF_STYLE(x, y)
112 #define _WIN32_WINNT 0x0500
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))
127 #ifdef HAVE_PTHREAD_NP_H
128 #include <pthread_np.h>
130 #include <sys/time.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
)
146 ret
= pthread_mutex_lock(cs
);
149 static __inline
void LeaveCriticalSection(CRITICAL_SECTION
*cs
)
152 ret
= pthread_mutex_unlock(cs
);
155 static __inline
void InitializeCriticalSection(CRITICAL_SECTION
*cs
)
157 pthread_mutexattr_t attrib
;
160 ret
= pthread_mutexattr_init(&attrib
);
163 ret
= pthread_mutexattr_settype(&attrib
, PTHREAD_MUTEX_RECURSIVE
);
164 #ifdef HAVE_PTHREAD_NP_H
166 ret
= pthread_mutexattr_setkind_np(&attrib
, PTHREAD_MUTEX_RECURSIVE
);
169 ret
= pthread_mutex_init(cs
, &attrib
);
172 pthread_mutexattr_destroy(&attrib
);
175 static __inline
void DeleteCriticalSection(CRITICAL_SECTION
*cs
)
178 ret
= pthread_mutex_destroy(cs
);
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;
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))
198 ret
= clock_gettime(CLOCK_MONOTONIC
, &ts
);
201 ret
= clock_gettime(CLOCK_REALTIME
, &ts
);
204 return ts
.tv_nsec
/1000000 + ts
.tv_sec
*1000;
209 ret
= gettimeofday(&tv
, NULL
);
212 return tv
.tv_usec
/1000 + tv
.tv_sec
*1000;
216 static __inline
void Sleep(ALuint t
)
218 struct timespec tv
, rem
;
219 tv
.tv_nsec
= (t
*1000000)%1000000000;
222 while(nanosleep(&tv
, &rem
) == -1 && errno
== EINTR
)
225 #define min(x,y) (((x)<(y))?(x):(y))
226 #define max(x,y) (((x)>(y))?(x):(y))
229 #include "alListener.h"
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
)
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
*);
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
{
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
);
328 static __inline ALvoid
*LookupUIntMapKey(UIntMap
*map
, ALuint key
)
333 ALsizei high
= map
->size
- 1;
336 ALsizei mid
= low
+ (high
-low
)/2;
337 if(map
->array
[mid
].key
< key
)
342 if(map
->array
[low
].key
== key
)
343 return map
->array
[low
].value
;
349 struct ALCdevice_struct
351 ALCboolean Connected
;
352 ALboolean IsCaptureDevice
;
359 ALCchar
*szDeviceName
;
363 // Maximum number of sources that can be created
364 ALuint MaxNoOfSources
;
365 // Maximum number of slots that can be created
366 ALuint AuxiliaryEffectSlotMax
;
368 ALCuint NumMonoSources
;
369 ALCuint NumStereoSources
;
372 // Map of Buffers for this device
375 // Map of Effects for this device
378 // Map of Filters for this device
381 // Map of Databuffers for this device
382 UIntMap DatabufferMap
;
384 // Stereo-to-binaural filter
388 // Simulated dampening from head occlusion
391 // Duplicate stereo sources on the side/rear channels
392 ALboolean DuplicateStereo
;
394 // Dry path buffer mix
395 ALfloat DryBuffer
[BUFFERSIZE
][OUTPUTCHANNELS
];
397 ALuint DevChannels
[OUTPUTCHANNELS
];
399 ALfloat ChannelMatrix
[OUTPUTCHANNELS
][OUTPUTCHANNELS
];
401 Channel Speaker2Chan
[OUTPUTCHANNELS
];
402 ALfloat PanningLUT
[OUTPUTCHANNELS
* LUT_NUM
];
405 ALfloat ClickRemoval
[OUTPUTCHANNELS
];
406 ALfloat PendingClicks
[OUTPUTCHANNELS
];
408 // Contexts created on this device
409 ALCcontext
**Contexts
;
413 void *ExtraData
; // For the backend's use
418 #define ALCdevice_OpenPlayback(a,b) ((a)->Funcs->OpenPlayback((a), (b)))
419 #define ALCdevice_ClosePlayback(a) ((a)->Funcs->ClosePlayback((a)))
420 #define ALCdevice_ResetPlayback(a) ((a)->Funcs->ResetPlayback((a)))
421 #define ALCdevice_StopPlayback(a) ((a)->Funcs->StopPlayback((a)))
422 #define ALCdevice_OpenCapture(a,b) ((a)->Funcs->OpenCapture((a), (b)))
423 #define ALCdevice_CloseCapture(a) ((a)->Funcs->CloseCapture((a)))
424 #define ALCdevice_StartCapture(a) ((a)->Funcs->StartCapture((a)))
425 #define ALCdevice_StopCapture(a) ((a)->Funcs->StopCapture((a)))
426 #define ALCdevice_CaptureSamples(a,b,c) ((a)->Funcs->CaptureSamples((a), (b), (c)))
427 #define ALCdevice_AvailableSamples(a) ((a)->Funcs->AvailableSamples((a)))
428 #define ALCdevice_GetTime(a) ((a)->Funcs->GetTime((a)))
430 struct ALCcontext_struct
435 UIntMap EffectSlotMap
;
437 struct ALdatabuffer
*SampleSource
;
438 struct ALdatabuffer
*SampleSink
;
444 ALenum DistanceModel
;
445 ALboolean SourceDistanceModel
;
447 ALfloat DopplerFactor
;
448 ALfloat DopplerVelocity
;
449 ALfloat flSpeedOfSound
;
451 struct ALsource
**ActiveSources
;
452 ALsizei ActiveSourceCount
;
453 ALsizei MaxActiveSources
;
456 const ALCchar
*ExtensionList
;
461 ALCvoid
ReleaseALC(ALCvoid
);
463 void AppendDeviceList(const ALCchar
*name
);
464 void AppendAllDeviceList(const ALCchar
*name
);
465 void AppendCaptureDeviceList(const ALCchar
*name
);
467 ALCvoid
alcSetError(ALCdevice
*device
, ALenum errorCode
);
469 ALCvoid
SuspendContext(ALCcontext
*context
);
470 ALCvoid
ProcessContext(ALCcontext
*context
);
472 ALvoid
*StartThread(ALuint (*func
)(ALvoid
*), ALvoid
*ptr
);
473 ALuint
StopThread(ALvoid
*thread
);
475 ALCcontext
*GetContextSuspended(void);
477 typedef struct RingBuffer RingBuffer
;
478 RingBuffer
*CreateRingBuffer(ALsizei frame_size
, ALsizei length
);
479 void DestroyRingBuffer(RingBuffer
*ring
);
480 ALsizei
RingBufferSize(RingBuffer
*ring
);
481 void WriteRingBuffer(RingBuffer
*ring
, const ALubyte
*data
, ALsizei len
);
482 void ReadRingBuffer(RingBuffer
*ring
, ALubyte
*data
, ALsizei len
);
484 void ReadALConfig(void);
485 void FreeALConfig(void);
486 int ConfigValueExists(const char *blockName
, const char *keyName
);
487 const char *GetConfigValue(const char *blockName
, const char *keyName
, const char *def
);
488 int GetConfigValueInt(const char *blockName
, const char *keyName
, int def
);
489 float GetConfigValueFloat(const char *blockName
, const char *keyName
, float def
);
490 int GetConfigValueBool(const char *blockName
, const char *keyName
, int def
);
492 void SetRTPriority(void);
494 void SetDefaultChannelOrder(ALCdevice
*device
);
495 void SetDefaultWFXChannelOrder(ALCdevice
*device
);
497 void al_print(const char *fname
, unsigned int line
, const char *fmt
, ...)
499 #define AL_PRINT(...) al_print(__FILE__, __LINE__, __VA_ARGS__)