1
0
mirror of https://github.com/f4exb/sdrangel.git synced 2025-07-30 04:32:25 -04:00

Compare commits

...

3 Commits

28 changed files with 258 additions and 284 deletions

View File

@ -486,18 +486,18 @@ void WDSPRxSink::applySettings(const WDSPRxSettings& settings, bool force)
if ((m_settings.m_dnr != settings.m_dnr) if ((m_settings.m_dnr != settings.m_dnr)
|| (m_settings.m_nrScheme != settings.m_nrScheme) || force) || (m_settings.m_nrScheme != settings.m_nrScheme) || force)
{ {
WDSP::ANR::SetANRRun(*m_rxa, 0); WDSP::RXA::SetANRRun(*m_rxa, 0);
WDSP::EMNR::SetEMNRRun(*m_rxa, 0); WDSP::RXA::SetEMNRRun(*m_rxa, 0);
if (settings.m_dnr) if (settings.m_dnr)
{ {
switch (settings.m_nrScheme) switch (settings.m_nrScheme)
{ {
case WDSPRxProfile::NRSchemeNR: case WDSPRxProfile::NRSchemeNR:
WDSP::ANR::SetANRRun(*m_rxa, 1); WDSP::RXA::SetANRRun(*m_rxa, 1);
break; break;
case WDSPRxProfile::NRSchemeNR2: case WDSPRxProfile::NRSchemeNR2:
WDSP::EMNR::SetEMNRRun(*m_rxa, 1); WDSP::RXA::SetEMNRRun(*m_rxa, 1);
break; break;
default: default:
break; break;
@ -560,7 +560,7 @@ void WDSPRxSink::applySettings(const WDSPRxSettings& settings, bool force)
} }
if ((m_settings.m_anf != settings.m_anf) || 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 // Caution: Causes corruption

View File

@ -289,7 +289,7 @@ RXA* RXA::create_rxa (
rxa->dsp_size, // buffer size rxa->dsp_size, // buffer size
rxa->midbuff, // pointer to input signal buffer rxa->midbuff, // pointer to input signal buffer
rxa->midbuff, // pointer to output 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 rxa->dsp_rate, // sample rate
5000.0, // cutoff freq for noise filter (Hz) 5000.0, // cutoff freq for noise filter (Hz)
&rxa->fmd->pllpole, // pointer to pole frequency of the fmd pll (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->amsq->setSamplerate(rxa->dsp_rate);
rxa->amd->setSamplerate(rxa->dsp_rate); rxa->amd->setSamplerate(rxa->dsp_rate);
rxa->fmd->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->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); rxa->eqp->setSamplerate(rxa->dsp_rate);
ANF::setSamplerate_anf (rxa->anf, rxa->dsp_rate); ANF::setSamplerate_anf (rxa->anf, rxa->dsp_rate);
ANR::setSamplerate_anr (rxa->anr, 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->amd->setSize(rxa->dsp_size);
rxa->fmd->setBuffers(rxa->midbuff, rxa->midbuff); rxa->fmd->setBuffers(rxa->midbuff, rxa->midbuff);
rxa->fmd->setSize(rxa->dsp_size); 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->fmsq->setSize(rxa->dsp_size);
rxa->snba->setBuffers(rxa->midbuff, rxa->midbuff); rxa->snba->setBuffers(rxa->midbuff, rxa->midbuff);
rxa->snba->setSize(rxa->dsp_size); 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::bp1Check (
rxa, rxa,
_run, run,
rxa.snba->run, rxa.snba->run,
rxa.emnr->run, rxa.emnr->run,
rxa.anf->run, rxa.anf->run,
rxa.anr->run rxa.anr->run
); );
rxa.amd->run = _run; rxa.amd->run = run;
RXA::bp1Set (rxa); 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 * * Collectives *

View File

@ -171,6 +171,12 @@ public:
static void SetAMDRun(RXA& rxa, int run); static void SetAMDRun(RXA& rxa, int run);
// SNBA // SNBA
static void SetSNBARun (RXA& rxa, int run); 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 // Collectives
static void SetPassband (RXA& rxa, float f_low, float f_high); static void SetPassband (RXA& rxa, float f_low, float f_high);

View File

@ -37,6 +37,8 @@ warren@wpratt.com
#define OUT_IDX (3 * STAGES) #define OUT_IDX (3 * STAGES)
#endif #endif
#include <array>
#include "export.h" #include "export.h"
namespace WDSP { namespace WDSP {
@ -68,12 +70,12 @@ public:
double onem_mtauR; // 1.0 - carrier_removal_multiplier double onem_mtauR; // 1.0 - carrier_removal_multiplier
double mtauI; // carrier insertion multiplier double mtauI; // carrier insertion multiplier
double onem_mtauI; // 1.0 - carrier_insertion_multiplier double onem_mtauI; // 1.0 - carrier_insertion_multiplier
double a[3 * STAGES + 3]; // Filter a variables std::array<double, 3*STAGES + 3> a; // Filter a variables
double b[3 * STAGES + 3]; // Filter b variables std::array<double, 3*STAGES + 3> b; // Filter b variables
double c[3 * STAGES + 3]; // Filter c variables std::array<double, 3*STAGES + 3> c; // Filter c variables
double d[3 * STAGES + 3]; // Filter d variables std::array<double, 3*STAGES + 3> d; // Filter d variables
double c0[STAGES]; // Filter coefficients - path 0 std::array<double, STAGES> c0; // Filter coefficients - path 0
double c1[STAGES]; // Filter coefficients - path 1 std::array<double, STAGES> c1; // Filter coefficients - path 1
double dsI; // delayed sample, I path double dsI; // delayed sample, I path
double dsQ; // delayed sample, Q path double dsQ; // delayed sample, Q path
double dc_insert; // dc component to insert in output double dc_insert; // dc component to insert in output
@ -97,6 +99,7 @@ public:
double tauR, double tauR,
double tauI double tauI
); );
AMD(const AMD&) = delete;
~AMD() = default; ~AMD() = default;
void init(); void init();

View File

@ -58,27 +58,20 @@ void AMSQ::compute_slews()
void AMSQ::calc() void AMSQ::calc()
{ {
// signal averaging // signal averaging
trigsig = new float[size * 2]; trigsig.resize(size * 2);
avm = exp(-1.0 / (rate * avtau)); avm = exp(-1.0 / (rate * avtau));
onem_avm = 1.0 - avm; onem_avm = 1.0 - avm;
avsig = 0.0; avsig = 0.0;
// level change // level change
ntup = (int)(tup * rate); ntup = (int)(tup * rate);
ntdown = (int)(tdown * rate); ntdown = (int)(tdown * rate);
cup = new double[(ntup + 1) * 2]; // (float *)malloc0((ntup + 1) * sizeof(float)); cup.resize((ntup + 1) * 2); // (float *)malloc0((ntup + 1) * sizeof(float));
cdown = new double[(ntdown + 1) * 2]; // (float *)malloc0((ntdown + 1) * sizeof(float)); cdown.resize((ntdown + 1) * 2); // (float *)malloc0((ntdown + 1) * sizeof(float));
compute_slews(); compute_slews();
// control // control
state = 0; state = 0;
} }
void AMSQ::decalc()
{
delete[] cdown;
delete[] cup;
delete[] trigsig;
}
AMSQ::AMSQ ( AMSQ::AMSQ (
int _run, int _run,
int _size, int _size,
@ -113,14 +106,9 @@ AMSQ::AMSQ (
calc(); calc();
} }
AMSQ::~AMSQ()
{
decalc();
}
void AMSQ::flush() void AMSQ::flush()
{ {
std::fill(trigsig, trigsig + size * 2, 0); std::fill(trigsig.begin(), trigsig.end(), 0);
avsig = 0.0; avsig = 0.0;
state = 0; state = 0;
} }
@ -222,7 +210,7 @@ void AMSQ::execute()
void AMSQ::xcap() 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) 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) void AMSQ::setSamplerate(int _rate)
{ {
decalc();
rate = _rate; rate = _rate;
calc(); calc();
} }
void AMSQ::setSize(int _size) void AMSQ::setSize(int _size)
{ {
decalc();
size = _size; size = _size;
calc(); calc();
} }

View File

@ -27,6 +27,8 @@ warren@wpratt.com
#ifndef _amsq_h #ifndef _amsq_h
#define _amsq_h #define _amsq_h
#include <vector>
#include "export.h" #include "export.h"
namespace WDSP { namespace WDSP {
@ -37,25 +39,25 @@ class TXA;
class WDSP_API AMSQ class WDSP_API AMSQ
{ {
public: public:
int run; // 0 if squelch system is OFF; 1 if it's ON int run; // 0 if squelch system is OFF; 1 if it's ON
int size; // size of input/output buffers int size; // size of input/output buffers
float* in; // squelch input signal buffer float* in; // squelch input signal buffer
float* out; // squelch output signal buffer float* out; // squelch output signal buffer
float* trigger; // pointer to trigger data source float* trigger; // pointer to trigger data source
float* trigsig; // buffer containing trigger signal std::vector<float> trigsig; // buffer containing trigger signal
double rate; // sample rate double rate; // sample rate
double avtau; // time constant for averaging noise double avtau; // time constant for averaging noise
double avm; double avm;
double onem_avm; double onem_avm;
double avsig; double avsig;
int state; // state machine control int state; // state machine control
int count; int count;
double tup; double tup;
double tdown; double tdown;
int ntup; int ntup;
int ntdown; int ntdown;
double* cup; std::vector<double> cup;
double* cdown; std::vector<double> cdown;
double tail_thresh; double tail_thresh;
double unmute_thresh; double unmute_thresh;
double min_tail; double min_tail;
@ -78,7 +80,8 @@ public:
double _max_tail, double _max_tail,
double _muted_gain double _muted_gain
); );
~AMSQ(); AMSQ(const AMSQ&) = delete;
~AMSQ() = default;
void flush(); void flush();
void execute(); void execute();
@ -95,7 +98,6 @@ public:
private: private:
void compute_slews(); void compute_slews();
void calc(); void calc();
void decalc();
}; };
} // namespace WDSP } // namespace WDSP

View File

@ -57,7 +57,7 @@ void ANB::initBlanker()
for (i = 0; i <= trans_count; i++) for (i = 0; i <= trans_count; i++)
wave[i] = 0.5 * cos(i * coef); wave[i] = 0.5 * cos(i * coef);
std::fill(dline, dline + dline_size * 2, 0); std::fill(dline.begin(), dline.end(), 0);
} }
ANB::ANB ( ANB::ANB (
@ -81,20 +81,20 @@ ANB::ANB (
hangtime(_hangtime), hangtime(_hangtime),
advtime(_advtime), advtime(_advtime),
backtau(_backtau), backtau(_backtau),
threshold(_threshold) threshold(_threshold),
dtime(0),
htime(0),
itime(0),
atime(0)
{ {
wave = new double[((int)(MAX_SAMPLERATE * MAX_TAU) + 1)]; tau = tau < 0.0 ? 0.0 : (tau > MAX_TAU ? MAX_TAU : tau);
hangtime = hangtime < 0.0 ? 0.0 : (hangtime > MAX_ADVTIME ? MAX_ADVTIME : hangtime);
advtime = advtime < 0.0 ? 0.0 : (advtime > MAX_ADVTIME ? MAX_ADVTIME : advtime);
samplerate = samplerate < 0.0 ? 0.0 : (samplerate > MAX_SAMPLERATE ? MAX_SAMPLERATE : samplerate);
wave.resize((int)(MAX_SAMPLERATE * MAX_TAU) + 1);
dline_size = (int)((MAX_TAU + MAX_ADVTIME) * MAX_SAMPLERATE) + 1; dline_size = (int)((MAX_TAU + MAX_ADVTIME) * MAX_SAMPLERATE) + 1;
dline = new float[dline_size * 2]; dline.resize(dline_size * 2);
initBlanker(); initBlanker();
legacy = new float[2048 * 2]; /////////////// legacy interface - remove
}
ANB::~ANB()
{
delete[] legacy; /////////////// legacy interface - remove
delete[] dline;
delete[] wave;
} }
void ANB::flush() void ANB::flush()

View File

@ -28,6 +28,8 @@ warren@wpratt.com
#ifndef wdsp_anb_h #ifndef wdsp_anb_h
#define wdsp_anb_h #define wdsp_anb_h
#include <vector>
#include "export.h" #include "export.h"
namespace WDSP { namespace WDSP {
@ -37,17 +39,17 @@ class WDSP_API ANB
public: public:
int run; int run;
int buffsize; // size of input/output buffer int buffsize; // size of input/output buffer
float* in; // input buffer float* in; // input buffer
float* out; // output buffer float* out; // output buffer
int dline_size; // length of delay line which is 'double dline[length][2]' int dline_size; // length of delay line which is 'double dline[length][2]'
float *dline; // pointer to delay line std::vector<float> dline; // delay line
double samplerate; // samplerate, used to convert times into sample counts double samplerate; // samplerate, used to convert times into sample counts
double tau; // transition time, signal<->zero double tau; // transition time, signal<->zero
double hangtime; // time to stay at zero after noise is no longer detected double hangtime; // time to stay at zero after noise is no longer detected
double advtime; // deadtime (zero output) in advance of detected noise double advtime; // deadtime (zero output) in advance of detected noise
double backtau; // time constant used in averaging the magnitude of the input signal double backtau; // time constant used in averaging the magnitude of the input signal
double threshold; // triggers if (noise > threshold * average_signal_magnitude) double threshold; // triggers if (noise > threshold * average_signal_magnitude)
double *wave; // pointer to array holding transition waveform std::vector<double> wave; // array holding transition waveform
int state; // state of the state machine int state; // state of the state machine
double avg; // average value of the signal magnitude double avg; // average value of the signal magnitude
int dtime; // count when decreasing the signal magnitude int dtime; // count when decreasing the signal magnitude
@ -64,7 +66,6 @@ public:
int count; // set each time a noise sample is detected, counts down int count; // set each time a noise sample is detected, counts down
double backmult; // multiplier for waveform averaging double backmult; // multiplier for waveform averaging
double ombackmult; // multiplier for waveform averaging double ombackmult; // multiplier for waveform averaging
float *legacy;
ANB( ANB(
int run, int run,
@ -78,7 +79,8 @@ public:
double backtau, double backtau,
double threshold double threshold
); );
~ANB(); ANB(const ANB&) = delete;
~ANB() = default;
void flush(); void flush();
void execute(); void execute();

View File

@ -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) void ANF::SetANFVals (RXA& rxa, int taps, int delay, double gain, double leakage)
{ {
rxa.anf->n_taps = taps; rxa.anf->n_taps = taps;

View File

@ -87,7 +87,6 @@ public:
static void setSamplerate_anf (ANF *a, int rate); static void setSamplerate_anf (ANF *a, int rate);
static void setSize_anf (ANF *a, int size); static void setSize_anf (ANF *a, int size);
// RXA Properties // RXA Properties
static void SetANFRun (RXA& rxa, int setit);
static void SetANFVals (RXA& rxa, int taps, int delay, double gain, double leakage); static void SetANFVals (RXA& rxa, int taps, int delay, double gain, double leakage);
static void SetANFTaps (RXA& rxa, int taps); static void SetANFTaps (RXA& rxa, int taps);
static void SetANFDelay (RXA& rxa, int delay); static void SetANFDelay (RXA& rxa, int delay);

View File

@ -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) void ANR::SetANRVals (RXA& rxa, int taps, int delay, double gain, double leakage)
{ {
rxa.anr->n_taps = taps; rxa.anr->n_taps = taps;

View File

@ -89,7 +89,6 @@ public:
static void setSamplerate_anr (ANR *a, int rate); static void setSamplerate_anr (ANR *a, int rate);
static void setSize_anr (ANR *a, int size); static void setSize_anr (ANR *a, int size);
// RXA Properties // RXA Properties
static void SetANRRun (RXA& rxa, int setit);
static void SetANRVals (RXA& rxa, int taps, int delay, double gain, double leakage); static void SetANRVals (RXA& rxa, int taps, int delay, double gain, double leakage);
static void SetANRTaps (RXA& rxa, int taps); static void SetANRTaps (RXA& rxa, int taps);
static void SetANRDelay (RXA& rxa, int delay); static void SetANRDelay (RXA& rxa, int delay);

View File

@ -79,6 +79,7 @@ public:
int maxpb, int maxpb,
NOTCHDB* notchdb NOTCHDB* notchdb
); );
BPSNBA(const BPSNBA&) = delete;
~BPSNBA(); ~BPSNBA();
void flush(); void flush();

View File

@ -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) void EMNR::SetEMNRgainMethod (RXA& rxa, int method)
{ {
rxa.emnr->g.gain_method = method; rxa.emnr->g.gain_method = method;

View File

@ -185,7 +185,6 @@ public:
static void setSamplerate_emnr (EMNR *a, int rate); static void setSamplerate_emnr (EMNR *a, int rate);
static void setSize_emnr (EMNR *a, int size); static void setSize_emnr (EMNR *a, int size);
// RXA Properties // RXA Properties
static void SetEMNRRun (RXA& rxa, int run);
static void SetEMNRgainMethod (RXA& rxa, int method); static void SetEMNRgainMethod (RXA& rxa, int method);
static void SetEMNRnpeMethod (RXA& rxa, int method); static void SetEMNRnpeMethod (RXA& rxa, int method);
static void SetEMNRaeRun (RXA& rxa, int run); static void SetEMNRaeRun (RXA& rxa, int run);

View File

@ -222,14 +222,14 @@ EQP::EQP(
in = _in; in = _in;
out = _out; out = _out;
nfreqs = _nfreqs; nfreqs = _nfreqs;
F = new float[nfreqs + 1]; // (float *) malloc0 ((nfreqs + 1) * sizeof (float)); F.resize(nfreqs + 1); // (float *) malloc0 ((nfreqs + 1) * sizeof (float));
G = new float[nfreqs + 1]; // (float *) malloc0 ((nfreqs + 1) * sizeof (float)); G.resize(nfreqs + 1); // (float *) malloc0 ((nfreqs + 1) * sizeof (float));
memcpy (F, _F, (_nfreqs + 1) * sizeof (float)); std::copy(_F, _F + (_nfreqs + 1), F.begin());
memcpy (G, _G, (_nfreqs + 1) * sizeof (float)); std::copy(_G, _G + (_nfreqs + 1), G.begin());
ctfmode = _ctfmode; ctfmode = _ctfmode;
wintype = _wintype; wintype = _wintype;
samplerate = (double) _samplerate; 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); fircore = FIRCORE::create_fircore (size, in, out, nc, mp, impulse);
delete[] (impulse); delete[] (impulse);
} }
@ -263,7 +263,7 @@ void EQP::setSamplerate(int rate)
{ {
float* impulse; float* impulse;
samplerate = rate; 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); FIRCORE::setImpulse_fircore (fircore, impulse, 1);
delete[] (impulse); delete[] (impulse);
} }
@ -273,7 +273,7 @@ void EQP::setSize(int _size)
float* impulse; float* impulse;
size = _size; size = _size;
FIRCORE::setSize_fircore (fircore, 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); FIRCORE::setImpulse_fircore (fircore, impulse, 1);
delete[] (impulse); delete[] (impulse);
} }
@ -296,7 +296,7 @@ void EQP::setNC(int _nc)
if (nc != _nc) if (nc != _nc)
{ {
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); FIRCORE::setNc_fircore (fircore, nc, impulse);
delete[] (impulse); delete[] (impulse);
} }
@ -314,15 +314,12 @@ void EQP::setMP(int _mp)
void EQP::setProfile(int _nfreqs, const float* _F, const float* _G) void EQP::setProfile(int _nfreqs, const float* _F, const float* _G)
{ {
float* impulse; float* impulse;
delete[] (G);
delete[] (F);
nfreqs = _nfreqs; nfreqs = _nfreqs;
F = new float[nfreqs + 1]; // (float *) malloc0 ((nfreqs + 1) * sizeof (float)); F.resize(nfreqs + 1); // (float *) malloc0 ((nfreqs + 1) * sizeof (float));
G = new float[nfreqs + 1]; // (float *) malloc0 ((nfreqs + 1) * sizeof (float)); G.resize(nfreqs + 1); // (float *) malloc0 ((nfreqs + 1) * sizeof (float));
memcpy (F, _F, (_nfreqs + 1) * sizeof (float)); std::copy(_F, _F + (_nfreqs + 1), F.begin());
memcpy (G, _G, (_nfreqs + 1) * sizeof (float)); std::copy(_G, _G + (_nfreqs + 1), G.begin());
impulse = eq_impulse (nc, nfreqs, F, G, impulse = eq_impulse (nc, nfreqs, F.data(), G.data(), samplerate, 1.0 / (2.0 * size), ctfmode, wintype);
samplerate, 1.0 / (2.0 * size), ctfmode, wintype);
FIRCORE::setImpulse_fircore (fircore, impulse, 1); FIRCORE::setImpulse_fircore (fircore, impulse, 1);
delete[] (impulse); delete[] (impulse);
} }
@ -331,7 +328,7 @@ void EQP::setCtfmode(int _mode)
{ {
float* impulse; float* impulse;
ctfmode = _mode; 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); FIRCORE::setImpulse_fircore (fircore, impulse, 1);
delete[] (impulse); delete[] (impulse);
} }
@ -340,7 +337,7 @@ void EQP::setWintype(int _wintype)
{ {
float* impulse; float* impulse;
wintype = _wintype; 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); FIRCORE::setImpulse_fircore (fircore, impulse, 1);
delete[] (impulse); delete[] (impulse);
} }
@ -348,11 +345,9 @@ void EQP::setWintype(int _wintype)
void EQP::setGrphEQ(int *rxeq) void EQP::setGrphEQ(int *rxeq)
{ // three band equalizer (legacy compatibility) { // three band equalizer (legacy compatibility)
float* impulse; float* impulse;
delete[] (G);
delete[] (F);
nfreqs = 4; nfreqs = 4;
F = new float[nfreqs + 1]; // (float *) malloc0 ((nfreqs + 1) * sizeof (float)); F.resize(nfreqs + 1); // (float *) malloc0 ((nfreqs + 1) * sizeof (float));
G = new float[nfreqs + 1]; // (float *) malloc0 ((nfreqs + 1) * sizeof (float)); G.resize(nfreqs + 1); // (float *) malloc0 ((nfreqs + 1) * sizeof (float));
F[1] = 150.0; F[1] = 150.0;
F[2] = 400.0; F[2] = 400.0;
F[3] = 1500.0; F[3] = 1500.0;
@ -363,7 +358,7 @@ void EQP::setGrphEQ(int *rxeq)
G[3] = (float)rxeq[2]; G[3] = (float)rxeq[2];
G[4] = (float)rxeq[3]; G[4] = (float)rxeq[3];
ctfmode = 0; 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); FIRCORE::setImpulse_fircore (fircore, impulse, 1);
delete[] (impulse); delete[] (impulse);
} }
@ -372,11 +367,9 @@ void EQP::setGrphEQ10(int *rxeq)
{ // ten band equalizer (legacy compatibility) { // ten band equalizer (legacy compatibility)
float* impulse; float* impulse;
int i; int i;
delete[] (G);
delete[] (F);
nfreqs = 10; nfreqs = 10;
F = new float[nfreqs + 1]; // (float *) malloc0 ((nfreqs + 1) * sizeof (float)); F.resize(nfreqs + 1); // (float *) malloc0 ((nfreqs + 1) * sizeof (float));
G = new float[nfreqs + 1]; // (float *) malloc0 ((nfreqs + 1) * sizeof (float)); G.resize(nfreqs + 1); // (float *) malloc0 ((nfreqs + 1) * sizeof (float));
F[1] = 32.0; F[1] = 32.0;
F[2] = 63.0; F[2] = 63.0;
F[3] = 125.0; F[3] = 125.0;
@ -390,7 +383,7 @@ void EQP::setGrphEQ10(int *rxeq)
for (i = 0; i <= nfreqs; i++) for (i = 0; i <= nfreqs; i++)
G[i] = (float)rxeq[i]; G[i] = (float)rxeq[i];
ctfmode = 0; 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); // print_impulse ("rxeq.txt", nc, impulse, 1, 0);
FIRCORE::setImpulse_fircore (fircore, impulse, 1); FIRCORE::setImpulse_fircore (fircore, impulse, 1);
delete[] (impulse); delete[] (impulse);

