Skip to content

Commit

Permalink
WDSP: impulse responses refactoring (5)
Browse files Browse the repository at this point in the history
  • Loading branch information
f4exb committed Aug 10, 2024
1 parent 12f4d0a commit ef0255f
Show file tree
Hide file tree
Showing 14 changed files with 88 additions and 82 deletions.
8 changes: 4 additions & 4 deletions wdsp/RXA.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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)
{
Expand Down Expand Up @@ -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
}
Expand All @@ -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)
Expand All @@ -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)
Expand Down
6 changes: 3 additions & 3 deletions wdsp/TXA.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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;
Expand All @@ -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);
}
}

Expand Down
14 changes: 7 additions & 7 deletions wdsp/bandpass.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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()
Expand Down Expand Up @@ -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)
Expand All @@ -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)
Expand All @@ -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)
Expand All @@ -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);
}
}

Expand All @@ -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();
Expand All @@ -227,7 +227,7 @@ void BANDPASS::SetBandpassNC(int _nc)
1,
gain / (double)( 2 * size)
);
fircore->setNc(nc, impulse.data());
fircore->setNc(impulse);
}
}

Expand Down
2 changes: 1 addition & 1 deletion wdsp/bpsnba.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}

/********************************************************************************************************
Expand Down
2 changes: 1 addition & 1 deletion wdsp/cfir.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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()
Expand Down
30 changes: 15 additions & 15 deletions wdsp/emphp.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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()
Expand Down Expand Up @@ -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)
Expand All @@ -142,7 +142,7 @@ void EMPHP::setSize(int _size)
0,
0
);
p->setImpulse(impulse.data(), 1);
p->setImpulse(impulse, 1);
}

/********************************************************************************************************
Expand Down Expand Up @@ -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);
}
}

Expand All @@ -208,7 +208,7 @@ void EMPHP::setFreqs(double low, double high)
0,
0
);
p->setImpulse(impulse.data(), 1);
p->setImpulse(impulse, 1);
}
}

Expand Down
18 changes: 9 additions & 9 deletions wdsp/eqp.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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()
Expand Down Expand Up @@ -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)
Expand All @@ -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);
}

/********************************************************************************************************
Expand All @@ -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);
}
}

Expand All @@ -330,23 +330,23 @@ 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)
{
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)
{
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)
Expand All @@ -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)
Expand All @@ -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
33 changes: 20 additions & 13 deletions wdsp/fircore.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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++)
{
Expand All @@ -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);
}

Expand Down Expand Up @@ -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());
calc(_update);
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);
}

Expand Down
7 changes: 3 additions & 4 deletions wdsp/fircore.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -70,9 +70,8 @@ class WDSP_API FIRCORE
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;
Expand All @@ -82,8 +81,8 @@ class WDSP_API FIRCORE
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();

Expand Down
Loading

0 comments on commit ef0255f

Please sign in to comment.