1
0
mirror of https://github.com/f4exb/sdrangel.git synced 2024-11-25 01:18:38 -05:00

WDSP: impulse responses refactoring (5)

This commit is contained in:
f4exb 2024-08-10 12:21:04 +02:00
parent 12f4d0a0fd
commit ef0255f2bb
14 changed files with 88 additions and 82 deletions

View File

@ -1005,7 +1005,7 @@ void RXA::updateNBPFilters()
if (a->fnfrun)
{
a->calc_impulse();
a->fircore->setImpulse(a->impulse.data(), 1);
a->fircore->setImpulse(a->impulse, 1);
}
if (b->bpsnba->fnfrun)
{
@ -1096,7 +1096,7 @@ void RXA::nbpSetNotchesRun(int _run)
b->fnfrun = a->master_run;
bpsnbaCheck(mode, _run);
b->calc_impulse(); // recalc nbp impulse response
b->fircore->setImpulse(b->impulse.data(), 0); // calculate new filter masks
b->fircore->setImpulse(b->impulse, 0); // calculate new filter masks
bpsnbaSet();
b->fircore->setUpdate(); // apply new filter masks
}
@ -1113,7 +1113,7 @@ void RXA::nbpSetWindow(int _wintype)
{
a->wintype = _wintype;
a->calc_impulse();
a->fircore->setImpulse(a->impulse.data(), 1);
a->fircore->setImpulse(a->impulse, 1);
}
if (b->wintype != _wintype)
@ -1134,7 +1134,7 @@ void RXA::nbpSetAutoIncrease(int _autoincr)
{
a->autoincr = _autoincr;
a->calc_impulse();
a->fircore->setImpulse(a->impulse.data(), 1);
a->fircore->setImpulse(a->impulse, 1);
}
if (b->autoincr != _autoincr)

View File

@ -926,7 +926,7 @@ void TXA::setBandpassNC(int _nc)
1,
a->gain / (double)(2 * a->size)
);
a->fircore->setNc(a->nc, impulse.data());
a->fircore->setNc(impulse);
}
a = bp1;
@ -945,7 +945,7 @@ void TXA::setBandpassNC(int _nc)
1,
a->gain / (double)(2 * a->size)
);
a->fircore->setNc(a->nc, impulse.data());
a->fircore->setNc(impulse);
}
a = bp2;
@ -964,7 +964,7 @@ void TXA::setBandpassNC(int _nc)
1,
a->gain / (double)(2 * a->size)
);
a->fircore->setNc(a->nc, impulse.data());
a->fircore->setNc(impulse);
}
}

View File

@ -77,7 +77,7 @@ BANDPASS::BANDPASS(
1,
gain / (double)(2 * size)
);
fircore = new FIRCORE(size, in, out, nc, mp, impulse.data());
fircore = new FIRCORE(size, in, out, mp, impulse);
}
BANDPASS::~BANDPASS()
@ -119,7 +119,7 @@ void BANDPASS::setSamplerate(int _rate)
1,
gain / (double) (2 * size)
);
fircore->setImpulse(impulse.data(), 1);
fircore->setImpulse(impulse, 1);
}
void BANDPASS::setSize(int _size)
@ -139,7 +139,7 @@ void BANDPASS::setSize(int _size)
1,
gain / (double) (2 * size)
);
fircore->setImpulse(impulse.data(), 1);
fircore->setImpulse(impulse, 1);
}
void BANDPASS::setGain(double _gain, int _update)
@ -156,7 +156,7 @@ void BANDPASS::setGain(double _gain, int _update)
1,
gain / (double) (2 * size)
);
fircore->setImpulse(impulse.data(), _update);
fircore->setImpulse(impulse, _update);
}
void BANDPASS::calcBandpassFilter(double _f_low, double _f_high, double _gain)
@ -177,7 +177,7 @@ void BANDPASS::calcBandpassFilter(double _f_low, double _f_high, double _gain)
1,
gain / (double)(2 * size)
);
fircore->setImpulse(impulse.data(), 1);
fircore->setImpulse(impulse, 1);
}
}
@ -203,7 +203,7 @@ void BANDPASS::setBandpassFreqs(double _f_low, double _f_high)
gain / (double)(2 * size)
);
fircore->setImpulse(impulse.data(), 0);
fircore->setImpulse(impulse, 0);
f_low = _f_low;
f_high = _f_high;
fircore->setUpdate();
@ -227,7 +227,7 @@ void BANDPASS::SetBandpassNC(int _nc)
1,
gain / (double)( 2 * size)
);
fircore->setNc(nc, impulse.data());
fircore->setNc(impulse);
}
}

