Home   Information   Classes   Download   Usage   Mail List   Requirements   Links   FAQ   Tutorial


Bowed.h
1 #ifndef STK_BOWED_H
2 #define STK_BOWED_H
3 
4 #include "Instrmnt.h"
5 #include "DelayL.h"
6 #include "BowTable.h"
7 #include "OnePole.h"
8 #include "BiQuad.h"
9 #include "SineWave.h"
10 #include "ADSR.h"
11 
12 namespace stk {
13 
14 /***************************************************/
38 /***************************************************/
39 
40 class Bowed : public Instrmnt
41 {
42  public:
44  Bowed( StkFloat lowestFrequency = 8.0 );
45 
47  ~Bowed( void );
48 
50  void clear( void );
51 
53  void setFrequency( StkFloat frequency );
54 
56  void setVibrato( StkFloat gain ) { vibratoGain_ = gain; };
57 
59  void startBowing( StkFloat amplitude, StkFloat rate );
60 
62  void stopBowing( StkFloat rate );
63 
65  void noteOn( StkFloat frequency, StkFloat amplitude );
66 
68  void noteOff( StkFloat amplitude );
69 
71  void controlChange( int number, StkFloat value );
72 
74  StkFloat tick( unsigned int channel = 0 );
75 
77 
84  StkFrames& tick( StkFrames& frames, unsigned int channel = 0 );
85 
86  protected:
87 
88  DelayL neckDelay_;
89  DelayL bridgeDelay_;
90  BowTable bowTable_;
91  OnePole stringFilter_;
92  BiQuad bodyFilters_[6];
93  SineWave vibrato_;
94  ADSR adsr_;
95 
96  bool bowDown_;
97  StkFloat maxVelocity_;
98  StkFloat baseDelay_;
99  StkFloat vibratoGain_;
100  StkFloat betaRatio_;
101 
102 };
103 
104 inline StkFloat Bowed :: tick( unsigned int )
105 {
106  StkFloat bowVelocity = maxVelocity_ * adsr_.tick();
107  StkFloat bridgeReflection = -stringFilter_.tick( bridgeDelay_.lastOut() );
108  StkFloat nutReflection = -neckDelay_.lastOut();
109  StkFloat stringVelocity = bridgeReflection + nutReflection;
110  StkFloat deltaV = bowVelocity - stringVelocity; // Differential velocity
111 
112  StkFloat newVelocity = 0.0;
113  if ( bowDown_ )
114  newVelocity = deltaV * bowTable_.tick( deltaV ); // Non-Linear bow function
115  neckDelay_.tick( bridgeReflection + newVelocity); // Do string propagations
116  bridgeDelay_.tick(nutReflection + newVelocity);
117 
118  if ( vibratoGain_ > 0.0 ) {
119  neckDelay_.setDelay( (baseDelay_ * (1.0 - betaRatio_) ) +
120  (baseDelay_ * vibratoGain_ * vibrato_.tick()) );
121  }
122 
123  lastFrame_[0] = 0.1248 * bodyFilters_[5].tick( bodyFilters_[4].tick( bodyFilters_[3].tick( bodyFilters_[2].tick( bodyFilters_[1].tick( bodyFilters_[0].tick( bridgeDelay_.lastOut() ) ) ) ) ) );
124 
125  return lastFrame_[0];
126 }
127 
128 inline StkFrames& Bowed :: tick( StkFrames& frames, unsigned int channel )
129 {
130  unsigned int nChannels = lastFrame_.channels();
131 #if defined(_STK_DEBUG_)
132  if ( channel > frames.channels() - nChannels ) {
133  oStream_ << "Bowed::tick(): channel and StkFrames arguments are incompatible!";
134  handleError( StkError::FUNCTION_ARGUMENT );
135  }
136 #endif
137 
138  StkFloat *samples = &frames[channel];
139  unsigned int j, hop = frames.channels() - nChannels;
140  if ( nChannels == 1 ) {
141  for ( unsigned int i=0; i<frames.frames(); i++, samples += hop )
142  *samples++ = tick();
143  }
144  else {
145  for ( unsigned int i=0; i<frames.frames(); i++, samples += hop ) {
146  *samples++ = tick();
147  for ( j=1; j<nChannels; j++ )
148  *samples++ = lastFrame_[j];
149  }
150  }
151 
152  return frames;
153 }
154 
155 } // stk namespace
156 
157 #endif
stk::OnePole
STK one-pole filter class.
Definition: OnePole.h:21
stk::Bowed::setVibrato
void setVibrato(StkFloat gain)
Set vibrato gain.
Definition: Bowed.h:56
stk::ADSR
STK ADSR envelope class.
Definition: ADSR.h:25
stk::SineWave
STK sinusoid oscillator class.
Definition: SineWave.h:26
stk::BowTable::tick
StkFloat tick(StkFloat input)
Take one sample input and map to one sample of output.
Definition: BowTable.h:84
stk::Bowed::Bowed
Bowed(StkFloat lowestFrequency=8.0)
Class constructor, taking the lowest desired playing frequency.
stk::StkFrames::frames
unsigned int frames(void) const
Return the number of sample frames represented by the data.
Definition: Stk.h:407
stk::BiQuad
STK biquad (two-pole, two-zero) filter class.
Definition: BiQuad.h:21
stk::Bowed
STK bowed string instrument class.
Definition: Bowed.h:41
stk::Bowed::~Bowed
~Bowed(void)
Class destructor.
stk::Bowed::stopBowing
void stopBowing(StkFloat rate)
Decrease breath pressure with given rate of decrease.
stk::OnePole::tick
StkFloat tick(StkFloat input)
Input one sample to the filter and return one output.
Definition: OnePole.h:80
stk::DelayL
STK linear interpolating delay line class.
Definition: DelayL.h:28
stk::Bowed::noteOn
void noteOn(StkFloat frequency, StkFloat amplitude)
Start a note with the given frequency and amplitude.
stk::DelayL::lastOut
StkFloat lastOut(void) const
Return the last computed output value.
Definition: DelayL.h:76
stk::StkFrames
An STK class to handle vectorized audio data.
Definition: Stk.h:276
stk::SineWave::tick
StkFloat tick(void)
Compute and return one output sample.
Definition: SineWave.h:99
stk::StkFrames::channels
unsigned int channels(void) const
Return the number of channels represented by the data.
Definition: Stk.h:404
stk::Bowed::controlChange
void controlChange(int number, StkFloat value)
Perform the control change specified by number and value (0.0 - 128.0).
stk::Stk::handleError
static void handleError(const char *message, StkError::Type type)
Static function for error reporting and handling using c-strings.
stk::Bowed::setFrequency
void setFrequency(StkFloat frequency)
Set instrument parameters for a particular frequency.
stk::Bowed::startBowing
void startBowing(StkFloat amplitude, StkFloat rate)
Apply breath pressure to instrument with given amplitude and rate of increase.
stk::Bowed::noteOff
void noteOff(StkFloat amplitude)
Stop a note with the given amplitude (speed of decay).
stk::DelayL::tick
StkFloat tick(StkFloat input)
Input one sample to the filter and return one output.
Definition: DelayL.h:163
stk::Bowed::clear
void clear(void)
Reset and clear all internal state.
stk::Bowed::tick
StkFloat tick(unsigned int channel=0)
Compute and return one output sample.
Definition: Bowed.h:104
stk::DelayL::setDelay
void setDelay(StkFloat delay)
Set the delay-line length.
Definition: DelayL.h:136
stk
The STK namespace.
Definition: ADSR.h:6
stk::ADSR::tick
StkFloat tick(void)
Compute and return one output sample.
Definition: ADSR.h:115
stk::Instrmnt
STK instrument abstract base class.
Definition: Instrmnt.h:20
stk::BiQuad::tick
StkFloat tick(StkFloat input)
Input one sample to the filter and return a reference to one output.
Definition: BiQuad.h:119
stk::BowTable
STK bowed string table class.
Definition: BowTable.h:23

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