Arduino STK  4.6.2
Mandolin.h
1 #ifndef STK_MANDOLIN_H
2 #define STK_MANDOLIN_H
3 
4 #include "Instrmnt.h"
5 #include "Twang.h"
6 #include "FileWvIn.h"
7 #include "MemoryWvIn.h"
8 
9 namespace stk {
10 
11 /***************************************************/
37 /***************************************************/
38 
39 class Mandolin : public Instrmnt
40 {
41  public:
43  Mandolin( StkFloat lowestFrequency );
44 
46  ~Mandolin( void );
47 
49  void clear( void );
50 
52  void setDetune( StkFloat detune );
53 
55  void setBodySize( StkFloat size );
56 
58  void setPluckPosition( StkFloat position );
59 
61  void setFrequency( StkFloat frequency );
62 
64  void pluck( StkFloat amplitude );
65 
67  void pluck( StkFloat amplitude,StkFloat position );
68 
70  void noteOn( StkFloat frequency, StkFloat amplitude );
71 
73  void noteOff( StkFloat amplitude );
74 
76  void controlChange( int number, StkFloat value );
77 
79  StkFloat tick( unsigned int channel = 0 );
80 
82 
89  StkFrames& tick( StkFrames& frames, unsigned int channel = 0 );
90 
91  protected:
92 
93  Twang strings_[2];
94 #ifdef __RAW_ARRAYS__
95  MemoryWvIn soundfile_[12];
96 #else
97  FileWvIn soundfile_[12];
98 #endif
99  int mic_;
100  StkFloat detuning_;
101  StkFloat frequency_;
102  StkFloat pluckAmplitude_;
103 };
104 
105 inline StkFloat Mandolin :: tick( unsigned int )
106 {
107  StkFloat temp = 0.0;
108  if ( !soundfile_[mic_].isFinished() )
109  temp = soundfile_[mic_].tick() * pluckAmplitude_;
110 
111  lastFrame_[0] = strings_[0].tick( temp );
112  lastFrame_[0] += strings_[1].tick( temp );
113  lastFrame_[0] *= 0.2;
114 
115  return lastFrame_[0];
116 }
117 
118 inline StkFrames& Mandolin :: tick( StkFrames& frames, unsigned int channel )
119 {
120  unsigned int nChannels = lastFrame_.channels();
121 #if defined(_STK_DEBUG_)
122  if ( channel > frames.channels() - nChannels ) {
123  oStream_ << "Mandolin::tick(): channel and StkFrames arguments are incompatible!";
124  handleError( StkError::FUNCTION_ARGUMENT );
125  }
126 #endif
127 
128  StkFloat *samples = &frames[channel];
129  unsigned int j, hop = frames.channels() - nChannels;
130  if ( nChannels == 1 ) {
131  for ( unsigned int i=0; i<frames.frames(); i++, samples += hop )
132  *samples++ = tick();
133  }
134  else {
135  for ( unsigned int i=0; i<frames.frames(); i++, samples += hop ) {
136  *samples++ = tick();
137  for ( j=1; j<nChannels; j++ )
138  *samples++ = lastFrame_[j];
139  }
140  }
141 
142  return frames;
143 }
144 
145 } // stk namespace
146 
147 #endif
STK audio file input class.
Definition: FileWvIn.h:53
virtual StkFloat tick(unsigned int channel=0)
Compute a sample frame and return the specified channel value.
STK instrument abstract base class.
Definition: Instrmnt.h:20
STK mandolin instrument model class.
Definition: Mandolin.h:40
void setBodySize(StkFloat size)
Set the body size (a value of 1.0 produces the "default" size).
void clear(void)
Reset and clear all internal state.
void pluck(StkFloat amplitude)
Pluck the strings with the given amplitude (0.0 - 1.0) using the current frequency.
void noteOff(StkFloat amplitude)
Stop a note with the given amplitude (speed of decay).
Mandolin(StkFloat lowestFrequency)
Class constructor, taking the lowest desired playing frequency.
void pluck(StkFloat amplitude, StkFloat position)
Pluck the strings with the given amplitude (0.0 - 1.0) and position (0.0 - 1.0).
void setPluckPosition(StkFloat position)
Set the pluck or "excitation" position along the string (0.0 - 1.0).
void noteOn(StkFloat frequency, StkFloat amplitude)
Start a note with the given frequency and amplitude (0.0 - 1.0).
~Mandolin(void)
Class destructor.
StkFloat tick(unsigned int channel=0)
Compute and return one output sample.
Definition: Mandolin.h:105
void controlChange(int number, StkFloat value)
Perform the control change specified by number and value (0.0 - 128.0).
void setDetune(StkFloat detune)
Detune the two strings by the given factor. A value of 1.0 produces unison strings.
void setFrequency(StkFloat frequency)
Set instrument parameters for a particular frequency.
STK audio input class from Memory.
Definition: MemoryWvIn.h:31
An STK class to handle vectorized audio data.
Definition: Stk.h:287
unsigned int channels(void) const
Return the number of channels represented by the data.
Definition: Stk.h:415
unsigned int frames(void) const
Return the number of sample frames represented by the data.
Definition: Stk.h:418
static void handleError(const char *message, StkError::Type type)
Static function for error reporting and handling using c-strings.
STK enhanced plucked string class.
Definition: Twang.h:35
StkFloat tick(StkFloat input)
Compute and return one output sample.
Definition: Twang.h:113
The STK namespace.
Definition: ADSR.h:8