1

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.

Community
  • 1
  • 1
the_moon
  • 553
  • 1
  • 7
  • 21

2 Answers2

1

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.

Boris Smus
  • 8,220
  • 2
  • 36
  • 33
0

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

cwilso
  • 13,610
  • 1
  • 30
  • 35
  • Yes, that should do it. – cwilso Jun 11 '14 at 18:24
  • It doesn't. It only generates a different sound; almost the same that I had but in a lower frequency... The guy from the question I mentioned above had the same troubles trying to set that to null. – the_moon Jun 11 '14 at 18:37
  • oh. you have to disconnect it too; otherwise it's continuing to use the same old buffer, just not firing the event. – cwilso Jun 14 '14 at 17:21
  • 1
    BTW, it's a lot cheaper computationally and nearly as mathematically valid to just fill a short (e.g. 2-second) AudioBuffer with noise and loop it as a BufferSourceNode to generate white noise. – cwilso Jun 14 '14 at 17:23