-
Notifications
You must be signed in to change notification settings - Fork 0
/
Program.h
289 lines (250 loc) · 9.48 KB
/
Program.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
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
#ifndef Program_h_
#define Program_h_
class Program {
private:
//Waveform of operators [2]
short waveform[2];
//Original frequency of operator will be multiplied by this value [2]
float freqMul[2];
//This value (in Hz) will be added to the operator frequency after freqMul was applied [2]
float freqAdd[2];
//Operator volume DAHDSR envelope [2][6]
float volumeDAHDSR[2][6];
//TODO: Operator pitch DAHDSR [2][6]
//The maximum volume of the operators
float operatorVolume[2];
//The waveshape of the operators
float waveshape[2][WAVESHAPE_SAMPLE_SIZE];
//float feedback; //feedback amount
//byte fmAlgorithm; //the fm algorithm to use (1x4 op, 2x2op, 4x1op etc.) UPDATE: This is not possible at the moment since the audio library can not really be reconnected/instanced at runtime
//byte algorithm; //The modulation algorithm to use. Frequency modulation or phase modulation
//string name; //name of the program
float filterCutoff; //Filter cutoff frequency
float filterResonance; //Filter resonance. Range 0-5. Values > 0.7 will amplify the signal near the corner frequency.
float filterOctaveControl; //Range is 0 to 7 octaves. For example, when set to 2.5, a full scale positive signal (1.0) will shift the filter frequency up 2.5 octaves, and a full scale negative signal will shift it down 2.5 octaves.
float filterMixer[3]; //Filter mixer settings. 0 = lowpass, 1 = bandpass, 2 = highpass
float filterDAHDSR[6];
void Setup(short waveform[2],
float waveshape[2][WAVESHAPE_SAMPLE_SIZE],
float freqMul[2],
float freqAdd[2],
float volumeDAHDSR[2][6],
float operatorVolume[2],
float filterCutoff,
float filterResonance,
float filterOctaveControl,
float filterMixer[3],
float filterDAHDSR[6]);
public:
Program();
Program(short waveform[2],
float waveshape[2][WAVESHAPE_SAMPLE_SIZE],
float freqMul[2],
float freqAdd[2],
float volumeDAHDSR[2][6],
float operatorVolume[2],
float filterCutoff,
float filterResonance,
float filterOctaveControl,
float filterMixer[3],
float filterDAHDSR[6]);
void SetWaveform(byte operatorIndex, short waveform);
short GetWaveform(byte operatorIndex);
void SetFreqMul(byte operatorIndex, float factor);
float GetFreqMul(byte operatorIndex);
void SetFreqAdd(byte operatorIndex, float hz);
float GetFreqAdd(byte operatorIndex);
void SetVolumeDAHDSR(byte operatorIndex, float dahdsr[6]);
float *GetVolumeDAHDSR(byte operatorIndex);
void SetOperatorVolume(byte operatorIndex, float volume);
float GetOperatorVolume(byte operatorIndex);
void SetWaveshape(byte operatorIndex, float samples[WAVESHAPE_SAMPLE_SIZE]);
void SetWaveshape(byte operatorIndex, byte sampleIndex, float sample);
float *GetWaveshape(byte operatorIndex);
float GetWaveshape(byte operatorIndex, byte sampleIndex);
void SetFilterCutoff(float cutoff);
float GetFilterCutoff();
void SetFilterResonance(float resonance);
float GetFilterResonance();
void SetFilterOctaveControl(float factor);
float GetFilterOctaveControl();
void SetFilterLowpassVolume(float volume);
float GetFilterLowpassVolume();
void SetFilterBandpassVolume(float volume);
float GetFilterBandpassVolume();
void SetFilterHighpassVolume(float volume);
float GetFilterHighpassVolume();
void SetFilterDAHDSR(float dahdsr[6]);
float *GetFilterDAHDSR();
};
Program::Program() {
short _waveform[2] = {WAVEFORM_SINE, WAVEFORM_SINE};
float _freqMul[2] = {1.0, 1.0};
float _freqAdd[2] = {0.0, 0.0};
/*
uint16_t _volumeDAHDSR[4][6] = {
{0, 10, 0, 10, 1, 10},
{0, 10, 0, 10, 1, 10},
{0, 10, 0, 10, 1, 10},
{0, 10, 0, 10, 1, 10}
};
*/
float _volumeDAHDSR[2][6] = {
{0, 1, 0, 1, 1, 1},
{0, 1, 0, 1, 1, 1}
//{0, 1, 0, 1, 1, 1},
//{0, 1, 0, 1, 1, 1}
};
float _operatorVolume[2] = {0, 1};
float _waveshape[2][WAVESHAPE_SAMPLE_SIZE] = {
{-1, -0.875, -0.75, -0.625, -0.5, -0.375, -0.25, -0.125, 0, 0.125, 0.25, 0.375, 0.5, 0.625, 0.75, 0.875, 1},
{-1, -0.875, -0.75, -0.625, -0.5, -0.375, -0.25, -0.125, 0, 0.125, 0.25, 0.375, 0.5, 0.625, 0.75, 0.875, 1}
};
float _filterMixer[3] = {1,1,1};
float _filterDAHDSR[6] = {0, 0,0,0,0,0};
this->Setup(_waveform, _waveshape, _freqMul, _freqAdd, _volumeDAHDSR, _operatorVolume, 11025, 0.707, 0, _filterMixer, _filterDAHDSR);
}
Program::Program(short waveform[2],
float waveshape[2][WAVESHAPE_SAMPLE_SIZE],
float freqMul[2],
float freqAdd[2],
float volumeDAHDSR[2][6],
float operatorVolume[2],
float filterCutoff,
float filterResonance,
float filterOctaveControl,
float filterMixer[3],
float filterDAHDSR[6]) {
this->Setup(waveform, waveshape, freqMul, freqAdd, volumeDAHDSR, operatorVolume, filterCutoff, filterResonance, filterOctaveControl, filterMixer, filterDAHDSR);
}
void Program::Setup(short waveform[2],
float waveshape[2][WAVESHAPE_SAMPLE_SIZE],
float freqMul[2],
float freqAdd[2],
float volumeDAHDSR[2][6],
float operatorVolume[2],
float filterCutoff,
float filterResonance,
float filterOctaveControl,
float filterMixer[3],
float filterDAHDSR[6]) {
//TODO: Reset settings and free memory
//Copy settings
for(int i=0; i<2; ++i){
this->waveform[i] = waveform[i];
this->freqMul[i] = freqMul[i];
this->freqAdd[i] = freqAdd[i];
this->SetVolumeDAHDSR(i, volumeDAHDSR[i]);
this->SetOperatorVolume(i, operatorVolume[i]);
this->SetWaveshape(i, waveshape[i]);
}
this->SetFilterCutoff(filterCutoff);
this->SetFilterResonance(filterResonance);
this->SetFilterOctaveControl(filterOctaveControl);
this->SetFilterLowpassVolume(filterMixer[0]);
this->SetFilterBandpassVolume(filterMixer[1]);
this->SetFilterHighpassVolume(filterMixer[2]);
this->SetFilterDAHDSR(filterDAHDSR);
}
//Sets the waveforms of an operator
void Program::SetWaveform(byte operatorIndex, short waveform) {
this->waveform[operatorIndex] = waveform;
}
//Gets the waveform of an operator
short Program::GetWaveform(byte operatorIndex) {
//byte _w[2] = {WAVEFORM_SINE, WAVEFORM_SINE, WAVEFORM_SINE, WAVEFORM_SINE};
//byte *test;
//return *(test+0) // *(test+1) *(test+2)
return this->waveform[operatorIndex];
}
//Sets the frequency multiplicator of an operator
void Program::SetFreqMul(byte operatorIndex, float factor) {
this->freqMul[operatorIndex] = factor;
}
//Gets the frequency multiplicator of an operator
float Program::GetFreqMul(byte operatorIndex) {
return this->freqMul[operatorIndex];
}
//Sets a frequency to be added to an operator
void Program::SetFreqAdd(byte operatorIndex, float hz) {
this->freqAdd[operatorIndex] = hz;
}
//Get the frequency that is added to an operator
float Program::GetFreqAdd(byte operatorIndex) {
return this->freqAdd[operatorIndex];
}
//Sets the volume DAHDSR envelope for an operator
void Program::SetVolumeDAHDSR(byte operatorIndex, float dahdsr[6]){
for(int i=0; i<6; ++i){
this->volumeDAHDSR[operatorIndex][i] = dahdsr[i];
}
}
//Gets the volume DAHDSR envelope for an operator
float *Program::GetVolumeDAHDSR(byte operatorIndex){
return this->volumeDAHDSR[operatorIndex];
}
void Program::SetOperatorVolume(byte operatorIndex, float volume){
this->operatorVolume[operatorIndex] = volume;
}
float Program::GetOperatorVolume(byte operatorIndex){
return this->operatorVolume[operatorIndex];
}
void Program::SetWaveshape(byte operatorIndex, float samples[WAVESHAPE_SAMPLE_SIZE]){
for(int i=0; i<WAVESHAPE_SAMPLE_SIZE; ++i){
this->waveshape[operatorIndex][i] = samples[i];
}
}
void Program::SetWaveshape(byte operatorIndex, byte sampleIndex, float sample){
this->waveshape[operatorIndex][sampleIndex] = sample;
}
float *Program::GetWaveshape(byte operatorIndex){
return this->waveshape[operatorIndex];
}
float Program::GetWaveshape(byte operatorIndex, byte sampleIndex){
return this->waveshape[operatorIndex][sampleIndex];
}
void Program::SetFilterCutoff(float cutoff){
this->filterCutoff = cutoff;
}
float Program::GetFilterCutoff(){
return this->filterCutoff;
}
void Program::SetFilterResonance(float resonance){
this->filterResonance = resonance;
}
float Program::GetFilterResonance(){
return this->filterResonance;
}
void Program::SetFilterOctaveControl(float factor){
this->filterOctaveControl = factor;
}
float Program::GetFilterOctaveControl(){
return this->filterOctaveControl;
}
void Program::SetFilterLowpassVolume(float volume){
this->filterMixer[0] = volume;
}
float Program::GetFilterLowpassVolume(){
return this->filterMixer[0];
}
void Program::SetFilterBandpassVolume(float volume){
this->filterMixer[1] = volume;
}
float Program::GetFilterBandpassVolume(){
return this->filterMixer[1];
}
void Program::SetFilterHighpassVolume(float volume){
this->filterMixer[2] = volume;
}
float Program::GetFilterHighpassVolume(){
return this->filterMixer[2];
}
void Program::SetFilterDAHDSR(float dahdsr[6]){
for(int i=0; i<6; ++i){
this->filterDAHDSR[i] = dahdsr[i];
}
}
float *Program::GetFilterDAHDSR(){
return this->filterDAHDSR;
}
#endif