View File

@ -34,6 +34,8 @@ warren@wpratt.com
#ifndef wdsp_eqp_h #ifndef wdsp_eqp_h
#define wdsp_eqp_h #define wdsp_eqp_h
#include <vector>
#include "export.h" #include "export.h"
namespace WDSP { namespace WDSP {
@ -52,8 +54,8 @@ public:
float* in; float* in;
float* out; float* out;
int nfreqs; int nfreqs;
float* F; std::vector<float> F;
float* G; std::vector<float> G;
int ctfmode; int ctfmode;
int wintype; int wintype;
double samplerate; double samplerate;
@ -73,6 +75,7 @@ public:
int wintype, int wintype,
int samplerate int samplerate
); );
EQP(const EQP&) = delete;
~EQP(); ~EQP();
void flush(); void flush();

View File

@ -136,9 +136,9 @@ FMD::FMD(
float* impulse; float* impulse;
calc(); calc();
// de-emphasis filter // 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); 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); delete[] (impulse);
// audio filter // audio filter
impulse = FIR::fir_bandpass(nc_aud, 0.8 * f_low, 1.1 * f_high, rate, 0, 1, afgain / (2.0 * size)); 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 (paud);
FIRCORE::destroy_fircore (pde); FIRCORE::destroy_fircore (pde);
delete[] (audio);
decalc(); decalc();
} }
void FMD::flush() void FMD::flush()
{ {
std::fill(audio, audio + size * 2, 0); std::fill(audio.begin(), audio.end(), 0);
FIRCORE::flush_fircore (pde); FIRCORE::flush_fircore (pde);
FIRCORE::flush_fircore (paud); FIRCORE::flush_fircore (paud);
phs = 0.0; phs = 0.0;
@ -219,7 +218,7 @@ void FMD::setBuffers(float* _in, float* _out)
in = _in; in = _in;
out = _out; out = _out;
calc(); calc();
FIRCORE::setBuffers_fircore (pde, audio, out); FIRCORE::setBuffers_fircore (pde, audio.data(), out);
FIRCORE::setBuffers_fircore (paud, out, out); FIRCORE::setBuffers_fircore (paud, out, out);
WCPAGC::setBuffers_wcpagc (plim, out, out); WCPAGC::setBuffers_wcpagc (plim, out, out);
} }
@ -245,14 +244,13 @@ void FMD::setSize(int _size)
{ {
float* impulse; float* impulse;
decalc(); decalc();
delete[] (audio);
size = _size; size = _size;
calc(); calc();
audio = new float[size * 2]; // (float *) malloc0 (size * sizeof (complex)); audio.resize(size * 2); // (float *) malloc0 (size * sizeof (complex));
// de-emphasis filter // de-emphasis filter
FIRCORE::destroy_fircore (pde); 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); 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); delete[] (impulse);
// audio filter // audio filter
FIRCORE::destroy_fircore (paud); FIRCORE::destroy_fircore (paud);

View File

@ -28,6 +28,8 @@ warren@wpratt.com
#ifndef wdsp_fmd_h #ifndef wdsp_fmd_h
#define wdsp_fmd_h #define wdsp_fmd_h
#include <vector>
#include "export.h" #include "export.h"
namespace WDSP { namespace WDSP {
@ -67,7 +69,7 @@ public:
double deviation; double deviation;
double again; double again;
// for de-emphasis filter // for de-emphasis filter
float* audio; std::vector<float> audio;
FIRCORE *pde; FIRCORE *pde;
int nc_de; int nc_de;
int mp_de; int mp_de;
@ -108,6 +110,7 @@ public:
int nc_aud, int nc_aud,
int mp_aud int mp_aud
); );
FMD(const FMD&) = delete;
~FMD(); ~FMD();
void flush(); void flush();

View File

@ -38,7 +38,7 @@ void FMSQ::calc()
float* impulse; float* impulse;
int i; int i;
// noise filter // 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[0] = 0.0;
F[1] = fc; F[1] = fc;
F[2] = *pllpole; F[2] = *pllpole;
@ -47,8 +47,8 @@ void FMSQ::calc()
G[1] = 0.0; G[1] = 0.0;
G[2] = 3.0; G[2] = 3.0;
G[3] = +20.0 * log10(20000.0 / *pllpole); G[3] = +20.0 * log10(20000.0 / *pllpole);
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);
p = FIRCORE::create_fircore (size, trigger, noise, nc, mp, impulse); p = FIRCORE::create_fircore (size, trigger, noise.data(), nc, mp, impulse);
delete[] (impulse); delete[] (impulse);
// noise averaging // noise averaging
avm = exp(-1.0 / (rate * avtau)); avm = exp(-1.0 / (rate * avtau));
@ -60,8 +60,8 @@ void FMSQ::calc()
// level change // level change
ntup = (int)(tup * rate); ntup = (int)(tup * rate);
ntdown = (int)(tdown * rate); ntdown = (int)(tdown * rate);
cup = new double[ntup + 1]; // (float *)malloc0 ((ntup + 1) * sizeof(float)); cup.resize(ntup + 1); // (float *)malloc0 ((ntup + 1) * sizeof(float));
cdown = new double[ntdown + 1]; //(float *)malloc0 ((ntdown + 1) * sizeof(float)); cdown.resize(ntdown + 1); //(float *)malloc0 ((ntdown + 1) * sizeof(float));
delta = PI / (double) ntup; delta = PI / (double) ntup;
theta = 0.0; theta = 0.0;
@ -88,10 +88,7 @@ void FMSQ::calc()
void FMSQ::decalc() void FMSQ::decalc()
{ {
delete[] (cdown);
delete[] (cup);
FIRCORE::destroy_fircore (p); FIRCORE::destroy_fircore (p);
delete[] (noise);
} }
FMSQ::FMSQ( FMSQ::FMSQ(
@ -261,7 +258,7 @@ void FMSQ::setBuffers(float* in, float* out, float* trig)
insig = in; insig = in;
outsig = out; outsig = out;
trigger = trig; trigger = trig;
FIRCORE::setBuffers_fircore (p, trigger, noise); FIRCORE::setBuffers_fircore (p, trigger, noise.data());
} }
void FMSQ::setSamplerate(int _rate) void FMSQ::setSamplerate(int _rate)
@ -302,7 +299,7 @@ void FMSQ::setNC(int _nc)
if (nc != _nc) if (nc != _nc)
{ {
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); FIRCORE::setNc_fircore (p, nc, impulse);
delete[] (impulse); delete[] (impulse);
} }

