Stories

The song my phone couldn't play

WeatherTunes · audio ·

WeatherTunes sounded fine on my laptop. On my phone it crackled and stuttered. Synthesizers in the browser have to make every sample just before it plays, and when the device falls behind, you hear it.

My first two fixes went after symptoms. Bigger audio buffers helped a little. Then I built a "32-bit mode" that plays the same song on simpler, console-style instruments, like an old game sound chip. It rendered 29 to 41% faster, and the phone still crackled. Profiling showed why: a song is hundreds of audio nodes, and just running that graph live was the cost, not any one instrument.

So nothing plays live anymore. The song renders offline as fast as the device allows, and the finished audio streams in blocks to a plain player. Play waits a moment until the render will stay ahead, so a slow phone waits a little longer instead of crackling. Muting a part mid-song renders the rest again and crossfades over.

It plays cleanly on my phone now. The fix wasn't a faster instrument; it was not running the instruments live at all. Try it on yours.