CoreAudio: fix supported channel count.
authorYoann Lopes <yoann.lopes@digia.com>
Mon, 31 Mar 2014 12:22:40 +0000 (14:22 +0200)
committerThe Qt Project <gerrit-noreply@qt-project.org>
Tue, 1 Apr 2014 11:43:13 +0000 (13:43 +0200)
We were using the number of channels actually used by audio devices as
the maximum channel count. This is wrong as CoreAudio can automatically
split or merge channels in order to accommodate the device.
We now assume all channel configurations are valid.

Task-number: QTBUG-37956
Change-Id: Ia8e8bbea8543caa7fecda305be74a2953b92fd25
Reviewed-by: Andy Nichols <andy.nichols@digia.com>
src/plugins/coreaudio/coreaudiodeviceinfo.mm
src/plugins/coreaudio/coreaudiosessionmanager.h
src/plugins/coreaudio/coreaudiosessionmanager.mm

index 56765ca..ac41a31 100644 (file)
@@ -196,38 +196,14 @@ QList<int> CoreAudioDeviceInfo::supportedSampleRates()
 
 QList<int> CoreAudioDeviceInfo::supportedChannelCounts()
 {
-    QList<int> supportedChannels;
-    int maxChannels = 0;
+    static QList<int> supportedChannels;
 
-#if defined(Q_OS_OSX)
-    UInt32 propSize = 0;
-    AudioObjectPropertyScope scope = m_mode == QAudio::AudioInput ? kAudioDevicePropertyScopeInput : kAudioDevicePropertyScopeOutput;
-    AudioObjectPropertyAddress streamConfigurationPropertyAddress = { kAudioDevicePropertyStreamConfiguration,
-                                                                      scope,
-                                                                      kAudioObjectPropertyElementMaster };
-
-    if (AudioObjectGetPropertyDataSize(m_deviceId, &streamConfigurationPropertyAddress, 0, NULL, &propSize) == noErr) {
-        AudioBufferList* audioBufferList = static_cast<AudioBufferList*>(malloc(propSize));
-
-        if (audioBufferList != 0) {
-            if (AudioObjectGetPropertyData(m_deviceId, &streamConfigurationPropertyAddress, 0, NULL, &propSize, audioBufferList) == noErr) {
-                for (int i = 0; i < int(audioBufferList->mNumberBuffers); ++i)
-                    maxChannels += audioBufferList->mBuffers[i].mNumberChannels;
-            }
-
-            free(audioBufferList);
-        }
+    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);
     }
-#else //iOS
-    if (m_mode == QAudio::AudioInput)
-        maxChannels = CoreAudioSessionManager::instance().inputChannelCount();
-    else if (m_mode == QAudio::AudioOutput)
-        maxChannels = CoreAudioSessionManager::instance().outputChannelCount();
-#endif
-
-    // Assume all channel configurations are supported up to the maximum number of channels
-    for (int i = 1; i <= maxChannels; ++i)
-        supportedChannels.append(i);
 
     return supportedChannels;
 }
index 61d8967..26f8fee 100644 (file)
@@ -92,9 +92,6 @@ public:
     QList<QByteArray> inputDevices();
     QList<QByteArray> outputDevices();
 
-    int inputChannelCount();
-    int outputChannelCount();
-
     float currentIOBufferDuration();
     float preferredSampleRate();
 
index 0e795e7..04c8b6e 100644 (file)
@@ -377,16 +377,6 @@ QList<QByteArray> CoreAudioSessionManager::outputDevices()
     return outputDevices;
 }
 
-int CoreAudioSessionManager::inputChannelCount()
-{
-    return [[m_sessionObserver audioSession] inputNumberOfChannels];
-}
-
-int CoreAudioSessionManager::outputChannelCount()
-{
-    return [[m_sessionObserver audioSession] outputNumberOfChannels];
-}
-
 float CoreAudioSessionManager::currentIOBufferDuration()
 {
     return [[m_sessionObserver audioSession] IOBufferDuration];