// chuck_note2hz.c // // Creates a list of note variables assigned to their frequencies. // Makes working with ChucK ugen instruments easier. // // eg. // TubeBell tb => dac; // C3 => tb.freq; // 1.0 => tb.noteOn; // // Frequency values created with the following formula: // // 0 < n < 128: // A = 440; // (A/32) * (2^((n-9)/12)) // // Build: cc -o chuck_note2hz chuck_note2hz.c -lm // // Usage: For the standard A5=440.0 tuning: // chuck_note2hz > midi2hz.ck // For a nonstandard tuning A5 != 440.0 HZ // A5=321.0 ./chuck_note2hz > midi2hz_A5_321.0.ck // // Author: Burton Samograd aka. kruhft .at. gmail - 2006 // // License: Public Domain. Do as thou wish. // Same with the generated code. #define A5 440.0 #include #include #include int main() { int i; double a5; char *tmp = getenv("A5"); if(tmp) a5 = strtod(tmp, 0); else a5 = A5; char *n[] = { "C", "Db", "D", "Eb", "E", "F", "Gb", "G", "Ab", "A", "Bb", "B" }; for(i=0;i<128;i++) { int note = i%12; double hz = (a5 / 32.0) * pow(2.0, (((double)i-9.0)/12.0)); if(*(n[note]+1)) { printf("%.8f => float %cs%d;\n", hz, (*n[note])-1, i/12); printf("%.8f => float %s%d;\n", hz, n[note], i/12); } else printf("%.8f => float %s%d;\n", hz, n[note], i/12); } }