45 Guitar(
unsigned int nStrings = 6, std::string bodyfile =
"" );
80 void noteOn( StkFloat frequency, StkFloat amplitude,
unsigned int string = 0 );
83 void noteOff( StkFloat amplitude,
unsigned int string = 0 );
93 StkFloat
lastOut(
void ) {
return lastFrame_[0]; };
96 StkFloat
tick( StkFloat input = 0.0 );
122 std::vector< stk::Twang > strings_;
123 std::vector< int > stringState_;
124 std::vector< unsigned int > decayCounter_;
125 std::vector< unsigned int > filePointer_;
126 std::vector< StkFloat > pluckGains_;
130 StkFloat couplingGain_;
138inline StkFloat Guitar :: tick( StkFloat input )
140 StkFloat temp, output = 0.0;
141 lastFrame_[0] = couplingGain_ * couplingFilter_.tick( lastFrame_[0] ) / strings_.
size();
142 for (
unsigned int i=0; i<strings_.size(); i++ ) {
143 if ( stringState_[i] ) {
146 if ( filePointer_[i] < excitation_.frames() && pluckGains_[i] > 0.2 )
147 temp += pluckGains_[i] * excitation_[filePointer_[i]++];
148 temp += lastFrame_[0];
149 output += strings_[i].tick( temp );
151 if ( stringState_[i] == 1 ) {
152 if ( fabs( strings_[i].lastOut() ) < 0.001 ) decayCounter_[i]++;
153 else decayCounter_[i] = 0;
154 if ( decayCounter_[i] > (
unsigned int) floor( 0.1 *
Stk::sampleRate() ) ) {
156 decayCounter_[i] = 0;
162 return lastFrame_[0] = output;
167#if defined(_STK_DEBUG_)
168 if ( channel >= frames.
channels() ) {
169 oStream_ <<
"Guitar::tick(): channel and StkFrames arguments are incompatible!";
170 handleError( StkError::FUNCTION_ARGUMENT );
174 StkFloat *samples = &frames[channel];
175 unsigned int hop = frames.
channels();
176 for (
unsigned int i=0; i<frames.
frames(); i++, samples += hop )
177 *samples = tick( *samples );
184#if defined(_STK_DEBUG_)
186 oStream_ <<
"Guitar::tick(): channel and StkFrames arguments are incompatible!";
187 handleError( StkError::FUNCTION_ARGUMENT );
191 StkFloat *iSamples = &iFrames[iChannel];
192 StkFloat *oSamples = &oFrames[oChannel];
194 for (
unsigned int i=0; i<iFrames.
frames(); i++, iSamples += iHop, oSamples += oHop )
195 *oSamples = tick( *iSamples );
STK guitar model class.
Definition Guitar.h:42
StkFloat tick(StkFloat input=0.0)
Take an optional input sample and compute one output sample.
Definition Guitar.h:138
void setPluckPosition(StkFloat position, int string=-1)
Set the pluck position for one or all strings.
Guitar(unsigned int nStrings=6, std::string bodyfile="")
Class constructor, specifying an arbitrary number of strings (default = 6).
void setFrequency(StkFloat frequency, unsigned int string=0)
Set instrument parameters for a particular frequency.
void setBodyFile(std::string bodyfile="")
Set the string excitation, using either a soundfile or computed noise.
void noteOn(StkFloat frequency, StkFloat amplitude, unsigned int string=0)
Start a note with the given frequency and amplitude.
void noteOff(StkFloat amplitude, unsigned int string=0)
Stop a note with the given amplitude (speed of decay).
void clear(void)
Reset and clear all internal state.
void setLoopGain(StkFloat gain, int string=-1)
Set the loop gain for one or all strings.
void controlChange(int number, StkFloat value, int string=-1)
Perform the control change specified by number and value (0.0 - 128.0).
StkFloat lastOut(void)
Return the last computed output value.
Definition Guitar.h:93
STK one-pole filter class.
Definition OnePole.h:21
An STK class to handle vectorized audio data.
Definition Stk.h:279
unsigned int channels(void) const
Return the number of channels represented by the data.
Definition Stk.h:416
unsigned int frames(void) const
Return the number of sample frames represented by the data.
Definition Stk.h:419
size_t size() const
Returns the total number of audio samples represented by the object.
Definition Stk.h:374
STK base class.
Definition Stk.h:136
static StkFloat sampleRate(void)
Static method that returns the current STK sample rate.
Definition Stk.h:148
The STK namespace.
Definition ADSR.h:6