From ff23b6eb269b51a868d9259520c15890d071b4c1 Mon Sep 17 00:00:00 2001 From: f4exb Date: Fri, 25 Aug 2017 10:32:18 +0200 Subject: [PATCH] UDP sink plugin: implemented mono/stereo input toggle --- plugins/channeltx/udpsink/udpsink.cpp | 63 +++--------------------- plugins/channeltx/udpsink/udpsink.h | 20 ++++++-- plugins/channeltx/udpsink/udpsinkgui.cpp | 62 +++++++---------------- plugins/channeltx/udpsink/udpsinkgui.ui | 17 +------ 4 files changed, 40 insertions(+), 122 deletions(-) diff --git a/plugins/channeltx/udpsink/udpsink.cpp b/plugins/channeltx/udpsink/udpsink.cpp index 86779347f..044d2c5b5 100644 --- a/plugins/channeltx/udpsink/udpsink.cpp +++ b/plugins/channeltx/udpsink/udpsink.cpp @@ -144,20 +144,10 @@ void UDPSink::modulateSample() m_modSample.imag(0.0f); } } - else if ((m_running.m_sampleFormat == FormatNFMMono) || (m_running.m_sampleFormat == FormatNFM)) + else if (m_running.m_sampleFormat == FormatNFM) { FixReal t; - Sample s; - - if (m_running.m_sampleFormat == FormatNFMMono) - { - m_udpHandler.readSample(t); - } - else - { - m_udpHandler.readSample(s); - t = (s.m_real + s.m_imag) / 2; - } + readMonoSample(t); m_inMovingAverage.feed((t*t)/1073741824.0); m_inMagsq = m_inMovingAverage.average(); @@ -177,10 +167,10 @@ void UDPSink::modulateSample() m_modSample.imag(0.0f); } } - else if (m_running.m_sampleFormat == FormatAMMono) + else if (m_running.m_sampleFormat == FormatAM) { FixReal t; - m_udpHandler.readSample(t); + readMonoSample(t); m_inMovingAverage.feed((t*t)/1073741824.0); m_inMagsq = m_inMovingAverage.average(); @@ -198,14 +188,14 @@ void UDPSink::modulateSample() m_modSample.imag(0.0f); } } - else if ((m_running.m_sampleFormat == FormatLSBMono) || (m_running.m_sampleFormat == FormatUSBMono)) + else if ((m_running.m_sampleFormat == FormatLSB) || (m_running.m_sampleFormat == FormatUSB)) { FixReal t; Complex c, ci; fftfilt::cmplx *filtered; int n_out = 0; - m_udpHandler.readSample(t); + readMonoSample(t); m_inMovingAverage.feed((t*t)/1073741824.0); m_inMagsq = m_inMovingAverage.average(); @@ -216,47 +206,6 @@ void UDPSink::modulateSample() ci.real((t / 32768.0f) * m_running.m_gain); ci.imag(0.0f); - n_out = m_SSBFilter->runSSB(ci, &filtered, (m_running.m_sampleFormat == FormatUSBMono)); - - if (n_out > 0) - { - memcpy((void *) m_SSBFilterBuffer, (const void *) filtered, n_out*sizeof(Complex)); - m_SSBFilterBufferIndex = 0; - } - - c = m_SSBFilterBuffer[m_SSBFilterBufferIndex]; - m_modSample.real(m_SSBFilterBuffer[m_SSBFilterBufferIndex].real() * 32768.0f); - m_modSample.imag(m_SSBFilterBuffer[m_SSBFilterBufferIndex].imag() * 32768.0f); - m_SSBFilterBufferIndex++; - - calculateLevel(m_modSample); - } - else - { - m_modSample.real(0.0f); - m_modSample.imag(0.0f); - } - } - else if ((m_running.m_sampleFormat == FormatLSB) || (m_running.m_sampleFormat == FormatUSB)) - { - Sample s; - Complex c, ci; - fftfilt::cmplx *filtered; - int n_out = 0; - - m_udpHandler.readSample(s); - - uint64_t magsq = s.m_real * s.m_real + s.m_imag * s.m_imag; - m_inMovingAverage.feed(magsq/1073741824.0); - m_inMagsq = m_inMovingAverage.average(); - - calculateSquelch(m_inMagsq); - - if (m_squelchOpen) - { - ci.real((s.m_real / 32768.0f) * m_running.m_gain); - ci.imag((s.m_imag / 32768.0f) * m_running.m_gain); - n_out = m_SSBFilter->runSSB(ci, &filtered, (m_running.m_sampleFormat == FormatUSB)); if (n_out > 0) diff --git a/plugins/channeltx/udpsink/udpsink.h b/plugins/channeltx/udpsink/udpsink.h index 84e1a13bc..9b542dd7a 100644 --- a/plugins/channeltx/udpsink/udpsink.h +++ b/plugins/channeltx/udpsink/udpsink.h @@ -38,12 +38,9 @@ public: enum SampleFormat { FormatS16LE, FormatNFM, - FormatNFMMono, FormatLSB, FormatUSB, - FormatLSBMono, - FormatUSBMono, - FormatAMMono, + FormatAM, FormatNone }; @@ -385,6 +382,21 @@ private: m_squelchCloseCount = 0; } } + + inline void readMonoSample(FixReal& t) + { + Sample s; + + if (m_running.m_stereoInput) + { + m_udpHandler.readSample(s); + t = (s.m_real + s.m_imag) / 2; + } + else + { + m_udpHandler.readSample(t); + } + } }; diff --git a/plugins/channeltx/udpsink/udpsinkgui.cpp b/plugins/channeltx/udpsink/udpsinkgui.cpp index 160632106..173a9141c 100644 --- a/plugins/channeltx/udpsink/udpsinkgui.cpp +++ b/plugins/channeltx/udpsink/udpsinkgui.cpp @@ -127,34 +127,10 @@ bool UDPSinkGUI::deserialize(const QByteArray& data) m_channelMarker.setCenterFrequency(s32tmp); d.readS32(3, &s32tmp, UDPSink::FormatS16LE); - switch(s32tmp) { - case UDPSink::FormatS16LE: - ui->sampleFormat->setCurrentIndex(0); - break; - case UDPSink::FormatNFM: - ui->sampleFormat->setCurrentIndex(1); - break; - case UDPSink::FormatNFMMono: - ui->sampleFormat->setCurrentIndex(2); - break; - case UDPSink::FormatLSB: - ui->sampleFormat->setCurrentIndex(3); - break; - case UDPSink::FormatUSB: - ui->sampleFormat->setCurrentIndex(4); - break; - case UDPSink::FormatLSBMono: - ui->sampleFormat->setCurrentIndex(5); - break; - case UDPSink::FormatUSBMono: - ui->sampleFormat->setCurrentIndex(6); - break; - case UDPSink::FormatAMMono: - ui->sampleFormat->setCurrentIndex(7); - break; - default: - ui->sampleFormat->setCurrentIndex(0); - break; + if (s32tmp < (int) UDPSink::FormatNone) { + ui->sampleFormat->setCurrentIndex(s32tmp); + } else { + ui->sampleFormat->setCurrentIndex(((int) UDPSink::FormatNone) - 1); } d.readReal(4, &realtmp, 48000); ui->sampleRate->setText(QString("%1").arg(realtmp, 0)); @@ -362,38 +338,34 @@ void UDPSinkGUI::applySettings(bool force) case 0: sampleFormat = UDPSink::FormatS16LE; ui->fmDeviation->setEnabled(false); + ui->stereoInput->setChecked(true); + ui->stereoInput->setEnabled(false); break; case 1: sampleFormat = UDPSink::FormatNFM; ui->fmDeviation->setEnabled(true); + ui->stereoInput->setEnabled(true); break; case 2: - sampleFormat = UDPSink::FormatNFMMono; - ui->fmDeviation->setEnabled(true); - break; - case 3: sampleFormat = UDPSink::FormatLSB; ui->fmDeviation->setEnabled(false); + ui->stereoInput->setEnabled(true); break; - case 4: + case 3: sampleFormat = UDPSink::FormatUSB; ui->fmDeviation->setEnabled(false); + ui->stereoInput->setEnabled(true); break; - case 5: - sampleFormat = UDPSink::FormatLSBMono; - ui->fmDeviation->setEnabled(false); - break; - case 6: - sampleFormat = UDPSink::FormatUSBMono; - ui->fmDeviation->setEnabled(false); - break; - case 7: - sampleFormat = UDPSink::FormatAMMono; + case 4: + sampleFormat = UDPSink::FormatAM; ui->fmDeviation->setEnabled(false); + ui->stereoInput->setEnabled(true); break; default: sampleFormat = UDPSink::FormatS16LE; ui->fmDeviation->setEnabled(false); + ui->stereoInput->setChecked(true); + ui->stereoInput->setEnabled(false); break; } @@ -445,13 +417,13 @@ void UDPSinkGUI::on_deltaFrequency_changed(qint64 value) void UDPSinkGUI::on_sampleFormat_currentIndexChanged(int index) { - if ((index == (int) UDPSink::FormatNFM) || (index == (int) UDPSink::FormatNFMMono)) { + if ((index == (int) UDPSink::FormatNFM)) { ui->fmDeviation->setEnabled(true); } else { ui->fmDeviation->setEnabled(false); } - if (index == (int) UDPSink::FormatAMMono) { + if (index == (int) UDPSink::FormatAM) { ui->amModPercent->setEnabled(true); } else { ui->amModPercent->setEnabled(false); diff --git a/plugins/channeltx/udpsink/udpsinkgui.ui b/plugins/channeltx/udpsink/udpsinkgui.ui index 6108a542e..4f169d306 100644 --- a/plugins/channeltx/udpsink/udpsinkgui.ui +++ b/plugins/channeltx/udpsink/udpsinkgui.ui @@ -275,11 +275,6 @@ S16LE NFM - - - S16LE NFM Mono - - S16LE LSB @@ -292,17 +287,7 @@ - S16LE LSB Mono - - - - - S16LE USB Mono - - - - - S16LE AM Mono + S16LE AM