Tone.js/examples/bembe.html

117 lines
2.6 KiB
HTML
Raw Normal View History

2024-05-15 19:24:20 +00:00
<!doctype html>
2016-01-30 21:13:44 +00:00
<html>
2024-05-15 19:24:20 +00:00
<head>
<meta charset="utf-8" />
<title>MetalSynth</title>
2016-01-30 21:13:44 +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"
/>
2016-01-30 21:13:44 +00:00
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>
</head>
<body>
<tone-example label="Bembe">
<div slot="explanation">
<a
href="https://tonejs.github.io/docs/latest/classes/MetalSynth"
>Tone.MetalSynth</a
>
creates metallic, inharmonic sounds using 6
<a
href="https://tonejs.github.io/docs/latest/classes/FMOscillator"
>Tone.FMOscillators</a
>
with a tuning based on the TR-808 Cymbal.
<a
href="https://tonejs.github.io/docs/latest/classes/MembraneSynth"
>Tone.MembraneSynth</a
>
makes kick and tom-like sounds using a frequency envelope which
is triggered on notes attack.
</div>
2016-01-30 21:13:44 +00:00
2024-05-15 19:24:20 +00:00
<div id="content">
<tone-play-toggle></tone-play-toggle>
</div>
</tone-example>
2016-01-30 21:13:44 +00:00
2024-05-15 19:24:20 +00:00
<script type="text/javascript">
const bell = new Tone.MetalSynth({
harmonicity: 12,
resonance: 800,
modulationIndex: 20,
envelope: {
decay: 0.4,
},
volume: -15,
}).toDestination();
2019-01-09 01:21:29 +00:00
2024-05-15 19:24:20 +00:00
const bellPart = new Tone.Sequence(
(time, freq) => {
bell.triggerAttack(freq, time, Math.random() * 0.5 + 0.5);
},
[
[300, null, 200],
[null, 200, 200],
[null, 200, null],
[200, null, 200],
],
"4n"
).start(0);
2016-01-30 21:13:44 +00:00
2024-05-15 19:24:20 +00:00
const conga = new Tone.MembraneSynth({
pitchDecay: 0.008,
octaves: 2,
envelope: {
attack: 0.0006,
decay: 0.5,
sustain: 0,
},
}).toDestination();
2016-01-30 21:13:44 +00:00
2024-05-15 19:24:20 +00:00
const congaPart = new Tone.Sequence(
(time, pitch) => {
conga.triggerAttack(pitch, time, Math.random() * 0.5 + 0.5);
},
["G3", "C4", "C4", "C4"],
"4n"
).start(0);
2016-01-30 21:13:44 +00:00
2024-05-15 19:24:20 +00:00
Tone.Transport.bpm.value = 115;
2016-01-30 21:13:44 +00:00
2024-05-15 19:24:20 +00:00
drawer()
.add({
tone: conga,
title: "Conga",
})
.add({
tone: bell,
title: "Bell",
});
2016-01-30 21:13:44 +00:00
2024-05-15 19:24:20 +00:00
// connect the UI with the components
document
.querySelector("tone-play-toggle")
.addEventListener("start", () => Tone.Transport.start());
document
.querySelector("tone-play-toggle")
.addEventListener("stop", () => Tone.Transport.stop());
</script>
</body>
</html>