mirror of
				https://github.com/f4exb/sdrangel.git
				synced 2025-11-03 13:11:20 -05:00 
			
		
		
		
	WDSP: NBP: use vectors instead of C arrays and disable copy constructor
This commit is contained in:
		
							parent
							
								
									8a267240df
								
							
						
					
					
						commit
						86f27fc4d6
					
				
							
								
								
									
										54
									
								
								wdsp/nbp.cpp
									
									
									
									
									
								
							
							
						
						
									
										54
									
								
								wdsp/nbp.cpp
									
									
									
									
									
								
							@ -44,20 +44,11 @@ NOTCHDB::NOTCHDB(int _master_run, int _maxnotches)
 | 
				
			|||||||
    master_run = _master_run;
 | 
					    master_run = _master_run;
 | 
				
			||||||
    maxnotches = _maxnotches;
 | 
					    maxnotches = _maxnotches;
 | 
				
			||||||
    nn = 0;
 | 
					    nn = 0;
 | 
				
			||||||
    fcenter = new double[maxnotches]; // (float *) malloc0 (maxnotches * sizeof (float));
 | 
					    fcenter.resize(maxnotches); // (float *) malloc0 (maxnotches * sizeof (float));
 | 
				
			||||||
    fwidth  = new double[maxnotches]; // (float *) malloc0 (maxnotches * sizeof (float));
 | 
					    fwidth.resize(maxnotches);  // (float *) malloc0 (maxnotches * sizeof (float));
 | 
				
			||||||
    nlow    = new double[maxnotches]; // (float *) malloc0 (maxnotches * sizeof (float));
 | 
					    nlow.resize(maxnotches);    // (float *) malloc0 (maxnotches * sizeof (float));
 | 
				
			||||||
    nhigh   = new double[maxnotches]; // (float *) malloc0 (maxnotches * sizeof (float));
 | 
					    nhigh.resize(maxnotches);   // (float *) malloc0 (maxnotches * sizeof (float));
 | 
				
			||||||
    active  = new int[maxnotches]; // (int    *) malloc0 (maxnotches * sizeof (int   ));
 | 
					    active.resize(maxnotches);  // (int    *) malloc0 (maxnotches * sizeof (int   ));
 | 
				
			||||||
}
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
NOTCHDB::~NOTCHDB()
 | 
					 | 
				
			||||||
{
 | 
					 | 
				
			||||||
    delete[] (active);
 | 
					 | 
				
			||||||
    delete[] (nhigh);
 | 
					 | 
				
			||||||
    delete[] (nlow);
 | 
					 | 
				
			||||||
    delete[] (fwidth);
 | 
					 | 
				
			||||||
    delete[] (fcenter);
 | 
					 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
int NOTCHDB::addNotch(int notch, double _fcenter, double _fwidth, int _active)
 | 
					int NOTCHDB::addNotch(int notch, double _fcenter, double _fwidth, int _active)
 | 
				
			||||||
@ -198,17 +189,17 @@ double NBP::min_notch_width()
 | 
				
			|||||||
 | 
					
 | 
				
			||||||
int NBP::make_nbp (
 | 
					int NBP::make_nbp (
 | 
				
			||||||
    int nn,
 | 
					    int nn,
 | 
				
			||||||
    int* active,
 | 
					    std::vector<int>& active,
 | 
				
			||||||
    double* center,
 | 
					    std::vector<double>& center,
 | 
				
			||||||
    double* width,
 | 
					    std::vector<double>& width,
 | 
				
			||||||
    double* nlow,
 | 
					    std::vector<double>& nlow,
 | 
				
			||||||
    double* nhigh,
 | 
					    std::vector<double>& nhigh,
 | 
				
			||||||
    double minwidth,
 | 
					    double minwidth,
 | 
				
			||||||
    int autoincr,
 | 
					    int autoincr,
 | 
				
			||||||
    double flow,
 | 
					    double flow,
 | 
				
			||||||
    double fhigh,
 | 
					    double fhigh,
 | 
				
			||||||
    double* bplow,
 | 
					    std::vector<double>& bplow,
 | 
				
			||||||
    double* bphigh,
 | 
					    std::vector<double>& bphigh,
 | 
				
			||||||
    int* havnotch
 | 
					    int* havnotch
 | 
				
			||||||
)
 | 
					)
 | 
				
			||||||
{
 | 
					{
 | 
				
			||||||
@ -328,8 +319,15 @@ void NBP::calc_lightweight()
 | 
				
			|||||||
                bplow[i]  -= offset;
 | 
					                bplow[i]  -= offset;
 | 
				
			||||||
                bphigh[i] -= offset;
 | 
					                bphigh[i] -= offset;
 | 
				
			||||||
            }
 | 
					            }
 | 
				
			||||||
            impulse = fir_mbandpass (nc, numpb, bplow, bphigh,
 | 
					            impulse = fir_mbandpass (
 | 
				
			||||||
                rate, gain / (float)(2 * size), wintype);
 | 
					                nc,
 | 
				
			||||||
 | 
					                numpb,
 | 
				
			||||||
 | 
					                bplow.data(),
 | 
				
			||||||
 | 
					                bphigh.data(),
 | 
				
			||||||
 | 
					                rate,
 | 
				
			||||||
 | 
					                gain / (float)(2 * size),
 | 
				
			||||||
 | 
					                wintype
 | 
				
			||||||
 | 
					            );
 | 
				
			||||||
            FIRCORE::setImpulse_fircore (fircore, impulse, 1);
 | 
					            FIRCORE::setImpulse_fircore (fircore, impulse, 1);
 | 
				
			||||||
            // print_impulse ("nbp.txt", size + 1, impulse, 1, 0);
 | 
					            // print_impulse ("nbp.txt", size + 1, impulse, 1, 0);
 | 
				
			||||||
            delete[](impulse);
 | 
					            delete[](impulse);
 | 
				
			||||||
@ -375,8 +373,8 @@ void NBP::calc_impulse ()
 | 
				
			|||||||
        impulse = fir_mbandpass (
 | 
					        impulse = fir_mbandpass (
 | 
				
			||||||
            nc,
 | 
					            nc,
 | 
				
			||||||
            numpb,
 | 
					            numpb,
 | 
				
			||||||
            bplow,
 | 
					            bplow.data(),
 | 
				
			||||||
            bphigh,
 | 
					            bphigh.data(),
 | 
				
			||||||
            rate,
 | 
					            rate,
 | 
				
			||||||
            gain / (float)(2 * size),
 | 
					            gain / (float)(2 * size),
 | 
				
			||||||
            wintype
 | 
					            wintype
 | 
				
			||||||
@ -431,8 +429,8 @@ NBP::NBP(
 | 
				
			|||||||
    maxpb(_maxpb),
 | 
					    maxpb(_maxpb),
 | 
				
			||||||
    notchdb(_notchdb)
 | 
					    notchdb(_notchdb)
 | 
				
			||||||
{
 | 
					{
 | 
				
			||||||
    bplow   = new double[maxpb]; // (float *) malloc0 (maxpb * sizeof (float));
 | 
					    bplow.resize(maxpb);  // (float *) malloc0 (maxpb * sizeof (float));
 | 
				
			||||||
    bphigh  = new double[maxpb]; // (float *) malloc0 (maxpb * sizeof (float));
 | 
					    bphigh.resize(maxpb); // (float *) malloc0 (maxpb * sizeof (float));
 | 
				
			||||||
    calc_impulse ();
 | 
					    calc_impulse ();
 | 
				
			||||||
    fircore = FIRCORE::create_fircore (size, in, out, nc, mp, impulse);
 | 
					    fircore = FIRCORE::create_fircore (size, in, out, nc, mp, impulse);
 | 
				
			||||||
    // print_impulse ("nbp.txt", size + 1, impulse, 1, 0);
 | 
					    // print_impulse ("nbp.txt", size + 1, impulse, 1, 0);
 | 
				
			||||||
@ -442,8 +440,6 @@ NBP::NBP(
 | 
				
			|||||||
NBP::~NBP()
 | 
					NBP::~NBP()
 | 
				
			||||||
{
 | 
					{
 | 
				
			||||||
    FIRCORE::destroy_fircore (fircore);
 | 
					    FIRCORE::destroy_fircore (fircore);
 | 
				
			||||||
    delete[] (bphigh);
 | 
					 | 
				
			||||||
    delete[] (bplow);
 | 
					 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
void NBP::flush()
 | 
					void NBP::flush()
 | 
				
			||||||
 | 
				
			|||||||
							
								
								
									
										34
									
								
								wdsp/nbp.hpp
									
									
									
									
									
								
							
							
						
						
									
										34
									
								
								wdsp/nbp.hpp
									
									
									
									
									
								
							@ -28,6 +28,8 @@ warren@wpratt.com
 | 
				
			|||||||
#ifndef wdsp_nbp_h
 | 
					#ifndef wdsp_nbp_h
 | 
				
			||||||
#define wdsp_nbp_h
 | 
					#define wdsp_nbp_h
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					#include <vector>
 | 
				
			||||||
 | 
					
 | 
				
			||||||
#include "export.h"
 | 
					#include "export.h"
 | 
				
			||||||
 | 
					
 | 
				
			||||||
namespace WDSP {
 | 
					namespace WDSP {
 | 
				
			||||||
@ -41,15 +43,16 @@ public:
 | 
				
			|||||||
    double tunefreq;
 | 
					    double tunefreq;
 | 
				
			||||||
    double shift;
 | 
					    double shift;
 | 
				
			||||||
    int nn;
 | 
					    int nn;
 | 
				
			||||||
    int* active;
 | 
					    std::vector<int> active;
 | 
				
			||||||
    double* fcenter;
 | 
					    std::vector<double> fcenter;
 | 
				
			||||||
    double* fwidth;
 | 
					    std::vector<double> fwidth;
 | 
				
			||||||
    double* nlow;
 | 
					    std::vector<double> nlow;
 | 
				
			||||||
    double* nhigh;
 | 
					    std::vector<double> nhigh;
 | 
				
			||||||
    int maxnotches;
 | 
					    int maxnotches;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    NOTCHDB(int master_run, int maxnotches);
 | 
					    NOTCHDB(int master_run, int maxnotches);
 | 
				
			||||||
    ~NOTCHDB();
 | 
					    NOTCHDB(const NOTCHDB&) = delete;
 | 
				
			||||||
 | 
					    ~NOTCHDB() = default;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    int addNotch (int notch, double fcenter, double fwidth, int active);
 | 
					    int addNotch (int notch, double fcenter, double fwidth, int active);
 | 
				
			||||||
    int getNotch (int notch, double* fcenter, double* fwidth, int* active);
 | 
					    int getNotch (int notch, double* fcenter, double* fwidth, int* active);
 | 
				
			||||||
@ -79,8 +82,8 @@ public:
 | 
				
			|||||||
    float* impulse;         // filter impulse response
 | 
					    float* impulse;         // filter impulse response
 | 
				
			||||||
    int maxpb;              // maximum number of passbands
 | 
					    int maxpb;              // maximum number of passbands
 | 
				
			||||||
    NOTCHDB* notchdb;       // ptr to addr of notch-database data structure
 | 
					    NOTCHDB* notchdb;       // ptr to addr of notch-database data structure
 | 
				
			||||||
    double* bplow;          // array of passband lows
 | 
					    std::vector<double> bplow;  // array of passband lows
 | 
				
			||||||
    double* bphigh;         // array of passband highs
 | 
					    std::vector<double> bphigh; // array of passband highs
 | 
				
			||||||
    int numpb;              // number of passbands
 | 
					    int numpb;              // number of passbands
 | 
				
			||||||
    FIRCORE *fircore;
 | 
					    FIRCORE *fircore;
 | 
				
			||||||
    int havnotch;
 | 
					    int havnotch;
 | 
				
			||||||
@ -104,6 +107,7 @@ public:
 | 
				
			|||||||
        int maxpb,
 | 
					        int maxpb,
 | 
				
			||||||
        NOTCHDB* notchdb
 | 
					        NOTCHDB* notchdb
 | 
				
			||||||
    );
 | 
					    );
 | 
				
			||||||
 | 
					    NBP(const NBP&) = delete;
 | 
				
			||||||
    ~NBP();
 | 
					    ~NBP();
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    void flush();
 | 
					    void flush();
 | 
				
			||||||
@ -127,17 +131,17 @@ private:
 | 
				
			|||||||
    double min_notch_width ();
 | 
					    double min_notch_width ();
 | 
				
			||||||
    static int make_nbp (
 | 
					    static int make_nbp (
 | 
				
			||||||
        int nn,
 | 
					        int nn,
 | 
				
			||||||
        int* active,
 | 
					        std::vector<int>& active,
 | 
				
			||||||
        double* center,
 | 
					        std::vector<double>& center,
 | 
				
			||||||
        double* width,
 | 
					        std::vector<double>& width,
 | 
				
			||||||
        double* nlow,
 | 
					        std::vector<double>& nlow,
 | 
				
			||||||
        double* nhigh,
 | 
					        std::vector<double>& nhigh,
 | 
				
			||||||
        double minwidth,
 | 
					        double minwidth,
 | 
				
			||||||
        int autoincr,
 | 
					        int autoincr,
 | 
				
			||||||
        double flow,
 | 
					        double flow,
 | 
				
			||||||
        double fhigh,
 | 
					        double fhigh,
 | 
				
			||||||
        double* bplow,
 | 
					        std::vector<double>& bplow,
 | 
				
			||||||
        double* bphigh,
 | 
					        std::vector<double>& bphigh,
 | 
				
			||||||
        int* havnotch
 | 
					        int* havnotch
 | 
				
			||||||
    );
 | 
					    );
 | 
				
			||||||
};
 | 
					};
 | 
				
			||||||
 | 
				
			|||||||
@ -84,7 +84,7 @@ void RESAMPLE::calc()
 | 
				
			|||||||
 | 
					
 | 
				
			||||||
    ncoef = (ncoef / L + 1) * L;
 | 
					    ncoef = (ncoef / L + 1) * L;
 | 
				
			||||||
    cpp = ncoef / L;
 | 
					    cpp = ncoef / L;
 | 
				
			||||||
    h = new double[ncoef]; // (float *)malloc0(ncoef * sizeof(float));
 | 
					    h.resize(ncoef); // (float *)malloc0(ncoef * sizeof(float));
 | 
				
			||||||
    impulse = FIR::fir_bandpass(ncoef, fc_norm_low, fc_norm_high, 1.0, 1, 0, gain * (double)L);
 | 
					    impulse = FIR::fir_bandpass(ncoef, fc_norm_low, fc_norm_high, 1.0, 1, 0, gain * (double)L);
 | 
				
			||||||
    i = 0;
 | 
					    i = 0;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
@ -95,19 +95,13 @@ void RESAMPLE::calc()
 | 
				
			|||||||
    }
 | 
					    }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    ringsize = cpp;
 | 
					    ringsize = cpp;
 | 
				
			||||||
    ring = new double[ringsize]; // (float *)malloc0(ringsize * sizeof(complex));
 | 
					    ring.resize(ringsize); // (float *)malloc0(ringsize * sizeof(complex));
 | 
				
			||||||
    idx_in = ringsize - 1;
 | 
					    idx_in = ringsize - 1;
 | 
				
			||||||
    phnum = 0;
 | 
					    phnum = 0;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    delete[] (impulse);
 | 
					    delete[] (impulse);
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
void RESAMPLE::decalc()
 | 
					 | 
				
			||||||
{
 | 
					 | 
				
			||||||
    delete[] ring;
 | 
					 | 
				
			||||||
    delete[] h;
 | 
					 | 
				
			||||||
}
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
RESAMPLE::RESAMPLE (
 | 
					RESAMPLE::RESAMPLE (
 | 
				
			||||||
    int _run,
 | 
					    int _run,
 | 
				
			||||||
    int _size,
 | 
					    int _size,
 | 
				
			||||||
@ -133,15 +127,10 @@ RESAMPLE::RESAMPLE (
 | 
				
			|||||||
    calc();
 | 
					    calc();
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
RESAMPLE::~RESAMPLE()
 | 
					 | 
				
			||||||
{
 | 
					 | 
				
			||||||
    decalc();
 | 
					 | 
				
			||||||
}
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
 | 
					
 | 
				
			||||||
void RESAMPLE::flush()
 | 
					void RESAMPLE::flush()
 | 
				
			||||||
{
 | 
					{
 | 
				
			||||||
    std::fill(ring, ring + 2 * ringsize, 0);
 | 
					    std::fill(ring.begin(), ring.end(), 0);
 | 
				
			||||||
    idx_in = ringsize - 1;
 | 
					    idx_in = ringsize - 1;
 | 
				
			||||||
    phnum = 0;
 | 
					    phnum = 0;
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
@ -210,14 +199,12 @@ void RESAMPLE::setSize(int _size)
 | 
				
			|||||||
 | 
					
 | 
				
			||||||
void RESAMPLE::setInRate(int _rate)
 | 
					void RESAMPLE::setInRate(int _rate)
 | 
				
			||||||
{
 | 
					{
 | 
				
			||||||
    decalc();
 | 
					 | 
				
			||||||
    in_rate = _rate;
 | 
					    in_rate = _rate;
 | 
				
			||||||
    calc();
 | 
					    calc();
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
void RESAMPLE::setOutRate(int _rate)
 | 
					void RESAMPLE::setOutRate(int _rate)
 | 
				
			||||||
{
 | 
					{
 | 
				
			||||||
    decalc();
 | 
					 | 
				
			||||||
    out_rate = _rate;
 | 
					    out_rate = _rate;
 | 
				
			||||||
    calc();
 | 
					    calc();
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
@ -226,7 +213,6 @@ void RESAMPLE::setFCLow(double _fc_low)
 | 
				
			|||||||
{
 | 
					{
 | 
				
			||||||
    if (fc_low != _fc_low)
 | 
					    if (fc_low != _fc_low)
 | 
				
			||||||
    {
 | 
					    {
 | 
				
			||||||
        decalc();
 | 
					 | 
				
			||||||
        fc_low = _fc_low;
 | 
					        fc_low = _fc_low;
 | 
				
			||||||
        calc();
 | 
					        calc();
 | 
				
			||||||
    }
 | 
					    }
 | 
				
			||||||
@ -236,7 +222,6 @@ void RESAMPLE::setBandwidth(double _fc_low, double _fc_high)
 | 
				
			|||||||
{
 | 
					{
 | 
				
			||||||
    if (fc_low != _fc_low || _fc_high != fcin)
 | 
					    if (fc_low != _fc_low || _fc_high != fcin)
 | 
				
			||||||
    {
 | 
					    {
 | 
				
			||||||
        decalc();
 | 
					 | 
				
			||||||
        fc_low = _fc_low;
 | 
					        fc_low = _fc_low;
 | 
				
			||||||
        fcin = _fc_high;
 | 
					        fcin = _fc_high;
 | 
				
			||||||
        calc();
 | 
					        calc();
 | 
				
			||||||
 | 
				
			|||||||
@ -34,6 +34,8 @@ warren@wpratt.com
 | 
				
			|||||||
#ifndef wdsp_resample_h
 | 
					#ifndef wdsp_resample_h
 | 
				
			||||||
#define wdsp_resample_h
 | 
					#define wdsp_resample_h
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					#include <vector>
 | 
				
			||||||
 | 
					
 | 
				
			||||||
#include "export.h"
 | 
					#include "export.h"
 | 
				
			||||||
 | 
					
 | 
				
			||||||
namespace WDSP {
 | 
					namespace WDSP {
 | 
				
			||||||
@ -56,9 +58,9 @@ public:
 | 
				
			|||||||
    int ncoef;          // number of coefficients
 | 
					    int ncoef;          // number of coefficients
 | 
				
			||||||
    int L;              // interpolation factor
 | 
					    int L;              // interpolation factor
 | 
				
			||||||
    int M;              // decimation factor
 | 
					    int M;              // decimation factor
 | 
				
			||||||
    double* h;          // coefficients
 | 
					    std::vector<double> h;    // coefficients
 | 
				
			||||||
    int ringsize;       // number of complex pairs the ring buffer holds
 | 
					    int ringsize;       // number of complex pairs the ring buffer holds
 | 
				
			||||||
    double* ring;       // ring buffer
 | 
					    std::vector<double> ring; // ring buffer
 | 
				
			||||||
    int cpp;            // coefficients of the phase
 | 
					    int cpp;            // coefficients of the phase
 | 
				
			||||||
    int phnum;          // phase number
 | 
					    int phnum;          // phase number
 | 
				
			||||||
 | 
					
 | 
				
			||||||
@ -73,7 +75,8 @@ public:
 | 
				
			|||||||
        int ncoef,
 | 
					        int ncoef,
 | 
				
			||||||
        double gain
 | 
					        double gain
 | 
				
			||||||
    );
 | 
					    );
 | 
				
			||||||
    ~RESAMPLE();
 | 
					    RESAMPLE(const RESAMPLE&) = delete;
 | 
				
			||||||
 | 
					    ~RESAMPLE() = default;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    void flush();
 | 
					    void flush();
 | 
				
			||||||
    int execute();
 | 
					    int execute();
 | 
				
			||||||
@ -90,7 +93,6 @@ public:
 | 
				
			|||||||
 | 
					
 | 
				
			||||||
private:
 | 
					private:
 | 
				
			||||||
    void calc();
 | 
					    void calc();
 | 
				
			||||||
    void decalc();
 | 
					 | 
				
			||||||
};
 | 
					};
 | 
				
			||||||
 | 
					
 | 
				
			||||||
} // namespace WDSP
 | 
					} // namespace WDSP
 | 
				
			||||||
 | 
				
			|||||||
		Loading…
	
	
			
			x
			
			
		
	
		Reference in New Issue
	
	Block a user