The Synthesis ToolKit in C++ (STK)

Home Information Classes Download Usage Mail List Requirements Links FAQ Tutorial

# Mandolin.h

    00001 #ifndef STK_MANDOLIN_H
    00002 #define STK_MANDOLIN_H
    00003
    00004 #include "Instrmnt.h"
    00005 #include "Twang.h"
    00006 #include "FileWvIn.h"
    00007
    00008 namespace stk {
    00009
    00010 /***************************************************/
    00036 /***************************************************/
    00037
    00038 class Mandolin : public Instrmnt
    00039 {
    00040  public:
    00042   Mandolin( StkFloat lowestFrequency );
    00043
    00045   ~Mandolin( void );
    00046
    00048   void clear( void );
    00049
    00051   void setDetune( StkFloat detune );
    00052
    00054   void setBodySize( StkFloat size );
    00055
    00057   void setPluckPosition( StkFloat position );
    00058
    00060   void setFrequency( StkFloat frequency );
    00061
    00063   void pluck( StkFloat amplitude );
    00064
    00066   void pluck( StkFloat amplitude,StkFloat position );
    00067
    00069   void noteOn( StkFloat frequency, StkFloat amplitude );
    00070
    00072   void noteOff( StkFloat amplitude );
    00073
    00075   void controlChange( int number, StkFloat value );
    00076
    00078   StkFloat tick( unsigned int channel = 0 );
    00079
    00081
    00088   StkFrames& tick( StkFrames& frames, unsigned int channel = 0 );
    00089
    00090   protected:
    00091
    00092   Twang strings_[2];
    00093   FileWvIn soundfile_[12];
    00094
    00095   int mic_;
    00096   StkFloat detuning_;
    00097   StkFloat frequency_;
    00098   StkFloat pluckAmplitude_;
    00099 };
    00100
    00101 inline StkFloat Mandolin :: tick( unsigned int )
    00102 {
    00103   StkFloat temp = 0.0;
    00104   if ( !soundfile_[mic_].isFinished() )
    00105     temp = soundfile_[mic_].tick() * pluckAmplitude_;
    00106
    00107   lastFrame_[0] = strings_[0].tick( temp );
    00108   lastFrame_[0] += strings_[1].tick( temp );
    00109   lastFrame_[0] *= 0.2;
    00110
    00111   return lastFrame_[0];
    00112 }
    00113
    00114 inline StkFrames& Mandolin :: tick( StkFrames& frames, unsigned int channel )
    00115 {
    00116   unsigned int nChannels = lastFrame_.channels();
    00117 #if defined(_STK_DEBUG_)
    00118   if ( channel > frames.channels() - nChannels ) {
    00119     oStream_ << "Mandolin::tick(): channel and StkFrames arguments are incompatible!";
    00120     handleError( StkError::FUNCTION_ARGUMENT );
    00121   }
    00122 #endif
    00123
    00124   StkFloat *samples = &frames[channel];
    00125   unsigned int j, hop = frames.channels() - nChannels;
    00126   if ( nChannels == 1 ) {
    00127     for ( unsigned int i=0; i<frames.frames(); i++, samples += hop )
    00128       *samples++ = tick();
    00129   }
    00130   else {
    00131     for ( unsigned int i=0; i<frames.frames(); i++, samples += hop ) {
    00132       *samples++ = tick();
    00133       for ( j=1; j<nChannels; j++ )
    00134         *samples++ = lastFrame_[j];
    00135     }
    00136   }
    00137
    00138   return frames;
    00139 }
    00140
    00141 } // stk namespace
    00142
    00143 #endif

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