Home Information Classes Download Usage Mail List Requirements Links FAQ Tutorial

StifKarp.h
1 #ifndef STK_STIFKARP_H
2 #define STK_STIFKARP_H
3
4 #include "Instrmnt.h"
5 #include "DelayL.h"
6 #include "DelayA.h"
7 #include "OneZero.h"
8 #include "Noise.h"
9 #include "BiQuad.h"
10
11 namespace stk {
12
13 /***************************************************/
34 /***************************************************/
35
36 class StifKarp : public Instrmnt
37 {
38 public:
40 StifKarp( StkFloat lowestFrequency = 8.0 );
41
43 ~StifKarp( void );
44
46 void clear( void );
47
49 void setFrequency( StkFloat frequency );
50
52 void setStretch( StkFloat stretch );
53
55 void setPickupPosition( StkFloat position );
56
58
63 void setBaseLoopGain( StkFloat aGain );
64
66 void pluck( StkFloat amplitude );
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 DelayA delayLine_;
93 DelayL combDelay_;
94 OneZero filter_;
95 Noise noise_;
96 BiQuad biquad_[4];
97
98 unsigned long length_;
99 StkFloat loopGain_;
100 StkFloat baseLoopGain_;
101 StkFloat lastFrequency_;
102 StkFloat lastLength_;
103 StkFloat stretching_;
104 StkFloat pluckAmplitude_;
105 StkFloat pickupPosition_;
106
107 };
108
109 inline StkFloat StifKarp :: tick( unsigned int )
110 {
111 StkFloat temp = delayLine_.lastOut() * loopGain_;
112
113 // Calculate allpass stretching.
114 for (int i=0; i<4; i++)
115 temp = biquad_[i].tick(temp);
116
117 // Moving average filter.
118 temp = filter_.tick(temp);
119
120 lastFrame_[0] = delayLine_.tick(temp);
121 lastFrame_[0] = lastFrame_[0] - combDelay_.tick( lastFrame_[0] );
122 return lastFrame_[0];
123 }
124
125 inline StkFrames& StifKarp :: tick( StkFrames& frames, unsigned int channel )
126 {
127 unsigned int nChannels = lastFrame_.channels();
128 #if defined(_STK_DEBUG_)
129 if ( channel > frames.channels() - nChannels ) {
130 oStream_ << "StifKarp::tick(): channel and StkFrames arguments are incompatible!";
131 handleError( StkError::FUNCTION_ARGUMENT );
132 }
133 #endif
134
135 StkFloat *samples = &frames[channel];
136 unsigned int j, hop = frames.channels() - nChannels;
137 if ( nChannels == 1 ) {
138 for ( unsigned int i=0; i<frames.frames(); i++, samples += hop )
139 *samples++ = tick();
140 }
141 else {
142 for ( unsigned int i=0; i<frames.frames(); i++, samples += hop ) {
143 *samples++ = tick();
144 for ( j=1; j<nChannels; j++ )
145 *samples++ = lastFrame_[j];
146 }
147 }
148
149 return frames;
150 }
151
152 } // stk namespace
153
154 #endif

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