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
This commit is contained in:
Bill Somerville 2017-03-21 13:34:01 +00:00
parent 39cf3e1b9a
commit 72c8eccf96
2 changed files with 11 additions and 6 deletions

View File

@ -3,6 +3,7 @@
#include <QAudioDeviceInfo> #include <QAudioDeviceInfo>
#include <QAudioFormat> #include <QAudioFormat>
#include <QAudioInput> #include <QAudioInput>
#include <QSysInfo>
#include <QDebug> #include <QDebug>
#include "moc_soundin.cpp" #include "moc_soundin.cpp"
@ -49,11 +50,13 @@ void SoundInput::start(QAudioDeviceInfo const& device, int framesPerBuffer, Audi
m_sink = sink; m_sink = sink;
QAudioFormat format (device.preferredFormat()); QAudioFormat format (device.preferredFormat());
qDebug () << "Preferred audio input format:" << format;
format.setChannelCount (AudioDevice::Mono == channel ? 1 : 2); format.setChannelCount (AudioDevice::Mono == channel ? 1 : 2);
format.setCodec ("audio/pcm"); format.setCodec ("audio/pcm");
format.setSampleRate (12000 * downSampleFactor); format.setSampleRate (12000 * downSampleFactor);
format.setSampleType (QAudioFormat::SignedInt); format.setSampleType (QAudioFormat::SignedInt);
format.setSampleSize (16); format.setSampleSize (16);
format.setByteOrder (QAudioFormat::Endian (QSysInfo::ByteOrder));
if (!format.isValid ()) if (!format.isValid ())
{ {
@ -61,12 +64,12 @@ void SoundInput::start(QAudioDeviceInfo const& device, int framesPerBuffer, Audi
return; return;
} }
// this function lies! if (!device.isFormatSupported (format))
// 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.")); Q_EMIT error (tr ("Requested input audio format is not supported on device."));
// return; return;
// } }
m_stream.reset (new QAudioInput {device, format}); m_stream.reset (new QAudioInput {device, format});
if (audioError ()) if (audioError ())

View File

@ -3,6 +3,7 @@
#include <QDateTime> #include <QDateTime>
#include <QAudioDeviceInfo> #include <QAudioDeviceInfo>
#include <QAudioOutput> #include <QAudioOutput>
#include <QSysInfo>
#include <qmath.h> #include <qmath.h>
#include <QDebug> #include <QDebug>
@ -59,6 +60,7 @@ void SoundOutput::setFormat (QAudioDeviceInfo const& device, unsigned channels,
format.setSampleRate (48000); format.setSampleRate (48000);
format.setSampleType (QAudioFormat::SignedInt); format.setSampleType (QAudioFormat::SignedInt);
format.setSampleSize (16); format.setSampleSize (16);
format.setByteOrder (QAudioFormat::Endian (QSysInfo::ByteOrder));
if (!format.isValid ()) if (!format.isValid ())
{ {
Q_EMIT error (tr ("Requested output audio format is not valid.")); Q_EMIT error (tr ("Requested output audio format is not valid."));