audio doesnt play on second loop of playing audio when used with soundtouch.js

when i increase the playbackrate of the audio using window.wavesurfer.playbackrate() function the rate changes but i dont want the pitch of audio to change along with it.
i have tried seen the topic "about variable audio rate" , and it helped alot . but i guess this topic didnt discussed on how to maintain the audio pitch when we play audio in loop.

  var wavesurfer2 = window.wavesurfer;
  wavesurfer2.on("ready", function () {
    console.log("audio wavesurfer ready");
    var st = new window.soundtouch.SoundTouch(
      wavesurfer2.backend.ac.sampleRate
    );
    var buffer = wavesurfer2.backend.buffer;
    var channels = buffer.numberOfChannels;
    var l = buffer.getChannelData(0);
    var r = channels > 1 ? buffer.getChannelData(1) : l;
    var length = buffer.length;
    var seekingPos = null;
    var seekingDiff = 0;

    var source = {
      extract: function (target, numFrames, position) {
        if (seekingPos != null) {
          seekingDiff = seekingPos - position;
          seekingPos = null;
        }

        position += seekingDiff;

        for (var i = 0; i < numFrames; i++) {
          target[i * 2] = l[i + position];
          target[i * 2 + 1] = r[i + position];
        }

        return Math.min(numFrames, length - position);
      },
    };

    var soundtouchNode;

    wavesurfer2.on("play", function () {
      seekingPos = ~~(wavesurfer2.backend.getPlayedPercents() * length);
      st.tempo = wavesurfer2.getPlaybackRate();
      if (st.tempo === 1) {
        wavesurfer2.backend.disconnectFilters();
      } else {
        if (!soundtouchNode) {
          var filter = new window.soundtouch.SimpleFilter(source, st);
          soundtouchNode = window.soundtouch.getWebAudioNode(
            wavesurfer2.backend.ac,
            filter
          );
        }
        wavesurfer2.backend.setFilter(soundtouchNode);
      }
    });
    wavesurfer2.on("pause", function () {
      soundtouchNode && soundtouchNode.disconnect();
    });

    wavesurfer2.on("seek", function () {
      seekingPos = ~~(wavesurfer2.backend.getPlayedPercents() * length);
    });
  });

this is the code i am using . here the pitch doesnt change when i change the audio playbackrate. but if i enable the loop option and play the audio doesnt play on second loop. any suggestion?

It seems that this topic is also something that is being discussed by the wavesurfer folks. It seems that it is an open issue too partially because different browser APIs handle this differently.

We'll keep an eye on the development of this Github issue and I'm also making a note to see if we can add playback speed buttons to our standard interface in Prodigy v2. No promises just yet, but it certainly seems like a fair feature to consider.

1 Like

One thing, did you notice the audio_rate setting mentioned here: