From fd8719594125d4a06bda133c5fbc0352906520be Mon Sep 17 00:00:00 2001 From: reuk Date: Thu, 5 Aug 2021 19:05:25 +0100 Subject: [PATCH] iOS Audio: Allow specifying a fixed set of preferred sample rates By defining JUCE_IOS_AUDIO_EXPLICIT_SAMPLERATES, the iOS audio device will always use the requested samplerates instead of querying the current audio device for the samplerates it supports. This is useful because certain hardware (such as the Focusrite iTrack Dock) takes a long time to set new samplerates, which can end up freezing the main thread for significant lengths of time. This approach is inspired by the AUM app for iOS, which appears to provide a fixed list of "allowed" samplerates, rather than querying the device for its allowed samplerates. --- .../juce_audio_devices/native/juce_ios_Audio.cpp | 14 +++++++++++++- 1 file changed, 13 insertions(+), 1 deletion(-) diff --git a/modules/juce_audio_devices/native/juce_ios_Audio.cpp b/modules/juce_audio_devices/native/juce_ios_Audio.cpp index 08a10add7f..ab3224afdd 100644 --- a/modules/juce_audio_devices/native/juce_ios_Audio.cpp +++ b/modules/juce_audio_devices/native/juce_ios_Audio.cpp @@ -25,7 +25,13 @@ namespace juce class iOSAudioIODevice; -static const char* const iOSAudioDeviceName = "iOS Audio"; +constexpr const char* const iOSAudioDeviceName = "iOS Audio"; + +#ifndef JUCE_IOS_AUDIO_EXPLICIT_SAMPLERATES + #define JUCE_IOS_AUDIO_EXPLICIT_SAMPLERATES +#endif + +constexpr std::initializer_list iOSExplicitSampleRates { JUCE_IOS_AUDIO_EXPLICIT_SAMPLERATES }; //============================================================================== struct AudioSessionHolder @@ -356,6 +362,12 @@ struct iOSAudioIODevice::Pimpl : public AudioPlayHead, // depending on whether the headphones are plugged in or not! void updateAvailableSampleRates() { + if (iOSExplicitSampleRates.size() != 0) + { + availableSampleRates = Array (iOSExplicitSampleRates); + return; + } + availableSampleRates.clear(); AudioUnitRemovePropertyListenerWithUserData (audioUnit,