YSE sound engine  1.0
cross platform sound engine
 All Classes Namespaces Functions Pages
ramp.hpp
1 /*
2  ==============================================================================
3 
4  ramp.h
5  Created: 31 Jan 2014 2:55:23pm
6  Author: yvan
7 
8  ==============================================================================
9 */
10 
11 #ifndef RAMP_H_INCLUDED
12 #define RAMP_H_INCLUDED
13 
14 #include "../headers/defines.hpp"
15 #include "sample.hpp"
16 
17 namespace YSE {
18 
19  namespace DSP {
20  class API ramp : public sample {
21  public:
22  ramp& set(Flt target, Int time = 0);
23  ramp& setIfNew(Flt target, Int time = 0);
24  ramp& stop();
25  ramp& update();
26  // TODO: check update and operator functions for consistency with other DSP objects
27  AUDIOBUFFER & operator()();
28  AUDIOBUFFER & getSample();
29  Flt getValue();
30 
31  ramp();
32  ramp(ramp &);
33 
34  private:
35  aFlt target;
36  aFlt time;
37  aFlt current;
38  aInt ticksLeft;
39  aBool reTarget;
40 
41  Flt _1overN;
42  Flt _dspTickToMSEC;
43  Flt inc, bigInc;
44  };
45 
46  class API lint {
47  // Linear interpolation towards target over time.
48  // This class does not use an audio buffer but adjusts
49  // one step for every time update is called.
50  // Update expects to be called at every new buffer
51  public:
52  lint& set(Flt target, Int time); // set new target and time
53  lint& setIfNew(Flt target, Int time); // set only if target is different from current target
54  lint& stop(); // sets target to current value
55  lint& update(); // call this once for every buffer update
56  Flt target(); // returns target
57  Flt operator()(); // returns current value
58  lint();
59  private:
60  aFlt targetValue, currentValue, step;
61  aBool up, calculate;
62  Flt stepSecond;
63  };
64 
65 
66 
67  // these functions are limited to the length of the buffer
68  void FastFadeIn(sample& s, UInt length);
69  void FastFadeOut(sample& s, UInt length);
70  void ChangeGain(sample& s, Flt currentGain, Flt newGain, UInt length);
71 
72 
73  }
74 }
75 
76 
77 
78 #endif // RAMP_H_INCLUDED