Bluetooth Latency Issues

About a week ago I was horrified to find a one star review on Google Play:

Audio is out of sync. Sputter is a good name for it.

At first I thought it was something wrong with the app, but then it struck me: The user is probably using bluetooth headphones, and there has not been made any effort in the app to compensate for the latency introduced by these.

So, I tried it out on a bluetooth speaker, and sure enough, the latency is not only noticeable but quite annoying:

For comparison, here is the same song playing from the phone speakers:

To be honest, Sputter has a naive approach when it comes to timing audio with what happens on the screen and assumes almost zero audio latency. When a “burst” of audio is generated and sent to the audio hardware it is considered playing immediately, which of course is not always the case, due to latency introduced in various steps on the way to our ears. On most phones this has worked well enough, since Sputter is not a live instrument and audio and screen just needs to be roughly in sync, but with bluetooth headphones it is a whole different story.

Luckily, I found an interesting article covering this topic. Hopefully the solutions discussed there will work. I will be working on this going forward, and hopefully there will be a solution within a few weeks.