1
0
mirror of https://github.com/f4exb/sdrangel.git synced 2024-11-21 23:55:13 -05:00

WDSP: use vectors instead of C arrays and disable copy constructor (more) and other changes

This commit is contained in:
f4exb 2024-07-28 11:36:45 +02:00
parent 86f27fc4d6
commit 3c2192603b
20 changed files with 160 additions and 168 deletions

View File

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

View File

@ -289,7 +289,7 @@ RXA* RXA::create_rxa (
rxa->dsp_size, // buffer size
rxa->midbuff, // pointer to input 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
5000.0, // cutoff freq for noise filter (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->amd->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->snba->setSamplerate(rxa->dsp_rate);
// rxa->snba->setSamplerate(rxa->dsp_rate); SMBA removed
rxa->eqp->setSamplerate(rxa->dsp_rate);
ANF::setSamplerate_anf (rxa->anf, 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->fmd->setBuffers(rxa->midbuff, rxa->midbuff);
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->snba->setBuffers(rxa->midbuff, rxa->midbuff);
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,
_run,
run,
rxa.snba->run,
rxa.emnr->run,
rxa.anf->run,
rxa.anr->run
);
rxa.amd->run = _run;
rxa.amd->run = run;
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 *

View File

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

View File

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

View File

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

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)
{
rxa.anf->n_taps = taps;

View File

@ -87,7 +87,6 @@ public:
static void setSamplerate_anf (ANF *a, int rate);
static void setSize_anf (ANF *a, int size);
// RXA Properties
static void SetANFRun (RXA& rxa, int setit);
static void SetANFVals (RXA& rxa, int taps, int delay, double gain, double leakage);
static void SetANFTaps (RXA& rxa, int taps);
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)
{
rxa.anr->n_taps = taps;

View File

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

View File

@ -79,6 +79,7 @@ public:
int maxpb,
NOTCHDB* notchdb
);
BPSNBA(const BPSNBA&) = delete;
~BPSNBA();
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)
{
rxa.emnr->g.gain_method = method;

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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