Tone.js/examples/pitchShift.html

91 lines
2.1 KiB
HTML
Raw Normal View History

2024-05-15 19:24:20 +00:00
<!doctype html>
2019-10-28 12:05:02 +00:00
<html>
2024-05-15 19:24:20 +00:00
<head>
<meta charset="utf-8" />
<title>Pitch Shift</title>
2019-10-28 12:05:02 +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"
/>
2019-10-28 12:05:02 +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>
<style>
tone-slider {
width: 100%;
margin-top: 10px;
}
</style>
<tone-example label="Pitch Shift">
<div slot="explanation">
This example demonstrates the Pitch Shift effect.
<br /><br />
<a
href="https://tonejs.github.io/docs/latest/classes/PitchShift"
>Tone.Pitch Shift</a
>
docs.
</div>
2019-10-28 12:05:02 +00:00
2024-05-15 19:24:20 +00:00
<tone-loader></tone-loader>
<div id="content">
<tone-play-toggle></tone-play-toggle>
<tone-slider
label="pitch"
min="-12"
max="12"
value="0"
units="hz"
></tone-slider>
</div>
</tone-example>
2019-10-28 12:05:02 +00:00
2024-05-15 19:24:20 +00:00
<script type="text/javascript">
const pitchShift = new Tone.PitchShift().toDestination();
const player = new Tone.Player(
"https://tonejs.github.io/audio/berklee/groovin_analogsynth1.mp3"
).connect(pitchShift);
player.loop = true;
2019-10-28 12:05:02 +00:00
2024-05-15 19:24:20 +00:00
const toneFFT = new Tone.FFT();
pitchShift.connect(toneFFT);
fft({
parent: document.querySelector("#content"),
tone: toneFFT,
});
2019-10-28 12:05:02 +00:00
2024-05-15 19:24:20 +00:00
// bind the interface
document
.querySelector("tone-play-toggle")
.addEventListener("start", () => player.start());
document
.querySelector("tone-play-toggle")
.addEventListener("stop", () => player.stop());
// document.querySelector("tone-play-toggle").addEventListener('start', () => {
// debugger;
// });
document
.querySelector("tone-slider")
.addEventListener("input", (e) => {
pitchShift.pitch = parseFloat(e.target.value);
});
</script>
</body>
2019-10-28 12:05:02 +00:00
</html>