Reject older versions of PipeWire than built against
[openal-soft.git] / al / auxeffectslot.h
blobca0dcd3105f50205cc42fb6ffaa2d7fbbfc6c5af
1 #ifndef AL_AUXEFFECTSLOT_H
2 #define AL_AUXEFFECTSLOT_H
4 #include <atomic>
5 #include <cstddef>
7 #include "AL/al.h"
8 #include "AL/alc.h"
9 #include "AL/efx.h"
11 #include "alc/device.h"
12 #include "alc/effects/base.h"
13 #include "almalloc.h"
14 #include "atomic.h"
15 #include "core/effectslot.h"
16 #include "intrusive_ptr.h"
17 #include "vector.h"
19 #ifdef ALSOFT_EAX
20 #include <memory>
22 #include "eax_eax_call.h"
23 #include "eax_effect.h"
24 #include "eax_fx_slot_index.h"
25 #endif // ALSOFT_EAX
27 struct ALbuffer;
28 struct ALeffect;
29 struct WetBuffer;
32 enum class SlotState : ALenum {
33 Initial = AL_INITIAL,
34 Playing = AL_PLAYING,
35 Stopped = AL_STOPPED,
38 struct ALeffectslot {
39 float Gain{1.0f};
40 bool AuxSendAuto{true};
41 ALeffectslot *Target{nullptr};
42 ALbuffer *Buffer{nullptr};
44 struct {
45 EffectSlotType Type{EffectSlotType::None};
46 EffectProps Props{};
48 al::intrusive_ptr<EffectState> State;
49 } Effect;
51 bool mPropsDirty{true};
53 SlotState mState{SlotState::Initial};
55 RefCount ref{0u};
57 EffectSlot mSlot;
59 /* Self ID */
60 ALuint id{};
62 ALeffectslot();
63 ALeffectslot(const ALeffectslot&) = delete;
64 ALeffectslot& operator=(const ALeffectslot&) = delete;
65 ~ALeffectslot();
67 ALenum initEffect(ALenum effectType, const EffectProps &effectProps, ALCcontext *context);
68 void updateProps(ALCcontext *context);
70 /* This can be new'd for the context's default effect slot. */
71 DEF_NEWDEL(ALeffectslot)
74 #ifdef ALSOFT_EAX
75 public:
76 void eax_initialize(
77 ALCcontext& al_context,
78 EaxFxSlotIndexValue index);
80 const EAX50FXSLOTPROPERTIES& eax_get_eax_fx_slot() const noexcept;
83 // [[nodiscard]]
84 bool eax_dispatch(const EaxEaxCall& eax_call)
85 { return eax_call.is_get() ? eax_get(eax_call) : eax_set(eax_call); }
88 void eax_unlock_legacy() noexcept;
90 void eax_commit() { eax_apply_deferred(); }
92 private:
93 ALCcontext* eax_al_context_{};
95 EaxFxSlotIndexValue eax_fx_slot_index_{};
97 EAX50FXSLOTPROPERTIES eax_eax_fx_slot_{};
99 EaxEffectUPtr eax_effect_{};
100 bool eax_is_locked_{};
103 [[noreturn]]
104 static void eax_fail(
105 const char* message);
108 GUID eax_get_eax_default_effect_guid() const noexcept;
109 long eax_get_eax_default_lock() const noexcept;
111 void eax_set_eax_fx_slot_defaults();
113 void eax_initialize_eax();
115 void eax_initialize_lock();
118 void eax_initialize_effects();
121 void eax_get_fx_slot_all(
122 const EaxEaxCall& eax_call) const;
124 void eax_get_fx_slot(
125 const EaxEaxCall& eax_call) const;
127 // [[nodiscard]]
128 bool eax_get(
129 const EaxEaxCall& eax_call);
132 void eax_set_fx_slot_effect(
133 ALenum effect_type);
135 void eax_set_fx_slot_effect();
138 void eax_set_efx_effect_slot_gain();
140 void eax_set_fx_slot_volume();
143 void eax_set_effect_slot_send_auto();
145 void eax_set_fx_slot_flags();
148 void eax_ensure_is_unlocked() const;
151 void eax_validate_fx_slot_effect(
152 const GUID& eax_effect_id);
154 void eax_validate_fx_slot_volume(
155 long eax_volume);
157 void eax_validate_fx_slot_lock(
158 long eax_lock);
160 void eax_validate_fx_slot_flags(
161 unsigned long eax_flags,
162 int eax_version);
164 void eax_validate_fx_slot_occlusion(
165 long eax_occlusion);
167 void eax_validate_fx_slot_occlusion_lf_ratio(
168 float eax_occlusion_lf_ratio);
170 void eax_validate_fx_slot_all(
171 const EAX40FXSLOTPROPERTIES& fx_slot,
172 int eax_version);
174 void eax_validate_fx_slot_all(
175 const EAX50FXSLOTPROPERTIES& fx_slot,
176 int eax_version);
179 void eax_set_fx_slot_effect(
180 const GUID& eax_effect_id);
182 void eax_set_fx_slot_volume(
183 long eax_volume);
185 void eax_set_fx_slot_lock(
186 long eax_lock);
188 void eax_set_fx_slot_flags(
189 unsigned long eax_flags);
191 // [[nodiscard]]
192 bool eax_set_fx_slot_occlusion(
193 long eax_occlusion);
195 // [[nodiscard]]
196 bool eax_set_fx_slot_occlusion_lf_ratio(
197 float eax_occlusion_lf_ratio);
199 void eax_set_fx_slot_all(
200 const EAX40FXSLOTPROPERTIES& eax_fx_slot);
202 // [[nodiscard]]
203 bool eax_set_fx_slot_all(
204 const EAX50FXSLOTPROPERTIES& eax_fx_slot);
207 void eax_set_fx_slot_effect(
208 const EaxEaxCall& eax_call);
210 void eax_set_fx_slot_volume(
211 const EaxEaxCall& eax_call);
213 void eax_set_fx_slot_lock(
214 const EaxEaxCall& eax_call);
216 void eax_set_fx_slot_flags(
217 const EaxEaxCall& eax_call);
219 // [[nodiscard]]
220 bool eax_set_fx_slot_occlusion(
221 const EaxEaxCall& eax_call);
223 // [[nodiscard]]
224 bool eax_set_fx_slot_occlusion_lf_ratio(
225 const EaxEaxCall& eax_call);
227 // [[nodiscard]]
228 bool eax_set_fx_slot_all(
229 const EaxEaxCall& eax_call);
231 bool eax_set_fx_slot(
232 const EaxEaxCall& eax_call);
234 void eax_apply_deferred();
236 // [[nodiscard]]
237 bool eax_set(
238 const EaxEaxCall& eax_call);
241 void eax_dispatch_effect(
242 const EaxEaxCall& eax_call);
245 // `alAuxiliaryEffectSloti(effect_slot, AL_EFFECTSLOT_EFFECT, effect)`
246 void eax_set_effect_slot_effect(EaxEffect &effect);
248 // `alAuxiliaryEffectSloti(effect_slot, AL_EFFECTSLOT_AUXILIARY_SEND_AUTO, value)`
249 void eax_set_effect_slot_send_auto(bool is_send_auto);
251 // `alAuxiliaryEffectSlotf(effect_slot, AL_EFFECTSLOT_GAIN, gain)`
252 void eax_set_effect_slot_gain(ALfloat gain);
254 public:
255 class EaxDeleter {
256 public:
257 void operator()(ALeffectslot *effect_slot);
258 }; // EaxAlEffectSlotDeleter
259 #endif // ALSOFT_EAX
262 void UpdateAllEffectSlotProps(ALCcontext *context);
264 #ifdef ALSOFT_EAX
266 using EaxAlEffectSlotUPtr = std::unique_ptr<ALeffectslot, ALeffectslot::EaxDeleter>;
269 EaxAlEffectSlotUPtr eax_create_al_effect_slot(
270 ALCcontext& context);
272 void eax_delete_al_effect_slot(
273 ALCcontext& context,
274 ALeffectslot& effect_slot);
275 #endif // ALSOFT_EAX
277 #endif