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

**URL:** https://forum.juce.com/t/clicks-high-pitched-noise-on-audio-device-initialisation-ios/22307
**Category:** MacOSX and iOS
**Created:** [May 8, 2017, 10:00am UTC](https://forum.juce.com/t/clicks-high-pitched-noise-on-audio-device-initialisation-ios/22307 "2017-05-08T10:00:23Z")
**Posts on this page:** 3
**Page:** 1

<div class="post-metadata">

### Author: ![adamwilson](https://sea2.discourse-cdn.com/flex026/user_avatar/forum.juce.com/adamwilson/32/1387_2.png) [@adamwilson](https://forum.juce.com/u/adamwilson)
#### Post date: [May 8, 2017, 10:00am UTC](https://forum.juce.com/t/clicks-high-pitched-noise-on-audio-device-initialisation-ios/22307/1 "2017-05-08T10:00:23Z")

</div>

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.

---

<div class="post-metadata">

### Author: ![adamwilson](https://sea2.discourse-cdn.com/flex026/user_avatar/forum.juce.com/adamwilson/32/1387_2.png) [@adamwilson](https://forum.juce.com/u/adamwilson)
#### Post date: [May 8, 2017, 10:37am UTC](https://forum.juce.com/t/clicks-high-pitched-noise-on-audio-device-initialisation-ios/22307/2 "2017-05-08T10:37:20Z")

</div>

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.

---

<div class="post-metadata">

### Author: ![adamwilson](https://sea2.discourse-cdn.com/flex026/user_avatar/forum.juce.com/adamwilson/32/1387_2.png) [@adamwilson](https://forum.juce.com/u/adamwilson)
#### Post date: [May 9, 2017, 10:42am UTC](https://forum.juce.com/t/clicks-high-pitched-noise-on-audio-device-initialisation-ios/22307/4 "2017-05-09T10:42:11Z")

</div>

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:

```auto
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.
