Tone.js/examples/panner.html

57 lines
1.2 KiB
HTML
Raw Normal View History

2014-04-05 00:24:19 +00:00
<html>
<head>
<title>PANNER</title>
2014-04-05 00:24:19 +00:00
<script type="text/javascript" src="../build/Tone.js"></script>
2014-04-05 00:24:19 +00:00
</head>
<body>
2014-04-06 00:47:59 +00:00
<button type="button">start</button>
2014-04-05 00:24:19 +00:00
<input type='range' value='50'>
<div id='left'>0</div>
<div id='right'>0</div>
<script type="text/javascript">
var pan = new Tone.Panner();
var sine = new Tone.Oscillator();
2014-04-05 00:24:19 +00:00
//connect it up
sine.connect(pan);
pan.toMaster();
2014-04-05 00:24:19 +00:00
//meters
var outputMeter = new Tone.Meter(2);
pan.connect(outputMeter);
2014-04-05 00:24:19 +00:00
//INTERFACE//
2014-04-05 00:24:19 +00:00
var button = document.querySelector("button");
2014-04-05 00:24:19 +00:00
button.onclick = function(){
if (!sine.started){
sine.start();
button.textContent = "stop";
} else {
sine.stop();
button.textContent = "start";
}
}
2014-04-06 00:47:59 +00:00
var left = document.querySelector("#left");
var right = document.querySelector("#right");
setInterval(function(){
left.textContent = "left: " + outputMeter.getDb(0).toFixed(2) + " db";
right.textContent = "right: " + outputMeter.getDb(1).toFixed(2) + " db";
}, 100);
var range = document.querySelector("input");
range.onchange = function(){
var val = range.value;
pan.setPan(val/100, "+.1");
}
2014-04-05 00:24:19 +00:00
</script>
</body>
</html>