Jamoma API  0.6.0.a19
CrossFade.h
1 // CrossFade.h
2 /***************************************************/
3 /*! \class CrossFade
4  \brief CrossFade class
5 
6  This class implements a crossfade event, which occurs
7  when a delay time changes quickly enough that the old
8  delay time must be crossfaded with the new delay time.
9 
10  by Tristan Matthews and Nils Peters, 2007-2008.
11  */
12 /***************************************************/
13 
14 #ifndef _CROSSFADE_H_
15 #define _CROSSFADE_H_
16 
17 #include "Properties.h"
18 #include "CrossFadeQueue.h"
19 #include <cassert>
20 
21 class CrossFade {
22  private:
23  CrossFadeQueue &owner_;
24  long fadeLength_;
25  long fadeInIdx_;
26  long fadeOutIdx_;
27  double fadeInGain_;
28  double fadeOutGain_;
29  void updateGains();
30 
31  public:
32  //! Class constructor, takes CrossFadeQueue that owns it.
33  CrossFade(CrossFadeQueue &owner);
34 
35  //! Returns true if the CrossFade is at step 0.
36  bool atStart() const;
37 
38  //! updates the CrossFade with a new fadelength.
39  void update(long fadeLength);
40 
41  //! Outputs crossfade of two samples.
42  double tick(double fadeInInput, double fadeOutInput);
43 
44  //! Increments the pointer to the crossfade table.
45  void increment();
46 
47  //! Class destructor.
48  ~CrossFade() {};
49 };
50 
51 inline double CrossFade::tick(double fadeInInput, double fadeOutInput)
52 {
53  //post("fadeOutGain: %f, fadeInGain: %f, sumgains %f", fadeOutGain_, fadeInGain_, fadeOutGain_ + fadeInGain_);
54  return ((double) fadeInInput * fadeInGain_) + ((double) fadeOutInput * fadeOutGain_);
55 }
56 
57 inline void CrossFade::increment()
58 {
59  fadeOutIdx_++;
60  fadeInIdx_--;
61 
62  if (fadeOutIdx_ >= fadeLength_) // fade is finished
63  {
64  assert(fadeInIdx_ < 0);
65  owner_.finishFade(); // TODO: check if this is safe
66  }
67  else
68  updateGains();
69 }
70 
71 #endif
72 // vim:sw=4:et:cindent:
CrossFade(CrossFadeQueue &owner)
Class constructor, takes CrossFadeQueue that owns it.
~CrossFade()
Class destructor.
Definition: CrossFade.h:48
double tick(double fadeInInput, double fadeOutInput)
Outputs crossfade of two samples.
Definition: CrossFade.h:51
CrossFade class.
Definition: CrossFade.h:21
void increment()
Increments the pointer to the crossfade table.
Definition: CrossFade.h:57
bool atStart() const
Returns true if the CrossFade is at step 0.
CrossFadeQueue class.
void finishFade()
Manages cleanup and end of crossfade.
void update(long fadeLength)
updates the CrossFade with a new fadelength.