The Synthesis ToolKit in C++ (STK)

Home Information Classes Download Usage Mail List Requirements Links FAQ Tutorial

Modulate.h
1 #ifndef STK_MODULATE_H
2 #define STK_MODULATE_H
3
4 #include "Generator.h"
5 #include "SineWave.h"
6 #include "Noise.h"
7 #include "OnePole.h"
8
9 namespace stk {
10
11 /***************************************************/
21 /***************************************************/
22
23 class Modulate : public Generator
24 {
25 public:
27
30 Modulate( void );
31
33 ~Modulate( void );
34
36 void reset( void ) { lastFrame_[0] = 0.0; };
37
39 void setVibratoRate( StkFloat rate ) { vibrato_.setFrequency( rate ); };
40
42 void setVibratoGain( StkFloat gain ) { vibratoGain_ = gain; };
43
45 void setRandomGain( StkFloat gain );
46
48 StkFloat lastOut( void ) const { return lastFrame_[0]; };
49
51 StkFloat tick( void );
52
54
61 StkFrames& tick( StkFrames& frames, unsigned int channel = 0 );
62
63 protected:
64
65 void sampleRateChanged( StkFloat newRate, StkFloat oldRate );
66
67 SineWave vibrato_;
68 Noise noise_;
69 OnePole filter_;
70 StkFloat vibratoGain_;
71 StkFloat randomGain_;
72 unsigned int noiseRate_;
73 unsigned int noiseCounter_;
74
75 };
76
77 inline StkFloat Modulate :: tick( void )
78 {
79 // Compute periodic and random modulations.
80 lastFrame_[0] = vibratoGain_ * vibrato_.tick();
81 if ( noiseCounter_++ >= noiseRate_ ) {
82 noise_.tick();
83 noiseCounter_ = 0;
84 }
85 lastFrame_[0] += filter_.tick( noise_.lastOut() );
86 return lastFrame_[0];
87 }
88
89 inline StkFrames& Modulate :: tick( StkFrames& frames, unsigned int channel )
90 {
91 #if defined(_STK_DEBUG_)
92 if ( channel >= frames.channels() ) {
93 oStream_ << "Modulate::tick(): channel and StkFrames arguments are incompatible!";
94 handleError( StkError::FUNCTION_ARGUMENT );
95 }
96 #endif
97
98 StkFloat *samples = &frames[channel];
99 unsigned int hop = frames.channels();
100 for ( unsigned int i=0; i<frames.frames(); i++, samples += hop )
101 *samples = Modulate::tick();
102
103 return frames;
104 }
105
106 } // stk namespace
107
108 #endif

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