Home Information Classes Download Usage Mail List Requirements Links FAQ Tutorial

Noise.h
1 #ifndef STK_NOISE_H
2 #define STK_NOISE_H
3
4 #include "Generator.h"
5 #include <stdlib.h>
6
7 namespace stk {
8
9 /***************************************************/
19 /***************************************************/
20
21 class Noise : public Generator
22 {
23 public:
24
26
30 Noise( unsigned int seed = 0 );
31
33
37 void setSeed( unsigned int seed = 0 );
38
40 StkFloat lastOut( void ) const { return lastFrame_[0]; };
41
43 StkFloat tick( void );
44
46
53 StkFrames& tick( StkFrames& frames, unsigned int channel = 0 );
54
55 protected:
56
57 };
58
59 inline StkFloat Noise :: tick( void )
60 {
61 return lastFrame_[0] = (StkFloat) ( 2.0 * rand() / (RAND_MAX + 1.0) - 1.0 );
62 }
63
64 inline StkFrames& Noise :: tick( StkFrames& frames, unsigned int channel )
65 {
66 #if defined(_STK_DEBUG_)
67 if ( channel >= frames.channels() ) {
68 oStream_ << "Noise::tick(): channel and StkFrames arguments are incompatible!";
69 handleError( StkError::FUNCTION_ARGUMENT );
70 }
71 #endif
72
73 StkFloat *samples = &frames[channel];
74 unsigned int hop = frames.channels();
75 for ( unsigned int i=0; i<frames.frames(); i++, samples += hop )
76 *samples = (StkFloat) ( 2.0 * rand() / (RAND_MAX + 1.0) - 1.0 );
77
78 lastFrame_[0] = *(samples-hop);
79 return frames;
80 }
81
82 } // stk namespace
83
84 #endif

The Synthesis ToolKit in C++ (STK)
©1995--2017 Perry R. Cook and Gary P. Scavone. All Rights Reserved.