From 913d5bf7b014d2c9d7e0c3eb52bb3404558200a9 Mon Sep 17 00:00:00 2001 From: f4exb Date: Tue, 30 Jul 2024 23:29:37 +0200 Subject: [PATCH] WDSP: CBL rework --- wdsp/RXA.cpp | 14 +++--- wdsp/cblock.cpp | 113 +++++++++++++++++++++++------------------------- wdsp/cblock.hpp | 23 +++++----- wdsp/ssql.cpp | 8 ++-- 4 files changed, 77 insertions(+), 81 deletions(-) diff --git a/wdsp/RXA.cpp b/wdsp/RXA.cpp index c0fc8f15a..289e27091 100644 --- a/wdsp/RXA.cpp +++ b/wdsp/RXA.cpp @@ -471,7 +471,7 @@ RXA* RXA::create_rxa ( 0); // specmode // AM carrier block - rxa->cbl = CBL::create_cbl ( + rxa->cbl = new CBL( 0, // run - needed only if set to ON rxa->dsp_size, // buffer size rxa->midbuff, // pointer to input buffer @@ -568,7 +568,7 @@ void RXA::destroy_rxa (RXA *rxa) SSQL::destroy_ssql (rxa->ssql); MPEAK::destroy_mpeak (rxa->mpeak); SPEAK::destroy_speak (rxa->speak); - CBL::destroy_cbl (rxa->cbl); + delete (rxa->cbl); delete (rxa->sip1); delete (rxa->bp1); delete (rxa->agcmeter); @@ -625,7 +625,7 @@ void RXA::flush_rxa (RXA *rxa) rxa->agcmeter->flush(); rxa->bp1->flush(); rxa->sip1->flush(); - CBL::flush_cbl (rxa->cbl); + rxa->cbl->flush(); SPEAK::flush_speak (rxa->speak); MPEAK::flush_mpeak (rxa->mpeak); SSQL::flush_ssql (rxa->ssql); @@ -664,7 +664,7 @@ void RXA::xrxa (RXA *rxa) rxa->bp1->execute(1); rxa->agcmeter->execute(); rxa->sip1->execute(0); - CBL::xcbl (rxa->cbl); + rxa->cbl->execute(); SPEAK::xspeak (rxa->speak); MPEAK::xmpeak (rxa->mpeak); SSQL::xssql (rxa->ssql); @@ -771,7 +771,7 @@ void RXA::setDSPSamplerate (RXA *rxa, int dsp_rate) rxa->agc->setSamplerate(rxa->dsp_rate); rxa->agcmeter->setSamplerate(rxa->dsp_rate); rxa->sip1->setSamplerate(rxa->dsp_rate); - CBL::setSamplerate_cbl (rxa->cbl, rxa->dsp_rate); + rxa->cbl->setSamplerate(rxa->dsp_rate); SPEAK::setSamplerate_speak (rxa->speak, rxa->dsp_rate); MPEAK::setSamplerate_mpeak (rxa->mpeak, rxa->dsp_rate); SSQL::setSamplerate_ssql (rxa->ssql, rxa->dsp_rate); @@ -851,8 +851,8 @@ void RXA::setDSPBuffsize (RXA *rxa, int dsp_size) rxa->agcmeter->setSize(rxa->dsp_size); rxa->sip1->setBuffers(rxa->midbuff); rxa->sip1->setSize(rxa->dsp_size); - CBL::setBuffers_cbl (rxa->cbl, rxa->midbuff, rxa->midbuff); - CBL::setSize_cbl (rxa->cbl, rxa->dsp_size); + rxa->cbl->setBuffers(rxa->midbuff, rxa->midbuff); + rxa->cbl->setSize(rxa->dsp_size); SPEAK::setBuffers_speak (rxa->speak, rxa->midbuff, rxa->midbuff); SPEAK::setSize_speak (rxa->speak, rxa->dsp_size); MPEAK::setBuffers_mpeak (rxa->mpeak, rxa->midbuff, rxa->midbuff); diff --git a/wdsp/cblock.cpp b/wdsp/cblock.cpp index 04119bed8..6514ea9c8 100644 --- a/wdsp/cblock.cpp +++ b/wdsp/cblock.cpp @@ -31,95 +31,88 @@ warren@wpratt.com namespace WDSP { -void CBL::calc_cbl (CBL *a) +void CBL::calc() { - a->prevIin = 0.0; - a->prevQin = 0.0; - a->prevIout = 0.0; - a->prevQout = 0.0; - a->mtau = exp(-1.0 / (a->sample_rate * a->tau)); + prevIin = 0.0; + prevQin = 0.0; + prevIout = 0.0; + prevQout = 0.0; + mtau = exp(-1.0 / (sample_rate * tau)); } -CBL* CBL::create_cbl( - int run, - int buff_size, - float *in_buff, - float *out_buff, - int mode, - int sample_rate, - double tau +CBL::CBL( + int _run, + int _buff_size, + float *_in_buff, + float *_out_buff, + int _mode, + int _sample_rate, + double _tau ) { - CBL *a = new CBL; - a->run = run; - a->buff_size = buff_size; - a->in_buff = in_buff; - a->out_buff = out_buff; - a->mode = mode; - a->sample_rate = (double) sample_rate; - a->tau = tau; - calc_cbl (a); - return a; + run = _run; + buff_size = _buff_size; + in_buff = _in_buff; + out_buff = _out_buff; + mode = _mode; + sample_rate = (double) _sample_rate; + tau = _tau; + calc(); } -void CBL::destroy_cbl(CBL *a) +void CBL::flush() { - delete a; + prevIin = 0.0; + prevQin = 0.0; + prevIout = 0.0; + prevQout = 0.0; } -void CBL::flush_cbl (CBL *a) +void CBL::execute() { - a->prevIin = 0.0; - a->prevQin = 0.0; - a->prevIout = 0.0; - a->prevQout = 0.0; -} - -void CBL::xcbl (CBL *a) -{ - if (a->run) + if (run) { int i; double tempI, tempQ; - for (i = 0; i < a->buff_size; i++) + for (i = 0; i < buff_size; i++) { - tempI = a->in_buff[2 * i + 0]; - tempQ = a->in_buff[2 * i + 1]; - a->out_buff[2 * i + 0] = a->in_buff[2 * i + 0] - a->prevIin + a->mtau * a->prevIout; - a->out_buff[2 * i + 1] = a->in_buff[2 * i + 1] - a->prevQin + a->mtau * a->prevQout; - a->prevIin = tempI; - a->prevQin = tempQ; + tempI = in_buff[2 * i + 0]; + tempQ = in_buff[2 * i + 1]; + out_buff[2 * i + 0] = in_buff[2 * i + 0] - prevIin + mtau * prevIout; + out_buff[2 * i + 1] = in_buff[2 * i + 1] - prevQin + mtau * prevQout; + prevIin = tempI; + prevQin = tempQ; - if (fabs(a->prevIout = a->out_buff[2 * i + 0]) < 1.0e-20) - a->prevIout = 0.0; + if (fabs(prevIout = out_buff[2 * i + 0]) < 1.0e-20) + prevIout = 0.0; - if (fabs(a->prevQout = a->out_buff[2 * i + 1]) < 1.0e-20) - a->prevQout = 0.0; + if (fabs(prevQout = out_buff[2 * i + 1]) < 1.0e-20) + prevQout = 0.0; } } - else if (a->in_buff != a->out_buff) + else if (in_buff != out_buff) { - std::copy(a->in_buff, a->in_buff + a->buff_size * 2, a->out_buff); + std::copy(in_buff, in_buff + buff_size * 2, out_buff); } } -void CBL::setBuffers_cbl (CBL *a, float* in, float* out) +void CBL::setBuffers(float* _in, float* _out) { - a->in_buff = in; - a->out_buff = out; + in_buff = _in; + out_buff = _out; } -void CBL::setSamplerate_cbl (CBL *a, int rate) +void CBL::setSamplerate(int _rate) { - a->sample_rate = rate; - calc_cbl (a); + sample_rate = _rate; + calc(); } -void CBL::setSize_cbl (CBL *a, int size) +void CBL::setSize(int _size) { - a->buff_size = size; - flush_cbl (a); + buff_size = _size; + flush(); } /******************************************************************************************************** @@ -128,9 +121,9 @@ void CBL::setSize_cbl (CBL *a, int size) * * ********************************************************************************************************/ -void CBL::SetCBLRun(RXA& rxa, int setit) +void CBL::setRun(int setit) { - rxa.cbl->run = setit; + run = setit; } } // namespace WDSP diff --git a/wdsp/cblock.hpp b/wdsp/cblock.hpp index 167a2a3b9..2bd781b4a 100644 --- a/wdsp/cblock.hpp +++ b/wdsp/cblock.hpp @@ -50,7 +50,7 @@ public: double tau; //carrier removal time constant double mtau; //carrier removal multiplier - static CBL* create_cbl( + CBL( int run, int buff_size, float *in_buff, @@ -59,17 +59,20 @@ public: int sample_rate, double tau ); - static void destroy_cbl (CBL *a); - static void flush_cbl (CBL *a); - static void xcbl (CBL *a); - static void setBuffers_cbl (CBL *a, float* in, float* out); - static void setSamplerate_cbl (CBL *a, int rate); - static void setSize_cbl (CBL *a, int size); - // RXA Properties - static void SetCBLRun(RXA& rxa, int setit); + CBL(const CBL&) = delete; + CBL& operator=(CBL& other) = delete; + ~CBL() = default; + + void flush(); + void execute(); + void setBuffers(float* in, float* out); + void setSamplerate(int rate); + void setSize(int size); + // Public Properties + void setRun(int setit); private: - static void calc_cbl (CBL *a); + void calc(); }; } // namespace WDSP diff --git a/wdsp/ssql.cpp b/wdsp/ssql.cpp index f6213b445..0d6283585 100644 --- a/wdsp/ssql.cpp +++ b/wdsp/ssql.cpp @@ -140,7 +140,7 @@ void SSQL::compute_ssql_slews(SSQL *a) void SSQL::calc_ssql (SSQL *a) { a->b1 = new float[a->size * 2]; // (float*) malloc0 (a->size * sizeof (complex)); - a->dcbl = CBL::create_cbl (1, a->size, a->in, a->b1, 0, a->rate, 0.02); + a->dcbl = new CBL(1, a->size, a->in, a->b1, 0, a->rate, 0.02); a->ibuff = new float[a->size]; // (float*) malloc0 (a->size * sizeof (float)); a->ftovbuff = new float[a->size]; // (float*) malloc0(a->size * sizeof (float)); a->cvtr = FTOV::create_ftov (1, a->size, a->rate, a->ftov_rsize, a->ftov_fmax, a->ibuff, a->ftovbuff); @@ -175,7 +175,7 @@ void SSQL::decalc_ssql (SSQL *a) FTOV::destroy_ftov (a->cvtr); delete[] (a->ftovbuff); delete[] (a->ibuff); - CBL::destroy_cbl (a->dcbl); + delete (a->dcbl); delete[] (a->b1); delete[] (a->cdown); delete[] (a->cup); @@ -230,7 +230,7 @@ void SSQL::flush_ssql (SSQL *a) { std::fill(a->b1, a->b1 + a->size * 2, 0); - CBL::flush_cbl (a->dcbl); + a->dcbl->flush(); memset (a->ibuff, 0, a->size * sizeof (float)); memset (a->ftovbuff, 0, a->size * sizeof (float)); FTOV::flush_ftov (a->cvtr); @@ -252,7 +252,7 @@ void SSQL::xssql (SSQL *a) { if (a->run) { - CBL::xcbl (a->dcbl); // dc block the input signal + a->dcbl->execute(); // dc block the input signal for (int i = 0; i < a->size; i++) // extract 'I' component a->ibuff[i] = a->b1[2 * i]; FTOV::xftov (a->cvtr); // convert frequency to voltage, ignoring amplitude