summaryrefslogtreecommitdiff
path: root/nyqstk/src/Noise.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'nyqstk/src/Noise.cpp')
-rw-r--r--nyqstk/src/Noise.cpp51
1 files changed, 51 insertions, 0 deletions
diff --git a/nyqstk/src/Noise.cpp b/nyqstk/src/Noise.cpp
new file mode 100644
index 0000000..d982e02
--- /dev/null
+++ b/nyqstk/src/Noise.cpp
@@ -0,0 +1,51 @@
+/***************************************************/
+/*! \class Noise
+ \brief STK noise generator.
+
+ Generic random number generation using the
+ C rand() function. The quality of the rand()
+ function varies from one OS to another.
+
+ by Perry R. Cook and Gary P. Scavone, 1995 - 2005.
+*/
+/***************************************************/
+
+#include "Noise.h"
+#include <stdlib.h>
+#include <time.h>
+
+using namespace Nyq;
+
+Noise :: Noise() : Generator()
+{
+ // Seed the random number generator with system time.
+ this->setSeed( 0 );
+ lastOutput_ = (StkFloat) 0.0;
+}
+
+Noise :: Noise( unsigned int seed ) : Generator()
+{
+ // Seed the random number generator
+ this->setSeed( seed );
+ lastOutput_ = (StkFloat) 0.0;
+}
+
+Noise :: ~Noise()
+{
+}
+
+void Noise :: setSeed( unsigned int seed )
+{
+ if ( seed == 0 )
+ srand( (unsigned int) time(NULL) );
+ else
+ srand( seed );
+}
+
+StkFloat Noise :: computeSample()
+{
+ lastOutput_ = (StkFloat) (2.0 * rand() / (RAND_MAX + 1.0) );
+ lastOutput_ -= 1.0;
+ return lastOutput_;
+}
+