Value for player.firstBeatMs gets reset after after calling player.openMemory
jhrtn opened this issue · 1 comments
jhrtn commented
After creating a player inside onReady() I set the value for player.firstBeatMs. I then download and decode an audio file and inside the SuperpoweredLoaded message log the value for player.firstBeatMs before and after calling player.openMemory(). The value for firstBeatMs gets reset back to 0 after calling openMemory. Is this expected behaviour? Other parameters do not get reset. Do we just need to set firstBeatMs in the SuperpoweredLoaded message after calling openMemory?
import { SuperpoweredWebAudio, SuperpoweredTrackLoader } from '/superpowered/SuperpoweredWebAudio.js';
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);
this.player.syncMode = this.Superpowered.AdvancedAudioPlayer.SyncMode_TempoAndBeat;
this.player.firstBeatMs = 1000.24;
this.bufferCount = 0;
console.log(this.player.firstBeatMs) // logs 1000.24
SuperpoweredTrackLoader.downloadAndDecode('example_track.mp3', this);
}
onMessageFromMainScope(message) {
if (message.SuperpoweredLoaded) {
const { buffer, url } = message.SuperpoweredLoaded;
console.log(this.player.firstBeatMs) // logs 1000.24
this.player.openMemory(this.Superpowered.arrayBufferToWASM(buffer), false, false);
console.log(this.player.firstBeatMs) // logs 0
this.player.play();
this.sendMessageToMainScope({ loaded: true });
}
}
processAudio(inputBuffer, outputBuffer, buffersize, parameters) {
if (this.bufferCount % 5000 === 0) console.log(this.player.firstBeatMs) // logs 0
if (!this.player.processStereo(outputBuffer.pointer, false, buffersize, 1)) {
for (let n = 0; n < buffersize * 2; n++) outputBuffer.array[n] = 0;
};
this.bufferCount++;
}
}
if (typeof AudioWorkletProcessor === 'function') registerProcessor('MyProcessor', MyProcessor);
export default MyProcessor;gaborszanto commented
Yes, changing firstBeatMs is the expected behaviour, since using openMemory you load new content. Just set it after calling openMemory.