From 55fb6dbe621a1855f2b4900c357c9fb99f98afed Mon Sep 17 00:00:00 2001 From: reuk Date: Mon, 18 Nov 2024 21:54:08 +0000 Subject: [PATCH] iOS Audio: Ensure current sampleRate and bufferSize are always updated after querying sample rates The code added in 6f20de54349470aff16453052a82aa7e8e0aea26 was only executed when no explicit sample rates were set. Now, the sample rate is always updated after querying available sample rates and before querying available buffer sizes, so that the buffer size check is guaranteed to use an up-to-date samplerate value. --- modules/juce_audio_devices/native/juce_Audio_ios.cpp | 11 +++++++---- 1 file changed, 7 insertions(+), 4 deletions(-) diff --git a/modules/juce_audio_devices/native/juce_Audio_ios.cpp b/modules/juce_audio_devices/native/juce_Audio_ios.cpp index 709777cec0..e7b1c5fbe1 100644 --- a/modules/juce_audio_devices/native/juce_Audio_ios.cpp +++ b/modules/juce_audio_devices/native/juce_Audio_ios.cpp @@ -518,10 +518,6 @@ struct iOSAudioIODevice::Pimpl final : public AsyncUpdater availableSampleRates.addIfNotAlreadyThere (highestRate); - // Reset sample rate back to the original, so that we don't end up stuck on the highest rate - sampleRate = trySampleRate (sampleRate); - bufferSize = getBufferSize (sampleRate); - AudioUnitAddPropertyListener (audioUnit, kAudioUnitProperty_StreamFormat, dispatchAudioUnitPropertyChange, @@ -553,6 +549,13 @@ struct iOSAudioIODevice::Pimpl final : public AsyncUpdater JUCE_IOS_AUDIO_LOG ("Updating hardware info"); updateAvailableSampleRates(); + + // The sample rate and buffer size may have been affected by + // updateAvailableSampleRates(), so try restoring the last good + // sample rate + sampleRate = trySampleRate (sampleRate); + bufferSize = getBufferSize (sampleRate); + updateAvailableBufferSizes(); if (deviceType != nullptr)