CoreAudio: fix supported channel count.
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>
This commit is contained in:
committed by
The Qt Project
parent
b6970e2e79
commit
d2b54b360e
@@ -196,38 +196,14 @@ QList<int> CoreAudioDeviceInfo::supportedSampleRates()
|
|||||||
|
|
||||||
QList<int> CoreAudioDeviceInfo::supportedChannelCounts()
|
QList<int> CoreAudioDeviceInfo::supportedChannelCounts()
|
||||||
{
|
{
|
||||||
QList<int> supportedChannels;
|
static QList<int> supportedChannels;
|
||||||
int maxChannels = 0;
|
|
||||||
|
|
||||||
#if defined(Q_OS_OSX)
|
if (supportedChannels.isEmpty()) {
|
||||||
UInt32 propSize = 0;
|
// If the number of channels is not supported by an audio device, Core Audio will
|
||||||
AudioObjectPropertyScope scope = m_mode == QAudio::AudioInput ? kAudioDevicePropertyScopeInput : kAudioDevicePropertyScopeOutput;
|
// automatically convert the audio data.
|
||||||
AudioObjectPropertyAddress streamConfigurationPropertyAddress = { kAudioDevicePropertyStreamConfiguration,
|
for (int i = 1; i <= 16; ++i)
|
||||||
scope,
|
supportedChannels.append(i);
|
||||||
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);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
#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;
|
return supportedChannels;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -92,9 +92,6 @@ public:
|
|||||||
QList<QByteArray> inputDevices();
|
QList<QByteArray> inputDevices();
|
||||||
QList<QByteArray> outputDevices();
|
QList<QByteArray> outputDevices();
|
||||||
|
|
||||||
int inputChannelCount();
|
|
||||||
int outputChannelCount();
|
|
||||||
|
|
||||||
float currentIOBufferDuration();
|
float currentIOBufferDuration();
|
||||||
float preferredSampleRate();
|
float preferredSampleRate();
|
||||||
|
|
||||||
|
|||||||
@@ -377,16 +377,6 @@ QList<QByteArray> CoreAudioSessionManager::outputDevices()
|
|||||||
return outputDevices;
|
return outputDevices;
|
||||||
}
|
}
|
||||||
|
|
||||||
int CoreAudioSessionManager::inputChannelCount()
|
|
||||||
{
|
|
||||||
return [[m_sessionObserver audioSession] inputNumberOfChannels];
|
|
||||||
}
|
|
||||||
|
|
||||||
int CoreAudioSessionManager::outputChannelCount()
|
|
||||||
{
|
|
||||||
return [[m_sessionObserver audioSession] outputNumberOfChannels];
|
|
||||||
}
|
|
||||||
|
|
||||||
float CoreAudioSessionManager::currentIOBufferDuration()
|
float CoreAudioSessionManager::currentIOBufferDuration()
|
||||||
{
|
{
|
||||||
return [[m_sessionObserver audioSession] IOBufferDuration];
|
return [[m_sessionObserver audioSession] IOBufferDuration];
|
||||||
|
|||||||
Reference in New Issue
Block a user