-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathOscillator.h
85 lines (69 loc) · 1.53 KB
/
Oscillator.h
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
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
#pragma once
/*
MINI VIRTUAL ANALOG SYNTHESIZER
Copyright 2014 Kenneth D. Miller III
Oscillator
*/
#include "Wave.h"
// base frequency oscillator configuration
class OscillatorConfig
{
public:
bool enable;
Wave wavetype;
float waveparam;
float frequency;
float amplitude;
// hard sync
bool sync_enable;
float sync_phase;
// derived values
WaveEvaluate evaluate;
size_t cycle;
float adjust;
OscillatorConfig(bool const enable, Wave const wavetype, float const waveparam, float const frequency, float const amplitude)
: enable(enable)
, wavetype(wavetype)
, waveparam(waveparam)
, frequency(frequency)
, amplitude(amplitude)
, sync_enable(false)
, sync_phase(1.0f)
{
SetWaveType(wavetype);
}
void SetWaveType(Wave type)
{
wavetype = type;
evaluate = wave_evaluate[wavetype];
cycle = wave_loop_cycle[wavetype];
adjust = wave_adjust_frequency[wavetype];
}
};
// oscillator state
class OscillatorState
{
public:
float phase;
int index;
// state values usable by wave functions
union
{
float f[8];
int i[8];
};
OscillatorState()
{
Reset();
}
// reset the oscillator
void Reset();
// start the oscillator
void Start();
// update the oscillator by one step
float Update(OscillatorConfig const &config, float const step);
// compute the oscillator value
float Compute(OscillatorConfig const &config, float delta);
// advance the oscillator phase
void Advance(OscillatorConfig const &config, float delta);
};