Last active
May 28, 2016 13:00
-
-
Save vinyll/195a149c0277e744123eeb752f9dafd7 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
/** | |
* Click to start the sound and move your mouse horizontally. | |
* Click again to stop the sound. | |
* To go further checkout the following links: | |
* Some tutorial: http://mmckegg.github.io/web-audio-school/ | |
* Midi demo: taktech.orgtakm/WebFMSynth | |
* Premade sounds library: https://github.com/Tonejs/Tone.js | |
* Checkout audioGraph | |
*/ | |
var audioContext = new AudioContext() | |
let oscillators = [ | |
audioContext.createOscillator(), | |
audioContext.createOscillator(), | |
audioContext.createOscillator(), | |
] | |
let filter = audioContext.createBiquadFilter() | |
//let gain = audioContext.createGain() | |
oscillator.type = 'sawtooth' | |
oscillator.connect(filter).connect(audioContext.destination) | |
oscillator.start() | |
window.addEventListener('mousemove', (event) => { | |
if(oscillator) { | |
oscillator.frequency.value = event.clientX | |
gain.gain.value = event.clientY / window.innerHeight * 10 | |
} | |
}) | |
// window.addEventListener('click', (event) => { | |
// if(oscillator) { | |
// oscillator.stop() | |
// oscillator = null | |
// } | |
// else { | |
// buildOscillator().start() | |
// } | |
// }) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment