1
0
mirror of https://github.com/f4exb/sdrangel.git synced 2024-11-26 17:58:43 -05:00

UDP source plugin: corrected UDP audio input

This commit is contained in:
f4exb 2016-04-06 09:33:29 +02:00
parent 9ea1c8f71d
commit 366ff0e1c3
3 changed files with 22 additions and 18 deletions

View File

@ -70,7 +70,7 @@ This is the maximum expected FM deviation in Hz for NFM demodulated samples. The
<h3>12: Boost</h3> <h3>12: Boost</h3>
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.
<h3>13: Audio volume</h3> <h3>13: Audio volume</h3>

View File

@ -42,6 +42,7 @@ UDPSrc::UDPSrc(MessageQueue* uiMessageQueue, UDPSrcGUI* udpSrcGUI, SampleSink* s
m_udpBuffer = new UDPSink<Sample>(this, udpBLockSampleSize, m_udpPort); m_udpBuffer = new UDPSink<Sample>(this, udpBLockSampleSize, m_udpPort);
m_udpBufferMono = new UDPSink<FixReal>(this, udpBLockSampleSize, m_udpPort); m_udpBufferMono = new UDPSink<FixReal>(this, udpBLockSampleSize, m_udpPort);
m_audioSocket = new QUdpSocket(this); m_audioSocket = new QUdpSocket(this);
m_udpAudioBuf = new char[m_udpAudioPayloadSize];
m_audioBuffer.resize(1<<9); m_audioBuffer.resize(1<<9);
m_audioBufferFill = 0; m_audioBufferFill = 0;
@ -73,7 +74,7 @@ UDPSrc::UDPSrc(MessageQueue* uiMessageQueue, UDPSrcGUI* udpSrcGUI, SampleSink* s
if (m_audioSocket->bind(QHostAddress::LocalHost, m_audioPort)) if (m_audioSocket->bind(QHostAddress::LocalHost, m_audioPort))
{ {
qDebug("UDPSrc::UDPSrc: bind audio socket to port %d", 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 else
{ {
@ -88,6 +89,7 @@ UDPSrc::~UDPSrc()
delete m_audioSocket; delete m_audioSocket;
delete m_udpBuffer; delete m_udpBuffer;
delete m_udpBufferMono; delete m_udpBufferMono;
delete[] m_udpAudioBuf;
if (UDPFilter) delete UDPFilter; if (UDPFilter) delete UDPFilter;
if (m_audioActive) DSPEngine::instance()->removeAudioSink(&m_audioFifo); if (m_audioActive) DSPEngine::instance()->removeAudioSink(&m_audioFifo);
} }
@ -349,9 +351,10 @@ bool UDPSrc::handleMessage(const Message& cmd)
delete m_audioSocket; delete m_audioSocket;
m_audioSocket = new QUdpSocket(this); 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 else
{ {
@ -406,24 +409,22 @@ bool UDPSrc::handleMessage(const Message& cmd)
void UDPSrc::audioReadyRead() void UDPSrc::audioReadyRead()
{ {
QByteArray buffer;
while (m_audioSocket->hasPendingDatagrams()) while (m_audioSocket->hasPendingDatagrams())
{ {
buffer.resize(m_audioSocket->pendingDatagramSize()); qint64 pendingDataSize = m_audioSocket->pendingDatagramSize();
m_audioSocket->readDatagram(buffer.data(), buffer.size(), 0, 0); qint64 udpReadBytes = m_audioSocket->readDatagram(m_udpAudioBuf, pendingDataSize, 0, 0);
//qDebug("UDPSrc::audioReadyRead: %d", buffer.size()); //qDebug("UDPSrc::audioReadyRead: %lld", udpReadBytes);
if (m_audioActive) if (m_audioActive)
{ {
if (m_audioStereo) 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 l_sample = (qint16) *(&m_udpAudioBuf[i]);
qint16 r_sample = (qint16) *(&buffer.data()[i+2]); qint16 r_sample = (qint16) *(&m_udpAudioBuf[i+2]);
m_audioBuffer[m_audioBufferFill].l = l_sample * 10 * m_volume; m_audioBuffer[m_audioBufferFill].l = l_sample * m_volume;
m_audioBuffer[m_audioBufferFill].r = r_sample * 10 * m_volume; m_audioBuffer[m_audioBufferFill].r = r_sample * m_volume;
++m_audioBufferFill; ++m_audioBufferFill;
if (m_audioBufferFill >= m_audioBuffer.size()) if (m_audioBufferFill >= m_audioBuffer.size())
@ -441,11 +442,11 @@ void UDPSrc::audioReadyRead()
} }
else 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]); qint16 sample = (qint16) *(&m_udpAudioBuf[i]);
m_audioBuffer[m_audioBufferFill].l = sample * 10 * m_volume; m_audioBuffer[m_audioBufferFill].l = sample * m_volume;
m_audioBuffer[m_audioBufferFill].r = sample * 10 * m_volume; m_audioBuffer[m_audioBufferFill].r = sample * m_volume;
++m_audioBufferFill; ++m_audioBufferFill;
if (m_audioBufferFill >= m_audioBuffer.size()) if (m_audioBufferFill >= m_audioBuffer.size())

View File

@ -245,6 +245,9 @@ protected:
quint32 m_nextSSBId; quint32 m_nextSSBId;
quint32 m_nextS16leId; 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; PhaseDiscriminators m_phaseDiscri;
QMutex m_settingsMutex; QMutex m_settingsMutex;