From 67927b0d56d704215faac71b33229e87768f17fc Mon Sep 17 00:00:00 2001 From: Phil Taylor Date: Sun, 6 Jun 2021 17:56:48 +0100 Subject: [PATCH] Fix to allow rtaudio to compile again --- audiohandler.cpp | 16 ++++--- audiohandler.h | 7 ++- rxaudiohandler.cpp | 104 --------------------------------------------- rxaudiohandler.h | 47 -------------------- wfview.pro | 4 ++ wfview.vcxproj | 8 ++-- 6 files changed, 24 insertions(+), 162 deletions(-) delete mode 100644 rxaudiohandler.cpp delete mode 100644 rxaudiohandler.h diff --git a/audiohandler.cpp b/audiohandler.cpp index 12b7da5..38a95ff 100644 --- a/audiohandler.cpp +++ b/audiohandler.cpp @@ -101,8 +101,8 @@ bool audioHandler::init(audioSetup setupIn) audio = new RtAudio(RtAudio::Api::MACOSX_CORE); #endif - if (port > 0) { - aParams.deviceId = port; + if (setup.port > 0) { + aParams.deviceId = setup.port; } else if (setup.isinput) { aParams.deviceId = audio->getDefaultInputDevice(); @@ -166,7 +166,7 @@ bool audioHandler::init(audioSetup setupIn) qInfo(logAudio()) << " chunkSize: " << chunkSize; try { if (setup.isinput) { - audio->openStream(NULL, &aParams, RTAUDIO_SINT16, nativeSampleRate, &this->chunkSize, &staticWrite, this, &options); + audio->openStream(NULL, &aParams, RTAUDIO_SINT16, this->nativeSampleRate, &this->chunkSize, &staticWrite, this, &options); } else { audio->openStream(&aParams, NULL, RTAUDIO_SINT16, this->nativeSampleRate, &this->chunkSize, &staticRead, this, &options); @@ -243,14 +243,16 @@ bool audioHandler::init(audioSetup setupIn) qInfo(logAudio()) << (setup.isinput ? "Input" : "Output") << "thread id" << QThread::currentThreadId(); - +#if !defined (RTAUDIO) && !defined(PORTAUDIO) if (isInitialized) { this->start(); } +#endif return isInitialized; } +#if !defined (RTAUDIO) && !defined(PORTAUDIO) void audioHandler::start() { qInfo(logAudio()) << (setup.isinput ? "Input" : "Output") << "start() running"; @@ -271,7 +273,7 @@ void audioHandler::start() audioOutput->start(this); } } - +#endif void audioHandler::setVolume(unsigned char volume) { @@ -625,6 +627,8 @@ void audioHandler::getNextAudioChunk(QByteArray& ret) } +#if !defined (RTAUDIO) && !defined(PORTAUDIO) + qint64 audioHandler::bytesAvailable() const { return 0; @@ -693,6 +697,6 @@ void audioHandler::stop() } } - +#endif diff --git a/audiohandler.h b/audiohandler.h index 3407a79..36993a5 100644 --- a/audiohandler.h +++ b/audiohandler.h @@ -9,9 +9,10 @@ #include #if defined(RTAUDIO) -#include "RtAudio.h" +#include "rtaudio/RtAudio.h" #elif defined (PORTAUDIO) #include "portaudio.h" +#error "PORTAUDIO is not currently supported" #else #include #include @@ -83,6 +84,7 @@ public: int getLatency(); +#if !defined (RTAUDIO) && !defined(PORTAUDIO) bool setDevice(QAudioDeviceInfo deviceInfo); void start(); @@ -90,6 +92,7 @@ public: void stop(); qint64 bytesAvailable() const; bool isSequential() const; +#endif void getNextAudioChunk(QByteArray &data); @@ -100,8 +103,10 @@ public slots: void incomingAudio(const audioPacket data); private slots: +#if !defined (RTAUDIO) && !defined(PORTAUDIO) void notified(); void stateChanged(QAudio::State state); +#endif signals: void audioMessage(QString message); diff --git a/rxaudiohandler.cpp b/rxaudiohandler.cpp deleted file mode 100644 index 4cc665f..0000000 --- a/rxaudiohandler.cpp +++ /dev/null @@ -1,104 +0,0 @@ -#include "rxaudiohandler.h" - -rxAudioHandler::rxAudioHandler() -{ - -} - -rxAudioHandler::~rxAudioHandler() -{ - audio->stop(); - delete audio; -} - -void rxAudioHandler::process() -{ - qDebug() << "rxAudio Handler created."; -} - -void rxAudioHandler::setup(const QAudioFormat format, const quint16 bufferSize, const bool isUlaw) -{ - this->format = format; - this->bufferSize = bufferSize; - this->isUlaw = isUlaw; - audio = new QAudioOutput(format); - audio->setBufferSize(bufferSize); - device = audio->start(); -} - - -void rxAudioHandler::incomingAudio(const QByteArray data) -{ - QMutexLocker locker(&mutex); - if (isUlaw) { - device->write(uLawDecode(data)); - } - else { - device->write(data, data.length()); - } -} - -void rxAudioHandler::changeBufferSize(const quint16 newSize) -{ - QMutexLocker locker(&mutex); - qDebug() << "Changing buffer size to: " << newSize << " from " << audio->bufferSize(); - audio->stop(); - audio->setBufferSize(newSize); - device = audio->start(); -} - -void rxAudioHandler::getBufferSize() -{ - emit sendBufferSize(audio->bufferSize()); -} - - - -QByteArray rxAudioHandler::uLawDecode(const QByteArray in) -{ - static const qint16 ulaw_decode[256] = { - -32124, -31100, -30076, -29052, -28028, -27004, -25980, -24956, - -23932, -22908, -21884, -20860, -19836, -18812, -17788, -16764, - -15996, -15484, -14972, -14460, -13948, -13436, -12924, -12412, - -11900, -11388, -10876, -10364, -9852, -9340, -8828, -8316, - -7932, -7676, -7420, -7164, -6908, -6652, -6396, -6140, - -5884, -5628, -5372, -5116, -4860, -4604, -4348, -4092, - -3900, -3772, -3644, -3516, -3388, -3260, -3132, -3004, - -2876, -2748, -2620, -2492, -2364, -2236, -2108, -1980, - -1884, -1820, -1756, -1692, -1628, -1564, -1500, -1436, - -1372, -1308, -1244, -1180, -1116, -1052, -988, -924, - -876, -844, -812, -780, -748, -716, -684, -652, - -620, -588, -556, -524, -492, -460, -428, -396, - -372, -356, -340, -324, -308, -292, -276, -260, - -244, -228, -212, -196, -180, -164, -148, -132, - -120, -112, -104, -96, -88, -80, -72, -64, - -56, -48, -40, -32, -24, -16, -8, 0, - 32124, 31100, 30076, 29052, 28028, 27004, 25980, 24956, - 23932, 22908, 21884, 20860, 19836, 18812, 17788, 16764, - 15996, 15484, 14972, 14460, 13948, 13436, 12924, 12412, - 11900, 11388, 10876, 10364, 9852, 9340, 8828, 8316, - 7932, 7676, 7420, 7164, 6908, 6652, 6396, 6140, - 5884, 5628, 5372, 5116, 4860, 4604, 4348, 4092, - 3900, 3772, 3644, 3516, 3388, 3260, 3132, 3004, - 2876, 2748, 2620, 2492, 2364, 2236, 2108, 1980, - 1884, 1820, 1756, 1692, 1628, 1564, 1500, 1436, - 1372, 1308, 1244, 1180, 1116, 1052, 988, 924, - 876, 844, 812, 780, 748, 716, 684, 652, - 620, 588, 556, 524, 492, 460, 428, 396, - 372, 356, 340, 324, 308, 292, 276, 260, - 244, 228, 212, 196, 180, 164, 148, 132, - 120, 112, 104, 96, 88, 80, 72, 64, - 56, 48, 40, 32, 24, 16, 8, 0 }; - - QByteArray out; - foreach(qint8 const temp, in) - { - qint16 decoded = ulaw_decode[0]; - if (temp != 0) { - decoded = ulaw_decode[static_cast(temp)]; - } - out.append(static_cast(decoded & 0xff)); - out.append(static_cast(decoded >> 8 & 0xff)); - } - return out; -} diff --git a/rxaudiohandler.h b/rxaudiohandler.h deleted file mode 100644 index fa4a05e..0000000 --- a/rxaudiohandler.h +++ /dev/null @@ -1,47 +0,0 @@ -#ifndef RXAUDIOHANDLER_H -#define RXAUDIOHANDLER_H - -#include - -#include -#include -#include - -#include - -class rxAudioHandler : public QObject -{ - Q_OBJECT - -public: - rxAudioHandler(); - ~rxAudioHandler(); - - -public slots: - void process(); - void setup(const QAudioFormat format, const quint16 bufferSize, const bool isulaw); - - void incomingAudio(const QByteArray data); - void changeBufferSize(const quint16 newSize); - void getBufferSize(); - -signals: - void audioMessage(QString message); - void sendBufferSize(quint16 newSize); - - -private: - QByteArray uLawDecode(const QByteArray in); - - QAudioOutput* audio; - QAudioFormat format; - QIODevice* device; - int bufferSize; - QMutex mutex; - bool isUlaw; - - -}; - -#endif // RXAUDIOHANDLER_H diff --git a/wfview.pro b/wfview.pro index 67ee5e5..59862f2 100644 --- a/wfview.pro +++ b/wfview.pro @@ -35,6 +35,10 @@ DEFINES += QCUSTOMPLOT_COMPILE_LIBRARY DEFINES += OUTSIDE_SPEEX DEFINES += RANDOM_PREFIX=wf +# Choose audio system, uses QTMultimedia if both are commented out. +DEFINES += RTAUDIO +# DEFINES += PORTAUDIO + # RTAudio defines win32:DEFINES += __WINDOWS_WASAPI__ #win32:DEFINES += __WINDOWS_DS__ # Requires DirectSound libraries diff --git a/wfview.vcxproj b/wfview.vcxproj index 33c7455..ce4ee99 100644 --- a/wfview.vcxproj +++ b/wfview.vcxproj @@ -57,7 +57,7 @@ Sync release\ MaxSpeed - _WINDOWS;UNICODE;_UNICODE;WIN32;_ENABLE_EXTENDED_ALIGNED_STORAGE;QT_DEPRECATED_WARNINGS;QCUSTOMPLOT_COMPILE_LIBRARY;OUTSIDE_SPEEX;RANDOM_PREFIX=wf;__WINDOWS_WASAPI__;GITSHORT="24ce16b";HOST="wfview.org";UNAME="build";NDEBUG;QT_NO_DEBUG;%(PreprocessorDefinitions) + _WINDOWS;UNICODE;_UNICODE;WIN32;_ENABLE_EXTENDED_ALIGNED_STORAGE;QT_DEPRECATED_WARNINGS;QCUSTOMPLOT_COMPILE_LIBRARY;OUTSIDE_SPEEX;RANDOM_PREFIX=wf;RTAUDIO;__WINDOWS_WASAPI__;GITSHORT="9a0ea32";HOST="wfview.org";UNAME="build";NDEBUG;QT_NO_DEBUG;%(PreprocessorDefinitions) false MultiThreadedDLL @@ -85,7 +85,7 @@ 0 - _WINDOWS;UNICODE;_UNICODE;WIN32;_ENABLE_EXTENDED_ALIGNED_STORAGE;QT_DEPRECATED_WARNINGS;QCUSTOMPLOT_COMPILE_LIBRARY;OUTSIDE_SPEEX;RANDOM_PREFIX=wf;__WINDOWS_WASAPI__;GITSHORT=\"24ce16b\";HOST=\"wfview.org\";UNAME=\"build\";NDEBUG;QT_NO_DEBUG;QT_MULTIMEDIA_LIB;QT_PRINTSUPPORT_LIB;QT_WIDGETS_LIB;QT_GUI_LIB;QT_SERIALPORT_LIB;QT_NETWORK_LIB;QT_CORE_LIB;%(PreprocessorDefinitions) + _WINDOWS;UNICODE;_UNICODE;WIN32;_ENABLE_EXTENDED_ALIGNED_STORAGE;QT_DEPRECATED_WARNINGS;QCUSTOMPLOT_COMPILE_LIBRARY;OUTSIDE_SPEEX;RANDOM_PREFIX=wf;RTAUDIO;__WINDOWS_WASAPI__;GITSHORT=\"9a0ea32\";HOST=\"wfview.org\";UNAME=\"build\";NDEBUG;QT_NO_DEBUG;QT_MULTIMEDIA_LIB;QT_PRINTSUPPORT_LIB;QT_WIDGETS_LIB;QT_GUI_LIB;QT_SERIALPORT_LIB;QT_NETWORK_LIB;QT_CORE_LIB;%(PreprocessorDefinitions) msvc./$(Configuration)/moc_predefs.hMoc'ing %(Identity)...output$(Configuration)moc_%(Filename).cppdefaultRcc'ing %(Identity)...$(Configuration)qrc_%(Filename).cppUic'ing %(Identity)...$(ProjectDir)ui_%(Filename).h @@ -99,7 +99,7 @@ Sync debug\ Disabled - _WINDOWS;UNICODE;_UNICODE;WIN32;_ENABLE_EXTENDED_ALIGNED_STORAGE;QT_DEPRECATED_WARNINGS;QCUSTOMPLOT_COMPILE_LIBRARY;OUTSIDE_SPEEX;RANDOM_PREFIX=wf;__WINDOWS_WASAPI__;GITSHORT="24ce16b";HOST="wfview.org";UNAME="build";%(PreprocessorDefinitions) + _WINDOWS;UNICODE;_UNICODE;WIN32;_ENABLE_EXTENDED_ALIGNED_STORAGE;QT_DEPRECATED_WARNINGS;QCUSTOMPLOT_COMPILE_LIBRARY;OUTSIDE_SPEEX;RANDOM_PREFIX=wf;RTAUDIO;__WINDOWS_WASAPI__;GITSHORT="9a0ea32";HOST="wfview.org";UNAME="build";%(PreprocessorDefinitions) false MultiThreadedDebugDLL true @@ -124,7 +124,7 @@ 0 - _WINDOWS;UNICODE;_UNICODE;WIN32;_ENABLE_EXTENDED_ALIGNED_STORAGE;QT_DEPRECATED_WARNINGS;QCUSTOMPLOT_COMPILE_LIBRARY;OUTSIDE_SPEEX;RANDOM_PREFIX=wf;__WINDOWS_WASAPI__;GITSHORT=\"24ce16b\";HOST=\"wfview.org\";UNAME=\"build\";QT_MULTIMEDIA_LIB;QT_PRINTSUPPORT_LIB;QT_WIDGETS_LIB;QT_GUI_LIB;QT_SERIALPORT_LIB;QT_NETWORK_LIB;QT_CORE_LIB;_DEBUG;%(PreprocessorDefinitions) + _WINDOWS;UNICODE;_UNICODE;WIN32;_ENABLE_EXTENDED_ALIGNED_STORAGE;QT_DEPRECATED_WARNINGS;QCUSTOMPLOT_COMPILE_LIBRARY;OUTSIDE_SPEEX;RANDOM_PREFIX=wf;RTAUDIO;__WINDOWS_WASAPI__;GITSHORT=\"9a0ea32\";HOST=\"wfview.org\";UNAME=\"build\";QT_MULTIMEDIA_LIB;QT_PRINTSUPPORT_LIB;QT_WIDGETS_LIB;QT_GUI_LIB;QT_SERIALPORT_LIB;QT_NETWORK_LIB;QT_CORE_LIB;_DEBUG;%(PreprocessorDefinitions) msvc./$(Configuration)/moc_predefs.hMoc'ing %(Identity)...output$(Configuration)moc_%(Filename).cppdefaultRcc'ing %(Identity)...$(Configuration)qrc_%(Filename).cppUic'ing %(Identity)...$(ProjectDir)ui_%(Filename).h