Home   Information   Classes   Download   Usage   Mail List   Requirements   Links   FAQ   Tutorial


Mesh2D.h

00001 #ifndef STK_MESH2D_H
00002 #define STK_MESH2D_H
00003 
00004 #include "Instrmnt.h"
00005 #include "OnePole.h"
00006 
00007 namespace stk {
00008 
00009 /***************************************************/
00033 /***************************************************/
00034 
00035 const unsigned short NXMAX = 12;
00036 const unsigned short NYMAX = 12;
00037 
00038 class Mesh2D : public Instrmnt
00039 {
00040  public:
00042   Mesh2D( unsigned short nX, unsigned short nY );
00043 
00045   ~Mesh2D( void );
00046 
00048   void clear( void );
00049 
00051   void setNX( unsigned short lenX );
00052 
00054   void setNY( unsigned short lenY );
00055 
00057   void setInputPosition( StkFloat xFactor, StkFloat yFactor );
00058 
00060   void setDecay( StkFloat decayFactor );
00061 
00063   void noteOn( StkFloat frequency, StkFloat amplitude );
00064 
00066   void noteOff( StkFloat amplitude );
00067 
00069   StkFloat energy( void );
00070 
00072   StkFloat inputTick( StkFloat input );
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   StkFloat tick0();
00093   StkFloat tick1();
00094   void clearMesh();
00095 
00096   unsigned short NX_, NY_;
00097   unsigned short xInput_, yInput_;
00098   OnePole  filterX_[NXMAX];
00099   OnePole  filterY_[NYMAX];
00100   StkFloat v_[NXMAX-1][NYMAX-1]; // junction velocities
00101   StkFloat vxp_[NXMAX][NYMAX];   // positive-x velocity wave
00102   StkFloat vxm_[NXMAX][NYMAX];   // negative-x velocity wave
00103   StkFloat vyp_[NXMAX][NYMAX];   // positive-y velocity wave
00104   StkFloat vym_[NXMAX][NYMAX];   // negative-y velocity wave
00105 
00106   // Alternate buffers
00107   StkFloat vxp1_[NXMAX][NYMAX];  // positive-x velocity wave
00108   StkFloat vxm1_[NXMAX][NYMAX];  // negative-x velocity wave
00109   StkFloat vyp1_[NXMAX][NYMAX];  // positive-y velocity wave
00110   StkFloat vym1_[NXMAX][NYMAX];  // negative-y velocity wave
00111 
00112   int counter_; // time in samples
00113 };
00114 
00115 inline StkFrames& Mesh2D :: tick( StkFrames& frames, unsigned int channel )
00116 {
00117   unsigned int nChannels = lastFrame_.channels();
00118 #if defined(_STK_DEBUG_)
00119   if ( channel > frames.channels() - nChannels ) {
00120     oStream_ << "Mesh2D::tick(): channel and StkFrames arguments are incompatible!";
00121     handleError( StkError::FUNCTION_ARGUMENT );
00122   }
00123 #endif
00124 
00125   StkFloat *samples = &frames[channel];
00126   unsigned int j, hop = frames.channels() - nChannels;
00127   if ( nChannels == 1 ) {
00128     for ( unsigned int i=0; i<frames.frames(); i++, samples += hop )
00129       *samples++ = tick();
00130   }
00131   else {
00132     for ( unsigned int i=0; i<frames.frames(); i++, samples += hop ) {
00133       *samples++ = tick();
00134       for ( j=1; j<nChannels; j++ )
00135         *samples++ = lastFrame_[j];
00136     }
00137   }
00138 
00139   return frames;
00140 }
00141 
00142 } // stk namespace
00143 
00144 #endif

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