Created
January 31, 2019 08:51
-
-
Save seven-phases-max/efe2070551ecf1cf75f025c64061818d to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#include <cmath> | |
#include <iostream> | |
#include <iomanip> | |
const double C0 = 16.352; | |
const double ln2per12 = std::log(2.) / 12; | |
// your ref and approx frequency values: | |
const int index[] = {46, 623, 954}; | |
const double refFreq[] = {1.33304775683583476286742097727255895733833313, 37.3506591867008808094396954402327537537, 252.719842525523120002617361024022102356}; | |
const double apxFreq[] = {1.33304797524971263555926270782947540283203125, 37.3506628974037084844894707202911376953, 252.719804590087733231484889984130859375}; | |
// ............................................................ | |
void testErrors() { | |
using namespace std; | |
cout.precision(12); | |
const int n = sizeof(index)/sizeof(*index); | |
cout << "pitch index: "; | |
for (int i = 0; i < n; i++) | |
cout << " " << setw(18) << left << index[i]; | |
cout << endl; | |
cout << "relative errors:"; | |
for (int i = 0; i < n; i++) | |
cout << " " << abs(refFreq[i] - apxFreq[i]) / refFreq[i]; | |
cout << endl; | |
cout << "pitch errors: "; | |
for (int i = 0; i < n; i++) { | |
double a = log(refFreq[i] / C0) / ln2per12; | |
double b = log(apxFreq[i] / C0) / ln2per12; | |
cout << " " << abs(a - b); | |
} | |
cout << endl; | |
} | |
// ............................................................ | |
int main() { | |
testErrors(); | |
return 0; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment