alAuxEffectSlot.h 6.3 KB

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