cutterbl/SoundTouchJS

Audio stuttering / glitching, especially on mobile and some lower performance browser contexts

cdcv opened this issue · 1 comments

cdcv commented

I have got soundtouch working and the audio quality for time shifting is great! Thanks for creating this.

However, it isn't currently working reliably across browser contexts.

Is there a way to get it to work reliably across browsers without audio glitches, including on mobile browsers and on iOS?

One potential solution: can PitchShifter run asynchronously on an audioBuffer to produce a time shifted or pitch shifted audioBuffer, which can then be played in realtime without audio glitches? Not sure if this is a viable solution.

I gather that no one has yet created a worklet version of soundtouch?

Unfortunately, when I've tried to using soundtouch beyond initial testing on a desktop browser, I'm running into a lot of audio glitches / problems during realtime audio. On iOS Safari and Chrome for instance the realtime audio that is produced has many glitches and can 'stutter', or 'loop'. For example, the audio may play fine (and well time shifted) for some seconds, and then start looping a small section of the audio, maybe a few hundred milliseconds. This seems to happen towards or at the end of an audioBuffer that is tens of seconds long. I initially thought this might be an iOS specific issue. However, I've now tried running the same code on a Mac Chrome browser on an old/slow desktop machine and got similar problems.

Here's some example code:

  this.source = audioContext.createBufferSource();
  this.source.buffer = this.audioBuffer;

  const shifter = new PitchShifter(audioContext, this.audioBuffer, 4096);
  shifter.tempo = playbackRate;
  shifter.connect(audioContext.destination);

// shifter.connect(gainNode);
// gainNode.connect(audioContext.destination);

  this.startTime = audioContext.currentTime;
  this.source.start(this.startTime, offset / playbackRate);

if it were possible to add an async step after createBufferSource() that would time shift the audio, and then play it later, this would be one possible solution.

Thank you for your help.

So, this version of SoundTouchJS was taking multiple dead projects (credited in the README), and modernizing the code for packaging in npm. While I have tooled around with some of it, I do not profess to understanding all of the logic around the PitchShifting (if I did, I would have attempted to make a true AudioNode out of all of this).

If I had to guess, I'm betting that it's reaching the end of the process array, and there aren't enough 'slots' to process properly.