# iOS: USB input channels not always made available when audio first initialized

**URL:** <https://forum.juce.com/t/ios-usb-input-channels-not-always-made-available-when-audio-first-initialized/28980>\
**Category:** MacOSX and iOS\
**Created:** [August 13, 2018, 11:05pm UTC](https://forum.juce.com/t/ios-usb-input-channels-not-always-made-available-when-audio-first-initialized/28980 "2018-08-13T23:05:29Z")\
**Posts on this page:** 7\
**Page:** 1

<div class="post-metadata">

**Author:** ![jemur](https://avatars.discourse-cdn.com/v4/letter/j/da6949/32.png) [@jemur](https://forum.juce.com/u/jemur)\
**Post date:** [August 13, 2018, 11:05pm UTC](https://forum.juce.com/t/ios-usb-input-channels-not-always-made-available-when-audio-first-initialized/28980/1 "2018-08-13T23:05:29Z")

</div>

I think perhaps the AVAudioSession needs to be set to active when calls are made to channelData.reconfigure(…) … otherwise, it appears the input channels are not correctly identified and made available on all iOS devices.

I changed this in the iOSAudioIODevice::Pimpl constructor and open methods, and it seems to now work.

---

<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:** [August 14, 2018, 7:32am UTC](https://forum.juce.com/t/ios-usb-input-channels-not-always-made-available-when-audio-first-initialized/28980/2 "2018-08-14T07:32:47Z")

</div>

Can you post your changes please? Sounds like the same bug we ran into recently.

---

<div class="post-metadata">

**Author:** ![jemur](https://avatars.discourse-cdn.com/v4/letter/j/da6949/32.png) [@jemur](https://forum.juce.com/u/jemur)\
**Post date:** [August 14, 2018, 6:03pm UTC](https://forum.juce.com/t/ios-usb-input-channels-not-always-made-available-when-audio-first-initialized/28980/3 "2018-08-14T18:03:07Z")

</div>

> struct iOSAudioIODevice::Pimpl : public AudioPlayHead,  
> public AsyncUpdater  
> {  
> Pimpl (iOSAudioIODeviceType& ioDeviceType, iOSAudioIODevice& ioDevice)  
> : deviceType (ioDeviceType),  
> owner (ioDevice)  
> {  
> JUCE\_IOS\_AUDIO\_LOG (“Creating iOS audio device”);
> 
> ```
> // We need to activate the audio session here to obtain the available sample rates and buffer sizes,
> // but if we don't set a category first then background audio will always be stopped. This category
> // may be changed later.
> setAudioSessionCategory (AVAudioSessionCategoryPlayAndRecord);
> 
> setAudioSessionActive (true);
> updateHardwareInfo();
> //setAudioSessionActive (false); //jvm
>     
> channelData.reconfigure ({}, {});
> setAudioSessionActive (false); //jvm
> 
> sessionHolder->activeDevices.add (this);
> }
> 
> ```

…

```
` String open (const BigInteger& inputChannelsWanted,
                 const BigInteger& outputChannelsWanted,
                 double sampleRateWanted, int bufferSizeWanted)
    {
        close();

        firstHostTime = true;
        lastNumFrames = 0;
        xrun = 0;
        lastError.clear();

        requestedInputChannels = inputChannelsWanted;
        requestedOutputChannels = outputChannelsWanted;
        targetSampleRate = sampleRateWanted;
        targetBufferSize = bufferSizeWanted > 0 ? bufferSizeWanted : defaultBufferSize;

        JUCE_IOS_AUDIO_LOG ("Opening audio device:"
                            << " inputChannelsWanted: " << requestedInputChannels .toString (2)
                            << ", outputChannelsWanted: " << requestedOutputChannels.toString (2)
                            << ", targetSampleRate: " << targetSampleRate
                            << ", targetBufferSize: " << targetBufferSize);

        setAudioSessionActive (true); //jvm

        channelData.reconfigure (requestedInputChannels, requestedOutputChannels);

        setAudioSessionCategory (channelData.areInputChannelsAvailable() ? AVAudioSessionCategoryPlayAndRecord : AVAudioSessionCategoryPlayback);
        //setAudioSessionActive (true); //jvm`

```

---

<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:** [August 15, 2018, 12:49pm UTC](https://forum.juce.com/t/ios-usb-input-channels-not-always-made-available-when-audio-first-initialized/28980/4 "2018-08-15T12:49:29Z")

</div>

What audio hardware are you using?

---

<div class="post-metadata">

**Author:** ![jemur](https://avatars.discourse-cdn.com/v4/letter/j/da6949/32.png) [@jemur](https://forum.juce.com/u/jemur)\
**Post date:** [August 15, 2018, 6:25pm UTC](https://forum.juce.com/t/ios-usb-input-channels-not-always-made-available-when-audio-first-initialized/28980/5 "2018-08-15T18:25:51Z")

</div>

Apple USB Camera Adapter model A1619 (firmware 1.0.5, hardware 1.0.0)

Seems to appear with a variety of both UAC 1 and 2 devices, eg.

- [http://cdn-assets.tc-helicon.com/en/products/perform-ve/](http://cdn-assets.tc-helicon.com/en/products/perform-ve/)
- [http://cdn-assets.tc-helicon.com/en/products/play-acoustic/](http://cdn-assets.tc-helicon.com/en/products/play-acoustic/)
- [https://itrack.focusrite.com/products/itrack-pocket](https://itrack.focusrite.com/products/itrack-pocket)

Apple devices I’ve tried that show the bug:

- iPad mini 2 model ME281C/A (running 11.4.1)
- iPhone S model MKU62VC/A (running 11.4.1)
- iPhone X model MQAC2VC/A (running 11.4)

---

<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:** [August 17, 2018, 7:48am UTC](https://forum.juce.com/t/ios-usb-input-channels-not-always-made-available-when-audio-first-initialized/28980/6 "2018-08-17T07:48:07Z")

</div>

OK, I’ll have a look at this next week when I have some devices available.

Have you tried disconnecting and reconnecting the hardware? Does the `AudioDeviceSelectorComponent` work correctly?

---

<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:** [August 20, 2018, 11:11am UTC](https://forum.juce.com/t/ios-usb-input-channels-not-always-made-available-when-audio-first-initialized/28980/7 "2018-08-20T11:11:39Z")

</div>

[https://github.com/WeAreROLI/JUCE/commit/693a66d73d86b4954f1c1a9a007fd6401bc29ad4](https://github.com/WeAreROLI/JUCE/commit/693a66d73d86b4954f1c1a9a007fd6401bc29ad4)
