-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathOscillator.ixx
54 lines (40 loc) · 1.04 KB
/
Oscillator.ixx
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
module;
#include <numbers>;
export module megasynth.oscillator;
constexpr inline double twoPi = 2 * std::numbers::pi;
export class Oscillator {
public:
enum Waveform
{
SINE = 0,
SAW,
SQUARE,
TRIANGLE,
kNumberOfWaveforms
};
inline void setWaveform(Waveform waveform) { this->waveform = waveform; }
void setFrequency(double frequency);
void setSampleRate(double sampleRate);
void setPitchMod(double amount);
// void generate(double* buffer, int numFrames);
virtual double nextSample();
void reset() { phase = 0.0; }
Oscillator() { updateIncrement(); }
protected:
Waveform waveform = SINE;
double frequency = 440.0;
double phase = 0.0;
static double sampleRate;
double phaseIncrement;
double pitchMod = 0.0;
void updateIncrement();
double naiveWaveform(Waveform wave);
};
export class PolyBlepOscillator : public Oscillator {
public:
PolyBlepOscillator() { updateIncrement(); }
double nextSample() override;
private:
double lastOutput = 0.0;
double poly_blep(double t);
};