Tone.js/examples/signalProcessing.html

101 lines
No EOL
2.8 KiB
HTML

<html>
<head>
<title>SIGNAL PROCESSING</title>
<link rel="stylesheet" type="text/css" href="../style/GUI.css">
<script src="http://code.jquery.com/jquery-2.1.0.min.js"></script>
<script type="text/javascript" src="../src/core/Tone.js"></script>
<script type="text/javascript" src="../src/signal/Signal.js"></script>
<script type="text/javascript" src="../src/signal/Add.js"></script>
<script type="text/javascript" src="../src/signal/Invert.js"></script>
<script type="text/javascript" src="../src/signal/Normalize.js"></script>
<script type="text/javascript" src="../src/signal/Scale.js"></script>
<script type="text/javascript" src="../src/components/Meter.js"></script>
<script type="text/javascript" src="../src/components/LFO.js"></script>
</head>
<body>
<style type="text/css">
</style>
<input type='range' value='100'>
<div id='signal'>0</div>
<div id='invert'>0</div>
<div id='add'>0</div>
<div id='normalize'>0</div>
<div id='scale'>0</div>
<script type="text/javascript">
var signal = new Tone.Signal();
var dryMeter = new Tone.Meter();
signal.connect(dryMeter);
var oscillator = Tone.context.createOscillator();
oscillator.connect(Tone.context.destination);
oscillator.start(0);
//the inverter
var inverter = new Tone.Invert();
var invertMeter = new Tone.Meter();
inverter.connect(invertMeter);
signal.connect(inverter);
//the adder
var adder = new Tone.Add(100);
var addMeter = new Tone.Meter();
adder.connect(addMeter);
inverter.connect(adder);
//control the frequency with the output
adder.connect(oscillator.frequency);
//normalize back to -1 to 1
var norm = new Tone.Normalize(99, 101);
var normMeter = new Tone.Meter();
norm.connect(normMeter);
adder.connect(norm);
//the scaler
var scaler = new Tone.Scale(5, 10);
var scaleMeter = new Tone.Meter();
scaler.connect(scaleMeter);
norm.connect(scaler);
//lfo
var lfo = new Tone.LFO(.5);
lfo.connect(signal);
lfo.start();
var $signal = $("#signal");
var $invert = $("#invert");
var $add = $("#add");
var $norm = $("#normalize");
var $scale = $("#scale");
setInterval(function(){
$signal.html("signal: " + dryMeter.getValue().toFixed(3));
$invert.html("inverted: " + invertMeter.getValue().toFixed(3));
$add.html("add 100: " + addMeter.getValue().toFixed(3));
$norm.html("normalized : "+normMeter.getValue().toFixed(3));
$scale.html("scaled 5 to 10: " + scaleMeter.getValue().toFixed(3));
/*$signal.html("signal: " + dryMeter.getValue());
$invert.html("incoming: " + );
$add.html("add 10: " + addMeter.getValue());*/
}, 100);
var range = $("input")[0];
range.onchange = function(){
var val = range.value;
var now = signal.now();
signal.linearRampToValueAtTime(val / 50 - 1, now + .1);
}
// signal.toMaster();
</script>
</body>
</html>