Support newer versions of rtaudio that don't generate exceptions

merge-requests/9/merge
Phil Taylor 2022-05-20 15:50:47 +01:00
rodzic 079a50980d
commit f2e9a90000
1 zmienionych plików z 13 dodań i 1 usunięć

Wyświetl plik

@ -6,6 +6,7 @@
#include <objbase.h> #include <objbase.h>
#endif #endif
#define RT_EXCEPTION
rtHandler::rtHandler(QObject* parent) rtHandler::rtHandler(QObject* parent)
{ {
@ -16,13 +17,17 @@ rtHandler::~rtHandler()
{ {
if (isInitialized) { if (isInitialized) {
#ifdef RT_EXCEPTION
try { try {
#endif
audio->abortStream(); audio->abortStream();
audio->closeStream(); audio->closeStream();
#ifdef RT_EXCEPTION
} }
catch (RtAudioError& e) { catch (RtAudioError& e) {
qInfo(logAudio()) << "Error closing stream:" << aParams.deviceId << ":" << QString::fromStdString(e.getMessage()); qInfo(logAudio()) << "Error closing stream:" << aParams.deviceId << ":" << QString::fromStdString(e.getMessage());
} }
#endif
delete audio; delete audio;
} }
@ -87,14 +92,17 @@ bool rtHandler::init(audioSetup setup)
} }
aParams.firstChannel = 0; aParams.firstChannel = 0;
#ifdef RT_EXCEPTION
try { try {
#endif
info = audio->getDeviceInfo(aParams.deviceId); info = audio->getDeviceInfo(aParams.deviceId);
#ifdef RT_EXCEPTION
} }
catch (RtAudioError e) { catch (RtAudioError e) {
qInfo(logAudio()) << (setup.isinput ? "Input" : "Output") << "Device exception:" << aParams.deviceId << ":" << QString::fromStdString(e.getMessage()); qInfo(logAudio()) << (setup.isinput ? "Input" : "Output") << "Device exception:" << aParams.deviceId << ":" << QString::fromStdString(e.getMessage());
goto errorHandler; goto errorHandler;
} }
#endif
if (info.probed) if (info.probed)
{ {
qInfo(logAudio()) << (setup.isinput ? "Input" : "Output") << QString::fromStdString(info.name) << "(" << aParams.deviceId << ") successfully 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. // Per channel chunk size.
this->chunkSize = (outFormat.bytesForDuration(setup.blockSize * 1000) / (outFormat.sampleSize()/8) / outFormat.channelCount()); this->chunkSize = (outFormat.bytesForDuration(setup.blockSize * 1000) / (outFormat.sampleSize()/8) / outFormat.channelCount());
#ifdef RT_EXCEPTION
try { try {
#endif
if (setup.isinput) { if (setup.isinput) {
audio->openStream(NULL, &aParams, sampleFormat, outFormat.sampleRate(), &this->chunkSize, &staticWrite, this, &options); audio->openStream(NULL, &aParams, sampleFormat, outFormat.sampleRate(), &this->chunkSize, &staticWrite, this, &options);
emit setupConverter(outFormat, inFormat, 7, setup.resampleQuality); emit setupConverter(outFormat, inFormat, 7, setup.resampleQuality);
@ -205,12 +215,14 @@ bool rtHandler::init(audioSetup setup)
isInitialized = true; isInitialized = true;
qInfo(logAudio()) << (setup.isinput ? "Input" : "Output") << "device successfully opened"; qInfo(logAudio()) << (setup.isinput ? "Input" : "Output") << "device successfully opened";
qInfo(logAudio()) << (setup.isinput ? "Input" : "Output") << "detected latency:" << audio->getStreamLatency(); qInfo(logAudio()) << (setup.isinput ? "Input" : "Output") << "detected latency:" << audio->getStreamLatency();
#ifdef RT_EXCEPTION
} }
catch (RtAudioError& e) { catch (RtAudioError& e) {
qInfo(logAudio()) << "Error opening:" << QString::fromStdString(e.getMessage()); qInfo(logAudio()) << "Error opening:" << QString::fromStdString(e.getMessage());
// Try again? // Try again?
goto errorHandler; goto errorHandler;
} }
#endif
} }
else else
{ {