Move assume_aligned to opthelpers.h and define force_inline
[openal-soft.git] / core / effects / base.h
blob3094f627bfcc841815280029fea0e5833b9c0588
1 #ifndef CORE_EFFECTS_BASE_H
2 #define CORE_EFFECTS_BASE_H
4 #include <stddef.h>
6 #include "albyte.h"
7 #include "almalloc.h"
8 #include "alspan.h"
9 #include "atomic.h"
10 #include "core/bufferline.h"
11 #include "intrusive_ptr.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 constexpr float ReverbDecayGain{0.001f}; /* -60 dB */
24 constexpr float ReverbMaxReflectionsDelay{0.3f};
25 constexpr float ReverbMaxLateReverbDelay{0.1f};
27 enum class ChorusWaveform {
28 Sinusoid,
29 Triangle
32 constexpr float ChorusMaxDelay{0.016f};
33 constexpr float FlangerMaxDelay{0.004f};
35 constexpr float EchoMaxDelay{0.207f};
36 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 union EffectProps {
63 struct {
64 // Shared Reverb Properties
65 float Density;
66 float Diffusion;
67 float Gain;
68 float GainHF;
69 float DecayTime;
70 float DecayHFRatio;
71 float ReflectionsGain;
72 float ReflectionsDelay;
73 float LateReverbGain;
74 float LateReverbDelay;
75 float AirAbsorptionGainHF;
76 float RoomRolloffFactor;
77 bool DecayHFLimit;
79 // Additional EAX Reverb Properties
80 float GainLF;
81 float DecayLFRatio;
82 float ReflectionsPan[3];
83 float LateReverbPan[3];
84 float EchoTime;
85 float EchoDepth;
86 float ModulationTime;
87 float ModulationDepth;
88 float HFReference;
89 float LFReference;
90 } Reverb;
92 struct {
93 float AttackTime;
94 float ReleaseTime;
95 float Resonance;
96 float PeakGain;
97 } Autowah;
99 struct {
100 ChorusWaveform Waveform;
101 int Phase;
102 float Rate;
103 float Depth;
104 float Feedback;
105 float Delay;
106 } Chorus; /* Also Flanger */
108 struct {
109 bool OnOff;
110 } Compressor;
112 struct {
113 float Edge;
114 float Gain;
115 float LowpassCutoff;
116 float EQCenter;
117 float EQBandwidth;
118 } Distortion;
120 struct {
121 float Delay;
122 float LRDelay;
124 float Damping;
125 float Feedback;
127 float Spread;
128 } Echo;
130 struct {
131 float LowCutoff;
132 float LowGain;
133 float Mid1Center;
134 float Mid1Gain;
135 float Mid1Width;
136 float Mid2Center;
137 float Mid2Gain;
138 float Mid2Width;
139 float HighCutoff;
140 float HighGain;
141 } Equalizer;
143 struct {
144 float Frequency;
145 FShifterDirection LeftDirection;
146 FShifterDirection RightDirection;
147 } Fshifter;
149 struct {
150 float Frequency;
151 float HighPassCutoff;
152 ModulatorWaveform Waveform;
153 } Modulator;
155 struct {
156 int CoarseTune;
157 int FineTune;
158 } Pshifter;
160 struct {
161 float Rate;
162 VMorpherPhenome PhonemeA;
163 VMorpherPhenome PhonemeB;
164 int PhonemeACoarseTuning;
165 int PhonemeBCoarseTuning;
166 VMorpherWaveform Waveform;
167 } Vmorpher;
169 struct {
170 float Gain;
171 } Dedicated;
175 struct EffectTarget {
176 MixParams *Main;
177 RealMixParams *RealOut;
180 struct EffectState : public al::intrusive_ref<EffectState> {
181 struct Buffer {
182 const BufferStorage *storage;
183 al::span<const al::byte> samples;
186 al::span<FloatBufferLine> mOutTarget;
189 virtual ~EffectState() = default;
191 virtual void deviceUpdate(const DeviceBase *device, const Buffer &buffer) = 0;
192 virtual void update(const ContextBase *context, const EffectSlot *slot,
193 const EffectProps *props, const EffectTarget target) = 0;
194 virtual void process(const size_t samplesToDo, const al::span<const FloatBufferLine> samplesIn,
195 const al::span<FloatBufferLine> samplesOut) = 0;
199 struct EffectStateFactory {
200 virtual ~EffectStateFactory() = default;
202 virtual al::intrusive_ptr<EffectState> create() = 0;
205 #endif /* CORE_EFFECTS_BASE_H */