Amuse
EffectReverb.hpp
1 #ifndef __AMUSE_EFFECTREVERB_HPP__
2 #define __AMUSE_EFFECTREVERB_HPP__
3 
4 #include "EffectBase.hpp"
5 #include "amuse/Common.hpp"
6 #include <memory>
7 
8 namespace amuse
9 {
10 
13 {
14  int32_t x0_inPoint = 0;
15  int32_t x4_outPoint = 0;
16  int32_t x8_length = 0;
17  std::unique_ptr<float[]> xc_inputs;
18  float x10_lastInput = 0.f;
19 
20  void allocate(int32_t delay);
21  void setdelay(int32_t delay);
22 };
23 
24 template <typename T>
26 
27 template <typename T>
29 
32 {
33 protected:
35  float x144_x1cc_mix;
39  bool m_dirty = true;
41  template <typename T>
42  friend class EffectReverbStdImp;
43  template <typename T>
44  friend class EffectReverbHiImp;
45  EffectReverbStd(float coloration, float mix, float time,
46  float damping, float preDelay);
47 public:
48  template <typename T>
50 
51  void setColoration(float coloration)
52  {
53  x140_x1c8_coloration = clamp(0.f, coloration, 1.f);
54  m_dirty = true;
55  }
56 
57  void setMix(float mix)
58  {
59  x144_x1cc_mix = clamp(0.f, mix, 1.f);
60  m_dirty = true;
61  }
62 
63  void setTime(float time)
64  {
65  x148_x1d0_time = clamp(0.01f, time, 10.f);
66  m_dirty = true;
67  }
68 
69  void setDamping(float damping)
70  {
71  x14c_x1d4_damping = clamp(0.f, damping, 1.f);
72  m_dirty = true;
73  }
74 
75  void setPreDelay(float preDelay)
76  {
77  x150_x1d8_preDelay = clamp(0.f, preDelay, 0.1f);
78  m_dirty = true;
79  }
80 };
81 
84 {
85  float x1dc_crosstalk;
87  template <typename T>
88  friend class EffectReverbHiImp;
89  EffectReverbHi(float coloration, float mix, float time,
90  float damping, float preDelay, float crosstalk);
91 public:
92  template <typename T>
94 
95  void setCrosstalk(float crosstalk)
96  {
97  x1dc_crosstalk = clamp(0.f, crosstalk, 1.f);
98  m_dirty = true;
99  }
100 };
101 
103 template <typename T>
104 class EffectReverbStdImp : public EffectBase<T>, public EffectReverbStd
105 {
106  ReverbDelayLine x0_AP[8][2] = {};
107  ReverbDelayLine x78_C[8][2] = {};
108  float xf0_allPassCoef = 0.f;
109  float xf4_combCoef[8][2] = {};
110  float x10c_lpLastout[8] = {};
111  float x118_level = 0.f;
112  float x11c_damping = 0.f;
113  int32_t x120_preDelayTime = 0;
114  std::unique_ptr<float[]> x124_preDelayLine[8];
115  float* x130_preDelayPtr[8] = {};
117  double m_sampleRate;
118  void _update();
119 public:
120  EffectReverbStdImp(float coloration, float mix, float time,
121  float damping, float preDelay, double sampleRate);
122  void applyEffect(T* audio, size_t frameCount, const ChannelMap& chanMap);
123 };
124 
126 template <typename T>
127 class EffectReverbHiImp : public EffectBase<T>, public EffectReverbHi
128 {
129  ReverbDelayLine x0_AP[8][2] = {};
130  ReverbDelayLine x78_LP[8] = {};
131  ReverbDelayLine xb4_C[8][3] = {};
132  float x168_allPassCoef = 0.f;
133  float x16c_combCoef[8][3] = {};
134  float x190_lpLastout[8] = {};
135  float x19c_level = 0.f;
136  float x1a0_damping = 0.f;
137  int32_t x1a4_preDelayTime = 0;
138  std::unique_ptr<float[]> x1ac_preDelayLine[8];
139  float* x1b8_preDelayPtr[8] = {};
140  float x1a8_internalCrosstalk;
141 
142  double m_sampleRate;
143  void _update();
144  void _handleReverb(T* audio, int chanIdx, int chanCount, int sampleCount);
145  void _doCrosstalk(T* audio, float wet, float dry, int chanCount, int sampleCount);
146 public:
147  EffectReverbHiImp(float coloration, float mix, float time,
148  float damping, float preDelay, float crosstalk, double sampleRate);
149  void applyEffect(T* audio, size_t frameCount, const ChannelMap& chanMap);
150 };
151 
152 }
153 
154 #endif // __AMUSE_EFFECTREVERB_HPP__