mirror of
https://github.com/f4exb/sdrangel.git
synced 2024-12-23 01:55:48 -05:00
Replaced hardcoded bit scaling literals by defines
This commit is contained in:
parent
f34750716a
commit
491b8a6d33
@ -22,6 +22,7 @@
|
||||
#include <boost/lexical_cast.hpp>
|
||||
#include <QtGlobal>
|
||||
|
||||
#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;
|
||||
|
@ -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()));
|
||||
}
|
||||
|
||||
|
@ -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()));
|
||||
}
|
||||
|
||||
|
@ -464,8 +464,6 @@ bool ChannelAnalyzerNGGUI::setNewFinalRate(int spanLog2)
|
||||
}
|
||||
|
||||
m_spanLog2 = spanLog2;
|
||||
//m_rate = 48000 / (1<<spanLog2);
|
||||
//m_rate = m_channelizer->getInputSampleRate() / (1<<spanLog2);
|
||||
m_rate = getRequestedChannelSampleRate() / (1<<spanLog2);
|
||||
|
||||
if (m_rate == 0) {
|
||||
|
@ -89,7 +89,6 @@ void AMDemod::feed(const SampleVector::const_iterator& begin, const SampleVector
|
||||
|
||||
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();
|
||||
|
||||
|
@ -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;
|
||||
}
|
||||
|
@ -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 **********
|
||||
|
||||
|
@ -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()) {
|
||||
|
@ -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)
|
||||
|
@ -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
|
||||
|
@ -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))
|
||||
|
@ -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;
|
||||
|
||||
|
@ -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<<settings.m_agcTimeLog2);
|
||||
m_agc.setThresholdEnable(settings.m_agcPowerThreshold != -99);
|
||||
double agcPowerThreshold = CalcDb::powerFromdB(settings.m_agcPowerThreshold) * (1<<30);
|
||||
double agcPowerThreshold = CalcDb::powerFromdB(settings.m_agcPowerThreshold) * (SDR_SCALED*SDR_SCALED);
|
||||
int agcThresholdGate = 48 * settings.m_agcThresholdGate; // ms
|
||||
bool agcClamping = settings.m_agcClamping;
|
||||
|
||||
|
@ -104,7 +104,6 @@ void WFMDemod::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(), 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;
|
||||
|
@ -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) {
|
||||
|
@ -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
|
||||
{
|
||||
|
@ -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();
|
||||
|
||||
|
@ -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();
|
||||
|
@ -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";
|
||||
|
@ -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)
|
||||
|
@ -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
|
||||
|
@ -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();
|
||||
|
||||
|
@ -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;
|
||||
|
@ -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
|
||||
|
@ -22,11 +22,15 @@
|
||||
#include <vector>
|
||||
#include <QtGlobal>
|
||||
|
||||
#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
|
||||
|
||||
|
@ -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())
|
||||
|
@ -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;
|
||||
}
|
||||
|
||||
|
@ -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;
|
||||
}
|
||||
|
||||
|
@ -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<Complex>::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;
|
||||
|
Loading…
Reference in New Issue
Block a user