From fe08cd4a789df9bb446eefc8b706a7f37d8f4124 Mon Sep 17 00:00:00 2001 From: f4exb Date: Tue, 6 Aug 2024 06:26:53 +0200 Subject: [PATCH] WDSP: FIRCORE rework --- wdsp/RXA.cpp | 14 +-- wdsp/TXA.cpp | 12 +-- wdsp/bandpass.cpp | 28 ++--- wdsp/bpsnba.cpp | 2 +- wdsp/cfir.cpp | 8 +- wdsp/emphp.cpp | 20 ++-- wdsp/eqp.cpp | 30 +++--- wdsp/fir.cpp | 8 +- wdsp/fir.hpp | 4 +- wdsp/fircore.cpp | 261 +++++++++++++++++++++------------------------- wdsp/fircore.hpp | 59 +++++++---- wdsp/fmd.cpp | 44 ++++---- wdsp/fmmod.cpp | 24 ++--- wdsp/fmsq.cpp | 14 +-- wdsp/icfir.cpp | 43 +++----- wdsp/nbp.cpp | 24 ++--- 16 files changed, 290 insertions(+), 305 deletions(-) diff --git a/wdsp/RXA.cpp b/wdsp/RXA.cpp index 91fef39d9..c030899db 100644 --- a/wdsp/RXA.cpp +++ b/wdsp/RXA.cpp @@ -904,7 +904,7 @@ void RXA::bp1Set () a->run = 0; if (!old && a->run) a->flush(); - FIRCORE::setUpdate_fircore(a->fircore); + a->fircore->setUpdate(); } void RXA::bpsnbaCheck(int _mode, int _notch_run) @@ -989,7 +989,7 @@ void RXA::bpsnbaSet() default: break; } - FIRCORE::setUpdate_fircore(a->bpsnba->fircore); + a->bpsnba->fircore->setUpdate(); } void RXA::updateNBPFiltersLightWeight() @@ -1005,7 +1005,7 @@ void RXA::updateNBPFilters() if (a->fnfrun) { a->calc_impulse(); - FIRCORE::setImpulse_fircore(a->fircore, a->impulse, 1); + a->fircore->setImpulse(a->impulse, 1); delete[] (a->impulse); } if (b->bpsnba->fnfrun) @@ -1097,10 +1097,10 @@ void RXA::nbpSetNotchesRun(int _run) b->fnfrun = a->master_run; bpsnbaCheck(mode, _run); b->calc_impulse(); // recalc nbp impulse response - FIRCORE::setImpulse_fircore(b->fircore, b->impulse, 0); // calculate new filter masks + b->fircore->setImpulse(b->impulse, 0); // calculate new filter masks delete[] (b->impulse); bpsnbaSet(); - FIRCORE::setUpdate_fircore(b->fircore); // apply new filter masks + b->fircore->setUpdate(); // apply new filter masks } } @@ -1115,7 +1115,7 @@ void RXA::nbpSetWindow(int _wintype) { a->wintype = _wintype; a->calc_impulse(); - FIRCORE::setImpulse_fircore(a->fircore, a->impulse, 1); + a->fircore->setImpulse(a->impulse, 1); delete[] (a->impulse); } @@ -1137,7 +1137,7 @@ void RXA::nbpSetAutoIncrease(int _autoincr) { a->autoincr = _autoincr; a->calc_impulse(); - FIRCORE::setImpulse_fircore(a->fircore, a->impulse, 1); + a->fircore->setImpulse(a->impulse, 1); delete[] (a->impulse); } diff --git a/wdsp/TXA.cpp b/wdsp/TXA.cpp index 9521d88a3..f57c1426d 100644 --- a/wdsp/TXA.cpp +++ b/wdsp/TXA.cpp @@ -925,7 +925,7 @@ void TXA::setBandpassNC(int _nc) 1, a->gain / (double)(2 * a->size) ); - FIRCORE::setNc_fircore(a->fircore, a->nc, impulse); + a->fircore->setNc(a->nc, impulse); delete[] impulse; } @@ -943,7 +943,7 @@ void TXA::setBandpassNC(int _nc) 1, a->gain / (double)(2 * a->size) ); - FIRCORE::setNc_fircore(a->fircore, a->nc, impulse); + a->fircore->setNc(a->nc, impulse); delete[] impulse; } @@ -961,7 +961,7 @@ void TXA::setBandpassNC(int _nc) 1, a->gain / (double)(2 * a->size) ); - FIRCORE::setNc_fircore(a->fircore, a->nc, impulse); + a->fircore->setNc(a->nc, impulse); delete[] impulse; } } @@ -974,7 +974,7 @@ void TXA::setBandpassMP(int _mp) if (_mp != a->mp) { a->mp = _mp; - FIRCORE::setMp_fircore(a->fircore, a->mp); + a->fircore->setMp(a->mp); } a = bp1; @@ -982,7 +982,7 @@ void TXA::setBandpassMP(int _mp) if (_mp != a->mp) { a->mp = _mp; - FIRCORE::setMp_fircore(a->fircore, a->mp); + a->fircore->setMp(a->mp); } a = bp2; @@ -990,7 +990,7 @@ void TXA::setBandpassMP(int _mp) if (_mp != a->mp) { a->mp = _mp; - FIRCORE::setMp_fircore(a->fircore, a->mp); + a->fircore->setMp(a->mp); } } diff --git a/wdsp/bandpass.cpp b/wdsp/bandpass.cpp index a730d2106..3bdc00ece 100644 --- a/wdsp/bandpass.cpp +++ b/wdsp/bandpass.cpp @@ -75,24 +75,24 @@ BANDPASS::BANDPASS( 1, gain / (double)(2 * size) ); - fircore = FIRCORE::create_fircore (size, in, out, nc, mp, impulse); + fircore = new FIRCORE(size, in, out, nc, mp, impulse); delete[] impulse; } BANDPASS::~BANDPASS() { - FIRCORE::destroy_fircore (fircore); + delete (fircore); } void BANDPASS::flush() { - FIRCORE::flush_fircore(fircore); + fircore->flush(); } void BANDPASS::execute(int pos) { if (run && position == pos) - FIRCORE::xfircore(fircore); + fircore->execute(); else if (out != in) std::copy(in, in + size * 2, out); } @@ -101,7 +101,7 @@ void BANDPASS::setBuffers(float* _in, float* _out) { in = _in; out = _out; - FIRCORE::setBuffers_fircore(fircore, in, out); + fircore->setBuffers(in, out); } void BANDPASS::setSamplerate(int _rate) @@ -116,7 +116,7 @@ void BANDPASS::setSamplerate(int _rate) 1, gain / (double) (2 * size) ); - FIRCORE::setImpulse_fircore (fircore, impulse, 1); + fircore->setImpulse(impulse, 1); delete[] impulse; } @@ -124,7 +124,7 @@ void BANDPASS::setSize(int _size) { // NOTE: 'size' must be <= 'nc' size = _size; - FIRCORE::setSize_fircore (fircore, size); + fircore->setSize(size); // recalc impulse because scale factor is a function of size float* impulse = FIR::fir_bandpass ( nc, @@ -135,7 +135,7 @@ void BANDPASS::setSize(int _size) 1, gain / (double) (2 * size) ); - FIRCORE::setImpulse_fircore (fircore, impulse, 1); + fircore->setImpulse(impulse, 1); delete[] impulse; } @@ -151,7 +151,7 @@ void BANDPASS::setGain(double _gain, int _update) 1, gain / (double) (2 * size) ); - FIRCORE::setImpulse_fircore (fircore, impulse, _update); + fircore->setImpulse(impulse, _update); delete[] impulse; } @@ -171,7 +171,7 @@ void BANDPASS::calcBandpassFilter(double _f_low, double _f_high, double _gain) 1, gain / (double)(2 * size) ); - FIRCORE::setImpulse_fircore (fircore, impulse, 1); + fircore->setImpulse(impulse, 1); delete[] impulse; } } @@ -196,11 +196,11 @@ void BANDPASS::setBandpassFreqs(double _f_low, double _f_high) gain / (double)(2 * size) ); - FIRCORE::setImpulse_fircore (fircore, impulse, 0); + fircore->setImpulse(impulse, 0); delete[] impulse; f_low = _f_low; f_high = _f_high; - FIRCORE::setUpdate_fircore (fircore); + fircore->setUpdate(); } } @@ -219,7 +219,7 @@ void BANDPASS::SetBandpassNC(int _nc) 1, gain / (double)( 2 * size) ); - FIRCORE::setNc_fircore (fircore, nc, impulse); + fircore->setNc(nc, impulse); delete[] impulse; } } @@ -229,7 +229,7 @@ void BANDPASS::SetBandpassMP(int _mp) if (_mp != mp) { mp = _mp; - FIRCORE::setMp_fircore (fircore, mp); + fircore->setMp(mp); } } diff --git a/wdsp/bpsnba.cpp b/wdsp/bpsnba.cpp index f7a3884f9..6720871ed 100644 --- a/wdsp/bpsnba.cpp +++ b/wdsp/bpsnba.cpp @@ -176,7 +176,7 @@ void BPSNBA::recalc_bpsnba_filter(int update) b->gain = gain; b->autoincr = autoincr; b->calc_impulse(); - FIRCORE::setImpulse_fircore (b->fircore, b->impulse, update); + b->fircore->setImpulse(b->impulse, update); delete[] (b->impulse); } diff --git a/wdsp/cfir.cpp b/wdsp/cfir.cpp index e4def1b4c..1e0b05bf7 100644 --- a/wdsp/cfir.cpp +++ b/wdsp/cfir.cpp @@ -37,13 +37,13 @@ void CFIR::calc_cfir (CFIR *a) float* impulse; a->scale = 1.0 / (float)(2 * a->size); impulse = cfir_impulse (a->nc, a->DD, a->R, a->Pairs, a->runrate, a->cicrate, a->cutoff, a->xtype, a->xbw, 1, a->scale, a->wintype); - a->p = FIRCORE::create_fircore (a->size, a->in, a->out, a->nc, a->mp, impulse); + a->p = new FIRCORE(a->size, a->in, a->out, a->nc, a->mp, impulse); delete[] (impulse); } void CFIR::decalc_cfir (CFIR *a) { - FIRCORE::destroy_fircore (a->p); + delete (a->p); } CFIR* CFIR::create_cfir ( @@ -105,13 +105,13 @@ void CFIR::destroy_cfir (CFIR *a) void CFIR::flush_cfir (CFIR *a) { - FIRCORE::flush_fircore (a->p); + a->p->flush(); } void CFIR::xcfir (CFIR *a) { if (a->run) - FIRCORE::xfircore (a->p); + a->p->execute(); else if (a->in != a->out) std::copy( a->in, a->in + a->size * 2, a->out); } diff --git a/wdsp/emphp.cpp b/wdsp/emphp.cpp index cb1fb8abd..33c7c28d3 100644 --- a/wdsp/emphp.cpp +++ b/wdsp/emphp.cpp @@ -76,7 +76,7 @@ EMPHP::EMPHP( 1.0 / (2.0 * size), 0, 0 ); - p = FIRCORE::create_fircore(size, in, out, nc, mp, impulse); + p = new FIRCORE(size, in, out, nc, mp, impulse); delete[] (impulse); } @@ -87,13 +87,13 @@ EMPHP::~EMPHP() void EMPHP::flush() { - FIRCORE::flush_fircore(p); + p->flush(); } void EMPHP::execute(int _position) { if (run && position == _position) - FIRCORE::xfircore(p); + p->execute(); else if (in != out) std::copy( in, in + size * 2, out); } @@ -102,7 +102,7 @@ void EMPHP::setBuffers(float* _in, float* _out) { in = _in; out = _out; - FIRCORE::setBuffers_fircore(p, in, out); + p->setBuffers(in, out); } void EMPHP::setSamplerate(int _rate) @@ -120,7 +120,7 @@ void EMPHP::setSamplerate(int _rate) 1.0 / (2.0 * size), 0, 0 ); - FIRCORE::setImpulse_fircore(p, impulse, 1); + p->setImpulse(impulse, 1); delete[] (impulse); } @@ -128,7 +128,7 @@ void EMPHP::setSize(int _size) { float* impulse; size = _size; - FIRCORE::setSize_fircore(p, size); + p->setSize(size); impulse = FCurve::fc_impulse ( nc, f_low, @@ -141,7 +141,7 @@ void EMPHP::setSize(int _size) 0, 0 ); - FIRCORE::setImpulse_fircore(p, impulse, 1); + p->setImpulse(impulse, 1); delete[] (impulse); } @@ -161,7 +161,7 @@ void EMPHP::setMP(int _mp) if (mp != _mp) { mp = _mp; - FIRCORE::setMp_fircore(p, mp); + p->setMp(mp); } } @@ -184,7 +184,7 @@ void EMPHP::setNC(int _nc) 0, 0 ); - FIRCORE::setNc_fircore(p, nc, impulse); + p->setNc(nc, impulse); delete[] (impulse); } } @@ -209,7 +209,7 @@ void EMPHP::setFreqs(double low, double high) 0, 0 ); - FIRCORE::setImpulse_fircore(p, impulse, 1); + p->setImpulse(impulse, 1); delete[] (impulse); } } diff --git a/wdsp/eqp.cpp b/wdsp/eqp.cpp index 2edf81b5a..c211e5a2e 100644 --- a/wdsp/eqp.cpp +++ b/wdsp/eqp.cpp @@ -234,24 +234,24 @@ EQP::EQP( wintype = _wintype; samplerate = (double) _samplerate; 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); + fircore = new FIRCORE(size, in, out, nc, mp, impulse); delete[] impulse; } EQP::~EQP() { - FIRCORE::destroy_fircore (fircore); + delete (fircore); } void EQP::flush() { - FIRCORE::flush_fircore (fircore); + fircore->flush(); } void EQP::execute() { if (run) - FIRCORE::xfircore (fircore); + fircore->execute(); else std::copy(in, in + size * 2, out); } @@ -260,7 +260,7 @@ void EQP::setBuffers(float* _in, float* _out) { in = _in; out = _out; - FIRCORE::setBuffers_fircore (fircore, in, out); + fircore->setBuffers(in, out); } void EQP::setSamplerate(int rate) @@ -268,7 +268,7 @@ void EQP::setSamplerate(int rate) float* impulse; samplerate = rate; impulse = eq_impulse (nc, nfreqs, F.data(), G.data(), samplerate, 1.0 / (2.0 * size), ctfmode, wintype); - FIRCORE::setImpulse_fircore (fircore, impulse, 1); + fircore->setImpulse(impulse, 1); delete[] impulse; } @@ -276,9 +276,9 @@ void EQP::setSize(int _size) { float* impulse; size = _size; - FIRCORE::setSize_fircore (fircore, size); + fircore->setSize(size); impulse = eq_impulse (nc, nfreqs, F.data(), G.data(), samplerate, 1.0 / (2.0 * size), ctfmode, wintype); - FIRCORE::setImpulse_fircore (fircore, impulse, 1); + fircore->setImpulse(impulse, 1); delete[] impulse; } @@ -301,7 +301,7 @@ void EQP::setNC(int _nc) { nc = _nc; impulse = eq_impulse (nc, nfreqs, F.data(), G.data(), samplerate, 1.0 / (2.0 * size), ctfmode, wintype); - FIRCORE::setNc_fircore (fircore, nc, impulse); + fircore->setNc(nc, impulse); delete[] impulse; } } @@ -311,7 +311,7 @@ void EQP::setMP(int _mp) if (mp != _mp) { mp = _mp; - FIRCORE::setMp_fircore (fircore, mp); + fircore->setMp(mp); } } @@ -324,7 +324,7 @@ void EQP::setProfile(int _nfreqs, const float* _F, const float* _G) 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); + fircore->setImpulse(impulse, 1); delete[] impulse; } @@ -333,7 +333,7 @@ void EQP::setCtfmode(int _mode) float* impulse; ctfmode = _mode; impulse = eq_impulse (nc, nfreqs, F.data(), G.data(), samplerate, 1.0 / (2.0 * size), ctfmode, wintype); - FIRCORE::setImpulse_fircore (fircore, impulse, 1); + fircore->setImpulse(impulse, 1); delete[] impulse; } @@ -342,7 +342,7 @@ void EQP::setWintype(int _wintype) float* impulse; wintype = _wintype; impulse = eq_impulse (nc, nfreqs, F.data(), G.data(), samplerate, 1.0 / (2.0 * size), ctfmode, wintype); - FIRCORE::setImpulse_fircore (fircore, impulse, 1); + fircore->setImpulse(impulse, 1); delete[] impulse; } @@ -363,7 +363,7 @@ void EQP::setGrphEQ(const int *rxeq) G[4] = (float)rxeq[3]; ctfmode = 0; impulse = eq_impulse (nc, nfreqs, F.data(), G.data(), samplerate, 1.0 / (2.0 * size), ctfmode, wintype); - FIRCORE::setImpulse_fircore (fircore, impulse, 1); + fircore->setImpulse(impulse, 1); delete[] impulse; } @@ -387,7 +387,7 @@ void EQP::setGrphEQ10(const int *rxeq) G[i] = (float)rxeq[i]; ctfmode = 0; impulse = eq_impulse (nc, nfreqs, F.data(), G.data(), samplerate, 1.0 / (2.0 * size), ctfmode, wintype); - FIRCORE::setImpulse_fircore (fircore, impulse, 1); + fircore->setImpulse(impulse, 1); delete[] impulse; } diff --git a/wdsp/fir.cpp b/wdsp/fir.cpp index 494e880db..9fd5075a5 100644 --- a/wdsp/fir.cpp +++ b/wdsp/fir.cpp @@ -377,7 +377,7 @@ void FIR::analytic (int N, float* in, float* out) fftwf_destroy_plan (pfor); } -void FIR::mp_imp (int N, float* fir, float* mpfir, int pfactor, int polarity) +void FIR::mp_imp (int N, std::vector& fir, std::vector& mpfir, int pfactor, int polarity) { int i; int size = N * pfactor; @@ -388,7 +388,7 @@ void FIR::mp_imp (int N, float* fir, float* mpfir, int pfactor, int polarity) std::vector ana(size * 2); std::vector impulse(size * 2); std::vector newfreq(size * 2); - std::copy(fir, fir + N * 2, firpad.begin()); + std::copy(fir.begin(), fir.begin() + N * 2, firpad.begin()); fftwf_plan pfor = fftwf_plan_dft_1d ( size, (fftwf_complex *) firpad.data(), @@ -425,9 +425,9 @@ void FIR::mp_imp (int N, float* fir, float* mpfir, int pfactor, int polarity) } fftwf_execute (prev); if (polarity) - std::copy(&impulse[2 * (pfactor - 1) * N], &impulse[2 * (pfactor - 1) * N] + N * 2, mpfir); + std::copy(&impulse[2 * (pfactor - 1) * N], &impulse[2 * (pfactor - 1) * N] + N * 2, mpfir.begin()); else - std::copy(impulse.begin(), impulse.end(), mpfir); + std::copy(impulse.begin(), impulse.end(), mpfir.begin()); fftwf_destroy_plan (prev); fftwf_destroy_plan (pfor); diff --git a/wdsp/fir.hpp b/wdsp/fir.hpp index dd60523fa..e852d0eb5 100644 --- a/wdsp/fir.hpp +++ b/wdsp/fir.hpp @@ -27,6 +27,8 @@ warren@pratt.one #ifndef wdsp_fir_h #define wdsp_fir_h +#include + #include "export.h" namespace WDSP { @@ -38,7 +40,7 @@ public: static float* fir_fsamp_odd (int N, const float* A, int rtype, double scale, int wintype); static float* fir_fsamp (int N, const float* A, int rtype, double scale, int wintype); static float* fir_bandpass (int N, double f_low, double f_high, double samplerate, int wintype, int rtype, double scale); - static void mp_imp (int N, float* fir, float* mpfir, int pfactor, int polarity); + static void mp_imp (int N, std::vector& fir, std::vector& mpfir, int pfactor, int polarity); private: static void analytic (int N, float* in, float* out); diff --git a/wdsp/fircore.cpp b/wdsp/fircore.cpp index 866e3dd9c..5bcf996f5 100644 --- a/wdsp/fircore.cpp +++ b/wdsp/fircore.cpp @@ -38,223 +38,202 @@ namespace WDSP { ********************************************************************************************************/ -void FIRCORE::plan_fircore (FIRCORE *a) +void FIRCORE::plan() { // must call for change in 'nc', 'size', 'out' - int i; - a->nfor = a->nc / a->size; - a->cset = 0; - a->buffidx = 0; - a->idxmask = a->nfor - 1; - a->fftin = new float[2 * a->size * 2]; // (float *) malloc0 (2 * a->size * sizeof (complex)); - a->fftout = new float*[a->nfor]; // (float **) malloc0 (a->nfor * sizeof (float *)); - a->fmask = new float**[2]; // (float ***) malloc0 (2 * sizeof (float **)); - a->fmask[0] = new float*[a->nfor]; // (float **) malloc0 (a->nfor * sizeof (float *)); - a->fmask[1] = new float*[a->nfor]; // (float **) malloc0 (a->nfor * sizeof (float *)); - a->maskgen = new float[2 * a->size * 2]; // (float *) malloc0 (2 * a->size * sizeof (complex)); - a->pcfor = new fftwf_plan[a->nfor]; // (fftwf_plan *) malloc0 (a->nfor * sizeof (fftwf_plan)); - a->maskplan = new fftwf_plan*[2]; // (fftwf_plan **) malloc0 (2 * sizeof (fftwf_plan *)); - a->maskplan[0] = new fftwf_plan[a->nfor]; // (fftwf_plan *) malloc0 (a->nfor * sizeof (fftwf_plan)); - a->maskplan[1] = new fftwf_plan[a->nfor]; // (fftwf_plan *) malloc0 (a->nfor * sizeof (fftwf_plan)); - for (i = 0; i < a->nfor; i++) + nfor = nc / size; + cset = 0; + buffidx = 0; + idxmask = nfor - 1; + fftin.resize(2 * size * 2); + fftout.resize(nfor); + fmask[0].resize(nfor); + fmask[1].resize(nfor); + maskgen.resize(2 * size * 2); + pcfor.resize(nfor); + maskplan[0].resize(nfor); + maskplan[1].resize(nfor); + for (int i = 0; i < nfor; i++) { - a->fftout[i] = new float[2 * a->size * 2]; // (float *) malloc0 (2 * a->size * sizeof (complex)); - a->fmask[0][i] = new float[2 * a->size * 2]; // (float *) malloc0 (2 * a->size * sizeof (complex)); - a->fmask[1][i] = new float[2 * a->size * 2]; // (float *) malloc0 (2 * a->size * sizeof (complex)); - a->pcfor[i] = fftwf_plan_dft_1d( - 2 * a->size, - (fftwf_complex *)a->fftin, - (fftwf_complex *)a->fftout[i], + fftout[i].resize(2 * size * 2); + fmask[0][i].resize(2 * size * 2); + fmask[1][i].resize(2 * size * 2); + pcfor[i] = fftwf_plan_dft_1d( + 2 * size, + (fftwf_complex *)fftin.data(), + (fftwf_complex *)fftout[i].data(), FFTW_FORWARD, FFTW_PATIENT ); - a->maskplan[0][i] = fftwf_plan_dft_1d( - 2 * a->size, - (fftwf_complex *)a->maskgen, - (fftwf_complex *)a->fmask[0][i], + maskplan[0][i] = fftwf_plan_dft_1d( + 2 * size, + (fftwf_complex *)maskgen.data(), + (fftwf_complex *)fmask[0][i].data(), FFTW_FORWARD, FFTW_PATIENT ); - a->maskplan[1][i] = fftwf_plan_dft_1d( - 2 * a->size, - (fftwf_complex *)a->maskgen, - (fftwf_complex *)a->fmask[1][i], + maskplan[1][i] = fftwf_plan_dft_1d( + 2 * size, + (fftwf_complex *)maskgen.data(), + (fftwf_complex *)fmask[1][i].data(), FFTW_FORWARD, FFTW_PATIENT ); } - a->accum = new float[2 * a->size * 2]; // (float *) malloc0 (2 * a->size * sizeof (complex)); - a->crev = fftwf_plan_dft_1d( - 2 * a->size, - (fftwf_complex *)a->accum, - (fftwf_complex *)a->out, + accum.resize(2 * size * 2); + crev = fftwf_plan_dft_1d( + 2 * size, + (fftwf_complex *)accum.data(), + (fftwf_complex *)out, FFTW_BACKWARD, FFTW_PATIENT ); - a->masks_ready = 0; + masks_ready = 0; } -void FIRCORE::calc_fircore (FIRCORE *a, int flip) +void FIRCORE::calc(int _flip) { // call for change in frequency, rate, wintype, gain // must also call after a call to plan_firopt() - int i; - if (a->mp) - FIR::mp_imp (a->nc, a->impulse, a->imp, 16, 0); + if (mp) + FIR::mp_imp (nc, impulse, imp, 16, 0); else - std::copy(a->impulse, a->impulse + a->nc * 2, a->imp); + std::copy(impulse.begin(), impulse.begin() + nc * 2, imp.begin()); - for (i = 0; i < a->nfor; i++) + for (int i = 0; i < nfor; i++) { // I right-justified the impulse response => take output from left side of output buff, discard right side // Be careful about flipping an asymmetrical impulse response. - std::copy(&(a->imp[2 * a->size * i]), &(a->imp[2 * a->size * i]) + a->size * 2, &(a->maskgen[2 * a->size])); - fftwf_execute (a->maskplan[1 - a->cset][i]); + std::copy(&(imp[2 * size * i]), &(imp[2 * size * i]) + size * 2, &(maskgen[2 * size])); + fftwf_execute (maskplan[1 - cset][i]); } - a->masks_ready = 1; + masks_ready = 1; - if (flip) + if (_flip) { - a->cset = 1 - a->cset; - a->masks_ready = 0; + cset = 1 - cset; + masks_ready = 0; } } -FIRCORE* FIRCORE::create_fircore (int size, float* in, float* out, int nc, int mp, float* impulse) +FIRCORE::FIRCORE( + int _size, + float* _in, + float* _out, + int _nc, + int _mp, + float* _impulse +) { - FIRCORE *a = new FIRCORE; - a->size = size; - a->in = in; - a->out = out; - a->nc = nc; - a->mp = mp; - // InitializeCriticalSectionAndSpinCount (&a->update, 2500); - plan_fircore (a); - a->impulse = new float[a->nc * 2]; // (float *) malloc0 (a->nc * sizeof (complex)); - a->imp = new float[a->nc * 2]; // (float *) malloc0 (a->nc * sizeof (complex)); - std::copy(impulse, impulse + a->nc * 2, a->impulse); - calc_fircore (a, 1); - return a; + size = _size; + in = _in; + out = _out; + nc = _nc; + mp = _mp; + plan(); + impulse.resize(nc * 2); + imp.resize(nc * 2); + std::copy(_impulse, _impulse + nc * 2, impulse.begin()); + calc(1); } -void FIRCORE::deplan_fircore (FIRCORE *a) +void FIRCORE::deplan() { - int i; - fftwf_destroy_plan (a->crev); - delete[] (a->accum); - for (i = 0; i < a->nfor; i++) + fftwf_destroy_plan (crev); + for (int i = 0; i < nfor; i++) { - delete[] (a->fftout[i]); - delete[] (a->fmask[0][i]); - delete[] (a->fmask[1][i]); - fftwf_destroy_plan (a->pcfor[i]); - fftwf_destroy_plan (a->maskplan[0][i]); - fftwf_destroy_plan (a->maskplan[1][i]); + fftwf_destroy_plan (pcfor[i]); + fftwf_destroy_plan (maskplan[0][i]); + fftwf_destroy_plan (maskplan[1][i]); } - delete[] (a->maskplan[0]); - delete[] (a->maskplan[1]); - delete[] (a->maskplan); - delete[] (a->pcfor); - delete[] (a->maskgen); - delete[] (a->fmask[0]); - delete[] (a->fmask[1]); - delete[] (a->fmask); - delete[] (a->fftout); - delete[] (a->fftin); } -void FIRCORE::destroy_fircore (FIRCORE *a) +FIRCORE::~FIRCORE() { - deplan_fircore (a); - delete[] (a->imp); - delete[] (a->impulse); - delete (a); + deplan(); } -void FIRCORE::flush_fircore (FIRCORE *a) +void FIRCORE::flush() { - int i; - std::fill(a->fftin, a->fftin + 2 * a->size * 2, 0); - for (i = 0; i < a->nfor; i++) - std::fill(a->fftout[i], a->fftout[i] + 2 * a->size * 2, 0); - a->buffidx = 0; + std::fill(fftin.begin(), fftin.end(), 0); + for (int i = 0; i < nfor; i++) + std::fill(fftout[i].begin(), fftout[i].end(), 0); + buffidx = 0; } -void FIRCORE::xfircore (FIRCORE *a) +void FIRCORE::execute() { - int i, j, k; - std::copy(a->in, a->in + a->size * 2, &(a->fftin[2 * a->size])); - fftwf_execute (a->pcfor[a->buffidx]); - k = a->buffidx; - std::fill(a->accum, a->accum + 2 * a->size * 2, 0); + int k; + std::copy(in, in + size * 2, &(fftin[2 * size])); + fftwf_execute (pcfor[buffidx]); + k = buffidx; + std::fill(accum.begin(), accum.end(), 0); - for (j = 0; j < a->nfor; j++) + for (int j = 0; j < nfor; j++) { - for (i = 0; i < 2 * a->size; i++) + for (int i = 0; i < 2 * size; i++) { - a->accum[2 * i + 0] += a->fftout[k][2 * i + 0] * a->fmask[a->cset][j][2 * i + 0] - a->fftout[k][2 * i + 1] * a->fmask[a->cset][j][2 * i + 1]; - a->accum[2 * i + 1] += a->fftout[k][2 * i + 0] * a->fmask[a->cset][j][2 * i + 1] + a->fftout[k][2 * i + 1] * a->fmask[a->cset][j][2 * i + 0]; + accum[2 * i + 0] += fftout[k][2 * i + 0] * fmask[cset][j][2 * i + 0] - fftout[k][2 * i + 1] * fmask[cset][j][2 * i + 1]; + accum[2 * i + 1] += fftout[k][2 * i + 0] * fmask[cset][j][2 * i + 1] + fftout[k][2 * i + 1] * fmask[cset][j][2 * i + 0]; } - k = (k + a->idxmask) & a->idxmask; + k = (k + idxmask) & idxmask; } - a->buffidx = (a->buffidx + 1) & a->idxmask; - fftwf_execute (a->crev); - std::copy(&(a->fftin[2 * a->size]), &(a->fftin[2 * a->size]) + a->size * 2, a->fftin); + buffidx = (buffidx + 1) & idxmask; + fftwf_execute (crev); + std::copy(&(fftin[2 * size]), &(fftin[2 * size]) + size * 2, fftin.begin()); } -void FIRCORE::setBuffers_fircore (FIRCORE *a, float* in, float* out) +void FIRCORE::setBuffers(float* _in, float* _out) { - a->in = in; - a->out = out; - deplan_fircore (a); - plan_fircore (a); - calc_fircore (a, 1); + in = _in; + out = _out; + deplan(); + plan(); + calc(1); } -void FIRCORE::setSize_fircore (FIRCORE *a, int size) +void FIRCORE::setSize(int _size) { - a->size = size; - deplan_fircore (a); - plan_fircore (a); - calc_fircore (a, 1); + size = _size; + deplan(); + plan(); + calc(1); } -void FIRCORE::setImpulse_fircore (FIRCORE *a, float* impulse, int update) +void FIRCORE::setImpulse(float* _impulse, int _update) { - std::copy(impulse, impulse + a->nc * 2, a->impulse); - calc_fircore (a, update); + std::copy(_impulse, _impulse + nc * 2, impulse.begin()); + calc(_update); } -void FIRCORE::setNc_fircore (FIRCORE *a, int nc, float* impulse) +void FIRCORE::setNc(int _nc, float* _impulse) { // because of FFT planning, this will probably cause a glitch in audio if done during dataflow - deplan_fircore (a); - delete[] (a->impulse); - delete[] (a->imp); - a->nc = nc; - plan_fircore (a); - a->imp = new float[a->nc * 2]; // (float *) malloc0 (a->nc * sizeof (complex)); - a->impulse = new float[a->nc * 2]; // (float *) malloc0 (a->nc * sizeof (complex)); - std::copy(impulse, impulse + a->nc * 2, a->impulse); - calc_fircore (a, 1); + deplan(); + nc = _nc; + plan(); + imp.resize(nc * 2); + impulse.resize(nc * 2); + std::copy(_impulse, _impulse + nc * 2, impulse.begin()); + calc(1); } -void FIRCORE::setMp_fircore (FIRCORE *a, int mp) +void FIRCORE::setMp(int _mp) { - a->mp = mp; - calc_fircore (a, 1); + mp = _mp; + calc(1); } -void FIRCORE::setUpdate_fircore (FIRCORE *a) +void FIRCORE::setUpdate() { - if (a->masks_ready) + if (masks_ready) { - a->cset = 1 - a->cset; - a->masks_ready = 0; + cset = 1 - cset; + masks_ready = 0; } } diff --git a/wdsp/fircore.hpp b/wdsp/fircore.hpp index 3dbb82334..66e2d4832 100644 --- a/wdsp/fircore.hpp +++ b/wdsp/fircore.hpp @@ -34,6 +34,9 @@ warren@wpratt.com #ifndef wdsp_fircore_h #define wdsp_fircore_h +#include +#include + #include "fftw3.h" #include "export.h" @@ -46,39 +49,49 @@ public: float* in; // input buffer float* out; // output buffer, can be same as input int nc; // number of filter coefficients, power of two, >= size - float* impulse; // impulse response of filter - float* imp; + std::vector impulse; // impulse response of filter + std::vector imp; int nfor; // number of buffers in delay line - float* fftin; // fft input buffer - float*** fmask; // frequency domain masks - float** fftout; // fftout delay line - float* accum; // frequency domain accumulator + std::vector fftin; // fft input buffer + std::array>, 2> fmask; // frequency domain masks + std::vector> fftout; // fftout delay line + std::vector accum; // frequency domain accumulator int buffidx; // fft out buffer index int idxmask; // mask for index computations - float* maskgen; // input for mask generation FFT - fftwf_plan* pcfor; // array of forward FFT plans + std::vector maskgen; // input for mask generation FFT + std::vector pcfor; // array of forward FFT plans fftwf_plan crev; // reverse fft plan - fftwf_plan** maskplan; // plans for frequency domain masks + std::array, 2> maskplan; // plans for frequency domain masks int cset; int mp; int masks_ready; - static FIRCORE* create_fircore (int size, float* in, float* out, - int nc, int mp, float* impulse); - static void xfircore (FIRCORE *a); - static void destroy_fircore (FIRCORE *a); - static void flush_fircore (FIRCORE *a); - static void setBuffers_fircore (FIRCORE *a, float* in, float* out); - static void setSize_fircore (FIRCORE *a, int size); - static void setImpulse_fircore (FIRCORE *a, float* impulse, int update); - static void setNc_fircore (FIRCORE *a, int nc, float* impulse); - static void setMp_fircore (FIRCORE *a, int mp); - static void setUpdate_fircore (FIRCORE *a); + FIRCORE( + int size, + float* in, + float* out, + int nc, + int mp, + float* + impulse + ); + FIRCORE(const FIRCORE&) = delete; + FIRCORE& operator=(const FIRCORE& other) = delete; + ~FIRCORE(); + + void flush(); + void execute(); + void setBuffers(float* in, float* out); + void setSize(int size); + void setImpulse(float* impulse, int update); + void setNc(int nc, float* impulse); + void setMp(int mp); + void setUpdate(); private: - static void plan_fircore (FIRCORE *a); - static void calc_fircore (FIRCORE *a, int flip); - static void deplan_fircore (FIRCORE *a); + void plan(); + void calc(int flip); + void deplan(); }; } // namespace WDSP diff --git a/wdsp/fmd.cpp b/wdsp/fmd.cpp index 5dd043fae..14eafe841 100644 --- a/wdsp/fmd.cpp +++ b/wdsp/fmd.cpp @@ -158,26 +158,26 @@ FMD::FMD( 0, 0 ); - pde = FIRCORE::create_fircore (size, audio.data(), out, nc_de, mp_de, impulse); + pde = new 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)); - paud = FIRCORE::create_fircore (size, out, out, nc_aud, mp_aud, impulse); + paud = new FIRCORE(size, out, out, nc_aud, mp_aud, impulse); delete[] impulse; } FMD::~FMD() { - FIRCORE::destroy_fircore (paud); - FIRCORE::destroy_fircore (pde); + delete (paud); + delete (pde); decalc(); } void FMD::flush() { std::fill(audio.begin(), audio.end(), 0); - FIRCORE::flush_fircore (pde); - FIRCORE::flush_fircore (paud); + pde->flush(); + paud->flush(); phs = 0.0; fil_out = 0.0; omega = 0.0; @@ -219,9 +219,9 @@ void FMD::execute() audio[2 * i + 1] = audio[2 * i + 0]; } // de-emphasis - FIRCORE::xfircore (pde); + pde->execute(); // audio filter - FIRCORE::xfircore (paud); + paud->execute(); // CTCSS Removal sntch->execute(); if (lim_run) @@ -241,8 +241,8 @@ void FMD::setBuffers(float* _in, float* _out) in = _in; out = _out; calc(); - FIRCORE::setBuffers_fircore (pde, audio.data(), out); - FIRCORE::setBuffers_fircore (paud, out, out); + pde->setBuffers(audio.data(), out); + paud->setBuffers(out, out); plim->setBuffers(out, out); } @@ -265,11 +265,11 @@ void FMD::setSamplerate(int _rate) 0, 0 ); - FIRCORE::setImpulse_fircore (pde, impulse, 1); + pde->setImpulse(impulse, 1); 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)); - FIRCORE::setImpulse_fircore (paud, impulse, 1); + paud->setImpulse(impulse, 1); delete[] impulse; plim->setSamplerate((int) rate); } @@ -282,7 +282,7 @@ void FMD::setSize(int _size) calc(); audio.resize(size * 2); // de-emphasis filter - FIRCORE::destroy_fircore (pde); + delete (pde); impulse = FCurve::fc_impulse ( nc_de, (float) f_low, @@ -295,12 +295,12 @@ void FMD::setSize(int _size) 0, 0 ); - pde = FIRCORE::create_fircore (size, audio.data(), out, nc_de, mp_de, impulse); + pde = new FIRCORE(size, audio.data(), out, nc_de, mp_de, impulse); delete[] impulse; // audio filter - FIRCORE::destroy_fircore (paud); + delete (paud); impulse = FIR::fir_bandpass(nc_aud, 0.8 * f_low, 1.1 * f_high, rate, 0, 1, afgain / (2.0 * size)); - paud = FIRCORE::create_fircore (size, out, out, nc_aud, mp_aud, impulse); + paud = new FIRCORE(size, out, out, nc_aud, mp_aud, impulse); delete[] impulse; plim->setSize(size); } @@ -348,7 +348,7 @@ void FMD::setNCde(int nc) 0, 0 ); - FIRCORE::setNc_fircore (pde, nc_de, impulse); + pde->setNc(nc_de, impulse); delete[] impulse; } } @@ -358,7 +358,7 @@ void FMD::setMPde(int mp) if (mp_de != mp) { mp_de = mp; - FIRCORE::setMp_fircore (pde, mp_de); + pde->setMp(mp_de); } } @@ -370,7 +370,7 @@ void FMD::setNCaud(int nc) { nc_aud = nc; impulse = FIR::fir_bandpass(nc_aud, 0.8 * f_low, 1.1 * f_high, rate, 0, 1, afgain / (2.0 * size)); - FIRCORE::setNc_fircore (paud, nc_aud, impulse); + paud->setNc(nc_aud, impulse); delete[] impulse; } } @@ -380,7 +380,7 @@ void FMD::setMPaud(int mp) if (mp_aud != mp) { mp_aud = mp; - FIRCORE::setMp_fircore (paud, mp_aud); + paud->setMp(mp_aud); } } @@ -424,11 +424,11 @@ void FMD::setAFFilter(double low, double high) 0, 0 ); - FIRCORE::setImpulse_fircore (pde, impulse, 1); + pde->setImpulse(impulse, 1); 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)); - FIRCORE::setImpulse_fircore (paud, impulse, 1); + paud->setImpulse(impulse, 1); delete[] impulse; } } diff --git a/wdsp/fmmod.cpp b/wdsp/fmmod.cpp index 59bdaaacf..81eed4486 100644 --- a/wdsp/fmmod.cpp +++ b/wdsp/fmmod.cpp @@ -81,14 +81,14 @@ FMMOD* FMMOD::create_fmmod ( a->mp = mp; calc_fmmod (a); impulse = FIR::fir_bandpass(a->nc, -a->bp_fc, +a->bp_fc, a->samplerate, 0, 1, 1.0 / (2 * a->size)); - a->p = FIRCORE::create_fircore (a->size, a->out, a->out, a->nc, a->mp, impulse); + a->p = new FIRCORE(a->size, a->out, a->out, a->nc, a->mp, impulse); delete[] (impulse); return a; } void FMMOD::destroy_fmmod (FMMOD *a) { - FIRCORE::destroy_fircore (a->p); + delete (a->p); delete (a); } @@ -124,7 +124,7 @@ void FMMOD::xfmmod (FMMOD *a) } //print_deviation ("peakdev.txt", peak, a->samplerate); if (a->bp_run) - FIRCORE::xfircore (a->p); + a->p->execute(); } else if (a->in != a->out) std::copy( a->in, a->in + a->size * 2, a->out); @@ -135,7 +135,7 @@ void FMMOD::setBuffers_fmmod (FMMOD *a, float* in, float* out) a->in = in; a->out = out; calc_fmmod (a); - FIRCORE::setBuffers_fircore (a->p, a->out, a->out); + a->p->setBuffers(a->out, a->out); } void FMMOD::setSamplerate_fmmod (FMMOD *a, int rate) @@ -144,7 +144,7 @@ void FMMOD::setSamplerate_fmmod (FMMOD *a, int rate) a->samplerate = rate; calc_fmmod (a); impulse = FIR::fir_bandpass(a->nc, -a->bp_fc, +a->bp_fc, a->samplerate, 0, 1, 1.0 / (2 * a->size)); - FIRCORE::setImpulse_fircore (a->p, impulse, 1); + a->p->setImpulse(impulse, 1); delete[] (impulse); } @@ -153,9 +153,9 @@ void FMMOD::setSize_fmmod (FMMOD *a, int size) float* impulse; a->size = size; calc_fmmod (a); - FIRCORE::setSize_fircore (a->p, a->size); + a->p->setSize(a->size); impulse = FIR::fir_bandpass(a->nc, -a->bp_fc, +a->bp_fc, a->samplerate, 0, 1, 1.0 / (2 * a->size)); - FIRCORE::setImpulse_fircore (a->p, impulse, 1); + a->p->setImpulse(impulse, 1); delete[] (impulse); } @@ -170,7 +170,7 @@ void FMMOD::SetFMDeviation (TXA& txa, float deviation) FMMOD *a = txa.fmmod; float bp_fc = a->f_high + deviation; float* impulse = FIR::fir_bandpass (a->nc, -bp_fc, +bp_fc, a->samplerate, 0, 1, 1.0 / (2 * a->size)); - FIRCORE::setImpulse_fircore (a->p, impulse, 0); + a->p->setImpulse(impulse, 0); delete[] (impulse); a->deviation = deviation; // mod @@ -178,7 +178,7 @@ void FMMOD::SetFMDeviation (TXA& txa, float deviation) a->sdelta = TWOPI * a->deviation / a->samplerate; // bandpass a->bp_fc = bp_fc; - FIRCORE::setUpdate_fircore (a->p); + a->p->setUpdate(); } void FMMOD::SetCTCSSFreq (TXA& txa, float freq) @@ -205,7 +205,7 @@ void FMMOD::SetFMNC (TXA& txa, int nc) { a->nc = nc; impulse = FIR::fir_bandpass (a->nc, -a->bp_fc, +a->bp_fc, a->samplerate, 0, 1, 1.0 / (2 * a->size)); - FIRCORE::setNc_fircore (a->p, a->nc, impulse); + a->p->setNc(a->nc, impulse); delete[] (impulse); } } @@ -217,7 +217,7 @@ void FMMOD::SetFMMP (TXA& txa, int mp) if (a->mp != mp) { a->mp = mp; - FIRCORE::setMp_fircore (a->p, a->mp); + a->p->setMp(a->mp); } } @@ -233,7 +233,7 @@ void FMMOD::SetFMAFFreqs (TXA& txa, float low, float high) a->f_high = high; a->bp_fc = a->deviation + a->f_high; impulse = FIR::fir_bandpass (a->nc, -a->bp_fc, +a->bp_fc, a->samplerate, 0, 1, 1.0 / (2 * a->size)); - FIRCORE::setImpulse_fircore (a->p, impulse, 1); + a->p->setImpulse(impulse, 1); delete[] (impulse); } } diff --git a/wdsp/fmsq.cpp b/wdsp/fmsq.cpp index 41980f20c..5f83a4675 100644 --- a/wdsp/fmsq.cpp +++ b/wdsp/fmsq.cpp @@ -49,7 +49,7 @@ void FMSQ::calc() G[2] = 3.0; G[3] = (float) (+20.0 * log10(20000.0 / *pllpole)); 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); + p = new FIRCORE(size, trigger, noise.data(), nc, mp, impulse); delete[] impulse; // noise averaging avm = exp(-1.0 / (rate * avtau)); @@ -89,7 +89,7 @@ void FMSQ::calc() void FMSQ::decalc() { - FIRCORE::destroy_fircore (p); + delete (p); } FMSQ::FMSQ( @@ -143,7 +143,7 @@ FMSQ::~FMSQ() void FMSQ::flush() { - FIRCORE::flush_fircore (p); + p->flush(); avnoise = 100.0; longnoise = 1.0; state = FMSQState::MUTED; @@ -157,7 +157,7 @@ void FMSQ::execute() { double _noise; double lnlimit; - FIRCORE::xfircore (p); + p->execute(); for (int i = 0; i < size; i++) { @@ -250,7 +250,7 @@ void FMSQ::setBuffers(float* in, float* out, float* trig) insig = in; outsig = out; trigger = trig; - FIRCORE::setBuffers_fircore (p, trigger, noise.data()); + p->setBuffers(trigger, noise.data()); } void FMSQ::setSamplerate(int _rate) @@ -292,7 +292,7 @@ void FMSQ::setNC(int _nc) { nc = _nc; impulse = EQP::eq_impulse (nc, 3, F.data(), G.data(), rate, 1.0 / (2.0 * size), 0, 0); - FIRCORE::setNc_fircore (p, nc, impulse); + p->setNc(nc, impulse); delete[] impulse; } } @@ -302,7 +302,7 @@ void FMSQ::setMP(int _mp) if (mp != _mp) { mp = _mp; - FIRCORE::setMp_fircore (p, mp); + p->setMp(mp); } } diff --git a/wdsp/icfir.cpp b/wdsp/icfir.cpp index dd7b8546c..f22043a77 100644 --- a/wdsp/icfir.cpp +++ b/wdsp/icfir.cpp @@ -35,15 +35,15 @@ namespace WDSP { void ICFIR::calc_icfir (ICFIR *a) { float* impulse; - a->scale = 1.0 / (float)(2 * a->size); - impulse = icfir_impulse (a->nc, a->DD, a->R, a->Pairs, a->runrate, a->cicrate, a->cutoff, a->xtype, a->xbw, 1, a->scale, a->wintype); - a->p = FIRCORE::create_fircore (a->size, a->in, a->out, a->nc, a->mp, impulse); + a->scale = 1.0f / (float)(2 * a->size); + impulse = icfir_impulse (a->nc, a->DD, a->R, a->Pairs, (float) a->runrate, (float) a->cicrate, a->cutoff, a->xtype, a->xbw, 1, a->scale, a->wintype); + a->p = new FIRCORE(a->size, a->in, a->out, a->nc, a->mp, impulse); delete[] (impulse); } void ICFIR::decalc_icfir (ICFIR *a) { - FIRCORE::destroy_fircore (a->p); + delete (a->p); } ICFIR* ICFIR::create_icfir ( @@ -105,13 +105,13 @@ void ICFIR::destroy_icfir (ICFIR *a) void ICFIR::flush_icfir (ICFIR *a) { - FIRCORE::flush_fircore (a->p); + a->p->flush(); } void ICFIR::xicfir (ICFIR *a) { if (a->run) - FIRCORE::xfircore (a->p); + a->p->execute(); else if (a->in != a->out) std::copy( a->in, a->in + a->size * 2, a->out); } @@ -171,16 +171,21 @@ float* ICFIR::icfir_impulse ( // xbw: transition bandwidth for raised cosine // rtype: 0 for real output, 1 for complex output // scale: scale factor to be applied to the output - int i, j; - float tmp, local_scale, ri, mag, fn; + int i; + int j; + float tmp; + float local_scale; + float ri; + float mag; + float fn; float* impulse; - float* A = new float[N]; // (float *) malloc0 (N * sizeof (float)); + auto* A = new float[N]; float ft = cutoff / cicrate; // normalized cutoff frequency int u_samps = (N + 1) / 2; // number of unique samples, OK for odd or even N int c_samps = (int)(cutoff / runrate * N) + (N + 1) / 2 - N / 2; // number of unique samples within bandpass, OK for odd or even N - int x_samps = (int)(xbw / runrate * N); // number of unique samples in transition region, OK for odd or even N - float offset = 0.5 - 0.5 * (float)((N + 1) / 2 - N / 2); // sample offset from center, OK for odd or even N - float* xistion = new float[x_samps + 1]; // (float *) malloc0 ((x_samps + 1) * sizeof (float)); + auto x_samps = (int)(xbw / runrate * N); // number of unique samples in transition region, OK for odd or even N + float offset = 0.5f - 0.5f * (float)((N + 1) / 2 - N / 2); // sample offset from center, OK for odd or even N + auto* xistion = new float[x_samps + 1]; float delta = PI / (float)x_samps; float L = cicrate / runrate; float phs = 0.0; @@ -235,24 +240,10 @@ float* ICFIR::icfir_impulse ( for (i = u_samps, j = 1; i < N; i++, j++) A[i] = A[u_samps - j]; impulse = FIR::fir_fsamp (N, A, rtype, 1.0, wintype); - // print_impulse ("icfirImpulse.txt", N, impulse, 1, 0); delete[] (A); delete[] xistion; return impulse; } -/******************************************************************************************************** -* * -* TXA Properties * -* * -********************************************************************************************************/ - -//PORT void -//SetTXAICFIRRun (int channel, int run) -//{ -// EnterCriticalSection(&ch[channel].csDSP); -// txa[channel].icfir.p->run = run; -// LeaveCriticalSection(&ch[channel].csDSP); -//} } // namespace WDSP diff --git a/wdsp/nbp.cpp b/wdsp/nbp.cpp index b9784ecb2..29c2befc7 100644 --- a/wdsp/nbp.cpp +++ b/wdsp/nbp.cpp @@ -333,7 +333,7 @@ void NBP::calc_lightweight() gain / (float)(2 * size), wintype ); - FIRCORE::setImpulse_fircore (fircore, impulse, 1); + fircore->setImpulse(impulse, 1); // print_impulse ("nbp.txt", size + 1, impulse, 1, 0); delete[] impulse; } @@ -437,25 +437,25 @@ NBP::NBP( bplow.resize(maxpb); bphigh.resize(maxpb); calc_impulse (); - fircore = FIRCORE::create_fircore (size, in, out, nc, mp, impulse); + fircore = new FIRCORE(size, in, out, nc, mp, impulse); // print_impulse ("nbp.txt", size + 1, impulse, 1, 0); delete[]impulse; } NBP::~NBP() { - FIRCORE::destroy_fircore (fircore); + delete (fircore); } void NBP::flush() { - FIRCORE::flush_fircore (fircore); + fircore->flush(); } void NBP::execute (int pos) { if (run && pos == position) - FIRCORE::xfircore (fircore); + fircore->execute(); else if (in != out) std::copy( in, in + size * 2, out); } @@ -464,14 +464,14 @@ void NBP::setBuffers(float* _in, float* _out) { in = _in; out = _out; - FIRCORE::setBuffers_fircore (fircore, in, out); + fircore->setBuffers(in, out); } void NBP::setSamplerate(int _rate) { rate = _rate; calc_impulse (); - FIRCORE::setImpulse_fircore (fircore, impulse, 1); + fircore->setImpulse(impulse, 1); delete[] impulse; } @@ -479,22 +479,22 @@ void NBP::setSize(int _size) { // NOTE: 'size' must be <= 'nc' size = _size; - FIRCORE::setSize_fircore (fircore, size); + fircore->setSize(size); calc_impulse (); - FIRCORE::setImpulse_fircore (fircore, impulse, 1); + fircore->setImpulse(impulse, 1); delete[] impulse; } void NBP::setNc() { calc_impulse(); - FIRCORE::setNc_fircore (fircore, nc, impulse); + fircore->setNc(nc, impulse); delete[] impulse; } void NBP::setMp() { - FIRCORE::setMp_fircore (fircore, mp); + fircore->setMp(mp); } /******************************************************************************************************** @@ -517,7 +517,7 @@ void NBP::SetFreqs(double _flow, double _fhigh) flow = _flow; fhigh = _fhigh; calc_impulse(); - FIRCORE::setImpulse_fircore (fircore, impulse, 1); + fircore->setImpulse(impulse, 1); delete[] impulse; } }