Search code examples
web-audio-apiaudio-processingaudiocontext

How to pause offline rendering?


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?

Solution

  • 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.