How can I stop/pause a WebAudio ScriptProcessor node?

1.2k views Asked by At

I can generate sounds using only createJavaScriptNode(...) on my HTML5 app. I need to generate white noise on the fly. The issue that I am having is that I can not stop/pause the generation for example setting null to the processor or the context.

I have seen this post: How can I stop a Web Audio Script Processor and clear the buffer? and I was wondering if there is a better solution than setting zero to a gain Node.

Do I have to worry about leaving the processor running if I don't need it? I wouldn't like to have "ghosts" in my code. It would be great if I can null the objects that I won't use anymore.

Thank you.

2

There are 2 answers

4
cwilso On

Actually, you should EXPLICITLY remove the onaudioprocess event handler from the object; otherwise it may not get garbage collected.

0
Boris Smus On

You should be using the ScriptProcessorNode, since JavaScriptAudioNode is deprecated. Disconnecting the node from the graph should cause onprocess to no longer be called back.