soundtouchjs-audio-worklet
soundtouchjs-audio-worklet copied to clipboard
Standalone AudioWorkletProcessor
Hello, using this I found it annoying how its a "psuedo-node" with it's own time scheduling, it can't be connected as part of a chain of AudioNodes. So I worked on refactoring the code into a standalone AudioWorkletProcessor.
Here is the file: https://gist.github.com/Moebits/fc9ab7b56721e7e37d97417ed60cc2f9
Although I exposed all of "rate", "tempo", and "pitch" as parameters, only pitch will work; rate and tempo would need the buffer of the entire file.
Below is an example of using the worklet, with Tone.js library:
const context = Tone.getContext()
await context.addAudioWorkletModule(soundtouchURL, "soundtouch")
let soundtouchNode = context.createAudioWorkletNode("soundtouch-processor")
soundtouchNode.parameters.get("pitch").value = functions.semitonesToScale(state.pitch)
let gainNode = new Tone.Gain(1)
let audioNode = new Tone.ToneAudioNode()
audioNode.input = player
audioNode.output = gainNode.input
audioNode.input.chain(soundtouchNode, audioNode.output)
audioNode.toDestination()