Indie dev efficiency3 min read

Web Audio loop still stops? Inspect the start duration argument

Render a constant signal offline to determine whether a finite start duration is ending a looping source.

Web Audio loop still stops? Inspect the start duration argument
A waveform inside a looping arrow ends at a vertical gate
Concept illustration

A source with loop=true can still finish at a fixed time when the code supplies the third argument to start(when, offset, duration). The limit applies to accumulated buffer content, including loop iterations.

Locate the endpoint with a constant fixture

  1. Make a mono 48 kHz buffer lasting 0.1 seconds and fill it with 0.25. Route it into a one-second OfflineAudioContext. Enable looping and set playbackRate to one. Create a fresh source and context for each comparison.
  2. Start one with start(0, 0, 0.25) and the other with start(0). Inspect the rendered samples. The finite version should stop around 0.25 seconds. The second should remain nonzero through the render window; the end of that window is separate from the source choosing to end.
  3. Keep duration at 0.25 in a third graph and set playbackRate to 0.5. With a constant rate and no detune automation, expect roughly half a second of output. Duration counts buffer-content seconds, so it does not specify the same wall-clock interval at every playback speed.

Trace playback control in the game

If the first comparison fails, look for an earlier stop call or a gain value becoming zero. When you restore the real ambience, log source creation, start arguments and the ended event. Check that each play gets a fresh source. Compare delivery sizes with Resource Compressor, and verify loop termination in the actual audio graph.

Ready to try "Web Audio loop still stops? Inspect the start duration argument"?

Use our online tools to apply this tutorial to your indie game project right away.