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_FUMA_SOFT*/
46 #define ALC_SN3D_SOFT 0x1602
47 #define ALC_N3D_SOFT 0x1603
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(0[x]))
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
364 #define DEFAULT_OUTPUT_RATE (44100)
365 #define MIN_OUTPUT_RATE (8000)
368 /* Find the next power-of-2 for non-power-of-2 numbers. */
369 inline ALuint
NextPowerOf2(ALuint value
)
383 /** Round up a value to the next multiple. */
384 inline size_t RoundUp(size_t value
, size_t r
)
387 return value
- (value
%r
);
390 /* Fast float-to-int conversion. Assumes the FPU is already in round-to-zero
392 inline ALint
fastf2i(ALfloat f
)
396 #elif defined(_MSC_VER) && defined(_M_IX86)
406 /* Fast float-to-uint conversion. Assumes the FPU is already in round-to-zero
408 inline ALuint
fastf2u(ALfloat f
)
409 { return fastf2i(f
); }
418 ALCenum (*OpenPlayback
)(ALCdevice
*, const ALCchar
*);
419 void (*ClosePlayback
)(ALCdevice
*);
420 ALCboolean (*ResetPlayback
)(ALCdevice
*);
421 ALCboolean (*StartPlayback
)(ALCdevice
*);
422 void (*StopPlayback
)(ALCdevice
*);
424 ALCenum (*OpenCapture
)(ALCdevice
*, const ALCchar
*);
425 void (*CloseCapture
)(ALCdevice
*);
426 void (*StartCapture
)(ALCdevice
*);
427 void (*StopCapture
)(ALCdevice
*);
428 ALCenum (*CaptureSamples
)(ALCdevice
*, void*, ALCuint
);
429 ALCuint (*AvailableSamples
)(ALCdevice
*);
432 ALCboolean
alc_qsa_init(BackendFuncs
*func_list
);
433 void alc_qsa_deinit(void);
434 void alc_qsa_probe(enum DevProbe type
);
440 InverseDistanceClamped
= AL_INVERSE_DISTANCE_CLAMPED
,
441 LinearDistanceClamped
= AL_LINEAR_DISTANCE_CLAMPED
,
442 ExponentDistanceClamped
= AL_EXPONENT_DISTANCE_CLAMPED
,
443 InverseDistance
= AL_INVERSE_DISTANCE
,
444 LinearDistance
= AL_LINEAR_DISTANCE
,
445 ExponentDistance
= AL_EXPONENT_DISTANCE
,
446 DisableDistance
= AL_NONE
,
448 DefaultDistanceModel
= InverseDistanceClamped
494 DevFmtByte
= ALC_BYTE_SOFT
,
495 DevFmtUByte
= ALC_UNSIGNED_BYTE_SOFT
,
496 DevFmtShort
= ALC_SHORT_SOFT
,
497 DevFmtUShort
= ALC_UNSIGNED_SHORT_SOFT
,
498 DevFmtInt
= ALC_INT_SOFT
,
499 DevFmtUInt
= ALC_UNSIGNED_INT_SOFT
,
500 DevFmtFloat
= ALC_FLOAT_SOFT
,
502 DevFmtTypeDefault
= DevFmtFloat
504 enum DevFmtChannels
{
505 DevFmtMono
= ALC_MONO_SOFT
,
506 DevFmtStereo
= ALC_STEREO_SOFT
,
507 DevFmtQuad
= ALC_QUAD_SOFT
,
508 DevFmtX51
= ALC_5POINT1_SOFT
,
509 DevFmtX61
= ALC_6POINT1_SOFT
,
510 DevFmtX71
= ALC_7POINT1_SOFT
,
511 DevFmtAmbi3D
= ALC_BFORMAT3D_SOFT
,
513 /* Similar to 5.1, except using rear channels instead of sides */
514 DevFmtX51Rear
= 0x80000000,
516 DevFmtChannelsDefault
= DevFmtStereo
518 #define MAX_OUTPUT_CHANNELS (16)
520 ALsizei
BytesFromDevFmt(enum DevFmtType type
);
521 ALsizei
ChannelsFromDevFmt(enum DevFmtChannels chans
, ALsizei ambiorder
);
522 inline ALsizei
FrameSizeFromDevFmt(enum DevFmtChannels chans
, enum DevFmtType type
, ALsizei ambiorder
)
524 return ChannelsFromDevFmt(chans
, ambiorder
) * BytesFromDevFmt(type
);
528 AmbiLayout_FuMa
= ALC_FUMA_SOFT
, /* FuMa channel order */
529 AmbiLayout_ACN
= ALC_ACN_SOFT
, /* ACN channel order */
531 AmbiLayout_Default
= AmbiLayout_ACN
535 AmbiNorm_FuMa
= ALC_FUMA_SOFT
, /* FuMa normalization */
536 AmbiNorm_SN3D
= ALC_SN3D_SOFT
, /* SN3D normalization */
537 AmbiNorm_N3D
= ALC_N3D_SOFT
, /* N3D normalization */
539 AmbiNorm_Default
= AmbiNorm_SN3D
543 extern const struct EffectList
{
565 /* The maximum number of Ambisonics coefficients. For a given order (o), the
566 * size needed will be (o+1)**2, thus zero-order has 1, first-order has 4,
567 * second-order has 9, third-order has 16, and fourth-order has 25.
569 #define MAX_AMBI_ORDER 3
570 #define MAX_AMBI_COEFFS ((MAX_AMBI_ORDER+1) * (MAX_AMBI_ORDER+1))
572 /* A bitmask of ambisonic channels with height information. If none of these
573 * channels are used/needed, there's no height (e.g. with most surround sound
574 * speaker setups). This only specifies up to 4th order, which is the highest
575 * order a 32-bit mask value can specify (a 64-bit mask could handle up to 7th
576 * order). This is ACN ordering, with bit 0 being ACN 0, etc.
578 #define AMBI_PERIPHONIC_MASK (0xfe7ce4)
580 /* The maximum number of Ambisonic coefficients for 2D (non-periphonic)
581 * representation. This is 2 per each order above zero-order, plus 1 for zero-
582 * order. Or simply, o*2 + 1.
584 #define MAX_AMBI2D_COEFFS (MAX_AMBI_ORDER*2 + 1)
587 typedef ALfloat ChannelConfig
[MAX_AMBI_COEFFS
];
588 typedef struct BFChannelConfig
{
593 typedef union AmbiConfig
{
594 /* Ambisonic coefficients for mixing to the dry buffer. */
595 ChannelConfig Coeffs
[MAX_OUTPUT_CHANNELS
];
596 /* Coefficient channel mapping for mixing to the dry buffer. */
597 BFChannelConfig Map
[MAX_OUTPUT_CHANNELS
];
601 #define HRTF_HISTORY_BITS (6)
602 #define HRTF_HISTORY_LENGTH (1<<HRTF_HISTORY_BITS)
603 #define HRTF_HISTORY_MASK (HRTF_HISTORY_LENGTH-1)
605 #define HRIR_BITS (7)
606 #define HRIR_LENGTH (1<<HRIR_BITS)
607 #define HRIR_MASK (HRIR_LENGTH-1)
609 typedef struct HrtfState
{
610 alignas(16) ALfloat History
[HRTF_HISTORY_LENGTH
];
611 alignas(16) ALfloat Values
[HRIR_LENGTH
][2];
614 typedef struct HrtfParams
{
615 alignas(16) ALfloat Coeffs
[HRIR_LENGTH
][2];
620 typedef struct DirectHrtfState
{
621 /* HRTF filter state for dry buffer content */
625 alignas(16) ALfloat Values
[HRIR_LENGTH
][2];
626 alignas(16) ALfloat Coeffs
[HRIR_LENGTH
][2];
630 typedef struct EnumeratedHrtf
{
633 struct HrtfEntry
*hrtf
;
635 TYPEDEF_VECTOR(EnumeratedHrtf
, vector_EnumeratedHrtf
)
638 /* Maximum delay in samples for speaker distance compensation. */
639 #define MAX_DELAY_LENGTH 1024
641 typedef struct DistanceComp
{
643 ALsizei Length
; /* Valid range is [0...MAX_DELAY_LENGTH). */
647 /* Size for temporary storage of buffer data, in ALfloats. Larger values need
648 * more memory, while smaller values may need more iterations. The value needs
649 * to be a sensible size, however, as it constrains the max stepping value used
650 * for mixing, as well as the maximum number of samples per mixing iteration.
652 #define BUFFERSIZE 2048
654 struct ALCdevice_struct
658 ALCboolean Connected
;
659 enum DeviceType Type
;
664 enum DevFmtChannels FmtChans
;
665 enum DevFmtType FmtType
;
666 ALboolean IsHeadphones
;
668 /* For DevFmtAmbi* output only, specifies the channel order and
671 enum AmbiLayout AmbiLayout
;
672 enum AmbiNorm AmbiScale
;
674 al_string DeviceName
;
676 ATOMIC(ALCenum
) LastError
;
678 // Maximum number of sources that can be created
680 // Maximum number of slots that can be created
681 ALuint AuxiliaryEffectSlotMax
;
683 ALCuint NumMonoSources
;
684 ALCuint NumStereoSources
;
687 // Map of Buffers for this device
690 // Map of Effects for this device
693 // Map of Filters for this device
696 /* HRTF state and info */
697 DirectHrtfState
*Hrtf
;
699 struct Hrtf
*HrtfHandle
;
700 vector_EnumeratedHrtf HrtfList
;
703 /* UHJ encoder state */
704 struct Uhj2Encoder
*Uhj_Encoder
;
706 /* High quality Ambisonic decoder */
707 struct BFormatDec
*AmbiDecoder
;
709 /* Stereo-to-binaural filter */
712 /* First-order ambisonic upsampler for higher-order output */
713 struct AmbiUpsampler
*AmbiUp
;
715 /* Rendering mode. */
716 enum RenderMode Render_Mode
;
724 /* Temp storage used for each source when mixing. */
725 alignas(16) ALfloat SourceData
[BUFFERSIZE
];
726 alignas(16) ALfloat ResampledData
[BUFFERSIZE
];
727 alignas(16) ALfloat FilteredData
[BUFFERSIZE
];
728 alignas(16) ALfloat NFCtrlData
[BUFFERSIZE
];
730 /* The "dry" path corresponds to the main output. */
733 /* Number of coefficients in each Ambi.Coeffs to mix together (4 for
734 * first-order, 9 for second-order, etc). If the count is 0, Ambi.Map
735 * is used instead to map each output to a coefficient index.
739 ALfloat (*Buffer
)[BUFFERSIZE
];
741 ALsizei NumChannelsPerOrder
[MAX_AMBI_ORDER
+1];
744 /* First-order ambisonics output, to be upsampled to the dry buffer if different. */
747 /* Will only be 4 or 0. */
750 ALfloat (*Buffer
)[BUFFERSIZE
];
754 /* "Real" output, which will be written to the device buffer. May alias the
758 enum Channel ChannelName
[MAX_OUTPUT_CHANNELS
];
760 ALfloat (*Buffer
)[BUFFERSIZE
];
764 /* The average speaker distance as determined by the ambdec configuration
765 * (or alternatively, by the NFC-HOA reference delay). Only used for NFC.
767 ALfloat AvgSpeakerDist
;
769 /* Delay buffers used to compensate for speaker distances. */
770 DistanceComp ChannelDelay
[MAX_OUTPUT_CHANNELS
];
772 /* Running count of the mixer invocations, in 31.1 fixed point. This
773 * actually increments *twice* when mixing, first at the start and then at
774 * the end, so the bottom bit indicates if the device is currently mixing
775 * and the upper bits indicates how many mixes have been done.
779 /* Default effect slot */
780 struct ALeffectslot
*DefaultSlot
;
782 // Contexts created on this device
783 ATOMIC(ALCcontext
*) ContextList
;
786 struct ALCbackend
*Backend
;
788 void *ExtraData
; // For the backend's use
790 ALCdevice
*volatile next
;
792 /* Memory space used by the default slot (Playback devices only) */
793 alignas(16) ALCbyte _slot_mem
[];
796 // Frequency was requested by the app or config file
797 #define DEVICE_FREQUENCY_REQUEST (1u<<1)
798 // Channel configuration was requested by the config file
799 #define DEVICE_CHANNELS_REQUEST (1u<<2)
800 // Sample type was requested by the config file
801 #define DEVICE_SAMPLE_TYPE_REQUEST (1u<<3)
803 // Specifies if the DSP is paused at user request
804 #define DEVICE_PAUSED (1u<<30)
806 // Specifies if the device is currently running
807 #define DEVICE_RUNNING (1u<<31)
810 /* Nanosecond resolution for the device clock time. */
811 #define DEVICE_CLOCK_RES U64(1000000000)
814 /* Must be less than 15 characters (16 including terminating null) for
815 * compatibility with pthread_setname_np limitations. */
816 #define MIXER_THREAD_NAME "alsoft-mixer"
818 #define RECORD_THREAD_NAME "alsoft-record"
821 struct ALCcontext_struct
{
824 struct ALlistener
*Listener
;
827 UIntMap EffectSlotMap
;
829 ATOMIC(ALenum
) LastError
;
831 enum DistanceModel DistanceModel
;
832 ALboolean SourceDistanceModel
;
834 ALfloat DopplerFactor
;
835 ALfloat DopplerVelocity
;
836 ALfloat SpeedOfSound
;
837 ATOMIC(ALenum
) DeferUpdates
;
841 /* Counter for the pre-mixing updates, in 31.1 fixed point (lowest bit
842 * indicates if updates are currently happening).
844 RefCount UpdateCount
;
845 ATOMIC(ALenum
) HoldUpdates
;
849 struct ALvoice
**Voices
;
853 ATOMIC(struct ALeffectslotArray
*) ActiveAuxSlots
;
856 const ALCchar
*ExtensionList
;
858 ALCcontext
*volatile next
;
860 /* Memory space used by the listener */
861 alignas(16) ALCbyte _listener_mem
[];
864 ALCcontext
*GetContextRef(void);
866 void ALCcontext_IncRef(ALCcontext
*context
);
867 void ALCcontext_DecRef(ALCcontext
*context
);
869 void AllocateVoices(ALCcontext
*context
, ALsizei num_voices
, ALsizei old_sends
);
871 void AppendAllDevicesList(const ALCchar
*name
);
872 void AppendCaptureDeviceList(const ALCchar
*name
);
874 void ALCdevice_Lock(ALCdevice
*device
);
875 void ALCdevice_Unlock(ALCdevice
*device
);
877 void ALCcontext_DeferUpdates(ALCcontext
*context
);
878 void ALCcontext_ProcessUpdates(ALCcontext
*context
);
883 DERIVE_FROM_TYPE(fenv_t
);
891 void SetMixerFPUMode(FPUCtl
*ctl
);
892 void RestoreFPUMode(const FPUCtl
*ctl
);
895 typedef struct ll_ringbuffer ll_ringbuffer_t
;
896 typedef struct ll_ringbuffer_data
{
899 } ll_ringbuffer_data_t
;
900 ll_ringbuffer_t
*ll_ringbuffer_create(size_t sz
, size_t elem_sz
);
901 void ll_ringbuffer_free(ll_ringbuffer_t
*rb
);
902 void ll_ringbuffer_get_read_vector(const ll_ringbuffer_t
*rb
, ll_ringbuffer_data_t
*vec
);
903 void ll_ringbuffer_get_write_vector(const ll_ringbuffer_t
*rb
, ll_ringbuffer_data_t
*vec
);
904 size_t ll_ringbuffer_read(ll_ringbuffer_t
*rb
, char *dest
, size_t cnt
);
905 size_t ll_ringbuffer_peek(ll_ringbuffer_t
*rb
, char *dest
, size_t cnt
);
906 void ll_ringbuffer_read_advance(ll_ringbuffer_t
*rb
, size_t cnt
);
907 size_t ll_ringbuffer_read_space(const ll_ringbuffer_t
*rb
);
908 int ll_ringbuffer_mlock(ll_ringbuffer_t
*rb
);
909 void ll_ringbuffer_reset(ll_ringbuffer_t
*rb
);
910 size_t ll_ringbuffer_write(ll_ringbuffer_t
*rb
, const char *src
, size_t cnt
);
911 void ll_ringbuffer_write_advance(ll_ringbuffer_t
*rb
, size_t cnt
);
912 size_t ll_ringbuffer_write_space(const ll_ringbuffer_t
*rb
);
914 void ReadALConfig(void);
915 void FreeALConfig(void);
916 int ConfigValueExists(const char *devName
, const char *blockName
, const char *keyName
);
917 const char *GetConfigValue(const char *devName
, const char *blockName
, const char *keyName
, const char *def
);
918 int GetConfigValueBool(const char *devName
, const char *blockName
, const char *keyName
, int def
);
919 int ConfigValueStr(const char *devName
, const char *blockName
, const char *keyName
, const char **ret
);
920 int ConfigValueInt(const char *devName
, const char *blockName
, const char *keyName
, int *ret
);
921 int ConfigValueUInt(const char *devName
, const char *blockName
, const char *keyName
, unsigned int *ret
);
922 int ConfigValueFloat(const char *devName
, const char *blockName
, const char *keyName
, float *ret
);
923 int ConfigValueBool(const char *devName
, const char *blockName
, const char *keyName
, int *ret
);
925 void SetRTPriority(void);
927 void SetDefaultChannelOrder(ALCdevice
*device
);
928 void SetDefaultWFXChannelOrder(ALCdevice
*device
);
930 const ALCchar
*DevFmtTypeString(enum DevFmtType type
);
931 const ALCchar
*DevFmtChannelsString(enum DevFmtChannels chans
);
934 * GetChannelIdxByName
936 * Returns the index for the given channel name (e.g. FrontCenter), or -1 if it
939 inline ALint
GetChannelIndex(const enum Channel names
[MAX_OUTPUT_CHANNELS
], enum Channel chan
)
942 for(i
= 0;i
< MAX_OUTPUT_CHANNELS
;i
++)
949 #define GetChannelIdxByName(x, c) GetChannelIndex((x).ChannelName, (c))
951 extern FILE *LogFile
;
953 #if defined(__GNUC__) && !defined(_WIN32) && !defined(IN_IDE_PARSER)
954 #define AL_PRINT(T, MSG, ...) fprintf(LogFile, "AL lib: %s %s: "MSG, T, __FUNCTION__ , ## __VA_ARGS__)
956 void al_print(const char *type
, const char *func
, const char *fmt
, ...) DECL_FORMAT(printf
, 3,4);
957 #define AL_PRINT(T, ...) al_print((T), __FUNCTION__, __VA_ARGS__)
961 #include <android/log.h>
962 #define LOG_ANDROID(T, MSG, ...) __android_log_print(T, "openal", "AL lib: %s: "MSG, __FUNCTION__ , ## __VA_ARGS__)
964 #define LOG_ANDROID(T, MSG, ...) ((void)0)
974 extern enum LogLevel LogLevel
;
976 #define TRACEREF(...) do { \
977 if(LogLevel >= LogRef) \
978 AL_PRINT("(--)", __VA_ARGS__); \
981 #define TRACE(...) do { \
982 if(LogLevel >= LogTrace) \
983 AL_PRINT("(II)", __VA_ARGS__); \
984 LOG_ANDROID(ANDROID_LOG_DEBUG, __VA_ARGS__); \
987 #define WARN(...) do { \
988 if(LogLevel >= LogWarning) \
989 AL_PRINT("(WW)", __VA_ARGS__); \
990 LOG_ANDROID(ANDROID_LOG_WARN, __VA_ARGS__); \
993 #define ERR(...) do { \
994 if(LogLevel >= LogError) \
995 AL_PRINT("(EE)", __VA_ARGS__); \
996 LOG_ANDROID(ANDROID_LOG_ERROR, __VA_ARGS__); \
1000 extern ALint RTPrioLevel
;
1003 extern ALuint CPUCapFlags
;
1006 CPU_CAP_SSE2
= 1<<1,
1007 CPU_CAP_SSE3
= 1<<2,
1008 CPU_CAP_SSE4_1
= 1<<3,
1009 CPU_CAP_NEON
= 1<<4,
1012 void FillCPUCaps(ALuint capfilter
);
1014 vector_al_string
SearchDataFiles(const char *match
, const char *subdir
);
1016 /* Small hack to use a pointer-to-array types as a normal argument type.
1017 * Shouldn't be used directly.
1019 typedef ALfloat ALfloatBUFFERSIZE
[BUFFERSIZE
];
1020 typedef ALfloat ALfloat2
[2];