Add TAL-Reverb-II plugin to test
[juce-lv2.git] / tal-reverb-2-juce / src / Engine / NoiseGenerator.h
blob083fe79c5e0445fe2c4484c1239635d07287f505
1 /*
2 ==============================================================================
3 This file is part of Tal-Reverb by Patrick Kunz.
5 Copyright(c) 2005-2009 Patrick Kunz, TAL
6 Togu Audio Line, Inc.
7 http://kunz.corrupt.ch
9 This file may be licensed under the terms of of the
10 GNU General Public License Version 2 (the ``GPL'').
12 Software distributed under the License is distributed
13 on an ``AS IS'' basis, WITHOUT WARRANTY OF ANY KIND, either
14 express or implied. See the GPL for the specific language
15 governing rights and limitations.
17 You should have received a copy of the GPL along with this
18 program. If not, go to http://www.gnu.org/licenses/gpl.html
19 or write to the Free Software Foundation, Inc.,
20 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
21 ==============================================================================
25 #if !defined(__NoiseGenerator_h)
26 #define __NoiseGenerator_h
28 #include <cstdlib>
30 class NoiseGenerator
32 public:
33 int randSeed;
34 float actualValue;
35 float deltaValue;
37 float actualValueFiltered;
38 float filterFactor;
39 float filterFactorInversePlusOne;
41 float invertedRandomMax;
43 NoiseGenerator(int sampleRate)
45 // No sample rate conversion here
46 filterFactor = 5000.0f;
47 filterFactorInversePlusOne = 1.0f / (filterFactor + 1.0f);
49 actualValue = 0.0f;
50 actualValueFiltered = 0.0f;
51 deltaValue = 0.0f;
53 getNextRandomPeriod(1.0f);
55 randSeed = 1;
58 // returns a random value [0..1]
59 inline float tickNoise()
61 // return ((float)(((randSeed = randSeed * 214013L + 2531011L) >> 16) & 0x7fff)/RAND_MAX);
63 randSeed *= 16807;
64 return (float)(randSeed & 0x7FFFFFFF) * 4.6566129e-010f;
65 //return (float)randSeed * 4.6566129e-010f;
68 // returns a lp filtered random value [0..1]
69 inline float tickFilteredNoise()
71 if (actualValue >= 1.0f)
73 getNextRandomPeriod(-1.0f);
75 if (actualValue <= 0.0f)
77 getNextRandomPeriod(1.0f);
79 actualValue += deltaValue;
81 // Exponential averager
82 actualValueFiltered = (actualValueFiltered * filterFactor + actualValue) * filterFactorInversePlusOne;
83 return actualValueFiltered;
86 inline void getNextRandomPeriod(float sign)
88 int randomPeriod = (int)(tickNoise() * 22768.0f) + 22188;
89 deltaValue = 1.0f / (float)randomPeriod;
90 deltaValue *= sign;
93 inline float tickFilteredNoiseFast()
95 actualValueFiltered = (actualValueFiltered * 1000.0f + tickNoise()) / 1001.0f;
96 return actualValueFiltered;
99 #endif