Created
December 8, 2016 04:48
-
-
Save soenkehahn/f2947c5e37a8fff8fedbbd9a1def4d98 to your computer and use it in GitHub Desktop.
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
<html> | |
<body id="main"> | |
hi | |
<script src="sound.js"></script> | |
<script> | |
/* | |
var node = document.getElementById('main'); | |
console.log(node); | |
var app = Elm.Main.embed(node); | |
console.log(app.ports.eval); | |
app.ports.eval.subscribe((string) => { | |
console.log('eval'); | |
console.log(string); | |
eval(string); | |
}); */ | |
</script> | |
</body> | |
</html> |
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
const context = new window.AudioContext | |
const oscillators = {} | |
const addOscillator = (key, freq) => { | |
var osc = context.createOscillator(); | |
osc.frequency.value = freq; | |
osc.connect(context.destination); | |
oscillators[key] = osc; | |
}; | |
const keys = "x2v3l4c5w6k7h8g9f0q"; | |
let keyNumber = 0; | |
for (key of keys) { | |
console.log(key, keyNumber); | |
freq = 300 * Math.pow(Math.pow(2, 1 / 12), keyNumber); | |
addOscillator(key, freq); | |
keyNumber += 1; | |
}; | |
document.body.onkeyup = (k) => { | |
if (oscillators.hasOwnProperty(k.key)) { | |
osc = oscillators[k.key]; | |
osc.stop(); | |
const freq = osc.frequency.value; | |
addOscillator(k.key, freq); | |
}; | |
}; | |
document.body.onkeydown = (k) => { | |
if (oscillators.hasOwnProperty(k.key)) { | |
osc = oscillators[k.key]; | |
osc.start(); | |
}; | |
} | |
/* | |
const osc = context.createOscillator() | |
osc.frequency.value = 440 | |
osc.connect(context.destination) | |
osc.start() | |
console.log(osc) | |
setTimeout(() => { | |
osc.stop(); | |
}, 1000); | |
*/ |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment