From b78f613ef2fd9ca75cdf1496621ccb4554d4c3c7 Mon Sep 17 00:00:00 2001 From: Phil Taylor Date: Fri, 13 May 2022 16:09:26 +0100 Subject: [PATCH] Bit of code-tidying and minor fixes --- audiohandler.h | 2 +- pahandler.cpp | 54 +++++++++++++++++++++++--------------------------- pahandler.h | 2 ++ rthandler.h | 2 +- 4 files changed, 29 insertions(+), 31 deletions(-) diff --git a/audiohandler.h b/audiohandler.h index 47e6412..1f56b2b 100644 --- a/audiohandler.h +++ b/audiohandler.h @@ -82,7 +82,7 @@ private: bool isUnderrun = false; - bool isOverrun = true; + bool isOverrun = false; bool isInitialized=false; bool isReady = false; bool audioBuffered = false; diff --git a/pahandler.cpp b/pahandler.cpp index 6bd3875..646142f 100644 --- a/pahandler.cpp +++ b/pahandler.cpp @@ -217,7 +217,11 @@ bool paHandler::init(audioSetup setup) void paHandler::setVolume(unsigned char volume) { +#ifdef Q_OS_WIN + this->volume = audiopot[volume] * 5; +#else this->volume = audiopot[volume]; +#endif qInfo(logAudio()) << (setup.isinput ? "Input" : "Output") << "setVolume: " << volume << "(" << this->volume << ")"; } @@ -246,6 +250,18 @@ int paHandler::writeData(const void* inputBuffer, void* outputBuffer, packet.data.append((char*)inputBuffer, nFrames*inFormat.channelCount()*sizeof(float)); emit sendToConverter(packet); + if (status == paInputUnderflow) { + isUnderrun = true; + } + else if (status == paInputOverflow) { + isOverrun = true; + } + else + { + isUnderrun = false; + isOverrun = false; + } + return paContinue; } @@ -261,44 +277,24 @@ void paHandler::convertedOutput(audioPacket packet) { qDebug(logAudio()) << (setup.isinput ? "Input" : "Output") << "Error writing audio!"; } const PaStreamInfo* info = Pa_GetStreamInfo(audio); - - //currentLatency = packet.time.msecsTo(QTime::currentTime()) + (info->outputLatency * 1000); - currentLatency = (info->outputLatency * 1000); - - } - /* - currentLatency = packet.time.msecsTo(QTime::currentTime()) + (outFormat.durationForBytes(audioOutput->bufferSize() - audioOutput->bytesFree()) / 1000); - - if (audioDevice != Q_NULLPTR) { - if (audioDevice->write(packet.data) < packet.data.size()) { - qDebug(logAudio()) << (setup.isinput ? "Input" : "Output") << "Buffer full!"; - isOverrun = true; - } - else { - isOverrun = false; - } - if (lastReceived.msecsTo(QTime::currentTime()) > 100) { - qDebug(logAudio()) << (setup.isinput ? "Input" : "Output") << "Time since last audio packet" << lastReceived.msecsTo(QTime::currentTime()) << "Expected around" << setup.blockSize; - } - lastReceived = QTime::currentTime(); + currentLatency = packet.time.msecsTo(QTime::currentTime()) + (info->outputLatency * 1000); } - lastSentSeq = packet.seq; - - */ amplitude = packet.amplitude; - emit haveLevels(getAmplitude(), setup.latency, currentLatency, false, false); + emit haveLevels(getAmplitude(), setup.latency, currentLatency, isUnderrun, isOverrun); } } -void paHandler::convertedInput(audioPacket audio) +void paHandler::convertedInput(audioPacket packet) { - if (audio.data.size() > 0) { - emit haveAudioData(audio); - amplitude = audio.amplitude; - emit haveLevels(getAmplitude(), setup.latency, currentLatency, false,false); + if (packet.data.size() > 0) { + emit haveAudioData(packet); + amplitude = packet.amplitude; + const PaStreamInfo* info = Pa_GetStreamInfo(audio); + currentLatency = packet.time.msecsTo(QTime::currentTime()) + (info->inputLatency * 1000); + emit haveLevels(getAmplitude(), setup.latency, currentLatency, isUnderrun, isOverrun); } } diff --git a/pahandler.h b/pahandler.h index 5e311aa..f55a79f 100644 --- a/pahandler.h +++ b/pahandler.h @@ -88,6 +88,8 @@ private: QAudioFormat outFormat; audioConverter* converter = Q_NULLPTR; QThread* converterThread = Q_NULLPTR; + bool isUnderrun = false; + bool isOverrun = false; }; #endif // PAHANDLER_H diff --git a/rthandler.h b/rthandler.h index c78cf6c..e3461cc 100644 --- a/rthandler.h +++ b/rthandler.h @@ -106,7 +106,7 @@ private: QThread* converterThread = Q_NULLPTR; QByteArray arrayBuffer; bool isUnderrun = false; - bool isOverrun = true; + bool isOverrun = false; QMutex audioMutex; };