-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathAudioUtil.cpp
281 lines (279 loc) · 4.45 KB
/
AudioUtil.cpp
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
#include "AudioUtil.h"
#include <math.h>
/**
* Takes a frequency and calculates a new frequency based on the number of semitones shifted.
*
* Only works with an integer number of steps on a 12-tone equal temperament scale.
*/
double AudioUtil::ScaleFrequency(double frequency, int numSemitones)
{
double ratio = pow(1.0594630943592952, numSemitones);
return ratio;
}
/**
* Gets the frequency of a MIDI note to 3 decimal places.
*/
double AudioUtil::GetFrequencyFromMIDINote(int noteNumber)
{
switch( noteNumber )
{
case 0: // C-1
return 8.176;
case 1:
return 8.662;
case 2:
return 9.177;
case 3:
return 9.723;
case 4:
return 10.301;
case 5:
return 10.913;
case 6:
return 11.562;
case 7:
return 12.250;
case 8:
return 12.978;
case 9: // A-1
return 13.750;
case 10:
return 14.568;
case 11:
return 15.434;
case 12: // C0
return 16.352;
case 13:
return 17.324;
case 14:
return 18.354;
case 15:
return 19.445;
case 16:
return 20.602;
case 17:
return 21.827;
case 18:
return 23.125;
case 19:
return 24.500;
case 20:
return 25.957;
case 21:
return 27.500;
case 22:
return 29.135;
case 23:
return 30.868;
case 24: // C1
return 32.703;
case 25:
return 34.648;
case 26:
return 36.708;
case 27:
return 38.891;
case 28:
return 41.203;
case 29:
return 43.654;
case 30:
return 46.249;
case 31:
return 48.999;
case 32:
return 51.913;
case 33: // A1
return 55.000;
case 34:
return 58.270;
case 35:
return 61.735;
case 36: // C2
return 65.406;
case 37:
return 69.296;
case 38:
return 73.416;
case 39:
return 77.782;
case 40:
return 82.407;
case 41:
return 87.307;
case 42:
return 92.499;
case 43:
return 97.999;
case 44:
return 103.826;
case 45: // A2
return 110.000;
case 46:
return 116.541;
case 47:
return 123.471;
case 48: // C3
return 130.813;
case 49:
return 138.591;
case 50:
return 146.832;
case 51:
return 155.563;
case 52:
return 164.814;
case 53:
return 174.614;
case 54:
return 184.997;
case 55:
return 195.998;
case 56:
return 207.652;
case 57: // A3
return 220.000;
case 58:
return 233.082;
case 59:
return 246.942;
case 60: // C4
return 261.626;
case 61:
return 277.183;
case 62:
return 293.665;
case 63:
return 311.127;
case 64:
return 329.628;
case 65:
return 349.228;
case 66:
return 369.994;
case 67:
return 391.995;
case 68:
return 415.305;
case 69: // A4
return 440.000;
case 70:
return 466.164;
case 71:
return 493.883;
case 72: // C5
return 523.251;
case 73:
return 554.365;
case 74:
return 587.330;
case 75:
return 622.254;
case 76:
return 659.255;
case 77:
return 698.456;
case 78:
return 739.989;
case 79:
return 783.991;
case 80:
return 830.609;
case 81: // A5
return 880.000;
case 82:
return 932.328;
case 83:
return 987.767;
case 84: // C6
return 1046.502;
case 85:
return 1108.731;
case 86:
return 1174.659;
case 87:
return 1244.508;
case 88:
return 1318.510;
case 89:
return 1396.913;
case 90:
return 1479.978;
case 91:
return 1567.982;
case 92:
return 1661.219;
case 93: // A6
return 1760.000;
case 94:
return 1864.655;
case 95:
return 1975.533;
case 96: // C7
return 2093.005;
case 97:
return 2217.461;
case 98:
return 2349.318;
case 99:
return 2489.016;
case 100:
return 2637.020;
case 101:
return 2793.826;
case 102:
return 2959.955;
case 103:
return 3135.963;
case 104:
return 3322.438;
case 105: // A7
return 3520.000;
case 106:
return 3729.310;
case 107:
return 3951.066;
case 108: // C8
return 4186.009;
case 109:
return 4434.922;
case 110:
return 4698.636;
case 111:
return 4978.032;
case 112:
return 5274.041;
case 113:
return 5587.652;
case 114:
return 5919.911;
case 115:
return 6271.927;
case 116:
return 6644.875;
case 117: // A8
return 7040.00;
case 118:
return 7548.620;
case 119:
return 7902.133;
case 120: // C9
return 8372.018;
case 121:
return 8869.844;
case 122:
return 9397.273;
case 123:
return 9956.063;
case 124:
return 10548.08;
case 125:
return 11175.30;
case 126:
return 11839.82;
case 127: // G9
return 12543.85;
default:
return 0.0;
}
}