View File

@ -176,7 +176,7 @@ void BPSNBA::recalc_bpsnba_filter(int update)
b->gain = gain;
b->autoincr = autoincr;
b->calc_impulse();
b->fircore->setImpulse(b->impulse.data(), update);
b->fircore->setImpulse(b->impulse, update);
}
/********************************************************************************************************

View File

@ -37,7 +37,7 @@ void CFIR::calc()
std::vector<float> impulse;
scale = 1.0 / (float)(2 * size);
cfir_impulse (impulse, nc, DD, R, Pairs, runrate, cicrate, cutoff, xtype, xbw, 1, scale, wintype);
p = new FIRCORE(size, in, out, nc, mp, impulse.data());
p = new FIRCORE(size, in, out, mp, impulse);
}
void CFIR::decalc()

View File

@ -68,16 +68,16 @@ EMPHP::EMPHP(
FCurve::fc_impulse (
impulse,
nc,
f_low,
f_high,
-20.0 * log10(f_high / f_low),
(float) f_low,
(float) f_high,
(float) (-20.0 * log10(f_high / f_low)),
0.0,
ctype,
rate,
1.0 / (2.0 * size),
(float) rate,
(float) (1.0 / (2.0 * size)),
0, 0
);
p = new FIRCORE(size, in, out, nc, mp, impulse.data());
p = new FIRCORE(size, in, out, mp, impulse);
}
EMPHP::~EMPHP()
@ -121,7 +121,7 @@ void EMPHP::setSamplerate(int _rate)
1.0 / (2.0 * size),
0, 0
);
p->setImpulse(impulse.data(), 1);
p->setImpulse(impulse, 1);
}
void EMPHP::setSize(int _size)
@ -142,7 +142,7 @@ void EMPHP::setSize(int _size)
0,
0
);
p->setImpulse(impulse.data(), 1);
p->setImpulse(impulse, 1);
}
/********************************************************************************************************
@ -174,17 +174,17 @@ void EMPHP::setNC(int _nc)
FCurve::fc_impulse (
impulse,
nc,
f_low,
f_high,
-20.0 * log10(f_high / f_low),
(float) f_low,
(float) f_high,
(float) (-20.0 * log10(f_high / f_low)),
0.0,
ctype,
rate,
1.0 / (2.0 * size),
(float) rate,
(float) (1.0 / (2.0 * size)),
0,
0
);
p->setNc(nc, impulse.data());
p->setNc(impulse);
}
}
@ -208,7 +208,7 @@ void EMPHP::setFreqs(double low, double high)
0,
0
);
p->setImpulse(impulse.data(), 1);
p->setImpulse(impulse, 1);
}
}

View File

@ -244,7 +244,7 @@ EQP::EQP(
wintype = _wintype;
samplerate = (double) _samplerate;
eq_impulse (impulse, nc, nfreqs, F.data(), G.data(), samplerate, 1.0 / (2.0 * size), ctfmode, wintype);
fircore = new FIRCORE(size, in, out, nc, mp, impulse.data());
fircore = new FIRCORE(size, in, out, mp, impulse);
}
EQP::~EQP()
@ -277,7 +277,7 @@ void EQP::setSamplerate(int rate)
std::vector<float> impulse;
samplerate = rate;
eq_impulse (impulse, nc, nfreqs, F.data(), G.data(), samplerate, 1.0 / (2.0 * size), ctfmode, wintype);
fircore->setImpulse(impulse.data(), 1);
fircore->setImpulse(impulse, 1);
}
void EQP::setSize(int _size)
@ -286,7 +286,7 @@ void EQP::setSize(int _size)
size = _size;
fircore->setSize(size);
eq_impulse (impulse, nc, nfreqs, F.data(), G.data(), samplerate, 1.0 / (2.0 * size), ctfmode, wintype);
fircore->setImpulse(impulse.data(), 1);
fircore->setImpulse(impulse, 1);
}
/********************************************************************************************************
@ -308,7 +308,7 @@ void EQP::setNC(int _nc)
{
nc = _nc;
eq_impulse (impulse, nc, nfreqs, F.data(), G.data(), samplerate, 1.0 / (2.0 * size), ctfmode, wintype);
fircore->setNc(nc, impulse.data());
fircore->setNc(impulse);
}
}
@ -330,7 +330,7 @@ void EQP::setProfile(int _nfreqs, const float* _F, const float* _G)
std::copy(_F, _F + (_nfreqs + 1), F.begin());
std::copy(_G, _G + (_nfreqs + 1), G.begin());
eq_impulse (impulse, nc, nfreqs, F.data(), G.data(), samplerate, 1.0 / (2.0 * size), ctfmode, wintype);
fircore->setImpulse(impulse.data(), 1);
fircore->setImpulse(impulse, 1);
}
void EQP::setCtfmode(int _mode)
@ -338,7 +338,7 @@ void EQP::setCtfmode(int _mode)
std::vector<float> impulse;
ctfmode = _mode;
eq_impulse (impulse, nc, nfreqs, F.data(), G.data(), samplerate, 1.0 / (2.0 * size), ctfmode, wintype);
fircore->setImpulse(impulse.data(), 1);
fircore->setImpulse(impulse, 1);
}
void EQP::setWintype(int _wintype)
@ -346,7 +346,7 @@ void EQP::setWintype(int _wintype)
std::vector<float> impulse;
wintype = _wintype;
eq_impulse (impulse, nc, nfreqs, F.data(), G.data(), samplerate, 1.0 / (2.0 * size), ctfmode, wintype);
fircore->setImpulse(impulse.data(), 1);
fircore->setImpulse(impulse, 1);
}
void EQP::setGrphEQ(const int *rxeq)
@ -366,7 +366,7 @@ void EQP::setGrphEQ(const int *rxeq)
G[4] = (float)rxeq[3];
ctfmode = 0;
eq_impulse (impulse, nc, nfreqs, F.data(), G.data(), samplerate, 1.0 / (2.0 * size), ctfmode, wintype);
fircore->setImpulse(impulse.data(), 1);
fircore->setImpulse(impulse, 1);
}
void EQP::setGrphEQ10(const int *rxeq)
@ -389,7 +389,7 @@ void EQP::setGrphEQ10(const int *rxeq)
G[i] = (float)rxeq[i];
ctfmode = 0;
eq_impulse (impulse, nc, nfreqs, F.data(), G.data(), samplerate, 1.0 / (2.0 * size), ctfmode, wintype);
fircore->setImpulse(impulse.data(), 1);
fircore->setImpulse(impulse, 1);
}
} // namespace WDSP

View File

@ -99,7 +99,7 @@ void FIRCORE::calc(int _flip)
if (mp)
FIR::mp_imp (nc, impulse, imp, 16, 0);
else
std::copy(impulse.begin(), impulse.begin() + nc * 2, imp.begin());
std::copy(impulse.begin(), impulse.end(), imp.begin());
for (int i = 0; i < nfor; i++)
{
@ -122,20 +122,19 @@ FIRCORE::FIRCORE(
int _size,
float* _in,
float* _out,
int _nc,
int _mp,
const float* _impulse
const std::vector<float>& _impulse
)
{
size = _size;
in = _in;
out = _out;
nc = _nc;
nc = (int) (_impulse.size() / 2);
mp = _mp;
plan();
impulse.resize(nc * 2);
imp.resize(nc * 2);
std::copy(_impulse, _impulse + nc * 2, impulse.begin());
impulse.resize(_impulse.size());
imp.resize(_impulse.size());
std::copy(_impulse.begin(), _impulse.end(), impulse.begin());
calc(1);
}
@ -204,21 +203,29 @@ void FIRCORE::setSize(int _size)
calc(1);
}
void FIRCORE::setImpulse(const float* _impulse, int _update)
void FIRCORE::setImpulse(const std::vector<float>& _impulse, int _update)
{
std::copy(_impulse, _impulse + nc * 2, impulse.begin());
auto imp_nc = (int) (_impulse.size() / 2);
if (imp_nc == nc) // to be on the safe side but setNc would be called if impulse size changes
{
std::copy(_impulse.begin(), _impulse.end(), impulse.begin());
calc(_update);
}
else{
setNc(_impulse);
}
}
void FIRCORE::setNc(int _nc, const float* _impulse)
void FIRCORE::setNc(const std::vector<float>& _impulse)
{
// because of FFT planning, this will probably cause a glitch in audio if done during dataflow
deplan();
nc = _nc;
nc = (int) (_impulse.size() / 2);
plan();
imp.resize(nc * 2);
impulse.resize(nc * 2);
std::copy(_impulse, _impulse + nc * 2, impulse.begin());
std::copy(_impulse.begin(), _impulse.end(), impulse.begin());
calc(1);
}

View File

@ -70,9 +70,8 @@ public:
int size,
float* in,
float* out,
int nc,
int mp,
const float* impulse
const std::vector<float>& impulse
);
FIRCORE(const FIRCORE&) = delete;
FIRCORE& operator=(const FIRCORE& other) = delete;
@ -82,8 +81,8 @@ public:
void execute();
void setBuffers(float* in, float* out);
void setSize(int size);
void setImpulse(const float* impulse, int update);
void setNc(int nc, const float* impulse);
void setImpulse(const std::vector<float>& impulse, int update);
void setNc(const std::vector<float>& impulse);
void setMp(int mp);
void setUpdate();

View File

@ -159,11 +159,11 @@ FMD::FMD(
0,
0
);
pde = new FIRCORE(size, audio.data(), out, nc_de, mp_de, impulse.data());
pde = new FIRCORE(size, audio.data(), out, mp_de, impulse);
// audio filter
std::vector<float> impulseb;
FIR::fir_bandpass(impulseb, nc_aud, 0.8 * f_low, 1.1 * f_high, rate, 0, 1, afgain / (2.0 * size));
paud = new FIRCORE(size, out, out, nc_aud, mp_aud, impulseb.data());
paud = new FIRCORE(size, out, out, mp_aud, impulseb);
}
FMD::~FMD()
@ -266,11 +266,11 @@ void FMD::setSamplerate(int _rate)
0,
0
);
pde->setImpulse(impulse.data(), 1);
pde->setImpulse(impulse, 1);
// audio filter
std::vector<float> impulseb;
FIR::fir_bandpass(impulseb, nc_aud, 0.8 * f_low, 1.1 * f_high, rate, 0, 1, afgain / (2.0 * size));
paud->setImpulse(impulseb.data(), 1);
paud->setImpulse(impulseb, 1);
plim->setSamplerate((int) rate);
}
@ -296,12 +296,12 @@ void FMD::setSize(int _size)
0,
0
);
pde = new FIRCORE(size, audio.data(), out, nc_de, mp_de, impulse.data());
pde = new FIRCORE(size, audio.data(), out, mp_de, impulse);
// audio filter
delete paud;
std::vector<float> impulseb;
FIR::fir_bandpass(impulseb, nc_aud, 0.8 * f_low, 1.1 * f_high, rate, 0, 1, afgain / (2.0 * size));
paud = new FIRCORE(size, out, out, nc_aud, mp_aud, impulseb.data());
paud = new FIRCORE(size, out, out, mp_aud, impulseb);
plim->setSize(size);
}
@ -348,7 +348,7 @@ void FMD::setNCde(int nc)
0,
0
);
pde->setNc(nc_de, impulse.data());
pde->setNc(impulse);
}
}
@ -368,7 +368,7 @@ void FMD::setNCaud(int nc)
nc_aud = nc;
std::vector<float> impulse;
FIR::fir_bandpass(impulse, nc_aud, 0.8 * f_low, 1.1 * f_high, rate, 0, 1, afgain / (2.0 * size));
paud->setNc(nc_aud, impulse.data());
paud->setNc(impulse);
}
}
@ -421,11 +421,11 @@ void FMD::setAFFilter(double low, double high)
0,
0
);
pde->setImpulse(impulse.data(), 1);
pde->setImpulse(impulse, 1);
// audio filter
std::vector<float> impulseb;
FIR::fir_bandpass (impulseb, nc_aud, 0.8 * f_low, 1.1 * f_high, rate, 0, 1, afgain / (2.0 * size));
paud->setImpulse(impulseb.data(), 1);
paud->setImpulse(impulseb, 1);
}
}

View File

@ -82,7 +82,7 @@ FMMOD::FMMOD(
mp = _mp;
calc();
FIR::fir_bandpass(impulse, nc, -bp_fc, +bp_fc, samplerate, 0, 1, 1.0 / (2 * size));
p = new FIRCORE(size, out, out, nc, mp, impulse.data());
p = new FIRCORE(size, out, out, mp, impulse);
}
FMMOD::~FMMOD()
@ -143,7 +143,7 @@ void FMMOD::setSamplerate(int _rate)
samplerate = _rate;
calc();
FIR::fir_bandpass(impulse, nc, -bp_fc, +bp_fc, samplerate, 0, 1, 1.0 / (2 * size));
p->setImpulse(impulse.data(), 1);
p->setImpulse(impulse, 1);
}
void FMMOD::setSize(int _size)
@ -153,7 +153,7 @@ void FMMOD::setSize(int _size)
calc();
p->setSize(size);
FIR::fir_bandpass(impulse, nc, -bp_fc, +bp_fc, samplerate, 0, 1, 1.0 / (2 * size));
p->setImpulse(impulse.data(), 1);
p->setImpulse(impulse, 1);
}
/********************************************************************************************************
@ -167,7 +167,7 @@ void FMMOD::setDeviation(float _deviation)
double _bp_fc = f_high + _deviation;
std::vector<float> impulse;
FIR::fir_bandpass (impulse, nc, -_bp_fc, +_bp_fc, samplerate, 0, 1, 1.0 / (2 * size));
p->setImpulse(impulse.data(), 0);
p->setImpulse(impulse, 0);
deviation = _deviation;
// mod
sphase = 0.0;
@ -197,7 +197,7 @@ void FMMOD::setNC(int _nc)
{
nc = _nc;
FIR::fir_bandpass (impulse, nc, -bp_fc, +bp_fc, samplerate, 0, 1, 1.0 / (2 * size));
p->setNc(nc, impulse.data());
p->setNc(impulse);
}
}
@ -220,7 +220,7 @@ void FMMOD::setAFFreqs(float _low, float _high)
f_high = _high;
bp_fc = deviation + f_high;
FIR::fir_bandpass (impulse, nc, -bp_fc, +bp_fc, samplerate, 0, 1, 1.0 / (2 * size));
p->setImpulse(impulse.data(), 1);
p->setImpulse(impulse, 1);
}
}

View File

@ -49,7 +49,7 @@ void FMSQ::calc()
G[2] = 3.0;
G[3] = (float) (+20.0 * log10(20000.0 / *pllpole));
EQP::eq_impulse (impulse, nc, 3, F.data(), G.data(), rate, 1.0 / (2.0 * size), 0, 0);
p = new FIRCORE(size, trigger, noise.data(), nc, mp, impulse.data());
p = new FIRCORE(size, trigger, noise.data(), mp, impulse);
// noise averaging
avm = exp(-1.0 / (rate * avtau));
onem_avm = 1.0 - avm;
@ -291,7 +291,7 @@ void FMSQ::setNC(int _nc)
{
nc = _nc;
EQP::eq_impulse (impulse, nc, 3, F.data(), G.data(), rate, 1.0 / (2.0 * size), 0, 0);
p->setNc(nc, impulse.data());
p->setNc(impulse);
}
}

View File

@ -37,7 +37,7 @@ void ICFIR::calc_icfir (ICFIR *a)
std::vector<float> impulse;
a->scale = 1.0f / (float)(2 * a->size);
icfir_impulse (impulse, a->nc, a->DD, a->R, a->Pairs, (float) a->runrate, (float) a->cicrate, a->cutoff, a->xtype, a->xbw, 1, a->scale, a->wintype);
a->p = new FIRCORE(a->size, a->in, a->out, a->nc, a->mp, impulse.data());
a->p = new FIRCORE(a->size, a->in, a->out, a->mp, impulse);
}
void ICFIR::decalc_icfir (ICFIR *a)

View File

@ -333,7 +333,7 @@ void NBP::calc_lightweight()
gain / (float)(2 * size),
wintype
);
fircore->setImpulse(impulse.data(), 1);
fircore->setImpulse(impulse, 1);
// print_impulse ("nbp.txt", size + 1, impulse, 1, 0);
}
hadnotch = havnotch;
@ -438,7 +438,7 @@ NBP::NBP(
bplow.resize(maxpb);
bphigh.resize(maxpb);
calc_impulse ();
fircore = new FIRCORE(size, in, out, nc, mp, impulse.data());
fircore = new FIRCORE(size, in, out, mp, impulse);
}
NBP::~NBP()
@ -470,7 +470,7 @@ void NBP::setSamplerate(int _rate)
{
rate = _rate;
calc_impulse ();
fircore->setImpulse(impulse.data(), 1);
fircore->setImpulse(impulse, 1);
}
void NBP::setSize(int _size)
@ -479,13 +479,13 @@ void NBP::setSize(int _size)
size = _size;
fircore->setSize(size);
calc_impulse ();
fircore->setImpulse(impulse.data(), 1);
fircore->setImpulse(impulse, 1);
}
void NBP::setNc()
{
calc_impulse();
fircore->setNc(nc, impulse.data());
fircore->setNc(impulse);
}
void NBP::setMp()
@ -513,7 +513,7 @@ void NBP::SetFreqs(double _flow, double _fhigh)
flow = _flow;
fhigh = _fhigh;
calc_impulse();
fircore->setImpulse(impulse.data(), 1);
fircore->setImpulse(impulse, 1);
}
}