From 40d0c9996480a1f4570853ce980ffabd6e208673 Mon Sep 17 00:00:00 2001 From: Phil Taylor Date: Sat, 13 Mar 2021 09:50:43 +0000 Subject: [PATCH] Some code tidying in udpserver/audiohandler --- audiohandler.cpp | 28 +++++++++++----------------- udpserver.cpp | 16 +++++++++++----- 2 files changed, 22 insertions(+), 22 deletions(-) diff --git a/audiohandler.cpp b/audiohandler.cpp index da6a713..69691f9 100644 --- a/audiohandler.cpp +++ b/audiohandler.cpp @@ -776,30 +776,16 @@ bool audioHandler::init(const quint8 bits, const quint8 channels, const quint16 this->radioSampleRate = samplerate; this->radioChannels = channels; - //this->chunkSize = (INTERNAL_SAMPLE_RATE / 25) * (radioSampleBits / 8)/2; - // chunk size is always relative to Internal Sample Rate. this->chunkSize = (INTERNAL_SAMPLE_RATE / 25) * radioChannels; qDebug(logAudio()) << "Audio chunkSize: " << this->chunkSize; int resample_error=0; - if (isinput) { - resampler = wf_resampler_init(radioChannels, INTERNAL_SAMPLE_RATE, samplerate, resampleQuality, &resample_error); - } - else - { - resampler = wf_resampler_init(radioChannels, samplerate, INTERNAL_SAMPLE_RATE, resampleQuality, &resample_error); - } - - - wf_resampler_get_ratio(resampler, &ratioNum, &ratioDen); - - qDebug(logAudio()) << "wf_resampler_init() returned: " << resample_error << " ratioNum" << ratioNum << " ratioDen" << ratioDen << " input " << isinput; - - qDebug(logAudio()) << "Got audio port name: " << port; if (isInput) { + resampler = wf_resampler_init(radioChannels, INTERNAL_SAMPLE_RATE, samplerate, resampleQuality, &resample_error); + const auto deviceInfos = QAudioDeviceInfo::availableDevices(QAudio::AudioInput); for (const QAudioDeviceInfo& deviceInfo : deviceInfos) { if (deviceInfo.deviceName() == port) { @@ -815,6 +801,8 @@ bool audioHandler::init(const quint8 bits, const quint8 channels, const quint16 } else { + resampler = wf_resampler_init(radioChannels, samplerate, INTERNAL_SAMPLE_RATE, resampleQuality, &resample_error); + const auto deviceInfos = QAudioDeviceInfo::availableDevices(QAudio::AudioOutput); for (const QAudioDeviceInfo& deviceInfo : deviceInfos) { if (deviceInfo.deviceName() == port) { @@ -828,7 +816,13 @@ bool audioHandler::init(const quint8 bits, const quint8 channels, const quint16 isInitialized = setDevice(QAudioDeviceInfo::defaultOutputDevice()); } } - return isInitialized; + + wf_resampler_get_ratio(resampler, &ratioNum, &ratioDen); + qDebug(logAudio()) << "wf_resampler_init() returned: " << resample_error << " ratioNum" << ratioNum << " ratioDen" << ratioDen << " input " << isinput; + + qDebug(logAudio()) << "Got audio port name: " << port; + + return isInitialized; } diff --git a/udpserver.cpp b/udpserver.cpp index 609739b..7b65f2f 100644 --- a/udpserver.cpp +++ b/udpserver.cpp @@ -1086,11 +1086,13 @@ void udpServer::receiveAudioData(const audioPacket &d) return; } - +/// +/// Find all gaps in received packets and then send requests for them. +/// This will run every 100ms so out-of-sequence packets will not trigger a retransmit request. +/// +/// void udpServer::sendRetransmitRequest(CLIENT *c) { - // Find all gaps in received packets and then send requests for them. - // This will run every 100ms so out-of-sequence packets will not trigger a retransmit request. QMutexLocker locker(&mutex); @@ -1174,8 +1176,12 @@ void udpServer::sendRetransmitRequest(CLIENT *c) } -// This function is passed a pointer to the list of connection objects and a pointer to the object itself -// Needs to stop and delete all timers, remove the connection from the list and delete the connection. +/// +/// This function is passed a pointer to the list of connection objects and a pointer to the object itself +/// Needs to stop and delete all timers, remove the connection from the list and delete the connection. +/// +/// +/// void udpServer::deleteConnection(QList *l, CLIENT* c) { qDebug(logUdpServer()) << "Deleting connection to: " << c->ipAddress.toString() << ":" << QString::number(c->port);