00001
00002
00003
00004
00005
00006 #ifndef INCLUDE_Noise_H
00007 #define INCLUDE_Noise_H
00008
00009 #include "CSL_Core.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
00052
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
00089
00090 inline int Noise :: generateRandomNumber() {
00091
00092 mSeed = (mSeed * 196314165) + 907633515;
00093 return mSeed;
00094
00095 }
00096
00097 inline float Noise :: generateNormalizedRandomNumber() {
00098
00099 mSeed = (mSeed * 196314165) + 907633515;
00100 return (float) mSeed / (float) 0x7fffffff;
00101 }
00102
00103
00104 }
00105
00106 #endif
00107