Noise.h

Go to the documentation of this file.
00001 //
00002 // Noise.h -- Noise Unit Generators
00003 //  Comprising Noise superclass, and WhiteNoise, PinkNoise subclasses 
00004 // 
00005 
00006 #ifndef INCLUDE_Noise_H
00007 #define INCLUDE_Noise_H
00008 
00009 #include "CSL_Core.h"           // include the main CSL header; this includes CSL_Types.h and CGestalt.h
00010 
00011 #define PINK_MAX_RANDOM_ROWS    (30)
00012 #define PINK_RANDOM_BITS        (24)
00013 #define PINK_RANDOM_SHIFT       ((sizeof(long)*8)-PINK_RANDOM_BITS)
00014 
00015 namespace csl {
00016 
00020 class Noise : public UnitGenerator, public Scalable {
00021 
00022 public:
00023     inline int generateRandomNumber();                  
00024     inline float generateNormalizedRandomNumber();      
00025 
00026     void setSeed(int seed) { mSeed = seed; }            
00027 
00028     void dump();                                        
00029 
00030     Noise();                                            
00031     Noise(double ampl, double offset = 0.0);        
00032     Noise(int seed, double ampl = 1.0, double offset = 0.0);
00033     ~Noise() {};                                        
00034     
00035 protected:
00036     int mSeed;                                          
00037     float mDivisor;                                     
00038 };
00039 
00043 class WhiteNoise : public Noise {
00044 
00045 public:                                     
00046     WhiteNoise() : Noise() {};
00047     WhiteNoise(double ampl, double offset = 0.0) : Noise(ampl, offset) {}; 
00048     WhiteNoise(int seed, double ampl = 1.0, double offset = 0.0) : Noise(seed, ampl, offset) {};
00049     ~WhiteNoise() {};                                       
00050     
00051 /********* THIS FUNCTION WAS PROTECTED, BUT IT'S NEEDED TO BE PUBLIC BECAUSE 
00052             OTHER UGENS MIGHT CALL IT DURING A NEXT BUFFER CALL . . . JORCE *********/
00054     void nextBuffer(Buffer& outputBuffer, unsigned outBufNum) throw (CException);
00055     
00056 protected:
00057 
00058 };
00059 
00063 
00064 class PinkNoise : public Noise {
00065 
00066 public:
00067     PinkNoise();                                        
00068     PinkNoise(double ampl, double offset = 0.f); 
00069     PinkNoise(int seed, double ampl = 1.f, double offset = 0.f);
00070     ~PinkNoise() {};                                    
00071     
00073     void nextBuffer(Buffer & outputBuffer, unsigned outBufNum) throw (CException);
00074     
00075     sample nextPink();                  
00076     
00077 protected:
00078     int mPinkRows[PINK_MAX_RANDOM_ROWS];
00079     int mPinkRunningSum;                
00080     int mPinkIndex;                     
00081     int mPinkIndexMask;                 
00082     float mPinkScalar;                  
00083 
00084     void initialize(int numRows);       
00085 
00086 };
00087 
00088 // inline functions have to be declared in the header file to avoid linker problems
00089 
00090 inline int Noise :: generateRandomNumber() {
00091     // Calculate pseudo-random 32 bit number based on linear congruential method
00092     mSeed = (mSeed * 196314165) + 907633515;
00093     return mSeed;
00094 
00095 }   
00096 
00097 inline float Noise :: generateNormalizedRandomNumber() {
00098     // Calculate pseudo-random 32 bit number based on linear congruential method
00099     mSeed = (mSeed * 196314165) + 907633515;
00100     return (float) mSeed / (float) 0x7fffffff; // dividing by INT_MAX
00101 }
00102 
00103 
00104 } // namespace csl
00105 
00106 #endif
00107 

Generated on Fri Apr 6 20:18:13 2007 for CSL by  doxygen 1.4.5-20051010