Tonejs / Tone.js

A Web Audio framework for making interactive music in the browser.
https://tonejs.github.io
MIT License
13.24k stars 963 forks source link

How can I use a Rubberband node? #1227

Closed benlieb closed 2 months ago

benlieb commented 4 months ago

I'm trying to get rubberband pitch shift node working with my Tone.js audio player. Can't seem to get it to work.

Trying something like this:

      const pitchShiftNode = await createRubberBandNode(
        player.context.rawContext._nativeAudioContext,
        '/audio/music/rubberband-processor.js'
      );

Does anyone have a working example of how to use Rubberband with Tone?

marcelblum commented 4 months ago

Assume you're talking about use with rubberband-web. I've experimented with it a bit but ultimately decided against using it because latency and cpu use were too high and Rubber Band licensing is not cheap. (Not a knock against Rubber Band itself, sound quality is wonderful and I would have gladly paid up if the other problems weren't there, but using it under the limitations of Wasm and web audio presented too many performance issues to make it worthwhile for me - currently using phaze instead as a good enough/faster/free alternative.)

Anyway for interoperability with Tone you just need to hack the native node returned by createRubberBandNode() into a ToneAudioNode. Something like this should work (untested code sorry, going from memory):


const newToneNode = new Tone.ToneAudioNode();
newToneNode.pitchShiftNode = await createRubberBandNode(nativeContext, 'rubberband-processor.js');
newToneNode.input = new Tone.Gain();
newToneNode.output= new Tone.Gain();
newToneNode.input.chain(newToneNode.pitchShiftNode, newToneNode.output);