window.actx = new window.AudioContext()
await window.actx.audioWorklet.addModule('worklet/test-processor.js')
let oscillatorNode = window.actx.createOscillator()
oscillatorNode.start()
let gainNode = new GainNode(window.actx)
let lfoNode = new AudioWorkletNode(window.actx, 'test-processor')
lfoNode.connect(gainNode.gain) // here is the problem
oscillatorNode.connect(gainNode)
gainNode.connect(window.actx.destination)
class TestProcessor extends AudioWorkletProcessor {
process (inputs, outputs, parameters) {
const output = outputs[0]
output.forEach(channel => {
for (let i = 0; i < channel.length; i++) {
channel[i] = Math.random() * 2 - 1 // if change to 0.01, it doesn't work correctly either
}
})
return true
}
}
registerProcessor('test-processor', TestProcessor)