23 #include "static_assert.h"
32 #ifndef ALC_SOFT_loopback2
33 #define ALC_SOFT_loopback2 1
34 #define ALC_AMBISONIC_LAYOUT_SOFT 0x1997
35 #define ALC_AMBISONIC_SCALING_SOFT 0x1998
36 #define ALC_AMBISONIC_ORDER_SOFT 0x1999
38 #define ALC_BFORMAT3D_SOFT 0x1508
40 /* Ambisonic layouts */
41 #define ALC_ACN_SOFT 0x1600
42 #define ALC_FUMA_SOFT 0x1601
44 /* Ambisonic scalings (normalization) */
45 #define ALC_N3D_SOFT 0x1700
46 #define ALC_SN3D_SOFT 0x1701
47 /*#define ALC_FUMA_SOFT*/
49 typedef ALCboolean (ALC_APIENTRY
*LPALCISAMBISONICFORMATSUPPORTEDSOFT
)(ALCdevice
*device
, ALCenum layout
, ALCenum scaling
, ALsizei order
);
50 #ifdef AL_ALEXT_PROTOTYPES
51 ALC_API ALCboolean ALC_APIENTRY
alcIsAmbisonicFormatSupportedSOFT(ALCdevice
*device
, ALCenum layout
, ALCenum scaling
, ALsizei order
);
55 #ifndef ALC_SOFT_device_clock
56 #define ALC_SOFT_device_clock 1
57 typedef int64_t ALCint64SOFT
;
58 typedef uint64_t ALCuint64SOFT
;
59 #define ALC_DEVICE_CLOCK_SOFT 0x1600
60 #define ALC_DEVICE_LATENCY_SOFT 0x1601
61 #define ALC_DEVICE_CLOCK_LATENCY_SOFT 0x1602
62 typedef void (ALC_APIENTRY
*LPALCGETINTEGER64VSOFT
)(ALCdevice
*device
, ALCenum pname
, ALsizei size
, ALCint64SOFT
*values
);
63 #ifdef AL_ALEXT_PROTOTYPES
64 ALC_API
void ALC_APIENTRY
alcGetInteger64vSOFT(ALCdevice
*device
, ALCenum pname
, ALsizei size
, ALCint64SOFT
*values
);
68 #ifndef AL_SOFT_buffer_samples2
69 #define AL_SOFT_buffer_samples2 1
70 /* Channel configurations */
71 #define AL_MONO_SOFT 0x1500
72 #define AL_STEREO_SOFT 0x1501
73 #define AL_REAR_SOFT 0x1502
74 #define AL_QUAD_SOFT 0x1503
75 #define AL_5POINT1_SOFT 0x1504
76 #define AL_6POINT1_SOFT 0x1505
77 #define AL_7POINT1_SOFT 0x1506
78 #define AL_BFORMAT2D_SOFT 0x1507
79 #define AL_BFORMAT3D_SOFT 0x1508
82 #define AL_BYTE_SOFT 0x1400
83 #define AL_UNSIGNED_BYTE_SOFT 0x1401
84 #define AL_SHORT_SOFT 0x1402
85 #define AL_UNSIGNED_SHORT_SOFT 0x1403
86 #define AL_INT_SOFT 0x1404
87 #define AL_UNSIGNED_INT_SOFT 0x1405
88 #define AL_FLOAT_SOFT 0x1406
89 #define AL_DOUBLE_SOFT 0x1407
90 #define AL_BYTE3_SOFT 0x1408
91 #define AL_UNSIGNED_BYTE3_SOFT 0x1409
92 #define AL_MULAW_SOFT 0x140A
95 #define AL_MONO8_SOFT 0x1100
96 #define AL_MONO16_SOFT 0x1101
97 #define AL_MONO32F_SOFT 0x10010
98 #define AL_STEREO8_SOFT 0x1102
99 #define AL_STEREO16_SOFT 0x1103
100 #define AL_STEREO32F_SOFT 0x10011
101 #define AL_QUAD8_SOFT 0x1204
102 #define AL_QUAD16_SOFT 0x1205
103 #define AL_QUAD32F_SOFT 0x1206
104 #define AL_REAR8_SOFT 0x1207
105 #define AL_REAR16_SOFT 0x1208
106 #define AL_REAR32F_SOFT 0x1209
107 #define AL_5POINT1_8_SOFT 0x120A
108 #define AL_5POINT1_16_SOFT 0x120B
109 #define AL_5POINT1_32F_SOFT 0x120C
110 #define AL_6POINT1_8_SOFT 0x120D
111 #define AL_6POINT1_16_SOFT 0x120E
112 #define AL_6POINT1_32F_SOFT 0x120F
113 #define AL_7POINT1_8_SOFT 0x1210
114 #define AL_7POINT1_16_SOFT 0x1211
115 #define AL_7POINT1_32F_SOFT 0x1212
116 #define AL_BFORMAT2D_8_SOFT 0x20021
117 #define AL_BFORMAT2D_16_SOFT 0x20022
118 #define AL_BFORMAT2D_32F_SOFT 0x20023
119 #define AL_BFORMAT3D_8_SOFT 0x20031
120 #define AL_BFORMAT3D_16_SOFT 0x20032
121 #define AL_BFORMAT3D_32F_SOFT 0x20033
123 /* Buffer attributes */
124 #define AL_INTERNAL_FORMAT_SOFT 0x2008
125 #define AL_BYTE_LENGTH_SOFT 0x2009
126 #define AL_SAMPLE_LENGTH_SOFT 0x200A
127 #define AL_SEC_LENGTH_SOFT 0x200B
130 typedef void (AL_APIENTRY
*LPALBUFFERSAMPLESSOFT
)(ALuint
,ALuint
,ALenum
,ALsizei
,ALenum
,ALenum
,const ALvoid
*);
131 typedef void (AL_APIENTRY
*LPALGETBUFFERSAMPLESSOFT
)(ALuint
,ALsizei
,ALsizei
,ALenum
,ALenum
,ALvoid
*);
132 typedef ALboolean (AL_APIENTRY
*LPALISBUFFERFORMATSUPPORTEDSOFT
)(ALenum
);
133 #ifdef AL_ALEXT_PROTOTYPES
134 AL_API
void AL_APIENTRY
alBufferSamplesSOFT(ALuint buffer
, ALuint samplerate
, ALenum internalformat
, ALsizei samples
, ALenum channels
, ALenum type
, const ALvoid
*data
);
135 AL_API
void AL_APIENTRY
alGetBufferSamplesSOFT(ALuint buffer
, ALsizei offset
, ALsizei samples
, ALenum channels
, ALenum type
, ALvoid
*data
);
136 AL_API ALboolean AL_APIENTRY
alIsBufferFormatSupportedSOFT(ALenum format
);
143 #define SZFMT "%I64u"
144 #elif defined(_WIN32)
152 /* Because of a long-standing deficiency in C, you're not allowed to implicitly
153 * cast a pointer-to-type-array to a pointer-to-const-type-array. For example,
156 * const int (*cptr)[10] = ptr;
158 * is not allowed and most compilers will generate noisy warnings about
159 * incompatible types, even though it just makes the array elements const.
160 * Clang will allow it if you make the array type a typedef, like this:
162 * typedef int int10[10];
164 * const int10 *cptr = ptr;
166 * however GCC does not and still issues the incompatible type warning. The
167 * "proper" way to fix it is to add an explicit cast for the constified type,
168 * but that removes the vast majority of otherwise useful type-checking you'd
169 * get, and runs the risk of improper casts if types are later changed. Leaving
170 * it non-const can also be an issue if you use it as a function parameter, and
171 * happen to have a const type as input (and also reduce the capabilities of
172 * the compiler to better optimize the function).
174 * So to work around the problem, we use a macro. The macro first assigns the
175 * incoming variable to the specified non-const type to ensure it's the correct
176 * type, then casts the variable as the desired constified type. Very ugly, but
177 * I'd rather not have hundreds of lines of warnings because I want to tell the
178 * compiler that some array(s) can't be changed by the code, or have lots of
181 #define SAFE_CONST(T, var) __extension__({ \
186 /* Non-GNU-compatible compilers have to use a straight cast with no extra
187 * checks, due to the lack of multi-statement expressions.
189 #define SAFE_CONST(T, var) ((const T)(var))
193 typedef ALint64SOFT ALint64
;
194 typedef ALuint64SOFT ALuint64
;
197 #if defined(_MSC_VER)
198 #define U64(x) ((ALuint64)(x##ui64))
199 #elif SIZEOF_LONG == 8
200 #define U64(x) ((ALuint64)(x##ul))
201 #elif SIZEOF_LONG_LONG == 8
202 #define U64(x) ((ALuint64)(x##ull))
207 #define UINT64_MAX U64(18446744073709551615)
211 #if defined(__cplusplus)
213 #elif defined(__GNUC__)
214 #define UNUSED(x) UNUSED_##x __attribute__((unused))
215 #elif defined(__LCLINT__)
216 #define UNUSED(x) /*@unused@*/ x
223 #define DECL_FORMAT(x, y, z) __attribute__((format(x, (y), (z))))
225 #define DECL_FORMAT(x, y, z)
228 #if defined(__GNUC__) && defined(__i386__)
229 /* force_align_arg_pointer is required for proper function arguments aligning
230 * when SSE code is used. Some systems (Windows, QNX) do not guarantee our
231 * thread functions will be properly aligned on the stack, even though GCC may
232 * generate code with the assumption that it is. */
233 #define FORCE_ALIGN __attribute__((force_align_arg_pointer))
239 #define DECL_VLA(T, _name, _size) T _name[(_size)]
241 #define DECL_VLA(T, _name, _size) T *_name = alloca((_size) * sizeof(T))
246 #define PATH_MAX MAX_PATH
248 #define PATH_MAX 4096
255 ALubyte b
[sizeof(ALuint
)];
256 } EndianTest
= { 1 };
257 #define IS_LITTLE_ENDIAN (EndianTest.b[0] == 1)
259 #define COUNTOF(x) (sizeof((x))/sizeof((x)[0]))
262 #define DERIVE_FROM_TYPE(t) t t##_parent
263 #define STATIC_CAST(to, obj) (&(obj)->to##_parent)
265 #define STATIC_UPCAST(to, from, obj) __extension__({ \
266 static_assert(__builtin_types_compatible_p(from, __typeof(*(obj))), \
267 "Invalid upcast object from type"); \
268 (to*)((char*)(obj) - offsetof(to, from##_parent)); \
271 #define STATIC_UPCAST(to, from, obj) ((to*)((char*)(obj) - offsetof(to, from##_parent)))
274 #define DECLARE_FORWARD(T1, T2, rettype, func) \
275 rettype T1##_##func(T1 *obj) \
276 { return T2##_##func(STATIC_CAST(T2, obj)); }
278 #define DECLARE_FORWARD1(T1, T2, rettype, func, argtype1) \
279 rettype T1##_##func(T1 *obj, argtype1 a) \
280 { return T2##_##func(STATIC_CAST(T2, obj), a); }
282 #define DECLARE_FORWARD2(T1, T2, rettype, func, argtype1, argtype2) \
283 rettype T1##_##func(T1 *obj, argtype1 a, argtype2 b) \
284 { return T2##_##func(STATIC_CAST(T2, obj), a, b); }
286 #define DECLARE_FORWARD3(T1, T2, rettype, func, argtype1, argtype2, argtype3) \
287 rettype T1##_##func(T1 *obj, argtype1 a, argtype2 b, argtype3 c) \
288 { return T2##_##func(STATIC_CAST(T2, obj), a, b, c); }
291 #define GET_VTABLE1(T1) (&(T1##_vtable))
292 #define GET_VTABLE2(T1, T2) (&(T1##_##T2##_vtable))
294 #define SET_VTABLE1(T1, obj) ((obj)->vtbl = GET_VTABLE1(T1))
295 #define SET_VTABLE2(T1, T2, obj) (STATIC_CAST(T2, obj)->vtbl = GET_VTABLE2(T1, T2))
297 #define DECLARE_THUNK(T1, T2, rettype, func) \
298 static rettype T1##_##T2##_##func(T2 *obj) \
299 { return T1##_##func(STATIC_UPCAST(T1, T2, obj)); }
301 #define DECLARE_THUNK1(T1, T2, rettype, func, argtype1) \
302 static rettype T1##_##T2##_##func(T2 *obj, argtype1 a) \
303 { return T1##_##func(STATIC_UPCAST(T1, T2, obj), a); }
305 #define DECLARE_THUNK2(T1, T2, rettype, func, argtype1, argtype2) \
306 static rettype T1##_##T2##_##func(T2 *obj, argtype1 a, argtype2 b) \
307 { return T1##_##func(STATIC_UPCAST(T1, T2, obj), a, b); }
309 #define DECLARE_THUNK3(T1, T2, rettype, func, argtype1, argtype2, argtype3) \
310 static rettype T1##_##T2##_##func(T2 *obj, argtype1 a, argtype2 b, argtype3 c) \
311 { return T1##_##func(STATIC_UPCAST(T1, T2, obj), a, b, c); }
313 #define DECLARE_THUNK4(T1, T2, rettype, func, argtype1, argtype2, argtype3, argtype4) \
314 static rettype T1##_##T2##_##func(T2 *obj, argtype1 a, argtype2 b, argtype3 c, argtype4 d) \
315 { return T1##_##func(STATIC_UPCAST(T1, T2, obj), a, b, c, d); }
317 #define DECLARE_DEFAULT_ALLOCATORS(T) \
318 static void* T##_New(size_t size) { return al_malloc(16, size); } \
319 static void T##_Delete(void *ptr) { al_free(ptr); }
321 /* Helper to extract an argument list for VCALL. Not used directly. */
322 #define EXTRACT_VCALL_ARGS(...) __VA_ARGS__))
324 /* Call a "virtual" method on an object, with arguments. */
325 #define V(obj, func) ((obj)->vtbl->func((obj), EXTRACT_VCALL_ARGS
326 /* Call a "virtual" method on an object, with no arguments. */
327 #define V0(obj, func) ((obj)->vtbl->func((obj) EXTRACT_VCALL_ARGS
329 #define DELETE_OBJ(obj) do { \
332 V0((obj),Destruct)(); \
333 V0((obj),Delete)(); \
338 #define EXTRACT_NEW_ARGS(...) __VA_ARGS__); \
342 #define NEW_OBJ(_res, T) do { \
343 _res = T##_New(sizeof(T)); \
346 memset(_res, 0, sizeof(T)); \
347 T##_Construct(_res, EXTRACT_NEW_ARGS
348 #define NEW_OBJ0(_res, T) do { \
349 _res = T##_New(sizeof(T)); \
352 memset(_res, 0, sizeof(T)); \
353 T##_Construct(_res EXTRACT_NEW_ARGS
363 #define DEFAULT_OUTPUT_RATE (44100)
364 #define MIN_OUTPUT_RATE (8000)
367 /* Find the next power-of-2 for non-power-of-2 numbers. */
368 inline ALuint
NextPowerOf2(ALuint value
)
382 /** Round up a value to the next multiple. */
383 inline size_t RoundUp(size_t value
, size_t r
)
386 return value
- (value
%r
);
389 /* Fast float-to-int conversion. Assumes the FPU is already in round-to-zero
391 inline ALint
fastf2i(ALfloat f
)
395 #elif defined(_MSC_VER) && defined(_M_IX86)
405 /* Fast float-to-uint conversion. Assumes the FPU is already in round-to-zero
407 inline ALuint
fastf2u(ALfloat f
)
408 { return fastf2i(f
); }
417 ALCenum (*OpenPlayback
)(ALCdevice
*, const ALCchar
*);
418 void (*ClosePlayback
)(ALCdevice
*);
419 ALCboolean (*ResetPlayback
)(ALCdevice
*);
420 ALCboolean (*StartPlayback
)(ALCdevice
*);
421 void (*StopPlayback
)(ALCdevice
*);
423 ALCenum (*OpenCapture
)(ALCdevice
*, const ALCchar
*);
424 void (*CloseCapture
)(ALCdevice
*);
425 void (*StartCapture
)(ALCdevice
*);
426 void (*StopCapture
)(ALCdevice
*);
427 ALCenum (*CaptureSamples
)(ALCdevice
*, void*, ALCuint
);
428 ALCuint (*AvailableSamples
)(ALCdevice
*);
431 ALCboolean
alc_ca_init(BackendFuncs
*func_list
);
432 void alc_ca_deinit(void);
433 void alc_ca_probe(enum DevProbe type
);
434 ALCboolean
alc_qsa_init(BackendFuncs
*func_list
);
435 void alc_qsa_deinit(void);
436 void alc_qsa_probe(enum DevProbe type
);
442 InverseDistanceClamped
= AL_INVERSE_DISTANCE_CLAMPED
,
443 LinearDistanceClamped
= AL_LINEAR_DISTANCE_CLAMPED
,
444 ExponentDistanceClamped
= AL_EXPONENT_DISTANCE_CLAMPED
,
445 InverseDistance
= AL_INVERSE_DISTANCE
,
446 LinearDistance
= AL_LINEAR_DISTANCE
,
447 ExponentDistance
= AL_EXPONENT_DISTANCE
,
448 DisableDistance
= AL_NONE
,
450 DefaultDistanceModel
= InverseDistanceClamped
496 DevFmtByte
= ALC_BYTE_SOFT
,
497 DevFmtUByte
= ALC_UNSIGNED_BYTE_SOFT
,
498 DevFmtShort
= ALC_SHORT_SOFT
,
499 DevFmtUShort
= ALC_UNSIGNED_SHORT_SOFT
,
500 DevFmtInt
= ALC_INT_SOFT
,
501 DevFmtUInt
= ALC_UNSIGNED_INT_SOFT
,
502 DevFmtFloat
= ALC_FLOAT_SOFT
,
504 DevFmtTypeDefault
= DevFmtFloat
506 enum DevFmtChannels
{
507 DevFmtMono
= ALC_MONO_SOFT
,
508 DevFmtStereo
= ALC_STEREO_SOFT
,
509 DevFmtQuad
= ALC_QUAD_SOFT
,
510 DevFmtX51
= ALC_5POINT1_SOFT
,
511 DevFmtX61
= ALC_6POINT1_SOFT
,
512 DevFmtX71
= ALC_7POINT1_SOFT
,
514 /* Similar to 5.1, except using rear channels instead of sides */
515 DevFmtX51Rear
= 0x80000000,
517 /* Ambisonic formats should be kept together */
522 DevFmtChannelsDefault
= DevFmtStereo
524 #define MAX_OUTPUT_CHANNELS (16)
526 ALsizei
BytesFromDevFmt(enum DevFmtType type
);
527 ALsizei
ChannelsFromDevFmt(enum DevFmtChannels chans
);
528 inline ALsizei
FrameSizeFromDevFmt(enum DevFmtChannels chans
, enum DevFmtType type
)
530 return ChannelsFromDevFmt(chans
) * BytesFromDevFmt(type
);
534 AmbiLayout_FuMa
= ALC_FUMA_SOFT
, /* FuMa channel order */
535 AmbiLayout_ACN
= ALC_ACN_SOFT
, /* ACN channel order */
537 AmbiLayout_Default
= AmbiLayout_ACN
541 AmbiNorm_FuMa
= ALC_FUMA_SOFT
, /* FuMa normalization */
542 AmbiNorm_SN3D
= ALC_SN3D_SOFT
, /* SN3D normalization */
543 AmbiNorm_N3D
= ALC_N3D_SOFT
, /* N3D normalization */
545 AmbiNorm_Default
= AmbiNorm_SN3D
549 extern const struct EffectList
{
571 /* The maximum number of Ambisonics coefficients. For a given order (o), the
572 * size needed will be (o+1)**2, thus zero-order has 1, first-order has 4,
573 * second-order has 9, third-order has 16, and fourth-order has 25.
575 #define MAX_AMBI_ORDER 3
576 #define MAX_AMBI_COEFFS ((MAX_AMBI_ORDER+1) * (MAX_AMBI_ORDER+1))
578 /* A bitmask of ambisonic channels with height information. If none of these
579 * channels are used/needed, there's no height (e.g. with most surround sound
580 * speaker setups). This only specifies up to 4th order, which is the highest
581 * order a 32-bit mask value can specify (a 64-bit mask could handle up to 7th
582 * order). This is ACN ordering, with bit 0 being ACN 0, etc.
584 #define AMBI_PERIPHONIC_MASK (0xfe7ce4)
586 /* The maximum number of Ambisonic coefficients for 2D (non-periphonic)
587 * representation. This is 2 per each order above zero-order, plus 1 for zero-
588 * order. Or simply, o*2 + 1.
590 #define MAX_AMBI2D_COEFFS (MAX_AMBI_ORDER*2 + 1)
593 typedef ALfloat ChannelConfig
[MAX_AMBI_COEFFS
];
594 typedef struct BFChannelConfig
{
599 typedef union AmbiConfig
{
600 /* Ambisonic coefficients for mixing to the dry buffer. */
601 ChannelConfig Coeffs
[MAX_OUTPUT_CHANNELS
];
602 /* Coefficient channel mapping for mixing to the dry buffer. */
603 BFChannelConfig Map
[MAX_OUTPUT_CHANNELS
];
607 #define HRTF_HISTORY_BITS (6)
608 #define HRTF_HISTORY_LENGTH (1<<HRTF_HISTORY_BITS)
609 #define HRTF_HISTORY_MASK (HRTF_HISTORY_LENGTH-1)
611 #define HRIR_BITS (7)
612 #define HRIR_LENGTH (1<<HRIR_BITS)
613 #define HRIR_MASK (HRIR_LENGTH-1)
615 typedef struct HrtfState
{
616 alignas(16) ALfloat History
[HRTF_HISTORY_LENGTH
];
617 alignas(16) ALfloat Values
[HRIR_LENGTH
][2];
620 typedef struct HrtfParams
{
621 alignas(16) ALfloat Coeffs
[HRIR_LENGTH
][2];
625 typedef struct HrtfEntry
{
628 const struct Hrtf
*hrtf
;
630 TYPEDEF_VECTOR(HrtfEntry
, vector_HrtfEntry
)
633 /* Maximum delay in samples for speaker distance compensation. */
634 #define MAX_DELAY_LENGTH 1024
636 typedef struct DistanceComp
{
638 ALsizei Length
; /* Valid range is [0...MAX_DELAY_LENGTH). */
642 /* Size for temporary storage of buffer data, in ALfloats. Larger values need
643 * more memory, while smaller values may need more iterations. The value needs
644 * to be a sensible size, however, as it constrains the max stepping value used
645 * for mixing, as well as the maximum number of samples per mixing iteration.
647 #define BUFFERSIZE 2048
649 struct ALCdevice_struct
653 ALCboolean Connected
;
654 enum DeviceType Type
;
659 enum DevFmtChannels FmtChans
;
660 enum DevFmtType FmtType
;
661 ALboolean IsHeadphones
;
662 /* For DevFmtAmbi* output only, specifies the channel order and
665 enum AmbiLayout AmbiLayout
;
666 enum AmbiNorm AmbiScale
;
668 al_string DeviceName
;
670 ATOMIC(ALCenum
) LastError
;
672 // Maximum number of sources that can be created
674 // Maximum number of slots that can be created
675 ALuint AuxiliaryEffectSlotMax
;
677 ALCuint NumMonoSources
;
678 ALCuint NumStereoSources
;
681 // Map of Buffers for this device
684 // Map of Effects for this device
687 // Map of Filters for this device
690 /* HRTF filter tables */
692 vector_HrtfEntry List
;
695 const struct Hrtf
*Handle
;
697 /* HRTF filter state for dry buffer content */
698 alignas(16) ALfloat Values
[9][HRIR_LENGTH
][2];
699 alignas(16) ALfloat Coeffs
[9][HRIR_LENGTH
][2];
704 /* UHJ encoder state */
705 struct Uhj2Encoder
*Uhj_Encoder
;
707 /* High quality Ambisonic decoder */
708 struct BFormatDec
*AmbiDecoder
;
710 /* Stereo-to-binaural filter */
713 /* First-order ambisonic upsampler for higher-order output */
714 struct AmbiUpsampler
*AmbiUp
;
716 /* Rendering mode. */
717 enum RenderMode Render_Mode
;
725 /* Temp storage used for each source when mixing. */
726 alignas(16) ALfloat SourceData
[BUFFERSIZE
];
727 alignas(16) ALfloat ResampledData
[BUFFERSIZE
];
728 alignas(16) ALfloat FilteredData
[BUFFERSIZE
];
729 alignas(16) ALfloat NFCtrlData
[BUFFERSIZE
];
731 /* The "dry" path corresponds to the main output. */
734 /* Number of coefficients in each Ambi.Coeffs to mix together (4 for
735 * first-order, 9 for second-order, etc). If the count is 0, Ambi.Map
736 * is used instead to map each output to a coefficient index.
740 ALfloat (*Buffer
)[BUFFERSIZE
];
742 ALsizei NumChannelsPerOrder
[MAX_AMBI_ORDER
+1];
745 /* First-order ambisonics output, to be upsampled to the dry buffer if different. */
748 /* Will only be 4 or 0. */
751 ALfloat (*Buffer
)[BUFFERSIZE
];
755 /* "Real" output, which will be written to the device buffer. May alias the
759 enum Channel ChannelName
[MAX_OUTPUT_CHANNELS
];
761 ALfloat (*Buffer
)[BUFFERSIZE
];
765 /* The average speaker distance as determined by the ambdec configuration
766 * (or alternatively, by the NFC-HOA reference delay). Only used for NFC.
768 ALfloat AvgSpeakerDist
;
770 /* Delay buffers used to compensate for speaker distances. */
771 DistanceComp ChannelDelay
[MAX_OUTPUT_CHANNELS
];
773 /* Running count of the mixer invocations, in 31.1 fixed point. This
774 * actually increments *twice* when mixing, first at the start and then at
775 * the end, so the bottom bit indicates if the device is currently mixing
776 * and the upper bits indicates how many mixes have been done.
780 /* Default effect slot */
781 struct ALeffectslot
*DefaultSlot
;
783 // Contexts created on this device
784 ATOMIC(ALCcontext
*) ContextList
;
787 struct ALCbackend
*Backend
;
789 void *ExtraData
; // For the backend's use
791 ALCdevice
*volatile next
;
793 /* Memory space used by the default slot (Playback devices only) */
794 alignas(16) ALCbyte _slot_mem
[];
797 // Frequency was requested by the app or config file
798 #define DEVICE_FREQUENCY_REQUEST (1u<<1)
799 // Channel configuration was requested by the config file
800 #define DEVICE_CHANNELS_REQUEST (1u<<2)
801 // Sample type was requested by the config file
802 #define DEVICE_SAMPLE_TYPE_REQUEST (1u<<3)
804 // Specifies if the DSP is paused at user request
805 #define DEVICE_PAUSED (1u<<30)
807 // Specifies if the device is currently running
808 #define DEVICE_RUNNING (1u<<31)
811 /* Nanosecond resolution for the device clock time. */
812 #define DEVICE_CLOCK_RES U64(1000000000)
815 /* Must be less than 15 characters (16 including terminating null) for
816 * compatibility with pthread_setname_np limitations. */
817 #define MIXER_THREAD_NAME "alsoft-mixer"
819 #define RECORD_THREAD_NAME "alsoft-record"
822 struct ALCcontext_struct
{
825 struct ALlistener
*Listener
;
828 UIntMap EffectSlotMap
;
830 ATOMIC(ALenum
) LastError
;
832 enum DistanceModel DistanceModel
;
833 ALboolean SourceDistanceModel
;
835 ALfloat DopplerFactor
;
836 ALfloat DopplerVelocity
;
837 ALfloat SpeedOfSound
;
838 ATOMIC(ALenum
) DeferUpdates
;
842 /* Counter for the pre-mixing updates, in 31.1 fixed point (lowest bit
843 * indicates if updates are currently happening).
845 RefCount UpdateCount
;
846 ATOMIC(ALenum
) HoldUpdates
;
850 struct ALvoice
**Voices
;
854 ATOMIC(struct ALeffectslot
*) ActiveAuxSlotList
;
857 const ALCchar
*ExtensionList
;
859 ALCcontext
*volatile next
;
861 /* Memory space used by the listener */
862 alignas(16) ALCbyte _listener_mem
[];
865 ALCcontext
*GetContextRef(void);
867 void ALCcontext_IncRef(ALCcontext
*context
);
868 void ALCcontext_DecRef(ALCcontext
*context
);
870 void AllocateVoices(ALCcontext
*context
, ALsizei num_voices
, ALsizei old_sends
);
872 void AppendAllDevicesList(const ALCchar
*name
);
873 void AppendCaptureDeviceList(const ALCchar
*name
);
875 void ALCdevice_Lock(ALCdevice
*device
);
876 void ALCdevice_Unlock(ALCdevice
*device
);
878 void ALCcontext_DeferUpdates(ALCcontext
*context
, ALenum type
);
879 void ALCcontext_ProcessUpdates(ALCcontext
*context
);
890 DERIVE_FROM_TYPE(fenv_t
);
898 void SetMixerFPUMode(FPUCtl
*ctl
);
899 void RestoreFPUMode(const FPUCtl
*ctl
);
902 typedef struct ll_ringbuffer ll_ringbuffer_t
;
903 typedef struct ll_ringbuffer_data
{
906 } ll_ringbuffer_data_t
;
907 ll_ringbuffer_t
*ll_ringbuffer_create(size_t sz
, size_t elem_sz
);
908 void ll_ringbuffer_free(ll_ringbuffer_t
*rb
);
909 void ll_ringbuffer_get_read_vector(const ll_ringbuffer_t
*rb
, ll_ringbuffer_data_t
*vec
);
910 void ll_ringbuffer_get_write_vector(const ll_ringbuffer_t
*rb
, ll_ringbuffer_data_t
*vec
);
911 size_t ll_ringbuffer_read(ll_ringbuffer_t
*rb
, char *dest
, size_t cnt
);
912 size_t ll_ringbuffer_peek(ll_ringbuffer_t
*rb
, char *dest
, size_t cnt
);
913 void ll_ringbuffer_read_advance(ll_ringbuffer_t
*rb
, size_t cnt
);
914 size_t ll_ringbuffer_read_space(const ll_ringbuffer_t
*rb
);
915 int ll_ringbuffer_mlock(ll_ringbuffer_t
*rb
);
916 void ll_ringbuffer_reset(ll_ringbuffer_t
*rb
);
917 size_t ll_ringbuffer_write(ll_ringbuffer_t
*rb
, const char *src
, size_t cnt
);
918 void ll_ringbuffer_write_advance(ll_ringbuffer_t
*rb
, size_t cnt
);
919 size_t ll_ringbuffer_write_space(const ll_ringbuffer_t
*rb
);
921 void ReadALConfig(void);
922 void FreeALConfig(void);
923 int ConfigValueExists(const char *devName
, const char *blockName
, const char *keyName
);
924 const char *GetConfigValue(const char *devName
, const char *blockName
, const char *keyName
, const char *def
);
925 int GetConfigValueBool(const char *devName
, const char *blockName
, const char *keyName
, int def
);
926 int ConfigValueStr(const char *devName
, const char *blockName
, const char *keyName
, const char **ret
);
927 int ConfigValueInt(const char *devName
, const char *blockName
, const char *keyName
, int *ret
);
928 int ConfigValueUInt(const char *devName
, const char *blockName
, const char *keyName
, unsigned int *ret
);
929 int ConfigValueFloat(const char *devName
, const char *blockName
, const char *keyName
, float *ret
);
930 int ConfigValueBool(const char *devName
, const char *blockName
, const char *keyName
, int *ret
);
932 void SetRTPriority(void);
934 void SetDefaultChannelOrder(ALCdevice
*device
);
935 void SetDefaultWFXChannelOrder(ALCdevice
*device
);
937 const ALCchar
*DevFmtTypeString(enum DevFmtType type
);
938 const ALCchar
*DevFmtChannelsString(enum DevFmtChannels chans
);
941 * GetChannelIdxByName
943 * Returns the index for the given channel name (e.g. FrontCenter), or -1 if it
946 inline ALint
GetChannelIndex(const enum Channel names
[MAX_OUTPUT_CHANNELS
], enum Channel chan
)
949 for(i
= 0;i
< MAX_OUTPUT_CHANNELS
;i
++)
956 #define GetChannelIdxByName(x, c) GetChannelIndex((x).ChannelName, (c))
958 extern FILE *LogFile
;
960 #if defined(__GNUC__) && !defined(_WIN32) && !defined(IN_IDE_PARSER)
961 #define AL_PRINT(T, MSG, ...) fprintf(LogFile, "AL lib: %s %s: "MSG, T, __FUNCTION__ , ## __VA_ARGS__)
963 void al_print(const char *type
, const char *func
, const char *fmt
, ...) DECL_FORMAT(printf
, 3,4);
964 #define AL_PRINT(T, ...) al_print((T), __FUNCTION__, __VA_ARGS__)
968 #include <android/log.h>
969 #define LOG_ANDROID(T, MSG, ...) __android_log_print(T, "openal", "AL lib: %s: "MSG, __FUNCTION__ , ## __VA_ARGS__)
971 #define LOG_ANDROID(T, MSG, ...) ((void)0)
981 extern enum LogLevel LogLevel
;
983 #define TRACEREF(...) do { \
984 if(LogLevel >= LogRef) \
985 AL_PRINT("(--)", __VA_ARGS__); \
988 #define TRACE(...) do { \
989 if(LogLevel >= LogTrace) \
990 AL_PRINT("(II)", __VA_ARGS__); \
991 LOG_ANDROID(ANDROID_LOG_DEBUG, __VA_ARGS__); \
994 #define WARN(...) do { \
995 if(LogLevel >= LogWarning) \
996 AL_PRINT("(WW)", __VA_ARGS__); \
997 LOG_ANDROID(ANDROID_LOG_WARN, __VA_ARGS__); \
1000 #define ERR(...) do { \
1001 if(LogLevel >= LogError) \
1002 AL_PRINT("(EE)", __VA_ARGS__); \
1003 LOG_ANDROID(ANDROID_LOG_ERROR, __VA_ARGS__); \
1007 extern ALint RTPrioLevel
;
1010 extern ALuint CPUCapFlags
;
1013 CPU_CAP_SSE2
= 1<<1,
1014 CPU_CAP_SSE3
= 1<<2,
1015 CPU_CAP_SSE4_1
= 1<<3,
1016 CPU_CAP_NEON
= 1<<4,
1019 void FillCPUCaps(ALuint capfilter
);
1021 vector_al_string
SearchDataFiles(const char *match
, const char *subdir
);
1023 /* Small hack to use a pointer-to-array type as a normal argument type.
1024 * Shouldn't be used directly. */
1025 typedef ALfloat ALfloatBUFFERSIZE
[BUFFERSIZE
];