Tone.js/examples/oscillator.html

72 lines
1.6 KiB
HTML
Raw Normal View History

2024-05-15 19:24:20 +00:00
<!doctype html>
<html>
2024-05-15 19:24:20 +00:00
<head>
<meta charset="utf-8" />
<title>Oscillator</title>
2014-08-28 04:39:17 +00:00
2024-05-15 19:24:20 +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"
/>
2024-05-15 19:24:20 +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>
<script src="./js/tone-ui.js"></script>
<script src="./js/components.js"></script>
<style type="text/css">
tone-play-toggle {
margin-bottom: 10px;
}
</style>
</head>
<body>
<tone-example label="Oscillator">
<div slot="explanation">
The oscillator has 4 basic types which can be altered by setting
the number of partials and partials array.
<br /><br />
<a
href="https://tonejs.github.io/docs/latest/classes/Oscillator"
>Tone.Oscillator</a
>
docs.
</div>
2019-01-09 01:21:29 +00:00
2024-05-15 19:24:20 +00:00
<div id="content">
<tone-momentary-button></tone-momentary-button>
</div>
</tone-example>
2019-01-09 01:21:29 +00:00
2024-05-15 19:24:20 +00:00
<script type="text/javascript">
const osc = new Tone.Oscillator({
type: "square",
frequency: 440,
volume: -16,
}).toDestination();
2019-01-09 01:21:29 +00:00
2024-05-15 19:24:20 +00:00
ui({
tone: osc,
parent: document.querySelector("#content"),
});
2024-05-15 19:24:20 +00:00
// bind the interface
document
.querySelector("tone-momentary-button")
.addEventListener("down", () => osc.start());
document
.querySelector("tone-momentary-button")
.addEventListener("up", () => osc.stop());
</script>
</body>
</html>