16 #ifndef AL_EXT_sample_buffer_object
17 #define AL_EXT_sample_buffer_object 1
18 typedef ptrdiff_t ALintptrEXT
;
19 typedef ptrdiff_t ALsizeiptrEXT
;
20 #define AL_SAMPLE_SOURCE_EXT 0x1040
21 #define AL_SAMPLE_SINK_EXT 0x1041
22 #define AL_READ_ONLY_EXT 0x1042
23 #define AL_WRITE_ONLY_EXT 0x1043
24 #define AL_READ_WRITE_EXT 0x1044
25 #define AL_STREAM_WRITE_EXT 0x1045
26 #define AL_STREAM_READ_EXT 0x1046
27 #define AL_STREAM_COPY_EXT 0x1047
28 #define AL_STATIC_WRITE_EXT 0x1048
29 #define AL_STATIC_READ_EXT 0x1049
30 #define AL_STATIC_COPY_EXT 0x104A
31 #define AL_DYNAMIC_WRITE_EXT 0x104B
32 #define AL_DYNAMIC_READ_EXT 0x104C
33 #define AL_DYNAMIC_COPY_EXT 0x104D
34 typedef ALvoid (AL_APIENTRY
*PFNALGENDATABUFFERSEXTPROC
)(ALsizei n
,ALuint
*puiBuffers
);
35 typedef ALvoid (AL_APIENTRY
*PFNALDELETEDATABUFFERSEXTPROC
)(ALsizei n
, const ALuint
*puiBuffers
);
36 typedef ALboolean (AL_APIENTRY
*PFNALISDATABUFFEREXTPROC
)(ALuint uiBuffer
);
37 typedef ALvoid (AL_APIENTRY
*PFNALDATABUFFERDATAEXTPROC
)(ALuint buffer
,const ALvoid
*data
,ALsizeiptrEXT size
,ALenum usage
);
38 typedef ALvoid (AL_APIENTRY
*PFNALDATABUFFERSUBDATAEXTPROC
)(ALuint buffer
, ALintptrEXT start
, ALsizeiptrEXT length
, const ALvoid
*);
39 typedef ALvoid (AL_APIENTRY
*PFNALGETDATABUFFERSUBDATAEXTPROC
)(ALuint buffer
, ALintptrEXT start
, ALsizeiptrEXT length
, ALvoid
*);
40 typedef ALvoid (AL_APIENTRY
*PFNALDATABUFFERFEXTPROC
)(ALuint buffer
, ALenum eParam
, ALfloat flValue
);
41 typedef ALvoid (AL_APIENTRY
*PFNALDATABUFFERFVEXTPROC
)(ALuint buffer
, ALenum eParam
, const ALfloat
* flValues
);
42 typedef ALvoid (AL_APIENTRY
*PFNALDATABUFFERIEXTPROC
)(ALuint buffer
, ALenum eParam
, ALint lValue
);
43 typedef ALvoid (AL_APIENTRY
*PFNALDATABUFFERIVEXTPROC
)(ALuint buffer
, ALenum eParam
, const ALint
* plValues
);
44 typedef ALvoid (AL_APIENTRY
*PFNALGETDATABUFFERFEXTPROC
)(ALuint buffer
, ALenum eParam
, ALfloat
*pflValue
);
45 typedef ALvoid (AL_APIENTRY
*PFNALGETDATABUFFERFVEXTPROC
)(ALuint buffer
, ALenum eParam
, ALfloat
* pflValues
);
46 typedef ALvoid (AL_APIENTRY
*PFNALGETDATABUFFERIEXTPROC
)(ALuint buffer
, ALenum eParam
, ALint
*plValue
);
47 typedef ALvoid (AL_APIENTRY
*PFNALGETDATABUFFERIVEXTPROC
)(ALuint buffer
, ALenum eParam
, ALint
* plValues
);
48 typedef ALvoid (AL_APIENTRY
*PFNALSELECTDATABUFFEREXTPROC
)(ALenum target
, ALuint uiBuffer
);
49 typedef ALvoid
* (AL_APIENTRY
*PFNALMAPDATABUFFEREXTPROC
)(ALuint uiBuffer
, ALintptrEXT start
, ALsizeiptrEXT length
, ALenum access
);
50 typedef ALvoid (AL_APIENTRY
*PFNALUNMAPDATABUFFEREXTPROC
)(ALuint uiBuffer
);
51 #ifdef AL_ALEXT_PROTOTYPES
52 AL_API ALvoid AL_APIENTRY
alGenDatabuffersEXT(ALsizei n
,ALuint
*puiBuffers
);
53 AL_API ALvoid AL_APIENTRY
alDeleteDatabuffersEXT(ALsizei n
, const ALuint
*puiBuffers
);
54 AL_API ALboolean AL_APIENTRY
alIsDatabufferEXT(ALuint uiBuffer
);
55 AL_API ALvoid AL_APIENTRY
alDatabufferDataEXT(ALuint buffer
,const ALvoid
*data
,ALsizeiptrEXT size
,ALenum usage
);
56 AL_API ALvoid AL_APIENTRY
alDatabufferSubDataEXT(ALuint buffer
, ALintptrEXT start
, ALsizeiptrEXT length
, const ALvoid
*data
);
57 AL_API ALvoid AL_APIENTRY
alGetDatabufferSubDataEXT(ALuint buffer
, ALintptrEXT start
, ALsizeiptrEXT length
, ALvoid
*data
);
58 AL_API ALvoid AL_APIENTRY
alDatabufferfEXT(ALuint buffer
, ALenum eParam
, ALfloat flValue
);
59 AL_API ALvoid AL_APIENTRY
alDatabufferfvEXT(ALuint buffer
, ALenum eParam
, const ALfloat
* flValues
);
60 AL_API ALvoid AL_APIENTRY
alDatabufferiEXT(ALuint buffer
, ALenum eParam
, ALint lValue
);
61 AL_API ALvoid AL_APIENTRY
alDatabufferivEXT(ALuint buffer
, ALenum eParam
, const ALint
* plValues
);
62 AL_API ALvoid AL_APIENTRY
alGetDatabufferfEXT(ALuint buffer
, ALenum eParam
, ALfloat
*pflValue
);
63 AL_API ALvoid AL_APIENTRY
alGetDatabufferfvEXT(ALuint buffer
, ALenum eParam
, ALfloat
* pflValues
);
64 AL_API ALvoid AL_APIENTRY
alGetDatabufferiEXT(ALuint buffer
, ALenum eParam
, ALint
*plValue
);
65 AL_API ALvoid AL_APIENTRY
alGetDatabufferivEXT(ALuint buffer
, ALenum eParam
, ALint
* plValues
);
66 AL_API ALvoid AL_APIENTRY
alSelectDatabufferEXT(ALenum target
, ALuint uiBuffer
);
67 AL_API ALvoid
* AL_APIENTRY
alMapDatabufferEXT(ALuint uiBuffer
, ALintptrEXT start
, ALsizeiptrEXT length
, ALenum access
);
68 AL_API ALvoid AL_APIENTRY
alUnmapDatabufferEXT(ALuint uiBuffer
);
72 #ifndef AL_EXT_loop_points
73 #define AL_EXT_loop_points 1
74 #define AL_LOOP_POINTS 0x2015
78 #if defined(HAVE_STDINT_H)
80 typedef int64_t ALint64
;
81 typedef uint64_t ALuint64
;
82 #elif defined(HAVE___INT64)
83 typedef __int64 ALint64
;
84 typedef unsigned __int64 ALuint64
;
85 #elif (SIZEOF_LONG == 8)
87 typedef unsigned long ALuint64
;
88 #elif (SIZEOF_LONG_LONG == 8)
89 typedef long long ALint64
;
90 typedef unsigned long long ALuint64
;
93 #ifdef HAVE_GCC_FORMAT
94 #define PRINTF_STYLE(x, y) __attribute__((format(printf, (x), (y))))
96 #define PRINTF_STYLE(x, y)
102 #define _WIN32_WINNT 0x0500
106 typedef DWORD tls_type
;
107 #define tls_create(x) (*(x) = TlsAlloc())
108 #define tls_delete(x) TlsFree((x))
109 #define tls_get(x) TlsGetValue((x))
110 #define tls_set(x, a) TlsSetValue((x), (a))
117 #ifdef HAVE_PTHREAD_NP_H
118 #include <pthread_np.h>
120 #include <sys/time.h>
124 #define IsBadWritePtr(a,b) ((a) == NULL && (b) != 0)
126 typedef pthread_key_t tls_type
;
127 #define tls_create(x) pthread_key_create((x), NULL)
128 #define tls_delete(x) pthread_key_delete((x))
129 #define tls_get(x) pthread_getspecific((x))
130 #define tls_set(x, a) pthread_setspecific((x), (a))
132 typedef pthread_mutex_t CRITICAL_SECTION
;
133 static __inline
void EnterCriticalSection(CRITICAL_SECTION
*cs
)
136 ret
= pthread_mutex_lock(cs
);
139 static __inline
void LeaveCriticalSection(CRITICAL_SECTION
*cs
)
142 ret
= pthread_mutex_unlock(cs
);
145 static __inline
void InitializeCriticalSection(CRITICAL_SECTION
*cs
)
147 pthread_mutexattr_t attrib
;
150 ret
= pthread_mutexattr_init(&attrib
);
153 ret
= pthread_mutexattr_settype(&attrib
, PTHREAD_MUTEX_RECURSIVE
);
154 #ifdef HAVE_PTHREAD_NP_H
156 ret
= pthread_mutexattr_setkind_np(&attrib
, PTHREAD_MUTEX_RECURSIVE
);
159 ret
= pthread_mutex_init(cs
, &attrib
);
162 pthread_mutexattr_destroy(&attrib
);
165 static __inline
void DeleteCriticalSection(CRITICAL_SECTION
*cs
)
168 ret
= pthread_mutex_destroy(cs
);
172 /* NOTE: This wrapper isn't quite accurate as it returns an ALuint, as opposed
173 * to the expected DWORD. Both are defined as unsigned 32-bit types, however.
174 * Additionally, Win32 is supposed to measure the time since Windows started,
175 * as opposed to the actual time. */
176 static __inline ALuint
timeGetTime(void)
178 #if _POSIX_TIMERS > 0
179 static int hasmono
= 0;
183 #if defined(_POSIX_MONOTONIC_CLOCK) && (_POSIX_MONOTONIC_CLOCK >= 0)
184 #if _POSIX_MONOTONIC_CLOCK == 0
185 if(hasmono
> 0 || (hasmono
== 0 &&
186 (hasmono
=sysconf(_SC_MONOTONIC_CLOCK
)) > 0))
188 ret
= clock_gettime(CLOCK_MONOTONIC
, &ts
);
191 ret
= clock_gettime(CLOCK_REALTIME
, &ts
);
194 return ts
.tv_nsec
/1000000 + ts
.tv_sec
*1000;
199 ret
= gettimeofday(&tv
, NULL
);
202 return tv
.tv_usec
/1000 + tv
.tv_sec
*1000;
206 static __inline
void Sleep(ALuint t
)
208 struct timespec tv
, rem
;
209 tv
.tv_nsec
= (t
*1000000)%1000000000;
212 while(nanosleep(&tv
, &rem
) == -1 && errno
== EINTR
)
215 #define min(x,y) (((x)<(y))?(x):(y))
216 #define max(x,y) (((x)>(y))?(x):(y))
219 #include "alListener.h"
227 #define SWMIXER_OUTPUT_RATE 44100
229 #define SPEEDOFSOUNDMETRESPERSEC (343.3f)
230 #define AIRABSORBGAINDBHF (-0.05f)
232 #define LOWPASSFREQCUTOFF (5000)
234 #define DEFAULT_HEAD_DAMPEN (0.25f)
237 // Find the next power-of-2 for non-power-of-2 numbers.
238 static __inline ALuint
NextPowerOf2(ALuint value
)
256 ALCboolean (*OpenPlayback
)(ALCdevice
*, const ALCchar
*);
257 void (*ClosePlayback
)(ALCdevice
*);
258 ALCboolean (*ResetPlayback
)(ALCdevice
*);
259 void (*StopPlayback
)(ALCdevice
*);
261 ALCboolean (*OpenCapture
)(ALCdevice
*, const ALCchar
*);
262 void (*CloseCapture
)(ALCdevice
*);
263 void (*StartCapture
)(ALCdevice
*);
264 void (*StopCapture
)(ALCdevice
*);
265 void (*CaptureSamples
)(ALCdevice
*, void*, ALCuint
);
266 ALCuint (*AvailableSamples
)(ALCdevice
*);
275 void alc_alsa_init(BackendFuncs
*func_list
);
276 void alc_alsa_deinit(void);
277 void alc_alsa_probe(int type
);
278 void alc_oss_init(BackendFuncs
*func_list
);
279 void alc_oss_deinit(void);
280 void alc_oss_probe(int type
);
281 void alc_solaris_init(BackendFuncs
*func_list
);
282 void alc_solaris_deinit(void);
283 void alc_solaris_probe(int type
);
284 void alcDSoundInit(BackendFuncs
*func_list
);
285 void alcDSoundDeinit(void);
286 void alcDSoundProbe(int type
);
287 void alcWinMMInit(BackendFuncs
*FuncList
);
288 void alcWinMMDeinit(void);
289 void alcWinMMProbe(int type
);
290 void alc_pa_init(BackendFuncs
*func_list
);
291 void alc_pa_deinit(void);
292 void alc_pa_probe(int type
);
293 void alc_wave_init(BackendFuncs
*func_list
);
294 void alc_wave_deinit(void);
295 void alc_wave_probe(int type
);
296 void alc_pulse_init(BackendFuncs
*func_list
);
297 void alc_pulse_deinit(void);
298 void alc_pulse_probe(int type
);
299 void alc_null_init(BackendFuncs
*func_list
);
300 void alc_null_deinit(void);
301 void alc_null_probe(int type
);
304 typedef struct UIntMap
{
313 void InitUIntMap(UIntMap
*map
);
314 void ResetUIntMap(UIntMap
*map
);
315 ALenum
InsertUIntMapEntry(UIntMap
*map
, ALuint key
, ALvoid
*value
);
316 void RemoveUIntMapKey(UIntMap
*map
, ALuint key
);
317 ALvoid
*LookupUIntMapKey(UIntMap
*map
, ALuint key
);
321 DevFmtByte
, /* AL_BYTE */
322 DevFmtUByte
, /* AL_UNSIGNED_BYTE */
323 DevFmtShort
, /* AL_SHORT */
324 DevFmtUShort
, /* AL_UNSIGNED_SHORT */
325 DevFmtFloat
, /* AL_FLOAT */
327 enum DevFmtChannels
{
328 DevFmtMono
, /* AL_MONO */
329 DevFmtStereo
, /* AL_STEREO */
330 DevFmtQuad
, /* AL_QUAD */
331 DevFmtX51
, /* AL_5POINT1 */
332 DevFmtX61
, /* AL_6POINT1 */
333 DevFmtX71
, /* AL_7POINT1 */
336 ALuint
BytesFromDevFmt(enum DevFmtType type
);
337 ALuint
ChannelsFromDevFmt(enum DevFmtChannels chans
);
338 static __inline ALuint
FrameSizeFromDevFmt(enum DevFmtChannels chans
,
339 enum DevFmtType type
)
341 return ChannelsFromDevFmt(chans
) * BytesFromDevFmt(type
);
345 struct ALCdevice_struct
347 ALCboolean Connected
;
348 ALboolean IsCaptureDevice
;
353 enum DevFmtChannels FmtChans
;
354 enum DevFmtType FmtType
;
356 ALCchar
*szDeviceName
;
360 // Maximum number of sources that can be created
361 ALuint MaxNoOfSources
;
362 // Maximum number of slots that can be created
363 ALuint AuxiliaryEffectSlotMax
;
365 ALCuint NumMonoSources
;
366 ALCuint NumStereoSources
;
369 // Map of Buffers for this device
372 // Map of Effects for this device
375 // Map of Filters for this device
378 // Map of Databuffers for this device
379 UIntMap DatabufferMap
;
381 // Stereo-to-binaural filter
385 // Simulated dampening from head occlusion
388 // Duplicate stereo sources on the side/rear channels
389 ALboolean DuplicateStereo
;
391 // Dry path buffer mix
392 ALfloat DryBuffer
[BUFFERSIZE
][MAXCHANNELS
];
394 ALuint DevChannels
[MAXCHANNELS
];
396 ALfloat ChannelMatrix
[MAXCHANNELS
][MAXCHANNELS
];
398 Channel Speaker2Chan
[MAXCHANNELS
];
399 ALfloat PanningLUT
[MAXCHANNELS
* LUT_NUM
];
402 ALfloat ClickRemoval
[MAXCHANNELS
];
403 ALfloat PendingClicks
[MAXCHANNELS
];
405 // Contexts created on this device
406 ALCcontext
**Contexts
;
410 void *ExtraData
; // For the backend's use
415 #define ALCdevice_OpenPlayback(a,b) ((a)->Funcs->OpenPlayback((a), (b)))
416 #define ALCdevice_ClosePlayback(a) ((a)->Funcs->ClosePlayback((a)))
417 #define ALCdevice_ResetPlayback(a) ((a)->Funcs->ResetPlayback((a)))
418 #define ALCdevice_StopPlayback(a) ((a)->Funcs->StopPlayback((a)))
419 #define ALCdevice_OpenCapture(a,b) ((a)->Funcs->OpenCapture((a), (b)))
420 #define ALCdevice_CloseCapture(a) ((a)->Funcs->CloseCapture((a)))
421 #define ALCdevice_StartCapture(a) ((a)->Funcs->StartCapture((a)))
422 #define ALCdevice_StopCapture(a) ((a)->Funcs->StopCapture((a)))
423 #define ALCdevice_CaptureSamples(a,b,c) ((a)->Funcs->CaptureSamples((a), (b), (c)))
424 #define ALCdevice_AvailableSamples(a) ((a)->Funcs->AvailableSamples((a)))
426 struct ALCcontext_struct
431 UIntMap EffectSlotMap
;
433 struct ALdatabuffer
*SampleSource
;
434 struct ALdatabuffer
*SampleSink
;
440 ALenum DistanceModel
;
441 ALboolean SourceDistanceModel
;
443 ALfloat DopplerFactor
;
444 ALfloat DopplerVelocity
;
445 ALfloat flSpeedOfSound
;
447 struct ALsource
**ActiveSources
;
448 ALsizei ActiveSourceCount
;
449 ALsizei MaxActiveSources
;
452 const ALCchar
*ExtensionList
;
457 void AppendDeviceList(const ALCchar
*name
);
458 void AppendAllDeviceList(const ALCchar
*name
);
459 void AppendCaptureDeviceList(const ALCchar
*name
);
461 ALCvoid
alcSetError(ALCdevice
*device
, ALenum errorCode
);
463 ALCvoid
SuspendContext(ALCcontext
*context
);
464 ALCvoid
ProcessContext(ALCcontext
*context
);
466 ALvoid
*StartThread(ALuint (*func
)(ALvoid
*), ALvoid
*ptr
);
467 ALuint
StopThread(ALvoid
*thread
);
469 ALCcontext
*GetContextSuspended(void);
471 typedef struct RingBuffer RingBuffer
;
472 RingBuffer
*CreateRingBuffer(ALsizei frame_size
, ALsizei length
);
473 void DestroyRingBuffer(RingBuffer
*ring
);
474 ALsizei
RingBufferSize(RingBuffer
*ring
);
475 void WriteRingBuffer(RingBuffer
*ring
, const ALubyte
*data
, ALsizei len
);
476 void ReadRingBuffer(RingBuffer
*ring
, ALubyte
*data
, ALsizei len
);
478 void ReadALConfig(void);
479 void FreeALConfig(void);
480 int ConfigValueExists(const char *blockName
, const char *keyName
);
481 const char *GetConfigValue(const char *blockName
, const char *keyName
, const char *def
);
482 int GetConfigValueInt(const char *blockName
, const char *keyName
, int def
);
483 float GetConfigValueFloat(const char *blockName
, const char *keyName
, float def
);
484 int GetConfigValueBool(const char *blockName
, const char *keyName
, int def
);
486 void SetRTPriority(void);
488 void SetDefaultChannelOrder(ALCdevice
*device
);
489 void SetDefaultWFXChannelOrder(ALCdevice
*device
);
491 void al_print(const char *fname
, unsigned int line
, const char *fmt
, ...)
493 #define AL_PRINT(...) al_print(__FILE__, __LINE__, __VA_ARGS__)