alMain.h 19 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763
  1. #ifndef AL_MAIN_H
  2. #define AL_MAIN_H
  3. #include <string.h>
  4. #include <stdio.h>
  5. #include <stddef.h>
  6. #include <stdarg.h>
  7. #include <assert.h>
  8. #include <math.h>
  9. #include <limits.h>
  10. #ifdef HAVE_STRINGS_H
  11. #include <strings.h>
  12. #endif
  13. #ifdef HAVE_INTRIN_H
  14. #include <intrin.h>
  15. #endif
  16. #include "AL/al.h"
  17. #include "AL/alc.h"
  18. #include "AL/alext.h"
  19. #include "inprogext.h"
  20. #include "logging.h"
  21. #include "polymorphism.h"
  22. #include "static_assert.h"
  23. #include "align.h"
  24. #include "atomic.h"
  25. #include "vector.h"
  26. #include "alstring.h"
  27. #include "almalloc.h"
  28. #include "threads.h"
  29. #if defined(_WIN64)
  30. #define SZFMT "%I64u"
  31. #elif defined(_WIN32)
  32. #define SZFMT "%u"
  33. #else
  34. #define SZFMT "%zu"
  35. #endif
  36. #ifdef __GNUC__
  37. #define LIKELY(x) __builtin_expect(!!(x), !0)
  38. #define UNLIKELY(x) __builtin_expect(!!(x), 0)
  39. #else
  40. #define LIKELY(x) (!!(x))
  41. #define UNLIKELY(x) (!!(x))
  42. #endif
  43. #ifndef UINT64_MAX
  44. #define UINT64_MAX U64(18446744073709551615)
  45. #endif
  46. #ifndef UNUSED
  47. #if defined(__cplusplus)
  48. #define UNUSED(x)
  49. #elif defined(__GNUC__)
  50. #define UNUSED(x) UNUSED_##x __attribute__((unused))
  51. #elif defined(__LCLINT__)
  52. #define UNUSED(x) /*@unused@*/ x
  53. #else
  54. #define UNUSED(x) x
  55. #endif
  56. #endif
  57. /* Calculates the size of a struct with N elements of a flexible array member.
  58. * GCC and Clang allow offsetof(Type, fam[N]) for this, but MSVC seems to have
  59. * trouble, so a bit more verbose workaround is needed.
  60. */
  61. #define FAM_SIZE(T, M, N) (offsetof(T, M) + sizeof(((T*)NULL)->M[0])*(N))
  62. #ifdef __cplusplus
  63. extern "C" {
  64. #endif
  65. typedef ALint64SOFT ALint64;
  66. typedef ALuint64SOFT ALuint64;
  67. #ifndef U64
  68. #if defined(_MSC_VER)
  69. #define U64(x) ((ALuint64)(x##ui64))
  70. #elif SIZEOF_LONG == 8
  71. #define U64(x) ((ALuint64)(x##ul))
  72. #elif SIZEOF_LONG_LONG == 8
  73. #define U64(x) ((ALuint64)(x##ull))
  74. #endif
  75. #endif
  76. /* Define a CTZ64 macro (count trailing zeros, for 64-bit integers). The result
  77. * is *UNDEFINED* if the value is 0.
  78. */
  79. #ifdef __GNUC__
  80. #if SIZEOF_LONG == 8
  81. #define CTZ64(x) __builtin_ctzl(x)
  82. #else
  83. #define CTZ64(x) __builtin_ctzll(x)
  84. #endif
  85. #elif defined(HAVE_BITSCANFORWARD64_INTRINSIC)
  86. inline int msvc64_ctz64(ALuint64 v)
  87. {
  88. unsigned long idx = 64;
  89. _BitScanForward64(&idx, v);
  90. return (int)idx;
  91. }
  92. #define CTZ64(x) msvc64_ctz64(x)
  93. #elif defined(HAVE_BITSCANFORWARD_INTRINSIC)
  94. inline int msvc_ctz64(ALuint64 v)
  95. {
  96. unsigned long idx = 64;
  97. if(!_BitScanForward(&idx, v&0xffffffff))
  98. {
  99. if(_BitScanForward(&idx, v>>32))
  100. idx += 32;
  101. }
  102. return (int)idx;
  103. }
  104. #define CTZ64(x) msvc_ctz64(x)
  105. #else
  106. /* There be black magics here. The popcnt64 method is derived from
  107. * https://graphics.stanford.edu/~seander/bithacks.html#CountBitsSetParallel
  108. * while the ctz-utilizing-popcnt algorithm is shown here
  109. * http://www.hackersdelight.org/hdcodetxt/ntz.c.txt
  110. * as the ntz2 variant. These likely aren't the most efficient methods, but
  111. * they're good enough if the GCC or MSVC intrinsics aren't available.
  112. */
  113. inline int fallback_popcnt64(ALuint64 v)
  114. {
  115. v = v - ((v >> 1) & U64(0x5555555555555555));
  116. v = (v & U64(0x3333333333333333)) + ((v >> 2) & U64(0x3333333333333333));
  117. v = (v + (v >> 4)) & U64(0x0f0f0f0f0f0f0f0f);
  118. return (int)((v * U64(0x0101010101010101)) >> 56);
  119. }
  120. inline int fallback_ctz64(ALuint64 value)
  121. {
  122. return fallback_popcnt64(~value & (value - 1));
  123. }
  124. #define CTZ64(x) fallback_ctz64(x)
  125. #endif
  126. static const union {
  127. ALuint u;
  128. ALubyte b[sizeof(ALuint)];
  129. } EndianTest = { 1 };
  130. #define IS_LITTLE_ENDIAN (EndianTest.b[0] == 1)
  131. #define COUNTOF(x) (sizeof(x) / sizeof(0[x]))
  132. struct ll_ringbuffer;
  133. struct Hrtf;
  134. struct HrtfEntry;
  135. struct DirectHrtfState;
  136. struct FrontStablizer;
  137. struct Compressor;
  138. struct ALCbackend;
  139. struct ALbuffer;
  140. struct ALeffect;
  141. struct ALfilter;
  142. struct ALsource;
  143. struct ALcontextProps;
  144. struct ALlistenerProps;
  145. struct ALvoiceProps;
  146. struct ALeffectslotProps;
  147. #define DEFAULT_OUTPUT_RATE (44100)
  148. #define MIN_OUTPUT_RATE (8000)
  149. /* Find the next power-of-2 for non-power-of-2 numbers. */
  150. inline ALuint NextPowerOf2(ALuint value)
  151. {
  152. if(value > 0)
  153. {
  154. value--;
  155. value |= value>>1;
  156. value |= value>>2;
  157. value |= value>>4;
  158. value |= value>>8;
  159. value |= value>>16;
  160. }
  161. return value+1;
  162. }
  163. /** Round up a value to the next multiple. */
  164. inline size_t RoundUp(size_t value, size_t r)
  165. {
  166. value += r-1;
  167. return value - (value%r);
  168. }
  169. /* Fast float-to-int conversion. Assumes the FPU is already in round-to-zero
  170. * mode. */
  171. inline ALint fastf2i(ALfloat f)
  172. {
  173. #ifdef HAVE_LRINTF
  174. return lrintf(f);
  175. #elif defined(_MSC_VER) && defined(_M_IX86)
  176. ALint i;
  177. __asm fld f
  178. __asm fistp i
  179. return i;
  180. #else
  181. return (ALint)f;
  182. #endif
  183. }
  184. enum DevProbe {
  185. ALL_DEVICE_PROBE,
  186. CAPTURE_DEVICE_PROBE
  187. };
  188. enum DistanceModel {
  189. InverseDistanceClamped = AL_INVERSE_DISTANCE_CLAMPED,
  190. LinearDistanceClamped = AL_LINEAR_DISTANCE_CLAMPED,
  191. ExponentDistanceClamped = AL_EXPONENT_DISTANCE_CLAMPED,
  192. InverseDistance = AL_INVERSE_DISTANCE,
  193. LinearDistance = AL_LINEAR_DISTANCE,
  194. ExponentDistance = AL_EXPONENT_DISTANCE,
  195. DisableDistance = AL_NONE,
  196. DefaultDistanceModel = InverseDistanceClamped
  197. };
  198. enum Channel {
  199. FrontLeft = 0,
  200. FrontRight,
  201. FrontCenter,
  202. LFE,
  203. BackLeft,
  204. BackRight,
  205. BackCenter,
  206. SideLeft,
  207. SideRight,
  208. UpperFrontLeft,
  209. UpperFrontRight,
  210. UpperBackLeft,
  211. UpperBackRight,
  212. LowerFrontLeft,
  213. LowerFrontRight,
  214. LowerBackLeft,
  215. LowerBackRight,
  216. Aux0,
  217. Aux1,
  218. Aux2,
  219. Aux3,
  220. Aux4,
  221. Aux5,
  222. Aux6,
  223. Aux7,
  224. Aux8,
  225. Aux9,
  226. Aux10,
  227. Aux11,
  228. Aux12,
  229. Aux13,
  230. Aux14,
  231. Aux15,
  232. InvalidChannel
  233. };
  234. /* Device formats */
  235. enum DevFmtType {
  236. DevFmtByte = ALC_BYTE_SOFT,
  237. DevFmtUByte = ALC_UNSIGNED_BYTE_SOFT,
  238. DevFmtShort = ALC_SHORT_SOFT,
  239. DevFmtUShort = ALC_UNSIGNED_SHORT_SOFT,
  240. DevFmtInt = ALC_INT_SOFT,
  241. DevFmtUInt = ALC_UNSIGNED_INT_SOFT,
  242. DevFmtFloat = ALC_FLOAT_SOFT,
  243. DevFmtTypeDefault = DevFmtFloat
  244. };
  245. enum DevFmtChannels {
  246. DevFmtMono = ALC_MONO_SOFT,
  247. DevFmtStereo = ALC_STEREO_SOFT,
  248. DevFmtQuad = ALC_QUAD_SOFT,
  249. DevFmtX51 = ALC_5POINT1_SOFT,
  250. DevFmtX61 = ALC_6POINT1_SOFT,
  251. DevFmtX71 = ALC_7POINT1_SOFT,
  252. DevFmtAmbi3D = ALC_BFORMAT3D_SOFT,
  253. /* Similar to 5.1, except using rear channels instead of sides */
  254. DevFmtX51Rear = 0x80000000,
  255. DevFmtChannelsDefault = DevFmtStereo
  256. };
  257. #define MAX_OUTPUT_CHANNELS (16)
  258. ALsizei BytesFromDevFmt(enum DevFmtType type);
  259. ALsizei ChannelsFromDevFmt(enum DevFmtChannels chans, ALsizei ambiorder);
  260. inline ALsizei FrameSizeFromDevFmt(enum DevFmtChannels chans, enum DevFmtType type, ALsizei ambiorder)
  261. {
  262. return ChannelsFromDevFmt(chans, ambiorder) * BytesFromDevFmt(type);
  263. }
  264. enum AmbiLayout {
  265. AmbiLayout_FuMa = ALC_FUMA_SOFT, /* FuMa channel order */
  266. AmbiLayout_ACN = ALC_ACN_SOFT, /* ACN channel order */
  267. AmbiLayout_Default = AmbiLayout_ACN
  268. };
  269. enum AmbiNorm {
  270. AmbiNorm_FuMa = ALC_FUMA_SOFT, /* FuMa normalization */
  271. AmbiNorm_SN3D = ALC_SN3D_SOFT, /* SN3D normalization */
  272. AmbiNorm_N3D = ALC_N3D_SOFT, /* N3D normalization */
  273. AmbiNorm_Default = AmbiNorm_SN3D
  274. };
  275. enum DeviceType {
  276. Playback,
  277. Capture,
  278. Loopback
  279. };
  280. enum RenderMode {
  281. NormalRender,
  282. StereoPair,
  283. HrtfRender
  284. };
  285. /* The maximum number of Ambisonics coefficients. For a given order (o), the
  286. * size needed will be (o+1)**2, thus zero-order has 1, first-order has 4,
  287. * second-order has 9, third-order has 16, and fourth-order has 25.
  288. */
  289. #define MAX_AMBI_ORDER 3
  290. #define MAX_AMBI_COEFFS ((MAX_AMBI_ORDER+1) * (MAX_AMBI_ORDER+1))
  291. /* A bitmask of ambisonic channels with height information. If none of these
  292. * channels are used/needed, there's no height (e.g. with most surround sound
  293. * speaker setups). This only specifies up to 4th order, which is the highest
  294. * order a 32-bit mask value can specify (a 64-bit mask could handle up to 7th
  295. * order). This is ACN ordering, with bit 0 being ACN 0, etc.
  296. */
  297. #define AMBI_PERIPHONIC_MASK (0xfe7ce4)
  298. /* The maximum number of Ambisonic coefficients for 2D (non-periphonic)
  299. * representation. This is 2 per each order above zero-order, plus 1 for zero-
  300. * order. Or simply, o*2 + 1.
  301. */
  302. #define MAX_AMBI2D_COEFFS (MAX_AMBI_ORDER*2 + 1)
  303. typedef ALfloat ChannelConfig[MAX_AMBI_COEFFS];
  304. typedef struct BFChannelConfig {
  305. ALfloat Scale;
  306. ALsizei Index;
  307. } BFChannelConfig;
  308. typedef union AmbiConfig {
  309. /* Ambisonic coefficients for mixing to the dry buffer. */
  310. ChannelConfig Coeffs[MAX_OUTPUT_CHANNELS];
  311. /* Coefficient channel mapping for mixing to the dry buffer. */
  312. BFChannelConfig Map[MAX_OUTPUT_CHANNELS];
  313. } AmbiConfig;
  314. typedef struct BufferSubList {
  315. ALuint64 FreeMask;
  316. struct ALbuffer *Buffers; /* 64 */
  317. } BufferSubList;
  318. TYPEDEF_VECTOR(BufferSubList, vector_BufferSubList)
  319. typedef struct EffectSubList {
  320. ALuint64 FreeMask;
  321. struct ALeffect *Effects; /* 64 */
  322. } EffectSubList;
  323. TYPEDEF_VECTOR(EffectSubList, vector_EffectSubList)
  324. typedef struct FilterSubList {
  325. ALuint64 FreeMask;
  326. struct ALfilter *Filters; /* 64 */
  327. } FilterSubList;
  328. TYPEDEF_VECTOR(FilterSubList, vector_FilterSubList)
  329. typedef struct SourceSubList {
  330. ALuint64 FreeMask;
  331. struct ALsource *Sources; /* 64 */
  332. } SourceSubList;
  333. TYPEDEF_VECTOR(SourceSubList, vector_SourceSubList)
  334. /* Effect slots are rather large, and apps aren't likely to have more than one
  335. * or two (let alone 64), so hold them individually.
  336. */
  337. typedef struct ALeffectslot *ALeffectslotPtr;
  338. TYPEDEF_VECTOR(ALeffectslotPtr, vector_ALeffectslotPtr)
  339. typedef struct EnumeratedHrtf {
  340. al_string name;
  341. struct HrtfEntry *hrtf;
  342. } EnumeratedHrtf;
  343. TYPEDEF_VECTOR(EnumeratedHrtf, vector_EnumeratedHrtf)
  344. /* Maximum delay in samples for speaker distance compensation. */
  345. #define MAX_DELAY_LENGTH 1024
  346. typedef struct DistanceComp {
  347. ALfloat Gain;
  348. ALsizei Length; /* Valid range is [0...MAX_DELAY_LENGTH). */
  349. ALfloat *Buffer;
  350. } DistanceComp;
  351. /* Size for temporary storage of buffer data, in ALfloats. Larger values need
  352. * more memory, while smaller values may need more iterations. The value needs
  353. * to be a sensible size, however, as it constrains the max stepping value used
  354. * for mixing, as well as the maximum number of samples per mixing iteration.
  355. */
  356. #define BUFFERSIZE 2048
  357. typedef struct DryMixParams {
  358. AmbiConfig Ambi;
  359. /* Number of coefficients in each Ambi.Coeffs to mix together (4 for first-
  360. * order, 9 for second-order, etc). If the count is 0, Ambi.Map is used
  361. * instead to map each output to a coefficient index.
  362. */
  363. ALsizei CoeffCount;
  364. ALfloat (*Buffer)[BUFFERSIZE];
  365. ALsizei NumChannels;
  366. ALsizei NumChannelsPerOrder[MAX_AMBI_ORDER+1];
  367. } DryMixParams;
  368. typedef struct BFMixParams {
  369. AmbiConfig Ambi;
  370. /* Will only be 4 or 0. */
  371. ALsizei CoeffCount;
  372. ALfloat (*Buffer)[BUFFERSIZE];
  373. ALsizei NumChannels;
  374. } BFMixParams;
  375. typedef struct RealMixParams {
  376. enum Channel ChannelName[MAX_OUTPUT_CHANNELS];
  377. ALfloat (*Buffer)[BUFFERSIZE];
  378. ALsizei NumChannels;
  379. } RealMixParams;
  380. typedef void (*POSTPROCESS)(ALCdevice *device, ALsizei SamplesToDo);
  381. struct ALCdevice_struct {
  382. RefCount ref;
  383. ATOMIC(ALenum) Connected;
  384. enum DeviceType Type;
  385. ALuint Frequency;
  386. ALuint UpdateSize;
  387. ALuint NumUpdates;
  388. enum DevFmtChannels FmtChans;
  389. enum DevFmtType FmtType;
  390. ALboolean IsHeadphones;
  391. ALsizei AmbiOrder;
  392. /* For DevFmtAmbi* output only, specifies the channel order and
  393. * normalization.
  394. */
  395. enum AmbiLayout AmbiLayout;
  396. enum AmbiNorm AmbiScale;
  397. al_string DeviceName;
  398. ATOMIC(ALCenum) LastError;
  399. // Maximum number of sources that can be created
  400. ALuint SourcesMax;
  401. // Maximum number of slots that can be created
  402. ALuint AuxiliaryEffectSlotMax;
  403. ALCuint NumMonoSources;
  404. ALCuint NumStereoSources;
  405. ALsizei NumAuxSends;
  406. // Map of Buffers for this device
  407. vector_BufferSubList BufferList;
  408. almtx_t BufferLock;
  409. // Map of Effects for this device
  410. vector_EffectSubList EffectList;
  411. almtx_t EffectLock;
  412. // Map of Filters for this device
  413. vector_FilterSubList FilterList;
  414. almtx_t FilterLock;
  415. POSTPROCESS PostProcess;
  416. /* HRTF state and info */
  417. struct DirectHrtfState *Hrtf;
  418. al_string HrtfName;
  419. struct Hrtf *HrtfHandle;
  420. vector_EnumeratedHrtf HrtfList;
  421. ALCenum HrtfStatus;
  422. /* UHJ encoder state */
  423. struct Uhj2Encoder *Uhj_Encoder;
  424. /* High quality Ambisonic decoder */
  425. struct BFormatDec *AmbiDecoder;
  426. /* Stereo-to-binaural filter */
  427. struct bs2b *Bs2b;
  428. /* First-order ambisonic upsampler for higher-order output */
  429. struct AmbiUpsampler *AmbiUp;
  430. /* Rendering mode. */
  431. enum RenderMode Render_Mode;
  432. // Device flags
  433. ALuint Flags;
  434. ALuint64 ClockBase;
  435. ALuint SamplesDone;
  436. /* Temp storage used for mixer processing. */
  437. alignas(16) ALfloat TempBuffer[4][BUFFERSIZE];
  438. /* The "dry" path corresponds to the main output. */
  439. DryMixParams Dry;
  440. /* First-order ambisonics output, to be upsampled to the dry buffer if different. */
  441. BFMixParams FOAOut;
  442. /* "Real" output, which will be written to the device buffer. May alias the
  443. * dry buffer.
  444. */
  445. RealMixParams RealOut;
  446. struct FrontStablizer *Stablizer;
  447. struct Compressor *Limiter;
  448. /* The average speaker distance as determined by the ambdec configuration
  449. * (or alternatively, by the NFC-HOA reference delay). Only used for NFC.
  450. */
  451. ALfloat AvgSpeakerDist;
  452. /* Delay buffers used to compensate for speaker distances. */
  453. DistanceComp ChannelDelay[MAX_OUTPUT_CHANNELS];
  454. /* Dithering control. */
  455. ALfloat DitherDepth;
  456. ALuint DitherSeed;
  457. /* Running count of the mixer invocations, in 31.1 fixed point. This
  458. * actually increments *twice* when mixing, first at the start and then at
  459. * the end, so the bottom bit indicates if the device is currently mixing
  460. * and the upper bits indicates how many mixes have been done.
  461. */
  462. RefCount MixCount;
  463. // Contexts created on this device
  464. ATOMIC(ALCcontext*) ContextList;
  465. almtx_t BackendLock;
  466. struct ALCbackend *Backend;
  467. ATOMIC(ALCdevice*) next;
  468. };
  469. // Frequency was requested by the app or config file
  470. #define DEVICE_FREQUENCY_REQUEST (1u<<1)
  471. // Channel configuration was requested by the config file
  472. #define DEVICE_CHANNELS_REQUEST (1u<<2)
  473. // Sample type was requested by the config file
  474. #define DEVICE_SAMPLE_TYPE_REQUEST (1u<<3)
  475. // Specifies if the DSP is paused at user request
  476. #define DEVICE_PAUSED (1u<<30)
  477. // Specifies if the device is currently running
  478. #define DEVICE_RUNNING (1u<<31)
  479. /* Nanosecond resolution for the device clock time. */
  480. #define DEVICE_CLOCK_RES U64(1000000000)
  481. /* Must be less than 15 characters (16 including terminating null) for
  482. * compatibility with pthread_setname_np limitations. */
  483. #define MIXER_THREAD_NAME "alsoft-mixer"
  484. #define RECORD_THREAD_NAME "alsoft-record"
  485. enum {
  486. EventType_SourceStateChange = 1<<0,
  487. EventType_BufferCompleted = 1<<1,
  488. EventType_Error = 1<<2,
  489. EventType_Performance = 1<<3,
  490. EventType_Deprecated = 1<<4,
  491. EventType_Disconnected = 1<<5,
  492. };
  493. typedef struct AsyncEvent {
  494. unsigned int EnumType;
  495. ALenum Type;
  496. ALuint ObjectId;
  497. ALuint Param;
  498. ALchar Message[1008];
  499. } AsyncEvent;
  500. struct ALCcontext_struct {
  501. RefCount ref;
  502. struct ALlistener *Listener;
  503. vector_SourceSubList SourceList;
  504. ALuint NumSources;
  505. almtx_t SourceLock;
  506. vector_ALeffectslotPtr EffectSlotList;
  507. almtx_t EffectSlotLock;
  508. ATOMIC(ALenum) LastError;
  509. enum DistanceModel DistanceModel;
  510. ALboolean SourceDistanceModel;
  511. ALfloat DopplerFactor;
  512. ALfloat DopplerVelocity;
  513. ALfloat SpeedOfSound;
  514. ALfloat MetersPerUnit;
  515. ATOMIC_FLAG PropsClean;
  516. ATOMIC(ALenum) DeferUpdates;
  517. almtx_t PropLock;
  518. /* Counter for the pre-mixing updates, in 31.1 fixed point (lowest bit
  519. * indicates if updates are currently happening).
  520. */
  521. RefCount UpdateCount;
  522. ATOMIC(ALenum) HoldUpdates;
  523. ALfloat GainBoost;
  524. ATOMIC(struct ALcontextProps*) Update;
  525. /* Linked lists of unused property containers, free to use for future
  526. * updates.
  527. */
  528. ATOMIC(struct ALcontextProps*) FreeContextProps;
  529. ATOMIC(struct ALlistenerProps*) FreeListenerProps;
  530. ATOMIC(struct ALvoiceProps*) FreeVoiceProps;
  531. ATOMIC(struct ALeffectslotProps*) FreeEffectslotProps;
  532. struct ALvoice **Voices;
  533. ALsizei VoiceCount;
  534. ALsizei MaxVoices;
  535. ATOMIC(struct ALeffectslotArray*) ActiveAuxSlots;
  536. almtx_t EventThrdLock;
  537. althrd_t EventThread;
  538. alsem_t EventSem;
  539. struct ll_ringbuffer *AsyncEvents;
  540. ATOMIC(ALbitfieldSOFT) EnabledEvts;
  541. almtx_t EventCbLock;
  542. ALEVENTPROCSOFT EventCb;
  543. void *EventParam;
  544. /* Default effect slot */
  545. struct ALeffectslot *DefaultSlot;
  546. ALCdevice *Device;
  547. const ALCchar *ExtensionList;
  548. ATOMIC(ALCcontext*) next;
  549. /* Memory space used by the listener (and possibly default effect slot) */
  550. alignas(16) ALCbyte _listener_mem[];
  551. };
  552. ALCcontext *GetContextRef(void);
  553. void ALCcontext_DecRef(ALCcontext *context);
  554. void ALCcontext_DeferUpdates(ALCcontext *context);
  555. void ALCcontext_ProcessUpdates(ALCcontext *context);
  556. void AllocateVoices(ALCcontext *context, ALsizei num_voices, ALsizei old_sends);
  557. void AppendAllDevicesList(const ALCchar *name);
  558. void AppendCaptureDeviceList(const ALCchar *name);
  559. extern ALint RTPrioLevel;
  560. void SetRTPriority(void);
  561. void SetDefaultChannelOrder(ALCdevice *device);
  562. void SetDefaultWFXChannelOrder(ALCdevice *device);
  563. const ALCchar *DevFmtTypeString(enum DevFmtType type);
  564. const ALCchar *DevFmtChannelsString(enum DevFmtChannels chans);
  565. inline ALint GetChannelIndex(const enum Channel names[MAX_OUTPUT_CHANNELS], enum Channel chan)
  566. {
  567. ALint i;
  568. for(i = 0;i < MAX_OUTPUT_CHANNELS;i++)
  569. {
  570. if(names[i] == chan)
  571. return i;
  572. }
  573. return -1;
  574. }
  575. /**
  576. * GetChannelIdxByName
  577. *
  578. * Returns the index for the given channel name (e.g. FrontCenter), or -1 if it
  579. * doesn't exist.
  580. */
  581. inline ALint GetChannelIdxByName(const RealMixParams *real, enum Channel chan)
  582. { return GetChannelIndex(real->ChannelName, chan); }
  583. inline void LockBufferList(ALCdevice *device) { almtx_lock(&device->BufferLock); }
  584. inline void UnlockBufferList(ALCdevice *device) { almtx_unlock(&device->BufferLock); }
  585. inline void LockEffectList(ALCdevice *device) { almtx_lock(&device->EffectLock); }
  586. inline void UnlockEffectList(ALCdevice *device) { almtx_unlock(&device->EffectLock); }
  587. inline void LockFilterList(ALCdevice *device) { almtx_lock(&device->FilterLock); }
  588. inline void UnlockFilterList(ALCdevice *device) { almtx_unlock(&device->FilterLock); }
  589. inline void LockEffectSlotList(ALCcontext *context)
  590. { almtx_lock(&context->EffectSlotLock); }
  591. inline void UnlockEffectSlotList(ALCcontext *context)
  592. { almtx_unlock(&context->EffectSlotLock); }
  593. vector_al_string SearchDataFiles(const char *match, const char *subdir);
  594. #ifdef __cplusplus
  595. }
  596. #endif
  597. #endif