0

I've modified the JS timestretch example to loop, but am not getting any audio out with loop() or loopBetween(). player.play() plays the whole file. I can force it by polling getPositionMs and setPosition in the process loop, but that's a hack. What should I be doing? Thanks.

class MyProcessor extends SuperpoweredWebAudio.AudioWorkletProcessor {
    // runs after the constructor
    onReady() {
        this.player = new this.Superpowered.AdvancedAudioPlayer(this.samplerate, 2, 2, 0, 0.501, 2, false);
        SuperpoweredTrackLoader.downloadAndDecode('../123456.mp3', this);
    }

    onMessageFromMainScope(message) {
        if (message.SuperpoweredLoaded) {
            this.player.openMemory(this.Superpowered.arrayBufferToWASM(message.SuperpoweredLoaded.buffer), false, false);
            this.player.loopBetween (   
                1000.0, //double    startMs,
                3000.0, // double   endMs,
                true, // bool   jumpToStartMs,
                255, //unsigned char    pointID,
                false); //bool  synchronisedStart

            this.player.play();
            this.sendMessageToMainScope({ loaded: true });
        }

        if (typeof message.rate !== 'undefined') this.player.playbackRate = message.rate / 10000.0;
        if (typeof message.pitchShift !== 'undefined') this.player.pitchShiftCents = parseInt(message.pitchShift) * 100;
    }

    processAudio(inputBuffer, outputBuffer, buffersize, parameters) {
        if (!this.player.processStereo(outputBuffer.pointer, false, buffersize, 1)) {
            for (let n = 0; n < buffersize * 2; n++) outputBuffer.array[n] = 0;
        };
        if (this.player.getPositionMs() > 3000) {
            this.player.setPosition(1000.0, false, false);

        }
    }
}
Progman
  • 16,827
  • 6
  • 33
  • 48
  • How about the 4th argument of `loopBetween`? `255` indicates that the OP does not care about a *Position identifier*. It also is documented that *`player.play(); // Starts playback immediately without any synchronization`*. – Peter Seliger Nov 11 '21 at 13:45
  • @PeterSeliger Thanks, but the code parameters i've used work in the c++ crossfader example on ios. The pointID seems to be for zero latency seeking on subsequent calls. For now, I'm not trying to synchronize multiple players. FWIW, getDurationMs isn't working either. Not quite a pain-free audio experience :) – sean1081 Nov 11 '21 at 22:44

0 Answers0