From 3c2192603b3deb92a7ba4806f67576f54b1f5f5a Mon Sep 17 00:00:00 2001 From: f4exb Date: Sun, 28 Jul 2024 11:36:45 +0200 Subject: [PATCH] WDSP: use vectors instead of C arrays and disable copy constructor (more) and other changes --- plugins/channelrx/wdsprx/wdsprxsink.cpp | 10 ++-- wdsp/RXA.cpp | 75 ++++++++++++++++++++++--- wdsp/RXA.hpp | 6 ++ wdsp/amd.hpp | 15 +++-- wdsp/amsq.cpp | 24 ++------ wdsp/amsq.hpp | 21 +++---- wdsp/anf.cpp | 21 ------- wdsp/anf.hpp | 1 - wdsp/anr.cpp | 20 ------- wdsp/anr.hpp | 1 - wdsp/bpsnba.hpp | 1 + wdsp/emnr.cpp | 19 ------- wdsp/emnr.hpp | 1 - wdsp/eqp.cpp | 49 +++++++--------- wdsp/eqp.hpp | 7 ++- wdsp/fmd.cpp | 14 ++--- wdsp/fmd.hpp | 5 +- wdsp/fmsq.cpp | 17 +++--- wdsp/fmsq.hpp | 14 +++-- wdsp/meter.cpp | 7 ++- 20 files changed, 160 insertions(+), 168 deletions(-) diff --git a/plugins/channelrx/wdsprx/wdsprxsink.cpp b/plugins/channelrx/wdsprx/wdsprxsink.cpp index 389673e37..d03c380b1 100644 --- a/plugins/channelrx/wdsprx/wdsprxsink.cpp +++ b/plugins/channelrx/wdsprx/wdsprxsink.cpp @@ -486,18 +486,18 @@ void WDSPRxSink::applySettings(const WDSPRxSettings& settings, bool force) if ((m_settings.m_dnr != settings.m_dnr) || (m_settings.m_nrScheme != settings.m_nrScheme) || force) { - WDSP::ANR::SetANRRun(*m_rxa, 0); - WDSP::EMNR::SetEMNRRun(*m_rxa, 0); + WDSP::RXA::SetANRRun(*m_rxa, 0); + WDSP::RXA::SetEMNRRun(*m_rxa, 0); if (settings.m_dnr) { switch (settings.m_nrScheme) { case WDSPRxProfile::NRSchemeNR: - WDSP::ANR::SetANRRun(*m_rxa, 1); + WDSP::RXA::SetANRRun(*m_rxa, 1); break; case WDSPRxProfile::NRSchemeNR2: - WDSP::EMNR::SetEMNRRun(*m_rxa, 1); + WDSP::RXA::SetEMNRRun(*m_rxa, 1); break; default: break; @@ -560,7 +560,7 @@ void WDSPRxSink::applySettings(const WDSPRxSettings& settings, bool force) } if ((m_settings.m_anf != settings.m_anf) || force) { - WDSP::ANF::SetANFRun(*m_rxa, settings.m_anf ? 1 : 0); + WDSP::RXA::SetANFRun(*m_rxa, settings.m_anf ? 1 : 0); } // Caution: Causes corruption diff --git a/wdsp/RXA.cpp b/wdsp/RXA.cpp index 9d0a6f60a..4c1d700d1 100644 --- a/wdsp/RXA.cpp +++ b/wdsp/RXA.cpp @@ -289,7 +289,7 @@ RXA* RXA::create_rxa ( rxa->dsp_size, // buffer size rxa->midbuff, // pointer to input signal buffer rxa->midbuff, // pointer to output signal buffer - rxa->fmd->audio, // pointer to trigger buffer + rxa->fmd->audio.data(), // pointer to trigger buffer rxa->dsp_rate, // sample rate 5000.0, // cutoff freq for noise filter (Hz) &rxa->fmd->pllpole, // pointer to pole frequency of the fmd pll (Hz) @@ -760,9 +760,9 @@ void RXA::setDSPSamplerate (RXA *rxa, int dsp_rate) rxa->amsq->setSamplerate(rxa->dsp_rate); rxa->amd->setSamplerate(rxa->dsp_rate); rxa->fmd->setSamplerate(rxa->dsp_rate); - rxa->fmsq->setBuffers(rxa->midbuff, rxa->midbuff, rxa->fmd->audio); + rxa->fmsq->setBuffers(rxa->midbuff, rxa->midbuff, rxa->fmd->audio.data()); rxa->fmsq->setSamplerate(rxa->dsp_rate); - rxa->snba->setSamplerate(rxa->dsp_rate); + // rxa->snba->setSamplerate(rxa->dsp_rate); SMBA removed rxa->eqp->setSamplerate(rxa->dsp_rate); ANF::setSamplerate_anf (rxa->anf, rxa->dsp_rate); ANR::setSamplerate_anr (rxa->anr, rxa->dsp_rate); @@ -831,7 +831,7 @@ void RXA::setDSPBuffsize (RXA *rxa, int dsp_size) rxa->amd->setSize(rxa->dsp_size); rxa->fmd->setBuffers(rxa->midbuff, rxa->midbuff); rxa->fmd->setSize(rxa->dsp_size); - rxa->fmsq->setBuffers(rxa->midbuff, rxa->midbuff, rxa->fmd->audio); + rxa->fmsq->setBuffers(rxa->midbuff, rxa->midbuff, rxa->fmd->audio.data()); rxa->fmsq->setSize(rxa->dsp_size); rxa->snba->setBuffers(rxa->midbuff, rxa->midbuff); rxa->snba->setSize(rxa->dsp_size); @@ -1225,20 +1225,20 @@ void RXA::NBPSetAutoIncrease (RXA& rxa, int autoincr) } } -void RXA::SetAMDRun(RXA& rxa, int _run) +void RXA::SetAMDRun(RXA& rxa, int run) { - if (rxa.amd->run != _run) + if (rxa.amd->run != run) { RXA::bp1Check ( rxa, - _run, + run, rxa.snba->run, rxa.emnr->run, rxa.anf->run, rxa.anr->run ); - rxa.amd->run = _run; + rxa.amd->run = run; RXA::bp1Set (rxa); } } @@ -1264,6 +1264,65 @@ void RXA::SetSNBARun (RXA& rxa, int run) } } +void RXA::SetANFRun (RXA& rxa, int run) +{ + ANF *a = rxa.anf; + + if (a->run != run) + { + RXA::bp1Check ( + rxa, + rxa.amd->run, + rxa.snba->run, + rxa.emnr->run, + run, + rxa.anr->run + ); + a->run = run; + RXA::bp1Set (rxa); + ANF::flush_anf (a); + } +} + +void RXA::SetANRRun (RXA& rxa, int run) +{ + ANR *a = rxa.anr; + + if (a->run != run) + { + RXA::bp1Check ( + rxa, + rxa.amd->run, + rxa.snba->run, + rxa.emnr->run, + rxa.anf->run, + run + ); + a->run = run; + RXA::bp1Set (rxa); + ANR::flush_anr (a); + } +} + +void RXA::SetEMNRRun (RXA& rxa, int run) +{ + EMNR *a = rxa.emnr; + + if (a->run != run) + { + RXA::bp1Check ( + rxa, + rxa.amd->run, + rxa.snba->run, + run, + rxa.anf->run, + rxa.anr->run + ); + a->run = run; + RXA::bp1Set (rxa); + } +} + /******************************************************************************************************** * * * Collectives * diff --git a/wdsp/RXA.hpp b/wdsp/RXA.hpp index 2fe18254a..26eb6167e 100644 --- a/wdsp/RXA.hpp +++ b/wdsp/RXA.hpp @@ -171,6 +171,12 @@ public: static void SetAMDRun(RXA& rxa, int run); // SNBA static void SetSNBARun (RXA& rxa, int run); + // ANF + static void SetANFRun (RXA& rxa, int run); + // ANR + static void SetANRRun (RXA& rxa, int run); + // EMNR + static void SetEMNRRun (RXA& rxa, int run); // Collectives static void SetPassband (RXA& rxa, float f_low, float f_high); diff --git a/wdsp/amd.hpp b/wdsp/amd.hpp index 5a9a243de..6b955587c 100644 --- a/wdsp/amd.hpp +++ b/wdsp/amd.hpp @@ -37,6 +37,8 @@ warren@wpratt.com #define OUT_IDX (3 * STAGES) #endif +#include + #include "export.h" namespace WDSP { @@ -68,12 +70,12 @@ public: double onem_mtauR; // 1.0 - carrier_removal_multiplier double mtauI; // carrier insertion multiplier double onem_mtauI; // 1.0 - carrier_insertion_multiplier - double a[3 * STAGES + 3]; // Filter a variables - double b[3 * STAGES + 3]; // Filter b variables - double c[3 * STAGES + 3]; // Filter c variables - double d[3 * STAGES + 3]; // Filter d variables - double c0[STAGES]; // Filter coefficients - path 0 - double c1[STAGES]; // Filter coefficients - path 1 + std::array a; // Filter a variables + std::array b; // Filter b variables + std::array c; // Filter c variables + std::array d; // Filter d variables + std::array c0; // Filter coefficients - path 0 + std::array c1; // Filter coefficients - path 1 double dsI; // delayed sample, I path double dsQ; // delayed sample, Q path double dc_insert; // dc component to insert in output @@ -97,6 +99,7 @@ public: double tauR, double tauI ); + AMD(const AMD&) = delete; ~AMD() = default; void init(); diff --git a/wdsp/amsq.cpp b/wdsp/amsq.cpp index 25a82c389..215646c12 100644 --- a/wdsp/amsq.cpp +++ b/wdsp/amsq.cpp @@ -58,27 +58,20 @@ void AMSQ::compute_slews() void AMSQ::calc() { // signal averaging - trigsig = new float[size * 2]; + trigsig.resize(size * 2); avm = exp(-1.0 / (rate * avtau)); onem_avm = 1.0 - avm; avsig = 0.0; // level change ntup = (int)(tup * rate); ntdown = (int)(tdown * rate); - cup = new double[(ntup + 1) * 2]; // (float *)malloc0((ntup + 1) * sizeof(float)); - cdown = new double[(ntdown + 1) * 2]; // (float *)malloc0((ntdown + 1) * sizeof(float)); + cup.resize((ntup + 1) * 2); // (float *)malloc0((ntup + 1) * sizeof(float)); + cdown.resize((ntdown + 1) * 2); // (float *)malloc0((ntdown + 1) * sizeof(float)); compute_slews(); // control state = 0; } -void AMSQ::decalc() -{ - delete[] cdown; - delete[] cup; - delete[] trigsig; -} - AMSQ::AMSQ ( int _run, int _size, @@ -113,14 +106,9 @@ AMSQ::AMSQ ( calc(); } -AMSQ::~AMSQ() -{ - decalc(); -} - void AMSQ::flush() { - std::fill(trigsig, trigsig + size * 2, 0); + std::fill(trigsig.begin(), trigsig.end(), 0); avsig = 0.0; state = 0; } @@ -222,7 +210,7 @@ void AMSQ::execute() void AMSQ::xcap() { - std::copy(trigger, trigger + size * 2, trigsig); + std::copy(trigger, trigger + size * 2, trigsig.begin()); } void AMSQ::setBuffers(float* _in, float* _out, float* _trigger) @@ -234,14 +222,12 @@ void AMSQ::setBuffers(float* _in, float* _out, float* _trigger) void AMSQ::setSamplerate(int _rate) { - decalc(); rate = _rate; calc(); } void AMSQ::setSize(int _size) { - decalc(); size = _size; calc(); } diff --git a/wdsp/amsq.hpp b/wdsp/amsq.hpp index f9acdf76b..5e48303b9 100644 --- a/wdsp/amsq.hpp +++ b/wdsp/amsq.hpp @@ -27,6 +27,8 @@ warren@wpratt.com #ifndef _amsq_h #define _amsq_h +#include + #include "export.h" namespace WDSP { @@ -37,25 +39,25 @@ class TXA; class WDSP_API AMSQ { public: - int run; // 0 if squelch system is OFF; 1 if it's ON - int size; // size of input/output buffers + int run; // 0 if squelch system is OFF; 1 if it's ON + int size; // size of input/output buffers float* in; // squelch input signal buffer float* out; // squelch output signal buffer float* trigger; // pointer to trigger data source - float* trigsig; // buffer containing trigger signal - double rate; // sample rate - double avtau; // time constant for averaging noise + std::vector trigsig; // buffer containing trigger signal + double rate; // sample rate + double avtau; // time constant for averaging noise double avm; double onem_avm; double avsig; - int state; // state machine control + int state; // state machine control int count; double tup; double tdown; int ntup; int ntdown; - double* cup; - double* cdown; + std::vector cup; + std::vector cdown; double tail_thresh; double unmute_thresh; double min_tail; @@ -79,7 +81,7 @@ public: double _muted_gain ); AMSQ(const AMSQ&) = delete; - ~AMSQ(); + ~AMSQ() = default; void flush(); void execute(); @@ -96,7 +98,6 @@ public: private: void compute_slews(); void calc(); - void decalc(); }; } // namespace WDSP diff --git a/wdsp/anf.cpp b/wdsp/anf.cpp index e08ce1a67..f4560f51f 100644 --- a/wdsp/anf.cpp +++ b/wdsp/anf.cpp @@ -182,27 +182,6 @@ void ANF::setSize_anf (ANF *a, int size) * * ********************************************************************************************************/ -void ANF::SetANFRun (RXA& rxa, int run) -{ - ANF *a = rxa.anf; - - if (a->run != run) - { - RXA::bp1Check ( - rxa, - rxa.amd->run, - rxa.snba->run, - rxa.emnr->run, - run, - rxa.anr->run - ); - a->run = run; - RXA::bp1Set (rxa); - flush_anf (a); - } -} - - void ANF::SetANFVals (RXA& rxa, int taps, int delay, double gain, double leakage) { rxa.anf->n_taps = taps; diff --git a/wdsp/anf.hpp b/wdsp/anf.hpp index 6b9ef6006..987495225 100644 --- a/wdsp/anf.hpp +++ b/wdsp/anf.hpp @@ -87,7 +87,6 @@ public: static void setSamplerate_anf (ANF *a, int rate); static void setSize_anf (ANF *a, int size); // RXA Properties - static void SetANFRun (RXA& rxa, int setit); static void SetANFVals (RXA& rxa, int taps, int delay, double gain, double leakage); static void SetANFTaps (RXA& rxa, int taps); static void SetANFDelay (RXA& rxa, int delay); diff --git a/wdsp/anr.cpp b/wdsp/anr.cpp index 6dcadb664..8fe3d5b5b 100644 --- a/wdsp/anr.cpp +++ b/wdsp/anr.cpp @@ -182,26 +182,6 @@ void ANR::setSize_anr (ANR *a, int size) * * ********************************************************************************************************/ -void ANR::SetANRRun (RXA& rxa, int run) -{ - ANR *a = rxa.anr; - - if (a->run != run) - { - RXA::bp1Check ( - rxa, - rxa.amd->run, - rxa.snba->run, - rxa.emnr->run, - rxa.anf->run, - run - ); - a->run = run; - RXA::bp1Set (rxa); - flush_anr (a); - } -} - void ANR::SetANRVals (RXA& rxa, int taps, int delay, double gain, double leakage) { rxa.anr->n_taps = taps; diff --git a/wdsp/anr.hpp b/wdsp/anr.hpp index c951c0c14..c0640d00f 100644 --- a/wdsp/anr.hpp +++ b/wdsp/anr.hpp @@ -89,7 +89,6 @@ public: static void setSamplerate_anr (ANR *a, int rate); static void setSize_anr (ANR *a, int size); // RXA Properties - static void SetANRRun (RXA& rxa, int setit); static void SetANRVals (RXA& rxa, int taps, int delay, double gain, double leakage); static void SetANRTaps (RXA& rxa, int taps); static void SetANRDelay (RXA& rxa, int delay); diff --git a/wdsp/bpsnba.hpp b/wdsp/bpsnba.hpp index 4e79f6744..a5b320afa 100644 --- a/wdsp/bpsnba.hpp +++ b/wdsp/bpsnba.hpp @@ -79,6 +79,7 @@ public: int maxpb, NOTCHDB* notchdb ); + BPSNBA(const BPSNBA&) = delete; ~BPSNBA(); void flush(); diff --git a/wdsp/emnr.cpp b/wdsp/emnr.cpp index a0bc55cee..20091f0be 100644 --- a/wdsp/emnr.cpp +++ b/wdsp/emnr.cpp @@ -1071,25 +1071,6 @@ void EMNR::setSize_emnr (EMNR *a, int size) * * ********************************************************************************************************/ -void EMNR::SetEMNRRun (RXA& rxa, int run) -{ - EMNR *a = rxa.emnr; - - if (a->run != run) - { - RXA::bp1Check ( - rxa, - rxa.amd->run, - rxa.snba->run, - run, - rxa.anf->run, - rxa.anr->run - ); - a->run = run; - RXA::bp1Set (rxa); - } -} - void EMNR::SetEMNRgainMethod (RXA& rxa, int method) { rxa.emnr->g.gain_method = method; diff --git a/wdsp/emnr.hpp b/wdsp/emnr.hpp index b3024194d..dadeb0176 100644 --- a/wdsp/emnr.hpp +++ b/wdsp/emnr.hpp @@ -185,7 +185,6 @@ public: static void setSamplerate_emnr (EMNR *a, int rate); static void setSize_emnr (EMNR *a, int size); // RXA Properties - static void SetEMNRRun (RXA& rxa, int run); static void SetEMNRgainMethod (RXA& rxa, int method); static void SetEMNRnpeMethod (RXA& rxa, int method); static void SetEMNRaeRun (RXA& rxa, int run); diff --git a/wdsp/eqp.cpp b/wdsp/eqp.cpp index 651d0a7e8..4dda77be2 100644 --- a/wdsp/eqp.cpp +++ b/wdsp/eqp.cpp @@ -222,14 +222,14 @@ EQP::EQP( in = _in; out = _out; nfreqs = _nfreqs; - F = new float[nfreqs + 1]; // (float *) malloc0 ((nfreqs + 1) * sizeof (float)); - G = new float[nfreqs + 1]; // (float *) malloc0 ((nfreqs + 1) * sizeof (float)); - memcpy (F, _F, (_nfreqs + 1) * sizeof (float)); - memcpy (G, _G, (_nfreqs + 1) * sizeof (float)); + F.resize(nfreqs + 1); // (float *) malloc0 ((nfreqs + 1) * sizeof (float)); + G.resize(nfreqs + 1); // (float *) malloc0 ((nfreqs + 1) * sizeof (float)); + std::copy(_F, _F + (_nfreqs + 1), F.begin()); + std::copy(_G, _G + (_nfreqs + 1), G.begin()); ctfmode = _ctfmode; wintype = _wintype; samplerate = (double) _samplerate; - impulse = eq_impulse (nc, nfreqs, F, G, samplerate, 1.0 / (2.0 * size), ctfmode, wintype); + impulse = eq_impulse (nc, nfreqs, F.data(), G.data(), samplerate, 1.0 / (2.0 * size), ctfmode, wintype); fircore = FIRCORE::create_fircore (size, in, out, nc, mp, impulse); delete[] (impulse); } @@ -263,7 +263,7 @@ void EQP::setSamplerate(int rate) { float* impulse; samplerate = rate; - impulse = eq_impulse (nc, nfreqs, F, G, samplerate, 1.0 / (2.0 * size), ctfmode, wintype); + impulse = eq_impulse (nc, nfreqs, F.data(), G.data(), samplerate, 1.0 / (2.0 * size), ctfmode, wintype); FIRCORE::setImpulse_fircore (fircore, impulse, 1); delete[] (impulse); } @@ -273,7 +273,7 @@ void EQP::setSize(int _size) float* impulse; size = _size; FIRCORE::setSize_fircore (fircore, size); - impulse = eq_impulse (nc, nfreqs, F, G, samplerate, 1.0 / (2.0 * size), ctfmode, wintype); + impulse = eq_impulse (nc, nfreqs, F.data(), G.data(), samplerate, 1.0 / (2.0 * size), ctfmode, wintype); FIRCORE::setImpulse_fircore (fircore, impulse, 1); delete[] (impulse); } @@ -296,7 +296,7 @@ void EQP::setNC(int _nc) if (nc != _nc) { nc = _nc; - impulse = eq_impulse (nc, nfreqs, F, G, samplerate, 1.0 / (2.0 * size), ctfmode, wintype); + impulse = eq_impulse (nc, nfreqs, F.data(), G.data(), samplerate, 1.0 / (2.0 * size), ctfmode, wintype); FIRCORE::setNc_fircore (fircore, nc, impulse); delete[] (impulse); } @@ -314,15 +314,12 @@ void EQP::setMP(int _mp) void EQP::setProfile(int _nfreqs, const float* _F, const float* _G) { float* impulse; - delete[] (G); - delete[] (F); nfreqs = _nfreqs; - F = new float[nfreqs + 1]; // (float *) malloc0 ((nfreqs + 1) * sizeof (float)); - G = new float[nfreqs + 1]; // (float *) malloc0 ((nfreqs + 1) * sizeof (float)); - memcpy (F, _F, (_nfreqs + 1) * sizeof (float)); - memcpy (G, _G, (_nfreqs + 1) * sizeof (float)); - impulse = eq_impulse (nc, nfreqs, F, G, - samplerate, 1.0 / (2.0 * size), ctfmode, wintype); + F.resize(nfreqs + 1); // (float *) malloc0 ((nfreqs + 1) * sizeof (float)); + G.resize(nfreqs + 1); // (float *) malloc0 ((nfreqs + 1) * sizeof (float)); + std::copy(_F, _F + (_nfreqs + 1), F.begin()); + std::copy(_G, _G + (_nfreqs + 1), G.begin()); + impulse = eq_impulse (nc, nfreqs, F.data(), G.data(), samplerate, 1.0 / (2.0 * size), ctfmode, wintype); FIRCORE::setImpulse_fircore (fircore, impulse, 1); delete[] (impulse); } @@ -331,7 +328,7 @@ void EQP::setCtfmode(int _mode) { float* impulse; ctfmode = _mode; - impulse = eq_impulse (nc, nfreqs, F, G, samplerate, 1.0 / (2.0 * size), ctfmode, wintype); + impulse = eq_impulse (nc, nfreqs, F.data(), G.data(), samplerate, 1.0 / (2.0 * size), ctfmode, wintype); FIRCORE::setImpulse_fircore (fircore, impulse, 1); delete[] (impulse); } @@ -340,7 +337,7 @@ void EQP::setWintype(int _wintype) { float* impulse; wintype = _wintype; - impulse = eq_impulse (nc, nfreqs, F, G, samplerate, 1.0 / (2.0 * size), ctfmode, wintype); + impulse = eq_impulse (nc, nfreqs, F.data(), G.data(), samplerate, 1.0 / (2.0 * size), ctfmode, wintype); FIRCORE::setImpulse_fircore (fircore, impulse, 1); delete[] (impulse); } @@ -348,11 +345,9 @@ void EQP::setWintype(int _wintype) void EQP::setGrphEQ(int *rxeq) { // three band equalizer (legacy compatibility) float* impulse; - delete[] (G); - delete[] (F); nfreqs = 4; - F = new float[nfreqs + 1]; // (float *) malloc0 ((nfreqs + 1) * sizeof (float)); - G = new float[nfreqs + 1]; // (float *) malloc0 ((nfreqs + 1) * sizeof (float)); + F.resize(nfreqs + 1); // (float *) malloc0 ((nfreqs + 1) * sizeof (float)); + G.resize(nfreqs + 1); // (float *) malloc0 ((nfreqs + 1) * sizeof (float)); F[1] = 150.0; F[2] = 400.0; F[3] = 1500.0; @@ -363,7 +358,7 @@ void EQP::setGrphEQ(int *rxeq) G[3] = (float)rxeq[2]; G[4] = (float)rxeq[3]; ctfmode = 0; - impulse = eq_impulse (nc, nfreqs, F, G, samplerate, 1.0 / (2.0 * size), ctfmode, wintype); + impulse = eq_impulse (nc, nfreqs, F.data(), G.data(), samplerate, 1.0 / (2.0 * size), ctfmode, wintype); FIRCORE::setImpulse_fircore (fircore, impulse, 1); delete[] (impulse); } @@ -372,11 +367,9 @@ void EQP::setGrphEQ10(int *rxeq) { // ten band equalizer (legacy compatibility) float* impulse; int i; - delete[] (G); - delete[] (F); nfreqs = 10; - F = new float[nfreqs + 1]; // (float *) malloc0 ((nfreqs + 1) * sizeof (float)); - G = new float[nfreqs + 1]; // (float *) malloc0 ((nfreqs + 1) * sizeof (float)); + F.resize(nfreqs + 1); // (float *) malloc0 ((nfreqs + 1) * sizeof (float)); + G.resize(nfreqs + 1); // (float *) malloc0 ((nfreqs + 1) * sizeof (float)); F[1] = 32.0; F[2] = 63.0; F[3] = 125.0; @@ -390,7 +383,7 @@ void EQP::setGrphEQ10(int *rxeq) for (i = 0; i <= nfreqs; i++) G[i] = (float)rxeq[i]; ctfmode = 0; - impulse = eq_impulse (nc, nfreqs, F, G, samplerate, 1.0 / (2.0 * size), ctfmode, wintype); + impulse = eq_impulse (nc, nfreqs, F.data(), G.data(), samplerate, 1.0 / (2.0 * size), ctfmode, wintype); // print_impulse ("rxeq.txt", nc, impulse, 1, 0); FIRCORE::setImpulse_fircore (fircore, impulse, 1); delete[] (impulse); diff --git a/wdsp/eqp.hpp b/wdsp/eqp.hpp index 3d1430a25..086bd42ab 100644 --- a/wdsp/eqp.hpp +++ b/wdsp/eqp.hpp @@ -34,6 +34,8 @@ warren@wpratt.com #ifndef wdsp_eqp_h #define wdsp_eqp_h +#include + #include "export.h" namespace WDSP { @@ -52,8 +54,8 @@ public: float* in; float* out; int nfreqs; - float* F; - float* G; + std::vector F; + std::vector G; int ctfmode; int wintype; double samplerate; @@ -73,6 +75,7 @@ public: int wintype, int samplerate ); + EQP(const EQP&) = delete; ~EQP(); void flush(); diff --git a/wdsp/fmd.cpp b/wdsp/fmd.cpp index 449658a29..27de2f753 100644 --- a/wdsp/fmd.cpp +++ b/wdsp/fmd.cpp @@ -136,9 +136,9 @@ FMD::FMD( float* impulse; calc(); // de-emphasis filter - audio = new float[size * 2]; // (float *) malloc0 (size * sizeof (complex)); + audio.resize(size * 2); // (float *) malloc0 (size * sizeof (complex)); impulse = FCurve::fc_impulse (nc_de, f_low, f_high, +20.0 * log10(f_high / f_low), 0.0, 1, rate, 1.0 / (2.0 * size), 0, 0); - pde = FIRCORE::create_fircore (size, audio, out, nc_de, mp_de, impulse); + pde = FIRCORE::create_fircore (size, audio.data(), out, nc_de, mp_de, impulse); delete[] (impulse); // audio filter impulse = FIR::fir_bandpass(nc_aud, 0.8 * f_low, 1.1 * f_high, rate, 0, 1, afgain / (2.0 * size)); @@ -150,13 +150,12 @@ FMD::~FMD() { FIRCORE::destroy_fircore (paud); FIRCORE::destroy_fircore (pde); - delete[] (audio); decalc(); } void FMD::flush() { - std::fill(audio, audio + size * 2, 0); + std::fill(audio.begin(), audio.end(), 0); FIRCORE::flush_fircore (pde); FIRCORE::flush_fircore (paud); phs = 0.0; @@ -219,7 +218,7 @@ void FMD::setBuffers(float* _in, float* _out) in = _in; out = _out; calc(); - FIRCORE::setBuffers_fircore (pde, audio, out); + FIRCORE::setBuffers_fircore (pde, audio.data(), out); FIRCORE::setBuffers_fircore (paud, out, out); WCPAGC::setBuffers_wcpagc (plim, out, out); } @@ -245,14 +244,13 @@ void FMD::setSize(int _size) { float* impulse; decalc(); - delete[] (audio); size = _size; calc(); - audio = new float[size * 2]; // (float *) malloc0 (size * sizeof (complex)); + audio.resize(size * 2); // (float *) malloc0 (size * sizeof (complex)); // de-emphasis filter FIRCORE::destroy_fircore (pde); impulse = FCurve::fc_impulse (nc_de, f_low, f_high, +20.0 * log10(f_high / f_low), 0.0, 1, rate, 1.0 / (2.0 * size), 0, 0); - pde = FIRCORE::create_fircore (size, audio, out, nc_de, mp_de, impulse); + pde = FIRCORE::create_fircore (size, audio.data(), out, nc_de, mp_de, impulse); delete[] (impulse); // audio filter FIRCORE::destroy_fircore (paud); diff --git a/wdsp/fmd.hpp b/wdsp/fmd.hpp index 3b47b045d..f8e37be77 100644 --- a/wdsp/fmd.hpp +++ b/wdsp/fmd.hpp @@ -28,6 +28,8 @@ warren@wpratt.com #ifndef wdsp_fmd_h #define wdsp_fmd_h +#include + #include "export.h" namespace WDSP { @@ -67,7 +69,7 @@ public: double deviation; double again; // for de-emphasis filter - float* audio; + std::vector audio; FIRCORE *pde; int nc_de; int mp_de; @@ -108,6 +110,7 @@ public: int nc_aud, int mp_aud ); + FMD(const FMD&) = delete; ~FMD(); void flush(); diff --git a/wdsp/fmsq.cpp b/wdsp/fmsq.cpp index fb673a954..74a9891e9 100644 --- a/wdsp/fmsq.cpp +++ b/wdsp/fmsq.cpp @@ -38,7 +38,7 @@ void FMSQ::calc() float* impulse; int i; // noise filter - noise = new float[2 * size * 2]; // (float *)malloc0(2 * size * sizeof(complex)); + noise.resize(2 * size * 2); // (float *)malloc0(2 * size * sizeof(complex)); F[0] = 0.0; F[1] = fc; F[2] = *pllpole; @@ -47,8 +47,8 @@ void FMSQ::calc() G[1] = 0.0; G[2] = 3.0; G[3] = +20.0 * log10(20000.0 / *pllpole); - impulse = EQP::eq_impulse (nc, 3, F, G, rate, 1.0 / (2.0 * size), 0, 0); - p = FIRCORE::create_fircore (size, trigger, noise, nc, mp, impulse); + impulse = EQP::eq_impulse (nc, 3, F.data(), G.data(), rate, 1.0 / (2.0 * size), 0, 0); + p = FIRCORE::create_fircore (size, trigger, noise.data(), nc, mp, impulse); delete[] (impulse); // noise averaging avm = exp(-1.0 / (rate * avtau)); @@ -60,8 +60,8 @@ void FMSQ::calc() // level change ntup = (int)(tup * rate); ntdown = (int)(tdown * rate); - cup = new double[ntup + 1]; // (float *)malloc0 ((ntup + 1) * sizeof(float)); - cdown = new double[ntdown + 1]; //(float *)malloc0 ((ntdown + 1) * sizeof(float)); + cup.resize(ntup + 1); // (float *)malloc0 ((ntup + 1) * sizeof(float)); + cdown.resize(ntdown + 1); //(float *)malloc0 ((ntdown + 1) * sizeof(float)); delta = PI / (double) ntup; theta = 0.0; @@ -88,10 +88,7 @@ void FMSQ::calc() void FMSQ::decalc() { - delete[] (cdown); - delete[] (cup); FIRCORE::destroy_fircore (p); - delete[] (noise); } FMSQ::FMSQ( @@ -261,7 +258,7 @@ void FMSQ::setBuffers(float* in, float* out, float* trig) insig = in; outsig = out; trigger = trig; - FIRCORE::setBuffers_fircore (p, trigger, noise); + FIRCORE::setBuffers_fircore (p, trigger, noise.data()); } void FMSQ::setSamplerate(int _rate) @@ -302,7 +299,7 @@ void FMSQ::setNC(int _nc) if (nc != _nc) { nc = _nc; - impulse = EQP::eq_impulse (nc, 3, F, G, rate, 1.0 / (2.0 * size), 0, 0); + impulse = EQP::eq_impulse (nc, 3, F.data(), G.data(), rate, 1.0 / (2.0 * size), 0, 0); FIRCORE::setNc_fircore (p, nc, impulse); delete[] (impulse); } diff --git a/wdsp/fmsq.hpp b/wdsp/fmsq.hpp index 97f47573f..02d2b13df 100644 --- a/wdsp/fmsq.hpp +++ b/wdsp/fmsq.hpp @@ -28,6 +28,9 @@ warren@wpratt.com #ifndef wdsp_fmsq_h #define wdsp_fmsq_h +#include +#include + #include "export.h" namespace WDSP { @@ -43,11 +46,11 @@ public: float* outsig; // squelch output signal buffer float* trigger; // buffer used to trigger mute/unmute (may be same as input; matches timing of input buffer) double rate; // sample rate - float* noise; + std::vector noise; double fc; // corner frequency for sig / noise detection double* pllpole; // pointer to pole frequency of the fm demodulator pll - float F[4]; - float G[4]; + std::array F; + std::array G; double avtau; // time constant for averaging noise double avm; double onem_avm; @@ -62,8 +65,8 @@ public: double tdown; int ntup; int ntdown; - double* cup; - double* cdown; + std::vector cup; + std::vector cdown; double tail_thresh; double unmute_thresh; double min_tail; @@ -97,6 +100,7 @@ public: int _nc, int _mp ); + FMSQ(const FMSQ&) = delete; ~FMSQ(); void flush(); diff --git a/wdsp/meter.cpp b/wdsp/meter.cpp index 6b9bd2a12..5ad168920 100644 --- a/wdsp/meter.cpp +++ b/wdsp/meter.cpp @@ -109,11 +109,11 @@ void METER::execute() if (np > peak) peak = np; - result[enum_av] = 10.0 * MemLog::mlog10 (avg + 1.0e-40); - result[enum_pk] = 10.0 * MemLog::mlog10 (peak + 1.0e-40); + result[enum_av] = 10.0 * MemLog::mlog10 (avg <= 0 ? 1.0e-20 : avg); + result[enum_pk] = 10.0 * MemLog::mlog10 (peak <= 0 ? 1.0e-20 : peak); if ((pgain != 0) && (enum_gain >= 0)) - result[enum_gain] = 20.0 * MemLog::mlog10 (*pgain + 1.0e-40); + result[enum_gain] = 20.0 * MemLog::mlog10 (*pgain <= 0 ? 1.0e-20 : *pgain); } else { @@ -129,6 +129,7 @@ void METER::execute() void METER::setBuffers(float* in) { buff = in; + flush(); } void METER::setSamplerate(int _rate)