The Synthesis ToolKit in C++ (STK)

Home Information Classes Download Usage Mail List Requirements Links FAQ Tutorial

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
8 namespace stk {
9
10 /***************************************************/
36 /***************************************************/
37
38 class Mandolin : public Instrmnt
39 {
40 public:
42 Mandolin( StkFloat lowestFrequency );
43
45 ~Mandolin( void );
46
48 void clear( void );
49
51 void setDetune( StkFloat detune );
52
54 void setBodySize( StkFloat size );
55
57 void setPluckPosition( StkFloat position );
58
60 void setFrequency( StkFloat frequency );
61
63 void pluck( StkFloat amplitude );
64
66 void pluck( StkFloat amplitude,StkFloat position );
67
69 void noteOn( StkFloat frequency, StkFloat amplitude );
70
72 void noteOff( StkFloat amplitude );
73
75 void controlChange( int number, StkFloat value );
76
78 StkFloat tick( unsigned int channel = 0 );
79
81
88 StkFrames& tick( StkFrames& frames, unsigned int channel = 0 );
89
90 protected:
91
92 Twang strings_[2];
93 FileWvIn soundfile_[12];
94
95 int mic_;
96 StkFloat detuning_;
97 StkFloat frequency_;
98 StkFloat pluckAmplitude_;
99 };
100
101 inline StkFloat Mandolin :: tick( unsigned int )
102 {
103 StkFloat temp = 0.0;
104 if ( !soundfile_[mic_].isFinished() )
105 temp = soundfile_[mic_].tick() * pluckAmplitude_;
106
107 lastFrame_[0] = strings_[0].tick( temp );
108 lastFrame_[0] += strings_[1].tick( temp );
109 lastFrame_[0] *= 0.2;
110
111 return lastFrame_[0];
112 }
113
114 inline StkFrames& Mandolin :: tick( StkFrames& frames, unsigned int channel )
115 {
116 unsigned int nChannels = lastFrame_.channels();
117 #if defined(_STK_DEBUG_)
118 if ( channel > frames.channels() - nChannels ) {
119 oStream_ << "Mandolin::tick(): channel and StkFrames arguments are incompatible!";
120 handleError( StkError::FUNCTION_ARGUMENT );
121 }
122 #endif
123
124 StkFloat *samples = &frames[channel];
125 unsigned int j, hop = frames.channels() - nChannels;
126 if ( nChannels == 1 ) {
127 for ( unsigned int i=0; i<frames.frames(); i++, samples += hop )
128 *samples++ = tick();
129 }
130 else {
131 for ( unsigned int i=0; i<frames.frames(); i++, samples += hop ) {
132 *samples++ = tick();
133 for ( j=1; j<nChannels; j++ )
134 *samples++ = lastFrame_[j];
135 }
136 }
137
138 return frames;
139 }
140
141 } // stk namespace
142
143 #endif

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