Skip to content

Instantly share code, notes, and snippets.

@FrankieFabuloso
Forked from anonymous/index.html
Last active February 8, 2017 18:17
Show Gist options
  • Save FrankieFabuloso/4c62978fba04f06b03ea670cb97f7242 to your computer and use it in GitHub Desktop.
Save FrankieFabuloso/4c62978fba04f06b03ea670cb97f7242 to your computer and use it in GitHub Desktop.
Play it again JavaScript
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width">
<title>JS Bin</title>
</head>
<body>
<button class='button1' onmousedown='noise(261.63)'onmouseup='silence()' >C</button>
<button class='button2' onmousedown='noise(293.66)'onmouseup='silence()' >D</button>
<button class='button1' onmousedown='noise(329.63)'onmouseup='silence()' >E</button>
<button class='button2' onmousedown='noise(349.23)'onmouseup='silence()' >F</button>
<button class='button1' onmousedown='noise(392.00)'onmouseup='silence()' >G</button>
<button class='button1' onmousedown='noise(440.00)'onmouseup='silence()' >A</button>
<button class='button2' onmousedown='noise(493.88)'onmouseup='silence()' >B</button>
<script id="jsbin-javascript">
var AudioContext = window.AudioContext || window.webkitAudioContext;
var audioCtx = new AudioContext();
var oscillator = audioCtx.createOscillator();
var gainNode = audioCtx.createGain();
var finish = audioCtx.destination;
oscillator.type = 'square';
oscillator.start();
function noise(value){
oscillator.frequency.value = value; // value in hertz
oscillator.connect(audioCtx.destination);
}
function silence(){
oscillator.disconnect(audioCtx.destination);
}
</script>
<script id="jsbin-source-javascript" type="text/javascript">var AudioContext = window.AudioContext || window.webkitAudioContext;
var audioCtx = new AudioContext();
var oscillator = audioCtx.createOscillator();
var gainNode = audioCtx.createGain();
var finish = audioCtx.destination;
oscillator.type = 'square';
oscillator.start();
function noise(value){
oscillator.frequency.value = value; // value in hertz
oscillator.connect(audioCtx.destination);
}
function silence(){
oscillator.disconnect(audioCtx.destination);
}
</script></body>
</html>
var AudioContext = window.AudioContext || window.webkitAudioContext;
var audioCtx = new AudioContext();
var oscillator = audioCtx.createOscillator();
var gainNode = audioCtx.createGain();
var finish = audioCtx.destination;
oscillator.type = 'square';
oscillator.start();
function noise(value){
oscillator.frequency.value = value; // value in hertz
oscillator.connect(audioCtx.destination);
}
function silence(){
oscillator.disconnect(audioCtx.destination);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment