CoreAudio: Allow more flexability when specifying SampleRates
authorAndy Nichols <andy.nichols@digia.com>
Sun, 2 Mar 2014 15:19:37 +0000 (16:19 +0100)
committerThe Qt Project <gerrit-noreply@qt-project.org>
Mon, 3 Mar 2014 13:54:54 +0000 (14:54 +0100)
The available sample rates for a given device are the nominal sample
rates reported by the device.  It is possible to use other sample rates
and CoreAudio will take care of the conversion.  So what we will do is
report what rates are available for a device, but not explicitly require
those sample rates to have a valid format.

Task-number: QTBUG-36265
Change-Id: Idbbdeacbb6bc1fe434bcd8dec519ad70d4ccd545
Reviewed-by: Yoann Lopes <yoann.lopes@digia.com>
src/plugins/coreaudio/coreaudiodeviceinfo.mm

index 92ce988..5d07ca4 100644 (file)
@@ -130,9 +130,11 @@ bool CoreAudioDeviceInfo::isFormatSupported(const QAudioFormat &format) const
 {
     CoreAudioDeviceInfo *self = const_cast<CoreAudioDeviceInfo*>(this);
 
+    //Sample rates are more of a suggestion with CoreAudio so as long as we get a
+    //sane value then we can likely use it.
     return format.isValid()
             && format.codec() == QString::fromLatin1("audio/pcm")
-            && self->supportedSampleRates().contains(format.sampleRate())
+            && format.sampleRate() > 0
             && self->supportedChannelCounts().contains(format.channelCount())
             && self->supportedSampleSizes().contains(format.sampleSize());
 }
@@ -168,8 +170,9 @@ QList<int> CoreAudioDeviceInfo::supportedSampleRates()
             AudioValueRange* vr = new AudioValueRange[pc];
 
             if (AudioObjectGetPropertyData(m_deviceId, &availableNominalSampleRatesAddress, 0, NULL, &propSize, vr) == noErr) {
-                for (int i = 0; i < pc; ++i)
-                    sampleRates << vr[i].mMaximum;
+                for (int i = 0; i < pc; ++i) {
+                    sampleRates << vr[i].mMinimum << vr[i].mMaximum;
+                }
             }
 
             delete vr;