[Interest] How to get number of channels from QAudioDeviceInfo

Glenn Ramsey gr at componic.co.nz
Mon Jan 25 22:35:00 CET 2016


On 23/01/16 08:37, Jason H wrote:
> 
> 
>> Sent: Thursday, January 21, 2016 at 11:07 PM From: "Glenn Ramsey"
>> <gr at componic.co.nz> To: interest at qt-project.org Subject: [Interest] How to
>> get number of channels from QAudioDeviceInfo
>> 
>> Hi,
>> 
>> I would like to use the Qt5.x QtMultiMedia to output sound independently
>> on multi-channel devices such as 5.1 and 7.1 sound cards. However I can't
>> figure out to tell how many channels a device has.
>> 
>> From the documentation I guess that
>> QAudioDeviceInfo::supportedChannelCounts is the call that I need but that
>> isn't giving the answers that I expect.
>> 
>> PyQt5 test program (built with Qt 5.5.1 on OSX 10.10.5):
>> 
>> from PyQt5.QtMultimedia import QAudioDeviceInfo, QAudio, QAudioFormat
>> 
>> for d in QAudioDeviceInfo.availableDevices(QAudio.AudioOutput): print
>> d.deviceName(), d.supportedChannelCounts() f =
>> QAudioFormat(d.preferredFormat()) f.setChannelCount(6) print
>> d.isFormatSupported(f)
>> 
>> Using OSX 10.10.5 on a MacBook Pro I have a 5.1 USB audio card plugged in
>> and the output from the above program is:
>> 
>> Built-in Output [1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16] 
>> True USB Audio [1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16] 
>> True
>> 
>> I was expecting some information that would tell me that the built in
>> output has 2 channels and that 6 isn't supported and the USB audio has 6
>> channels. I get I similar result on Windows 7.
>> 
>> What is the right way to query the number of channels on a device?
> 
> 
> I am mucking about the OSX multimedia stuff for an unrelated issue. From what
> I can tell the backends are for reading an writing multimedia from system
> sources. I don't know if you can count on Qt to be the equivalent of
> BandCamp, because so much of AVFoundation works differently from other
> platforms. Qt does a good job of the common stuff, but I think you'll have to
> go native for low-level details like that. You could extend Qt to those
> details or just use AVFoundation/CoreAudio directly.
> 
> Or I could be completely wrong. But that's how Interpret what I've seen so
> far.
> 

On 23/01/16 08:37, Jason H wrote:
>
>
>> Sent: Thursday, January 21, 2016 at 11:07 PM
>> From: "Glenn Ramsey" <gr at componic.co.nz>
>> To: interest at qt-project.org
>> Subject: [Interest] How to get number of channels from QAudioDeviceInfo
>>
>> Hi,
>>
>> I would like to use the Qt5.x QtMultiMedia to output sound independently on
>> multi-channel devices such as 5.1 and 7.1 sound cards. However I can't figure
>> out to tell how many channels a device has.
>>
>> From the documentation I guess that QAudioDeviceInfo::supportedChannelCounts is
>> the call that I need but that isn't giving the answers that I expect.
>>
>> PyQt5 test program (built with Qt 5.5.1 on OSX 10.10.5):
>>
>>     from PyQt5.QtMultimedia import QAudioDeviceInfo, QAudio, QAudioFormat
>>
>>     for d in QAudioDeviceInfo.availableDevices(QAudio.AudioOutput):
>>         print d.deviceName(), d.supportedChannelCounts()
>>         f = QAudioFormat(d.preferredFormat())
>>         f.setChannelCount(6)
>>         print d.isFormatSupported(f)
>>
>> Using OSX 10.10.5 on a MacBook Pro I have a 5.1 USB audio card plugged in and
>> the output from the above program is:
>>
>>     Built-in Output [1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16]
>>     True
>>     USB Audio [1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16]
>>     True
>>
>> I was expecting some information that would tell me that the built in output has
>> 2 channels and that 6 isn't supported and the USB audio has 6 channels. I get I
>> similar result on Windows 7.
>>
>> What is the right way to query the number of channels on a device?
>
>
> I am mucking about the OSX multimedia stuff for an unrelated issue. From what
I can tell the backends are for reading an writing multimedia from system
sources. I don't know if you can count on Qt to be the equivalent of BandCamp,
because so much of AVFoundation works differently from other platforms. Qt does
a good job of the common stuff, but I think you'll have to go native for
low-level details like that. You could extend Qt to those details or just use
AVFoundation/CoreAudio directly.
>
> Or I could be completely wrong. But that's how Interpret what I've seen so far.
>

It appears that supportedChannelCounts is not really implemented and the
implementation explains the output that I get. This snippet is from
coreaudiodeviceinfo.mm in 5.5.1.

QList<int> CoreAudioDeviceInfo::supportedChannelCounts()
{
    static QList<int> supportedChannels;

    if (supportedChannels.isEmpty()) {
        // If the number of channels is not supported by an audio device, Core
Audio will
        // automatically convert the audio data.
        for (int i = 1; i <= 16; ++i)
            supportedChannels.append(i);
    }

    return supportedChannels;
}

I guess it is saying is that you can supply up to 16 channels and Qt will let
CoreAudio decide what to do  with it.

In the application am writing I can work around not being able to detect the
actual number of channels on a device but I do need to be able to send sound
data independently to each channel. Is this possible with Qt?

Glenn



More information about the Interest mailing list