diff --git a/audiohandler.cpp b/audiohandler.cpp index d6f1172..968ec39 100644 --- a/audiohandler.cpp +++ b/audiohandler.cpp @@ -166,7 +166,12 @@ bool audioHandler::init(audioSetup setupIn) qInfo(logAudio()) << (setup.isinput ? "Input" : "Output") << "thread id" << QThread::currentThreadId(); + underTimer = new QTimer(); + underTimer->setSingleShot(true); + connect(underTimer, &QTimer::timeout, this, &audioHandler::clearUnderrun); + this->start(); + return true; } @@ -571,15 +576,15 @@ void audioHandler::stateChanged(QAudio::State state) case QAudio::IdleState: { isUnderrun = true; + if (underTimer->isActive()) { + underTimer->stop(); + } break; } case QAudio::ActiveState: { //qDebug(logAudio()) << (setup.isinput ? "Input" : "Output") << "Audio started!"; - if (underTimer == Q_NULLPTR) { - underTimer = new QTimer(); - underTimer->setSingleShot(true); - connect(underTimer, &QTimer::timeout, this, &audioHandler::clearUnderrun); + if (!underTimer->isActive()) { underTimer->start(500); } break; @@ -601,6 +606,5 @@ void audioHandler::stateChanged(QAudio::State state) void audioHandler::clearUnderrun() { isUnderrun = false; - delete underTimer; - underTimer = Q_NULLPTR; + underTimer->stop(); } \ No newline at end of file diff --git a/audiohandler.h b/audiohandler.h index e10aeac..e0584e8 100644 --- a/audiohandler.h +++ b/audiohandler.h @@ -142,7 +142,7 @@ private: OpusEncoder* encoder=Q_NULLPTR; OpusDecoder* decoder=Q_NULLPTR; - QTimer * underTimer=Q_NULLPTR; + QTimer* underTimer; };