Tone.js/examples/signalMath.html
2014-12-03 22:18:51 -05:00

112 lines
No EOL
3.1 KiB
HTML

<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<title>SIGNAL PROCESSING</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">
Audio-Rate Math
<br>
<br>
One of the most powerful features of Tone.js is the ability to
perform math and logic on audio-rate signal. Signals
can be ramped and scheduled to control Audio Parameters and
other Signals making it simple to create elaborate,
interconnected automations. Additionally, Signals and Signal maths use no
ScriptProcessorNodes which make them very efficient.
</div>
<div id="Content">
<div id='Slider'></div>
</div>
</div>
<script type="text/javascript">
/* globals Tone, GUI */
//the driving signal
var signal = new Tone.Signal(0);
var dryMeter = new Tone.Meter();
signal.connect(dryMeter);
//take the absolute value of the signal
var abs = new Tone.Abs();
var absMeter = new Tone.Meter();
abs.connect(absMeter);
//add a constant value to the dry signal
var adder = new Tone.Add(100);
var addMeter = new Tone.Meter();
adder.connect(addMeter);
//normalize the added value between 0 to 1
var norm = new Tone.Normalize(100, 101);
var normMeter = new Tone.Meter();
norm.connect(normMeter);
//normalize the added value between 0 to 1
var scaler = new Tone.Scale(5, 10);
var scaleMeter = new Tone.Meter();
scaler.connect(scaleMeter);
//multiply the output by 10
var mult = new Tone.Multiply(10);
var multMeter = new Tone.Meter();
mult.connect(multMeter);
//clip the results between 70 and 80
var clip = new Tone.Clip(70, 80);
var clipMeter = new Tone.Meter();
clip.connect(clipMeter);
//chain the components together
signal.chain(abs, adder, norm, scaler, mult);
// GUI //
new GUI.TopBar(Tone);
var container = $("#Content");
$("#Slider").slider({
"orientation" : "horizontal",
"min" : -100,
"max" : 100,
"slide" : function(e, ui){
signal.linearRampToValueAtTime(ui.value / 100, "+0.1");
}
});
new GUI.ValueMeter(container, dryMeter, "Tone.Signal");
new GUI.ValueMeter(container, absMeter, "Tone.Abs()");
new GUI.ValueMeter(container, addMeter, "Tone.Add(100)");
new GUI.ValueMeter(container, normMeter, "Tone.Normalize(100, 101)");
new GUI.ValueMeter(container, scaleMeter, "Tone.Scale(5, 10)");
new GUI.ValueMeter(container, multMeter, "Tone.Multiply(10)");
</script>
<style type="text/css">
#Content {
text-align: center;
width: 280px;
height: 250px;
}
.ValueMeter {
margin-top: 10px;
display: block;
}
</style>
</body>
</html>