mirror of
https://github.com/Tonejs/Tone.js
synced 2024-11-16 08:38:00 +00:00
fec9c3e49d
[skip ci]
136 lines
No EOL
3.8 KiB
HTML
136 lines
No EOL
3.8 KiB
HTML
<!DOCTYPE html>
|
|
<html>
|
|
<head>
|
|
<meta charset="utf-8">
|
|
<title>SIGNAL RAMP</title>
|
|
|
|
<meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1, user-scalable=no">
|
|
<link rel="icon" type="image/png" sizes="174x174" href="./style/favicon.png">
|
|
|
|
<script type="text/javascript" src="../build/Tone.js"></script>
|
|
<script type="text/javascript" src="./scripts/jquery.min.js"></script>
|
|
<script type="text/javascript" src="./scripts/draggabilly.js"></script>
|
|
<script type="text/javascript" src="https://tonejs.github.io/Logo/build/Logo.js"></script>
|
|
<script type="text/javascript" src="./scripts/StartAudioContext.js"></script>
|
|
<script type="text/javascript" src="./scripts/Interface.js"></script>
|
|
<script type="text/javascript" src="./scripts/nexusUI.js"></script>
|
|
|
|
<link rel="stylesheet" type="text/css" href="./style/examples.css">
|
|
|
|
<script type="text/javascript">
|
|
// jshint ignore: start
|
|
</script>
|
|
|
|
</head>
|
|
<body>
|
|
<style type="text/css">
|
|
canvas {
|
|
margin-top: 3px;
|
|
}
|
|
</style>
|
|
|
|
<div id="Content" class="FullScreen">
|
|
<div id="Title">rampTo</div>
|
|
<div id="Explanation">
|
|
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:
|
|
Signals are values which are updated at audio rate,
|
|
which allows for sample-accurate scheduling and ramping. <code>.rampTo(value, rampTime)</code>
|
|
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.
|
|
<br><br>
|
|
As the large dot gets closer to each of the smaller dots, a different harmonic is heard depending
|
|
on the distance to that smaller dot. The "harmony" slider adjusts each of the oscillators frequencies'
|
|
distance from the fundamental frequency.
|
|
</div>
|
|
<canvas nx="joints"></canvas>
|
|
</div>
|
|
|
|
<script type="text/javascript">
|
|
|
|
Tone.Master.volume.value = -Infinity;
|
|
|
|
var oscillators = {};
|
|
|
|
var bassFreq = 32;
|
|
|
|
var reverb = new Tone.JCReverb().toMaster();
|
|
|
|
for (var i = 0; i < 8; i++){
|
|
oscillators["node" + i] = new Tone.Oscillator({
|
|
"frequency" : bassFreq * i,
|
|
"type" : "sawtooth10",
|
|
"detune" : Math.random() * 30 - 15,
|
|
}).connect(reverb).start();
|
|
}
|
|
|
|
</script>
|
|
|
|
<script type="text/javascript">
|
|
|
|
nx.onload = function(){
|
|
nx.colorize("#7F33ED");
|
|
|
|
joints1.nodeSize = 25;
|
|
joints1.val.x = Math.random();
|
|
joints1.val.y = Math.random();
|
|
joints1.resize($("#Content").width(), 250);
|
|
joints1.animate("bounce");
|
|
var width = joints1.width;
|
|
var height = joints1.height;
|
|
joints1.threshold = Math.max($("#Content").width() / 1.5, 60);
|
|
joints1.init();
|
|
joints1.draw();
|
|
|
|
$(window).on("resize", function(){
|
|
joints1.resize($("#Content").width(), 250);
|
|
joints1.threshold = Math.max($("#Content").width() / 1.5, 60);
|
|
joints1.draw();
|
|
});
|
|
|
|
function setValues(data){
|
|
for (var n in oscillators){
|
|
if (data.hasOwnProperty(n)){
|
|
oscillators[n].volume.rampTo((1 - Math.pow(data[n], 0.5)) * -60, 0.3);
|
|
} else {
|
|
oscillators[n].volume.rampTo(-Infinity, 0.4);
|
|
}
|
|
}
|
|
}
|
|
|
|
joints1.on("*", setValues);
|
|
|
|
Interface.Slider({
|
|
name : "harmony",
|
|
min : 0.5,
|
|
max : 2,
|
|
value : 1,
|
|
drag : function(value){
|
|
var i = 0;
|
|
for (var n in oscillators){
|
|
var osc = oscillators[n];
|
|
osc.frequency.rampTo(bassFreq * i * value, 0.4);
|
|
i++;
|
|
}
|
|
},
|
|
});
|
|
|
|
|
|
Interface.Button({
|
|
text : "Unmute",
|
|
activeText : "Mute",
|
|
type : "toggle",
|
|
key : 32, //spacebar
|
|
start : function(){
|
|
Tone.Master.volume.rampTo(-20, 0.5);
|
|
},
|
|
end : function(){
|
|
Tone.Master.volume.rampTo(-Infinity, 0.5);
|
|
},
|
|
});
|
|
|
|
}
|
|
</script>
|
|
|
|
</body>
|
|
</html> |