-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathMusical_Notes_2
More file actions
49 lines (42 loc) · 1.83 KB
/
Musical_Notes_2
File metadata and controls
49 lines (42 loc) · 1.83 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
//Music.cpp
//gets the frequency of music notes and wavelength
//chukim@chapman.edu
#include <iostream>
#include <cmath>
#include <iomanip>
using namespace std;
int main(int argc, const char * argv[]) {
// insert code here...
double ReferenceFrequency = 16.35;
double speedOfSound = 345;
double dTwelfthRootOfTwo = pow(2.0,(1/12.0));
string a_strNotes[] = {
"C0", "C#0", "D0","D#0", "E0", "F0", "F#0", "G0", "G#0", "A0", "A#0", "B0",
"C1", "C#1", "D1","D#1", "E1", "F1", "F#1", "G1", "G#1", "A1", "A#1", "B1",
"C2", "C#2", "D2","D#2", "E2", "F2", "F#2", "G2", "G#2", "A2", "A#2", "B2",
"C3", "C#3", "D3","D#3", "E3", "F3", "F#3", "G3", "G#3", "A3", "A#3", "B3",
"C4", "C#4", "D4","D#4", "E4", "F4", "F#4", "G4", "G#4", "A4", "A#4", "B4",
"C5", "C#5", "D5","D#5", "E5", "F5", "F#5", "G5", "G#5", "A5", "A#5", "B5",
"C6", "C#6", "D6","D#6", "E6", "F6", "F#6", "G6", "G#6", "A6", "A#6", "B6",
"C7", "C#7", "D7","D#7", "E7", "F7", "F#7", "G7", "G#7", "A7", "A#7", "B7",
"C8", "C#8", "D8","D#8", "E8", "F8", "F#8", "G8", "G#8", "A8", "A#8", "B8",
};
const int k_nOctaves = 9;
const int n_nHalfTones =12;
string strNote;
int x;
double f;
double dWavelengthCentimeters;
for (int nu = 0; nu < k_nOctaves; nu++){
for (int k = 0; k <n_nHalfTones; k++){
strNote = a_strNotes[x];
x += 1;
f = ReferenceFrequency * pow(2.0,nu) * pow(dTwelfthRootOfTwo,k);
dWavelengthCentimeters = (speedOfSound * 100) / f;
cout << "Note: " << strNote << "; nu: " << nu << "; k: " << k << "; frequency: " << f << " Hz; wavelength: " << dWavelengthCentimeters << " cm" << endl;
// cout << nu << endl;
// cout << k << endl;
}
}
return 0;
}