Clicks / high pitched noise on audio device initialisation (iOS)


#1

A client has reported an issue where a high pitched tone follows a click when loading our JUCE app on an iPad which is connected to a USB audio interface, which apparently does not occur with other audio software.The device becomes unusable at that point and needs to be switch off and on to reset.

The high pitched noise fault only occurs on an iPad 4th gen running iOS 10.3 together with a Focusrite 6i6 interface.
Testing with my Tascam US 4x4 interface on an iPad 2, I hear a series of clicks when a JUCE app is loading, which does not occur with non-JUCE audio apps.


#2

I’ve tried moving my audio initialisation code so it happens in MainComponent constructor rather than JUCEApplication::initialise (which seems better anyhow), the issue remains however, just occurs right before the GUI appears rather than when the app starts loading.


#4

So, after diving into juce_ios_Audio.cpp, I found the offending code. Its the multiple calls to trySampleRate in getAvailableSampleRates - stepping through I found each call produces an audible click. So I tried changing the first call to setAudioSessionActive to false instead of true. So it sets the audio session to inactive while testing for available sample rates. This has fixed the issue and my client is happy. However, I’m not sure whether it actually gets available sample rates with this change (I don’t need to set an arbitrary sample rate). A also found that debugging on device caused an assertion:

AVAudioSession.mm:692: -[AVAudioSession setActive:withOptions:error:]: Deactivating an audio session that has running I/O. All I/O should be stopped or paused prior to deactivating the audio session.

However release builds do not have this issue - my client reported testing our app without issues since the change.