Uniqueness of input and output device names

When creating an AudioIODevice by calling the function below, how significant are the input and output device names in identifying which input device to connect to which output device? The reason I ask is that suppose you wish to create an AudioIODevice from the input device of one physical interface (e.g. Focusrite Scalett 2i2) and the output device of an identical physical interface. How would you distinguish between the two input and output devices?

Another way of putting this is as follows: are the input device names, as returned by getDeviceNames(true), guarateed to be unique within the context of a particular platform at a particular point in time? Ditto the output device names, as returned by getDeviceNames(false).


AudioIODevice* createDevice (const String& outputDeviceName,
                                 const String& inputDeviceName)
    jassert (hasScanned); // need to call scanForDevices() before doing this

    const int outputIndex = deviceList.outputDeviceNames.indexOf (outputDeviceName);
    const int inputIndex = deviceList.inputDeviceNames.indexOf (inputDeviceName);

    if (outputIndex >= 0 || inputIndex >= 0)
        return new DSoundAudioIODevice (outputDeviceName.isNotEmpty() ? outputDeviceName
                                                                      : inputDeviceName,
                                        outputIndex, inputIndex);

    return nullptr;

As far as I can see, studying the different implementations of scanForDevices() and getDeviceNames(bool) for all the different APIs (CoreAudio, ALSA, JACK, ASIO, DirectSound, WASAPI):

The StringArray returned by getDeviceNames is guaranteed to have unique string entries. For some APIs there is some code in JUCE like

inputDeviceNames.appendNumbersToDuplicates (false, true);
outputDeviceNames.appendNumbersToDuplicates (false, true);

in scanForDevices() that appends numbers to device names occurring more than once to guarantee unique entries. In this case, the numbers will be appended by JUCE, so the device name in JUCE may be different from the device name in other audio apps. Some APIs append these numbers themselves, I believe ASIO does that (not 100% sure though).

On the other hand, I don't see anything that would prevent the input device and the corresponding output device from having the same name.

Thanks, Timur.

Just to be clear. It's one thing adding numbers to the elements of a string array to ensure that they are unique, which from its signature appears to be what appendNumbersToDuplicates() does. But how does JUCE relate these (by now) unique elements to the devices themselves? Does it do it on the basis of their positions in the array?

To be honest I am not entirely sure, but my guess is that you can't rely on the order of these duplicate devices.

Surely something in JUCE must know e.g. that a particular audio buffer is destined for the output device in slot 1 as opposed to the identical output device in slot 2.

Can anyone else help?

Thanks anyway Timur.