dos33fsprogs/music/redbook_sound/generate_frequencies.c

56 lines
1.8 KiB
C

#include <stdio.h>
#include <math.h>
static float note_frequencies[9][12]={
/* C C# D D# E F F# G G# A A# B */
{16.35, 17.32, 18.35, 19.45, 20.60, 21.83, 23.12, 24.50, 25.96, 27.50, 29.14, 30.87},
{32.70, 34.65, 36.71, 38.89, 41.20, 43.65, 46.25, 49.00, 51.91, 55.00, 58.27, 61.74},
{65.41, 69.30, 73.42, 77.78, 82.41, 87.31, 92.50, 98.00, 103.8, 110.0, 116.5, 123.5},
{130.8, 138.6, 146.8, 155.6, 164.8, 174.6, 185.0, 196.0, 207.7, 220.0, 233.1, 246.9},
{261.6, 277.2, 293.7, 311.1, 329.6, 349.2, 370.0, 392.0, 415.3, 440.0, 466.2, 493.9},
{523.3, 554.4, 587.3, 622.3, 659.3, 698.5, 740.0, 784.0, 830.6, 880.0, 932.3, 987.8},
{1047, 1109, 1175, 1245, 1319, 1397, 1480, 1568, 1661, 1760, 1865, 1976},
{2093, 2217, 2349, 2489, 2637, 2794, 2960, 3136, 3322, 3520, 3729, 3951},
{4186, 4435, 4699, 4978, 5274, 5588, 5920, 6272, 6645, 7040, 7459, 7902},
};
static char note_names[12][12]={
"C","CSHARP","D","DSHARP","E","F","FSHARP","G","GSHARP","A","ASHARP","B",
};
int main(int argc, char **argv) {
int f,o;
float value,actual;
char temp_string[50];
for(o=3;o<7;o++) {
for(f=0;f<12;f++) {
// freq = 1/((20v+17)*1.023e-6)
// ((20v+17)*1.023e-6)= 1/freq
// 20v*1.023e-6 + 17*1.023e-6 = 1/freq
// 20v*1.023e-6 = (1/freq)-17*1.023e-6)
// v = ((1/freq)-17*1.023e-6)/(20*1.023e-6)
value=(1.0/(
(20.0*(1.023e-6)*note_frequencies[o][f])-
17*1.023e-6
));
actual=1.0/((20.0*value+17)*1.023e-6);
// value = ((1.0/note_frequencies[o][f])-17.0*1.023e-6)/
// 20.0*1.023e-6;
snprintf(temp_string,50,"NOTE_%s%1d",
note_names[f],o);
printf("%-12s = %d\t; %.1f (%.1f)\n",
temp_string,(int)round(value),
actual,note_frequencies[o][f]);
}
}
return 0;
}