The read-only currentFrame property of the AudioWorkletGlobalScope interface returns an integer that represents the ever-increasing current sample-frame of the audio block being processed. It is incremented by 128 (the size of a render quantum) after the processing of each audio block.
The AudioWorkletProcessor has access to the specific AudioWorkletGlobalScope properties:
class TestProcessor extends AudioWorkletProcessor {
constructor() {
super();
console.log(currentFrame);
console.log(currentTime);
}
process(inputs, outputs, parameters) {
return true;
}
}
console.log(sampleRate);
const usefulVariable = 42;
console.log(usefulVariable);
registerProcessor("test-processor", TestProcessor);
The main script loads the processor, creates an instance of AudioWorkletNode, passes the name of the processor to it, and connects the node to an audio graph. We should see the output of console.log() calls in the console:
const audioContext = new AudioContext();
await audioContext.audioWorklet.addModule("test-processor.js");
const testNode = new AudioWorkletNode(audioContext, "test-processor");
testNode.connect(audioContext.destination);