From 2b588ffce00ff690026bb2c11cb603d3d851b3b1 Mon Sep 17 00:00:00 2001 From: Phil Taylor Date: Mon, 11 Apr 2022 11:59:38 +0100 Subject: [PATCH] Switch back to using a timer. --- audiohandler.cpp | 12 +++++++++++- audiohandler.h | 1 + 2 files changed, 12 insertions(+), 1 deletion(-) diff --git a/audiohandler.cpp b/audiohandler.cpp index cfcf843..f404d5c 100644 --- a/audiohandler.cpp +++ b/audiohandler.cpp @@ -31,6 +31,12 @@ audioHandler::~audioHandler() audioOutput = Q_NULLPTR; } + if (audioTimer != Q_NULLPTR) { + audioTimer->stop(); + delete audioTimer; + audioTimer = Q_NULLPTR; + } + if (resampler != Q_NULLPTR) { speex_resampler_destroy(resampler); @@ -127,6 +133,9 @@ bool audioHandler::init(audioSetup setupIn) if (setup.isinput) { audioInput = new QAudioInput(setup.port, format, this); qDebug(logAudio()) << (setup.isinput ? "Input" : "Output") << "Starting audio timer"; + audioTimer = new QTimer(); + audioTimer->setTimerType(Qt::PreciseTimer); + connect(audioTimer, &QTimer::timeout, this, &audioHandler::getNextAudioChunk); connect(audioInput, SIGNAL(stateChanged(QAudio::State)), SLOT(stateChanged(QAudio::State))); } @@ -186,7 +195,8 @@ void audioHandler::start() if (setup.isinput) { audioDevice = audioInput->start(); connect(audioInput, &QAudioInput::destroyed, audioDevice, &QIODevice::deleteLater, Qt::UniqueConnection); - connect(audioDevice, &QIODevice::readyRead, this, &audioHandler::getNextAudioChunk); + //connect(audioDevice, &QIODevice::readyRead, this, &audioHandler::getNextAudioChunk); + audioTimer->start(setup.blockSize); } else { // Buffer size must be set before audio is started. diff --git a/audiohandler.h b/audiohandler.h index ace1e5f..128b270 100644 --- a/audiohandler.h +++ b/audiohandler.h @@ -115,6 +115,7 @@ private: QAudioOutput* audioOutput=Q_NULLPTR; QAudioInput* audioInput=Q_NULLPTR; QIODevice* audioDevice=Q_NULLPTR; + QTimer* audioTimer = Q_NULLPTR; QAudioFormat format; QAudioDeviceInfo deviceInfo; SpeexResamplerState* resampler = Q_NULLPTR;