Skip to content

Commit d811ea4

Browse files
author
Martin Klang
committed
added NoiseOscillator class (whitenoise s+h)
1 parent d5ed8c2 commit d811ea4

3 files changed

Lines changed: 38 additions & 7 deletions

File tree

HISTORY.md

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,6 @@
1+
v22.2
2+
-----
3+
* Added NoiseOscillator (whitenoise s+h)
14
* Added PhaseShiftOscillator template
25
* Added Biquad allpass filter configuration
36
* Fixed Antialiased oscillators (Triangle, SquareWave, Ramp)

LibSource/NoiseOscillator.h

Lines changed: 34 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,40 @@
11
#ifndef NOISE_OSCILLATOR_HPP
22
#define NOISE_OSCILLATOR_HPP
33

4-
#include "NoiseGenerator.h"
4+
#include "Oscillator.h"
55

6-
#warning "NoiseOscillator.h is deprecated, use NoiseGenerator.h instead"
7-
8-
typedef WhiteNoiseGenerator WhiteNoiseOscillator;
9-
typedef PinkNoiseGenerator PinkNoiseOscillator;
10-
typedef BrownNoiseGenerator BrownNoiseOscillator;
11-
typedef GaussianNoiseGenerator GaussianNoiseOscillator;
6+
/**
7+
* The NoiseOscillator generates random values in the range [-1, 1] at
8+
* a given frequency.
9+
* It behaves like a white noise generator going into a sample and hold.
10+
*/
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;
17+
NoiseOscillator(){}
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+
}
32+
using OscillatorTemplate<NoiseOscillator>::generate;
33+
void reset(){
34+
sample = randf()*2 - 1;
35+
phase = 0;
36+
}
37+
using SignalGenerator::generate;
38+
};
1239

1340
#endif /* NOISE_OSCILLATOR_HPP */

LibSource/OpenWareLibrary.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,7 @@
3333
#include "MorphingOscillator.h"
3434
#include "MonophonicProcessor.h"
3535
#include "NoiseGenerator.h"
36+
#include "NoiseOscillator.h"
3637
#include "OpenWareMidiControl.h"
3738
#include "Oscillator.h"
3839
#include "Patch.h"

0 commit comments

Comments
 (0)