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 
00021 class Noise : public UnitGenerator, public Scalable {
00022 
00023 public:
00024     inline int generateRandomNumber();                  
00025     inline float generateNormalizedRandomNumber();      
00026 
00027     void setSeed(int seed) { mSeed = seed; }            
00028 
00029     void dump();                                        
00030 
00031     Noise();                                            
00032     Noise(double ampl, double offset = 0.0);        
00033     Noise(int seed, double ampl = 1.0, double offset = 0.0);
00034     ~Noise() { };                                       
00035     
00036 protected:
00037     int mSeed;                                          
00038     float mDivisor;                                     
00039 };
00040 
00044 
00045 class WhiteNoise : public Noise {
00046 
00047 public:                                     
00048     WhiteNoise() : Noise() { };
00049     WhiteNoise(double ampl, double offset = 0.0) : Noise(ampl, offset) { }; 
00050     WhiteNoise(int seed, double ampl = 1.0, double offset = 0.0) : Noise(seed, ampl, offset) { };
00051     ~WhiteNoise() { };                                      
00052     
00053 /********* THIS FUNCTION WAS PROTECTED, BUT IT'S NEEDED TO BE PUBLIC BECAUSE 
00054             OTHER UGENS MIGHT CALL IT DURING A NEXT BUFFER CALL . . . *********/
00056     void nextBuffer(Buffer& outputBuffer, unsigned outBufNum) throw (CException);
00057     
00058 protected:
00059 
00060 };
00061 
00065 
00066 class PinkNoise : public Noise {
00067 
00068 public:
00069     PinkNoise();                                        
00070     PinkNoise(double ampl, double offset = 0.f); 
00071     PinkNoise(int seed, double ampl = 1.f, double offset = 0.f);
00072     ~PinkNoise() { };                                   
00073     
00075     void nextBuffer(Buffer & outputBuffer, unsigned outBufNum) throw (CException);
00076     
00077     sample nextPink();                  
00078     
00079 protected:
00080     int mPinkRows[PINK_MAX_RANDOM_ROWS];
00081     int mPinkRunningSum;                
00082     int mPinkIndex;                     
00083     int mPinkIndexMask;                 
00084     float mPinkScalar;                  
00085 
00086     void initialize(int numRows);       
00087 
00088 };
00089 
00090 // inline functions have to be declared in the header file to avoid linker problems
00091 
00092 inline int Noise::generateRandomNumber() {
00093     // Calculate pseudo-random 32 bit number based on linear congruential method
00094     mSeed = (mSeed * 196314165) + 907633515;
00095     return mSeed;
00096 
00097 }   
00098 
00099 inline float Noise::generateNormalizedRandomNumber() {
00100     // Calculate pseudo-random 32 bit number based on linear congruential method
00101     mSeed = (mSeed * 196314165) + 907633515;
00102     return (float) mSeed / (float) 0x7fffffff; // dividing by INT_MAX
00103 }
00104 
00105 
00106 } // namespace csl
00107 
00108 #endif
00109 

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