Hi Jelle,
I usually work around this using a Timer.
It basically boils down to:
- Have a Timer running with a non expensive speed, e.g. 1 second
- In the timerCallback implementation, check that the app is the currently focused one (
juce::TopLevelWindow::getActiveTopLevelWindow()
comes to the rescue) - If the app is the currently focused one, check the value of your desired sample rate against the one that’s currently being set by the device
- If they don’t match (and the device supports the desired sample rate, this is important as it can happen also on Windows where WASAPI is a bit obtuse), reconfigure the AudioDeviceManager accordingly
Please note that in my case I want to “force” the sample rate that I want in my app.
If you instead would like to “adapt” to the current sample rate set by CoreAudio then you could maybe use the same workaround but with some adjustments at the end.
Hope this helps