🛠️🐜 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.

240 lines
5.6 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/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. const EaxCall& call,
  57. ALCcontext& al_context,
  58. EaxFxSlotIndexValue index);
  59. const EAX50FXSLOTPROPERTIES& eax_get_eax_fx_slot() const noexcept;
  60. // [[nodiscard]]
  61. bool eax_dispatch(const EaxCall& call)
  62. { return call.is_get() ? eax_get(call) : eax_set(call); }
  63. void eax_unlock_legacy() noexcept;
  64. void eax_commit() { eax_apply_deferred(); }
  65. private:
  66. ALCcontext* eax_al_context_{};
  67. EaxFxSlotIndexValue eax_fx_slot_index_{};
  68. EAX50FXSLOTPROPERTIES eax_eax_fx_slot_{};
  69. EaxEffectUPtr eax_effect_{};
  70. bool eax_is_locked_{};
  71. [[noreturn]]
  72. static void eax_fail(
  73. const char* message);
  74. GUID eax_get_eax_default_effect_guid() const noexcept;
  75. long eax_get_eax_default_lock() const noexcept;
  76. void eax_set_eax_fx_slot_defaults();
  77. void eax_initialize_eax();
  78. void eax_initialize_lock();
  79. void eax_initialize_effects(const EaxCall& call);
  80. void eax_get_fx_slot_all(const EaxCall& call) const;
  81. void eax_get_fx_slot(const EaxCall& call) const;
  82. // [[nodiscard]]
  83. bool eax_get(const EaxCall& call);
  84. void eax_set_fx_slot_effect(const EaxCall& call, ALenum effect_type);
  85. void eax_set_fx_slot_effect(const EaxCall& call);
  86. void eax_set_efx_effect_slot_gain();
  87. void eax_set_fx_slot_volume();
  88. void eax_set_effect_slot_send_auto();
  89. void eax_set_fx_slot_flags();
  90. void eax_ensure_is_unlocked() const;
  91. void eax_validate_fx_slot_effect(const GUID& eax_effect_id);
  92. void eax_validate_fx_slot_volume(long eax_volume);
  93. void eax_validate_fx_slot_lock(long eax_lock);
  94. void eax_validate_fx_slot_flags(const EaxCall& call, unsigned long eax_flags);
  95. void eax_validate_fx_slot_occlusion(long eax_occlusion);
  96. void eax_validate_fx_slot_occlusion_lf_ratio(float eax_occlusion_lf_ratio);
  97. void eax_validate_fx_slot_all(const EaxCall& call, const EAX40FXSLOTPROPERTIES& fx_slot);
  98. void eax_validate_fx_slot_all(const EaxCall& call, const EAX50FXSLOTPROPERTIES& fx_slot);
  99. void eax_set_fx_slot_effect(const EaxCall& call, const GUID& eax_effect_id);
  100. void eax_set_fx_slot_volume(
  101. long eax_volume);
  102. void eax_set_fx_slot_lock(
  103. long eax_lock);
  104. void eax_set_fx_slot_flags(
  105. unsigned long eax_flags);
  106. // [[nodiscard]]
  107. bool eax_set_fx_slot_occlusion(
  108. long eax_occlusion);
  109. // [[nodiscard]]
  110. bool eax_set_fx_slot_occlusion_lf_ratio(
  111. float eax_occlusion_lf_ratio);
  112. void eax_set_fx_slot_all(const EaxCall& call, const EAX40FXSLOTPROPERTIES& eax_fx_slot);
  113. // [[nodiscard]]
  114. bool eax_set_fx_slot_all(const EaxCall& call, const EAX50FXSLOTPROPERTIES& eax_fx_slot);
  115. void eax_defer_fx_slot_effect(const EaxCall& call);
  116. void eax_defer_fx_slot_volume(const EaxCall& call);
  117. void eax_defer_fx_slot_lock(const EaxCall& call);
  118. void eax_defer_fx_slot_flags(const EaxCall& call);
  119. // [[nodiscard]]
  120. bool eax_defer_fx_slot_occlusion(const EaxCall& call);
  121. // [[nodiscard]]
  122. bool eax_defer_fx_slot_occlusion_lf_ratio(const EaxCall& call);
  123. // [[nodiscard]]
  124. bool eax_defer_fx_slot_all(const EaxCall& call);
  125. bool eax_set_fx_slot(const EaxCall& call);
  126. void eax_apply_deferred();
  127. // [[nodiscard]]
  128. bool eax_set(const EaxCall& call);
  129. void eax_dispatch_effect(const EaxCall& call);
  130. // `alAuxiliaryEffectSloti(effect_slot, AL_EFFECTSLOT_EFFECT, effect)`
  131. void eax_set_effect_slot_effect(EaxEffect &effect);
  132. // `alAuxiliaryEffectSloti(effect_slot, AL_EFFECTSLOT_AUXILIARY_SEND_AUTO, value)`
  133. void eax_set_effect_slot_send_auto(bool is_send_auto);
  134. // `alAuxiliaryEffectSlotf(effect_slot, AL_EFFECTSLOT_GAIN, gain)`
  135. void eax_set_effect_slot_gain(ALfloat gain);
  136. public:
  137. class EaxDeleter {
  138. public:
  139. void operator()(ALeffectslot *effect_slot);
  140. }; // EaxAlEffectSlotDeleter
  141. #endif // ALSOFT_EAX
  142. };
  143. void UpdateAllEffectSlotProps(ALCcontext *context);
  144. #ifdef ALSOFT_EAX
  145. using EaxAlEffectSlotUPtr = std::unique_ptr<ALeffectslot, ALeffectslot::EaxDeleter>;
  146. EaxAlEffectSlotUPtr eax_create_al_effect_slot(
  147. ALCcontext& context);
  148. void eax_delete_al_effect_slot(
  149. ALCcontext& context,
  150. ALeffectslot& effect_slot);
  151. #endif // ALSOFT_EAX
  152. #endif