Track 5.1 Rear with WASAPI playback
[openal-soft.git] / al / auxeffectslot.h
blob83711372120950e4850f65ecb9ec62be4cf6d9ee
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>
21 #include "eax/call.h"
22 #include "eax/effect.h"
23 #include "eax/fx_slot_index.h"
24 #endif // ALSOFT_EAX
26 struct ALbuffer;
27 struct ALeffect;
28 struct WetBuffer;
31 enum class SlotState : ALenum {
32 Initial = AL_INITIAL,
33 Playing = AL_PLAYING,
34 Stopped = AL_STOPPED,
37 struct ALeffectslot {
38 float Gain{1.0f};
39 bool AuxSendAuto{true};
40 ALeffectslot *Target{nullptr};
41 ALbuffer *Buffer{nullptr};
43 struct {
44 EffectSlotType Type{EffectSlotType::None};
45 EffectProps Props{};
47 al::intrusive_ptr<EffectState> State;
48 } Effect;
50 bool mPropsDirty{true};
52 SlotState mState{SlotState::Initial};
54 RefCount ref{0u};
56 EffectSlot mSlot;
58 /* Self ID */
59 ALuint id{};
61 ALeffectslot();
62 ALeffectslot(const ALeffectslot&) = delete;
63 ALeffectslot& operator=(const ALeffectslot&) = delete;
64 ~ALeffectslot();
66 ALenum initEffect(ALenum effectType, const EffectProps &effectProps, ALCcontext *context);
67 void updateProps(ALCcontext *context);
69 /* This can be new'd for the context's default effect slot. */
70 DEF_NEWDEL(ALeffectslot)
73 #ifdef ALSOFT_EAX
74 public:
75 void eax_initialize(
76 const EaxCall& call,
77 ALCcontext& al_context,
78 EaxFxSlotIndexValue index);
80 const EAX50FXSLOTPROPERTIES& eax_get_eax_fx_slot() const noexcept;
83 // [[nodiscard]]
84 bool eax_dispatch(const EaxCall& call)
85 { return call.is_get() ? eax_get(call) : eax_set(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(const EaxCall& call);
121 void eax_get_fx_slot_all(const EaxCall& call) const;
123 void eax_get_fx_slot(const EaxCall& call) const;
125 // [[nodiscard]]
126 bool eax_get(const EaxCall& call);
129 void eax_set_fx_slot_effect(const EaxCall& call, ALenum effect_type);
131 void eax_set_fx_slot_effect(const EaxCall& call);
134 void eax_set_efx_effect_slot_gain();
136 void eax_set_fx_slot_volume();
139 void eax_set_effect_slot_send_auto();
141 void eax_set_fx_slot_flags();
144 void eax_ensure_is_unlocked() const;
146 void eax_validate_fx_slot_effect(const GUID& eax_effect_id);
147 void eax_validate_fx_slot_volume(long eax_volume);
148 void eax_validate_fx_slot_lock(long eax_lock);
149 void eax_validate_fx_slot_flags(const EaxCall& call, unsigned long eax_flags);
150 void eax_validate_fx_slot_occlusion(long eax_occlusion);
151 void eax_validate_fx_slot_occlusion_lf_ratio(float eax_occlusion_lf_ratio);
152 void eax_validate_fx_slot_all(const EaxCall& call, const EAX40FXSLOTPROPERTIES& fx_slot);
153 void eax_validate_fx_slot_all(const EaxCall& call, const EAX50FXSLOTPROPERTIES& fx_slot);
155 void eax_set_fx_slot_effect(const EaxCall& call, const GUID& eax_effect_id);
157 void eax_set_fx_slot_volume(
158 long eax_volume);
160 void eax_set_fx_slot_lock(
161 long eax_lock);
163 void eax_set_fx_slot_flags(
164 unsigned long eax_flags);
166 // [[nodiscard]]
167 bool eax_set_fx_slot_occlusion(
168 long eax_occlusion);
170 // [[nodiscard]]
171 bool eax_set_fx_slot_occlusion_lf_ratio(
172 float eax_occlusion_lf_ratio);
174 void eax_set_fx_slot_all(const EaxCall& call, const EAX40FXSLOTPROPERTIES& eax_fx_slot);
176 // [[nodiscard]]
177 bool eax_set_fx_slot_all(const EaxCall& call, const EAX50FXSLOTPROPERTIES& eax_fx_slot);
180 void eax_defer_fx_slot_effect(const EaxCall& call);
182 void eax_defer_fx_slot_volume(const EaxCall& call);
184 void eax_defer_fx_slot_lock(const EaxCall& call);
186 void eax_defer_fx_slot_flags(const EaxCall& call);
188 // [[nodiscard]]
189 bool eax_defer_fx_slot_occlusion(const EaxCall& call);
191 // [[nodiscard]]
192 bool eax_defer_fx_slot_occlusion_lf_ratio(const EaxCall& call);
194 // [[nodiscard]]
195 bool eax_defer_fx_slot_all(const EaxCall& call);
197 bool eax_set_fx_slot(const EaxCall& call);
199 void eax_apply_deferred();
201 // [[nodiscard]]
202 bool eax_set(const EaxCall& call);
205 void eax_dispatch_effect(const EaxCall& call);
208 // `alAuxiliaryEffectSloti(effect_slot, AL_EFFECTSLOT_EFFECT, effect)`
209 void eax_set_effect_slot_effect(EaxEffect &effect);
211 // `alAuxiliaryEffectSloti(effect_slot, AL_EFFECTSLOT_AUXILIARY_SEND_AUTO, value)`
212 void eax_set_effect_slot_send_auto(bool is_send_auto);
214 // `alAuxiliaryEffectSlotf(effect_slot, AL_EFFECTSLOT_GAIN, gain)`
215 void eax_set_effect_slot_gain(ALfloat gain);
217 public:
218 class EaxDeleter {
219 public:
220 void operator()(ALeffectslot *effect_slot);
221 }; // EaxAlEffectSlotDeleter
222 #endif // ALSOFT_EAX
225 void UpdateAllEffectSlotProps(ALCcontext *context);
227 #ifdef ALSOFT_EAX
229 using EaxAlEffectSlotUPtr = std::unique_ptr<ALeffectslot, ALeffectslot::EaxDeleter>;
232 EaxAlEffectSlotUPtr eax_create_al_effect_slot(
233 ALCcontext& context);
235 void eax_delete_al_effect_slot(
236 ALCcontext& context,
237 ALeffectslot& effect_slot);
238 #endif // ALSOFT_EAX
240 #endif