Home   Information   Classes   Download   Usage   Mail List   Requirements   Links   FAQ   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 
00085   void setGrainParameters( unsigned int duration = 30, unsigned int rampPercent = 50,
00086                            int offset = 0, unsigned int delay = 0 );
00087 
00089 
00097   void setRandomFactor( StkFloat randomness = 0.1 );
00098 
00099   enum GrainState {
00100     GRAIN_STOPPED,
00101     GRAIN_FADEIN,
00102     GRAIN_SUSTAIN,
00103     GRAIN_FADEOUT
00104   };
00105 
00106  protected:
00107 
00108   struct Grain {
00109     StkFloat eScaler;
00110     StkFloat eRate;
00111     unsigned long attackCount;
00112     unsigned long sustainCount;
00113     unsigned long decayCount;
00114     unsigned long delayCount;
00115     unsigned long counter;
00116     unsigned long pointer;
00117     unsigned long startPointer;
00118     unsigned int repeats;
00119     GrainState state;
00120 
00121     // Default constructor.
00122     Grain()
00123       :eScaler(0.0), eRate(0.0), attackCount(0), sustainCount(0), decayCount(0),
00124        delayCount(0), counter(0), pointer(0), startPointer(0), repeats(0), state(GRAIN_STOPPED) {}
00125   };
00126 
00127   StkFloat computeSample( void );
00128   void calculateGrain( Granulate::Grain& grain );
00129 
00130   StkFrames data_;
00131   std::vector<Grain> grains_;
00132   Noise noise;
00133   long gPointer_;
00134 
00135   // Global grain parameters.
00136   unsigned int gDuration_;
00137   unsigned int gRampPercent_;
00138   unsigned int gDelay_;
00139   unsigned int gStretch_;
00140   unsigned int stretchCounter_;
00141   int gOffset_;
00142   StkFloat gRandomFactor_;
00143   StkFloat gain_;
00144 
00145 };
00146 
00147 #endif

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