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