summaryrefslogtreecommitdiffstats
path: root/src/multimedia/audio/qaudioinput_mac_p.cpp
diff options
context:
space:
mode:
authorJustin McPherson <justin.mcpherson@nokia.com>2010-03-16 00:12:21 (GMT)
committerJustin McPherson <justin.mcpherson@nokia.com>2010-03-16 03:47:10 (GMT)
commitabcbcece2988d36fe88116fae429685430452689 (patch)
treedbcf6e2890e1a83e4262700215044ae9e26b6ad2 /src/multimedia/audio/qaudioinput_mac_p.cpp
parent1c5f43489f7c2e47dd602307570dd6235355da9d (diff)
downloadQt-abcbcece2988d36fe88116fae429685430452689.zip
Qt-abcbcece2988d36fe88116fae429685430452689.tar.gz
Qt-abcbcece2988d36fe88116fae429685430452689.tar.bz2
Use AudioConverter when not preferred format.
Reviewed-by:Dmytro Poplavskiy
Diffstat (limited to 'src/multimedia/audio/qaudioinput_mac_p.cpp')
-rw-r--r--src/multimedia/audio/qaudioinput_mac_p.cpp58
1 files changed, 32 insertions, 26 deletions
diff --git a/src/multimedia/audio/qaudioinput_mac_p.cpp b/src/multimedia/audio/qaudioinput_mac_p.cpp
index 1db5866..4b37b18 100644
--- a/src/multimedia/audio/qaudioinput_mac_p.cpp
+++ b/src/multimedia/audio/qaudioinput_mac_p.cpp
@@ -54,12 +54,11 @@
#include <QtCore/qtimer.h>
#include <QtCore/qdebug.h>
-#include <QtMultimedia/qaudiodeviceinfo.h>
#include <QtMultimedia/qaudioinput.h>
#include "qaudio_mac_p.h"
#include "qaudioinput_mac_p.h"
-
+#include "qaudiodeviceinfo_mac_p.h"
QT_BEGIN_NAMESPACE
@@ -241,7 +240,7 @@ public:
m_flushTimer = new QTimer(this);
connect(m_flushTimer, SIGNAL(timeout()), SLOT(flushBuffer()));
- if (inputFormat.mSampleRate != outputFormat.mSampleRate) {
+ if (toQAudioFormat(inputFormat) != toQAudioFormat(outputFormat)) {
if (AudioConverterNew(&m_inputFormat, &m_outputFormat, &m_audioConverter) != noErr) {
qWarning() << "QAudioInput: Unable to create an Audio Converter";
m_audioConverter = 0;
@@ -520,6 +519,7 @@ QAudioInputPrivate::QAudioInputPrivate(const QByteArray& device, QAudioFormat co
if (QAudio::Mode(mode) == QAudio::AudioOutput)
errorCode = QAudio::OpenError;
else {
+ audioDeviceInfo = new QAudioDeviceInfoInternal(device, QAudio::AudioInput);
isOpen = false;
audioDeviceId = AudioDeviceID(did);
audioUnit = 0;
@@ -540,6 +540,7 @@ QAudioInputPrivate::QAudioInputPrivate(const QByteArray& device, QAudioFormat co
QAudioInputPrivate::~QAudioInputPrivate()
{
close();
+ delete audioDeviceInfo;
}
bool QAudioInputPrivate::open()
@@ -577,7 +578,7 @@ bool QAudioInputPrivate::open()
1,
&enable,
sizeof(enable)) != noErr) {
- qWarning() << "QAudioInput: Unabled to switch to input mode (Enable Input)";
+ qWarning() << "QAudioInput: Unable to switch to input mode (Enable Input)";
return false;
}
@@ -588,7 +589,7 @@ bool QAudioInputPrivate::open()
0,
&enable,
sizeof(enable)) != noErr) {
- qWarning() << "QAudioInput: Unabled to switch to input mode (Disable output)";
+ qWarning() << "QAudioInput: Unable to switch to input mode (Disable output)";
return false;
}
@@ -619,35 +620,40 @@ bool QAudioInputPrivate::open()
}
// Set format
+ // Wanted
streamFormat = toAudioStreamBasicDescription(audioFormat);
- size = sizeof(deviceFormat);
- if (AudioUnitGetProperty(audioUnit,
- kAudioUnitProperty_StreamFormat,
- kAudioUnitScope_Input,
- 1,
- &deviceFormat,
- &size) != noErr) {
- qWarning() << "QAudioInput: Unable to retrieve device format";
- return false;
- }
-
- // If the device frequency is different to the requested use a converter
- if (deviceFormat.mSampleRate != streamFormat.mSampleRate) {
- AudioUnitSetProperty(audioUnit,
+ // Required on unit
+ if (audioFormat == audioDeviceInfo->preferredFormat()) {
+ deviceFormat = streamFormat;
+ AudioUnitSetProperty(audioUnit,
kAudioUnitProperty_StreamFormat,
kAudioUnitScope_Output,
1,
&deviceFormat,
- sizeof(streamFormat));
+ sizeof(deviceFormat));
}
else {
- AudioUnitSetProperty(audioUnit,
- kAudioUnitProperty_StreamFormat,
- kAudioUnitScope_Output,
- 1,
- &streamFormat,
- sizeof(streamFormat));
+ size = sizeof(deviceFormat);
+ if (AudioUnitGetProperty(audioUnit,
+ kAudioUnitProperty_StreamFormat,
+ kAudioUnitScope_Input,
+ 1,
+ &deviceFormat,
+ &size) != noErr) {
+ qWarning() << "QAudioInput: Unable to retrieve device format";
+ return false;
+ }
+
+ if (AudioUnitSetProperty(audioUnit,
+ kAudioUnitProperty_StreamFormat,
+ kAudioUnitScope_Output,
+ 1,
+ &deviceFormat,
+ sizeof(deviceFormat)) != noErr) {
+ qWarning() << "QAudioInput: Unable to set device format";
+ return false;
+ }
}
// Setup buffers