Home   Information   Classes   Download   Usage   Mail List   Requirements   Links   FAQ   Tutorial


Twang.h
1 #ifndef STK_TWANG_H
2 #define STK_TWANG_H
3 
4 #include "Stk.h"
5 #include "DelayA.h"
6 #include "DelayL.h"
7 #include "Fir.h"
8 
9 namespace stk {
10 
11 /***************************************************/
32 /***************************************************/
33 
34 class Twang : public Stk
35 {
36  public:
38  Twang( StkFloat lowestFrequency = 50.0 );
39 
41  void clear( void );
42 
44  void setLowestFrequency( StkFloat frequency );
45 
47  void setFrequency( StkFloat frequency );
48 
50  void setPluckPosition( StkFloat position );
51 
53 
59  void setLoopGain( StkFloat loopGain );
60 
62 
67  void setLoopFilter( std::vector<StkFloat> coefficients );
68 
70  //const StkFrames& lastFrame( void ) const { return lastFrame_; };
71 
73  // StkFloat lastOut( void ) { return lastFrame_[0]; };
74  StkFloat lastOut( void ) { return lastOutput_; };
75 
77  StkFloat tick( StkFloat input );
78 
80 
88  StkFrames& tick( StkFrames& frames, unsigned int channel = 0 );
89 
91 
99  StkFrames& tick( StkFrames& iFrames, StkFrames &oFrames, unsigned int iChannel = 0, unsigned int oChannel = 0 );
100 
101  protected:
102 
103  DelayA delayLine_;
104  DelayL combDelay_;
105  Fir loopFilter_;
106 
107  StkFloat lastOutput_;
108  StkFloat frequency_;
109  StkFloat loopGain_;
110  StkFloat pluckPosition_;
111 };
112 
113 inline StkFloat Twang :: tick( StkFloat input )
114 {
115  lastOutput_ = delayLine_.tick( input + loopFilter_.tick( delayLine_.lastOut() ) );
116  lastOutput_ -= combDelay_.tick( lastOutput_ ); // comb filtering on output
117  lastOutput_ *= 0.5;
118 
119  return lastOutput_;
120 }
121 
122 inline StkFrames& Twang :: tick( StkFrames& frames, unsigned int channel )
123 {
124 #if defined(_STK_DEBUG_)
125  if ( channel >= frames.channels() ) {
126  oStream_ << "Twang::tick(): channel and StkFrames arguments are incompatible!";
127  handleError( StkError::FUNCTION_ARGUMENT );
128  }
129 #endif
130 
131  StkFloat *samples = &frames[channel];
132  unsigned int hop = frames.channels();
133  for ( unsigned int i=0; i<frames.frames(); i++, samples += hop )
134  *samples = tick( *samples );
135 
136  return frames;
137 }
138 
139 inline StkFrames& Twang :: tick( StkFrames& iFrames, StkFrames& oFrames, unsigned int iChannel, unsigned int oChannel )
140 {
141 #if defined(_STK_DEBUG_)
142  if ( iChannel >= iFrames.channels() || oChannel >= oFrames.channels() ) {
143  oStream_ << "Twang::tick(): channel and StkFrames arguments are incompatible!";
144  handleError( StkError::FUNCTION_ARGUMENT );
145  }
146 #endif
147 
148  StkFloat *iSamples = &iFrames[iChannel];
149  StkFloat *oSamples = &oFrames[oChannel];
150  unsigned int iHop = iFrames.channels(), oHop = oFrames.channels();
151  for ( unsigned int i=0; i<iFrames.frames(); i++, iSamples += iHop, oSamples += oHop )
152  *oSamples = tick( *iSamples );
153 
154  return iFrames;
155 }
156 
157 } // stk namespace
158 
159 #endif
160 

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