# Does iOS preprocess microphone data on modern iPhones?

**URL:** <https://forum.juce.com/t/does-ios-preprocess-microphone-data-on-modern-iphones/26369>\
**Category:** MacOSX and iOS\
**Created:** [February 11, 2018, 7:32pm UTC](https://forum.juce.com/t/does-ios-preprocess-microphone-data-on-modern-iphones/26369 "2018-02-11T19:32:04Z")\
**Posts on this page:** 7\
**Page:** 1

<div class="post-metadata">

**Author:** ![p-i](https://sea2.discourse-cdn.com/flex026/user_avatar/forum.juce.com/p-i/32/1785_2.png) [@p-i](https://forum.juce.com/u/p-i)\
**Post date:** [February 11, 2018, 7:32pm UTC](https://forum.juce.com/t/does-ios-preprocess-microphone-data-on-modern-iphones/26369/1 "2018-02-11T19:32:04Z")

</div>

I play a .WAV trigger tone and have a JUCE iOS decoder app that catches it by processing the microphone data. It works perfectly on my iPhone 5. It is extremely robust.

Someone else is loading exactly the same code onto their iPhone6 and iPhoneX. They are playing the trigger tone from an identical MacBook Pro, but the decoder does not correctly recognise the tone.

The only explanation I can think of is that on these more modern devices there is maybe some preprocessing done on the microphone data, maybe some kind of echo-cancellation?

Does anyone know if this is true? And if so, is there any way to disable this preprocessing?

---

<div class="post-metadata">

**Author:** ![p-i](https://sea2.discourse-cdn.com/flex026/user_avatar/forum.juce.com/p-i/32/1785_2.png) [@p-i](https://forum.juce.com/u/p-i)\
**Post date:** [February 11, 2018, 7:39pm UTC](https://forum.juce.com/t/does-ios-preprocess-microphone-data-on-modern-iphones/26369/2 "2018-02-11T19:39:50Z")

</div>

> [@Disable AGC and highpass filter on iOS](https://forum.juce.com/t/disable-agc-and-highpass-filter-on-ios/12812):
>
> iOS has automatic gain control and a high pass filter on the mic input. You may want to disable this if doing an audio app. Adding this to the iOSAudioIODevice&nbsp;will disable it.&nbsp; setSessionUInt32Property(kAudioSessionProperty\_Mode, kAudioSessionMode\_Measurement); And this will re-enable it. setSessionUInt32Property(kAudioSessionProperty\_Mode, kAudioSessionMode\_Default); It would be good if the AudioIODevice had a way to platform agnosticlly turn on or off any input processing.

^ this looks like the culprit.

However it’s very strange that it works on an iPhone 5S but not on an iPhone 6. All of the devices are using the latest iOS. And if I look at detailed comparisons between the two models I find no mention of anything related to microphone preprocessing.

---

<div class="post-metadata">

**Author:** ![p-i](https://sea2.discourse-cdn.com/flex026/user_avatar/forum.juce.com/p-i/32/1785_2.png) [@p-i](https://forum.juce.com/u/p-i)\
**Post date:** [February 14, 2018, 1:56pm UTC](https://forum.juce.com/t/does-ios-preprocess-microphone-data-on-modern-iphones/26369/3 "2018-02-14T13:56:34Z")

</div>

It turns out my particular problem is due to the fact that the iPhone \<= 5S samples from the microphone at 44.1 kHz and \>= 6S @ 48 kHz.

I was trying (on my 5S) to set the sample rate to `48000`:

```auto
AudioDeviceManager::AudioDeviceSetup audioSetup;
deviceManager.getAudioDeviceSetup (audioSetup);
audioSetup.sampleRate = 48000.0;
auto ret = deviceManager.setAudioDeviceSetup (audioSetup, true);

```

`setAudioDeviceSetup` does not return any error, and in fact a subsequent call to `getAudioDeviceSetup` reports that the sample rate has been successfully changed to `48000`.

Even `deviceManager.getCurrentAudioDevice()->getCurrentSampleRate()` reports `48000`.

However,

```auto
    void prepareToPlay (int samplesPerBlockExpected, double sampleRate) override {
        LOG("prepareToPlay sampleRate: %.1f", sampleRate);
    }

```

… correctly reports that the sample rate has been reverted to its system value of `44100`.

I wonder if this is something that might be improved in JUCE – it took us a while to figure out that the sample rate is misreporting.

---

<div class="post-metadata">

**Author:** ![t0m](https://sea2.discourse-cdn.com/flex026/user_avatar/forum.juce.com/t0m/32/16413_2.png) [@t0m](https://forum.juce.com/u/t0m)\
**Post date:** [February 14, 2018, 2:18pm UTC](https://forum.juce.com/t/does-ios-preprocess-microphone-data-on-modern-iphones/26369/4 "2018-02-14T14:18:28Z")

</div>

Unfortunately the one in `prepareToPlay` is the only one you can trust. On Apple’s mobile devices both the sample rate and buffer size can be changed underneath your feet by other apps (which share the same AudioSession in the OS), or by the OS itself. If this happens then we restart the audio and you get a new `prepareToPlay` call with the updated info. It’s possible that the system is reverting between your audio device setup code and the start of the audio processing.

If you want to find out more about what’s going on you can get a debugger inside the iOSAudioDevice class and enable more verbose logging by setting the macro `JUCE_IOS_AUDIO_LOGGING 1`.

---

<div class="post-metadata">

**Author:** ![t0m](https://sea2.discourse-cdn.com/flex026/user_avatar/forum.juce.com/t0m/32/16413_2.png) [@t0m](https://forum.juce.com/u/t0m)\
**Post date:** [February 14, 2018, 2:19pm UTC](https://forum.juce.com/t/does-ios-preprocess-microphone-data-on-modern-iphones/26369/5 "2018-02-14T14:19:41Z")

</div>

Something that might help is setting the `JUCE_DISABLE_AUDIO_MIXING_WITH_OTHER_APPS` option in the `juce_audio_devices` module options.

---

<div class="post-metadata">

**Author:** ![p-i](https://sea2.discourse-cdn.com/flex026/user_avatar/forum.juce.com/p-i/32/1785_2.png) [@p-i](https://forum.juce.com/u/p-i)\
**Post date:** [February 14, 2018, 10:26pm UTC](https://forum.juce.com/t/does-ios-preprocess-microphone-data-on-modern-iphones/26369/6 "2018-02-14T22:26:16Z")

</div>

Just to report that setting `JUCE_DISABLE_AUDIO_MIXING_WITH_OTHER_APPS` doesn’t lift the 44.1kHz limit on my iPhone 5S.

---

<div class="post-metadata">

**Author:** ![8b17](https://avatars.discourse-cdn.com/v4/letter/8/82dd89/32.png) [@8b17](https://forum.juce.com/u/8b17)\
**Post date:** [October 8, 2018, 12:09pm UTC](https://forum.juce.com/t/does-ios-preprocess-microphone-data-on-modern-iphones/26369/7 "2018-10-08T12:09:32Z")

</div>

Hey p-i, did you find out what caused this issue? I have a similar problem, I am using the iPhone 6s and want to set the samplerate to 44.100Hz but the only option I get is 48kHz… Is there a way to achieve this?