View File

@ -28,6 +28,9 @@ warren@wpratt.com
#ifndef wdsp_fmsq_h #ifndef wdsp_fmsq_h
#define wdsp_fmsq_h #define wdsp_fmsq_h
#include <array>
#include <vector>
#include "export.h" #include "export.h"
namespace WDSP { namespace WDSP {
@ -43,11 +46,11 @@ public:
float* outsig; // squelch output signal buffer float* outsig; // squelch output signal buffer
float* trigger; // buffer used to trigger mute/unmute (may be same as input; matches timing of input buffer) float* trigger; // buffer used to trigger mute/unmute (may be same as input; matches timing of input buffer)
double rate; // sample rate double rate; // sample rate
float* noise; std::vector<float> noise;
double fc; // corner frequency for sig / noise detection double fc; // corner frequency for sig / noise detection
double* pllpole; // pointer to pole frequency of the fm demodulator pll double* pllpole; // pointer to pole frequency of the fm demodulator pll
float F[4]; std::array<float, 4> F;
float G[4]; std::array<float, 4> G;
double avtau; // time constant for averaging noise double avtau; // time constant for averaging noise
double avm; double avm;
double onem_avm; double onem_avm;
@ -62,8 +65,8 @@ public:
double tdown; double tdown;
int ntup; int ntup;
int ntdown; int ntdown;
double* cup; std::vector<double> cup;
double* cdown; std::vector<double> cdown;
double tail_thresh; double tail_thresh;
double unmute_thresh; double unmute_thresh;
double min_tail; double min_tail;
@ -97,6 +100,7 @@ public:
int _nc, int _nc,
int _mp int _mp
); );
FMSQ(const FMSQ&) = delete;
~FMSQ(); ~FMSQ();
void flush(); void flush();

