I want to sound an oscillator note for 2 seconds. But the next time, even after recreating a new oscillator, no sound is played:
oscillator = context.createOscillator();
oscillator.frequency.value = 440;
oscillator.type = oscillator.SINE;
oscillator.connect(context.destination);
oscillator.start(0);
oscillator.stop(2);
If I omit stop(2) and instead use setTimeout() to oscillator.stop() in a function, it works. I have read that the node should be disconnected, but disconnect() does not accept a time as argument, only an output index. Any pointer for the solution?