14.3.07

CC Week 2 - MIDI n to freq

With the assistance of your function from the previous week create a control structure that generates the entire MIDI note range of frequencies. The code will build and print an array that contains note name, octave number, MIDI note number and frequency.


(
// build a table of note names

var table = ();

value
{
var semitones = [0, 2, 4, 5, 7, 9, 11];
var naturalNoteNames = ["c", "d", "e", "f", "g", "a", "b"];


(0..9).do
{
arg o;

naturalNoteNames.do
{

arg c, i;

var n = (o + 1) * 12 + semitones[i];

table[(c ++ o).asSymbol] = n; table[(c ++ "s" ++ o).asSymbol] = n + 1; //determine sharp
table[(c ++ "ss" ++ o).asSymbol] = n + 2; //determine double sharp
table[(c ++ "b" ++ o).asSymbol] = n - 1; //determine flat
table[(c ++ "bb" ++ o).asSymbol] = n - 2; //determine double flat

};
};
};

"Pitch class and Octave Number, MIDI Note Number, Frequency Value" .postln;
a = table.atAll (#[a4].postln).postln;// Creates MIDI Note number --Enter Pitch class and Octave number here.


a = 2**((a-69)/12) *440; //Coverts MIDI note number to frequency value


)


__________
[1] Christian Haines. "Creative Computing: Semester 1, Week 2. Introduction (2)" Lecture presented at EMU, University of Adelaide, South Australia, 08/03/2007.