Last active
July 30, 2017 06:20
-
-
Save softpunch/9a2a1e4d806f8a40b1e9babfea32a27f to your computer and use it in GitHub Desktop.
Just Intonation WebMIDI conversion [WIP]
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// MIDI note conversion | |
// util adapted from | |
// https://github.com/sole/MIDIUtils/blob/master/src/MIDIUtils.js | |
var noteMap = {}; | |
var noteNumberMap = []; | |
var notes = [ "C", "C#", "D", "D#", "E", "F", "F#", "G", "G#", "A", "A#", "B" ]; | |
for(var i = 0; i < 127; i++) { | |
var index = i, | |
key = notes[index % 12], | |
octave = ((index / 12) | 0) - 1; // MIDI scale starts at octave = -1 | |
if(key.length === 1) { | |
key = key + '-'; | |
} | |
key += octave; | |
noteMap[key] = i; | |
noteNumberMap[i] = key; | |
} | |
function getBaseLog(value, base) { | |
return Math.log(value) / Math.log(base); | |
} | |
var MIDIUtils = { | |
noteNameToNoteNumber: function(name) { | |
return noteMap[name]; | |
}, | |
noteNumberToFrequency: function(note) { | |
return 440.0 * Math.pow(2, (note - 69.0) / 12.0); | |
}, | |
noteNumberToName: function(note) { | |
return noteNumberMap[note]; | |
}, | |
frequencyToNoteNumber: function(f) { | |
return Math.round(12.0 * getBaseLog(f / 440.0, 2) + 69); | |
} | |
}; | |
// http://www.microtonal-synthesis.com/scale_just_intonation.html | |
// | |
// | |
// https://algoart.com/help/artwonk4/MicroTone/microtone.htm | |
Just | |
Step Key Freq PB Freq Cents PB c Note PBend Ratio Interval | |
00 69 440.0 hz 440.2 hz 0.0 0 0 0 1:1 unison | |
01 70 469.3 hz 469.8 hz 111.7 113 1 8 16:15 minor diatonic semitone | |
02 71 495.0 hz 495.4 hz 203.9 205 2 3 9:8 major whole tone | |
03 72 528.0 hz 528.3 hz 315.6 316 3 10 6:5 minor third | |
04 73 550.0 hz 550.2 hz 386.3 386 3 55 5:4 major third | |
05 74 586.7 hz 587.0 hz 498.0 498 4 63 4:3 perfect fourth | |
06 75 618.8 hz 619.2 hz 590.2 591 5 58 45:32 tritone | |
07 76 660.0 hz 660.2 hz 702.0 702 7 1 3:2 perfect fifth | |
08 77 704.0 hz 704.6 hz 813.7 814 8 9 8:5 minor sixth | |
09 78 733.3 hz 733.8 hz 884.4 884 8 54 5:3 major sixth | |
10 79 792.0 hz 792.2 hz 1018.0 1017 10 11 9:5 just minor seventh | |
11 80 825.0 hz 825.1 hz 1088.0 1088 10 56 15:8 classic major seventh | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment