Skip to content

Instantly share code, notes, and snippets.

@41y08h
Created January 26, 2023 07:18
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save 41y08h/668e65a153dd7168e1738c11e3efa3eb to your computer and use it in GitHub Desktop.
Save 41y08h/668e65a153dd7168e1738c11e3efa3eb to your computer and use it in GitHub Desktop.
working pitch shift
import "./styles.css";
import { useEffect, useState } from "react";
import * as Tone from "tone";
export default function App() {
const [filter, setFilter] = useState<Tone.PitchShift | undefined>(undefined);
const [pitch, setPitch] = useState(1);
async function init() {
const stream = await navigator.mediaDevices.getUserMedia({ audio: true });
const source = Tone.context.createMediaStreamSource(stream);
const filter = new Tone.PitchShift().toDestination();
setFilter(filter);
Tone.connect(source, filter);
}
useEffect(() => {
init();
}, []);
return (
<div className="App">
<input
type="range"
min={-10}
max={10}
value={pitch}
onChange={(event) => {
const pitch = parseInt(event.target.value, 10);
setPitch(pitch);
if (filter) {
filter.pitch = pitch;
}
}}
/>
<h1>Hello CodeSandbox {pitch}</h1>
<h2>Start editing to see some magic happen!</h2>
</div>
);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment