SpectMorph
smadsrenvelope.hh
1 // Licensed GNU LGPL v3 or later: http://www.gnu.org/licenses/lgpl.html
2 
3 #ifndef SPECTMORPH_ADSR_ENVELOPE_HH
4 #define SPECTMORPH_ADSR_ENVELOPE_HH
5 
6 #include <stddef.h>
7 
8 namespace SpectMorph {
9 
11 {
12  enum class State { ATTACK, DECAY, SUSTAIN, RELEASE, DONE };
13 
14  State state;
15  double level;
16  int attack_len;
17  int decay_len;
18  int release_len;
19  float sustain_level;
20 
21  struct SlopeParams {
22  int len;
23 
24  double factor; // exponential slope only
25  double delta; // exponential slope & linear slope
26  double end;
27 
28  bool linear;
29  } params;
30 
31  size_t process_params (size_t len, float *values);
32  void compute_slope_params (int len, float start_x, float end_x, State param_state);
33 public:
34  void set_config (float attack, float decay, float sustain, float release, float mix_freq);
35  void retrigger();
36  void release();
37  bool done() const;
38  void process (size_t n_values, float *values);
39 
40  // test only
41  void test_decay (int len, float start_x, float end_x);
42 };
43 
44 }
45 
46 #endif
Definition: smadsrenvelope.hh:8
Definition: smadsrenvelope.hh:10