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 <QAudioFormat>
#include <QAudioInput>
#include <QSysInfo>
#include <QDebug>
#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 ())

View File

@ -3,6 +3,7 @@
#include <QDateTime>
#include <QAudioDeviceInfo>
#include <QAudioOutput>
#include <QSysInfo>
#include <qmath.h>
#include <QDebug>
@ -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."));