View File

@ -109,11 +109,11 @@ void METER::execute()
if (np > peak) if (np > peak)
peak = np; peak = np;
result[enum_av] = 10.0 * MemLog::mlog10 (avg + 1.0e-40); result[enum_av] = 10.0 * MemLog::mlog10 (avg <= 0 ? 1.0e-20 : avg);
result[enum_pk] = 10.0 * MemLog::mlog10 (peak + 1.0e-40); result[enum_pk] = 10.0 * MemLog::mlog10 (peak <= 0 ? 1.0e-20 : peak);
if ((pgain != 0) && (enum_gain >= 0)) 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 else
{ {
@ -129,6 +129,7 @@ void METER::execute()
void METER::setBuffers(float* in) void METER::setBuffers(float* in)
{ {
buff = in; buff = in;
flush();
} }
void METER::setSamplerate(int _rate) void METER::setSamplerate(int _rate)

View File

@ -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()

View File

@ -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
); );
}; };

View File

@ -105,15 +105,15 @@ NOB::NOB (
MAX_HANG_SLEW_TIME + MAX_HANG_SLEW_TIME +
MAX_HANG_TIME + MAX_HANG_TIME +
MAX_SEQ_TIME ) + 2); MAX_SEQ_TIME ) + 2);
dline = new double[dline_size * 2]; dline.resize(dline_size * 2);
imp = new int[dline_size]; imp.resize(dline_size);
awave = new double[(int)(MAX_ADV_SLEW_TIME * MAX_SAMPLERATE + 1)]; awave.resize((int)(MAX_ADV_SLEW_TIME * MAX_SAMPLERATE + 1));
hwave = new double[(int)(MAX_HANG_SLEW_TIME * MAX_SAMPLERATE + 1)]; hwave.resize((int)(MAX_HANG_SLEW_TIME * MAX_SAMPLERATE + 1));
filterlen = 10; filterlen = 10;
bfbuff = new double[filterlen * 2]; bfbuff.resize(filterlen * 2);
ffbuff = new double[filterlen * 2]; ffbuff.resize(filterlen * 2);
fcoefs = new double[filterlen]; fcoefs.resize(filterlen);
fcoefs[0] = 0.308720593; fcoefs[0] = 0.308720593;
fcoefs[1] = 0.216104415; fcoefs[1] = 0.216104415;
fcoefs[2] = 0.151273090; fcoefs[2] = 0.151273090;
@ -128,17 +128,6 @@ NOB::NOB (
init(); init();
} }
NOB::~NOB()
{
delete[] fcoefs;
delete[] ffbuff;
delete[] bfbuff;
delete[] hwave;
delete[] awave;
delete[] imp;
delete[] dline;
}
void NOB::flush() void NOB::flush()
{ {
out_idx = 0; out_idx = 0;
@ -149,10 +138,10 @@ void NOB::flush()
avg = 1.0; avg = 1.0;
bfb_in_idx = filterlen - 1; bfb_in_idx = filterlen - 1;
ffb_in_idx = filterlen - 1; ffb_in_idx = filterlen - 1;
std::fill(dline, dline + dline_size * 2, 0); std::fill(dline.begin(), dline.end(), 0);
std::fill(imp, imp + dline_size, 0); std::fill(imp.begin(), imp.end(), 0);
std::fill(bfbuff, bfbuff + filterlen * 2, 0); std::fill(bfbuff.begin(), bfbuff.end(), 0);
std::fill(ffbuff, ffbuff + filterlen * 2, 0); std::fill(ffbuff.begin(), ffbuff.end(), 0);
} }
void NOB::execute() void NOB::execute()

