Tone.js/examples/noises.html

45 lines
1 KiB
HTML
Raw Normal View History

2014-06-20 04:25:00 +00:00
<html>
<head>
<title>NOISES</title>
<script src="http://code.jquery.com/jquery-2.1.0.min.js"></script>
<script type="text/javascript" src="../Tone.js"></script>
<link rel="stylesheet" type="text/css" href="exampleStyle.css">
2014-06-20 04:25:00 +00:00
</head>
<body>
<div>Change switch to random noise type every quarter-second for 8 seconds</div>
<br>
<button>start</button>
<div id='noise'></div>
2014-06-20 04:25:00 +00:00
<script type="text/javascript">
var noise = new Tone.Noise();
noise.toMaster();
2014-06-20 04:25:00 +00:00
var noiseTypes = ["white", "brown", "pink"];
2014-06-20 04:25:00 +00:00
Tone.Transport.setInterval(function(time){
//set a random noise type
var randomIndex = Math.floor(Math.random()* noiseTypes.length);
var randomNoise = noiseTypes[randomIndex];
noise.setType(randomNoise, time);
2014-06-20 04:25:00 +00:00
$("#noise").text(randomNoise);
}, 0.25);
2014-06-20 04:25:00 +00:00
Tone.Transport.setTimeout(function(time){
noise.stop(time);
Tone.Transport.stop();
$("#noise").text("");
}, 8);
2014-06-20 04:25:00 +00:00
$("button").click(function(){
Tone.Transport.start();
noise.start();
$(this).remove();
2014-06-20 04:25:00 +00:00
});
</script>
</body>
</html>