Separate ALCdevice from the implementation
[openal-soft.git] / core / effects / base.h
blob879f83900549448e799a19fb4d465553c263b6fc
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"
11 #include "opthelpers.h"
13 struct BufferStorage;
14 struct ContextBase;
15 struct DeviceBase;
16 struct EffectSlot;
17 struct MixParams;
18 struct RealMixParams;
21 /** Target gain for the reverb decay feedback reaching the decay time. */
22 inline constexpr float ReverbDecayGain{0.001f}; /* -60 dB */
24 inline constexpr float ReverbMaxReflectionsDelay{0.3f};
25 inline constexpr float ReverbMaxLateReverbDelay{0.1f};
27 enum class ChorusWaveform {
28 Sinusoid,
29 Triangle
32 inline constexpr float ChorusMaxDelay{0.016f};
33 inline constexpr float FlangerMaxDelay{0.004f};
35 inline constexpr float EchoMaxDelay{0.207f};
36 inline constexpr float EchoMaxLRDelay{0.404f};
38 enum class FShifterDirection {
39 Down,
40 Up,
41 Off
44 enum class ModulatorWaveform {
45 Sinusoid,
46 Sawtooth,
47 Square
50 enum class VMorpherPhenome {
51 A, E, I, O, U,
52 AA, AE, AH, AO, EH, ER, IH, IY, UH, UW,
53 B, D, F, G, J, K, L, M, N, P, R, S, T, V, Z
56 enum class VMorpherWaveform {
57 Sinusoid,
58 Triangle,
59 Sawtooth
62 struct ReverbProps {
63 float Density;
64 float Diffusion;
65 float Gain;
66 float GainHF;
67 float GainLF;
68 float DecayTime;
69 float DecayHFRatio;
70 float DecayLFRatio;
71 float ReflectionsGain;
72 float ReflectionsDelay;
73 std::array<float,3> ReflectionsPan;
74 float LateReverbGain;
75 float LateReverbDelay;
76 std::array<float,3> LateReverbPan;
77 float EchoTime;
78 float EchoDepth;
79 float ModulationTime;
80 float ModulationDepth;
81 float AirAbsorptionGainHF;
82 float HFReference;
83 float LFReference;
84 float RoomRolloffFactor;
85 bool DecayHFLimit;
88 struct AutowahProps {
89 float AttackTime;
90 float ReleaseTime;
91 float Resonance;
92 float PeakGain;
95 struct ChorusProps {
96 ChorusWaveform Waveform;
97 int Phase;
98 float Rate;
99 float Depth;
100 float Feedback;
101 float Delay;
104 struct CompressorProps {
105 bool OnOff;
108 struct DistortionProps {
109 float Edge;
110 float Gain;
111 float LowpassCutoff;
112 float EQCenter;
113 float EQBandwidth;
116 struct EchoProps {
117 float Delay;
118 float LRDelay;
120 float Damping;
121 float Feedback;
123 float Spread;
126 struct EqualizerProps {
127 float LowCutoff;
128 float LowGain;
129 float Mid1Center;
130 float Mid1Gain;
131 float Mid1Width;
132 float Mid2Center;
133 float Mid2Gain;
134 float Mid2Width;
135 float HighCutoff;
136 float HighGain;
139 struct FshifterProps {
140 float Frequency;
141 FShifterDirection LeftDirection;
142 FShifterDirection RightDirection;
145 struct ModulatorProps {
146 float Frequency;
147 float HighPassCutoff;
148 ModulatorWaveform Waveform;
151 struct PshifterProps {
152 int CoarseTune;
153 int FineTune;
156 struct VmorpherProps {
157 float Rate;
158 VMorpherPhenome PhonemeA;
159 VMorpherPhenome PhonemeB;
160 int PhonemeACoarseTuning;
161 int PhonemeBCoarseTuning;
162 VMorpherWaveform Waveform;
165 struct DedicatedProps {
166 enum TargetType : bool { Dialog, Lfe };
167 TargetType Target;
168 float Gain;
171 struct ConvolutionProps {
172 std::array<float,3> OrientAt;
173 std::array<float,3> OrientUp;
176 using EffectProps = std::variant<std::monostate,
177 ReverbProps,
178 AutowahProps,
179 ChorusProps,
180 CompressorProps,
181 DistortionProps,
182 EchoProps,
183 EqualizerProps,
184 FshifterProps,
185 ModulatorProps,
186 PshifterProps,
187 VmorpherProps,
188 DedicatedProps,
189 ConvolutionProps>;
192 struct EffectTarget {
193 MixParams *Main;
194 RealMixParams *RealOut;
197 struct SIMDALIGN EffectState : public al::intrusive_ref<EffectState> {
198 al::span<FloatBufferLine> mOutTarget;
201 virtual ~EffectState() = default;
203 virtual void deviceUpdate(const DeviceBase *device, const BufferStorage *buffer) = 0;
204 virtual void update(const ContextBase *context, const EffectSlot *slot,
205 const EffectProps *props, const EffectTarget target) = 0;
206 virtual void process(const size_t samplesToDo, const al::span<const FloatBufferLine> samplesIn,
207 const al::span<FloatBufferLine> samplesOut) = 0;
211 struct EffectStateFactory {
212 EffectStateFactory() = default;
213 EffectStateFactory(const EffectStateFactory&) = delete;
214 EffectStateFactory(EffectStateFactory&&) = delete;
215 virtual ~EffectStateFactory() = default;
217 void operator=(const EffectStateFactory&) = delete;
218 void operator=(EffectStateFactory&&) = delete;
220 virtual al::intrusive_ptr<EffectState> create() = 0;
223 #endif /* CORE_EFFECTS_BASE_H */