Arduino STK  4.6.2
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
STK linear line envelope class.
Definition: Envelope.h:22
void setTarget(StkFloat target)
Set the target value.
StkFloat tick(void)
Compute and return one output sample.
Definition: Envelope.h:88
STK sweepable formant filter class.
Definition: FormSwep.h:21
StkFloat tick(StkFloat input)
Input one sample to the filter and return a reference to one output.
Definition: FormSwep.h:123
STK instrument abstract base class.
Definition: Instrmnt.h:20
STK noise generator.
Definition: Noise.h:22
StkFloat tick(void)
Compute and return one output sample.
Definition: Noise.h:59
STK one-pole filter class.
Definition: OnePole.h:21
StkFloat tick(StkFloat input)
Input one sample to the filter and return one output.
Definition: OnePole.h:80
STK one-zero filter class.
Definition: OneZero.h:21
StkFloat tick(StkFloat input)
Input one sample to the filter and return one output.
Definition: OneZero.h:79
STK "singing" looped soundfile class.
Definition: SingWave.h:26
StkFloat tick(void)
Compute and return one output sample.
Definition: SingWave.h:104
void noteOn(void)
Start a note.
Definition: SingWave.h:72
void setSweepRate(StkFloat rate)
Set the sweep rate.
Definition: SingWave.h:63
void setGainTarget(StkFloat target)
Set the gain target value.
Definition: SingWave.h:69
An STK class to handle vectorized audio data.
Definition: Stk.h:287
unsigned int channels(void) const
Return the number of channels represented by the data.
Definition: Stk.h:415
unsigned int frames(void) const
Return the number of sample frames represented by the data.
Definition: Stk.h:418
static void handleError(const char *message, StkError::Type type)
Static function for error reporting and handling using c-strings.
Four formant synthesis instrument.
Definition: VoicForm.h:42
void setFilterSweepRate(unsigned int whichOne, StkFloat rate)
Set the sweep rate for a particular formant filter (0-3).
~VoicForm(void)
Class destructor.
void setPitchSweepRate(StkFloat rate)
Set voiced component pitch sweep rate.
Definition: VoicForm.h:72
void quiet(void)
Stop the voice.
void speak(void)
Start the voice.
Definition: VoicForm.h:75
void controlChange(int number, StkFloat value)
Perform the control change specified by number and value (0.0 - 128.0).
bool setPhoneme(const char *phoneme)
Set instrument parameters for the given phoneme. Returns false if phoneme not found.
VoicForm(void)
Class constructor.
void noteOn(StkFloat frequency, StkFloat amplitude)
Start a note with the given frequency and amplitude.
void setUnVoiced(StkFloat nGain)
Set the unvoiced component gain.
Definition: VoicForm.h:66
void noteOff(StkFloat amplitude)
Stop a note with the given amplitude (speed of decay).
Definition: VoicForm.h:84
StkFloat tick(unsigned int channel=0)
Compute and return one output sample.
Definition: VoicForm.h:113
void setVoiced(StkFloat vGain)
Set the voiced component gain.
Definition: VoicForm.h:63
void clear(void)
Reset and clear all internal state.
void setFrequency(StkFloat frequency)
Set instrument parameters for a particular frequency.
The STK namespace.
Definition: ADSR.h:8