-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathzmModuleOsc.h
71 lines (59 loc) · 1.94 KB
/
zmModuleOsc.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
#ifndef zMorsModuleOsc_h
#define zMorsModuleOsc_h
#define PORT_OSC_OUT_SAW 0
#define PORT_OSC_OUT_SIN 1
#define PORT_OSC_OUT_SQR 2
#define PORT_OSC_FRQ 3
#define PORT_OSC_AMP 4
class zmModuleOsc : public zmModule {
public:
float thea = 0;
const float B = 4.0f / M_PI;
const float C = -4.0f / (M_PI * M_PI);
zmModuleOsc() {
title = "OSC";
portName[PORT_OSC_OUT_SAW] = "out saw";
portName[PORT_OSC_OUT_SIN] = "out sin";
portName[PORT_OSC_OUT_SQR] = "out sqr";
portName[PORT_OSC_FRQ] = "frq";
portName[PORT_OSC_AMP] = "amp";
parameterName[0] = "thea";
parameterDefaults[0] = 0.005;
parameterName[1] = "level";
parameterDefaults[1] = 1.0;
parameterName[2] = "pw";
parameterDefaults[2] = 0.5;
parameterName[3] = "fm_deep";
parameterDefaults[3] = 0.5;
thea = 0;
}
void genSample(float * bus) {
thea += (parameterMap[0] ) + bus[portMap[PORT_OSC_FRQ]] * parameterMap[3];
if (thea < -1.0) {
thea = -1.0;
} else if (thea >= 1.0) {
thea -= 2.0;
}
if (portMap[PORT_OSC_OUT_SAW]) {
// saw out
bus[portMap[PORT_OSC_OUT_SAW]] = thea * (parameterMap[1] + bus[portMap[PORT_OSC_AMP]]) ;
bus[0] = 0.0;
}
if (portMap[PORT_OSC_OUT_SQR]) {
// sqr out
if ( thea > parameterMap[2] ) {
bus[portMap[PORT_OSC_OUT_SQR]] = (parameterMap[1] + bus[portMap[PORT_OSC_AMP]]) ;
} else {
bus[portMap[PORT_OSC_OUT_SQR]] = (parameterMap[1] + bus[portMap[PORT_OSC_AMP]]) * -1.0;
}
bus[0] = 0.0;
}
if (portMap[PORT_OSC_OUT_SIN]) {
// sin out
float x = thea * M_PI;
bus[portMap[PORT_OSC_OUT_SIN]] = ( B * x + C * x * fabs(x) ) * (parameterMap[1] + bus[portMap[PORT_OSC_AMP]]) ;
bus[0] = 0.0;
}
};
};
#endif