The Synthesis ToolKit in C++ (STK)

Home Information Classes Download Usage Mail List Requirements Links FAQ Tutorial

FormSwep.h
1#ifndef STK_FORMSWEP_H
2#define STK_FORMSWEP_H
3
4#include "Filter.h"
5
6namespace stk {
7
8/***************************************************/
18/***************************************************/
19
20 class FormSwep : public Filter
21{
22 public:
23
25 FormSwep( void );
26
28 ~FormSwep();
29
31 void ignoreSampleRateChange( bool ignore = true ) { ignoreSampleRateChange_ = ignore; };
32
34
47 void setResonance( StkFloat frequency, StkFloat radius );
48
50 void setStates( StkFloat frequency, StkFloat radius, StkFloat gain = 1.0 );
51
53 void setTargets( StkFloat frequency, StkFloat radius, StkFloat gain = 1.0 );
54
56
64 void setSweepRate( StkFloat rate );
65
67
72 void setSweepTime( StkFloat time );
73
75 StkFloat lastOut( void ) const { return lastFrame_[0]; };
76
78 StkFloat tick( StkFloat input );
79
81
89 StkFrames& tick( StkFrames& frames, unsigned int channel = 0 );
90
92
100 StkFrames& tick( StkFrames& iFrames, StkFrames &oFrames, unsigned int iChannel = 0, unsigned int oChannel = 0 );
101
102 protected:
103
104 virtual void sampleRateChanged( StkFloat newRate, StkFloat oldRate );
105
106 bool dirty_;
107 StkFloat frequency_;
108 StkFloat radius_;
109 StkFloat startFrequency_;
110 StkFloat startRadius_;
111 StkFloat startGain_;
112 StkFloat targetFrequency_;
113 StkFloat targetRadius_;
114 StkFloat targetGain_;
115 StkFloat deltaFrequency_;
116 StkFloat deltaRadius_;
117 StkFloat deltaGain_;
118 StkFloat sweepState_;
119 StkFloat sweepRate_;
120
121};
122
123 inline StkFloat FormSwep :: tick( StkFloat input )
124{
125 if ( dirty_ ) {
126 sweepState_ += sweepRate_;
127 if ( sweepState_ >= 1.0 ) {
128 sweepState_ = 1.0;
129 dirty_ = false;
130 radius_ = targetRadius_;
131 frequency_ = targetFrequency_;
132 gain_ = targetGain_;
133 }
134 else {
135 radius_ = startRadius_ + (deltaRadius_ * sweepState_);
136 frequency_ = startFrequency_ + (deltaFrequency_ * sweepState_);
137 gain_ = startGain_ + (deltaGain_ * sweepState_);
138 }
139 this->setResonance( frequency_, radius_ );
140 }
141
142 inputs_[0] = gain_ * input;
143 lastFrame_[0] = b_[0] * inputs_[0] + b_[1] * inputs_[1] + b_[2] * inputs_[2];
144 lastFrame_[0] -= a_[2] * outputs_[2] + a_[1] * outputs_[1];
145 inputs_[2] = inputs_[1];
146 inputs_[1] = inputs_[0];
147 outputs_[2] = outputs_[1];
148 outputs_[1] = lastFrame_[0];
149
150 return lastFrame_[0];
151}
152
153 inline StkFrames& FormSwep :: tick( StkFrames& frames, unsigned int channel )
154{
155#if defined(_STK_DEBUG_)
156 if ( channel >= frames.channels() ) {
157 oStream_ << "FormSwep::tick(): channel and StkFrames arguments are incompatible!";
158 handleError( StkError::FUNCTION_ARGUMENT );
159 }
160#endif
161
162 StkFloat *samples = &frames[channel];
163 unsigned int hop = frames.channels();
164 for ( unsigned int i=0; i<frames.frames(); i++, samples += hop )
165 *samples = tick( *samples );
166
167 return frames;
168}
169
170 inline StkFrames& FormSwep :: tick( StkFrames& iFrames, StkFrames& oFrames, unsigned int iChannel, unsigned int oChannel )
171{
172#if defined(_STK_DEBUG_)
173 if ( iChannel >= iFrames.channels() || oChannel >= oFrames.channels() ) {
174 oStream_ << "FormSwep::tick(): channel and StkFrames arguments are incompatible!";
175 handleError( StkError::FUNCTION_ARGUMENT );
176 }
177#endif
178
179 StkFloat *iSamples = &iFrames[iChannel];
180 StkFloat *oSamples = &oFrames[oChannel];
181 unsigned int iHop = iFrames.channels(), oHop = oFrames.channels();
182 for ( unsigned int i=0; i<iFrames.frames(); i++, iSamples += iHop, oSamples += oHop )
183 *oSamples = tick( *iSamples );
184
185 return iFrames;
186}
187
188} // stk namespace
189
190#endif
stk::Filter
STK abstract filter class.
Definition Filter.h:23
stk::FormSwep
STK sweepable formant filter class.
Definition FormSwep.h:21
stk::FormSwep::setSweepTime
void setSweepTime(StkFloat time)
Set the sweep rate in terms of a time value in seconds.
stk::FormSwep::setSweepRate
void setSweepRate(StkFloat rate)
Set the sweep rate (between 0.0 - 1.0).
stk::FormSwep::setTargets
void setTargets(StkFloat frequency, StkFloat radius, StkFloat gain=1.0)
Set target resonance parameters.
stk::FormSwep::setStates
void setStates(StkFloat frequency, StkFloat radius, StkFloat gain=1.0)
Set both the current and target resonance parameters.
stk::FormSwep::lastOut
StkFloat lastOut(void) const
Return the last computed output value.
Definition FormSwep.h:75
stk::FormSwep::ignoreSampleRateChange
void ignoreSampleRateChange(bool ignore=true)
A function to enable/disable the automatic updating of class data when the STK sample rate changes.
Definition FormSwep.h:31
stk::FormSwep::setResonance
void setResonance(StkFloat frequency, StkFloat radius)
Sets the filter coefficients for a resonance at frequency (in Hz).
stk::FormSwep::tick
StkFloat tick(StkFloat input)
Input one sample to the filter and return a reference to one output.
Definition FormSwep.h:123
stk::FormSwep::~FormSwep
~FormSwep()
Class destructor.
stk::FormSwep::FormSwep
FormSwep(void)
Default constructor creates a second-order pass-through filter.
stk::StkFrames
An STK class to handle vectorized audio data.
Definition Stk.h:279
stk::StkFrames::channels
unsigned int channels(void) const
Return the number of channels represented by the data.
Definition Stk.h:416
stk::StkFrames::frames
unsigned int frames(void) const
Return the number of sample frames represented by the data.
Definition Stk.h:419
stk
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.