The Synthesis ToolKit in C++ (STK)

Home Information Classes Download Usage Mail List Requirements Links FAQ Tutorial

# Drummer.h

    00001 #ifndef STK_DRUMMER_H
    00002 #define STK_DRUMMER_H
    00003
    00004 #include "Instrmnt.h"
    00005 #include "FileWvIn.h"
    00006 #include "OnePole.h"
    00007
    00008 namespace stk {
    00009
    00010 /***************************************************/
    00025 /***************************************************/
    00026
    00027 const int DRUM_NUMWAVES = 11;
    00028 const int DRUM_POLYPHONY = 4;
    00029
    00030 class Drummer : public Instrmnt
    00031 {
    00032  public:
    00034
    00037   Drummer( void );
    00038
    00040   ~Drummer( void );
    00041
    00043
    00049   void noteOn( StkFloat instrument, StkFloat amplitude );
    00050
    00052   void noteOff( StkFloat amplitude );
    00053
    00055   StkFloat tick( unsigned int channel = 0 );
    00056
    00058
    00065   StkFrames& tick( StkFrames& frames, unsigned int channel = 0 );
    00066
    00067  protected:
    00068
    00069   FileWvIn waves_[DRUM_POLYPHONY];
    00070   OnePole  filters_[DRUM_POLYPHONY];
    00071   std::vector<int> soundOrder_;
    00072   std::vector<int> soundNumber_;
    00073   int      nSounding_;
    00074 };
    00075
    00076 inline StkFloat Drummer :: tick( unsigned int )
    00077 {
    00078   lastFrame_[0] = 0.0;
    00079   if ( nSounding_ == 0 ) return lastFrame_[0];
    00080
    00081   for ( int i=0; i<DRUM_POLYPHONY; i++ ) {
    00082     if ( soundOrder_[i] >= 0 ) {
    00083       if ( waves_[i].isFinished() ) {
    00084         // Re-order the list.
    00085         for ( int j=0; j<DRUM_POLYPHONY; j++ ) {
    00086           if ( soundOrder_[j] > soundOrder_[i] )
    00087             soundOrder_[j] -= 1;
    00088         }
    00089         soundOrder_[i] = -1;
    00090         nSounding_--;
    00091       }
    00092       else
    00093         lastFrame_[0] += filters_[i].tick( waves_[i].tick() );
    00094     }
    00095   }
    00096
    00097   return lastFrame_[0];
    00098 }
    00099
    00100 inline StkFrames& Drummer :: tick( StkFrames& frames, unsigned int channel )
    00101 {
    00102   unsigned int nChannels = lastFrame_.channels();
    00103 #if defined(_STK_DEBUG_)
    00104   if ( channel > frames.channels() - nChannels ) {
    00105     oStream_ << "Drummer::tick(): channel and StkFrames arguments are incompatible!";
    00106     handleError( StkError::FUNCTION_ARGUMENT );
    00107   }
    00108 #endif
    00109
    00110   StkFloat *samples = &frames[channel];
    00111   unsigned int j, hop = frames.channels() - nChannels;
    00112   if ( nChannels == 1 ) {
    00113     for ( unsigned int i=0; i<frames.frames(); i++, samples += hop )
    00114       *samples++ = tick();
    00115   }
    00116   else {
    00117     for ( unsigned int i=0; i<frames.frames(); i++, samples += hop ) {
    00118       *samples++ = tick();
    00119       for ( j=1; j<nChannels; j++ )
    00120         *samples++ = lastFrame_[j];
    00121     }
    00122   }
    00123
    00124   return frames;
    00125 }
    00126
    00127
    00128 } // stk namespace
    00129
    00130 #endif

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