Home   Information   Classes   Download   Usage   Mail List   Requirements   Links   FAQ   Tutorial


Flute.h
1 #ifndef STK_FLUTE_H
2 #define STK_FLUTE_H
3 
4 #include "Instrmnt.h"
5 #include "JetTable.h"
6 #include "DelayL.h"
7 #include "OnePole.h"
8 #include "PoleZero.h"
9 #include "Noise.h"
10 #include "ADSR.h"
11 #include "SineWave.h"
12 
13 namespace stk {
14 
15 /***************************************************/
37 /***************************************************/
38 
39 class Flute : public Instrmnt
40 {
41  public:
43 
46  Flute( StkFloat lowestFrequency );
47 
49  ~Flute( void );
50 
52  void clear( void );
53 
55  void setFrequency( StkFloat frequency );
56 
58  void setJetReflection( StkFloat coefficient ) { jetReflection_ = coefficient; };
59 
61  void setEndReflection( StkFloat coefficient ) { endReflection_ = coefficient; };
62 
64  void setJetDelay( StkFloat aRatio );
65 
67  void startBlowing( StkFloat amplitude, StkFloat rate );
68 
70  void stopBlowing( StkFloat rate );
71 
73  void noteOn( StkFloat frequency, StkFloat amplitude );
74 
76  void noteOff( StkFloat amplitude );
77 
79  void controlChange( int number, StkFloat value );
80 
82  StkFloat tick( unsigned int channel = 0 );
83 
85 
92  StkFrames& tick( StkFrames& frames, unsigned int channel = 0 );
93 
94  protected:
95 
96  DelayL jetDelay_;
97  DelayL boreDelay_;
98  JetTable jetTable_;
99  OnePole filter_;
100  PoleZero dcBlock_;
101  Noise noise_;
102  ADSR adsr_;
103  SineWave vibrato_;
104 
105  StkFloat lastFrequency_;
106  StkFloat maxPressure_;
107  StkFloat jetReflection_;
108  StkFloat endReflection_;
109  StkFloat noiseGain_;
110  StkFloat vibratoGain_;
111  StkFloat outputGain_;
112  StkFloat jetRatio_;
113 
114 };
115 
116 inline StkFloat Flute :: tick( unsigned int )
117 {
118  StkFloat pressureDiff;
119  StkFloat breathPressure;
120 
121  // Calculate the breath pressure (envelope + noise + vibrato)
122  breathPressure = maxPressure_ * adsr_.tick();
123  breathPressure += breathPressure * ( noiseGain_ * noise_.tick() + vibratoGain_ * vibrato_.tick() );
124 
125  StkFloat temp = -filter_.tick( boreDelay_.lastOut() );
126  //temp = dcBlock_.tick( temp ); // Block DC on reflection.
127 
128  pressureDiff = breathPressure - (jetReflection_ * temp);
129  pressureDiff = jetDelay_.tick( pressureDiff );
130  //pressureDiff = jetTable_.tick( pressureDiff ) + (endReflection_ * temp);
131  pressureDiff = dcBlock_.tick(jetTable_.tick( pressureDiff )) + (endReflection_ * temp); // moved the DC blocker to after the jet non-linearity (GPS, 29 Jan. 2020)
132  lastFrame_[0] = (StkFloat) 0.3 * boreDelay_.tick( pressureDiff );
133 
134  lastFrame_[0] *= outputGain_;
135  return lastFrame_[0];
136 }
137 
138 inline StkFrames& Flute :: tick( StkFrames& frames, unsigned int channel )
139 {
140  unsigned int nChannels = lastFrame_.channels();
141 #if defined(_STK_DEBUG_)
142  if ( channel > frames.channels() - nChannels ) {
143  oStream_ << "Flute::tick(): channel and StkFrames arguments are incompatible!";
144  handleError( StkError::FUNCTION_ARGUMENT );
145  }
146 #endif
147 
148  StkFloat *samples = &frames[channel];
149  unsigned int j, hop = frames.channels() - nChannels;
150  if ( nChannels == 1 ) {
151  for ( unsigned int i=0; i<frames.frames(); i++, samples += hop )
152  *samples++ = tick();
153  }
154  else {
155  for ( unsigned int i=0; i<frames.frames(); i++, samples += hop ) {
156  *samples++ = tick();
157  for ( j=1; j<nChannels; j++ )
158  *samples++ = lastFrame_[j];
159  }
160  }
161 
162  return frames;
163 }
164 
165 } // stk namespace
166 
167 #endif

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