View File

@ -28,6 +28,8 @@ warren@wpratt.com
#ifndef wdsp_nob_h #ifndef wdsp_nob_h
#define wdsp_nob_h #define wdsp_nob_h
#include <vector>
#include "export.h" #include "export.h"
namespace WDSP { namespace WDSP {
@ -37,11 +39,11 @@ class WDSP_API NOB
public: public:
int run; int run;
int buffsize; // size of input/output buffer int buffsize; // size of input/output buffer
float* in; // input buffer float* in; // input buffer
float* out; // output buffer float* out; // output buffer
int dline_size; // length of delay line which is 'double dline[length][2]' int dline_size; // length of delay line which is 'double dline[length][2]'
double *dline; // pointer to delay line std::vector<double> dline; // delay line
int *imp; std::vector<int> imp;
double samplerate; // samplerate, used to convert times into sample counts double samplerate; // samplerate, used to convert times into sample counts
int mode; int mode;
double advslewtime; // transition time, signal<->zero double advslewtime; // transition time, signal<->zero
@ -50,15 +52,15 @@ public:
double hangtime; // time to stay at zero after noise is no longer detected double hangtime; // time to stay at zero after noise is no longer detected
double max_imp_seq_time; double max_imp_seq_time;
int filterlen; int filterlen;
double *fcoefs; std::vector<double> fcoefs;
double *bfbuff; std::vector<double> bfbuff;
int bfb_in_idx; int bfb_in_idx;
double *ffbuff; std::vector<double> ffbuff;
int ffb_in_idx; int ffb_in_idx;
double backtau; // time constant used in averaging the magnitude of the input signal double backtau; // time constant used in averaging the magnitude of the input signal
double threshold; // triggers if (noise > threshold * average_signal_magnitude) double threshold; // triggers if (noise > threshold * average_signal_magnitude)
double *awave; // pointer to array holding transition waveform std::vector<double> awave; // array holding transition waveform
double *hwave; std::vector<double> hwave;
int state; // state of the state machine int state; // state of the state machine
double avg; // average value of the signal magnitude double avg; // average value of the signal magnitude
int time; // count when decreasing the signal magnitude int time; // count when decreasing the signal magnitude
@ -96,7 +98,8 @@ public:
double backtau, double backtau,
double threshold double threshold
); );
~NOB(); NOB(const NOB&) = delete;
~NOB() = default;
//////////// legacy interface - remove //////////// legacy interface - remove
void flush(); void flush();
void execute(); void execute();

View File

@ -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();

View File

@ -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