From 366ff0e1c3f06f4a511d8173f83c9c29e6a74787 Mon Sep 17 00:00:00 2001 From: f4exb Date: Wed, 6 Apr 2016 09:33:29 +0200 Subject: [PATCH] UDP source plugin: corrected UDP audio input --- plugins/channel/udpsrc/readme.md | 2 +- plugins/channel/udpsrc/udpsrc.cpp | 35 ++++++++++++++++--------------- plugins/channel/udpsrc/udpsrc.h | 3 +++ 3 files changed, 22 insertions(+), 18 deletions(-) diff --git a/plugins/channel/udpsrc/readme.md b/plugins/channel/udpsrc/readme.md index aa2250e26..b49cf8d68 100644 --- a/plugins/channel/udpsrc/readme.md +++ b/plugins/channel/udpsrc/readme.md @@ -70,7 +70,7 @@ This is the maximum expected FM deviation in Hz for NFM demodulated samples. The

12: Boost

-Amplifies the signal from the input passband signal before processing. The level of amplification is the log2 of the amplification factor applied therefore it varies from 0 dB (0) to +30 dB (3) in 10 dB steps. +Amplifies the input passband signal before processing. The level of amplification is the log2 of the amplification factor applied therefore it varies from 0 dB (0) to +30 dB (3) in 10 dB steps.

13: Audio volume

diff --git a/plugins/channel/udpsrc/udpsrc.cpp b/plugins/channel/udpsrc/udpsrc.cpp index 2167f97a1..672b0842a 100644 --- a/plugins/channel/udpsrc/udpsrc.cpp +++ b/plugins/channel/udpsrc/udpsrc.cpp @@ -42,6 +42,7 @@ UDPSrc::UDPSrc(MessageQueue* uiMessageQueue, UDPSrcGUI* udpSrcGUI, SampleSink* s m_udpBuffer = new UDPSink(this, udpBLockSampleSize, m_udpPort); m_udpBufferMono = new UDPSink(this, udpBLockSampleSize, m_udpPort); m_audioSocket = new QUdpSocket(this); + m_udpAudioBuf = new char[m_udpAudioPayloadSize]; m_audioBuffer.resize(1<<9); m_audioBufferFill = 0; @@ -73,7 +74,7 @@ UDPSrc::UDPSrc(MessageQueue* uiMessageQueue, UDPSrcGUI* udpSrcGUI, SampleSink* s if (m_audioSocket->bind(QHostAddress::LocalHost, m_audioPort)) { qDebug("UDPSrc::UDPSrc: bind audio socket to port %d", m_audioPort); - connect(m_audioSocket, SIGNAL(readyRead()), this, SLOT(audioReadyRead())); + connect(m_audioSocket, SIGNAL(readyRead()), this, SLOT(audioReadyRead()), Qt::QueuedConnection); } else { @@ -88,6 +89,7 @@ UDPSrc::~UDPSrc() delete m_audioSocket; delete m_udpBuffer; delete m_udpBufferMono; + delete[] m_udpAudioBuf; if (UDPFilter) delete UDPFilter; if (m_audioActive) DSPEngine::instance()->removeAudioSink(&m_audioFifo); } @@ -349,9 +351,10 @@ bool UDPSrc::handleMessage(const Message& cmd) delete m_audioSocket; m_audioSocket = new QUdpSocket(this); - if (m_audioSocket->bind(QHostAddress::Any, m_audioPort)) + if (m_audioSocket->bind(QHostAddress::LocalHost, m_audioPort)) { - connect(m_audioSocket, SIGNAL(readyRead()), this, SLOT(audioReadyRead())); + connect(m_audioSocket, SIGNAL(readyRead()), this, SLOT(audioReadyRead()), Qt::QueuedConnection); + qDebug("UDPSrc::handleMessage: audio socket bound to port %d", m_audioPort); } else { @@ -406,24 +409,22 @@ bool UDPSrc::handleMessage(const Message& cmd) void UDPSrc::audioReadyRead() { - QByteArray buffer; - while (m_audioSocket->hasPendingDatagrams()) { - buffer.resize(m_audioSocket->pendingDatagramSize()); - m_audioSocket->readDatagram(buffer.data(), buffer.size(), 0, 0); - //qDebug("UDPSrc::audioReadyRead: %d", buffer.size()); + qint64 pendingDataSize = m_audioSocket->pendingDatagramSize(); + qint64 udpReadBytes = m_audioSocket->readDatagram(m_udpAudioBuf, pendingDataSize, 0, 0); + //qDebug("UDPSrc::audioReadyRead: %lld", udpReadBytes); if (m_audioActive) { if (m_audioStereo) { - for (int i = 0; i < buffer.size() - 3; i += 4) + for (int i = 0; i < udpReadBytes - 3; i += 4) { - qint16 l_sample = (qint16) *(&buffer.data()[i]); - qint16 r_sample = (qint16) *(&buffer.data()[i+2]); - m_audioBuffer[m_audioBufferFill].l = l_sample * 10 * m_volume; - m_audioBuffer[m_audioBufferFill].r = r_sample * 10 * m_volume; + qint16 l_sample = (qint16) *(&m_udpAudioBuf[i]); + qint16 r_sample = (qint16) *(&m_udpAudioBuf[i+2]); + m_audioBuffer[m_audioBufferFill].l = l_sample * m_volume; + m_audioBuffer[m_audioBufferFill].r = r_sample * m_volume; ++m_audioBufferFill; if (m_audioBufferFill >= m_audioBuffer.size()) @@ -441,11 +442,11 @@ void UDPSrc::audioReadyRead() } else { - for (int i = 0; i < buffer.size() - 1; i += 2) + for (int i = 0; i < udpReadBytes - 1; i += 2) { - qint16 sample = (qint16) *(&buffer.data()[i]); - m_audioBuffer[m_audioBufferFill].l = sample * 10 * m_volume; - m_audioBuffer[m_audioBufferFill].r = sample * 10 * m_volume; + qint16 sample = (qint16) *(&m_udpAudioBuf[i]); + m_audioBuffer[m_audioBufferFill].l = sample * m_volume; + m_audioBuffer[m_audioBufferFill].r = sample * m_volume; ++m_audioBufferFill; if (m_audioBufferFill >= m_audioBuffer.size()) diff --git a/plugins/channel/udpsrc/udpsrc.h b/plugins/channel/udpsrc/udpsrc.h index e4ba5afe3..28348be2f 100644 --- a/plugins/channel/udpsrc/udpsrc.h +++ b/plugins/channel/udpsrc/udpsrc.h @@ -245,6 +245,9 @@ protected: quint32 m_nextSSBId; quint32 m_nextS16leId; + char *m_udpAudioBuf; + static const int m_udpAudioPayloadSize = 8192; //!< UDP audio samples buffer. No UDP block on Earth is larger than this + PhaseDiscriminators m_phaseDiscri; QMutex m_settingsMutex;