cutterbl / soundtouchjs-audio-worklet

AudioWorkletNode and AudioWorkletProcessor implementing SoundTouchJS
GNU Lesser General Public License v2.1
70 stars 10 forks source link

Is it possible to have the bufferNode.start() work with the soundtouch-worklet, as in, have the worklet start with the scheduler that bufferNode has? #8

Closed 432player closed 3 years ago

432player commented 3 years ago

I would like to sync streaming buffers and play them through soundtouch-audio-nodes/soundtouch-worklets but there's no option to use start() function. I cant use setTimeouts because it's extremely not accurate.

Any chance you can lead me in the right direction? What makes the worklet start processing and playing music if there's no start anywhere?

currentSoundtouch = createSoundTouchNode(currentAudioCtx, AudioWorkletNode, buffer); currentSoundtouch.on('initialized', onInitialized);

//in the onInitialized function Test 1 if (currentSoundtouch.ready) { bufferNode = currentSoundtouch.connectToBuffer(); // AudioBuffer goes to SoundTouchNode gainNode = currentAudioCtx.createGain(); gainNode.connect(currentAudioCtx.destination); currentSoundtouch.connect(gainNode); }

If I do this code the soundtouch-node just starts playing with no option for a delay. But in the following code

//in the onInitialized function Test 2 if (currentSoundtouch.ready) { bufferNode = currentSoundtouch.connectToBuffer(); // AudioBuffer goes to SoundTouchNode gainNode = currentAudioCtx.createGain(); gainNode.connect(currentAudioCtx.destination); bufferNode.connect(gainNode); bufferNode.start(); }

this works with the start but doesn't go through the soundtouch-worklet and there's no pitchshifting

Any help would be most appreciated

cutterbl commented 3 years ago

Unfortunately, that isn't possible at this time, because of "how" SoundTouchJS reads the AudioBuffer and not the actual InputStream. I explain this a little better in a blog post. It's something I would love to fix, but just haven't had the time to do so.