Period to MIDI helper
authorAlyssa Rosenzweig <alyssa@backtick.town>
Tue, 5 Jul 2016 16:47:26 +0000 (09:47 -0700)
committerAlyssa Rosenzweig <alyssa@backtick.town>
Tue, 5 Jul 2016 16:47:26 +0000 (09:47 -0700)
src/APU/period2midi.js [new file with mode: 0644]

diff --git a/src/APU/period2midi.js b/src/APU/period2midi.js
new file mode 100644 (file)
index 0000000..5c5d096
--- /dev/null
@@ -0,0 +1,18 @@
+/* period2midi.js
+ * generates a table mapping NES periods into MIDI notes
+ * internally, it's NES period -> frequency (Hz) -> MIDI note
+ * a lookup table is madef as a result
+ */
+
+var fs = require("fs");
+
+var results = [];
+for(var i = 0; i < 2048; ++i) {
+    results.push(mapping(i));
+}
+
+function mapping(period) {
+    var frequency = CPU / (period + 1);
+    var midi = 59 + (12*Math.log(frequency / 440)/Math.log(2));
+    return midi;
+}
This page took 0.023841 seconds and 4 git commands to generate.