Tone.js/examples/envelope.html

129 lines
2.7 KiB
HTML
Raw Normal View History

<!DOCTYPE html>
2014-03-15 03:17:18 +00:00
<html>
<head>
<meta charset="utf-8">
2014-03-15 05:02:33 +00:00
<title>Envelope</title>
2014-03-15 03:17:18 +00:00
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-02-12 03:39:28 +00:00
<script src="../build/Tone.js"></script>
<script src="./scripts/jquery.min.js"></script>
<script src="./scripts/draggabilly.js"></script>
<script src="./scripts/StartAudioContext.js"></script>
<script src="./scripts/Interface.js"></script>
<script src="https://tonejs.github.io/Logo/build/Logo.js"></script>
2014-08-27 15:16:49 +00:00
2015-02-12 03:39:28 +00:00
<link rel="stylesheet" type="text/css" href="./style/examples.css">
2014-06-20 15:04:32 +00:00
<script>
2015-02-12 03:39:28 +00:00
// jshint ignore: start
</script>
2014-08-26 03:47:07 +00:00
2015-02-12 03:39:28 +00:00
</head>
<body>
<style type="text/css">
2015-06-26 05:23:05 +00:00
img {
2015-06-27 22:02:55 +00:00
width: 300px!important;
2015-02-12 03:39:28 +00:00
}
2015-06-26 05:23:05 +00:00
.y {
float: left;
height: 290px!important;
}
#Sliders {
float: left;
position: relative;
width: calc(100% - 100px);
}
.Button {
clear: both;
2015-02-12 03:39:28 +00:00
}
</style>
<div id="Content">
2015-06-26 05:23:05 +00:00
<div id="Title">Envelope</div>
<div id="Explanation">
2015-06-27 21:25:01 +00:00
Envelopes ramp amplitude, frequency or any other parameter over time.
<a href="https://tonejs.github.io/docs/#Envelope">Tone.Envelope</a> and the classes that extend it
2015-06-26 05:23:05 +00:00
implement an <a href="https://en.wikipedia.org/wiki/Synthesizer#ADSR_envelope" target="_blank">ADSR</a> envelope type
which splits its ramp into four distinct phases: Attack, Decay, Sustain, Release.
<img src="https://upload.wikimedia.org/wikipedia/commons/e/ea/ADSR_parameter.svg">
2015-02-20 05:59:19 +00:00
</div>
2015-06-26 05:23:05 +00:00
<div id="Sliders"></div>
2015-02-12 03:39:28 +00:00
</div>
2014-08-26 03:47:07 +00:00
<script>
2015-02-12 03:39:28 +00:00
var env = new Tone.AmplitudeEnvelope({
2015-06-26 05:23:05 +00:00
"attack" : 0.11,
"decay" : 0.21,
2015-02-12 03:39:28 +00:00
"sustain" : 0.09,
"release" : 1.2
}).toMaster();
2014-08-26 03:47:07 +00:00
2015-06-26 05:23:05 +00:00
//create an oscillator and connect it to the envelope
var osc = new Tone.Oscillator({
"partials" : [3, 2, 1],
"type" : "custom",
2015-06-26 05:23:05 +00:00
"frequency" : "C#4",
"volume" : -8,
}).connect(env).start();
2014-08-28 04:39:17 +00:00
2017-03-26 20:39:19 +00:00
// GUI //
Interface.Slider({
param : "attack",
name : "attack",
parent : $("#Sliders"),
tone : env,
min : 0.005,
max : 1,
exp : 2,
});
2015-06-26 05:23:05 +00:00
2017-03-26 20:39:19 +00:00
Interface.Slider({
param : "decay",
name : "decay",
parent : $("#Sliders"),
tone : env,
min : 0.005,
max : 1,
exp : 2,
});
2015-06-26 05:23:05 +00:00
2017-03-26 20:39:19 +00:00
Interface.Slider({
param : "release",
name : "release",
parent : $("#Sliders"),
tone : env,
min : 0.2,
max : 2,
exp : 2,
});
2015-06-26 05:23:05 +00:00
2017-03-26 20:39:19 +00:00
Interface.Slider({
param : "sustain",
name : "sustain",
tone : env,
axis : "y",
min : 0.0,
max : 1,
exp : 2,
});
2015-06-26 05:23:05 +00:00
2017-03-26 20:39:19 +00:00
Interface.Button({
text : "Trigger Attack",
activeText : "Trigger Release",
key : 32, //spacebar
start : function(){
env.triggerAttack();
},
end : function(){
env.triggerRelease();
},
2014-08-28 04:39:17 +00:00
});
2014-03-15 03:17:18 +00:00
</script>
</body>
</html>