The Synthesis ToolKit in C++ (STK)

Home Information Classes Download Usage Mail List Requirements Links FAQ Tutorial

Moog.h
1 #ifndef STK_MOOG_H
2 #define STK_MOOG_H
3
4 #include "Sampler.h"
5 #include "FormSwep.h"
6
7 namespace stk {
8
9 /***************************************************/
27 /***************************************************/
28
29 class Moog : public Sampler
30 {
31 public:
33
36 Moog( void );
37
39 ~Moog( void );
40
42 void setFrequency( StkFloat frequency );
43
45 void noteOn( StkFloat frequency, StkFloat amplitude );
46
48 void setModulationSpeed( StkFloat mSpeed ) { loops_[1]->setFrequency( mSpeed ); };
49
51 void setModulationDepth( StkFloat mDepth ) { modDepth_ = mDepth * 0.5; };
52
54 void controlChange( int number, StkFloat value );
55
57 StkFloat tick( unsigned int channel = 0 );
58
60
67 StkFrames& tick( StkFrames& frames, unsigned int channel = 0 );
68
69 protected:
70
71 FormSwep filters_[2];
72 StkFloat modDepth_;
73 StkFloat filterQ_;
74 StkFloat filterRate_;
75
76 };
77
78 inline StkFloat Moog :: tick( unsigned int )
79 {
80 StkFloat temp;
81
82 if ( modDepth_ != 0.0 ) {
83 temp = loops_[1]->tick() * modDepth_;
84 loops_[0]->setFrequency( baseFrequency_ * (1.0 + temp) );
85 }
86
87 temp = attackGain_ * attacks_[0]->tick();
88 temp += loopGain_ * loops_[0]->tick();
89 temp = filter_.tick( temp );
90 temp *= adsr_.tick();
91 temp = filters_[0].tick( temp );
92 lastFrame_[0] = filters_[1].tick( temp );
93 return lastFrame_[0] * 6.0;
94 }
95
96 inline StkFrames& Moog :: tick( StkFrames& frames, unsigned int channel )
97 {
98 unsigned int nChannels = lastFrame_.channels();
99 #if defined(_STK_DEBUG_)
100 if ( channel > frames.channels() - nChannels ) {
101 oStream_ << "Moog::tick(): channel and StkFrames arguments are incompatible!";
102 handleError( StkError::FUNCTION_ARGUMENT );
103 }
104 #endif
105
106 StkFloat *samples = &frames[channel];
107 unsigned int j, hop = frames.channels() - nChannels;
108 if ( nChannels == 1 ) {
109 for ( unsigned int i=0; i<frames.frames(); i++, samples += hop )
110 *samples++ = tick();
111 }
112 else {
113 for ( unsigned int i=0; i<frames.frames(); i++, samples += hop ) {
114 *samples++ = tick();
115 for ( j=1; j<nChannels; j++ )
116 *samples++ = lastFrame_[j];
117 }
118 }
119
120 return frames;
121 }
122
123 } // stk namespace
124
125 #endif

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