Home   Information   Classes   Download   Usage   Mail List   Requirements   Links   FAQ   Tutorial


Twang.h
1#ifndef STK_TWANG_H
2#define STK_TWANG_H
3
4#include "Stk.h"
5#include "DelayA.h"
6#include "DelayL.h"
7#include "Fir.h"
8
9namespace stk {
10
11/***************************************************/
32/***************************************************/
33
34class Twang : public Stk
35{
36 public:
38 Twang( StkFloat lowestFrequency = 50.0 );
39
41 void clear( void );
42
44 void setLowestFrequency( StkFloat frequency );
45
47 void setFrequency( StkFloat frequency );
48
50 void setPluckPosition( StkFloat position );
51
53
59 void setLoopGain( StkFloat loopGain );
60
62
67 void setLoopFilter( std::vector<StkFloat> coefficients );
68
70 //const StkFrames& lastFrame( void ) const { return lastFrame_; };
71
73 // StkFloat lastOut( void ) { return lastFrame_[0]; };
74 StkFloat lastOut( void ) { return lastOutput_; };
75
77 StkFloat tick( StkFloat input );
78
80
88 StkFrames& tick( StkFrames& frames, unsigned int channel = 0 );
89
91
99 StkFrames& tick( StkFrames& iFrames, StkFrames &oFrames, unsigned int iChannel = 0, unsigned int oChannel = 0 );
100
101 protected:
102
103 DelayA delayLine_;
104 DelayL combDelay_;
105 Fir loopFilter_;
106
107 StkFloat lastOutput_;
108 StkFloat frequency_;
109 StkFloat loopGain_;
110 StkFloat pluckPosition_;
111};
112
113inline StkFloat Twang :: tick( StkFloat input )
114{
115 lastOutput_ = delayLine_.tick( input + loopFilter_.tick( delayLine_.lastOut() ) );
116 lastOutput_ -= combDelay_.tick( lastOutput_ ); // comb filtering on output
117 lastOutput_ *= 0.5;
118
119 return lastOutput_;
120}
121
122inline StkFrames& Twang :: tick( StkFrames& frames, unsigned int channel )
123{
124#if defined(_STK_DEBUG_)
125 if ( channel >= frames.channels() ) {
126 oStream_ << "Twang::tick(): channel and StkFrames arguments are incompatible!";
127 handleError( StkError::FUNCTION_ARGUMENT );
128 }
129#endif
130
131 StkFloat *samples = &frames[channel];
132 unsigned int hop = frames.channels();
133 for ( unsigned int i=0; i<frames.frames(); i++, samples += hop )
134 *samples = tick( *samples );
135
136 return frames;
137}
138
139inline StkFrames& Twang :: tick( StkFrames& iFrames, StkFrames& oFrames, unsigned int iChannel, unsigned int oChannel )
140{
141#if defined(_STK_DEBUG_)
142 if ( iChannel >= iFrames.channels() || oChannel >= oFrames.channels() ) {
143 oStream_ << "Twang::tick(): channel and StkFrames arguments are incompatible!";
144 handleError( StkError::FUNCTION_ARGUMENT );
145 }
146#endif
147
148 StkFloat *iSamples = &iFrames[iChannel];
149 StkFloat *oSamples = &oFrames[oChannel];
150 unsigned int iHop = iFrames.channels(), oHop = oFrames.channels();
151 for ( unsigned int i=0; i<iFrames.frames(); i++, iSamples += iHop, oSamples += oHop )
152 *oSamples = tick( *iSamples );
153
154 return iFrames;
155}
156
157} // stk namespace
158
159#endif
160
STK allpass interpolating delay line class.
Definition DelayA.h:29
STK linear interpolating delay line class.
Definition DelayL.h:28
STK general finite impulse response filter class.
Definition Fir.h:31
StkFloat tick(StkFloat input)
Input one sample to the filter and return one output.
Definition Fir.h:86
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
STK base class.
Definition Stk.h:136
STK enhanced plucked string class.
Definition Twang.h:35
void setFrequency(StkFloat frequency)
Set the delayline parameters for a particular frequency.
StkFloat tick(StkFloat input)
Compute and return one output sample.
Definition Twang.h:113
void setPluckPosition(StkFloat position)
Set the pluck or "excitation" position along the string (0.0 - 1.0).
void setLoopFilter(std::vector< StkFloat > coefficients)
Set the loop filter coefficients.
void clear(void)
Reset and clear all internal state.
Twang(StkFloat lowestFrequency=50.0)
Class constructor, taking the lowest desired playing frequency.
StkFloat lastOut(void)
Return an StkFrames reference to the last output sample frame.
Definition Twang.h:74
void setLoopGain(StkFloat loopGain)
Set the nominal loop gain.
void setLowestFrequency(StkFloat frequency)
Set the delayline parameters to allow frequencies as low as specified.
The STK namespace.
Definition ADSR.h:6

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