33 Cubic(
void ) : a1_(0.5), a2_(0.5), a3_(0.5), gain_(1.0), threshold_(1.0) {};
36 void setA1( StkFloat a1 ) { a1_ = a1; };
39 void setA2( StkFloat a2 ) { a2_ = a2; };
42 void setA3( StkFloat a3 ) { a3_ = a3; };
45 void setGain( StkFloat gain ) { gain_ = gain; };
48 void setThreshold( StkFloat threshold ) { threshold_ = threshold; };
51 StkFloat
tick( StkFloat input );
86 StkFloat inSquared = input * input;
87 StkFloat inCubed = inSquared * input;
89 lastFrame_[0] = gain_ * (a1_ * input + a2_ * inSquared + a3_ * inCubed);
92 if ( fabs( lastFrame_[0] ) > threshold_ ) {
93 lastFrame_[0] = ( lastFrame_[0] < 0 ? -threshold_ : threshold_ );
101 #if defined(_STK_DEBUG_)
102 if ( channel >= frames.
channels() ) {
103 oStream_ <<
"Cubic::tick(): channel and StkFrames arguments are incompatible!";
108 StkFloat *samples = &frames[channel];
109 unsigned int hop = frames.
channels();
110 for (
unsigned int i=0; i<frames.
frames(); i++, samples += hop )
111 *samples =
tick( *samples );
113 lastFrame_[0] = *(samples-hop);
119 #if defined(_STK_DEBUG_)
121 oStream_ <<
"Cubic::tick(): channel and StkFrames arguments are incompatible!";
126 StkFloat *iSamples = &iFrames[iChannel];
127 StkFloat *oSamples = &oFrames[oChannel];
129 for (
unsigned int i=0; i<iFrames.
frames(); i++, iSamples += iHop, oSamples += oHop )
130 *oSamples =
tick( *iSamples );
132 lastFrame_[0] = *(oSamples-oHop);
STK cubic non-linearity class.
Definition: Cubic.h:30
void setThreshold(StkFloat threshold)
Set the threshold value.
Definition: Cubic.h:48
Cubic(void)
Default constructor.
Definition: Cubic.h:33
StkFloat tick(StkFloat input)
Input one sample to the function and return one output.
Definition: Cubic.h:84
void setGain(StkFloat gain)
Set the gain value.
Definition: Cubic.h:45
void setA3(StkFloat a3)
Set the a3 coefficient value.
Definition: Cubic.h:42
void setA1(StkFloat a1)
Set the a1 coefficient value.
Definition: Cubic.h:36
void setA2(StkFloat a2)
Set the a2 coefficient value.
Definition: Cubic.h:39
STK abstract function parent class.
Definition: Function.h:21
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.
The STK namespace.
Definition: ADSR.h:8