-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathAlgorithm.h
180 lines (176 loc) · 6.59 KB
/
Algorithm.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
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
#ifndef ALGORITHM_H
#define ALGORITHM_H
#include "Operator.h" // class with operators definition
#include "Parameters.h" // for accessing parameters set by the user interface
/// Algorithm class which defines phase modulation routing for operators.
class Algorithm
{
public:
/// process algorithm
/// @param Operator*, array with operators
/// @param bool*, empty bool array (should be the same size as the operators array);
/// array gets overwritten: true means the operator outputs sound,
/// false means the operator modulates another.
/// @return float, output sample
float process (Operator* ops, bool* isOutput)
{
float algorithmOut = 0.0f;
float opSampleA, opSampleB, opSampleC, opSampleD;
for (int i = 0; i < numOperators; i++)
isOutput[i] = false;
// switch to specified algorithm
switch (algorithm)
{
case 0:
// specify output operators
isOutput[0] = true;
// process algorithm
opSampleD = ops[3].process();
ops[2].setOscPhaseOffset (opSampleD);
opSampleC = ops[2].process();
ops[1].setOscPhaseOffset (opSampleC);
opSampleB = ops[1].process();
ops[0].setOscPhaseOffset (opSampleB);
algorithmOut = ops[0].process();
break;
case 1:
// specify output operators
isOutput[0] = true;
// process algorithm
opSampleD = ops[3].process();
opSampleC = ops[2].process();
ops[1].setOscPhaseOffset ((opSampleC + opSampleD) / 2);
opSampleB = ops[1].process();
ops[0].setOscPhaseOffset (opSampleB);
algorithmOut = ops[0].process();
break;
case 2:
// specify output operators
isOutput[0] = true;
// process algorithm
opSampleD = ops[3].process();
opSampleC = ops[2].process();
ops[1].setOscPhaseOffset (opSampleC);
opSampleB = ops[1].process();
ops[0].setOscPhaseOffset ((opSampleB + opSampleD) / 2);
algorithmOut = ops[0].process();
break;
case 3:
// specify output operators
isOutput[0] = true;
// process algorithm
opSampleD = ops[3].process();
ops[2].setOscPhaseOffset (opSampleD);
opSampleC = ops[2].process();
ops[1].setOscPhaseOffset (opSampleD);
opSampleB = ops[1].process();
ops[0].setOscPhaseOffset ((opSampleB + opSampleC) / 2);
algorithmOut = ops[0].process();
break;
case 4:
// specify output operators
isOutput[0] = true;
isOutput[1] = true;
// process algorithm
opSampleD = ops[3].process();
ops[2].setOscPhaseOffset (opSampleD);
opSampleC = ops[2].process();
ops[1].setOscPhaseOffset (opSampleC);
opSampleB = ops[1].process();
ops[0].setOscPhaseOffset (opSampleC);
opSampleA = ops[0].process();
algorithmOut = (opSampleA + opSampleB) / 2;
break;
case 5:
// specify output operators
isOutput[0] = true;
isOutput[1] = true;
// process algorithm
opSampleD = ops[3].process();
ops[2].setOscPhaseOffset (opSampleD);
opSampleC = ops[2].process();
ops[1].setOscPhaseOffset (opSampleC);
opSampleB = ops[1].process();
opSampleA = ops[0].process();
algorithmOut = (opSampleA + opSampleB) / 2;
break;
case 6:
// specify output operators
isOutput[0] = true;
// process algorithm
opSampleD = ops[3].process();
opSampleC = ops[2].process();
opSampleB = ops[1].process();
ops[0].setOscPhaseOffset ((opSampleB + opSampleC + opSampleD) / 3);
algorithmOut = ops[0].process();
break;
case 7:
// specify output operators
isOutput[0] = true;
isOutput[2] = true;
// process algorithm
opSampleD = ops[3].process();
ops[2].setOscPhaseOffset (opSampleD);
opSampleC = ops[2].process();
opSampleB = ops[1].process();
ops[0].setOscPhaseOffset (opSampleB);
opSampleA = ops[0].process();
algorithmOut = (opSampleA + opSampleC) / 2;
break;
case 8:
// specify output operators
isOutput[0] = true;
isOutput[1] = true;
isOutput[2] = true;
// process algorithm
opSampleD = ops[3].process();
ops[2].setOscPhaseOffset (opSampleD);
opSampleC = ops[2].process();
ops[1].setOscPhaseOffset (opSampleD);
opSampleB = ops[1].process();
ops[0].setOscPhaseOffset (opSampleD);
opSampleA = ops[0].process();
algorithmOut = (opSampleA + opSampleB + opSampleC) / 3;
break;
case 9:
// specify output operators
isOutput[0] = true;
isOutput[1] = true;
isOutput[2] = true;
// process algorithm
opSampleD = ops[3].process();
ops[2].setOscPhaseOffset (opSampleD);
opSampleC = ops[2].process();
opSampleB = ops[1].process();
opSampleA = ops[0].process();
algorithmOut = (opSampleA + opSampleB + opSampleC) / 3;
break;
case 10:
// specify output operators
isOutput[0] = true;
isOutput[1] = true;
isOutput[2] = true;
isOutput[3] = true;
// process algorithm
opSampleD = ops[3].process();
opSampleC = ops[2].process();
opSampleB = ops[1].process();
opSampleA = ops[0].process();
algorithmOut = (opSampleA + opSampleB + opSampleC + opSampleD) / 4;
break;
}
return algorithmOut;
}
/// initialises algorithm per each note
/// @param Parameters*, pointer to the parameters class (that contains
/// algorithm number and number of operators)
void startNote (Parameters* _param)
{
algorithm = *_param->algorithm;
numOperators = _param->numOperators;
}
private:
int algorithm; // algorithm number
int numOperators; // number of operators
};
#endif // ALGORITHM_H