The Synth Sounded Fine When Nobody Was Listening
This is my entry for DEV's Summer Bug Smash — Smash Stories. There is a specific kind of bug that makes you doubt your own ears. I had a browser-based audio engine that played fine in export and sounded broken in real time. Hit play, and the output was thin, muffled, strangled — like someone had thrown a blanket over the speakers. Hit "render to file" on the exact same project data , and the…
In a case of a browser-based audio engine that sounded muffled in real-time, but perfect when rendered to file, the issue stemmed from a difference in the code paths. The live playback path ran on a scheduler, while the offline render path had no scheduler. The scheduler created and destroyed audio nodes at a rate of roughly 6,636 times per short run, which was the actual source of the issue.
The scheduler had a lookahead window of 0.28 seconds and a seek detector that triggered when the user dragged the playhead backwards. The seek detector compared the current transport position against the position it last saw and canceled every scheduled voice if there was a backward seek. The scheduler's lookahead window caused a backwards gap, which triggered the seek detector, leading to a continuous cycle of cancellation and recreation of audio nodes.
The fix involved increasing the backward-seek threshold to be larger than the lookahead window, preventing the scheduler's forward progress from being mistaken for a user seek. This bug highlights the importance of comparing different code paths and counting occurrences to identify the root cause.
Written by urgent.news from Dev.to's reporting — not their text. Machine-written — may contain errors; check the original before relying on it.