Tone.js/examples/signal.html

108 lines
2.9 KiB
HTML
Raw Normal View History

2015-06-08 14:41:45 +00:00
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<title>Signals</title>
2015-06-27 22:10:18 +00:00
<meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1, user-scalable=no">
2015-12-08 05:06:58 +00:00
<link rel="icon" type="image/png" sizes="174x174" href="./style/favicon.png">
2015-06-08 14:41:45 +00:00
<script src="../build/Tone.js"></script>
<script src="./scripts/jquery.min.js"></script>
<script src="./scripts/draggabilly.js"></script>
<script src="https://tonejs.github.io/Logo/build/Logo.js"></script>
<script src="./scripts/StartAudioContext.js"></script>
<script src="./scripts/Interface.js"></script>
2015-06-08 14:41:45 +00:00
<link rel="stylesheet" type="text/css" href="./style/examples.css">
<script>
2015-06-08 14:41:45 +00:00
// jshint ignore: start
</script>
</head>
<body>
<div id="Content">
2015-06-27 22:02:55 +00:00
<div id="Title">Control Voltage</div>
2015-06-08 14:41:45 +00:00
<div id="Explanation">
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,
2015-06-26 05:23:05 +00:00
interconnected automations.
<br><br>
2015-06-27 22:02:55 +00:00
This example applies a series of mappings to a
2015-06-26 05:23:05 +00:00
signal value and applies the results of those mappings
2015-06-27 22:02:55 +00:00
to the frequency attribute of 2
<a href="https://tonejs.github.io/docs/#Oscillator">Tone.Oscillators</a>
and a <a href="https://tonejs.github.io/docs/#LFO">Tone.LFO</a>.
2015-06-08 14:41:45 +00:00
</div>
</div>
<script>
2015-06-26 05:23:05 +00:00
//initially muted
Tone.Master.mute = true;
//use this to pan the two oscillators hard left/right
var merge = new Tone.Merge().toMaster();
//two oscillators panned hard left / hard right
var rightOsc = new Tone.Oscillator({
"type" : "sawtooth",
"volume" : -20
}).connect(merge.right).start();
2015-06-08 14:41:45 +00:00
2015-06-26 05:23:05 +00:00
var leftOsc = new Tone.Oscillator({
"type" : "square",
"volume" : -20
}).connect(merge.left).start();
2015-06-08 14:41:45 +00:00
2015-06-26 05:23:05 +00:00
//create an oscillation that goes from 0 to 1200
//connection it to the detune of the two oscillators
var detuneLFO = new Tone.LFO({
"type" : "square",
"min" : 0,
"max" : 1200
}).fan(rightOsc.detune, leftOsc.detune).start();
//the frequency signal
var frequency = new Tone.Signal(0.5);
//the move the 0 to 1 value into frequency range
var scale = new Tone.ScaleExp(110, 440);
2015-06-08 14:41:45 +00:00
2015-06-26 05:23:05 +00:00
//multiply the frequency by 2.5 to get a 10th above
var mult = new Tone.Multiply(2.5);
2015-06-08 14:41:45 +00:00
//chain the components together
2015-06-26 05:23:05 +00:00
frequency.chain(scale, mult);
scale.connect(rightOsc.frequency);
mult.connect(leftOsc.frequency);
//multiply the frequency by 2 to get the octave above
var detuneScale = new Tone.Scale(14, 4);
frequency.chain(detuneScale, detuneLFO.frequency);
2017-03-26 20:39:19 +00:00
// GUI //
Interface.Slider({
drag : function(value){
frequency.rampTo(value, 0.1);
},
start : function(){
Tone.Master.mute = false;
},
end: function(){
Tone.Master.mute = true;
},
name : "frequency",
min : 0,
max : 1,
exp : 0.5,
value : 0.5,
position: 5
2015-06-26 05:23:05 +00:00
});
2015-06-08 14:41:45 +00:00
</script>
2017-03-26 20:39:19 +00:00
2015-06-08 14:41:45 +00:00
</body>
</html>