alAuxEffectSlot.h 6.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183
  1. #ifndef _AL_AUXEFFECTSLOT_H_
  2. #define _AL_AUXEFFECTSLOT_H_
  3. #include "alMain.h"
  4. #include "alEffect.h"
  5. #include "atomic.h"
  6. #include "align.h"
  7. #ifdef __cplusplus
  8. extern "C" {
  9. #endif
  10. struct ALeffectStateVtable;
  11. struct ALeffectslot;
  12. typedef struct ALeffectState {
  13. RefCount Ref;
  14. const struct ALeffectStateVtable *vtbl;
  15. ALfloat (*OutBuffer)[BUFFERSIZE];
  16. ALsizei OutChannels;
  17. } ALeffectState;
  18. void ALeffectState_Construct(ALeffectState *state);
  19. void ALeffectState_Destruct(ALeffectState *state);
  20. struct ALeffectStateVtable {
  21. void (*const Destruct)(ALeffectState *state);
  22. ALboolean (*const deviceUpdate)(ALeffectState *state, ALCdevice *device);
  23. void (*const update)(ALeffectState *state, const ALCcontext *context, const struct ALeffectslot *slot, const union ALeffectProps *props);
  24. void (*const process)(ALeffectState *state, ALsizei samplesToDo, const ALfloat (*restrict samplesIn)[BUFFERSIZE], ALfloat (*restrict samplesOut)[BUFFERSIZE], ALsizei numChannels);
  25. void (*const Delete)(void *ptr);
  26. };
  27. /* Small hack to use a pointer-to-array types as a normal argument type.
  28. * Shouldn't be used directly.
  29. */
  30. typedef ALfloat ALfloatBUFFERSIZE[BUFFERSIZE];
  31. #define DEFINE_ALEFFECTSTATE_VTABLE(T) \
  32. DECLARE_THUNK(T, ALeffectState, void, Destruct) \
  33. DECLARE_THUNK1(T, ALeffectState, ALboolean, deviceUpdate, ALCdevice*) \
  34. DECLARE_THUNK3(T, ALeffectState, void, update, const ALCcontext*, const ALeffectslot*, const ALeffectProps*) \
  35. DECLARE_THUNK4(T, ALeffectState, void, process, ALsizei, const ALfloatBUFFERSIZE*restrict, ALfloatBUFFERSIZE*restrict, ALsizei) \
  36. static void T##_ALeffectState_Delete(void *ptr) \
  37. { return T##_Delete(STATIC_UPCAST(T, ALeffectState, (ALeffectState*)ptr)); } \
  38. \
  39. static const struct ALeffectStateVtable T##_ALeffectState_vtable = { \
  40. T##_ALeffectState_Destruct, \
  41. \
  42. T##_ALeffectState_deviceUpdate, \
  43. T##_ALeffectState_update, \
  44. T##_ALeffectState_process, \
  45. \
  46. T##_ALeffectState_Delete, \
  47. }
  48. struct EffectStateFactoryVtable;
  49. typedef struct EffectStateFactory {
  50. const struct EffectStateFactoryVtable *vtab;
  51. } EffectStateFactory;
  52. struct EffectStateFactoryVtable {
  53. ALeffectState *(*const create)(EffectStateFactory *factory);
  54. };
  55. #define EffectStateFactory_create(x) ((x)->vtab->create((x)))
  56. #define DEFINE_EFFECTSTATEFACTORY_VTABLE(T) \
  57. DECLARE_THUNK(T, EffectStateFactory, ALeffectState*, create) \
  58. \
  59. static const struct EffectStateFactoryVtable T##_EffectStateFactory_vtable = { \
  60. T##_EffectStateFactory_create, \
  61. }
  62. #define MAX_EFFECT_CHANNELS (4)
  63. struct ALeffectslotArray {
  64. ALsizei count;
  65. struct ALeffectslot *slot[];
  66. };
  67. struct ALeffectslotProps {
  68. ALfloat Gain;
  69. ALboolean AuxSendAuto;
  70. ALenum Type;
  71. ALeffectProps Props;
  72. ALeffectState *State;
  73. ATOMIC(struct ALeffectslotProps*) next;
  74. };
  75. typedef struct ALeffectslot {
  76. ALfloat Gain;
  77. ALboolean AuxSendAuto;
  78. struct {
  79. ALenum Type;
  80. ALeffectProps Props;
  81. ALeffectState *State;
  82. } Effect;
  83. ATOMIC_FLAG PropsClean;
  84. RefCount ref;
  85. ATOMIC(struct ALeffectslotProps*) Update;
  86. struct {
  87. ALfloat Gain;
  88. ALboolean AuxSendAuto;
  89. ALenum EffectType;
  90. ALeffectProps EffectProps;
  91. ALeffectState *EffectState;
  92. ALfloat RoomRolloff; /* Added to the source's room rolloff, not multiplied. */
  93. ALfloat DecayTime;
  94. ALfloat DecayLFRatio;
  95. ALfloat DecayHFRatio;
  96. ALboolean DecayHFLimit;
  97. ALfloat AirAbsorptionGainHF;
  98. } Params;
  99. /* Self ID */
  100. ALuint id;
  101. ALsizei NumChannels;
  102. BFChannelConfig ChanMap[MAX_EFFECT_CHANNELS];
  103. /* Wet buffer configuration is ACN channel order with N3D scaling:
  104. * * Channel 0 is the unattenuated mono signal.
  105. * * Channel 1 is OpenAL -X * sqrt(3)
  106. * * Channel 2 is OpenAL Y * sqrt(3)
  107. * * Channel 3 is OpenAL -Z * sqrt(3)
  108. * Consequently, effects that only want to work with mono input can use
  109. * channel 0 by itself. Effects that want multichannel can process the
  110. * ambisonics signal and make a B-Format pan (ComputeFirstOrderGains) for
  111. * first-order device output (FOAOut).
  112. */
  113. alignas(16) ALfloat WetBuffer[MAX_EFFECT_CHANNELS][BUFFERSIZE];
  114. } ALeffectslot;
  115. ALenum InitEffectSlot(ALeffectslot *slot);
  116. void DeinitEffectSlot(ALeffectslot *slot);
  117. void UpdateEffectSlotProps(ALeffectslot *slot, ALCcontext *context);
  118. void UpdateAllEffectSlotProps(ALCcontext *context);
  119. ALvoid ReleaseALAuxiliaryEffectSlots(ALCcontext *Context);
  120. EffectStateFactory *NullStateFactory_getFactory(void);
  121. EffectStateFactory *ReverbStateFactory_getFactory(void);
  122. EffectStateFactory *ChorusStateFactory_getFactory(void);
  123. EffectStateFactory *CompressorStateFactory_getFactory(void);
  124. EffectStateFactory *DistortionStateFactory_getFactory(void);
  125. EffectStateFactory *EchoStateFactory_getFactory(void);
  126. EffectStateFactory *EqualizerStateFactory_getFactory(void);
  127. EffectStateFactory *FlangerStateFactory_getFactory(void);
  128. EffectStateFactory *ModulatorStateFactory_getFactory(void);
  129. EffectStateFactory *PshifterStateFactory_getFactory(void);
  130. EffectStateFactory *DedicatedStateFactory_getFactory(void);
  131. ALenum InitializeEffect(ALCcontext *Context, ALeffectslot *EffectSlot, ALeffect *effect);
  132. void ALeffectState_DecRef(ALeffectState *state);
  133. #ifdef __cplusplus
  134. }
  135. #endif
  136. #endif