Created
January 26, 2023 07:17
-
-
Save 41y08h/fb51c77067a784589a7ec7875e6ffc45 to your computer and use it in GitHub Desktop.
pitch shift from audio
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import "./styles.css"; | |
import { useEffect, useRef, 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); | |
const audioRef = useRef<any>(); | |
async function init() { | |
const player = new Tone.Player("./elle-raw.mp3").toDestination(); | |
Tone.loaded().then(() => { | |
alert("loaded") | |
const filter = new Tone.PitchShift().toDestination(); | |
setFilter(filter); | |
player.connect(filter); | |
player.start() | |
}); | |
} | |
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> | |
<audio onCanPlay={() => init()} ref={audioRef} controls src="https://github.com/41y08h/GHaaS/blob/main/elle-raw.mp3?raw=true" /> | |
<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