-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathCalculateCorrection.cpp
More file actions
61 lines (51 loc) · 1.65 KB
/
Copy pathCalculateCorrection.cpp
File metadata and controls
61 lines (51 loc) · 1.65 KB
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
#include <fstream>
#include <vector>
using namespace std;
struct mapping_t {
vector<int> frequencies {33, 311, 880, 2093, 3729, 5274, 5588, 7902};
vector<double> volume {0.0, 48.5475, 588.928, 957.485, 2814.41, 1386.78, 433.613, 62.1036};
} mappingStruct;
// Calculate correction with one value per note
void calculateCorrection1() {
ifstream infile("frequencyScale");
ofstream outfile("frequencyCorrection");
int frequency;
double value;
float level = 200.0;
float counter = 0.0;
float stepSize = 0;
while(infile >> frequency >> value) {
// Ignore frequencies below 180hz, values are getting too big
if(frequency > 180) {
double correction = (level - counter) / value;
correction = correction + (1 - correction)/4;
outfile << frequency << " " << correction << endl;
counter += stepSize;
}
}
infile.close();
outfile.close();
}
// Calculate correction with approximate values
void calculateCorrection2() {
ofstream outfile("frequencyCorrectionAlt");
float level = 200.0;
float counter = 0.0;
float stepSize = 8;
for(int i = 0; i < mappingStruct.frequencies.size(); i++) {
float val = mappingStruct.volume[i];
int freq = mappingStruct.frequencies[i];
if(val != 0) {
double correction = (level - counter) / val;
outfile << freq << " " << correction << endl;
counter += stepSize;
} else {
outfile << freq << " " << val << endl;
}
}
outfile.close();
}
int main(int argc, char *argv[]) {
calculateCorrection1();
calculateCorrection2();
}