From b82ed43086aebb4698a8a52965eeb17349ef1d04 Mon Sep 17 00:00:00 2001 From: Justin McPherson Date: Mon, 21 Jun 2010 15:11:59 +1000 Subject: Audio(osx); Fix audio format converters. Reviewed-by:Dmytro Poplavskiy --- src/multimedia/audio/qaudio_mac.cpp | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) diff --git a/src/multimedia/audio/qaudio_mac.cpp b/src/multimedia/audio/qaudio_mac.cpp index 14fee8b..4e17b52 100644 --- a/src/multimedia/audio/qaudio_mac.cpp +++ b/src/multimedia/audio/qaudio_mac.cpp @@ -68,11 +68,11 @@ QAudioFormat toQAudioFormat(AudioStreamBasicDescription const& sf) audioFormat.setChannels(sf.mChannelsPerFrame); audioFormat.setSampleSize(sf.mBitsPerChannel); audioFormat.setCodec(QString::fromLatin1("audio/pcm")); - audioFormat.setByteOrder(sf.mFormatFlags & kLinearPCMFormatFlagIsBigEndian != 0 ? QAudioFormat::BigEndian : QAudioFormat::LittleEndian); + audioFormat.setByteOrder((sf.mFormatFlags & kAudioFormatFlagIsBigEndian) != 0 ? QAudioFormat::BigEndian : QAudioFormat::LittleEndian); QAudioFormat::SampleType type = QAudioFormat::UnSignedInt; - if ((sf.mFormatFlags & kLinearPCMFormatFlagIsSignedInteger) != 0) + if ((sf.mFormatFlags & kAudioFormatFlagIsSignedInteger) != 0) type = QAudioFormat::SignedInt; - else if ((sf.mFormatFlags & kLinearPCMFormatFlagIsFloat) != 0) + else if ((sf.mFormatFlags & kAudioFormatFlagIsFloat) != 0) type = QAudioFormat::Float; audioFormat.setSampleType(type); @@ -99,6 +99,9 @@ AudioStreamBasicDescription toAudioStreamBasicDescription(QAudioFormat const& au case QAudioFormat::Unknown: default: break; } + if (audioFormat.byteOrder() == QAudioFormat::BigEndian) + sf.mFormatFlags |= kAudioFormatFlagIsBigEndian; + return sf; } -- cgit v0.12 From 66d02e4bde0a628978436217032abe555ed77fad Mon Sep 17 00:00:00 2001 From: Justin McPherson Date: Mon, 21 Jun 2010 15:18:32 +1000 Subject: Audio(osx); refactor input period conversion Reviewed-by:Dmytro Poplavskiy --- src/multimedia/audio/qaudioinput_mac_p.cpp | 49 +++++++++++++++--------------- 1 file changed, 25 insertions(+), 24 deletions(-) diff --git a/src/multimedia/audio/qaudioinput_mac_p.cpp b/src/multimedia/audio/qaudioinput_mac_p.cpp index b99fe11..5897e75 100644 --- a/src/multimedia/audio/qaudioinput_mac_p.cpp +++ b/src/multimedia/audio/qaudioinput_mac_p.cpp @@ -210,6 +210,11 @@ public: return true; } + bool empty() const + { + return position == totalPackets; + } + private: UInt32 totalPackets; UInt32 position; @@ -275,36 +280,32 @@ public: if (m_audioConverter != 0) { QAudioPacketFeeder feeder(m_inputBufferList); - bool wecan = true; int copied = 0; - const int available = m_buffer->free(); - while (err == noErr && wecan) { + while (err == noErr && !feeder.empty()) { QAudioRingBuffer::Region region = m_buffer->acquireWriteRegion(available); - if (region.second > 0) { - AudioBufferList output; - output.mNumberBuffers = 1; - output.mBuffers[0].mNumberChannels = 1; - output.mBuffers[0].mDataByteSize = region.second; - output.mBuffers[0].mData = region.first; - - UInt32 packetSize = region.second / m_outputFormat.mBytesPerPacket; - err = AudioConverterFillComplexBuffer(m_audioConverter, - converterCallback, - &feeder, - &packetSize, - &output, - 0); - - region.second = output.mBuffers[0].mDataByteSize; - copied += region.second; + if (region.second == 0) + break; + + AudioBufferList output; + output.mNumberBuffers = 1; + output.mBuffers[0].mNumberChannels = 1; + output.mBuffers[0].mDataByteSize = region.second; + output.mBuffers[0].mData = region.first; + + UInt32 packetSize = region.second / m_outputFormat.mBytesPerPacket; + err = AudioConverterFillComplexBuffer(m_audioConverter, + converterCallback, + &feeder, + &packetSize, + &output, + 0); + region.second = output.mBuffers[0].mDataByteSize; + copied += region.second; - m_buffer->releaseWriteRegion(region); - } - else - wecan = false; + m_buffer->releaseWriteRegion(region); } framesRendered += copied / m_outputFormat.mBytesPerFrame; -- cgit v0.12 From 76c256bdabcc207a6ed70d5b5b62698495548a25 Mon Sep 17 00:00:00 2001 From: Justin McPherson Date: Tue, 22 Jun 2010 12:01:51 +1000 Subject: Audio(osx); Fix period size calculation. Task-number: QTBUG-8878 Reviewed-by:Dmytro Poplavskiy --- src/multimedia/audio/qaudiooutput_mac_p.cpp | 15 ++------------- 1 file changed, 2 insertions(+), 13 deletions(-) diff --git a/src/multimedia/audio/qaudiooutput_mac_p.cpp b/src/multimedia/audio/qaudiooutput_mac_p.cpp index 9689101..cc52d90 100644 --- a/src/multimedia/audio/qaudiooutput_mac_p.cpp +++ b/src/multimedia/audio/qaudiooutput_mac_p.cpp @@ -358,17 +358,7 @@ bool QAudioOutputPrivate::open() // Set stream format streamFormat = toAudioStreamBasicDescription(audioFormat); - UInt32 size = sizeof(deviceFormat); - if (AudioUnitGetProperty(audioUnit, - kAudioUnitProperty_StreamFormat, - kAudioUnitScope_Input, - 0, - &deviceFormat, - &size) != noErr) { - qWarning() << "QAudioOutput: Unable to retrieve device format"; - return false; - } - + UInt32 size = sizeof(streamFormat); if (AudioUnitSetProperty(audioUnit, kAudioUnitProperty_StreamFormat, kAudioUnitScope_Input, @@ -392,8 +382,7 @@ bool QAudioOutputPrivate::open() return false; } - periodSizeBytes = (numberOfFrames * streamFormat.mSampleRate / deviceFormat.mSampleRate) * - streamFormat.mBytesPerFrame; + periodSizeBytes = numberOfFrames * streamFormat.mBytesPerFrame; if (internalBufferSize < periodSizeBytes * 2) internalBufferSize = periodSizeBytes * 2; else -- cgit v0.12