alAuxEffectSlot.h 6.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190
  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 ALCdevice *device, 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. #define DEFINE_ALEFFECTSTATE_VTABLE(T) \
  28. DECLARE_THUNK(T, ALeffectState, void, Destruct) \
  29. DECLARE_THUNK1(T, ALeffectState, ALboolean, deviceUpdate, ALCdevice*) \
  30. DECLARE_THUNK3(T, ALeffectState, void, update, const ALCdevice*, const ALeffectslot*, const ALeffectProps*) \
  31. DECLARE_THUNK4(T, ALeffectState, void, process, ALsizei, const ALfloatBUFFERSIZE*restrict, ALfloatBUFFERSIZE*restrict, ALsizei) \
  32. static void T##_ALeffectState_Delete(void *ptr) \
  33. { return T##_Delete(STATIC_UPCAST(T, ALeffectState, (ALeffectState*)ptr)); } \
  34. \
  35. static const struct ALeffectStateVtable T##_ALeffectState_vtable = { \
  36. T##_ALeffectState_Destruct, \
  37. \
  38. T##_ALeffectState_deviceUpdate, \
  39. T##_ALeffectState_update, \
  40. T##_ALeffectState_process, \
  41. \
  42. T##_ALeffectState_Delete, \
  43. }
  44. struct ALeffectStateFactoryVtable;
  45. typedef struct ALeffectStateFactory {
  46. const struct ALeffectStateFactoryVtable *vtbl;
  47. } ALeffectStateFactory;
  48. struct ALeffectStateFactoryVtable {
  49. ALeffectState *(*const create)(ALeffectStateFactory *factory);
  50. };
  51. #define DEFINE_ALEFFECTSTATEFACTORY_VTABLE(T) \
  52. DECLARE_THUNK(T, ALeffectStateFactory, ALeffectState*, create) \
  53. \
  54. static const struct ALeffectStateFactoryVtable T##_ALeffectStateFactory_vtable = { \
  55. T##_ALeffectStateFactory_create, \
  56. }
  57. #define MAX_EFFECT_CHANNELS (4)
  58. struct ALeffectslotArray {
  59. ALsizei count;
  60. struct ALeffectslot *slot[];
  61. };
  62. struct ALeffectslotProps {
  63. ALfloat Gain;
  64. ALboolean AuxSendAuto;
  65. ALenum Type;
  66. ALeffectProps Props;
  67. ALeffectState *State;
  68. ATOMIC(struct ALeffectslotProps*) next;
  69. };
  70. typedef struct ALeffectslot {
  71. ALfloat Gain;
  72. ALboolean AuxSendAuto;
  73. struct {
  74. ALenum Type;
  75. ALeffectProps Props;
  76. ALeffectState *State;
  77. } Effect;
  78. ATOMIC_FLAG PropsClean;
  79. RefCount ref;
  80. ATOMIC(struct ALeffectslotProps*) Update;
  81. ATOMIC(struct ALeffectslotProps*) FreeList;
  82. struct {
  83. ALfloat Gain;
  84. ALboolean AuxSendAuto;
  85. ALenum EffectType;
  86. ALeffectState *EffectState;
  87. ALfloat RoomRolloff; /* Added to the source's room rolloff, not multiplied. */
  88. ALfloat DecayTime;
  89. ALfloat DecayHFRatio;
  90. ALboolean DecayHFLimit;
  91. ALfloat AirAbsorptionGainHF;
  92. } Params;
  93. /* Self ID */
  94. ALuint id;
  95. ALsizei NumChannels;
  96. BFChannelConfig ChanMap[MAX_EFFECT_CHANNELS];
  97. /* Wet buffer configuration is ACN channel order with N3D scaling:
  98. * * Channel 0 is the unattenuated mono signal.
  99. * * Channel 1 is OpenAL -X
  100. * * Channel 2 is OpenAL Y
  101. * * Channel 3 is OpenAL -Z
  102. * Consequently, effects that only want to work with mono input can use
  103. * channel 0 by itself. Effects that want multichannel can process the
  104. * ambisonics signal and make a B-Format pan (ComputeFirstOrderGains) for
  105. * first-order device output (FOAOut).
  106. */
  107. alignas(16) ALfloat WetBuffer[MAX_EFFECT_CHANNELS][BUFFERSIZE];
  108. } ALeffectslot;
  109. inline void LockEffectSlotsRead(ALCcontext *context)
  110. { LockUIntMapRead(&context->EffectSlotMap); }
  111. inline void UnlockEffectSlotsRead(ALCcontext *context)
  112. { UnlockUIntMapRead(&context->EffectSlotMap); }
  113. inline void LockEffectSlotsWrite(ALCcontext *context)
  114. { LockUIntMapWrite(&context->EffectSlotMap); }
  115. inline void UnlockEffectSlotsWrite(ALCcontext *context)
  116. { UnlockUIntMapWrite(&context->EffectSlotMap); }
  117. inline struct ALeffectslot *LookupEffectSlot(ALCcontext *context, ALuint id)
  118. { return (struct ALeffectslot*)LookupUIntMapKeyNoLock(&context->EffectSlotMap, id); }
  119. inline struct ALeffectslot *RemoveEffectSlot(ALCcontext *context, ALuint id)
  120. { return (struct ALeffectslot*)RemoveUIntMapKeyNoLock(&context->EffectSlotMap, id); }
  121. ALenum InitEffectSlot(ALeffectslot *slot);
  122. void DeinitEffectSlot(ALeffectslot *slot);
  123. void UpdateEffectSlotProps(ALeffectslot *slot);
  124. void UpdateAllEffectSlotProps(ALCcontext *context);
  125. ALvoid ReleaseALAuxiliaryEffectSlots(ALCcontext *Context);
  126. ALeffectStateFactory *ALnullStateFactory_getFactory(void);
  127. ALeffectStateFactory *ALreverbStateFactory_getFactory(void);
  128. ALeffectStateFactory *ALchorusStateFactory_getFactory(void);
  129. ALeffectStateFactory *ALcompressorStateFactory_getFactory(void);
  130. ALeffectStateFactory *ALdistortionStateFactory_getFactory(void);
  131. ALeffectStateFactory *ALechoStateFactory_getFactory(void);
  132. ALeffectStateFactory *ALequalizerStateFactory_getFactory(void);
  133. ALeffectStateFactory *ALflangerStateFactory_getFactory(void);
  134. ALeffectStateFactory *ALmodulatorStateFactory_getFactory(void);
  135. ALeffectStateFactory *ALdedicatedStateFactory_getFactory(void);
  136. ALenum InitializeEffect(ALCdevice *Device, ALeffectslot *EffectSlot, ALeffect *effect);
  137. void InitEffectFactoryMap(void);
  138. void DeinitEffectFactoryMap(void);
  139. #ifdef __cplusplus
  140. }
  141. #endif
  142. #endif