-
Notifications
You must be signed in to change notification settings - Fork 1.8k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
[Bug]: Audio breaks up when using Bluetooth speaker on iOS #1456
Comments
I'd be interested to see the stack trace that leads to I've tested this a bit, both on the develop branch, and on the 8.0.3 release. I'm using a 9th gen iPad running iOS 17.7. So far, I haven't been able reproduce the behaviour you describe when connecting and disconnecting a bluetooth headset while audio is playing via the AudioPlaybackDemo in the DemoRunner. Another issue in this area was reported after the 8.0.3 release here. My potential fix for that issue is to add the following at line 523 in juce_Audio_ios.cpp, in
The idea is to set the stored sampleRate and bufferSize back to whatever values they held before querying the available sample rates. This looks similar to the solution you're suggesting, but in a different location. Please could you try making the change I outlined above and see whether it solves the problem for you? |
Sure, I can try your solution tomorrow and set a breakpoint to capture the stack trace. |
When I connect to Bluetooth (cheap AirPods imitation) while the app is running, the JUCE_IOS_AUDIO_LOGGING stuff prints the following:
Note that here the sample rate is fine but there is a mismatch between the buffer sizes. This causes the sound to break up. The stack trace for By the way, if I turn off the Bluetooth headset while the app is still running, the logging shows:
Note how it suddenly attempts to set the target sample rate to 8000 and chooses the closest, which is 22050, even though this device handles 44100 just fine. The stacktrace for that is the same as above. If I now connect the Bluetooth headset again, it might ask for 8000 Hz or for 44100 Hz. It all seems a bit arbitrary. I'm sure that's due to these headphones being a bit janky. ;-) |
If I connect to Bluetooth before starting the app, the logging shows:
Here the sample rate is the issue while the buffer size is OK. Note that it's weird that now it suddenly does support a 256 buffer while previously it only supported 1024. The stack trace is: The App/Window/PluginHolder are essentially copies of the JUCE standalone stuff and it goes wrong with the default standalone as well. |
Unfortunately your suggestion does not work in this case. |
I've spent a bit more time investigating this issue, but haven't made much progress so far.
I'm not convinced that a buffer-size mismatch here would cause garbled audio. The The "Internal buffer size" value appears to be an upper limit on the size of any given buffer. If I stick a DBG in the actual process callback, the
The target sample rate is only set when opening the device. It looks like the AudioDeviceManager will query the device for available sample rates, and then pick the best one of those rates before opening the device. From the output you posted, it looks like your device initially only reports a supported rate of 8kHz, so this is the value that ends up being set as the target sample rate. The fix I mentioned earlier is now on the develop branch. I know you said that it didn't help for you, but maybe it's worth checking out the version on the develop branch just in case it differs in any way from the version you tested. Other than that, I'm starting to run out of ideas. The Apple docs suggest that it's best to call |
Hi, just wanted to check whether you'd had a chance to test the latest changes on the develop branch. |
Sorry, I have not had time to test this yet. |
@reuk I only just had time to test with the current develop branch and I can't make the problem occur on iOS 17 anymore. So it seems to have been fixed for iOS 17. I don't have any devices that run iOS 18 and am not able to test on an iOS 18 simulator right now, so I'm going to close this issue for now. Thanks! |
Detailed steps on how to reproduce the bug
I have an AUv3 that's wrapped inside a standalone app running on iPad. When the app is active and I switch to a Bluetooth speaker, the sound becomes all garbled. This also happens if Bluetooth is active before starting the app. Without Bluetooth, it sounds fine. Other audio apps (not written with JUCE) work fine over Bluetooth. The audio processing code in my AUv3 can handle different sample rates and buffer sizes without problems.
I have traced it to the following: When Bluetooth is active, iOS for some reason first attempts to set the sample rate to 8000 Hz (and use a mono bus). With
JUCE_IOS_AUDIO_LOGGING
enabled, it prints the following:It's possible to reproduce this behavior even without Bluetooth. In
juce_Audio_ios.cpp
, inopen()
, change the linetargetSampleRate = sampleRateWanted;
totargetSampleRate = 8000.0;
.After some debugging, I was able to fix the issue by doing the following in
juce_Audio_ios.cpp
insetTargetSampleRateAndBufferSize()
:trySampleRate
sets thepreferredSampleRate
on theAVAudioSession
, even if the audio hardware cannot handle that sample rate. My hypothesis is that at some point iOS may still attempt to use this preferred rate, while JUCE is using a different sample rate. My fix/workaround changes thepreferredSampleRate
to something that is actually supported. Same thing for the buffer size.What is the expected behaviour?
The audio plays over the Bluetooth speaker.
Operating systems
iOS
What versions of the operating systems?
Tried on iPadOS 17.6.1 on iPad Pro (10.5-inch). Several beta testers have mentioned this Bluetooth problem on their devices as well. JUCE 8.0.3.
Architectures
ARM, 64-bit
Stacktrace
Plug-in formats (if applicable)
AUv3
Plug-in host applications (DAWs) (if applicable)
Standalone app
Testing on the
develop
branchI have not tested against the
develop
branchCode of Conduct
The text was updated successfully, but these errors were encountered: