Qt World Summit: Register Today!

Using a non default audio device in OS Windows

  • Hi everyone!

    I've got a trouble with my work project and I need some help from gurus of Qt development.

    The bottom line is that i write a program which implements an intercom functionality. So there are three audio-cards on the target computer. Every audio-card has its own audio-input (microphone), and audio-output (speakers). So my program's got to do this:

    1. capture audio stream from audio input of the first audio-device and transfer it to the audio output of the second or third audio device.
    2. and vice versa - capture audio stream from audio input of the second or third audio-device and transfer it to the audio output of the first audio device.

    So the trouble occurs when I try to use NON DEFAULT audio device. Actually it's not using another audio device then default device at all.

    I've wrote something like that:

    QAudioInput* AudioInput;
    QList<QAudioDeviceInfo> AudioInputDevices = QAudioDeviceInfo::availableDevices(QAudio::AudioInput);
    QAudioFormat AudioFormat;


    AudioInput = new QAudioInput(AudioInputDevices[AudioInputDeviceIndex], AudioFormat, this);

    So whatever value the AudioInputDeviceIndex has got, AudioInput always works only with the default device (the device which is set up as a default device in OS Windows preferences). The same thing occurs with the AudioOutput (pointer to an object of the QAudioOutput class).

    In short, how am I supposed to work with three audio-devices all of which except one is non default device in OS preferences.
    I'm using Qt 4.7.4 (32 bit) and OS Windows 7.

    PS: Sorry for my English. I'm working on it. ;)

  • The only person who can help you is yourself. ;)
    Finally the problem has been solved. The cause of such behavior (the objects of QAudioInput and QAudioOutput classes work only with default devices) is that I use Russian localization of MS Windows 7. So if you use or are going to use Russian (and I guess another not English version) of MS Windows 7 you should read the rest of this post.
    The point is that QAudioDeviceInfo::availableDevices method returns list of QAudioDeviceInfo objects. And every object of that list describes its own audio device from all available in the system devices. By the by, there is one virtual device which relates with default system device and the name of that virtual device is always “Default”. So the whole point is all another devices in Russian localization of Windows has Russian names (like «Динамики …» or «Микрофон …») and that’s why Qt can’t recognize them. For example the QAudioDeviceInfo::devicename returns something like “D2fq8&$f32” and QAudioDeviceInfo::supportedchannels (supportedcodec, etc.) returns null arrays. So you can’t work with those devices. I don’t know who mess it up - Qt methods or WinAPI functions (which are wrapped into Qt methods how I guess) but we have what we have. My opinion is that this problem occurs because of such thing: Windows contains the names of devices in Unicode (each char takes two bytes), but WinAPI function which is response to give you the name of device returns this name in ASCII or something (one byte per char). Or maybe Qt holds than device names in ASCII. Anyhow the cause of the issue hides in the circumstance of not correct device name encoding. It’s just my guess. If anybody can correct me, please, feel free to do that. ;)

Log in to reply