🛠️🐜 Antkeeper superbuild with dependencies included https://antkeeper.com
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

277 lines
5.8 KiB

  1. #ifndef AL_AUXEFFECTSLOT_H
  2. #define AL_AUXEFFECTSLOT_H
  3. #include <atomic>
  4. #include <cstddef>
  5. #include "AL/al.h"
  6. #include "AL/alc.h"
  7. #include "AL/efx.h"
  8. #include "alc/device.h"
  9. #include "alc/effects/base.h"
  10. #include "almalloc.h"
  11. #include "atomic.h"
  12. #include "core/effectslot.h"
  13. #include "intrusive_ptr.h"
  14. #include "vector.h"
  15. #ifdef ALSOFT_EAX
  16. #include <memory>
  17. #include "eax_eax_call.h"
  18. #include "eax_effect.h"
  19. #include "eax_fx_slot_index.h"
  20. #endif // ALSOFT_EAX
  21. struct ALbuffer;
  22. struct ALeffect;
  23. struct WetBuffer;
  24. enum class SlotState : ALenum {
  25. Initial = AL_INITIAL,
  26. Playing = AL_PLAYING,
  27. Stopped = AL_STOPPED,
  28. };
  29. struct ALeffectslot {
  30. float Gain{1.0f};
  31. bool AuxSendAuto{true};
  32. ALeffectslot *Target{nullptr};
  33. ALbuffer *Buffer{nullptr};
  34. struct {
  35. EffectSlotType Type{EffectSlotType::None};
  36. EffectProps Props{};
  37. al::intrusive_ptr<EffectState> State;
  38. } Effect;
  39. bool mPropsDirty{true};
  40. SlotState mState{SlotState::Initial};
  41. RefCount ref{0u};
  42. EffectSlot mSlot;
  43. /* Self ID */
  44. ALuint id{};
  45. ALeffectslot();
  46. ALeffectslot(const ALeffectslot&) = delete;
  47. ALeffectslot& operator=(const ALeffectslot&) = delete;
  48. ~ALeffectslot();
  49. ALenum initEffect(ALenum effectType, const EffectProps &effectProps, ALCcontext *context);
  50. void updateProps(ALCcontext *context);
  51. /* This can be new'd for the context's default effect slot. */
  52. DEF_NEWDEL(ALeffectslot)
  53. #ifdef ALSOFT_EAX
  54. public:
  55. void eax_initialize(
  56. ALCcontext& al_context,
  57. EaxFxSlotIndexValue index);
  58. const EAX50FXSLOTPROPERTIES& eax_get_eax_fx_slot() const noexcept;
  59. // [[nodiscard]]
  60. bool eax_dispatch(const EaxEaxCall& eax_call)
  61. { return eax_call.is_get() ? eax_get(eax_call) : eax_set(eax_call); }
  62. void eax_unlock_legacy() noexcept;
  63. void eax_commit() { eax_apply_deferred(); }
  64. private:
  65. ALCcontext* eax_al_context_{};
  66. EaxFxSlotIndexValue eax_fx_slot_index_{};
  67. EAX50FXSLOTPROPERTIES eax_eax_fx_slot_{};
  68. EaxEffectUPtr eax_effect_{};
  69. bool eax_is_locked_{};
  70. [[noreturn]]
  71. static void eax_fail(
  72. const char* message);
  73. GUID eax_get_eax_default_effect_guid() const noexcept;
  74. long eax_get_eax_default_lock() const noexcept;
  75. void eax_set_eax_fx_slot_defaults();
  76. void eax_initialize_eax();
  77. void eax_initialize_lock();
  78. void eax_initialize_effects();
  79. void eax_get_fx_slot_all(
  80. const EaxEaxCall& eax_call) const;
  81. void eax_get_fx_slot(
  82. const EaxEaxCall& eax_call) const;
  83. // [[nodiscard]]
  84. bool eax_get(
  85. const EaxEaxCall& eax_call);
  86. void eax_set_fx_slot_effect(
  87. ALenum effect_type);
  88. void eax_set_fx_slot_effect();
  89. void eax_set_efx_effect_slot_gain();
  90. void eax_set_fx_slot_volume();
  91. void eax_set_effect_slot_send_auto();
  92. void eax_set_fx_slot_flags();
  93. void eax_ensure_is_unlocked() const;
  94. void eax_validate_fx_slot_effect(
  95. const GUID& eax_effect_id);
  96. void eax_validate_fx_slot_volume(
  97. long eax_volume);
  98. void eax_validate_fx_slot_lock(
  99. long eax_lock);
  100. void eax_validate_fx_slot_flags(
  101. unsigned long eax_flags,
  102. int eax_version);
  103. void eax_validate_fx_slot_occlusion(
  104. long eax_occlusion);
  105. void eax_validate_fx_slot_occlusion_lf_ratio(
  106. float eax_occlusion_lf_ratio);
  107. void eax_validate_fx_slot_all(
  108. const EAX40FXSLOTPROPERTIES& fx_slot,
  109. int eax_version);
  110. void eax_validate_fx_slot_all(
  111. const EAX50FXSLOTPROPERTIES& fx_slot,
  112. int eax_version);
  113. void eax_set_fx_slot_effect(
  114. const GUID& eax_effect_id);
  115. void eax_set_fx_slot_volume(
  116. long eax_volume);
  117. void eax_set_fx_slot_lock(
  118. long eax_lock);
  119. void eax_set_fx_slot_flags(
  120. unsigned long eax_flags);
  121. // [[nodiscard]]
  122. bool eax_set_fx_slot_occlusion(
  123. long eax_occlusion);
  124. // [[nodiscard]]
  125. bool eax_set_fx_slot_occlusion_lf_ratio(
  126. float eax_occlusion_lf_ratio);
  127. void eax_set_fx_slot_all(
  128. const EAX40FXSLOTPROPERTIES& eax_fx_slot);
  129. // [[nodiscard]]
  130. bool eax_set_fx_slot_all(
  131. const EAX50FXSLOTPROPERTIES& eax_fx_slot);
  132. void eax_set_fx_slot_effect(
  133. const EaxEaxCall& eax_call);
  134. void eax_set_fx_slot_volume(
  135. const EaxEaxCall& eax_call);
  136. void eax_set_fx_slot_lock(
  137. const EaxEaxCall& eax_call);
  138. void eax_set_fx_slot_flags(
  139. const EaxEaxCall& eax_call);
  140. // [[nodiscard]]
  141. bool eax_set_fx_slot_occlusion(
  142. const EaxEaxCall& eax_call);
  143. // [[nodiscard]]
  144. bool eax_set_fx_slot_occlusion_lf_ratio(
  145. const EaxEaxCall& eax_call);
  146. // [[nodiscard]]
  147. bool eax_set_fx_slot_all(
  148. const EaxEaxCall& eax_call);
  149. bool eax_set_fx_slot(
  150. const EaxEaxCall& eax_call);
  151. void eax_apply_deferred();
  152. // [[nodiscard]]
  153. bool eax_set(
  154. const EaxEaxCall& eax_call);
  155. void eax_dispatch_effect(
  156. const EaxEaxCall& eax_call);
  157. // `alAuxiliaryEffectSloti(effect_slot, AL_EFFECTSLOT_EFFECT, effect)`
  158. void eax_set_effect_slot_effect(EaxEffect &effect);
  159. // `alAuxiliaryEffectSloti(effect_slot, AL_EFFECTSLOT_AUXILIARY_SEND_AUTO, value)`
  160. void eax_set_effect_slot_send_auto(bool is_send_auto);
  161. // `alAuxiliaryEffectSlotf(effect_slot, AL_EFFECTSLOT_GAIN, gain)`
  162. void eax_set_effect_slot_gain(ALfloat gain);
  163. public:
  164. class EaxDeleter {
  165. public:
  166. void operator()(ALeffectslot *effect_slot);
  167. }; // EaxAlEffectSlotDeleter
  168. #endif // ALSOFT_EAX
  169. };
  170. void UpdateAllEffectSlotProps(ALCcontext *context);
  171. #ifdef ALSOFT_EAX
  172. using EaxAlEffectSlotUPtr = std::unique_ptr<ALeffectslot, ALeffectslot::EaxDeleter>;
  173. EaxAlEffectSlotUPtr eax_create_al_effect_slot(
  174. ALCcontext& context);
  175. void eax_delete_al_effect_slot(
  176. ALCcontext& context,
  177. ALeffectslot& effect_slot);
  178. #endif // ALSOFT_EAX
  179. #endif