Handle AL effect properties with a variant
[openal-soft.git] / core / effects / base.h
blobe939afbdf127f1245f29b28bd371bb6aec9c5986
1 #ifndef CORE_EFFECTS_BASE_H
2 #define CORE_EFFECTS_BASE_H
4 #include <array>
5 #include <cstddef>
6 #include <variant>
8 #include "alspan.h"
9 #include "core/bufferline.h"
10 #include "intrusive_ptr.h"
12 struct BufferStorage;
13 struct ContextBase;
14 struct DeviceBase;
15 struct EffectSlot;
16 struct MixParams;
17 struct RealMixParams;
20 /** Target gain for the reverb decay feedback reaching the decay time. */
21 inline constexpr float ReverbDecayGain{0.001f}; /* -60 dB */
23 inline constexpr float ReverbMaxReflectionsDelay{0.3f};
24 inline constexpr float ReverbMaxLateReverbDelay{0.1f};
26 enum class ChorusWaveform {
27 Sinusoid,
28 Triangle
31 inline constexpr float ChorusMaxDelay{0.016f};
32 inline constexpr float FlangerMaxDelay{0.004f};
34 inline constexpr float EchoMaxDelay{0.207f};
35 inline constexpr float EchoMaxLRDelay{0.404f};
37 enum class FShifterDirection {
38 Down,
39 Up,
40 Off
43 enum class ModulatorWaveform {
44 Sinusoid,
45 Sawtooth,
46 Square
49 enum class VMorpherPhenome {
50 A, E, I, O, U,
51 AA, AE, AH, AO, EH, ER, IH, IY, UH, UW,
52 B, D, F, G, J, K, L, M, N, P, R, S, T, V, Z
55 enum class VMorpherWaveform {
56 Sinusoid,
57 Triangle,
58 Sawtooth
61 struct ReverbProps {
62 float Density;
63 float Diffusion;
64 float Gain;
65 float GainHF;
66 float GainLF;
67 float DecayTime;
68 float DecayHFRatio;
69 float DecayLFRatio;
70 float ReflectionsGain;
71 float ReflectionsDelay;
72 std::array<float,3> ReflectionsPan;
73 float LateReverbGain;
74 float LateReverbDelay;
75 std::array<float,3> LateReverbPan;
76 float EchoTime;
77 float EchoDepth;
78 float ModulationTime;
79 float ModulationDepth;
80 float AirAbsorptionGainHF;
81 float HFReference;
82 float LFReference;
83 float RoomRolloffFactor;
84 bool DecayHFLimit;
87 struct AutowahProps {
88 float AttackTime;
89 float ReleaseTime;
90 float Resonance;
91 float PeakGain;
94 struct ChorusProps {
95 ChorusWaveform Waveform;
96 int Phase;
97 float Rate;
98 float Depth;
99 float Feedback;
100 float Delay;
103 struct CompressorProps {
104 bool OnOff;
107 struct DistortionProps {
108 float Edge;
109 float Gain;
110 float LowpassCutoff;
111 float EQCenter;
112 float EQBandwidth;
115 struct EchoProps {
116 float Delay;
117 float LRDelay;
119 float Damping;
120 float Feedback;
122 float Spread;
125 struct EqualizerProps {
126 float LowCutoff;
127 float LowGain;
128 float Mid1Center;
129 float Mid1Gain;
130 float Mid1Width;
131 float Mid2Center;
132 float Mid2Gain;
133 float Mid2Width;
134 float HighCutoff;
135 float HighGain;
138 struct FshifterProps {
139 float Frequency;
140 FShifterDirection LeftDirection;
141 FShifterDirection RightDirection;
144 struct ModulatorProps {
145 float Frequency;
146 float HighPassCutoff;
147 ModulatorWaveform Waveform;
150 struct PshifterProps {
151 int CoarseTune;
152 int FineTune;
155 struct VmorpherProps {
156 float Rate;
157 VMorpherPhenome PhonemeA;
158 VMorpherPhenome PhonemeB;
159 int PhonemeACoarseTuning;
160 int PhonemeBCoarseTuning;
161 VMorpherWaveform Waveform;
164 struct DedicatedProps {
165 enum TargetType : bool { Dialog, Lfe };
166 TargetType Target;
167 float Gain;
170 struct ConvolutionProps {
171 std::array<float,3> OrientAt;
172 std::array<float,3> OrientUp;
175 using EffectProps = std::variant<std::monostate,
176 ReverbProps,
177 AutowahProps,
178 ChorusProps,
179 CompressorProps,
180 DistortionProps,
181 EchoProps,
182 EqualizerProps,
183 FshifterProps,
184 ModulatorProps,
185 PshifterProps,
186 VmorpherProps,
187 DedicatedProps,
188 ConvolutionProps>;
191 struct EffectTarget {
192 MixParams *Main;
193 RealMixParams *RealOut;
196 struct EffectState : public al::intrusive_ref<EffectState> {
197 al::span<FloatBufferLine> mOutTarget;
200 virtual ~EffectState() = default;
202 virtual void deviceUpdate(const DeviceBase *device, const BufferStorage *buffer) = 0;
203 virtual void update(const ContextBase *context, const EffectSlot *slot,
204 const EffectProps *props, const EffectTarget target) = 0;
205 virtual void process(const size_t samplesToDo, const al::span<const FloatBufferLine> samplesIn,
206 const al::span<FloatBufferLine> samplesOut) = 0;
210 struct EffectStateFactory {
211 virtual ~EffectStateFactory() = default;
213 virtual al::intrusive_ptr<EffectState> create() = 0;
216 #endif /* CORE_EFFECTS_BASE_H */