Tone.js/examples/noises.html

80 lines
No EOL
1.9 KiB
HTML

<html>
<head>
<title>NOISES</title>
<meta name="viewport" content="width=device-width, initial-scale=1, user-scalable=no">
<script type="text/javascript" src="./deps/jquery.min.js"></script>
<script type="text/javascript" src="./deps/jquery-ui.js"></script>
<script type="text/javascript" src="./deps/jquery.ui.touch-punch.js"></script>
<script type="text/javascript" src="../build/Tone.js"></script>
<script type="text/javascript" src="./Widgets.js"></script>
<script type="text/javascript" src="./ExampleList.js"></script>
<link rel="stylesheet" type="text/css" href="./style/widgets.css">
<link rel="stylesheet" type="text/css" href="./style/jquery-ui.css">
</head>
<body>
<div id="Container">
<div id="Explanation">
Noise
<br>
<br>
Tone has 3 different types of noise. Here's a little noise song.
</div>
<div id="Content">
<div id="Button"></div>
<div id='Noise'></div>
</div>
<script type="text/javascript">
/* globals Tone, GUI */
var noise = new Tone.Noise();
noise.setVolume(-20);
noise.toMaster();
var noiseTypes = ["white", "brown", "pink"];
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);
$("#Noise").text(randomNoise);
}, "8n");
//stop it after 4 measures
Tone.Transport.setTimeout(function(time){
noise.stop(time);
Tone.Transport.stop();
$("#Noise").text("done");
setTimeout(function(){
$("#Noise").text("");
}, 500);
}, "4m");
// GUI //
new GUI.TopBar(Tone);
new GUI.Momentary($("#Button"), function(){
Tone.Transport.start();
noise.start();
$("#Button").remove();
}, "start", "");
</script>
<style type="text/css">
#Content {
text-align: center;
width: 120px;
}
#Content .Momentary{
width: 100%;
}
</style>
</body>
</html>