Amuse
EffectChorus.hpp
1 #ifndef __AMUSE_EFFECTCHORUS_HPP__
2 #define __AMUSE_EFFECTCHORUS_HPP__
3 
4 #include "EffectBase.hpp"
5 #include "Common.hpp"
6 #include <stdint.h>
7 
8 namespace amuse
9 {
10 template <typename T>
12 
13 #define AMUSE_CHORUS_NUM_BLOCKS 3
14 
17 {
18  uint32_t x90_baseDelay;
19  uint32_t x94_variation;
20  uint32_t x98_period;
21  bool m_dirty = true;
23  template <typename T>
24  friend class EffectChorusImp;
25  EffectChorus(uint32_t baseDelay, uint32_t variation, uint32_t period);
26 public:
27  template <typename T>
29 
30  void setBaseDelay(uint32_t baseDelay)
31  {
32  baseDelay = clamp(5u, baseDelay, 15u);
33  x90_baseDelay = baseDelay;
34  m_dirty = true;
35  }
36 
37  void setVariation(uint32_t variation)
38  {
39  variation = clamp(0u, variation, 5u);
40  x94_variation = variation;
41  m_dirty = true;
42  }
43 
44  void setPeriod(uint32_t period)
45  {
46  period = clamp(500u, period, 10000u);
47  x98_period = period;
48  m_dirty = true;
49  }
50 };
51 
53 template <typename T>
54 class EffectChorusImp : public EffectBase<T>, public EffectChorus
55 {
56  T* x0_lastChans[8][AMUSE_CHORUS_NUM_BLOCKS];
58  uint8_t x24_currentLast = 1;
59  T x28_oldChans[8][4] = {};
61  uint32_t x58_currentPosLo = 0;
62  uint32_t x5c_currentPosHi = 0;
64  int32_t x60_pitchOffset;
65  uint32_t x64_pitchOffsetPeriodCount;
66  uint32_t x68_pitchOffsetPeriod;
68  struct SrcInfo
69  {
70  T* x6c_dest;
71  T* x70_smpBase;
72  T* x74_old;
73  uint32_t x78_posLo;
74  uint32_t x7c_posHi;
75  uint32_t x80_pitchLo;
76  uint32_t x84_pitchHi;
77  uint32_t x88_trigger;
78  uint32_t x8c_target = 0;
80  void doSrc1(size_t blockSamples, size_t chanCount);
81  void doSrc2(size_t blockSamples, size_t chanCount);
82  } x6c_src;
83 
84  uint32_t m_sampsPerMs;
85  uint32_t m_blockSamples;
87  void _update();
88 
89 public:
90  ~EffectChorusImp();
91  EffectChorusImp(uint32_t baseDelay, uint32_t variation, uint32_t period, double sampleRate);
92  void applyEffect(T* audio, size_t frameCount, const ChannelMap& chanMap);
93 };
94 
95 }
96 
97 #endif // __AMUSE_EFFECTCHORUS_HPP__