1
0
Fork 0
mirror of https://github.com/juce-framework/JUCE.git synced 2026-01-10 23:44:24 +00:00

iOS Audio: Request exactly the desired buffersize, to avoid an issue where iOS 18 fails to apply non-power-of-2 sizes

This commit is contained in:
reuk 2024-09-18 14:56:18 +01:00
parent 171edbec7f
commit d3e254e24f
No known key found for this signature in database
GPG key ID: FCB43929F012EE5C

View file

@ -320,7 +320,18 @@ struct iOSAudioIODevice::Pimpl final : public AsyncUpdater
int tryBufferSize (const double currentSampleRate, const int newBufferSize)
{
NSTimeInterval bufferDuration = currentSampleRate > 0 ? (NSTimeInterval) ((newBufferSize + 1) / currentSampleRate) : 0.0;
const auto extraOffset = std::invoke ([&]
{
// Older iOS versions (iOS 12) seem to require that the requested buffer size is a bit
// larger than the desired buffer size.
// This breaks on iOS 18, which needs the buffer duration to be as precise as possible.
if (@available (ios 18, *))
return 0;
return 1;
});
NSTimeInterval bufferDuration = currentSampleRate > 0 ? (NSTimeInterval) (newBufferSize + extraOffset) / currentSampleRate : 0.0;
auto session = [AVAudioSession sharedInstance];
JUCE_NSERROR_CHECK ([session setPreferredIOBufferDuration: bufferDuration