Tone.js/examples/rampTo.html

91 lines
2.3 KiB
HTML
Raw Normal View History

2015-06-27 21:25:01 +00:00
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<title>SIGNAL RAMP</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-27 21:25:01 +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-27 21:25:01 +00:00
<link rel="stylesheet" type="text/css" href="./style/examples.css">
<script>
2015-06-27 21:25:01 +00:00
// jshint ignore: start
</script>
</head>
<body>
<style type="text/css">
canvas {
margin-top: 3px;
}
</style>
2017-08-31 16:41:54 +00:00
2015-06-27 21:25:01 +00:00
<div id="Content" class="FullScreen">
<div id="Title">rampTo</div>
<div id="Explanation">
2017-08-31 16:41:54 +00:00
In Tone.js, many of a class' members are <a href="https://tonejs.github.io/docs/#Signal">Tone.Signals</a>.
Working with signals is different than working with numbers or strings:
2015-06-27 22:02:55 +00:00
Signals are values which are updated at audio rate,
2015-06-27 21:25:01 +00:00
which allows for sample-accurate scheduling and ramping. <code>.rampTo(value, rampTime)</code>
2017-08-31 16:41:54 +00:00
smoothly changes the signal from the current value to the target value over the duration of the rampTime.
This example uses <code>.rampTo</code> in to smooth out changes in volume and frequency.
2015-06-27 21:25:01 +00:00
</div>
</div>
<script>
2015-06-27 21:25:01 +00:00
2017-08-31 16:41:54 +00:00
var oscillators = [];
2015-06-27 21:25:01 +00:00
var bassFreq = 32;
for (var i = 0; i < 8; i++){
2017-08-31 16:41:54 +00:00
oscillators.push(new Tone.Oscillator({
2015-06-27 21:25:01 +00:00
"frequency" : bassFreq * i,
"type" : "sawtooth10",
2017-08-31 16:41:54 +00:00
"volume" : -Infinity,
2015-06-27 21:25:01 +00:00
"detune" : Math.random() * 30 - 15,
2017-08-31 16:41:54 +00:00
}).start().toMaster());
2015-06-27 21:25:01 +00:00
}
2017-08-31 16:41:54 +00:00
Interface.Slider({
name : "harmony",
min : 0.5,
max : 2,
value : 1,
drag : function(value){
oscillators.forEach(function(osc, i){
osc.frequency.rampTo(bassFreq * i * value, 0.4);
});
},
});
Interface.Button({
text : "Unmute",
activeText : "Mute",
type : "toggle",
key : 32, //spacebar
start : function(){
oscillators.forEach(function(osc){
osc.volume.rampTo(-20, 1);
});
},
end : function(){
oscillators.forEach(function(osc){
osc.volume.rampTo(-Infinity, 1);
});
},
});
2015-06-27 21:25:01 +00:00
</script>
</body>
</html>