Bug with disabling inputs

We found a bug with input device mappings that is reproducible in the DemoRunner (using the Audio Recording demo). If we go into Audio Settings and disable input 1 with the intention to record using input 2 we get silence.

In debug mode it stops on the assert in the following function (tracktion_WaveInputDevice.cpp):

void copyIncomingDataIntoBuffer (const float* const* allChannels, int numChannels, int numSamples)
{
    if (numChannels == 0)
        return;

    auto& wi = getWaveInput();
    auto& channelSet = wi.getChannelSet();
    inputBuffer.setSize (channelSet.size(), numSamples);

    for (const auto& ci : wi.getChannels())
    {
        if (juce::isPositiveAndBelow (ci.indexInDevice, numChannels))
        {
            auto inputIndex = channelSet.getChannelIndexForType (ci.channel);
            juce::FloatVectorOperations::copy (inputBuffer.getWritePointer (inputIndex),
                                                allChannels[ci.indexInDevice], numSamples);
        }
        else
        {
            jassertfalse; // Is an input device getting created with more channels than the total number of device channels?
        }
    }
}

numChannels appears to represent the total number of channels available and decreases when disabling an input in the settings. The if (juce::isPositiveAndBelow (ci.indexInDevice, numChannels)) compares the index of the enabled channels with numChannels so the assert will happen every time you disable any input but the last one.

On a two input interface these are the settings where we get unexpected results:
Mic in input 2, Settings input 1 disabled input 2 enabled, Track input 1+2: No sound
Mic in input 2, Settings input 1 disabled input 2 enabled, Track input 2: No sound (also arming turns off).
Mic in input 2, Settings input 1 disabled input 2 enabled, Track input 1: Sound (??)

Any idea what could be going on? :slight_smile:

Have you called WaveInputDevice::setStereoPair false? I think you need to do that in order to get channels 1 and 2 as separate devices. This might be an oversight in the demo.

Yes, sorry I failed to mention that we use setStereoPair false and I had to add that modification to DemoRunner as well!

Edit: Hm I checked and we set showChannelsAsStereoPairs to false in the constructor of the AudioDeviceSelectorComponent but I don’t think we explicitly set it on each WaveInputDevice, that could indeed be an issue.

RecordingDemo.h appears to turn off stereo pairing for every WaveInputDevice:

        for (int i = 0; i < dm.getNumWaveInDevices(); i++)
            if (auto wip = dm.getWaveInDevice (i))
                wip->setStereoPair (false);

Issue is still present though.