CoreAudio: Allow more flexability when specifying SampleRates

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>
This commit is contained in:
Andy Nichols
2014-03-02 16:19:37 +01:00
committed by The Qt Project
parent d5dfef66bb
commit 4d31ec0793

View File

@@ -130,9 +130,11 @@ bool CoreAudioDeviceInfo::isFormatSupported(const QAudioFormat &format) const
{ {
CoreAudioDeviceInfo *self = const_cast<CoreAudioDeviceInfo*>(this); 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() return format.isValid()
&& format.codec() == QString::fromLatin1("audio/pcm") && format.codec() == QString::fromLatin1("audio/pcm")
&& self->supportedSampleRates().contains(format.sampleRate()) && format.sampleRate() > 0
&& self->supportedChannelCounts().contains(format.channelCount()) && self->supportedChannelCounts().contains(format.channelCount())
&& self->supportedSampleSizes().contains(format.sampleSize()); && self->supportedSampleSizes().contains(format.sampleSize());
} }
@@ -168,8 +170,9 @@ QList<int> CoreAudioDeviceInfo::supportedSampleRates()
AudioValueRange* vr = new AudioValueRange[pc]; AudioValueRange* vr = new AudioValueRange[pc];
if (AudioObjectGetPropertyData(m_deviceId, &availableNominalSampleRatesAddress, 0, NULL, &propSize, vr) == noErr) { if (AudioObjectGetPropertyData(m_deviceId, &availableNominalSampleRatesAddress, 0, NULL, &propSize, vr) == noErr) {
for (int i = 0; i < pc; ++i) for (int i = 0; i < pc; ++i) {
sampleRates << vr[i].mMaximum; sampleRates << vr[i].mMinimum << vr[i].mMaximum;
}
} }
delete vr; delete vr;