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

iOS Audio: Use hard-coded set of potential block sizes to avoid slow hardware queries

This commit is contained in:
reuk 2024-10-02 14:17:05 +01:00
parent 70c9c5bfdb
commit 7e73ed7c36
No known key found for this signature in database
GPG key ID: FCB43929F012EE5C

View file

@ -441,21 +441,29 @@ struct iOSAudioIODevice::Pimpl final : public AsyncUpdater
{ {
availableBufferSizes.clear(); availableBufferSizes.clear();
auto newBufferSize = tryBufferSize (sampleRate, 64); const auto [minBufSize, maxBufSize] = std::invoke ([this]
jassert (newBufferSize > 0);
const auto longestBufferSize = tryBufferSize (sampleRate, 4096);
while (newBufferSize <= longestBufferSize)
{ {
availableBufferSizes.add (newBufferSize); constexpr auto suggestedMin = 64;
newBufferSize *= 2; constexpr auto suggestedMax = 4096;
}
if (@available (ios 18, *))
return std::tuple (suggestedMin, suggestedMax);
const auto min = tryBufferSize (sampleRate, suggestedMin);
const auto max = tryBufferSize (sampleRate, suggestedMax);
bufferSize = tryBufferSize (sampleRate, bufferSize);
return std::tuple (min, max);
});
jassert (minBufSize > 0);
for (auto i = minBufSize; i <= maxBufSize; i *= 2)
availableBufferSizes.add (i);
// Sometimes the largest supported buffer size is not a power of 2 // Sometimes the largest supported buffer size is not a power of 2
availableBufferSizes.addIfNotAlreadyThere (longestBufferSize); availableBufferSizes.addIfNotAlreadyThere (maxBufSize);
bufferSize = tryBufferSize (sampleRate, bufferSize);
#if JUCE_IOS_AUDIO_LOGGING #if JUCE_IOS_AUDIO_LOGGING
{ {
@ -512,10 +520,6 @@ struct iOSAudioIODevice::Pimpl final : public AsyncUpdater
availableSampleRates.addIfNotAlreadyThere (highestRate); availableSampleRates.addIfNotAlreadyThere (highestRate);
// Restore the original values.
sampleRate = trySampleRate (sampleRate);
bufferSize = tryBufferSize (sampleRate, bufferSize);
AudioUnitAddPropertyListener (audioUnit, AudioUnitAddPropertyListener (audioUnit,
kAudioUnitProperty_StreamFormat, kAudioUnitProperty_StreamFormat,
dispatchAudioUnitPropertyChange, dispatchAudioUnitPropertyChange,
@ -1227,9 +1231,6 @@ struct iOSAudioIODevice::Pimpl final : public AsyncUpdater
{ {
const ScopedLock sl (callbackLock); const ScopedLock sl (callbackLock);
updateHardwareInfo();
setTargetSampleRateAndBufferSize();
if (isRunning) if (isRunning)
{ {
if (audioUnit != nullptr) if (audioUnit != nullptr)
@ -1241,6 +1242,13 @@ struct iOSAudioIODevice::Pimpl final : public AsyncUpdater
callback->audioDeviceStopped(); callback->audioDeviceStopped();
} }
}
updateHardwareInfo();
setTargetSampleRateAndBufferSize();
if (isRunning)
{
channelData.reconfigure (requestedInputChannels, requestedOutputChannels); channelData.reconfigure (requestedInputChannels, requestedOutputChannels);
createAudioUnit(); createAudioUnit();