Amuse
Submix.hpp
1 #ifndef __AMUSE_SUBMIX_HPP__
2 #define __AMUSE_SUBMIX_HPP__
3 
4 #include <memory>
5 #include "SoundMacroState.hpp"
6 #include "IBackendSubmix.hpp"
7 #include "IBackendVoice.hpp"
8 #include "EffectBase.hpp"
9 #include "EffectChorus.hpp"
10 #include "EffectDelay.hpp"
11 #include "EffectReverb.hpp"
12 #include <unordered_set>
13 
14 namespace amuse
15 {
16 class IBackendSubmix;
17 class Sequencer;
18 
20 class Submix
21 {
22  friend class Engine;
23  friend class Voice;
24  friend class Sequencer;
25  Engine& m_root;
26  Submix* m_submix = nullptr;
27  std::list<Submix>::iterator m_engineIt;
28  std::unique_ptr<IBackendSubmix> m_backendSubmix;
29  std::vector<std::unique_ptr<EffectBaseTypeless>> m_effectStack;
30  bool m_destroyed = false;
31  void _destroy();
32 
33 public:
34  Submix(Engine& engine, Submix* smx);
35  ~Submix()
36  {
37 #ifndef NDEBUG
38  /* Ensure proper destruction procedure followed */
39  assert(m_destroyed);
40 #endif
41  }
42 
44  Submix* getParentSubmix() {return m_submix;}
45 
47  template <class T, class ...Args>
48  T& makeEffect(Args... args)
49  {
50  switch (m_backendSubmix->getSampleFormat())
51  {
52  case SubmixFormat::Int16:
53  {
54  using ImpType = typename T::template ImpType<int16_t>;
55  m_effectStack.emplace_back(new ImpType(args..., m_backendSubmix->getSampleRate()));
56  return static_cast<ImpType&>(*m_effectStack.back());
57  }
58  case SubmixFormat::Int32:
59  {
60  using ImpType = typename T::template ImpType<int32_t>;
61  m_effectStack.emplace_back(new ImpType(args..., m_backendSubmix->getSampleRate()));
62  return static_cast<ImpType&>(*m_effectStack.back());
63  }
64  case SubmixFormat::Float:
65  {
66  using ImpType = typename T::template ImpType<float>;
67  m_effectStack.emplace_back(new ImpType(args..., m_backendSubmix->getSampleRate()));
68  return static_cast<ImpType&>(*m_effectStack.back());
69  }
70  }
71  }
72 
74  EffectChorus& makeChorus(uint32_t baseDelay, uint32_t variation, uint32_t period);
75 
77  EffectDelay& makeDelay(uint32_t initDelay, uint32_t initFeedback, uint32_t initOutput);
78 
80  EffectReverbStd& makeReverbStd(float coloration, float mix, float time,
81  float damping, float preDelay);
82 
84  EffectReverbHi& makeReverbHi(float coloration, float mix, float time,
85  float damping, float preDelay, float crosstalk);
86 
88  void clearEffects() {m_effectStack.clear();}
89 
91  bool canApplyEffect() const {return m_effectStack.size() != 0;}
92 
94  void applyEffect(int16_t* audio, size_t frameCount, const ChannelMap& chanMap) const;
95 
97  void applyEffect(int32_t* audio, size_t frameCount, const ChannelMap& chanMap) const;
98 
100  void applyEffect(float* audio, size_t frameCount, const ChannelMap& chanMap) const;
101 
102  Engine& getEngine() {return m_root;}
103 };
104 
105 }
106 
107 #endif // __AMUSE_SUBMIX_HPP__
void applyEffect(int16_t *audio, size_t frameCount, const ChannelMap &chanMap) const
void clearEffects()
Definition: Submix.hpp:88
EffectReverbStd & makeReverbStd(float coloration, float mix, float time, float damping, float preDelay)
EffectChorus & makeChorus(uint32_t baseDelay, uint32_t variation, uint32_t period)
EffectReverbHi & makeReverbHi(float coloration, float mix, float time, float damping, float preDelay, float crosstalk)
Submix * getParentSubmix()
Definition: Submix.hpp:44
bool canApplyEffect() const
Definition: Submix.hpp:91
T & makeEffect(Args...args)
Definition: Submix.hpp:48
EffectDelay & makeDelay(uint32_t initDelay, uint32_t initFeedback, uint32_t initOutput)