OpenWareLaboratory
NoiseOscillator.h
Go to the documentation of this file.
1 #ifndef NOISE_OSCILLATOR_HPP
2 #define NOISE_OSCILLATOR_HPP
3 
4 #include "Oscillator.h"
5 
11 class NoiseOscillator : public OscillatorTemplate<NoiseOscillator> {
12 protected:
13  float sample = 0;
14 public:
15  static constexpr float begin_phase = 0;
16  static constexpr float end_phase = 1;
18  NoiseOscillator(float sr){
19  setSampleRate(sr);
20  }
21  float getSample(){
22  return sample;
23  }
24  float generate() {
25  phase += incr;
26  if(phase >= 1){
27  sample = randf()*2 - 1;
28  phase -= 1;
29  }
30  return sample;
31  }
33  void reset(){
34  sample = randf()*2 - 1;
35  phase = 0;
36  }
38 };
39 
40 #endif /* NOISE_OSCILLATOR_HPP */
float randf()
generate a random number between 0 and 1
Definition: basicmaths.c:74
The NoiseOscillator generates random values in the range [-1, 1] at a given frequency.
static constexpr float begin_phase
void reset()
Reset oscillator (typically resets phase)
static constexpr float end_phase
float generate()
Produce the next consecutive sample.
NoiseOscillator(float sr)
virtual float generate()
Produce the next consecutive sample.