diff --git a/wdsp/TXA.cpp b/wdsp/TXA.cpp index c1f160ef7..8897f043c 100644 --- a/wdsp/TXA.cpp +++ b/wdsp/TXA.cpp @@ -1040,9 +1040,8 @@ void TXA::SetBPSFreqs (TXA& txa, double _f_low, double _f_high) { a->f_low = _f_low; a->f_high = _f_high; - delete[] (a->mults); impulse = FIR::fir_bandpass(a->size + 1, _f_low, _f_high, a->samplerate, a->wintype, 1, 1.0 / (float)(2 * a->size)); - a->mults = FIR::fftcv_mults (2 * a->size, impulse); + FIR::fftcv_mults (a->mults, 2 * a->size, impulse); delete[] (impulse); } @@ -1052,9 +1051,8 @@ void TXA::SetBPSFreqs (TXA& txa, double _f_low, double _f_high) { a->f_low = _f_low; a->f_high = _f_high; - delete[] (a->mults); impulse = FIR::fir_bandpass(a->size + 1, _f_low, _f_high, a->samplerate, a->wintype, 1, 1.0 / (float)(2 * a->size)); - a->mults = FIR::fftcv_mults (2 * a->size, impulse); + FIR::fftcv_mults (a->mults, 2 * a->size, impulse); delete[] (impulse); } @@ -1064,9 +1062,8 @@ void TXA::SetBPSFreqs (TXA& txa, double _f_low, double _f_high) { a->f_low = _f_low; a->f_high = _f_high; - delete[] (a->mults); impulse = FIR::fir_bandpass(a->size + 1, _f_low, _f_high, a->samplerate, a->wintype, 1, 1.0 / (float)(2 * a->size)); - a->mults = FIR::fftcv_mults (2 * a->size, impulse); + FIR::fftcv_mults (a->mults, 2 * a->size, impulse); delete[] (impulse); } } @@ -1080,9 +1077,8 @@ void TXA::SetBPSWindow (TXA& txa, int _wintype) if (a->wintype != _wintype) { a->wintype = _wintype; - delete[] (a->mults); impulse = FIR::fir_bandpass(a->size + 1, a->f_low, a->f_high, a->samplerate, a->wintype, 1, 1.0 / (float)(2 * a->size)); - a->mults = FIR::fftcv_mults (2 * a->size, impulse); + FIR::fftcv_mults (a->mults, 2 * a->size, impulse); delete[] (impulse); } @@ -1091,9 +1087,8 @@ void TXA::SetBPSWindow (TXA& txa, int _wintype) if (a->wintype != _wintype) { a->wintype = _wintype; - delete[] (a->mults); impulse = FIR::fir_bandpass(a->size + 1, a->f_low, a->f_high, a->samplerate, a->wintype, 1, 1.0 / (float)(2 * a->size)); - a->mults = FIR::fftcv_mults (2 * a->size, impulse); + FIR::fftcv_mults (a->mults, 2 * a->size, impulse); delete[] impulse; } @@ -1102,9 +1097,8 @@ void TXA::SetBPSWindow (TXA& txa, int _wintype) if (a->wintype != _wintype) { a->wintype = _wintype; - delete[] (a->mults); impulse = FIR::fir_bandpass (a->size + 1, a->f_low, a->f_high, a->samplerate, a->wintype, 1, 1.0 / (float)(2 * a->size)); - a->mults = FIR::fftcv_mults (2 * a->size, impulse); + FIR::fftcv_mults (a->mults, 2 * a->size, impulse); delete[] impulse; } } diff --git a/wdsp/bps.cpp b/wdsp/bps.cpp index af99c0e19..03d9ee0f7 100644 --- a/wdsp/bps.cpp +++ b/wdsp/bps.cpp @@ -46,7 +46,7 @@ void BPS::calc() infilt.resize(2 * size * 2); product.resize(2 * size * 2); impulse = FIR::fir_bandpass(size + 1, f_low, f_high, samplerate, wintype, 1, 1.0 / (float)(2 * size)); - mults = FIR::fftcv_mults(2 * size, impulse); + FIR::fftcv_mults(mults, 2 * size, impulse); CFor = fftwf_plan_dft_1d(2 * size, (fftwf_complex *) infilt.data(), (fftwf_complex *) product.data(), FFTW_FORWARD, FFTW_PATIENT); CRev = fftwf_plan_dft_1d(2 * size, (fftwf_complex *) product.data(), (fftwf_complex *) out, FFTW_BACKWARD, FFTW_PATIENT); delete[]impulse; @@ -56,7 +56,6 @@ void BPS::decalc() { fftwf_destroy_plan(CRev); fftwf_destroy_plan(CFor); - delete[] mults; } BPS::BPS( diff --git a/wdsp/bps.hpp b/wdsp/bps.hpp index 8133bef58..8a46e5fb3 100644 --- a/wdsp/bps.hpp +++ b/wdsp/bps.hpp @@ -56,7 +56,7 @@ public: double f_high; std::vector infilt; std::vector product; - float* mults; + std::vector mults; double samplerate; int wintype; double gain; diff --git a/wdsp/emph.cpp b/wdsp/emph.cpp index 552ac1539..e8f99db14 100644 --- a/wdsp/emph.cpp +++ b/wdsp/emph.cpp @@ -43,7 +43,8 @@ void EMPH::calc() { infilt = new float[2 * size * 2]; product = new float[2 * size * 2]; - mults = FCurve::fc_mults( + FCurve::fc_mults( + mults, size, f_low, f_high, @@ -63,7 +64,6 @@ void EMPH::decalc() { fftwf_destroy_plan(CRev); fftwf_destroy_plan(CFor); - delete[] mults; delete[] product; delete[] infilt; } diff --git a/wdsp/emph.hpp b/wdsp/emph.hpp index 21b9f8fc1..8aa535ca6 100644 --- a/wdsp/emph.hpp +++ b/wdsp/emph.hpp @@ -34,6 +34,8 @@ warren@wpratt.com #ifndef _emph_h #define _emph_h +#include + #include "fftw3.h" #include "export.h" @@ -52,7 +54,7 @@ public: double f_high; float* infilt; float* product; - float* mults; + std::vector mults; double rate; fftwf_plan CFor; fftwf_plan CRev; diff --git a/wdsp/eq.cpp b/wdsp/eq.cpp index b2d61bc15..7d7132128 100644 --- a/wdsp/eq.cpp +++ b/wdsp/eq.cpp @@ -46,10 +46,10 @@ void EQ::eq_mults (std::vector& mults, int size, int nfreqs, float* F, fl { std::vector impulse; EQP::eq_impulse (impulse, size + 1, nfreqs, F, G, samplerate, scale, ctfmode, wintype); - float* _mults = FIR::fftcv_mults(2 * size, impulse.data()); + std::vector _mults; + FIR::fftcv_mults(_mults, 2 * size, impulse.data()); mults.resize(2 * size * 2); - std::copy(_mults, _mults + 2*size*2, mults.begin()); - delete[] _mults; + std::copy(_mults.begin(), _mults.end(), mults.begin()); } void EQ::calc() diff --git a/wdsp/fcurve.cpp b/wdsp/fcurve.cpp index e0e9781c7..9e0c74bb6 100644 --- a/wdsp/fcurve.cpp +++ b/wdsp/fcurve.cpp @@ -149,12 +149,11 @@ void FCurve::fc_impulse (std::vector& impulse, int nc, float f0, float f1 } // generate mask for Overlap-Save Filter -float* FCurve::fc_mults (int size, float f0, float f1, float g0, float g1, int curve, float samplerate, float scale, int ctfmode, int wintype) +float* FCurve::fc_mults (std::vector& mults, int size, float f0, float f1, float g0, float g1, int curve, float samplerate, float scale, int ctfmode, int wintype) { std::vector impulse(2 * (size + 1)); fc_impulse (impulse, size + 1, f0, f1, g0, g1, curve, samplerate, scale, ctfmode, wintype); - float* mults = FIR::fftcv_mults(2 * size, impulse.data()); - return mults; + FIR::fftcv_mults(mults, 2 * size, impulse.data()); } } // namespace WDSP diff --git a/wdsp/fcurve.hpp b/wdsp/fcurve.hpp index 4b137408a..4b33b1eb9 100644 --- a/wdsp/fcurve.hpp +++ b/wdsp/fcurve.hpp @@ -38,7 +38,7 @@ class WDSP_API FCurve { public: static void fc_impulse (std::vector& impulse, int nc, float f0, float f1, float g0, float g1, int curve, float samplerate, float scale, int ctfmode, int wintype); - static float* fc_mults (int size, float f0, float f1, float g0, float g1, int curve, float samplerate, float scale, int ctfmode, int wintype); + static float* fc_mults (std::vector& mults, int size, float f0, float f1, float g0, float g1, int curve, float samplerate, float scale, int ctfmode, int wintype); }; } // namespace WDSP diff --git a/wdsp/fir.cpp b/wdsp/fir.cpp index b2da83530..aba6ddaae 100644 --- a/wdsp/fir.cpp +++ b/wdsp/fir.cpp @@ -35,14 +35,14 @@ warren@pratt.one namespace WDSP { -float* FIR::fftcv_mults (int NM, float* c_impulse) +void FIR::fftcv_mults (std::vector& mults, int NM, float* c_impulse) { - auto mults = new float[NM * 2]; + mults.resize(NM * 2); std::vector cfft_impulse(NM * 2); fftwf_plan ptmp = fftwf_plan_dft_1d( NM, (fftwf_complex *) cfft_impulse.data(), - (fftwf_complex *) mults, + (fftwf_complex *) mults.data(), FFTW_FORWARD, FFTW_PATIENT ); @@ -51,7 +51,6 @@ float* FIR::fftcv_mults (int NM, float* c_impulse) std::copy(c_impulse, c_impulse + (NM / 2 + 1) * 2, &(cfft_impulse[NM - 2])); fftwf_execute (ptmp); fftwf_destroy_plan (ptmp); - return mults; } float* FIR::get_fsamp_window(int N, int wintype) diff --git a/wdsp/fir.hpp b/wdsp/fir.hpp index a57d19630..2cf4a5f4f 100644 --- a/wdsp/fir.hpp +++ b/wdsp/fir.hpp @@ -36,7 +36,7 @@ namespace WDSP { class WDSP_API FIR { public: - static float* fftcv_mults (int NM, float* c_impulse); + static void fftcv_mults (std::vector& mults, int NM, float* c_impulse); static void fir_fsamp_odd (std::vector& c_impulse, int N, const float* A, int rtype, double scale, int wintype); static void fir_fsamp (std::vector& c_impulse, 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);