From 72c8eccf96284cc88a534001398cf1fd7dd694ed Mon Sep 17 00:00:00 2001 From: Bill Somerville Date: Tue, 21 Mar 2017 13:34:01 +0000 Subject: [PATCH] Fix endian issue with some Mac OS X sound devices Audio loop back devices on Mac OS X Intel strangely have a big endian sample format, perhaps a hang over from PowerPC days. This change ensures that samples are converted to the machine endianness before processing. Also re-enabled is the input audio format validation which now seems to work. git-svn-id: svn+ssh://svn.code.sf.net/p/wsjt/wsjt/branches/wsjtx@7614 ab8295b8-cf94-4d9e-aec4-7959e3be5d79 --- soundin.cpp | 15 +++++++++------ soundout.cpp | 2 ++ 2 files changed, 11 insertions(+), 6 deletions(-) diff --git a/soundin.cpp b/soundin.cpp index 2bccbf7bd..0df8bc287 100644 --- a/soundin.cpp +++ b/soundin.cpp @@ -3,6 +3,7 @@ #include #include #include +#include #include #include "moc_soundin.cpp" @@ -49,11 +50,13 @@ void SoundInput::start(QAudioDeviceInfo const& device, int framesPerBuffer, Audi m_sink = sink; QAudioFormat format (device.preferredFormat()); + qDebug () << "Preferred audio input format:" << format; format.setChannelCount (AudioDevice::Mono == channel ? 1 : 2); format.setCodec ("audio/pcm"); format.setSampleRate (12000 * downSampleFactor); format.setSampleType (QAudioFormat::SignedInt); format.setSampleSize (16); + format.setByteOrder (QAudioFormat::Endian (QSysInfo::ByteOrder)); if (!format.isValid ()) { @@ -61,12 +64,12 @@ void SoundInput::start(QAudioDeviceInfo const& device, int framesPerBuffer, Audi return; } - // this function lies! - // if (!device.isFormatSupported (format)) - // { - // Q_EMIT error (tr ("Requested input audio format is not supported on device.")); - // return; - // } + if (!device.isFormatSupported (format)) + { + qDebug () << "Nearest supported audio format:" << device.nearestFormat (format); + Q_EMIT error (tr ("Requested input audio format is not supported on device.")); + return; + } m_stream.reset (new QAudioInput {device, format}); if (audioError ()) diff --git a/soundout.cpp b/soundout.cpp index d79929525..de89f17bd 100644 --- a/soundout.cpp +++ b/soundout.cpp @@ -3,6 +3,7 @@ #include #include #include +#include #include #include @@ -59,6 +60,7 @@ void SoundOutput::setFormat (QAudioDeviceInfo const& device, unsigned channels, format.setSampleRate (48000); format.setSampleType (QAudioFormat::SignedInt); format.setSampleSize (16); + format.setByteOrder (QAudioFormat::Endian (QSysInfo::ByteOrder)); if (!format.isValid ()) { Q_EMIT error (tr ("Requested output audio format is not valid."));