Tone.js/examples/autoPanner.html

67 lines
1.3 KiB
HTML
Raw Normal View History

2014-04-03 21:13:13 +00:00
<html>
<head>
2014-04-06 00:47:59 +00:00
<title>AUTOPANNER</title>
2014-04-05 00:24:19 +00:00
<script type="text/javascript" src='../Tone.js'></script>
2014-04-03 21:13:13 +00:00
</head>
<body>
2014-04-06 00:47:59 +00:00
<button>start</button>
<input type='range' value='50'>
2014-04-05 00:24:19 +00:00
<div id='left'>0</div>
<div id='right'>0</div>
2014-04-03 21:13:13 +00:00
<script type="text/javascript">
//panner
var pan = new Tone.AutoPanner();
2014-04-03 21:13:13 +00:00
//input signals
var sine = new Tone.Oscillator();
2014-04-03 21:13:13 +00:00
//connect it up
sine.connect(pan);
pan.toMaster();
2014-04-03 21:13:13 +00:00
//meter
var meter = new Tone.Meter(2);
pan.connect(meter);
2014-04-05 00:24:19 +00:00
//star the panner lfo
pan.start();
2014-04-05 00:24:19 +00:00
var leftMeter = document.querySelector("#left");
var rightMeter = document.querySelector("#right");
//meter the content
setInterval(function(){
leftMeter.textContent = "left: " + meter.getDb(0).toFixed(2) + " db";
rightMeter.textContent = "right: " + meter.getDb(1).toFixed(2) + " db";
}, 100);
2014-04-05 00:24:19 +00:00
//INTERFACE//
2014-04-05 00:24:19 +00:00
var button = document.querySelector("button");
2014-04-03 21:13:13 +00:00
//called when the start button is clicked
button.onclick = function(){
if (!sine.started){
2014-04-06 00:47:59 +00:00
sine.start();
button.textContent = "stop";
} else {
sine.stop();
button.textContent = "start";
2014-04-06 00:47:59 +00:00
}
}
var range = document.querySelector("input");
2014-04-06 00:47:59 +00:00
//called when the range is changed
range.onchange = function(){
var val = range.value;
2014-06-15 21:37:17 +00:00
pan.setDry(val / 50 - 1, "+ .1");
}
2014-04-06 00:47:59 +00:00
2014-04-03 21:13:13 +00:00
</script>
</body>
</html>