1
0
mirror of https://github.com/f4exb/sdrangel.git synced 2024-11-10 18:43:28 -05:00

WDSP: RXA and TXA rework

This commit is contained in:
f4exb 2024-08-03 13:54:42 +02:00
parent d6159067a8
commit de756413e8
11 changed files with 1377 additions and 1369 deletions

View File

@ -125,14 +125,14 @@ WDSPRxSink::WDSPRxSink() :
m_sPeak = 0.0; m_sPeak = 0.0;
m_sCount = m_wdspBufSize; m_sCount = m_wdspBufSize;
m_rxa = WDSP::RXA::create_rxa( m_rxa = new WDSP::RXA(
m_wdspSampleRate, // input samplerate m_wdspSampleRate, // input samplerate
m_wdspSampleRate, // output samplerate m_wdspSampleRate, // output samplerate
m_wdspSampleRate, // sample rate for mainstream dsp processing (dsp) m_wdspSampleRate, // sample rate for mainstream dsp processing (dsp)
m_wdspBufSize // number complex samples processed per buffer in mainstream dsp processing m_wdspBufSize // number complex samples processed per buffer in mainstream dsp processing
); );
m_rxa->setSpectrumProbe(&m_spectrumProbe); m_rxa->setSpectrumProbe(&m_spectrumProbe);
WDSP::RXA::SetPassband(*m_rxa, 0, m_Bandwidth); m_rxa->setPassband(0, m_Bandwidth);
applyChannelSettings(m_channelSampleRate, m_channelFrequencyOffset, true); applyChannelSettings(m_channelSampleRate, m_channelFrequencyOffset, true);
applySettings(m_settings, true); applySettings(m_settings, true);
@ -140,7 +140,7 @@ WDSPRxSink::WDSPRxSink() :
WDSPRxSink::~WDSPRxSink() WDSPRxSink::~WDSPRxSink()
{ {
WDSP::RXA::destroy_rxa(m_rxa); delete m_rxa;
} }
void WDSPRxSink::feed(const SampleVector::const_iterator& begin, const SampleVector::const_iterator& end) void WDSPRxSink::feed(const SampleVector::const_iterator& begin, const SampleVector::const_iterator& end)
@ -189,7 +189,7 @@ void WDSPRxSink::processOneSample(Complex &ci)
if (++m_inCount == m_rxa->get_insize()) if (++m_inCount == m_rxa->get_insize())
{ {
WDSP::RXA::xrxa(m_rxa); m_rxa->execute();
m_sCount = m_wdspBufSize; m_sCount = m_wdspBufSize;
m_sAvg = m_rxa->smeter->getMeter(WDSP::RXA::RXA_S_AV); m_sAvg = m_rxa->smeter->getMeter(WDSP::RXA::RXA_S_AV);
@ -306,7 +306,7 @@ void WDSPRxSink::applyAudioSampleRate(int sampleRate)
m_interpolatorDistanceRemain = 0; m_interpolatorDistanceRemain = 0;
m_interpolatorDistance = (Real) m_channelSampleRate / (Real) m_wdspSampleRate; m_interpolatorDistance = (Real) m_channelSampleRate / (Real) m_wdspSampleRate;
WDSP::RXA::setOutputSamplerate(m_rxa, sampleRate); m_rxa->setOutputSamplerate(sampleRate);
m_audioFifo.setSize(sampleRate); m_audioFifo.setSize(sampleRate);
m_audioSampleRate = sampleRate; m_audioSampleRate = sampleRate;
@ -446,24 +446,24 @@ void WDSPRxSink::applySettings(const WDSPRxSettings& settings, bool force)
m_interpolatorDistanceRemain = 0; m_interpolatorDistanceRemain = 0;
m_interpolatorDistance = (Real) m_channelSampleRate / (Real) m_audioSampleRate; m_interpolatorDistance = (Real) m_channelSampleRate / (Real) m_audioSampleRate;
WDSP::RXA::SetPassband(*m_rxa, fLow, fHigh); m_rxa->setPassband(fLow, fHigh);
WDSP::RXA::NBPSetWindow(*m_rxa, m_settings.m_profiles[m_settings.m_profileIndex].m_fftWindow); m_rxa->nbpSetWindow(m_settings.m_profiles[m_settings.m_profileIndex].m_fftWindow);
if (settings.m_demod == WDSPRxProfile::DemodSSB) if (settings.m_demod == WDSPRxProfile::DemodSSB)
{ {
if (dsb) { if (dsb) {
WDSP::RXA::SetMode(*m_rxa, WDSP::RXA::RXA_DSB); m_rxa->setMode(WDSP::RXA::RXA_DSB);
} else { } else {
WDSP::RXA::SetMode(*m_rxa, usb ? WDSP::RXA::RXA_USB : WDSP::RXA::RXA_LSB); m_rxa->setMode(usb ? WDSP::RXA::RXA_USB : WDSP::RXA::RXA_LSB);
} }
} }
else if (settings.m_demod == WDSPRxProfile::DemodAM) else if (settings.m_demod == WDSPRxProfile::DemodAM)
{ {
WDSP::RXA::SetMode(*m_rxa, WDSP::RXA::RXA_AM); m_rxa->setMode(WDSP::RXA::RXA_AM);
} }
else if (settings.m_demod == WDSPRxProfile::DemodSAM) else if (settings.m_demod == WDSPRxProfile::DemodSAM)
{ {
WDSP::RXA::SetMode(*m_rxa, WDSP::RXA::RXA_SAM); m_rxa->setMode(WDSP::RXA::RXA_SAM);
if (dsb) { if (dsb) {
m_rxa->amd->setSBMode(0); m_rxa->amd->setSBMode(0);
@ -473,7 +473,7 @@ void WDSPRxSink::applySettings(const WDSPRxSettings& settings, bool force)
} }
else if (settings.m_demod == WDSPRxProfile::DemodFMN) else if (settings.m_demod == WDSPRxProfile::DemodFMN)
{ {
WDSP::RXA::SetMode(*m_rxa, WDSP::RXA::RXA_FM); m_rxa->setMode(WDSP::RXA::RXA_FM);
} }
} }
@ -486,18 +486,18 @@ void WDSPRxSink::applySettings(const WDSPRxSettings& settings, bool force)
if ((m_settings.m_dnr != settings.m_dnr) if ((m_settings.m_dnr != settings.m_dnr)
|| (m_settings.m_nrScheme != settings.m_nrScheme) || force) || (m_settings.m_nrScheme != settings.m_nrScheme) || force)
{ {
WDSP::RXA::SetANRRun(*m_rxa, 0); m_rxa->setANRRun(0);
WDSP::RXA::SetEMNRRun(*m_rxa, 0); m_rxa->setEMNRRun(0);
if (settings.m_dnr) if (settings.m_dnr)
{ {
switch (settings.m_nrScheme) switch (settings.m_nrScheme)
{ {
case WDSPRxProfile::NRSchemeNR: case WDSPRxProfile::NRSchemeNR:
WDSP::RXA::SetANRRun(*m_rxa, 1); m_rxa->setANRRun(1);
break; break;
case WDSPRxProfile::NRSchemeNR2: case WDSPRxProfile::NRSchemeNR2:
WDSP::RXA::SetEMNRRun(*m_rxa, 1); m_rxa->setEMNRRun(1);
break; break;
default: default:
break; break;
@ -510,12 +510,12 @@ void WDSPRxSink::applySettings(const WDSPRxSettings& settings, bool force)
switch (settings.m_nrPosition) switch (settings.m_nrPosition)
{ {
case WDSPRxProfile::NRPositionPreAGC: case WDSPRxProfile::NRPositionPreAGC:
WDSP::RXA::SetANRPosition(*m_rxa, 0); m_rxa->setANRPosition(0);
WDSP::RXA::SetEMNRPosition(*m_rxa, 0); m_rxa->setEMNRPosition(0);
break; break;
case WDSPRxProfile::NRPositionPostAGC: case WDSPRxProfile::NRPositionPostAGC:
WDSP::RXA::SetANRPosition(*m_rxa, 1); m_rxa->setANRPosition(1);
WDSP::RXA::SetEMNRPosition(*m_rxa, 1); m_rxa->setEMNRPosition(1);
break; break;
default: default:
break; break;
@ -560,12 +560,12 @@ void WDSPRxSink::applySettings(const WDSPRxSettings& settings, bool force)
} }
if ((m_settings.m_anf != settings.m_anf) || force) { if ((m_settings.m_anf != settings.m_anf) || force) {
WDSP::RXA::SetANFRun(*m_rxa, settings.m_anf ? 1 : 0); m_rxa->setANFRun(settings.m_anf ? 1 : 0);
} }
// Caution: Causes corruption // Caution: Causes corruption
if ((m_settings.m_snb != settings.m_snb) || force) { if ((m_settings.m_snb != settings.m_snb) || force) {
WDSP::RXA::SetSNBARun(*m_rxa, settings.m_snb ? 1 : 0); m_rxa->setSNBARun(settings.m_snb ? 1 : 0);
} }
// CW Peaking // CW Peaking

View File

@ -62,6 +62,7 @@ set(wdsp_SOURCES
sphp.cpp sphp.cpp
ssql.cpp ssql.cpp
TXA.cpp TXA.cpp
unit.cpp
varsamp.cpp varsamp.cpp
wcpAGC.cpp wcpAGC.cpp
) )
@ -129,6 +130,7 @@ set(wdsp_HEADERS
sphp.hpp sphp.hpp
ssql.hpp ssql.hpp
TXA.hpp TXA.hpp
unit.hpp
varsamp.hpp varsamp.hpp
wcpAGC.hpp wcpAGC.hpp
) )

File diff suppressed because it is too large Load Diff

View File

@ -128,70 +128,68 @@ public:
PANEL *panel; PANEL *panel;
RESAMPLE *rsmpout; RESAMPLE *rsmpout;
static RXA* create_rxa ( RXA(
int in_rate, // input samplerate int in_rate, // input samplerate
int out_rate, // output samplerate int out_rate, // output samplerate
int dsp_rate, // sample rate for mainstream dsp processing int dsp_rate, // sample rate for mainstream dsp processing
int dsp_size // number complex samples processed per buffer in mainstream dsp processing int dsp_size // number complex samples processed per buffer in mainstream dsp processing
); );
static void destroy_rxa (RXA *rxa); RXA(const RXA&) = delete;
static void flush_rxa (RXA *rxa); RXA& operator=(const RXA& other) = delete;
static void xrxa (RXA *rxa); ~RXA();
int get_insize() const { return dsp_insize; }
int get_outsize() const { return dsp_outsize; } void flush();
float *get_inbuff() { return inbuff; } void execute();
float *get_outbuff() { return outbuff; } void setInputSamplerate(int _in_rate);
void setOutputSamplerate(int _out_rate);
void setDSPSamplerate(int _dsp_rate);
void setDSPBuffsize(int _dsp_size);
int get_insize() const { return Unit::dsp_insize; }
int get_outsize() const { return Unit::dsp_outsize; }
float *get_inbuff() { return Unit::inbuff; }
float *get_outbuff() { return Unit::outbuff; }
void setSpectrumProbe(BufferProbe *_spectrumProbe); void setSpectrumProbe(BufferProbe *_spectrumProbe);
static void setInputSamplerate (RXA *rxa, int in_rate);
static void setOutputSamplerate (RXA *rxa, int out_rate);
static void setDSPSamplerate (RXA *rxa, int dsp_rate);
static void setDSPBuffsize (RXA *rxa, int dsp_size);
// RXA Properties // RXA Properties
static void SetMode (RXA& rxa, int mode); void setMode (int mode);
static void ResCheck (RXA& rxa); void resCheck ();
static void bp1Check (RXA& rxa, int amd_run, int snba_run, int emnr_run, int anf_run, int anr_run); void bp1Check (int amd_run, int snba_run, int emnr_run, int anf_run, int anr_run);
static void bp1Set (RXA& rxa); void bp1Set ();
static void bpsnbaCheck (RXA& rxa, int mode, int notch_run); void bpsnbaCheck (int mode, int notch_run);
static void bpsnbaSet (RXA& rxa); void bpsnbaSet ();
// NOTCHDB, NBP, SNBA // NOTCHDB, NBP, SNBA
static void UpdateNBPFiltersLightWeight (RXA& rxa); void updateNBPFiltersLightWeight();
static void UpdateNBPFilters(RXA& rxa); void updateNBPFilters();
static int NBPAddNotch (RXA& rxa, int notch, double fcenter, double fwidth, int active); int nbpAddNotch(int notch, double fcenter, double fwidth, int active);
static int NBPGetNotch (RXA& rxa, int notch, double* fcenter, double* fwidth, int* active); int nbpGetNotch(int notch, double* fcenter, double* fwidth, int* active);
static int NBPDeleteNotch (RXA& rxa, int notch); int nbpDeleteNotch(int notch);
static int NBPEditNotch (RXA& rxa, int notch, double fcenter, double fwidth, int active); int nbpEditNotch(int notch, double fcenter, double fwidth, int active);
static void NBPGetNumNotches (RXA& rxa, int* nnotches); void nbpGetNumNotches(int* nnotches);
static void NBPSetTuneFrequency (RXA& rxa, double tunefreq); void nbpSetTuneFrequency(double tunefreq);
static void NBPSetShiftFrequency (RXA& rxa, double shift); void nbpSetShiftFrequency(double shift);
static void NBPSetNotchesRun (RXA& rxa, int run); void nbpSetNotchesRun(int run);
static void NBPSetWindow (RXA& rxa, int wintype); void nbpSetWindow(int wintype);
static void NBPSetAutoIncrease (RXA& rxa, int autoincr); void nbpSetAutoIncrease(int autoincr);
// AMD // AMD
static void SetAMDRun(RXA& rxa, int run); void setAMDRun(int run);
// SNBA // SNBA
static void SetSNBARun (RXA& rxa, int run); void setSNBARun(int run);
// ANF // ANF
static void SetANFRun (RXA& rxa, int run); void setANFRun(int run);
static void SetANFPosition (RXA& rxa, int position); void setANFPosition(int position);
// ANR // ANR
static void SetANRRun (RXA& rxa, int run); void setANRRun(int run);
static void SetANRPosition (RXA& rxa, int position); void setANRPosition(int position);
// EMNR // EMNR
static void SetEMNRRun (RXA& rxa, int run); void setEMNRRun(int run);
static void SetEMNRPosition (RXA& rxa, int position); void setEMNRPosition(int position);
// WCPAGC // WCPAGC
static void SetAGCThresh(RXA& rxa, double thresh, double size, double rate); void setAGCThresh(double thresh, double size, double rate);
static void GetAGCThresh(RXA& rxa, double *thresh, double size, double rate); void getAGCThresh(double *thresh, double size, double rate);
// Collectives // Collectives
static void SetPassband (RXA& rxa, float f_low, float f_high); void setPassband(float f_low, float f_high);
static void SetNC (RXA& rxa, int nc); void setNC(int nc);
static void SetMP (RXA& rxa, int mp); void setMP(int mp);
private:
float* inbuff;
float* midbuff;
float* outbuff;
}; };
} // namespace WDSP } // namespace WDSP

File diff suppressed because it is too large Load Diff

View File

@ -157,11 +157,6 @@ public:
GEN *gen0; GEN *gen0;
GEN *gen1; GEN *gen1;
USLEW *uslew; USLEW *uslew;
// struct
// {
// CALCC *p;
// CRITICAL_SECTION cs_update;
// } calcc;
struct struct
{ {
IQC *p0, *p1; IQC *p0, *p1;
@ -169,42 +164,42 @@ public:
} iqc; } iqc;
CFIR *cfir; CFIR *cfir;
static TXA* create_txa ( TXA(
int in_rate, // input samplerate int in_rate, // input samplerate
int out_rate, // output samplerate int out_rate, // output samplerate
int dsp_rate, // sample rate for mainstream dsp processing int dsp_rate, // sample rate for mainstream dsp processing
int dsp_size // number complex samples processed per buffer in mainstream dsp processing int dsp_size // number complex samples processed per buffer in mainstream dsp processing
); );
static void destroy_txa (TXA *txa); TXA(const TXA&) = delete;
static void flush_txa (TXA *txa); TXA& operator=(const TXA& other) = delete;
static void xtxa (TXA *txa); ~TXA();
int get_insize() const { return dsp_insize; }
int get_outsize() const { return dsp_outsize; } void flush();
float *get_inbuff() { return inbuff; } void execute();
float *get_outbuff() { return outbuff; } void setInputSamplerate(int _in_rate);
static void setInputSamplerate (TXA *txa, int in_rate); void setOutputSamplerate(int _out_rate);
static void setOutputSamplerate (TXA *txa, int out_rate); void setDSPSamplerate(int _dsp_rate);
static void setDSPSamplerate (TXA *txa, int dsp_rate); void setDSPBuffsize(int _dsp_size);
static void setDSPBuffsize (TXA *txa, int dsp_size); int get_insize() const { return Unit::dsp_insize; }
int get_outsize() const { return Unit::dsp_outsize; }
float *get_inbuff() { return Unit::inbuff; }
float *get_outbuff() { return Unit::outbuff; }
// TXA Properties // TXA Properties
static void SetMode (TXA& txa, int mode); void setMode(int mode);
static void SetBandpassFreqs (TXA& txa, float f_low, float f_high); void setBandpassFreqs(float f_low, float f_high);
static void SetBandpassNC (TXA& txa, int nc); void setBandpassNC(int nc);
static void SetBandpassMP (TXA& txa, int mp); void setBandpassMP(int mp);
// Collectives // Collectives
static void SetNC (TXA& txa, int nc); void setNC(int nc);
static void SetMP (TXA& txa, int mp); void setMP(int mp);
static void SetFMAFFilter (TXA& txa, float low, float high); void setFMAFFilter(float low, float high);
static void SetupBPFilters (TXA& txa); void setupBPFilters();
static int UslewCheck (TXA& txa); int uslewCheck();
private: private:
static void ResCheck (TXA& txa); void resCheck();
float* inbuff;
float* midbuff;
float* outbuff;
}; };
} // namespace WDSP } // namespace WDSP

