Amuse
Envelope.hpp
1 #ifndef __AMUSE_ENVELOPE_HPP__
2 #define __AMUSE_ENVELOPE_HPP__
3 
4 #include "AudioGroupPool.hpp"
5 
6 namespace amuse
7 {
8 
10 class Envelope
11 {
12 public:
13  enum class State
14  {
15  Attack,
16  Decay,
17  Sustain,
18  Release,
19  Complete
20  };
21 private:
22  State m_phase = State::Attack;
23  double m_attackTime = 0.0;
24  double m_decayTime = 0.0;
25  double m_sustainFactor = 1.0;
26  double m_releaseTime = 0.0;
27  double m_releaseStartFactor;
28  double m_curTime;
29 public:
30  void reset(const ADSR* adsr);
31  void reset(const ADSRDLS* adsr, int8_t note, int8_t vel);
32  void keyOff();
33  float nextSample(double sampleRate);
34  bool isComplete() const {return m_phase == State::Complete;}
35 };
36 
37 }
38 
39 #endif // __AMUSE_ENVELOPE_HPP__