33 #include "static_assert.h"
44 #ifndef ALC_SOFT_device_clock
45 #define ALC_SOFT_device_clock 1
46 typedef int64_t ALCint64SOFT
;
47 typedef uint64_t ALCuint64SOFT
;
48 #define ALC_DEVICE_CLOCK_SOFT 0x1600
49 #define ALC_DEVICE_LATENCY_SOFT 0x1601
50 #define ALC_DEVICE_CLOCK_LATENCY_SOFT 0x1602
51 typedef void (ALC_APIENTRY
*LPALCGETINTEGER64VSOFT
)(ALCdevice
*device
, ALCenum pname
, ALsizei size
, ALCint64SOFT
*values
);
52 #ifdef AL_ALEXT_PROTOTYPES
53 ALC_API
void ALC_APIENTRY
alcGetInteger64vSOFT(ALCdevice
*device
, ALCenum pname
, ALsizei size
, ALCint64SOFT
*values
);
57 #ifndef AL_SOFT_buffer_samples2
58 #define AL_SOFT_buffer_samples2 1
59 /* Channel configurations */
60 #define AL_MONO_SOFT 0x1500
61 #define AL_STEREO_SOFT 0x1501
62 #define AL_REAR_SOFT 0x1502
63 #define AL_QUAD_SOFT 0x1503
64 #define AL_5POINT1_SOFT 0x1504
65 #define AL_6POINT1_SOFT 0x1505
66 #define AL_7POINT1_SOFT 0x1506
67 #define AL_BFORMAT2D_SOFT 0x1507
68 #define AL_BFORMAT3D_SOFT 0x1508
71 #define AL_BYTE_SOFT 0x1400
72 #define AL_UNSIGNED_BYTE_SOFT 0x1401
73 #define AL_SHORT_SOFT 0x1402
74 #define AL_UNSIGNED_SHORT_SOFT 0x1403
75 #define AL_INT_SOFT 0x1404
76 #define AL_UNSIGNED_INT_SOFT 0x1405
77 #define AL_FLOAT_SOFT 0x1406
78 #define AL_DOUBLE_SOFT 0x1407
79 #define AL_BYTE3_SOFT 0x1408
80 #define AL_UNSIGNED_BYTE3_SOFT 0x1409
81 #define AL_MULAW_SOFT 0x140A
84 #define AL_MONO8_SOFT 0x1100
85 #define AL_MONO16_SOFT 0x1101
86 #define AL_MONO32F_SOFT 0x10010
87 #define AL_STEREO8_SOFT 0x1102
88 #define AL_STEREO16_SOFT 0x1103
89 #define AL_STEREO32F_SOFT 0x10011
90 #define AL_QUAD8_SOFT 0x1204
91 #define AL_QUAD16_SOFT 0x1205
92 #define AL_QUAD32F_SOFT 0x1206
93 #define AL_REAR8_SOFT 0x1207
94 #define AL_REAR16_SOFT 0x1208
95 #define AL_REAR32F_SOFT 0x1209
96 #define AL_5POINT1_8_SOFT 0x120A
97 #define AL_5POINT1_16_SOFT 0x120B
98 #define AL_5POINT1_32F_SOFT 0x120C
99 #define AL_6POINT1_8_SOFT 0x120D
100 #define AL_6POINT1_16_SOFT 0x120E
101 #define AL_6POINT1_32F_SOFT 0x120F
102 #define AL_7POINT1_8_SOFT 0x1210
103 #define AL_7POINT1_16_SOFT 0x1211
104 #define AL_7POINT1_32F_SOFT 0x1212
105 #define AL_BFORMAT2D_8_SOFT 0x20021
106 #define AL_BFORMAT2D_16_SOFT 0x20022
107 #define AL_BFORMAT2D_32F_SOFT 0x20023
108 #define AL_BFORMAT3D_8_SOFT 0x20031
109 #define AL_BFORMAT3D_16_SOFT 0x20032
110 #define AL_BFORMAT3D_32F_SOFT 0x20033
112 /* Buffer attributes */
113 #define AL_INTERNAL_FORMAT_SOFT 0x2008
114 #define AL_BYTE_LENGTH_SOFT 0x2009
115 #define AL_SAMPLE_LENGTH_SOFT 0x200A
116 #define AL_SEC_LENGTH_SOFT 0x200B
119 typedef void (AL_APIENTRY
*LPALBUFFERSAMPLESSOFT
)(ALuint
,ALuint
,ALenum
,ALsizei
,ALenum
,ALenum
,const ALvoid
*);
120 typedef void (AL_APIENTRY
*LPALGETBUFFERSAMPLESSOFT
)(ALuint
,ALsizei
,ALsizei
,ALenum
,ALenum
,ALvoid
*);
121 typedef ALboolean (AL_APIENTRY
*LPALISBUFFERFORMATSUPPORTEDSOFT
)(ALenum
);
122 #ifdef AL_ALEXT_PROTOTYPES
123 AL_API
void AL_APIENTRY
alBufferSamplesSOFT(ALuint buffer
, ALuint samplerate
, ALenum internalformat
, ALsizei samples
, ALenum channels
, ALenum type
, const ALvoid
*data
);
124 AL_API
void AL_APIENTRY
alGetBufferSamplesSOFT(ALuint buffer
, ALsizei offset
, ALsizei samples
, ALenum channels
, ALenum type
, ALvoid
*data
);
125 AL_API ALboolean AL_APIENTRY
alIsBufferFormatSupportedSOFT(ALenum format
);
132 /* Because of a long-standing deficiency in C, you're not allowed to implicitly
133 * cast a pointer-to-type-array to a pointer-to-const-type-array. For example,
136 * const int (*cptr)[10] = ptr;
138 * is not allowed and most compilers will generate noisy warnings about
139 * incompatible types, even though it just makes the array elements const.
140 * Clang will allow it if you make the array type a typedef, like this:
142 * typedef int int10[10];
144 * const int10 *cptr = ptr;
146 * however GCC does not and still issues the incompatible type warning. The
147 * "proper" way to fix it is to add an explicit cast for the constified type,
148 * but that removes the vast majority of otherwise useful type-checking you'd
149 * get, and runs the risk of improper casts if types are later changed. Leaving
150 * it non-const can also be an issue if you use it as a function parameter, and
151 * happen to have a const type as input (and also reduce the capabilities of
152 * the compiler to better optimize the function).
154 * So to work around the problem, we use a macro. The macro first assigns the
155 * incoming variable to the specified non-const type to ensure it's the correct
156 * type, then casts the variable as the desired constified type. Very ugly, but
157 * I'd rather not have hundreds of lines of warnings because I want to tell the
158 * compiler that some array(s) can't be changed by the code, or have lots of
161 #define SAFE_CONST(T, var) __extension__({ \
166 /* Non-GNU-compatible compilers have to use a straight cast with no extra
167 * checks, due to the lack of multi-statement expressions.
169 #define SAFE_CONST(T, var) ((const T)(var))
173 typedef ALint64SOFT ALint64
;
174 typedef ALuint64SOFT ALuint64
;
177 #if defined(_MSC_VER)
178 #define U64(x) ((ALuint64)(x##ui64))
179 #elif SIZEOF_LONG == 8
180 #define U64(x) ((ALuint64)(x##ul))
181 #elif SIZEOF_LONG_LONG == 8
182 #define U64(x) ((ALuint64)(x##ull))
187 #define UINT64_MAX U64(18446744073709551615)
191 #if defined(__cplusplus)
193 #elif defined(__GNUC__)
194 #define UNUSED(x) UNUSED_##x __attribute__((unused))
195 #elif defined(__LCLINT__)
196 #define UNUSED(x) /*@unused@*/ x
203 #define DECL_FORMAT(x, y, z) __attribute__((format(x, (y), (z))))
205 #define DECL_FORMAT(x, y, z)
208 #if defined(__GNUC__) && defined(__i386__)
209 /* force_align_arg_pointer is required for proper function arguments aligning
210 * when SSE code is used. Some systems (Windows, QNX) do not guarantee our
211 * thread functions will be properly aligned on the stack, even though GCC may
212 * generate code with the assumption that it is. */
213 #define FORCE_ALIGN __attribute__((force_align_arg_pointer))
219 #define DECL_VLA(T, _name, _size) T _name[(_size)]
221 #define DECL_VLA(T, _name, _size) T *_name = alloca((_size) * sizeof(T))
226 #define PATH_MAX MAX_PATH
228 #define PATH_MAX 4096
235 ALubyte b
[sizeof(ALuint
)];
236 } EndianTest
= { 1 };
237 #define IS_LITTLE_ENDIAN (EndianTest.b[0] == 1)
239 #define COUNTOF(x) (sizeof((x))/sizeof((x)[0]))
242 #define DERIVE_FROM_TYPE(t) t t##_parent
243 #define STATIC_CAST(to, obj) (&(obj)->to##_parent)
245 #define STATIC_UPCAST(to, from, obj) __extension__({ \
246 static_assert(__builtin_types_compatible_p(from, __typeof(*(obj))), \
247 "Invalid upcast object from type"); \
248 (to*)((char*)(obj) - offsetof(to, from##_parent)); \
251 #define STATIC_UPCAST(to, from, obj) ((to*)((char*)(obj) - offsetof(to, from##_parent)))
254 #define DECLARE_FORWARD(T1, T2, rettype, func) \
255 rettype T1##_##func(T1 *obj) \
256 { return T2##_##func(STATIC_CAST(T2, obj)); }
258 #define DECLARE_FORWARD1(T1, T2, rettype, func, argtype1) \
259 rettype T1##_##func(T1 *obj, argtype1 a) \
260 { return T2##_##func(STATIC_CAST(T2, obj), a); }
262 #define DECLARE_FORWARD2(T1, T2, rettype, func, argtype1, argtype2) \
263 rettype T1##_##func(T1 *obj, argtype1 a, argtype2 b) \
264 { return T2##_##func(STATIC_CAST(T2, obj), a, b); }
266 #define DECLARE_FORWARD3(T1, T2, rettype, func, argtype1, argtype2, argtype3) \
267 rettype T1##_##func(T1 *obj, argtype1 a, argtype2 b, argtype3 c) \
268 { return T2##_##func(STATIC_CAST(T2, obj), a, b, c); }
271 #define GET_VTABLE1(T1) (&(T1##_vtable))
272 #define GET_VTABLE2(T1, T2) (&(T1##_##T2##_vtable))
274 #define SET_VTABLE1(T1, obj) ((obj)->vtbl = GET_VTABLE1(T1))
275 #define SET_VTABLE2(T1, T2, obj) (STATIC_CAST(T2, obj)->vtbl = GET_VTABLE2(T1, T2))
277 #define DECLARE_THUNK(T1, T2, rettype, func) \
278 static rettype T1##_##T2##_##func(T2 *obj) \
279 { return T1##_##func(STATIC_UPCAST(T1, T2, obj)); }
281 #define DECLARE_THUNK1(T1, T2, rettype, func, argtype1) \
282 static rettype T1##_##T2##_##func(T2 *obj, argtype1 a) \
283 { return T1##_##func(STATIC_UPCAST(T1, T2, obj), a); }
285 #define DECLARE_THUNK2(T1, T2, rettype, func, argtype1, argtype2) \
286 static rettype T1##_##T2##_##func(T2 *obj, argtype1 a, argtype2 b) \
287 { return T1##_##func(STATIC_UPCAST(T1, T2, obj), a, b); }
289 #define DECLARE_THUNK3(T1, T2, rettype, func, argtype1, argtype2, argtype3) \
290 static rettype T1##_##T2##_##func(T2 *obj, argtype1 a, argtype2 b, argtype3 c) \
291 { return T1##_##func(STATIC_UPCAST(T1, T2, obj), a, b, c); }
293 #define DECLARE_THUNK4(T1, T2, rettype, func, argtype1, argtype2, argtype3, argtype4) \
294 static rettype T1##_##T2##_##func(T2 *obj, argtype1 a, argtype2 b, argtype3 c, argtype4 d) \
295 { return T1##_##func(STATIC_UPCAST(T1, T2, obj), a, b, c, d); }
297 #define DECLARE_DEFAULT_ALLOCATORS(T) \
298 static void* T##_New(size_t size) { return al_malloc(16, size); } \
299 static void T##_Delete(void *ptr) { al_free(ptr); }
301 /* Helper to extract an argument list for VCALL. Not used directly. */
302 #define EXTRACT_VCALL_ARGS(...) __VA_ARGS__))
304 /* Call a "virtual" method on an object, with arguments. */
305 #define V(obj, func) ((obj)->vtbl->func((obj), EXTRACT_VCALL_ARGS
306 /* Call a "virtual" method on an object, with no arguments. */
307 #define V0(obj, func) ((obj)->vtbl->func((obj) EXTRACT_VCALL_ARGS
309 #define DELETE_OBJ(obj) do { \
312 V0((obj),Destruct)(); \
313 V0((obj),Delete)(); \
318 #define EXTRACT_NEW_ARGS(...) __VA_ARGS__); \
322 #define NEW_OBJ(_res, T) do { \
323 _res = T##_New(sizeof(T)); \
326 memset(_res, 0, sizeof(T)); \
327 T##_Construct(_res, EXTRACT_NEW_ARGS
328 #define NEW_OBJ0(_res, T) do { \
329 _res = T##_New(sizeof(T)); \
332 memset(_res, 0, sizeof(T)); \
333 T##_Construct(_res EXTRACT_NEW_ARGS
343 #define DEFAULT_OUTPUT_RATE (44100)
344 #define MIN_OUTPUT_RATE (8000)
347 /* Find the next power-of-2 for non-power-of-2 numbers. */
348 inline ALuint
NextPowerOf2(ALuint value
)
362 /* Fast float-to-int conversion. Assumes the FPU is already in round-to-zero
364 inline ALint
fastf2i(ALfloat f
)
368 #elif defined(_MSC_VER) && defined(_M_IX86)
378 /* Fast float-to-uint conversion. Assumes the FPU is already in round-to-zero
380 inline ALuint
fastf2u(ALfloat f
)
381 { return fastf2i(f
); }
390 ALCenum (*OpenPlayback
)(ALCdevice
*, const ALCchar
*);
391 void (*ClosePlayback
)(ALCdevice
*);
392 ALCboolean (*ResetPlayback
)(ALCdevice
*);
393 ALCboolean (*StartPlayback
)(ALCdevice
*);
394 void (*StopPlayback
)(ALCdevice
*);
396 ALCenum (*OpenCapture
)(ALCdevice
*, const ALCchar
*);
397 void (*CloseCapture
)(ALCdevice
*);
398 void (*StartCapture
)(ALCdevice
*);
399 void (*StopCapture
)(ALCdevice
*);
400 ALCenum (*CaptureSamples
)(ALCdevice
*, void*, ALCuint
);
401 ALCuint (*AvailableSamples
)(ALCdevice
*);
404 ALCboolean
alc_sndio_init(BackendFuncs
*func_list
);
405 void alc_sndio_deinit(void);
406 void alc_sndio_probe(enum DevProbe type
);
407 ALCboolean
alc_ca_init(BackendFuncs
*func_list
);
408 void alc_ca_deinit(void);
409 void alc_ca_probe(enum DevProbe type
);
410 ALCboolean
alc_opensl_init(BackendFuncs
*func_list
);
411 void alc_opensl_deinit(void);
412 void alc_opensl_probe(enum DevProbe type
);
413 ALCboolean
alc_qsa_init(BackendFuncs
*func_list
);
414 void alc_qsa_deinit(void);
415 void alc_qsa_probe(enum DevProbe type
);
421 InverseDistanceClamped
= AL_INVERSE_DISTANCE_CLAMPED
,
422 LinearDistanceClamped
= AL_LINEAR_DISTANCE_CLAMPED
,
423 ExponentDistanceClamped
= AL_EXPONENT_DISTANCE_CLAMPED
,
424 InverseDistance
= AL_INVERSE_DISTANCE
,
425 LinearDistance
= AL_LINEAR_DISTANCE
,
426 ExponentDistance
= AL_EXPONENT_DISTANCE
,
427 DisableDistance
= AL_NONE
,
429 DefaultDistanceModel
= InverseDistanceClamped
475 DevFmtByte
= ALC_BYTE_SOFT
,
476 DevFmtUByte
= ALC_UNSIGNED_BYTE_SOFT
,
477 DevFmtShort
= ALC_SHORT_SOFT
,
478 DevFmtUShort
= ALC_UNSIGNED_SHORT_SOFT
,
479 DevFmtInt
= ALC_INT_SOFT
,
480 DevFmtUInt
= ALC_UNSIGNED_INT_SOFT
,
481 DevFmtFloat
= ALC_FLOAT_SOFT
,
483 DevFmtTypeDefault
= DevFmtFloat
485 enum DevFmtChannels
{
486 DevFmtMono
= ALC_MONO_SOFT
,
487 DevFmtStereo
= ALC_STEREO_SOFT
,
488 DevFmtQuad
= ALC_QUAD_SOFT
,
489 DevFmtX51
= ALC_5POINT1_SOFT
,
490 DevFmtX61
= ALC_6POINT1_SOFT
,
491 DevFmtX71
= ALC_7POINT1_SOFT
,
493 /* Similar to 5.1, except using rear channels instead of sides */
494 DevFmtX51Rear
= 0x80000000,
496 /* Ambisonic formats should be kept together */
501 DevFmtChannelsDefault
= DevFmtStereo
503 #define MAX_OUTPUT_CHANNELS (16)
505 ALuint
BytesFromDevFmt(enum DevFmtType type
);
506 ALuint
ChannelsFromDevFmt(enum DevFmtChannels chans
);
507 inline ALuint
FrameSizeFromDevFmt(enum DevFmtChannels chans
, enum DevFmtType type
)
509 return ChannelsFromDevFmt(chans
) * BytesFromDevFmt(type
);
513 AmbiFormat_FuMa
, /* FuMa channel order and normalization */
514 AmbiFormat_ACN_SN3D
, /* ACN channel order and SN3D normalization */
515 AmbiFormat_ACN_N3D
, /* ACN channel order and N3D normalization */
517 AmbiFormat_Default
= AmbiFormat_ACN_SN3D
521 extern const struct EffectList
{
543 /* The maximum number of Ambisonics coefficients. For a given order (o), the
544 * size needed will be (o+1)**2, thus zero-order has 1, first-order has 4,
545 * second-order has 9, third-order has 16, and fourth-order has 25.
547 #define MAX_AMBI_ORDER 3
548 #define MAX_AMBI_COEFFS ((MAX_AMBI_ORDER+1) * (MAX_AMBI_ORDER+1))
550 /* A bitmask of ambisonic channels with height information. If none of these
551 * channels are used/needed, there's no height (e.g. with most surround sound
552 * speaker setups). This only specifies up to 4th order, which is the highest
553 * order a 32-bit mask value can specify (a 64-bit mask could handle up to 7th
554 * order). This is ACN ordering, with bit 0 being ACN 0, etc.
556 #define AMBI_PERIPHONIC_MASK (0xfe7ce4)
558 /* The maximum number of Ambisonic coefficients for 2D (non-periphonic)
559 * representation. This is 2 per each order above zero-order, plus 1 for zero-
560 * order. Or simply, o*2 + 1.
562 #define MAX_AMBI2D_COEFFS (MAX_AMBI_ORDER*2 + 1)
565 typedef ALfloat ChannelConfig
[MAX_AMBI_COEFFS
];
566 typedef struct BFChannelConfig
{
571 typedef union AmbiConfig
{
572 /* Ambisonic coefficients for mixing to the dry buffer. */
573 ChannelConfig Coeffs
[MAX_OUTPUT_CHANNELS
];
574 /* Coefficient channel mapping for mixing to the dry buffer. */
575 BFChannelConfig Map
[MAX_OUTPUT_CHANNELS
];
579 #define HRTF_HISTORY_BITS (6)
580 #define HRTF_HISTORY_LENGTH (1<<HRTF_HISTORY_BITS)
581 #define HRTF_HISTORY_MASK (HRTF_HISTORY_LENGTH-1)
583 typedef struct HrtfState
{
584 alignas(16) ALfloat History
[HRTF_HISTORY_LENGTH
];
585 alignas(16) ALfloat Values
[HRIR_LENGTH
][2];
588 typedef struct HrtfParams
{
589 alignas(16) ALfloat Coeffs
[HRIR_LENGTH
][2];
594 /* Size for temporary storage of buffer data, in ALfloats. Larger values need
595 * more memory, while smaller values may need more iterations. The value needs
596 * to be a sensible size, however, as it constrains the max stepping value used
597 * for mixing, as well as the maximum number of samples per mixing iteration.
599 #define BUFFERSIZE (2048u)
601 struct ALCdevice_struct
605 ALCboolean Connected
;
606 enum DeviceType Type
;
611 enum DevFmtChannels FmtChans
;
612 enum DevFmtType FmtType
;
613 ALboolean IsHeadphones
;
614 /* For DevFmtAmbi* output only, specifies the channel order and
617 enum AmbiFormat AmbiFmt
;
619 al_string DeviceName
;
621 ATOMIC(ALCenum
) LastError
;
623 // Maximum number of sources that can be created
625 // Maximum number of slots that can be created
626 ALuint AuxiliaryEffectSlotMax
;
628 ALCuint NumMonoSources
;
629 ALCuint NumStereoSources
;
632 // Map of Buffers for this device
635 // Map of Effects for this device
638 // Map of Filters for this device
641 /* HRTF filter tables */
643 vector_HrtfEntry List
;
646 const struct Hrtf
*Handle
;
648 /* HRTF filter state for dry buffer content */
649 alignas(16) ALfloat Values
[4][HRIR_LENGTH
][2];
650 alignas(16) ALfloat Coeffs
[4][HRIR_LENGTH
][2];
655 /* UHJ encoder state */
656 struct Uhj2Encoder
*Uhj_Encoder
;
658 /* High quality Ambisonic decoder */
659 struct BFormatDec
*AmbiDecoder
;
661 /* Stereo-to-binaural filter */
664 /* First-order ambisonic upsampler for higher-order output */
665 struct AmbiUpsampler
*AmbiUp
;
667 /* Rendering mode. */
668 enum RenderMode Render_Mode
;
676 /* Temp storage used for each source when mixing. */
677 alignas(16) ALfloat SourceData
[BUFFERSIZE
];
678 alignas(16) ALfloat ResampledData
[BUFFERSIZE
];
679 alignas(16) ALfloat FilteredData
[BUFFERSIZE
];
681 /* The "dry" path corresponds to the main output. */
684 /* Number of coefficients in each Ambi.Coeffs to mix together (4 for
685 * first-order, 9 for second-order, etc). If the count is 0, Ambi.Map
686 * is used instead to map each output to a coefficient index.
690 ALfloat (*Buffer
)[BUFFERSIZE
];
694 /* First-order ambisonics output, to be upsampled to the dry buffer if different. */
697 /* Will only be 4 or 0. */
700 ALfloat (*Buffer
)[BUFFERSIZE
];
704 /* "Real" output, which will be written to the device buffer. May alias the
708 enum Channel ChannelName
[MAX_OUTPUT_CHANNELS
];
710 ALfloat (*Buffer
)[BUFFERSIZE
];
714 /* Running count of the mixer invocations, in 31.1 fixed point. This
715 * actually increments *twice* when mixing, first at the start and then at
716 * the end, so the bottom bit indicates if the device is currently mixing
717 * and the upper bits indicates how many mixes have been done.
721 /* Default effect slot */
722 struct ALeffectslot
*DefaultSlot
;
724 // Contexts created on this device
725 ATOMIC(ALCcontext
*) ContextList
;
728 struct ALCbackend
*Backend
;
730 void *ExtraData
; // For the backend's use
732 ALCdevice
*volatile next
;
734 /* Memory space used by the default slot (Playback devices only) */
735 alignas(16) ALCbyte _slot_mem
[];
738 // Frequency was requested by the app or config file
739 #define DEVICE_FREQUENCY_REQUEST (1u<<1)
740 // Channel configuration was requested by the config file
741 #define DEVICE_CHANNELS_REQUEST (1u<<2)
742 // Sample type was requested by the config file
743 #define DEVICE_SAMPLE_TYPE_REQUEST (1u<<3)
745 // Specifies if the DSP is paused at user request
746 #define DEVICE_PAUSED (1u<<30)
748 // Specifies if the device is currently running
749 #define DEVICE_RUNNING (1u<<31)
752 /* Nanosecond resolution for the device clock time. */
753 #define DEVICE_CLOCK_RES U64(1000000000)
756 /* Must be less than 15 characters (16 including terminating null) for
757 * compatibility with pthread_setname_np limitations. */
758 #define MIXER_THREAD_NAME "alsoft-mixer"
760 #define RECORD_THREAD_NAME "alsoft-record"
763 struct ALCcontext_struct
{
766 struct ALlistener
*Listener
;
769 UIntMap EffectSlotMap
;
771 ATOMIC(ALenum
) LastError
;
773 enum DistanceModel DistanceModel
;
774 ALboolean SourceDistanceModel
;
776 ALfloat DopplerFactor
;
777 ALfloat DopplerVelocity
;
778 ALfloat SpeedOfSound
;
779 ATOMIC(ALenum
) DeferUpdates
;
783 /* Counter for the pre-mixing updates, in 31.1 fixed point (lowest bit
784 * indicates if updates are currently happening).
786 RefCount UpdateCount
;
787 ATOMIC(ALenum
) HoldUpdates
;
791 struct ALvoice
*Voices
;
795 ATOMIC(struct ALeffectslot
*) ActiveAuxSlotList
;
798 const ALCchar
*ExtensionList
;
800 ALCcontext
*volatile next
;
802 /* Memory space used by the listener */
803 alignas(16) ALCbyte _listener_mem
[];
806 ALCcontext
*GetContextRef(void);
808 void ALCcontext_IncRef(ALCcontext
*context
);
809 void ALCcontext_DecRef(ALCcontext
*context
);
811 void AppendAllDevicesList(const ALCchar
*name
);
812 void AppendCaptureDeviceList(const ALCchar
*name
);
814 void ALCdevice_Lock(ALCdevice
*device
);
815 void ALCdevice_Unlock(ALCdevice
*device
);
817 void ALCcontext_DeferUpdates(ALCcontext
*context
, ALenum type
);
818 void ALCcontext_ProcessUpdates(ALCcontext
*context
);
820 inline void LockContext(ALCcontext
*context
)
821 { ALCdevice_Lock(context
->Device
); }
823 inline void UnlockContext(ALCcontext
*context
)
824 { ALCdevice_Unlock(context
->Device
); }
835 DERIVE_FROM_TYPE(fenv_t
);
843 void SetMixerFPUMode(FPUCtl
*ctl
);
844 void RestoreFPUMode(const FPUCtl
*ctl
);
847 typedef struct ll_ringbuffer ll_ringbuffer_t
;
848 typedef struct ll_ringbuffer_data
{
851 } ll_ringbuffer_data_t
;
852 ll_ringbuffer_t
*ll_ringbuffer_create(size_t sz
, size_t elem_sz
);
853 void ll_ringbuffer_free(ll_ringbuffer_t
*rb
);
854 void ll_ringbuffer_get_read_vector(const ll_ringbuffer_t
*rb
, ll_ringbuffer_data_t
*vec
);
855 void ll_ringbuffer_get_write_vector(const ll_ringbuffer_t
*rb
, ll_ringbuffer_data_t
*vec
);
856 size_t ll_ringbuffer_read(ll_ringbuffer_t
*rb
, char *dest
, size_t cnt
);
857 size_t ll_ringbuffer_peek(ll_ringbuffer_t
*rb
, char *dest
, size_t cnt
);
858 void ll_ringbuffer_read_advance(ll_ringbuffer_t
*rb
, size_t cnt
);
859 size_t ll_ringbuffer_read_space(const ll_ringbuffer_t
*rb
);
860 int ll_ringbuffer_mlock(ll_ringbuffer_t
*rb
);
861 void ll_ringbuffer_reset(ll_ringbuffer_t
*rb
);
862 size_t ll_ringbuffer_write(ll_ringbuffer_t
*rb
, const char *src
, size_t cnt
);
863 void ll_ringbuffer_write_advance(ll_ringbuffer_t
*rb
, size_t cnt
);
864 size_t ll_ringbuffer_write_space(const ll_ringbuffer_t
*rb
);
866 void ReadALConfig(void);
867 void FreeALConfig(void);
868 int ConfigValueExists(const char *devName
, const char *blockName
, const char *keyName
);
869 const char *GetConfigValue(const char *devName
, const char *blockName
, const char *keyName
, const char *def
);
870 int GetConfigValueBool(const char *devName
, const char *blockName
, const char *keyName
, int def
);
871 int ConfigValueStr(const char *devName
, const char *blockName
, const char *keyName
, const char **ret
);
872 int ConfigValueInt(const char *devName
, const char *blockName
, const char *keyName
, int *ret
);
873 int ConfigValueUInt(const char *devName
, const char *blockName
, const char *keyName
, unsigned int *ret
);
874 int ConfigValueFloat(const char *devName
, const char *blockName
, const char *keyName
, float *ret
);
875 int ConfigValueBool(const char *devName
, const char *blockName
, const char *keyName
, int *ret
);
877 void SetRTPriority(void);
879 void SetDefaultChannelOrder(ALCdevice
*device
);
880 void SetDefaultWFXChannelOrder(ALCdevice
*device
);
882 const ALCchar
*DevFmtTypeString(enum DevFmtType type
);
883 const ALCchar
*DevFmtChannelsString(enum DevFmtChannels chans
);
886 * GetChannelIdxByName
888 * Returns the index for the given channel name (e.g. FrontCenter), or -1 if it
891 inline ALint
GetChannelIndex(const enum Channel names
[MAX_OUTPUT_CHANNELS
], enum Channel chan
)
894 for(i
= 0;i
< MAX_OUTPUT_CHANNELS
;i
++)
901 #define GetChannelIdxByName(x, c) GetChannelIndex((x).ChannelName, (c))
903 extern FILE *LogFile
;
905 #if defined(__GNUC__) && !defined(_WIN32) && !defined(IN_IDE_PARSER)
906 #define AL_PRINT(T, MSG, ...) fprintf(LogFile, "AL lib: %s %s: "MSG, T, __FUNCTION__ , ## __VA_ARGS__)
908 void al_print(const char *type
, const char *func
, const char *fmt
, ...) DECL_FORMAT(printf
, 3,4);
909 #define AL_PRINT(T, ...) al_print((T), __FUNCTION__, __VA_ARGS__)
919 extern enum LogLevel LogLevel
;
921 #define TRACEREF(...) do { \
922 if(LogLevel >= LogRef) \
923 AL_PRINT("(--)", __VA_ARGS__); \
926 #define TRACE(...) do { \
927 if(LogLevel >= LogTrace) \
928 AL_PRINT("(II)", __VA_ARGS__); \
931 #define WARN(...) do { \
932 if(LogLevel >= LogWarning) \
933 AL_PRINT("(WW)", __VA_ARGS__); \
936 #define ERR(...) do { \
937 if(LogLevel >= LogError) \
938 AL_PRINT("(EE)", __VA_ARGS__); \
942 extern ALint RTPrioLevel
;
945 extern ALuint CPUCapFlags
;
950 CPU_CAP_SSE4_1
= 1<<3,
954 void FillCPUCaps(ALuint capfilter
);
956 vector_al_string
SearchDataFiles(const char *match
, const char *subdir
);
958 /* Small hack to use a pointer-to-array type as a normal argument type.
959 * Shouldn't be used directly. */
960 typedef ALfloat ALfloatBUFFERSIZE
[BUFFERSIZE
];