sean1081
sean1081

Reputation: 1

Superpowered loop or loopBetween not working as expected

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);

        }
    }
}

Upvotes: 0

Views: 82

Answers (0)

Related Questions