aboutsummaryrefslogtreecommitdiffstats
path: root/al/auxeffectslot.h
blob: 12213df65f1fea103857ce19fdc8f979103cfff0 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
#ifndef AL_AUXEFFECTSLOT_H
#define AL_AUXEFFECTSLOT_H

#include <atomic>
#include <cstddef>

#include "AL/al.h"
#include "AL/alc.h"
#include "AL/efx.h"

#include "alc/device.h"
#include "alc/effects/base.h"
#include "almalloc.h"
#include "atomic.h"
#include "core/effectslot.h"
#include "intrusive_ptr.h"
#include "vector.h"

#ifdef ALSOFT_EAX
#include <memory>

#include "al/effect.h"

#include "eax_eax_call.h"
#include "eax_fx_slot_index.h"
#endif // ALSOFT_EAX

struct ALbuffer;
struct ALeffect;
struct WetBuffer;


enum class SlotState : ALenum {
    Initial = AL_INITIAL,
    Playing = AL_PLAYING,
    Stopped = AL_STOPPED,
};

struct ALeffectslot {
    float Gain{1.0f};
    bool  AuxSendAuto{true};
    ALeffectslot *Target{nullptr};
    ALbuffer *Buffer{nullptr};

    struct {
        EffectSlotType Type{EffectSlotType::None};
        EffectProps Props{};

        al::intrusive_ptr<EffectState> State;
    } Effect;

    al::atomic_invflag mPropsDirty;

    SlotState mState{SlotState::Initial};

    RefCount ref{0u};

    EffectSlot mSlot;

    /* Self ID */
    ALuint id{};

    ALeffectslot();
    ALeffectslot(const ALeffectslot&) = delete;
    ALeffectslot& operator=(const ALeffectslot&) = delete;
    ~ALeffectslot();

    ALenum initEffect(ALeffect *effect, ALCcontext *context);
    void updateProps(ALCcontext *context);

    /* This can be new'd for the context's default effect slot. */
    DEF_NEWDEL(ALeffectslot)


#ifdef ALSOFT_EAX
public:
    void eax_initialize(
        ALCcontext& al_context,
        EaxFxSlotIndexValue index);

    void eax_uninitialize() noexcept;


    const EAX50FXSLOTPROPERTIES& eax_get_eax_fx_slot() const noexcept;


    // [[nodiscard]]
    bool eax_dispatch(
        const EaxEaxCall& eax_call);


private:
    ALCcontext* eax_al_context_{};

    EaxFxSlotIndexValue eax_fx_slot_index_{};

    EAX50FXSLOTPROPERTIES eax_eax_fx_slot_{};

    EaxAlEffectUPtr eax_al_effect_{};


    [[noreturn]]
    static void eax_fail(
        const char* message);


    void eax_set_eax_fx_slot_defaults();

    void eax_initialize_eax();


    void eax_initialize_effects();


    void eax_set_default_slot_0_defaults();

    void eax_set_default_slot_1_defaults();

    void eax_set_default_slots_defaults();


    void eax_get_fx_slot_all(
        const EaxEaxCall& eax_call) const;

    void eax_get_fx_slot(
        const EaxEaxCall& eax_call) const;

    // [[nodiscard]]
    bool eax_get(
        const EaxEaxCall& eax_call);


    void eax_set_fx_slot_effect(
        ALenum effect_type);

    void eax_set_fx_slot_effect();


    void eax_set_efx_effect_slot_gain();

    void eax_set_fx_slot_volume();


    void eax_set_effect_slot_send_auto();

    void eax_set_fx_slot_flags();


    void eax_validate_fx_slot_effect(
        const GUID& eax_effect_id);

    void eax_validate_fx_slot_volume(
        long eax_volume);

    void eax_validate_fx_slot_lock(
        long eax_lock);

    void eax_validate_fx_slot_lock_state(
        long eax_lock,
        const GUID& eax_effect_id);

    void eax_validate_fx_slot_flags(
        unsigned long eax_flags,
        int eax_version);

    void eax_validate_fx_slot_occlusion(
        long eax_occlusion);

    void eax_validate_fx_slot_occlusion_lf_ratio(
        float eax_occlusion_lf_ratio);

    void eax_validate_fx_slot_all(
        const EAX40FXSLOTPROPERTIES& fx_slot,
        int eax_version);

    void eax_validate_fx_slot_all(
        const EAX50FXSLOTPROPERTIES& fx_slot,
        int eax_version);


    void eax_set_fx_slot_effect(
        const GUID& eax_effect_id);

    void eax_set_fx_slot_volume(
        long eax_volume);

    void eax_set_fx_slot_lock(
        long eax_lock);

    void eax_set_fx_slot_flags(
        unsigned long eax_flags);

    // [[nodiscard]]
    bool eax_set_fx_slot_occlusion(
        long eax_occlusion);

    // [[nodiscard]]
    bool eax_set_fx_slot_occlusion_lf_ratio(
        float eax_occlusion_lf_ratio);

    void eax_set_fx_slot_all(
        const EAX40FXSLOTPROPERTIES& eax_fx_slot);

    // [[nodiscard]]
    bool eax_set_fx_slot_all(
        const EAX50FXSLOTPROPERTIES& eax_fx_slot);


    void eax_set_fx_slot_effect(
        const EaxEaxCall& eax_call);

    void eax_set_fx_slot_volume(
        const EaxEaxCall& eax_call);

    void eax_set_fx_slot_lock(
        const EaxEaxCall& eax_call);

    void eax_set_fx_slot_flags(
        const EaxEaxCall& eax_call);

    // [[nodiscard]]
    bool eax_set_fx_slot_occlusion(
        const EaxEaxCall& eax_call);

    // [[nodiscard]]
    bool eax_set_fx_slot_occlusion_lf_ratio(
        const EaxEaxCall& eax_call);

    // [[nodiscard]]
    bool eax_set_fx_slot_all(
        const EaxEaxCall& eax_call);

    bool eax_set_fx_slot(
        const EaxEaxCall& eax_call);

    // [[nodiscard]]
    bool eax_set(
        const EaxEaxCall& eax_call);


    void eax_dispatch_effect(
        const EaxEaxCall& eax_call);


    // `alAuxiliaryEffectSloti(effect_slot, AL_EFFECTSLOT_EFFECT, effect)`
    void eax_set_effect_slot_effect(
        ALeffect& effect);

    // `alAuxiliaryEffectSloti(effect_slot, AL_EFFECTSLOT_AUXILIARY_SEND_AUTO, value)`
    void eax_set_effect_slot_send_auto(
        bool is_send_auto);

    // `alAuxiliaryEffectSlotf(effect_slot, AL_EFFECTSLOT_GAIN, gain)`
    void eax_set_effect_slot_gain(
        ALfloat gain);
#endif // ALSOFT_EAX
};

void UpdateAllEffectSlotProps(ALCcontext *context);

#ifdef ALSOFT_EAX
class EaxAlEffectSlotDeleter
{
public:
    EaxAlEffectSlotDeleter() noexcept = default;

    EaxAlEffectSlotDeleter(
        ALCcontext& context) noexcept;

    void operator()(
        ALeffectslot* effect_slot);


private:
    ALCcontext* context_{};
}; // EaxAlEffectSlotDeleter

using EaxAlEffectSlotUPtr = std::unique_ptr<ALeffectslot, EaxAlEffectSlotDeleter>;


EaxAlEffectSlotUPtr eax_create_al_effect_slot(
    ALCcontext& context);

void eax_delete_al_effect_slot(
    ALCcontext& context,
    ALeffectslot& effect_slot);
#endif // ALSOFT_EAX

#endif