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

1 Like

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:

1 Like

Hi,

I was wondering, did you solve the problem?I think I have similar problem on Android. I have created a simple audio player application with a few basic effects like eq, reverb etc. and it calculates bpm while music is playing. The app works fine with built in speakers or wired headphones, but when a bluetooth headphone is connected, bpm calculation seems not working. But other effects work.
I don’t know the reason but I’ve experienced that bluetooth headphones may have different samplerate values, so this was the first potential problem that I could think about.

I’ve added required permissions in Android manifest file. By the way, in juce::RuntimePermissions class I colud not see any bluetooth permission ID except bluetoothMidi to request.

Maybe the problem is permissions or changing samplerate and blocksize, but I could not fix that.

I’ll be pleased if you have a suggestion or any idea.