Granulator.h

Go to the documentation of this file.
00001 //
00002 //  Granulator.h -- CSL class for doing granular synthesis
00003 //  See the copyright notice and acknowledgment of authors in the file COPYRIGHT
00004 //
00005 
00006 #ifndef CSL_GRAN_H
00007 #define CSL_GRAN_H
00008 
00009 #include "CSL_Core.h"       // my superclass
00010 #include "ThreadUtilities.h"
00011 
00012 namespace csl {             // my namespace
00013 
00014 #define MAXGRAINS 200
00015 
00020 
00021 typedef struct Grain {
00022     float amplitude;        // amplitude scale (0 - 1)
00023     float rate;             // playback rate
00024     float duration;         // duration in samples
00025     float pan;              // stereo pan 0 - 1
00026     float time;             // current time (index) in samples
00027     float position;         // sample position index
00028     unsigned delay;         // initial delay in samples
00029     float * samples;        // sample buffer pointer
00030     unsigned numSamples;    // length of sample vector
00031     Grain * nextGrain;      // A pointer to the next grain in the linked list
00032 } Grain;
00033 
00034 // This flag is for the app state, so that we don't change the grain lists while calculating samples
00035 
00036 typedef enum {          
00037     kFree,              
00038     kDSP,               
00039     kSched,             
00040 } GrainulatorState;
00041 
00042 
00046 
00047 class GrainPlayer : public UnitGenerator {
00048 public:
00049     GrainPlayer();
00050     ~GrainPlayer();
00051                     // this sums up the list of live grains -- very simple
00052     void nextBuffer(Buffer & outputBuffer) throw (CException);
00053 };
00054 
00055 
00061 
00062 class GrainCloud {
00063 public:
00064     GrainCloud();           // simple constructor
00065     ~GrainCloud();
00066             
00067     void startThread();     // method to start-up the thread
00068     void reset();           // reset all grains to silent
00069     
00070                 // public data members (set from GUI)
00071     float mRate;            // grain rate
00072     float mRDisp;           // rate dispersion
00073     float mOffset;          // starting index offset
00074     float mODisp;           // offset dispersion
00075     float mDensity;         // grain density
00076     float mDuration;        // grain duration
00077     float mWidth;           // stereo width
00078     float * mSamples;       // sample buffer pointer
00079     unsigned numSamples;    // # of samples
00080     bool isPlaying;         // whether I'm on or off
00081 
00082 protected:
00083     Thread * thread;        // thread to create grains
00084     bool threadOn;          // if the thread's running
00085 };
00086 
00087 }       // end of namespace
00088 
00089 #endif

Generated on Thu Sep 17 23:14:16 2009 for CSL by  doxygen 1.5.8