-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathsynthesizer.h
164 lines (139 loc) · 2.79 KB
/
synthesizer.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
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
#ifndef SYNTHESIZER_H
#define SYNTHESIZER_H
#include "audio.h"
class ADSREnvelope
{
public:
float attack;
float decay;
float sustain;
float release;
char state;
int a_s;
int d_s;
int r_s;
float cur_amp;
float starting_amp;
ADSREnvelope() : attack(0.01),
decay(0.1),
sustain(1),
release(0.01),
state('z'),
a_s((int)(attack * SR)),
d_s((int)(decay * SR)),
r_s((int)(release * SR)),
cur_amp(0),
starting_amp(0) {}
};
class LowFrequencyOscillator
{
public:
float freq;
int choice;
bool enabled;
float phase;
float phase_incr;
int osc_type;
float o_freq;
float o_phase_incr;
float o_ratio;
float f_cutoff;
int b_amount;
float o_amount;
int amount;
LowFrequencyOscillator() : freq(5),
choice(0),
enabled(true),
phase(0),
phase_incr(freq * phase_factor * 16),
osc_type(0),
o_freq(0),
o_phase_incr(0),
o_ratio(0),
f_cutoff(440),
b_amount(0),
o_amount(0),
amount(50) {}
};
class Filter {
public:
int filter_type;
bool filter_enabled;
float cutoff;
float resonance;
float bandwidth;
float x1;
float x2;
float y1;
float y2;
float C;
float D;
float a0;
float a1;
float a2;
float b1;
float b2;
std::vector<float *> values;
Filter() : filter_type(0),
filter_enabled(false),
cutoff(440),
resonance(0),
bandwidth(0),
x1(0),
x2(0),
y1(0),
y2(0),
C(0),
D(0),
a0(0),
a1(0),
a2(0),
b1(0),
b2(0) {}
};
class Distortion {
public:
bool enabled;
int type;
int b_amount;
float o_amount;
Distortion() : enabled(false),
type(0),
b_amount(16),
o_amount(1) {}
};
class Synthesizer
{
public:
float freq;
float osc_ratio;
int osc1_type;
int osc2_type;
int samp; // the current sample number
float phase; // current phase
float phase_incr; // calculate based on value of freq
float output_volume;
int midi_device;
int pbend_range;
Synthesizer() : freq(0),
osc_ratio(.5),
osc1_type(0),
osc2_type(0),
samp(0),
phase(0),
phase_incr(freq * TWOPI_T),
output_volume(.75),
midi_device(-1),
pbend_range(100) {}
float get_sample();
};
extern Synthesizer g;
extern LowFrequencyOscillator l;
extern ADSREnvelope e;
extern Filter f;
extern Distortion d;
extern std::vector<float> wave_table_saw;
extern std::vector<float> wave_table_sine;
extern std::vector<float> wave_table_tri;
extern std::vector<float> wave_table_square;
#endif // SYNTHESIZER_H