Home   Information   Classes   Download   Usage   Mail List   Requirements   Links   Tutorial


Granulate.h

00001 /***************************************************/
00016 /***************************************************/
00017 
00018 #ifndef STK_GRANULATE_H
00019 #define STK_GRANULATE_H
00020 
00021 #include <vector>
00022 #include "Generator.h"
00023 #include "Envelope.h"
00024 #include "Noise.h"
00025 
00026 class Granulate: public Generator
00027 {
00028  public:
00030   Granulate( void );
00031 
00033   Granulate( unsigned int nVoices, std::string fileName, bool typeRaw = false );
00034 
00036   ~Granulate();
00037 
00039 
00043   void openFile( std::string fileName, bool typeRaw = false );
00044 
00046 
00050   void reset();
00051 
00053 
00058   void setVoices( unsigned int nVoices = 1 );
00059 
00061 
00067   void setStretch( unsigned int stretchFactor = 1 );
00068 
00070 
00083   void setGrainParameters( unsigned int duration = 30, unsigned int rampPercent = 50,
00084                            int offset = 0, unsigned int delay = 0 );
00085 
00087 
00095   void setRandomFactor( StkFloat randomness = 0.1 );
00096 
00097   enum GrainState {
00098     GRAIN_STOPPED,
00099     GRAIN_FADEIN,
00100     GRAIN_SUSTAIN,
00101     GRAIN_FADEOUT
00102   };
00103 
00104  protected:
00105 
00106   struct Grain {
00107     StkFloat eScaler;
00108     StkFloat eRate;
00109     unsigned long attackCount;
00110     unsigned long sustainCount;
00111     unsigned long decayCount;
00112     unsigned long delayCount;
00113     unsigned long counter;
00114     unsigned long pointer;
00115     unsigned long startPointer;
00116     unsigned int repeats;
00117     GrainState state;
00118 
00119     // Default constructor.
00120     Grain()
00121       :eScaler(0.0), eRate(0.0), attackCount(0), sustainCount(0), decayCount(0),
00122        delayCount(0), counter(0), pointer(0), startPointer(0), repeats(0), state(GRAIN_STOPPED) {}
00123   };
00124 
00125   StkFloat computeSample( void );
00126   void calculateGrain( Granulate::Grain& grain );
00127 
00128   StkFrames data_;
00129   std::vector<Grain> grains_;
00130   Noise noise;
00131   long gPointer_;
00132 
00133   // Global grain parameters.
00134   unsigned int gDuration_;
00135   unsigned int gRampPercent_;
00136   unsigned int gDelay_;
00137   unsigned int gStretch_;
00138   unsigned int stretchCounter_;
00139   int gOffset_;
00140   StkFloat gRandomFactor_;
00141   StkFloat gain_;
00142 
00143 };
00144 
00145 #endif

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