In our iOS app, if I open a different app that sets the samplerate to something different (like 24000, yes, really), then open my app, it doesn't actually respect the sampleRate I set in my AudioDeviceSetup:
AudioDeviceManager::AudioDeviceSetup setup;
setup.bufferSize = M_DEFAULT_BUFFER_SIZE;
setup.inputChannels = 1;
setup.outputChannels = 2;
setup.sampleRate = DEFAULT_SAMPLE_RATE;
m_deviceManager->initialise(numInputChannels, numOutputChannels, savedState, true, String::empty, &setup);
It seems that juce doesn't call updateSampleRates until it's already in open, meaning the code in setAudioDeviceSetup will never get any sample rate other than 24000. If I add code to close, then ask for samplerate again, then reopen, it fixes the problem, but this is obviously not the right way to fix it.
currentSetup = newSetup;
currentSetup.sampleRate = chooseBestSampleRate (newSetup.sampleRate);
currentSetup.bufferSize = chooseBestBufferSize (newSetup.bufferSize);
error = currentAudioDevice->open (inputChannels,
outputChannels,
currentSetup.sampleRate,
currentSetup.bufferSize);
// My changes
if (error.isNotEmpty()) {
deleteCurrentDevice();
return error;
}
currentAudioDevice->close();
currentSetup.sampleRate = chooseBestSampleRate (newSetup.sampleRate);
currentSetup.bufferSize = chooseBestBufferSize (newSetup.bufferSize);
error = currentAudioDevice->open (inputChannels,
outputChannels,
currentSetup.sampleRate,
currentSetup.bufferSize);
Is there something I'm doing wrong? Is there a better workaround?
