From 491b8a6d3340c0f1f2724b548258a74ff4d3f796 Mon Sep 17 00:00:00 2001 From: f4exb Date: Sun, 21 Jan 2018 10:57:04 +0100 Subject: [PATCH] Replaced hardcoded bit scaling literals by defines --- devices/plutosdr/deviceplutosdrbox.cpp | 3 +- plugins/channelrx/chanalyzer/chanalyzer.cpp | 7 ++-- plugins/channelrx/chanalyzerng/chanalyzerng.h | 6 +-- .../chanalyzerng/chanalyzernggui.cpp | 2 - plugins/channelrx/demodam/amdemod.cpp | 1 - plugins/channelrx/demodam/amdemod.h | 7 ++-- plugins/channelrx/demodatv/atvdemod.cpp | 3 +- plugins/channelrx/demodatv/atvdemodgui.cpp | 2 +- plugins/channelrx/demodbfm/bfmdemod.cpp | 6 +-- plugins/channelrx/demoddsd/dsddemod.cpp | 6 ++- plugins/channelrx/demodlora/lorademod.cpp | 2 +- plugins/channelrx/demodnfm/nfmdemod.cpp | 2 +- plugins/channelrx/demodssb/ssbdemod.cpp | 7 ++-- plugins/channelrx/demodwfm/wfmdemod.cpp | 3 +- plugins/channelrx/tcpsrc/tcpsrc.cpp | 6 +-- plugins/channelrx/udpsrc/udpsrc.cpp | 20 ++++----- plugins/channeltx/modam/ammod.cpp | 4 +- plugins/channeltx/modatv/atvmod.cpp | 4 +- plugins/channeltx/modatv/atvmodsettings.cpp | 2 +- plugins/channeltx/modnfm/nfmmod.cpp | 8 ++-- plugins/channeltx/modssb/ssbmod.cpp | 42 +++++-------------- plugins/channeltx/modwfm/wfmmod.cpp | 8 ++-- plugins/channeltx/udpsink/udpsink.cpp | 22 +++++----- .../plutosdroutput/plutosdroutput.cpp | 1 - sdrbase/dsp/dsptypes.h | 8 +++- sdrgui/dsp/scopevis.cpp | 6 +-- sdrgui/dsp/scopevismulti.h | 4 +- sdrgui/dsp/scopevisng.h | 4 +- sdrgui/dsp/spectrumvis.cpp | 4 +- 29 files changed, 89 insertions(+), 111 deletions(-) diff --git a/devices/plutosdr/deviceplutosdrbox.cpp b/devices/plutosdr/deviceplutosdrbox.cpp index f792f28d2..0ac0c7203 100644 --- a/devices/plutosdr/deviceplutosdrbox.cpp +++ b/devices/plutosdr/deviceplutosdrbox.cpp @@ -22,6 +22,7 @@ #include #include +#include "dsp/dsptypes.h" #include "dsp/wfir.h" #include "deviceplutosdr.h" #include "deviceplutosdrbox.h" @@ -638,7 +639,7 @@ void DevicePlutoSDRBox::formatFIRCoefficients(std::ostringstream& ostr, uint32_t WFIR::BasicFIR(fcoeffs, nbTaps, WFIR::LPF, normalizedBW, 0.0, normalizedBW < 0.2 ? WFIR::wtHAMMING : WFIR::wtBLACKMAN_HARRIS, 0.0); for (unsigned int i = 0; i < nbTaps; i++) { - ostr << (int16_t) (fcoeffs[i] * 32768.0) << ", " << (int16_t) (fcoeffs[i] * 32768.0) << std::endl; + ostr << (int16_t) (fcoeffs[i] * SDR_SCALEF) << ", " << (int16_t) (fcoeffs[i] * SDR_SCALEF) << std::endl; } delete[] fcoeffs; diff --git a/plugins/channelrx/chanalyzer/chanalyzer.cpp b/plugins/channelrx/chanalyzer/chanalyzer.cpp index b26308f38..cb4e627bd 100644 --- a/plugins/channelrx/chanalyzer/chanalyzer.cpp +++ b/plugins/channelrx/chanalyzer/chanalyzer.cpp @@ -92,7 +92,6 @@ void ChannelAnalyzer::feed(const SampleVector::const_iterator& begin, const Samp for(SampleVector::const_iterator it = begin; it < end; ++it) { - //Complex c(it->real() / 32768.0f, it->imag() / 32768.0f); Complex c(it->real(), it->imag()); c *= m_nco.nextIQ(); @@ -115,16 +114,16 @@ void ChannelAnalyzer::feed(const SampleVector::const_iterator& begin, const Samp if (!(m_undersampleCount++ & decim_mask)) { m_sum /= decim; - m_magsq = (m_sum.real() * m_sum.real() + m_sum.imag() * m_sum.imag())/ (1<<30); + Real re = m_sum.real() / SDR_SCALED; + Real im = m_sum.imag() / SDR_SCALED; + m_magsq = re*re + im*im; if (m_ssb & !m_usb) { // invert spectrum for LSB - //m_sampleBuffer.push_back(Sample(m_sum.imag() * 32768.0, m_sum.real() * 32768.0)); m_sampleBuffer.push_back(Sample(m_sum.imag(), m_sum.real())); } else { - //m_sampleBuffer.push_back(Sample(m_sum.real() * 32768.0, m_sum.imag() * 32768.0)); m_sampleBuffer.push_back(Sample(m_sum.real(), m_sum.imag())); } diff --git a/plugins/channelrx/chanalyzerng/chanalyzerng.h b/plugins/channelrx/chanalyzerng/chanalyzerng.h index c80c02ca7..5734ee235 100644 --- a/plugins/channelrx/chanalyzerng/chanalyzerng.h +++ b/plugins/channelrx/chanalyzerng/chanalyzerng.h @@ -229,16 +229,16 @@ private: if (!(m_undersampleCount++ & (decim - 1))) // counter LSB bit mask for decimation by 2^(m_scaleLog2 - 1) { m_sum /= decim; - m_magsq = (m_sum.real() * m_sum.real() + m_sum.imag() * m_sum.imag())/ (1<<30); + Real re = m_sum.real() / SDR_SCALED; + Real im = m_sum.imag() / SDR_SCALED; + m_magsq = re*re + im*im; if (m_running.m_ssb & !m_usb) { // invert spectrum for LSB - //m_sampleBuffer.push_back(Sample(m_sum.imag() * 32768.0, m_sum.real() * 32768.0)); m_sampleBuffer.push_back(Sample(m_sum.imag(), m_sum.real())); } else { - //m_sampleBuffer.push_back(Sample(m_sum.real() * 32768.0, m_sum.imag() * 32768.0)); m_sampleBuffer.push_back(Sample(m_sum.real(), m_sum.imag())); } diff --git a/plugins/channelrx/chanalyzerng/chanalyzernggui.cpp b/plugins/channelrx/chanalyzerng/chanalyzernggui.cpp index 6bc2a3561..b290020ef 100644 --- a/plugins/channelrx/chanalyzerng/chanalyzernggui.cpp +++ b/plugins/channelrx/chanalyzerng/chanalyzernggui.cpp @@ -464,8 +464,6 @@ bool ChannelAnalyzerNGGUI::setNewFinalRate(int spanLog2) } m_spanLog2 = spanLog2; - //m_rate = 48000 / (1<getInputSampleRate() / (1<real() / 32768.0, it->imag() / 32768.0); Complex c(it->real(), it->imag()); c *= m_nco.nextIQ(); diff --git a/plugins/channelrx/demodam/amdemod.h b/plugins/channelrx/demodam/amdemod.h index b6cc056e3..01ebe092a 100644 --- a/plugins/channelrx/demodam/amdemod.h +++ b/plugins/channelrx/demodam/amdemod.h @@ -161,8 +161,9 @@ private: void processOneSample(Complex &ci) { - Real magsq = ci.real() * ci.real() + ci.imag() * ci.imag(); - magsq /= (1<<30); + Real re = ci.real() / SDR_SCALED; + Real im = ci.imag() / SDR_SCALED; + Real magsq = re*re + im*im; m_movingAverage.feed(magsq); m_magsq = m_movingAverage.average(); m_magsqSum += magsq; @@ -209,7 +210,7 @@ private: Real attack = (m_squelchCount - 0.05f * m_settings.m_audioSampleRate) / (0.05f * m_settings.m_audioSampleRate); sample = demod * attack * 2048 * m_settings.m_volume; - if (m_settings.m_copyAudioToUDP) m_udpBufferAudio->write(demod * attack * 32768); + if (m_settings.m_copyAudioToUDP) m_udpBufferAudio->write(demod * attack * SDR_SCALEF); m_squelchOpen = true; } diff --git a/plugins/channelrx/demodatv/atvdemod.cpp b/plugins/channelrx/demodatv/atvdemod.cpp index 1635e6c7d..d1acb0355 100644 --- a/plugins/channelrx/demodatv/atvdemod.cpp +++ b/plugins/channelrx/demodatv/atvdemod.cpp @@ -338,8 +338,7 @@ void ATVDemod::demod(Complex& c) magSq = fltI*fltI + fltQ*fltQ; m_objMagSqAverage.feed(magSq); fltNorm = sqrt(magSq); - fltVal = fltNorm / (1<<15); - //fltVal = magSq / (1<<30); + fltVal = fltNorm / SDR_SCALEF; //********** Mini and Maxi Amplitude tracking ********** diff --git a/plugins/channelrx/demodatv/atvdemodgui.cpp b/plugins/channelrx/demodatv/atvdemodgui.cpp index 365ccb329..586f79d52 100644 --- a/plugins/channelrx/demodatv/atvdemodgui.cpp +++ b/plugins/channelrx/demodatv/atvdemodgui.cpp @@ -474,7 +474,7 @@ void ATVDemodGUI::tick() if (m_atvDemod) { m_objMagSqAverage.feed(m_atvDemod->getMagSq()); - double magSqDB = CalcDb::dbPower(m_objMagSqAverage.average() / (1<<30)); + double magSqDB = CalcDb::dbPower(m_objMagSqAverage.average() / (SDR_SCALED*SDR_SCALED)); ui->channePowerText->setText(tr("%1 dB").arg(magSqDB, 0, 'f', 1)); if (m_atvDemod->getBFOLocked()) { diff --git a/plugins/channelrx/demodbfm/bfmdemod.cpp b/plugins/channelrx/demodbfm/bfmdemod.cpp index 5dc2f6075..4f1a54774 100644 --- a/plugins/channelrx/demodbfm/bfmdemod.cpp +++ b/plugins/channelrx/demodbfm/bfmdemod.cpp @@ -125,7 +125,7 @@ void BFMDemod::feed(const SampleVector::const_iterator& begin, const SampleVecto for (SampleVector::const_iterator it = begin; it != end; ++it) { - Complex c(it->real() / 32768.0f, it->imag() / 32768.0f); + Complex c(it->real() / SDR_SCALEF, it->imag() / SDR_SCALEF); c *= m_nco.nextIQ(); rf_out = m_rfFilter->runFilt(c, &rf); // filter RF before demod @@ -163,7 +163,7 @@ void BFMDemod::feed(const SampleVector::const_iterator& begin, const SampleVecto if (!m_settings.m_showPilot) { - m_sampleBuffer.push_back(Sample(demod * (1<<15), 0.0)); + m_sampleBuffer.push_back(Sample(demod * SDR_SCALEF, 0.0)); } if (m_settings.m_rdsActive) @@ -197,7 +197,7 @@ void BFMDemod::feed(const SampleVector::const_iterator& begin, const SampleVecto if (m_settings.m_showPilot) { - m_sampleBuffer.push_back(Sample(m_pilotPLLSamples[1] * (1<<15), 0.0)); // debug 38 kHz pilot + m_sampleBuffer.push_back(Sample(m_pilotPLLSamples[1] * SDR_SCALEF, 0.0)); // debug 38 kHz pilot } if (m_settings.m_lsbStereo) diff --git a/plugins/channelrx/demoddsd/dsddemod.cpp b/plugins/channelrx/demoddsd/dsddemod.cpp index a02c8c637..451e21497 100644 --- a/plugins/channelrx/demoddsd/dsddemod.cpp +++ b/plugins/channelrx/demoddsd/dsddemod.cpp @@ -128,7 +128,9 @@ void DSDDemod::feed(const SampleVector::const_iterator& begin, const SampleVecto { qint16 sample, delayedSample; - Real magsq = ((ci.real()*ci.real() + ci.imag()*ci.imag())) / (1<<30); + Real re = ci.real() / SDR_SCALED; + Real im = ci.imag() / SDR_SCALED; + Real magsq = re*re + im*im; m_movingAverage.feed(magsq); m_magsqSum += magsq; @@ -140,7 +142,7 @@ void DSDDemod::feed(const SampleVector::const_iterator& begin, const SampleVecto m_magsqCount++; - Real demod = 32768.0f * m_phaseDiscri.phaseDiscriminator(ci) * m_settings.m_demodGain; + Real demod = SDR_SCALEF * m_phaseDiscri.phaseDiscriminator(ci) * m_settings.m_demodGain; m_sampleCount++; // AF processing diff --git a/plugins/channelrx/demodlora/lorademod.cpp b/plugins/channelrx/demodlora/lorademod.cpp index fe2b96d0f..cd30f01a6 100644 --- a/plugins/channelrx/demodlora/lorademod.cpp +++ b/plugins/channelrx/demodlora/lorademod.cpp @@ -261,7 +261,7 @@ void LoRaDemod::feed(const SampleVector::const_iterator& begin, const SampleVect for(SampleVector::const_iterator it = begin; it < end; ++it) { - Complex c(it->real() / 32768.0f, it->imag() / 32768.0f); + Complex c(it->real() / SDR_SCALEF, it->imag() / SDR_SCALEF); c *= m_nco.nextIQ(); if(m_interpolator.decimate(&m_sampleDistanceRemain, c, &ci)) diff --git a/plugins/channelrx/demodnfm/nfmdemod.cpp b/plugins/channelrx/demodnfm/nfmdemod.cpp index bf2c1965d..7fdcb54eb 100644 --- a/plugins/channelrx/demodnfm/nfmdemod.cpp +++ b/plugins/channelrx/demodnfm/nfmdemod.cpp @@ -153,7 +153,7 @@ void NFMDemod::feed(const SampleVector::const_iterator& begin, const SampleVecto Real demod = m_phaseDiscri.phaseDiscriminatorDelta(ci, magsqRaw, deviation); - Real magsq = magsqRaw / (1<<30); + Real magsq = magsqRaw / (SDR_SCALED*SDR_SCALED); m_movingAverage.feed(magsq); m_magsqSum += magsq; diff --git a/plugins/channelrx/demodssb/ssbdemod.cpp b/plugins/channelrx/demodssb/ssbdemod.cpp index 581608fb3..44f880e98 100644 --- a/plugins/channelrx/demodssb/ssbdemod.cpp +++ b/plugins/channelrx/demodssb/ssbdemod.cpp @@ -77,7 +77,7 @@ SSBDemod::SSBDemod(DeviceSourceAPI *deviceAPI) : m_magsqPeak = 0.0f; m_magsqCount = 0; - m_agc.setClampMax(32768.0*32768.0); + m_agc.setClampMax(SDR_SCALED*SDR_SCALED); m_agc.setClamping(m_agcClamping); SSBFilter = new fftfilt(m_LowCutoff / m_audioSampleRate, m_Bandwidth / m_audioSampleRate, ssbFftLen); @@ -154,7 +154,6 @@ void SSBDemod::feed(const SampleVector::const_iterator& begin, const SampleVecto for(SampleVector::const_iterator it = begin; it < end; ++it) { - //Complex c(it->real() / 32768.0, it->imag() / 32768.0); Complex c(it->real(), it->imag()); c *= m_nco.nextIQ(); @@ -187,7 +186,7 @@ void SSBDemod::feed(const SampleVector::const_iterator& begin, const SampleVecto { Real avgr = m_sum.real() / decim; Real avgi = m_sum.imag() / decim; - m_magsq = (avgr * avgr + avgi * avgi) / (1<<30); + m_magsq = (avgr * avgr + avgi * avgi) / (SDR_SCALED*SDR_SCALED); m_magsqSum += m_magsq; @@ -428,7 +427,7 @@ void SSBDemod::applySettings(const SSBDemodSettings& settings, bool force) { int agcNbSamples = 48 * (1<real() / 32768.0f, it->imag() / 32768.0f); Complex c(it->real(), it->imag()); c *= m_nco.nextIQ(); @@ -113,7 +112,7 @@ void WFMDemod::feed(const SampleVector::const_iterator& begin, const SampleVecto for (int i = 0 ; i < rf_out; i++) { demod = m_phaseDiscri.phaseDiscriminatorDelta(rf[i], msq, fmDev); - Real magsq = msq / (1<<30); + Real magsq = msq / (SDR_SCALED*SDR_SCALED); m_movingAverage.feed(magsq); m_magsqSum += magsq; diff --git a/plugins/channelrx/tcpsrc/tcpsrc.cpp b/plugins/channelrx/tcpsrc/tcpsrc.cpp index a92a043cc..017bdd6d9 100644 --- a/plugins/channelrx/tcpsrc/tcpsrc.cpp +++ b/plugins/channelrx/tcpsrc/tcpsrc.cpp @@ -97,17 +97,15 @@ void TCPSrc::feed(const SampleVector::const_iterator& begin, const SampleVector: m_settingsMutex.lock(); // Rtl-Sdr uses full 16-bit scale; FCDPP does not - //int rescale = 32768 * (1 << m_boost); int rescale = (1 << m_volume); for(SampleVector::const_iterator it = begin; it < end; ++it) { - //Complex c(it->real() / 32768.0f, it->imag() / 32768.0f); Complex c(it->real(), it->imag()); c *= m_nco.nextIQ(); if(m_interpolator.decimate(&m_sampleDistanceRemain, c, &ci)) { - m_magsq = ((ci.real()*ci.real() + ci.imag()*ci.imag())*rescale*rescale) / (1<<30); + m_magsq = ((ci.real()*ci.real() + ci.imag()*ci.imag())*rescale*rescale) / (SDR_SCALED*SDR_SCALED); m_sampleBuffer.push_back(Sample(ci.real() * rescale, ci.imag() * rescale)); m_sampleDistanceRemain += m_inputSampleRate / m_outputSampleRate; } @@ -145,7 +143,7 @@ void TCPSrc::feed(const SampleVector::const_iterator& begin, const SampleVector: if((m_sampleFormat == TCPSrcSettings::FormatNFM) && (m_ssbSockets.count() > 0)) { for(SampleVector::const_iterator it = m_sampleBuffer.begin(); it != m_sampleBuffer.end(); ++it) { - Complex cj(it->real() / 32768.0f, it->imag() / 32768.0f); + Complex cj(it->real() / SDR_SCALEF, it->imag() / SDR_SCALEF); // An FFT filter here is overkill, but was already set up for SSB int n_out = TCPFilter->runFilt(cj, &sideband); if (n_out) { diff --git a/plugins/channelrx/udpsrc/udpsrc.cpp b/plugins/channelrx/udpsrc/udpsrc.cpp index c0aa7be87..6652c53ab 100644 --- a/plugins/channelrx/udpsrc/udpsrc.cpp +++ b/plugins/channelrx/udpsrc/udpsrc.cpp @@ -92,7 +92,7 @@ UDPSrc::UDPSrc(DeviceSourceAPI *deviceAPI) : qWarning("UDPSrc::UDPSrc: cannot bind audio port"); } - m_agc.setClampMax(32768.0*32768.0); + m_agc.setClampMax(SDR_SCALED*SDR_SCALED); m_agc.setClamping(true); //DSPEngine::instance()->addAudioSink(&m_audioFifo); @@ -158,7 +158,7 @@ void UDPSrc::feed(const SampleVector::const_iterator& begin, const SampleVector: inMagSq = ci.real()*ci.real() + ci.imag()*ci.imag(); } - m_inMovingAverage.feed(inMagSq / (1<<30)); + m_inMovingAverage.feed(inMagSq / (SDR_SCALED*SDR_SCALED)); m_inMagsq = m_inMovingAverage.average(); Sample ss(ci.real(), ci.imag()); @@ -180,7 +180,7 @@ void UDPSrc::feed(const SampleVector::const_iterator& begin, const SampleVector: l = m_squelchOpen ? sideband[i].real() * m_settings.m_gain : 0; r = m_squelchOpen ? sideband[i].imag() * m_settings.m_gain : 0; m_udpBuffer->write(Sample(l, r)); - m_outMovingAverage.feed((l*l + r*r) / (1<<30)); + m_outMovingAverage.feed((l*l + r*r) / (SDR_SCALED*SDR_SCALED)); } } } @@ -196,19 +196,19 @@ void UDPSrc::feed(const SampleVector::const_iterator& begin, const SampleVector: l = m_squelchOpen ? sideband[i].real() * m_settings.m_gain : 0; r = m_squelchOpen ? sideband[i].imag() * m_settings.m_gain : 0; m_udpBuffer->write(Sample(l, r)); - m_outMovingAverage.feed((l*l + r*r) / (1<<30)); + m_outMovingAverage.feed((l*l + r*r) / (SDR_SCALED*SDR_SCALED)); } } } else if (m_settings.m_sampleFormat == UDPSrcSettings::FormatNFM) { - double demod = m_squelchOpen ? 32768.0 * m_phaseDiscri.phaseDiscriminator(ci) * m_settings.m_gain : 0; + double demod = m_squelchOpen ? SDR_SCALED * m_phaseDiscri.phaseDiscriminator(ci) * m_settings.m_gain : 0; m_udpBuffer->write(Sample(demod, demod)); - m_outMovingAverage.feed((demod * demod) / (1<<30)); + m_outMovingAverage.feed((demod * demod) / (SDR_SCALED*SDR_SCALED)); } else if (m_settings.m_sampleFormat == UDPSrcSettings::FormatNFMMono) { - FixReal demod = m_squelchOpen ? (FixReal) (32768.0f * m_phaseDiscri.phaseDiscriminator(ci) * m_settings.m_gain) : 0; + FixReal demod = m_squelchOpen ? (FixReal) (SDR_SCALEF * m_phaseDiscri.phaseDiscriminator(ci) * m_settings.m_gain) : 0; m_udpBufferMono->write(demod); m_outMovingAverage.feed((demod * demod) / 1073741824.0); } @@ -223,7 +223,7 @@ void UDPSrc::feed(const SampleVector::const_iterator& begin, const SampleVector: { l = m_squelchOpen ? (sideband[i].real() + sideband[i].imag()) * 0.7 * m_settings.m_gain : 0; m_udpBufferMono->write(l); - m_outMovingAverage.feed((l * l) / (1<<30)); + m_outMovingAverage.feed((l * l) / (SDR_SCALED*SDR_SCALED)); } } } @@ -238,7 +238,7 @@ void UDPSrc::feed(const SampleVector::const_iterator& begin, const SampleVector: { l = m_squelchOpen ? (sideband[i].real() + sideband[i].imag()) * 0.7 * m_settings.m_gain : 0; m_udpBufferMono->write(l); - m_outMovingAverage.feed((l * l) / (1<<30)); + m_outMovingAverage.feed((l * l) / (SDR_SCALED*SDR_SCALED)); } } } @@ -287,7 +287,7 @@ void UDPSrc::feed(const SampleVector::const_iterator& begin, const SampleVector: { Sample s(ci.real() * m_settings.m_gain, ci.imag() * m_settings.m_gain); m_udpBuffer->write(s); - m_outMovingAverage.feed((inMagSq*m_settings.m_gain*m_settings.m_gain) / (1<<30)); + m_outMovingAverage.feed((inMagSq*m_settings.m_gain*m_settings.m_gain) / (SDR_SCALED*SDR_SCALED)); } else { diff --git a/plugins/channeltx/modam/ammod.cpp b/plugins/channeltx/modam/ammod.cpp index d8fe9016f..17672a523 100644 --- a/plugins/channeltx/modam/ammod.cpp +++ b/plugins/channeltx/modam/ammod.cpp @@ -129,8 +129,8 @@ void AMMod::pull(Sample& sample) m_settingsMutex.unlock(); - Real magsq = ci.real() * ci.real() + ci.imag() * ci.imag(); - magsq /= (1<<30); + double magsq = ci.real() * ci.real() + ci.imag() * ci.imag(); + magsq /= (SDR_SCALED*SDR_SCALED); m_movingAverage.feed(magsq); m_magsq = m_movingAverage.average(); diff --git a/plugins/channeltx/modatv/atvmod.cpp b/plugins/channeltx/modatv/atvmod.cpp index f28b6ae93..bbc079a25 100644 --- a/plugins/channeltx/modatv/atvmod.cpp +++ b/plugins/channeltx/modatv/atvmod.cpp @@ -163,8 +163,8 @@ void ATVMod::pullFinalize(Complex& ci, Sample& sample) m_settingsMutex.unlock(); - Real magsq = ci.real() * ci.real() + ci.imag() * ci.imag(); - magsq /= (1<<30); + double magsq = ci.real() * ci.real() + ci.imag() * ci.imag(); + magsq /= (SDR_SCALED*SDR_SCALED); m_movingAverage.feed(magsq); sample.m_real = (FixReal) ci.real(); diff --git a/plugins/channeltx/modatv/atvmodsettings.cpp b/plugins/channeltx/modatv/atvmodsettings.cpp index 1b5014d3c..192c98db9 100644 --- a/plugins/channeltx/modatv/atvmodsettings.cpp +++ b/plugins/channeltx/modatv/atvmodsettings.cpp @@ -43,7 +43,7 @@ void ATVModSettings::resetToDefaults() m_cameraPlay = false; m_channelMute = false; m_invertedVideo = false; - m_rfScalingFactor = 29204.0f; // -1dB + m_rfScalingFactor = 0.891235351562f * SDR_SCALEF; // -1dB m_fmExcursion = 0.5f; // half bandwidth m_forceDecimator = false; m_overlayText = "ATV"; diff --git a/plugins/channeltx/modnfm/nfmmod.cpp b/plugins/channeltx/modnfm/nfmmod.cpp index dad97319c..812e52332 100644 --- a/plugins/channeltx/modnfm/nfmmod.cpp +++ b/plugins/channeltx/modnfm/nfmmod.cpp @@ -135,8 +135,8 @@ void NFMMod::pull(Sample& sample) m_settingsMutex.unlock(); - Real magsq = ci.real() * ci.real() + ci.imag() * ci.imag(); - magsq /= (1<<30); + double magsq = ci.real() * ci.real() + ci.imag() * ci.imag(); + magsq /= (SDR_SCALED*SDR_SCALED); m_movingAverage.feed(magsq); m_magsq = m_movingAverage.average(); @@ -175,8 +175,8 @@ void NFMMod::modulateSample() m_modPhasor += (m_settings.m_fmDeviation / (float) m_settings.m_audioSampleRate) * m_bandpass.filter(t) * (M_PI / 378.0f); } - m_modSample.real(cos(m_modPhasor) * 29204.0f); // -1 dB - m_modSample.imag(sin(m_modPhasor) * 29204.0f); + m_modSample.real(cos(m_modPhasor) * 0.891235351562f * SDR_SCALEF); // -1 dB + m_modSample.imag(sin(m_modPhasor) * 0.891235351562f * SDR_SCALEF); } void NFMMod::pullAF(Real& sample) diff --git a/plugins/channeltx/modssb/ssbmod.cpp b/plugins/channeltx/modssb/ssbmod.cpp index ad90f716e..84d8e7a72 100644 --- a/plugins/channeltx/modssb/ssbmod.cpp +++ b/plugins/channeltx/modssb/ssbmod.cpp @@ -160,12 +160,12 @@ void SSBMod::pull(Sample& sample) m_interpolatorDistanceRemain += m_interpolatorDistance; ci *= m_carrierNco.nextIQ(); // shift to carrier frequency - ci *= 29204.0f; //scaling at -1 dB to account for possible filter overshoot + ci *= 0.891235351562f * SDR_SCALEF; //scaling at -1 dB to account for possible filter overshoot m_settingsMutex.unlock(); - Real magsq = ci.real() * ci.real() + ci.imag() * ci.imag(); - magsq /= (1<<30); + double magsq = ci.real() * ci.real() + ci.imag() * ci.imag(); + magsq /= (SDR_SCALED*SDR_SCALED); m_movingAverage.feed(magsq); m_magsq = m_movingAverage.average(); @@ -298,13 +298,13 @@ void SSBMod::pullAF(Complex& sample) { if (m_settings.m_audioFlipChannels) { - ci.real((m_audioBuffer[m_audioBufferFill].r / 32768.0f) * m_settings.m_volumeFactor); - ci.imag((m_audioBuffer[m_audioBufferFill].l / 32768.0f) * m_settings.m_volumeFactor); + ci.real((m_audioBuffer[m_audioBufferFill].r / SDR_SCALEF) * m_settings.m_volumeFactor); + ci.imag((m_audioBuffer[m_audioBufferFill].l / SDR_SCALEF) * m_settings.m_volumeFactor); } else { - ci.real((m_audioBuffer[m_audioBufferFill].l / 32768.0f) * m_settings.m_volumeFactor); - ci.imag((m_audioBuffer[m_audioBufferFill].r / 32768.0f) * m_settings.m_volumeFactor); + ci.real((m_audioBuffer[m_audioBufferFill].l / SDR_SCALEF) * m_settings.m_volumeFactor); + ci.imag((m_audioBuffer[m_audioBufferFill].r / SDR_SCALEF) * m_settings.m_volumeFactor); } } else @@ -419,18 +419,8 @@ void SSBMod::pullAF(Complex& sample) if (!(m_undersampleCount++ & decim_mask)) { - Real avgr = (m_sum.real() / decim) * 29204.0f; //scaling at -1 dB to account for possible filter overshoot - Real avgi = (m_sum.imag() / decim) * 29204.0f; -// m_magsqSpectrum = (avgr * avgr + avgi * avgi) / (1<<30); -// -// m_magsqSum += m_magsqSpectrum; -// -// if (m_magsqSpectrum > m_magsqPeak) -// { -// m_magsqPeak = m_magsqSpectrum; -// } -// -// m_magsqCount++; + Real avgr = (m_sum.real() / decim) * 0.891235351562f * SDR_SCALEF; //scaling at -1 dB to account for possible filter overshoot + Real avgi = (m_sum.imag() / decim) * 0.891235351562f * SDR_SCALEF; if (!m_settings.m_dsb & !m_settings.m_usb) { // invert spectrum for LSB @@ -453,18 +443,8 @@ void SSBMod::pullAF(Complex& sample) if (!(m_undersampleCount++ & decim_mask)) { - Real avgr = (m_sum.real() / decim) * 29204.0f; //scaling at -1 dB to account for possible filter overshoot - Real avgi = (m_sum.imag() / decim) * 29204.0f; -// m_magsqSpectrum = (avgr * avgr + avgi * avgi) / (1<<30); -// -// m_magsqSum += m_magsqSpectrum; -// -// if (m_magsqSpectrum > m_magsqPeak) -// { -// m_magsqPeak = m_magsqSpectrum; -// } -// -// m_magsqCount++; + Real avgr = (m_sum.real() / decim) * 0.891235351562f * SDR_SCALEF; //scaling at -1 dB to account for possible filter overshoot + Real avgi = (m_sum.imag() / decim) * 0.891235351562f * SDR_SCALEF; if (!m_settings.m_dsb & !m_settings.m_usb) { // invert spectrum for LSB diff --git a/plugins/channeltx/modwfm/wfmmod.cpp b/plugins/channeltx/modwfm/wfmmod.cpp index 3801a255f..7492b6a77 100644 --- a/plugins/channeltx/modwfm/wfmmod.cpp +++ b/plugins/channeltx/modwfm/wfmmod.cpp @@ -139,8 +139,8 @@ void WFMMod::pull(Sample& sample) } m_modPhasor += (m_settings.m_fmDeviation / (float) m_outputSampleRate) * ri.real() * M_PI * 2.0f; - ci.real(cos(m_modPhasor) * 29204.0f); // -1 dB - ci.imag(sin(m_modPhasor) * 29204.0f); + ci.real(cos(m_modPhasor) * 0.891235351562f * SDR_SCALEF); // -1 dB + ci.imag(sin(m_modPhasor) * 0.891235351562f * SDR_SCALEF); // RF filtering rf_out = m_rfFilter->runFilt(ci, &rf); @@ -157,8 +157,8 @@ void WFMMod::pull(Sample& sample) m_settingsMutex.unlock(); - Real magsq = ci.real() * ci.real() + ci.imag() * ci.imag(); - magsq /= (1<<30); + double magsq = ci.real() * ci.real() + ci.imag() * ci.imag(); + magsq /= (SDR_SCALED*SDR_SCALED); m_movingAverage.feed(magsq); m_magsq = m_movingAverage.average(); diff --git a/plugins/channeltx/udpsink/udpsink.cpp b/plugins/channeltx/udpsink/udpsink.cpp index 889376930..f36fd1737 100644 --- a/plugins/channeltx/udpsink/udpsink.cpp +++ b/plugins/channeltx/udpsink/udpsink.cpp @@ -134,7 +134,7 @@ void UDPSink::pull(Sample& sample) m_settingsMutex.unlock(); double magsq = ci.real() * ci.real() + ci.imag() * ci.imag(); - magsq /= (1<<30); + magsq /= (SDR_SCALED*SDR_SCALED); m_movingAverage.feed(magsq); m_magsq = m_movingAverage.average(); @@ -180,9 +180,9 @@ void UDPSink::modulateSample() if (m_squelchOpen) { - m_modPhasor += (m_settings.m_fmDeviation / m_settings.m_inputSampleRate) * (t / 32768.0f) * M_PI * 2.0f; - m_modSample.real(cos(m_modPhasor) * 10362.2f * m_settings.m_gainOut); - m_modSample.imag(sin(m_modPhasor) * 10362.2f * m_settings.m_gainOut); + m_modPhasor += (m_settings.m_fmDeviation / m_settings.m_inputSampleRate) * (t / SDR_SCALEF) * M_PI * 2.0f; + m_modSample.real(cos(m_modPhasor) * 0.3162292f * SDR_SCALEF * m_settings.m_gainOut); + m_modSample.imag(sin(m_modPhasor) * 0.3162292f * SDR_SCALEF * m_settings.m_gainOut); calculateLevel(m_modSample); } else @@ -195,14 +195,14 @@ void UDPSink::modulateSample() { FixReal t; readMonoSample(t); - m_inMovingAverage.feed((t*t)/1073741824.0); + m_inMovingAverage.feed((t*t)/(SDR_SCALED*SDR_SCALED)); m_inMagsq = m_inMovingAverage.average(); calculateSquelch(m_inMagsq); if (m_squelchOpen) { - m_modSample.real(((t / 32768.0f)*m_settings.m_amModFactor*m_settings.m_gainOut + 1.0f) * 16384.0f); // modulate and scale zero frequency carrier + m_modSample.real(((t / SDR_SCALEF)*m_settings.m_amModFactor*m_settings.m_gainOut + 1.0f) * (SDR_SCALEF/2)); // modulate and scale zero frequency carrier m_modSample.imag(0.0f); calculateLevel(m_modSample); } @@ -227,7 +227,7 @@ void UDPSink::modulateSample() if (m_squelchOpen) { - ci.real((t / 32768.0f) * m_settings.m_gainOut); + ci.real((t / SDR_SCALEF) * m_settings.m_gainOut); ci.imag(0.0f); n_out = m_SSBFilter->runSSB(ci, &filtered, (m_settings.m_sampleFormat == UDPSinkSettings::FormatUSB)); @@ -239,8 +239,8 @@ void UDPSink::modulateSample() } 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_modSample.real(m_SSBFilterBuffer[m_SSBFilterBufferIndex].real() * SDR_SCALEF); + m_modSample.imag(m_SSBFilterBuffer[m_SSBFilterBufferIndex].imag() * SDR_SCALEF); m_SSBFilterBufferIndex++; calculateLevel(m_modSample); @@ -305,8 +305,8 @@ void UDPSink::calculateLevel(Complex sample) } else { - qreal rmsLevel = m_levelSum > 0.0 ? sqrt((m_levelSum/(1<<30)) / m_levelNbSamples) : 0.0; - emit levelChanged(rmsLevel, m_peakLevel / 32768.0, m_levelNbSamples); + qreal rmsLevel = m_levelSum > 0.0 ? sqrt((m_levelSum/(SDR_SCALED*SDR_SCALED)) / m_levelNbSamples) : 0.0; + emit levelChanged(rmsLevel, m_peakLevel / SDR_SCALEF, m_levelNbSamples); m_peakLevel = 0.0f; m_levelSum = 0.0f; m_levelCalcCount = 0; diff --git a/plugins/samplesink/plutosdroutput/plutosdroutput.cpp b/plugins/samplesink/plutosdroutput/plutosdroutput.cpp index 8ad6cdaa2..d6493a1ea 100644 --- a/plugins/samplesink/plutosdroutput/plutosdroutput.cpp +++ b/plugins/samplesink/plutosdroutput/plutosdroutput.cpp @@ -221,7 +221,6 @@ bool PlutoSDROutput::handleMessage(const Message& message) bool PlutoSDROutput::openDevice() { - //m_sampleSourceFifo.resize(m_settings.m_devSampleRate/(1<<(m_settings.m_log2Interp <= 4 ? m_settings.m_log2Interp : 4))); m_sampleSourceFifo.resize(32*PLUTOSDR_BLOCKSIZE_SAMPLES); // look for Rx buddy and get reference to common parameters diff --git a/sdrbase/dsp/dsptypes.h b/sdrbase/dsp/dsptypes.h index 8d8c92e6c..b6462e48d 100644 --- a/sdrbase/dsp/dsptypes.h +++ b/sdrbase/dsp/dsptypes.h @@ -22,11 +22,15 @@ #include #include -#ifdef SAMPLE_32BIT -#define SDR_SAMP_SZ 32 // internal fixed arithmetic sample size +#ifdef SAMPLE_24BIT +#define SDR_SAMP_SZ 24 // internal fixed arithmetic sample size +#define SDR_SCALEF 8388608.0f +#define SDR_SCALED 8388608.0 typedef qint32 FixReal; #else #define SDR_SAMP_SZ 16 // internal fixed arithmetic sample size +#define SDR_SCALEF 32768.0f +#define SDR_SCALED 32768.0 typedef qint16 FixReal; #endif diff --git a/sdrgui/dsp/scopevis.cpp b/sdrgui/dsp/scopevis.cpp index 7050e122a..02fd0066c 100644 --- a/sdrgui/dsp/scopevis.cpp +++ b/sdrgui/dsp/scopevis.cpp @@ -111,7 +111,7 @@ void ScopeVis::feed(const SampleVector::const_iterator& cbegin, const SampleVect for(int i = 0; i < count; ++i) { - *it++ = Complex(begin->real() / 32768.0f, begin->imag() / 32768.0f); + *it++ = Complex(begin->real() / SDR_SCALEF, begin->imag() / SDR_SCALEF); ++begin; } @@ -234,7 +234,7 @@ void ScopeVis::feed(const SampleVector::const_iterator& cbegin, const SampleVect for(int i = 0; i < count; ++i) { - *it++ = Complex(begin->real() / 32768.0f, begin->imag() / 32768.0f); + *it++ = Complex(begin->real() / SDR_SCALEF, begin->imag() / SDR_SCALEF); ++begin; } @@ -341,7 +341,7 @@ void ScopeVis::setSampleRate(int sampleRate) bool ScopeVis::triggerCondition(SampleVector::const_iterator& it) { - Complex c(it->real()/32768.0f, it->imag()/32768.0f); + Complex c(it->real()/SDR_SCALEF, it->imag()/SDR_SCALEF); m_traceback.push_back(c); // store into trace memory FIFO if (m_tracebackCount < m_traceback.size()) diff --git a/sdrgui/dsp/scopevismulti.h b/sdrgui/dsp/scopevismulti.h index 9c1c83427..c05656a8c 100644 --- a/sdrgui/dsp/scopevismulti.h +++ b/sdrgui/dsp/scopevismulti.h @@ -556,7 +556,7 @@ private: switch (m_projectionType) { case ProjectionImag: - v = s.m_imag / 32768.0f; + v = s.m_imag / SDR_SCALEF; break; case ProjectionMagLin: { @@ -590,7 +590,7 @@ private: break; case ProjectionReal: default: - v = s.m_real / 32768.0f; + v = s.m_real / SDR_SCALEF; break; } diff --git a/sdrgui/dsp/scopevisng.h b/sdrgui/dsp/scopevisng.h index b47a0cea7..3687f7d20 100644 --- a/sdrgui/dsp/scopevisng.h +++ b/sdrgui/dsp/scopevisng.h @@ -545,7 +545,7 @@ private: switch (m_projectionType) { case ProjectionImag: - v = s.m_imag / 32768.0f; + v = s.m_imag / SDR_SCALEF; break; case ProjectionMagLin: { @@ -579,7 +579,7 @@ private: break; case ProjectionReal: default: - v = s.m_real / 32768.0f; + v = s.m_real / SDR_SCALEF; break; } diff --git a/sdrgui/dsp/spectrumvis.cpp b/sdrgui/dsp/spectrumvis.cpp index 5489c0965..779436130 100644 --- a/sdrgui/dsp/spectrumvis.cpp +++ b/sdrgui/dsp/spectrumvis.cpp @@ -85,7 +85,7 @@ void SpectrumVis::feed(const SampleVector::const_iterator& cbegin, const SampleV for (std::size_t i = 0; i < samplesNeeded; ++i, ++begin) { - *it++ = Complex(begin->real() / 32768.0f, begin->imag() / 32768.0f); + *it++ = Complex(begin->real() / SDR_SCALEF, begin->imag() / SDR_SCALEF); } // apply fft window (and copy from m_fftBuffer to m_fftIn) @@ -144,7 +144,7 @@ void SpectrumVis::feed(const SampleVector::const_iterator& cbegin, const SampleV // not enough samples for FFT - just fill in new data and return for(std::vector::iterator it = m_fftBuffer.begin() + m_fftBufferFill; begin < end; ++begin) { - *it++ = Complex(begin->real() / 32768.0f, begin->imag() / 32768.0f); + *it++ = Complex(begin->real() / SDR_SCALEF, begin->imag() / SDR_SCALEF); } m_fftBufferFill += todo;