Tone.js/examples/signal.html

106 lines
3.2 KiB
HTML
Raw Normal View History

2015-06-08 14:41:45 +00:00
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
2019-01-09 01:21:29 +00:00
<title>Signal</title>
2015-06-08 14:41:45 +00:00
2019-01-09 01:21:29 +00:00
<meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1">
<link rel="icon" type="image/png" sizes="174x174" href="./favicon.png">
2015-06-08 14:41:45 +00:00
2020-07-18 00:58:09 +00:00
<script src="https://cdnjs.cloudflare.com/ajax/libs/webcomponentsjs/2.4.3/webcomponents-bundle.js"></script>
<link href="https://fonts.googleapis.com/css?family=Material+Icons&display=block" rel="stylesheet"/>
<script src="../build/Tone.js"></script>
2020-07-18 00:58:09 +00:00
<script src="./js/tone-ui.js"></script>
<script src="./js/components.js"></script>
2019-01-09 01:21:29 +00:00
<style type="text/css">
tone-play-toggle {
margin-bottom: 10px;
}
tone-slider {
display: block;
width: 100%;
}
</style>
2015-06-08 14:41:45 +00:00
</head>
<body>
<tone-example label="Control Voltage">
<div slot="explanation">
2019-01-09 01:21:29 +00:00
One of the most powerful features of Tone.js and the Web Audio API is the ability to
2015-06-08 14:41:45 +00:00
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
2019-01-09 01:21:29 +00:00
<a href="https://tonejs.github.io/docs/Oscillator">Tone.Oscillators</a>
and a <a href="https://tonejs.github.io/docs/LFO">Tone.LFO</a>.
</div>
2015-06-26 05:23:05 +00:00
<div id="content">
2019-01-09 01:21:29 +00:00
<tone-play-toggle></tone-play-toggle>
<tone-slider label="Modulation Rate" min="0.1" max="1" exp="2" value="0.5"></tone-slider>
</div>
2019-01-09 01:21:29 +00:00
</tone-example>
<script type="text/javascript">//use this to pan the two oscillators hard left/right
var merge = new Tone.Merge().toDestination();
2015-06-26 05:23:05 +00:00
//two oscillators panned hard left / hard right
var rightOsc = new Tone.Oscillator({
"type" : "sawtooth",
"volume" : -20
}).connect(merge, 0, 0);
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, 0, 1);
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);
2019-01-09 01:21:29 +00:00
//start the oscillators with the play button
document.querySelector("tone-play-toggle").addEventListener("start", () => {
rightOsc.start();
leftOsc.start();
});
document.querySelector("tone-play-toggle").addEventListener("stop", () => {
rightOsc.stop();
leftOsc.stop();
2019-01-09 01:21:29 +00:00
});
2017-03-26 20:39:19 +00:00
2019-01-09 01:21:29 +00:00
//ramp the frequency with the slider
document.querySelector("tone-slider").addEventListener("input", e => {
frequency.rampTo(parseFloat(e.target.value), 0.1);
2015-06-26 05:23:05 +00:00
});
2019-01-09 01:21:29 +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>