Home Information Classes Download Usage Mail List Requirements Links FAQ Tutorial

VoicForm.h
1 #ifndef STK_VOICFORM_H
2 #define STK_VOICFORM_H
3
4 #include "Instrmnt.h"
5 #include "Envelope.h"
6 #include "Noise.h"
7 #include "SingWave.h"
8 #include "FormSwep.h"
9 #include "OnePole.h"
10 #include "OneZero.h"
11
12 namespace stk {
13
14 /***************************************************/
39 /***************************************************/
40
41 class VoicForm : public Instrmnt
42 {
43 public:
45
48 VoicForm( void );
49
51 ~VoicForm( void );
52
54 void clear( void );
55
57 void setFrequency( StkFloat frequency );
58
60 bool setPhoneme( const char* phoneme );
61
63 void setVoiced( StkFloat vGain ) { voiced_->setGainTarget(vGain); };
64
66 void setUnVoiced( StkFloat nGain ) { noiseEnv_.setTarget(nGain); };
67
69 void setFilterSweepRate( unsigned int whichOne, StkFloat rate );
70
72 void setPitchSweepRate( StkFloat rate ) { voiced_->setSweepRate(rate); };
73
75 void speak( void ) { voiced_->noteOn(); };
76
78 void quiet( void );
79
81 void noteOn( StkFloat frequency, StkFloat amplitude );
82
84 void noteOff( StkFloat amplitude ) { this->quiet(); };
85
87 void controlChange( int number, StkFloat value );
88
90 StkFloat tick( unsigned int channel = 0 );
91
93
100 StkFrames& tick( StkFrames& frames, unsigned int channel = 0 );
101
102 protected:
103
104 SingWave *voiced_;
105 Noise noise_;
106 Envelope noiseEnv_;
107 FormSwep filters_[4];
108 OnePole onepole_;
109 OneZero onezero_;
110
111 };
112
113 inline StkFloat VoicForm :: tick( unsigned int )
114 {
115 StkFloat temp;
116 temp = onepole_.tick( onezero_.tick( voiced_->tick() ) );
117 temp += noiseEnv_.tick() * noise_.tick();
118 lastFrame_[0] = filters_[0].tick(temp);
119 lastFrame_[0] += filters_[1].tick(temp);
120 lastFrame_[0] += filters_[2].tick(temp);
121 lastFrame_[0] += filters_[3].tick(temp);
122 /*
123 temp += noiseEnv_.tick() * noise_.tick();
124 lastFrame_[0] = filters_[0].tick(temp);
125 lastFrame_[0] = filters_[1].tick(lastFrame_[0]);
126 lastFrame_[0] = filters_[2].tick(lastFrame_[0]);
127 lastFrame_[0] = filters_[3].tick(lastFrame_[0]);
128 */
129 return lastFrame_[0];
130 }
131
132 inline StkFrames& VoicForm :: tick( StkFrames& frames, unsigned int channel )
133 {
134 unsigned int nChannels = lastFrame_.channels();
135 #if defined(_STK_DEBUG_)
136 if ( channel > frames.channels() - nChannels ) {
137 oStream_ << "VoicForm::tick(): channel and StkFrames arguments are incompatible!";
138 handleError( StkError::FUNCTION_ARGUMENT );
139 }
140 #endif
141
142 StkFloat *samples = &frames[channel];
143 unsigned int j, hop = frames.channels() - nChannels;
144 if ( nChannels == 1 ) {
145 for ( unsigned int i=0; i<frames.frames(); i++, samples += hop )
146 *samples++ = tick();
147 }
148 else {
149 for ( unsigned int i=0; i<frames.frames(); i++, samples += hop ) {
150 *samples++ = tick();
151 for ( j=1; j<nChannels; j++ )
152 *samples++ = lastFrame_[j];
153 }
154 }
155
156 return frames;
157 }
158
159 } // stk namespace
160
161 #endif

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