Home Information Classes Download Usage Mail List Requirements Links FAQ Tutorial

Resonate.h
1 #ifndef STK_RESONATE_H
2 #define STK_RESONATE_H
3
4 #include "Instrmnt.h"
5 #include "ADSR.h"
6 #include "BiQuad.h"
7 #include "Noise.h"
8
9 namespace stk {
10
11 /***************************************************/
28 /***************************************************/
29
30 class Resonate : public Instrmnt
31 {
32 public:
34 Resonate( void );
35
37 ~Resonate( void );
38
40 void setResonance( StkFloat frequency, StkFloat radius );
41
43 void setNotch( StkFloat frequency, StkFloat radius );
44
46 void setEqualGainZeroes( void ) { filter_.setEqualGainZeroes(); };
47
49 void keyOn( void ) { adsr_.keyOn(); };
50
52 void keyOff( void ) { adsr_.keyOff(); };
53
55 void noteOn( StkFloat frequency, StkFloat amplitude );
56
58 void noteOff( StkFloat amplitude );
59
61 void controlChange( int number, StkFloat value );
62
64 StkFloat tick( unsigned int channel = 0 );
65
67
74 StkFrames& tick( StkFrames& frames, unsigned int channel = 0 );
75
76 protected:
77
78 ADSR adsr_;
79 BiQuad filter_;
80 Noise noise_;
81 StkFloat poleFrequency_;
82 StkFloat poleRadius_;
83 StkFloat zeroFrequency_;
84 StkFloat zeroRadius_;
85
86 };
87
88 inline StkFloat Resonate :: tick( unsigned int )
89 {
90 lastFrame_[0] = filter_.tick( noise_.tick() );
91 lastFrame_[0] *= adsr_.tick();
92 return lastFrame_[0];
93 }
94
95 inline StkFrames& Resonate :: tick( StkFrames& frames, unsigned int channel )
96 {
97 unsigned int nChannels = lastFrame_.channels();
98 #if defined(_STK_DEBUG_)
99 if ( channel > frames.channels() - nChannels ) {
100 oStream_ << "Resonate::tick(): channel and StkFrames arguments are incompatible!";
101 handleError( StkError::FUNCTION_ARGUMENT );
102 }
103 #endif
104
105 StkFloat *samples = &frames[channel];
106 unsigned int j, hop = frames.channels() - nChannels;
107 if ( nChannels == 1 ) {
108 for ( unsigned int i=0; i<frames.frames(); i++, samples += hop )
109 *samples++ = tick();
110 }
111 else {
112 for ( unsigned int i=0; i<frames.frames(); i++, samples += hop ) {
113 *samples++ = tick();
114 for ( j=1; j<nChannels; j++ )
115 *samples++ = lastFrame_[j];
116 }
117 }
118
119 return frames;
120 }
121
122 } // stk namespace
123
124 #endif

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