The Synthesis ToolKit in C++ (STK)

Home Information Classes Download Usage Mail List Requirements Links FAQ Tutorial

# VoicForm.h

    00001 #ifndef STK_VOICFORM_H
    00002 #define STK_VOICFORM_H
    00003
    00004 #include "Instrmnt.h"
    00005 #include "Envelope.h"
    00006 #include "Noise.h"
    00007 #include "SingWave.h"
    00008 #include "FormSwep.h"
    00009 #include "OnePole.h"
    00010 #include "OneZero.h"
    00011
    00012 namespace stk {
    00013
    00014 /***************************************************/
    00039 /***************************************************/
    00040
    00041 class VoicForm : public Instrmnt
    00042 {
    00043   public:
    00045
    00048   VoicForm( void );
    00049
    00051   ~VoicForm( void );
    00052
    00054   void clear( void );
    00055
    00057   void setFrequency( StkFloat frequency );
    00058
    00060   bool setPhoneme( const char* phoneme );
    00061
    00063   void setVoiced( StkFloat vGain ) { voiced_->setGainTarget(vGain); };
    00064
    00066   void setUnVoiced( StkFloat nGain ) { noiseEnv_.setTarget(nGain); };
    00067
    00069   void setFilterSweepRate( unsigned int whichOne, StkFloat rate );
    00070
    00072   void setPitchSweepRate( StkFloat rate ) { voiced_->setSweepRate(rate); };
    00073
    00075   void speak( void ) { voiced_->noteOn(); };
    00076
    00078   void quiet( void );
    00079
    00081   void noteOn( StkFloat frequency, StkFloat amplitude );
    00082
    00084   void noteOff( StkFloat amplitude ) { this->quiet(); };
    00085
    00087   void controlChange( int number, StkFloat value );
    00088
    00090   StkFloat tick( unsigned int channel = 0 );
    00091
    00093
    00100   StkFrames& tick( StkFrames& frames, unsigned int channel = 0 );
    00101
    00102 protected:
    00103
    00104   SingWave *voiced_;
    00105   Noise    noise_;
    00106   Envelope noiseEnv_;
    00107   FormSwep filters_[4];
    00108   OnePole  onepole_;
    00109   OneZero  onezero_;
    00110
    00111 };
    00112
    00113 inline StkFloat VoicForm :: tick( unsigned int )
    00114 {
    00115   StkFloat temp;
    00116   temp = onepole_.tick( onezero_.tick( voiced_->tick() ) );
    00117   temp += noiseEnv_.tick() * noise_.tick();
    00118   lastFrame_[0] = filters_[0].tick(temp);
    00119   lastFrame_[0] += filters_[1].tick(temp);
    00120   lastFrame_[0] += filters_[2].tick(temp);
    00121   lastFrame_[0] += filters_[3].tick(temp);
    00122   /*
    00123     temp  += noiseEnv_.tick() * noise_.tick();
    00124     lastFrame_[0]  = filters_[0].tick(temp);
    00125     lastFrame_[0]  = filters_[1].tick(lastFrame_[0]);
    00126     lastFrame_[0]  = filters_[2].tick(lastFrame_[0]);
    00127     lastFrame_[0]  = filters_[3].tick(lastFrame_[0]);
    00128   */
    00129   return lastFrame_[0];
    00130 }
    00131
    00132 inline StkFrames& VoicForm :: tick( StkFrames& frames, unsigned int channel )
    00133 {
    00134   unsigned int nChannels = lastFrame_.channels();
    00135 #if defined(_STK_DEBUG_)
    00136   if ( channel > frames.channels() - nChannels ) {
    00137     oStream_ << "VoicForm::tick(): channel and StkFrames arguments are incompatible!";
    00138     handleError( StkError::FUNCTION_ARGUMENT );
    00139   }
    00140 #endif
    00141
    00142   StkFloat *samples = &frames[channel];
    00143   unsigned int j, hop = frames.channels() - nChannels;
    00144   if ( nChannels == 1 ) {
    00145     for ( unsigned int i=0; i<frames.frames(); i++, samples += hop )
    00146       *samples++ = tick();
    00147   }
    00148   else {
    00149     for ( unsigned int i=0; i<frames.frames(); i++, samples += hop ) {
    00150       *samples++ = tick();
    00151       for ( j=1; j<nChannels; j++ )
    00152         *samples++ = lastFrame_[j];
    00153     }
    00154   }
    00155
    00156   return frames;
    00157 }
    00158
    00159 } // stk namespace
    00160
    00161 #endif

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