Bluetooth stuttering with Android

Hi there,

I’m creating an audio app on Android, everything works fine when listening on my phone speakers but when i connect my device to bluetooth speakers, the sound stutters. I still here good audio quality but it seems like things are not “synchronised” anymore.

Is anyone experiencing the same issue ?

It seems that my bufferToFill.numSamples in my getNextAudioBlock method goes crazy when my phone is connected to a bluetooth speaker or headphones…

When not connected to my bluetooth speaker, i have a stable numSamples value of 240 samples, but as soon as i connect to my bluetooth speaker this number goes crazy changing value randomly at each getNextAudioBlock call…

You mean a sample buffer size of 240? That’s a pretty odd number, usually it’s 2^n (32, 64, 128, 256…). How are you setting up your audio device manager in the first instance?

If you give a bit of code people may help you better, otherwise we just can make wild guesses.

Thank you for replying.

Actually if you look at this article, 240 is pretty usual for an Android smartphone : https://medium.com/@juliozynger/your-app-and-low-latency-audio-output-d21d7b672305

Or if you look at Android developer website in the audio latency chapter :
" Typical buffer sizes include 96, 128, 160, 192, 240, 256, or 512 frames, but other values are possible."

I don’t think that putting my code here can be relevant as it seems to be a problem with JUCE Android code. Indeed I don’t have any problem with bluetooth on my desktop app (i have a stable 512 buffer size, bluetooth or not).

At each getNextAudioBlock call i increment a counter with my bufferToFill.numSamples in order to make a step sequencer like in this tutorial : https://youtu.be/M9NhoEs3Jzg
If this value doesn’t change my steps remain equal so everything works fine, but when connected to bluetooth this value goes crazy and my steps are not equals anymore.

Just wanted to know if someone experienced the same issue with Android. I will test on iOS today.

Thank you

It is totally in the realm of possibilities that you get different buffer sizes in your getNextAudioBlock, but the max size will be the one you get in prepareToPlay. ie. your code needs to be able to handle that, because that is how it works. :slight_smile: