From f2e9a9000021e58fb87c09ea7c7b77b964d9df4f Mon Sep 17 00:00:00 2001 From: Phil Taylor Date: Fri, 20 May 2022 15:50:47 +0100 Subject: [PATCH 1/4] Support newer versions of rtaudio that don't generate exceptions --- rthandler.cpp | 14 +++++++++++++- 1 file changed, 13 insertions(+), 1 deletion(-) diff --git a/rthandler.cpp b/rthandler.cpp index b7438f5..af5e7cb 100644 --- a/rthandler.cpp +++ b/rthandler.cpp @@ -6,6 +6,7 @@ #include #endif +#define RT_EXCEPTION rtHandler::rtHandler(QObject* parent) { @@ -16,13 +17,17 @@ rtHandler::~rtHandler() { if (isInitialized) { +#ifdef RT_EXCEPTION try { +#endif audio->abortStream(); audio->closeStream(); +#ifdef RT_EXCEPTION } catch (RtAudioError& e) { qInfo(logAudio()) << "Error closing stream:" << aParams.deviceId << ":" << QString::fromStdString(e.getMessage()); } +#endif delete audio; } @@ -87,14 +92,17 @@ bool rtHandler::init(audioSetup setup) } aParams.firstChannel = 0; +#ifdef RT_EXCEPTION try { +#endif info = audio->getDeviceInfo(aParams.deviceId); +#ifdef RT_EXCEPTION } catch (RtAudioError e) { qInfo(logAudio()) << (setup.isinput ? "Input" : "Output") << "Device exception:" << aParams.deviceId << ":" << QString::fromStdString(e.getMessage()); goto errorHandler; } - +#endif if (info.probed) { qInfo(logAudio()) << (setup.isinput ? "Input" : "Output") << QString::fromStdString(info.name) << "(" << aParams.deviceId << ") successfully probed"; @@ -190,7 +198,9 @@ bool rtHandler::init(audioSetup setup) // Per channel chunk size. this->chunkSize = (outFormat.bytesForDuration(setup.blockSize * 1000) / (outFormat.sampleSize()/8) / outFormat.channelCount()); +#ifdef RT_EXCEPTION try { +#endif if (setup.isinput) { audio->openStream(NULL, &aParams, sampleFormat, outFormat.sampleRate(), &this->chunkSize, &staticWrite, this, &options); emit setupConverter(outFormat, inFormat, 7, setup.resampleQuality); @@ -205,12 +215,14 @@ bool rtHandler::init(audioSetup setup) isInitialized = true; qInfo(logAudio()) << (setup.isinput ? "Input" : "Output") << "device successfully opened"; qInfo(logAudio()) << (setup.isinput ? "Input" : "Output") << "detected latency:" << audio->getStreamLatency(); +#ifdef RT_EXCEPTION } catch (RtAudioError& e) { qInfo(logAudio()) << "Error opening:" << QString::fromStdString(e.getMessage()); // Try again? goto errorHandler; } +#endif } else { From c807c40bd25a7acc6d12ef6175e523606c09e220 Mon Sep 17 00:00:00 2001 From: Phil Taylor Date: Fri, 20 May 2022 18:24:28 +0100 Subject: [PATCH 2/4] Small .pro file update and cleanup --- wfserver.pro | 32 ++------------------------------ wfview.pro | 28 ++-------------------------- 2 files changed, 4 insertions(+), 56 deletions(-) diff --git a/wfserver.pro b/wfserver.pro index bbd4fee..5a854ec 100644 --- a/wfserver.pro +++ b/wfserver.pro @@ -22,7 +22,7 @@ CONFIG(debug, release|debug) { # For Debug builds only: QMAKE_CXXFLAGS += -faligned-new win32:DESTDIR = wfview-release - win32:LIBS += -L../portaudio/msvc/Win32/Debug/ -lportaudio_x86 + win32:LIBS += -L../portaudio/msvc/Win32/Debug/ -lportaudio_x86 -ole32 } else { # For Release builds only: linux:QMAKE_CXXFLAGS += -s @@ -31,7 +31,7 @@ CONFIG(debug, release|debug) { QMAKE_CXXFLAGS += -faligned-new linux:QMAKE_LFLAGS += -O2 -s win32:DESTDIR = wfview-debug - win32:LIBS += -L../portaudio/msvc/Win32/Release/ -lportaudio_x86 + win32:LIBS += -L../portaudio/msvc/Win32/Release/ -lportaudio_x86 -lole32 } # RTAudio defines @@ -76,34 +76,6 @@ equals(QT_ARCH, x86_64): DEFINES += EIGEN_VECTORIZE_SSE3 DEFINES += PREFIX=\\\"$$PREFIX\\\" -# Choose audio system, uses QTMultimedia if both are commented out. -# DEFINES += RTAUDIO -# DEFINES += PORTAUDIO - -contains(DEFINES, RTAUDIO) { - # RTAudio defines - win32:DEFINES += __WINDOWS_WASAPI__ - #win32:DEFINES += __WINDOWS_DS__ # Requires DirectSound libraries - linux:DEFINES += __LINUX_ALSA__ - #linux:DEFINES += __LINUX_OSS__ - #linux:DEFINES += __LINUX_PULSE__ - macx:DEFINES += __MACOSX_CORE__ - win32:SOURCES += ../rtaudio/RTAudio.cpp - win32:HEADERS += ../rtaudio/RTAUdio.h - !linux:INCLUDEPATH += ../rtaudio - linux:LIBS += -lpulse -lpulse-simple -lrtaudio -lpthread -} - -contains(DEFINES, PORTAUDIO) { - CONFIG(debug, release|debug) { - win32:LIBS += -L../portaudio/msvc/Win32/Debug/ -lportaudio_x86 - } else { - win32:LIBS += -L../portaudio/msvc/Win32/Release/ -lportaudio_x86 - } - win32:INCLUDEPATH += ../portaudio/include - !win32:LIBS += -lportaudio -} - macx:INCLUDEPATH += /usr/local/include /opt/local/include macx:LIBS += -L/usr/local/lib -L/opt/local/lib diff --git a/wfview.pro b/wfview.pro index 63d0391..c9cd8aa 100644 --- a/wfview.pro +++ b/wfview.pro @@ -19,7 +19,7 @@ CONFIG(debug, release|debug) { # For Debug builds only: QMAKE_CXXFLAGS += -faligned-new win32:DESTDIR = wfview-release - win32:LIBS += -L../portaudio/msvc/Win32/Debug/ -lportaudio_x86 + win32:LIBS += -L../portaudio/msvc/Win32/Debug/ -lportaudio_x86 -lole32 } else { # For Release builds only: linux:QMAKE_CXXFLAGS += -s @@ -28,7 +28,7 @@ CONFIG(debug, release|debug) { QMAKE_CXXFLAGS += -faligned-new linux:QMAKE_LFLAGS += -O2 -s win32:DESTDIR = wfview-debug - win32:LIBS += -L../portaudio/msvc/Win32/Release/ -lportaudio_x86 + win32:LIBS += -L../portaudio/msvc/Win32/Release/ -lportaudio_x86 -lole32 } # RTAudio defines @@ -77,30 +77,6 @@ isEmpty(PREFIX) { DEFINES += PREFIX=\\\"$$PREFIX\\\" -contains(DEFINES, RTAUDIO) { - # RTAudio defines - win32:DEFINES += __WINDOWS_WASAPI__ - #win32:DEFINES += __WINDOWS_DS__ # Requires DirectSound libraries - linux:DEFINES += __LINUX_ALSA__ - #linux:DEFINES += __LINUX_OSS__ - #linux:DEFINES += __LINUX_PULSE__ - macx:DEFINES += __MACOSX_CORE__ - win32:SOURCES += ../rtaudio/RTAudio.cpp - win32:HEADERS += ../rtaudio/RTAUdio.h - !linux:INCLUDEPATH += ../rtaudio - linux:LIBS += -lpulse -lpulse-simple -lrtaudio -lpthread -} - -contains(DEFINES, PORTAUDIO) { - CONFIG(debug, release|debug) { - win32:LIBS += -L../portaudio/msvc/Win32/Debug/ -lportaudio_x86 - } else { - win32:LIBS += -L../portaudio/msvc/Win32/Release/ -lportaudio_x86 - } - win32:INCLUDEPATH += ../portaudio/include - !win32:LIBS += -lportaudio -} - macx:INCLUDEPATH += /usr/local/include /opt/local/include macx:LIBS += -L/usr/local/lib -L/opt/local/lib From 5cb81b412f328f0315ef158db72e67cf229f8eb7 Mon Sep 17 00:00:00 2001 From: Phil Taylor Date: Tue, 24 May 2022 10:08:18 +0100 Subject: [PATCH 3/4] Try to quit wfserver on ctrl-c --- main.cpp | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/main.cpp b/main.cpp index 2dc33e0..3583a0a 100644 --- a/main.cpp +++ b/main.cpp @@ -33,7 +33,7 @@ bool debugMode=false; Q_UNUSED(sig) qDebug() << "Exiting via SIGNAL"; if (w!=Q_NULLPTR) w->deleteLater(); - qApp->quit(); + QCoreApplication::quit(); #ifdef Q_OS_WIN return true; @@ -177,6 +177,8 @@ int main(int argc, char *argv[]) SetConsoleCtrlHandler((PHANDLER_ROUTINE)cleanup, TRUE); #else signal(SIGINT, cleanup); + signal(SIG_TERM, cleanup); + signal(SIG_CLOSE, cleanup); #endif w = new servermain(serialPortCL, hostCL, settingsFile); #else From 06017148dd7d5ed3bc548b9af2fbdc3d27d0bb50 Mon Sep 17 00:00:00 2001 From: Phil Taylor Date: Tue, 24 May 2022 10:13:44 +0100 Subject: [PATCH 4/4] Update main.cpp --- main.cpp | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/main.cpp b/main.cpp index 3583a0a..8e945ae 100644 --- a/main.cpp +++ b/main.cpp @@ -177,8 +177,8 @@ int main(int argc, char *argv[]) SetConsoleCtrlHandler((PHANDLER_ROUTINE)cleanup, TRUE); #else signal(SIGINT, cleanup); - signal(SIG_TERM, cleanup); - signal(SIG_CLOSE, cleanup); + signal(SIGTERM, cleanup); + signal(SIGKILL, cleanup); #endif w = new servermain(serialPortCL, hostCL, settingsFile); #else