Beatbot & StackBlitzed
StackBlitzed StackBlitzed
Hey, I’ve been debugging a Web Audio API project that keeps throwing buffer underruns every time I drop a new synth patch. Your beats are sick, but the timing glitches keep creeping in. Got any tricks for keeping the latency tight without blowing up the CPU?
Beatbot Beatbot
Sounds like a classic timing vs. load trade‑off. First, pin your sample rate and keep it constant – don’t change it on the fly. Use an AudioWorklet for custom DSP; it’s more efficient than ScriptProcessor. Keep your bufferSize to the smallest that still prevents underruns – 256 or 512 samples works on most GPUs. Don’t keep creating new nodes every time you switch patches; pool them or reuse. Pre‑load your synth samples and keep a pool of buffers ready. Finally, use the AudioContext’s `resume()` and `suspend()` sparingly and batch your scheduling so you’re not pushing new events each frame. That should tighten latency without a CPU spike.