0

OfflineContext.suspend stops the progression of OfflineContext.currentTime, but what effect does it have while rendering (OfflineContext.startRendering)? What I want to do is start the rendering process, pause it, do some other task and resume it when the other task is done. While the rendering process is paused, the imminent AudioBuffer should not be getting larger, meaning that when I export the AudioBuffer into a wav file and play it, there should be no silence corresponding to the pause that was taken by the rendering process.

I have tried OfflineContext.suspend while rendering and it does seem to add some silence in the resulting wav file, but perhaps I'm doing something wrong.

  1. How can I pause the rendering process?
  2. What is OfflineContext.suspend for?
Maxime Dupré
  • 5,319
  • 7
  • 38
  • 72

1 Answers1

0

suspend is intended to cause the offline context to stop at controlled times, before startRendering() is called. You can call suspend() after starting rendering, but this is not very precise, especially since rendering is probably faster than real time.

Plus you have not access to the AudioBuffer during rendering. If you want to capture the audio while rendering, use a ScriptProcessorNode or an AudioWorkletNode to save the audio data.

Raymond Toy
  • 5,490
  • 10
  • 13
  • So does `suspend ` allow me to start rendering, pause the rendering, do some task and resume rendering without adding silence in the audio? If yes, then I probably have silence in my audio because I call `suspend` after starting rendering. The couple milliseconds that it takes for the execution of the code to reach `suspend` after calling `startRendering` are enough to insert 1 minute of silence. – Maxime Dupré Feb 13 '17 at 20:29
  • 1
    Yes. You should call `suspend` and `resume` to do whatever you need to do and then call `startRendering`. What happens is that while rendering, the context will stop at the requested times, run the code, and resume (if requested), all synchronously. The only thing to be careful about is that the suspend times are quantized to the preceeding (?) 128-frame boundary. – Raymond Toy Feb 13 '17 at 22:16