Home   Information   Classes   Download   Usage   Mail List   Requirements   Links   FAQ   Tutorial


Sitar.h
1 #ifndef STK_SITAR_H
2 #define STK_SITAR_H
3 
4 #include "Instrmnt.h"
5 #include "DelayA.h"
6 #include "OneZero.h"
7 #include "Noise.h"
8 #include "ADSR.h"
9 #include <cmath>
10 
11 namespace stk {
12 
13 /***************************************************/
30 /***************************************************/
31 
32 class Sitar : public Instrmnt
33 {
34  public:
36  Sitar( StkFloat lowestFrequency = 8.0 );
37 
39  ~Sitar( void );
40 
42  void clear( void );
43 
45  void setFrequency( StkFloat frequency );
46 
48  void pluck( StkFloat amplitude );
49 
51  void noteOn( StkFloat frequency, StkFloat amplitude );
52 
54  void noteOff( StkFloat amplitude );
55 
57  StkFloat tick( unsigned int channel = 0 );
58 
60 
67  StkFrames& tick( StkFrames& frames, unsigned int channel = 0 );
68 
69  protected:
70 
71  DelayA delayLine_;
72  OneZero loopFilter_;
73  Noise noise_;
74  ADSR envelope_;
75 
76  StkFloat loopGain_;
77  StkFloat amGain_;
78  StkFloat delay_;
79  StkFloat targetDelay_;
80 
81 };
82 
83 inline StkFloat Sitar :: tick( unsigned int )
84 {
85  if ( fabs(targetDelay_ - delay_) > 0.001 ) {
86  if ( targetDelay_ < delay_ )
87  delay_ *= 0.99999;
88  else
89  delay_ *= 1.00001;
90  delayLine_.setDelay( delay_ );
91  }
92 
93  lastFrame_[0] = delayLine_.tick( loopFilter_.tick( delayLine_.lastOut() * loopGain_ ) +
94  (amGain_ * envelope_.tick() * noise_.tick()));
95 
96  return lastFrame_[0];
97 }
98 
99 inline StkFrames& Sitar :: tick( StkFrames& frames, unsigned int channel )
100 {
101  unsigned int nChannels = lastFrame_.channels();
102 #if defined(_STK_DEBUG_)
103  if ( channel > frames.channels() - nChannels ) {
104  oStream_ << "Sitar::tick(): channel and StkFrames arguments are incompatible!";
105  handleError( StkError::FUNCTION_ARGUMENT );
106  }
107 #endif
108 
109  StkFloat *samples = &frames[channel];
110  unsigned int j, hop = frames.channels() - nChannels;
111  if ( nChannels == 1 ) {
112  for ( unsigned int i=0; i<frames.frames(); i++, samples += hop )
113  *samples++ = tick();
114  }
115  else {
116  for ( unsigned int i=0; i<frames.frames(); i++, samples += hop ) {
117  *samples++ = tick();
118  for ( j=1; j<nChannels; j++ )
119  *samples++ = lastFrame_[j];
120  }
121  }
122 
123  return frames;
124 }
125 
126 } // stk namespace
127 
128 #endif
129 
void clear(void)
Reset and clear all internal state.
static void handleError(const char *message, StkError::Type type)
Static function for error reporting and handling using c-strings.
StkFloat tick(void)
Compute and return one output sample.
Definition: Noise.h:59
~Sitar(void)
Class destructor.
StkFloat tick(StkFloat input)
Input one sample to the filter and return one output.
Definition: DelayA.h:137
unsigned int channels(void) const
Return the number of channels represented by the data.
Definition: Stk.h:377
STK sitar string model class.
Definition: Sitar.h:32
STK one-zero filter class.
Definition: OneZero.h:20
StkFloat tick(StkFloat input)
Input one sample to the filter and return one output.
Definition: OneZero.h:79
The STK namespace.
Definition: ADSR.h:6
StkFloat tick(unsigned int channel=0)
Compute and return one output sample.
Definition: Sitar.h:83
unsigned int frames(void) const
Return the number of sample frames represented by the data.
Definition: Stk.h:380
void noteOn(StkFloat frequency, StkFloat amplitude)
Start a note with the given frequency and amplitude.
void noteOff(StkFloat amplitude)
Stop a note with the given amplitude (speed of decay).
STK allpass interpolating delay line class.
Definition: DelayA.h:28
void pluck(StkFloat amplitude)
Pluck the string with the given amplitude using the current frequency.
STK ADSR envelope class.
Definition: ADSR.h:24
StkFloat lastOut(void) const
Return the last computed output value.
Definition: DelayA.h:80
void setFrequency(StkFloat frequency)
Set instrument parameters for a particular frequency.
An STK class to handle vectorized audio data.
Definition: Stk.h:272
STK instrument abstract base class.
Definition: Instrmnt.h:19
StkFloat tick(void)
Compute and return one output sample.
Definition: ADSR.h:115
STK noise generator.
Definition: Noise.h:21
Sitar(StkFloat lowestFrequency=8.0)
Class constructor, taking the lowest desired playing frequency.
void setDelay(StkFloat delay)
Set the delay-line length.

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