Home   Information   Classes   Download   Usage   Mail List   Requirements   Links   FAQ   Tutorial


PercFlut.h
1 #ifndef STK_PERCFLUT_H
2 #define STK_PERCFLUT_H
3 
4 #include "FM.h"
5 
6 namespace stk {
7 
8 /***************************************************/
34 /***************************************************/
35 
36 class PercFlut : public FM
37 {
38  public:
40 
43  PercFlut( void );
44 
46  ~PercFlut( void );
47 
49  void setFrequency( StkFloat frequency );
50 
52  void noteOn( StkFloat frequency, StkFloat amplitude );
53 
55  StkFloat tick( unsigned int channel = 0 );
56 
58 
65  StkFrames& tick( StkFrames& frames, unsigned int channel = 0 );
66 
67  protected:
68 
69 };
70 
71 inline StkFloat PercFlut :: tick( unsigned int )
72 {
73  StkFloat temp;
74 
75  temp = vibrato_.tick() * modDepth_ * 0.2;
76  waves_[0]->setFrequency(baseFrequency_ * (1.0 + temp) * ratios_[0]);
77  waves_[1]->setFrequency(baseFrequency_ * (1.0 + temp) * ratios_[1]);
78  waves_[2]->setFrequency(baseFrequency_ * (1.0 + temp) * ratios_[2]);
79  waves_[3]->setFrequency(baseFrequency_ * (1.0 + temp) * ratios_[3]);
80 
81  waves_[3]->addPhaseOffset( twozero_.lastOut() );
82  temp = gains_[3] * adsr_[3]->tick() * waves_[3]->tick();
83 
84  twozero_.tick(temp);
85  waves_[2]->addPhaseOffset( temp );
86  temp = (1.0 - (control2_ * 0.5)) * gains_[2] * adsr_[2]->tick() * waves_[2]->tick();
87 
88  temp += control2_ * 0.5 * gains_[1] * adsr_[1]->tick() * waves_[1]->tick();
89  temp = temp * control1_;
90 
91  waves_[0]->addPhaseOffset(temp);
92  temp = gains_[0] * adsr_[0]->tick() * waves_[0]->tick();
93 
94  lastFrame_[0] = temp * 0.5;
95  return lastFrame_[0];
96 }
97 
98 inline StkFrames& PercFlut :: tick( StkFrames& frames, unsigned int channel )
99 {
100  unsigned int nChannels = lastFrame_.channels();
101 #if defined(_STK_DEBUG_)
102  if ( channel > frames.channels() - nChannels ) {
103  oStream_ << "PercFlut::tick(): channel and StkFrames arguments are incompatible!";
104  handleError( StkError::FUNCTION_ARGUMENT );
105  }
106 #endif
107 
108  StkFloat *samples = &frames[channel];
109  unsigned int j, hop = frames.channels() - nChannels;
110  if ( nChannels == 1 ) {
111  for ( unsigned int i=0; i<frames.frames(); i++, samples += hop )
112  *samples++ = tick();
113  }
114  else {
115  for ( unsigned int i=0; i<frames.frames(); i++, samples += hop ) {
116  *samples++ = tick();
117  for ( j=1; j<nChannels; j++ )
118  *samples++ = lastFrame_[j];
119  }
120  }
121 
122  return frames;
123 }
124 
125 } // stk namespace
126 
127 #endif

The Synthesis ToolKit in C++ (STK)
©1995--2014 Perry R. Cook and Gary P. Scavone. All Rights Reserved.