View File

@ -103,7 +103,7 @@ void COMPRESSOR::SetCompressorRun (TXA& txa, int run)
if (txa.compressor->run != run) if (txa.compressor->run != run)
{ {
txa.compressor->run = run; txa.compressor->run = run;
TXA::SetupBPFilters (txa); txa.setupBPFilters();
} }
} }

View File

@ -149,7 +149,7 @@ void OSCTRL::SetosctrlRun (TXA& txa, int run)
if (txa.osctrl->run != run) if (txa.osctrl->run != run)
{ {
txa.osctrl->run = run; txa.osctrl->run = run;
TXA::SetupBPFilters (txa); txa.setupBPFilters();
} }
} }

View File

@ -103,7 +103,7 @@ void USLEW::flush_uslew (USLEW *a)
void USLEW::xuslew (USLEW *a) void USLEW::xuslew (USLEW *a)
{ {
if (!a->runmode && TXA::UslewCheck (*a->txa)) if (!a->runmode && a->txa->uslewCheck())
a->runmode = 1; a->runmode = 1;
long upslew = *a->ch_upslew; long upslew = *a->ch_upslew;

148
wdsp/unit.cpp Normal file
View File

@ -0,0 +1,148 @@
/* unit.hpp
This file is part of a program that implements a Software-Defined Radio.
Copyright (C) 2013 Warren Pratt, NR0V
Copyright (C) 2024 Edouard Griffiths, F4EXB Adapted to SDRangel
This program is free software; you can redistribute it and/or
modify it under the terms of the GNU General Public License
as published by the Free Software Foundation; either version 2
of the License, or (at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program; if not, write to the Free Software
Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
The author can be reached by email at
warren@wpratt.com
*/
#include <algorithm>
#include "unit.hpp"
namespace WDSP {
Unit::Unit(
int _in_rate, // input samplerate
int _out_rate, // output samplerate
int _dsp_rate, // sample rate for mainstream dsp processing
int _dsp_size // number complex samples processed per buffer in mainstream dsp processing
) :
in_rate{_in_rate},
out_rate(_out_rate),
dsp_rate(_dsp_rate),
dsp_size(_dsp_size)
{
if (_in_rate >= _dsp_rate)
dsp_insize = _dsp_size * (_in_rate / _dsp_rate);
else
dsp_insize = _dsp_size / (_dsp_rate / _in_rate);
if (_out_rate >= _dsp_rate)
dsp_outsize = _dsp_size * (_out_rate / _dsp_rate);
else
dsp_outsize = _dsp_size / (_dsp_rate / _out_rate);
// buffers
inbuff = new float[1 * dsp_insize * 2];
outbuff = new float[1 * dsp_outsize * 2];
midbuff = new float[2 * dsp_size * 2];
}
Unit::~Unit()
{
delete[] inbuff;
delete[] outbuff;
delete[] midbuff;
}
void Unit::flushBuffers()
{
std::fill(inbuff, inbuff + 1 * dsp_insize * 2, 0);
std::fill(outbuff, outbuff + 1 * dsp_outsize * 2, 0);
std::fill(midbuff, midbuff + 2 * dsp_size * 2, 0);
}
void Unit::setBuffersInputSamplerate(int _in_rate)
{
if (_in_rate >= dsp_rate)
dsp_insize = dsp_size * (_in_rate / dsp_rate);
else
dsp_insize = dsp_size / (dsp_rate / _in_rate);
in_rate = _in_rate;
// buffers
delete[] (inbuff);
inbuff = new float[1 * dsp_insize * 2];
}
void Unit::setBuffersOutputSamplerate(int _out_rate)
{
if (_out_rate >= dsp_rate)
dsp_outsize = dsp_size * (_out_rate / dsp_rate);
else
dsp_outsize = dsp_size / (dsp_rate / _out_rate);
out_rate = _out_rate;
// buffers
delete[] outbuff;
outbuff = new float[1 * dsp_outsize * 2];
}
void Unit::setBuffersDSPSamplerate(int _dsp_rate)
{
if (in_rate >= _dsp_rate)
dsp_insize = dsp_size * (in_rate / _dsp_rate);
else
dsp_insize = dsp_size / (_dsp_rate / in_rate);
if (out_rate >= _dsp_rate)
dsp_outsize = dsp_size * (out_rate / _dsp_rate);
else
dsp_outsize = dsp_size / (_dsp_rate / out_rate);
dsp_rate = _dsp_rate;
// buffers
delete[] inbuff;
inbuff = new float[1 * dsp_insize * 2];
delete[] outbuff;
outbuff = new float[1 * dsp_outsize * 2];
}
void Unit::setBuffersDSPBuffsize(int _dsp_size)
{
if (in_rate >= dsp_rate)
dsp_insize = _dsp_size * (in_rate / dsp_rate);
else
dsp_insize = _dsp_size / (dsp_rate / in_rate);
if (out_rate >= dsp_rate)
dsp_outsize = _dsp_size * (out_rate / dsp_rate);
else
dsp_outsize = _dsp_size / (dsp_rate / out_rate);
dsp_size = _dsp_size;
// buffers
delete[]inbuff;
inbuff = new float[1 * dsp_insize * 2];
delete[] midbuff;
midbuff = new float[2 * dsp_size * 2];
delete[] outbuff;
outbuff = new float[1 * dsp_outsize * 2];
}
} // namespace

View File

@ -42,6 +42,25 @@ public:
int dsp_insize; // size (complex samples) of the input buffer int dsp_insize; // size (complex samples) of the input buffer
int dsp_outsize; // size (complex samples) of the output buffer int dsp_outsize; // size (complex samples) of the output buffer
int state; // 0 for unit OFF; 1 for unit ON int state; // 0 for unit OFF; 1 for unit ON
Unit(
int _in_rate, // input samplerate
int _out_rate, // output samplerate
int _dsp_rate, // sample rate for mainstream dsp processing
int _dsp_size // number complex samples processed per buffer in mainstream dsp processing
);
~Unit();
void flushBuffers();
void setBuffersInputSamplerate(int _in_rate);
void setBuffersOutputSamplerate(int _out_rate);
void setBuffersDSPSamplerate(int _dsp_rate);
void setBuffersDSPBuffsize(int _dsp_size);
protected:
float* inbuff;
float* midbuff;
float* outbuff;
}; };
} // namespace WDSP } // namespace WDSP