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 00011 namespace csl { // my namespace 00012 00013 #define MAX_GRAINS 200 00014 00015 // This implementation of grain assumes a linked list data structure 00016 struct Grain { 00017 float amplitude; 00018 float frequency; 00019 long duration; 00020 float pan; 00021 long position; //to maintain state of te sample position we are at in case it is played over the boundary of buffers 00022 Grain *nextGrain; //A pointer to the next grain in the linked list 00023 }; 00024 00026 class Granulator : public UnitGenerator { 00027 00028 public: 00029 00030 Granulator(); 00031 virtual ~Granulator(); 00032 00033 Granulator(FrameStream &wave, FrameStream &env, FrameStream &rate, FrameStream &, FrameStream &freq, FrameStream &dur, FrameStream &pan); 00034 00035 status nextBuffer(Buffer &inputBuffer, Buffer &outputBuffer); 00036 00037 //status mono_next_buffer(Buffer & inputBuffer, Buffer & outputBuffer, unsigned inBufNum, unsigned outBufNum); 00038 00039 int numGrains; 00040 00041 protected: 00042 00043 UnitGenerator *mWave, //the waveform that is played back granularized - current version does not implement 00044 *mEnv, //generic envelope for all grains - current version does not implement 00045 *mRate, //next_sample called when at the beginning of next_buffer - the rate of grains/second (this could be called more often) 00046 *mAmplitude, //next_sample called when spawning a new grain to set amplitude multiplier 00047 *mFrequency, //next_sample called when spawning a new grain to set frequency of wave (Hz) (in future: wave multiplier?) 00048 *mDuration, //next_sample called when spawning a new grain to set duration (secs) 00049 *mPan; //The pan position (-1 is left +1 is right) 00050 00051 // Note: all calls that are used to set parameters for spawning grains are not realtime framestreams. 00052 // They will be modulated by the grain spawn rate; this could be fixed by calling next_sample a total 00053 // of bufferLength times each next_buffer call. 00054 // Also, this would break down if there were more than 1 grain per sampletime being spawned (e.g. 44100grains/sec) 00055 Buffer rateBuff, durBuff, ampBuff, panBuff, freqBuff; 00056 00057 //std::vector <Grain> *mGrains; //an array of grains 00058 Grain * newGrain; 00059 Grain *deadGrains, *aliveGrains; 00060 00061 bool outOfMemory; 00062 00063 }; // end of class spec. 00064 00065 } // end of namespace 00066 00067 #endif 00068
1.4.5-20051010