mirror of
https://github.com/f4exb/sdrangel.git
synced 2025-09-03 05:37:50 -04:00
WDSP: ANF, ANR, EMNR: use vectors instead of C arrays and disable copy constructor
This commit is contained in:
parent
3c2192603b
commit
6662357bcf
@ -510,12 +510,12 @@ void WDSPRxSink::applySettings(const WDSPRxSettings& settings, bool force)
|
|||||||
switch (settings.m_nrPosition)
|
switch (settings.m_nrPosition)
|
||||||
{
|
{
|
||||||
case WDSPRxProfile::NRPositionPreAGC:
|
case WDSPRxProfile::NRPositionPreAGC:
|
||||||
WDSP::ANR::SetANRPosition(*m_rxa, 0);
|
WDSP::RXA::SetANRPosition(*m_rxa, 0);
|
||||||
WDSP::EMNR::SetEMNRPosition(*m_rxa, 0);
|
WDSP::RXA::SetEMNRPosition(*m_rxa, 0);
|
||||||
break;
|
break;
|
||||||
case WDSPRxProfile::NRPositionPostAGC:
|
case WDSPRxProfile::NRPositionPostAGC:
|
||||||
WDSP::ANR::SetANRPosition(*m_rxa, 1);
|
WDSP::RXA::SetANRPosition(*m_rxa, 1);
|
||||||
WDSP::EMNR::SetEMNRPosition(*m_rxa, 1);
|
WDSP::RXA::SetEMNRPosition(*m_rxa, 1);
|
||||||
break;
|
break;
|
||||||
default:
|
default:
|
||||||
break;
|
break;
|
||||||
@ -527,13 +527,13 @@ void WDSPRxSink::applySettings(const WDSPRxSettings& settings, bool force)
|
|||||||
switch (settings.m_nr2Gain)
|
switch (settings.m_nr2Gain)
|
||||||
{
|
{
|
||||||
case WDSPRxProfile::NR2GainLinear:
|
case WDSPRxProfile::NR2GainLinear:
|
||||||
WDSP::EMNR::SetEMNRgainMethod(*m_rxa, 0);
|
m_rxa->emnr->setGainMethod(0);
|
||||||
break;
|
break;
|
||||||
case WDSPRxProfile::NR2GainLog:
|
case WDSPRxProfile::NR2GainLog:
|
||||||
WDSP::EMNR::SetEMNRgainMethod(*m_rxa, 1);
|
m_rxa->emnr->setGainMethod(1);
|
||||||
break;
|
break;
|
||||||
case WDSPRxProfile::NR2GainGamma:
|
case WDSPRxProfile::NR2GainGamma:
|
||||||
WDSP::EMNR::SetEMNRgainMethod(*m_rxa, 2);
|
m_rxa->emnr->setGainMethod(2);
|
||||||
break;
|
break;
|
||||||
default:
|
default:
|
||||||
break;
|
break;
|
||||||
@ -545,10 +545,10 @@ void WDSPRxSink::applySettings(const WDSPRxSettings& settings, bool force)
|
|||||||
switch (settings.m_nr2NPE)
|
switch (settings.m_nr2NPE)
|
||||||
{
|
{
|
||||||
case WDSPRxProfile::NR2NPEOSMS:
|
case WDSPRxProfile::NR2NPEOSMS:
|
||||||
WDSP::EMNR::SetEMNRnpeMethod(*m_rxa, 0);
|
m_rxa->emnr->setNpeMethod(0);
|
||||||
break;
|
break;
|
||||||
case WDSPRxProfile::NR2NPEMMSE:
|
case WDSPRxProfile::NR2NPEMMSE:
|
||||||
WDSP::EMNR::SetEMNRnpeMethod(*m_rxa, 1);
|
m_rxa->emnr->setNpeMethod(1);
|
||||||
break;
|
break;
|
||||||
default:
|
default:
|
||||||
break;
|
break;
|
||||||
@ -556,7 +556,7 @@ void WDSPRxSink::applySettings(const WDSPRxSettings& settings, bool force)
|
|||||||
}
|
}
|
||||||
|
|
||||||
if ((m_settings.m_nr2ArtifactReduction != settings.m_nr2ArtifactReduction) || force) {
|
if ((m_settings.m_nr2ArtifactReduction != settings.m_nr2ArtifactReduction) || force) {
|
||||||
WDSP::EMNR::SetEMNRaeRun(*m_rxa, settings.m_nr2ArtifactReduction ? 1 : 0);
|
m_rxa->emnr->setAeRun(settings.m_nr2ArtifactReduction ? 1 : 0);
|
||||||
}
|
}
|
||||||
|
|
||||||
if ((m_settings.m_anf != settings.m_anf) || force) {
|
if ((m_settings.m_anf != settings.m_anf) || force) {
|
||||||
|
72
wdsp/RXA.cpp
72
wdsp/RXA.cpp
@ -347,7 +347,7 @@ RXA* RXA::create_rxa (
|
|||||||
}
|
}
|
||||||
|
|
||||||
// Auto notch filter
|
// Auto notch filter
|
||||||
rxa->anf = ANF::create_anf (
|
rxa->anf = new ANF(
|
||||||
0, // run - OFF by default
|
0, // run - OFF by default
|
||||||
0, // position
|
0, // position
|
||||||
rxa->dsp_size, // buffer size
|
rxa->dsp_size, // buffer size
|
||||||
@ -367,7 +367,7 @@ RXA* RXA::create_rxa (
|
|||||||
3.0); // ldecr
|
3.0); // ldecr
|
||||||
|
|
||||||
// LMS noise reduction (ANR or "NR")
|
// LMS noise reduction (ANR or "NR")
|
||||||
rxa->anr = ANR::create_anr (
|
rxa->anr = new ANR(
|
||||||
0, // run - OFF by default
|
0, // run - OFF by default
|
||||||
0, // position
|
0, // position
|
||||||
rxa->dsp_size, // buffer size
|
rxa->dsp_size, // buffer size
|
||||||
@ -387,7 +387,7 @@ RXA* RXA::create_rxa (
|
|||||||
3.0); // ldecr
|
3.0); // ldecr
|
||||||
|
|
||||||
// Spectral noise reduyction (EMNR or "NR2")
|
// Spectral noise reduyction (EMNR or "NR2")
|
||||||
rxa->emnr = EMNR::create_emnr (
|
rxa->emnr = new EMNR(
|
||||||
0, // run
|
0, // run
|
||||||
0, // position
|
0, // position
|
||||||
rxa->dsp_size, // buffer size
|
rxa->dsp_size, // buffer size
|
||||||
@ -573,9 +573,9 @@ void RXA::destroy_rxa (RXA *rxa)
|
|||||||
BANDPASS::destroy_bandpass (rxa->bp1);
|
BANDPASS::destroy_bandpass (rxa->bp1);
|
||||||
delete (rxa->agcmeter);
|
delete (rxa->agcmeter);
|
||||||
WCPAGC::destroy_wcpagc (rxa->agc);
|
WCPAGC::destroy_wcpagc (rxa->agc);
|
||||||
EMNR::destroy_emnr (rxa->emnr);
|
delete (rxa->emnr);
|
||||||
ANR::destroy_anr (rxa->anr);
|
delete (rxa->anr);
|
||||||
ANF::destroy_anf (rxa->anf);
|
delete (rxa->anf);
|
||||||
delete (rxa->eqp);
|
delete (rxa->eqp);
|
||||||
delete (rxa->snba);
|
delete (rxa->snba);
|
||||||
delete (rxa->fmsq);
|
delete (rxa->fmsq);
|
||||||
@ -618,9 +618,9 @@ void RXA::flush_rxa (RXA *rxa)
|
|||||||
rxa->fmsq->flush();
|
rxa->fmsq->flush();
|
||||||
rxa->snba->flush();
|
rxa->snba->flush();
|
||||||
rxa->eqp->flush();
|
rxa->eqp->flush();
|
||||||
ANF::flush_anf (rxa->anf);
|
rxa->anf->flush();
|
||||||
ANR::flush_anr (rxa->anr);
|
rxa->anr->flush();
|
||||||
EMNR::flush_emnr (rxa->emnr);
|
rxa->emnr->flush();
|
||||||
WCPAGC::flush_wcpagc (rxa->agc);
|
WCPAGC::flush_wcpagc (rxa->agc);
|
||||||
rxa->agcmeter->flush();
|
rxa->agcmeter->flush();
|
||||||
BANDPASS::flush_bandpass (rxa->bp1);
|
BANDPASS::flush_bandpass (rxa->bp1);
|
||||||
@ -653,14 +653,14 @@ void RXA::xrxa (RXA *rxa)
|
|||||||
rxa->bpsnba->exec_out(1);
|
rxa->bpsnba->exec_out(1);
|
||||||
rxa->snba->execute();
|
rxa->snba->execute();
|
||||||
rxa->eqp->execute();
|
rxa->eqp->execute();
|
||||||
ANF::xanf (rxa->anf, 0);
|
rxa->anf->execute(0);
|
||||||
ANR::xanr (rxa->anr, 0);
|
rxa->anr->ANR::execute(0);
|
||||||
EMNR::xemnr (rxa->emnr, 0);
|
rxa->emnr->execute(0);
|
||||||
BANDPASS::xbandpass (rxa->bp1, 0);
|
BANDPASS::xbandpass (rxa->bp1, 0);
|
||||||
WCPAGC::xwcpagc (rxa->agc);
|
WCPAGC::xwcpagc (rxa->agc);
|
||||||
ANF::xanf (rxa->anf, 1);
|
rxa->anf->execute(1);
|
||||||
ANR::xanr (rxa->anr, 1);
|
rxa->anr->execute(1);
|
||||||
EMNR::xemnr (rxa->emnr, 1);
|
rxa->emnr->execute(1);
|
||||||
BANDPASS::xbandpass (rxa->bp1, 1);
|
BANDPASS::xbandpass (rxa->bp1, 1);
|
||||||
rxa->agcmeter->execute();
|
rxa->agcmeter->execute();
|
||||||
SIPHON::xsiphon (rxa->sip1, 0);
|
SIPHON::xsiphon (rxa->sip1, 0);
|
||||||
@ -764,9 +764,9 @@ void RXA::setDSPSamplerate (RXA *rxa, int dsp_rate)
|
|||||||
rxa->fmsq->setSamplerate(rxa->dsp_rate);
|
rxa->fmsq->setSamplerate(rxa->dsp_rate);
|
||||||
// rxa->snba->setSamplerate(rxa->dsp_rate); SMBA removed
|
// 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);
|
rxa->anf->setSamplerate(rxa->dsp_rate);
|
||||||
ANR::setSamplerate_anr (rxa->anr, rxa->dsp_rate);
|
rxa->anr->setSamplerate(rxa->dsp_rate);
|
||||||
EMNR::setSamplerate_emnr (rxa->emnr, rxa->dsp_rate);
|
rxa->emnr->setSamplerate(rxa->dsp_rate);
|
||||||
BANDPASS::setSamplerate_bandpass (rxa->bp1, rxa->dsp_rate);
|
BANDPASS::setSamplerate_bandpass (rxa->bp1, rxa->dsp_rate);
|
||||||
WCPAGC::setSamplerate_wcpagc (rxa->agc, rxa->dsp_rate);
|
WCPAGC::setSamplerate_wcpagc (rxa->agc, rxa->dsp_rate);
|
||||||
rxa->agcmeter->setSamplerate(rxa->dsp_rate);
|
rxa->agcmeter->setSamplerate(rxa->dsp_rate);
|
||||||
@ -837,12 +837,12 @@ void RXA::setDSPBuffsize (RXA *rxa, int dsp_size)
|
|||||||
rxa->snba->setSize(rxa->dsp_size);
|
rxa->snba->setSize(rxa->dsp_size);
|
||||||
rxa->eqp->setBuffers(rxa->midbuff, rxa->midbuff);
|
rxa->eqp->setBuffers(rxa->midbuff, rxa->midbuff);
|
||||||
rxa->eqp->setSize(rxa->dsp_size);
|
rxa->eqp->setSize(rxa->dsp_size);
|
||||||
ANF::setBuffers_anf (rxa->anf, rxa->midbuff, rxa->midbuff);
|
rxa->anf->setBuffers(rxa->midbuff, rxa->midbuff);
|
||||||
ANF::setSize_anf (rxa->anf, rxa->dsp_size);
|
rxa->anf->setSize(rxa->dsp_size);
|
||||||
ANR::setBuffers_anr (rxa->anr, rxa->midbuff, rxa->midbuff);
|
rxa->anr->setBuffers(rxa->midbuff, rxa->midbuff);
|
||||||
ANR::setSize_anr (rxa->anr, rxa->dsp_size);
|
rxa->anr->setSize(rxa->dsp_size);
|
||||||
EMNR::setBuffers_emnr (rxa->emnr, rxa->midbuff, rxa->midbuff);
|
rxa->emnr->setBuffers(rxa->midbuff, rxa->midbuff);
|
||||||
EMNR::setSize_emnr (rxa->emnr, rxa->dsp_size);
|
rxa->emnr->setSize(rxa->dsp_size);
|
||||||
BANDPASS::setBuffers_bandpass (rxa->bp1, rxa->midbuff, rxa->midbuff);
|
BANDPASS::setBuffers_bandpass (rxa->bp1, rxa->midbuff, rxa->midbuff);
|
||||||
BANDPASS::setSize_bandpass (rxa->bp1, rxa->dsp_size);
|
BANDPASS::setSize_bandpass (rxa->bp1, rxa->dsp_size);
|
||||||
WCPAGC::setBuffers_wcpagc (rxa->agc, rxa->midbuff, rxa->midbuff);
|
WCPAGC::setBuffers_wcpagc (rxa->agc, rxa->midbuff, rxa->midbuff);
|
||||||
@ -1280,10 +1280,17 @@ void RXA::SetANFRun (RXA& rxa, int run)
|
|||||||
);
|
);
|
||||||
a->run = run;
|
a->run = run;
|
||||||
RXA::bp1Set (rxa);
|
RXA::bp1Set (rxa);
|
||||||
ANF::flush_anf (a);
|
a->flush();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void RXA::SetANFPosition (RXA& rxa, int position)
|
||||||
|
{
|
||||||
|
rxa.anf->position = position;
|
||||||
|
rxa.bp1->position = position;
|
||||||
|
rxa.anf->flush();
|
||||||
|
}
|
||||||
|
|
||||||
void RXA::SetANRRun (RXA& rxa, int run)
|
void RXA::SetANRRun (RXA& rxa, int run)
|
||||||
{
|
{
|
||||||
ANR *a = rxa.anr;
|
ANR *a = rxa.anr;
|
||||||
@ -1300,10 +1307,17 @@ void RXA::SetANRRun (RXA& rxa, int run)
|
|||||||
);
|
);
|
||||||
a->run = run;
|
a->run = run;
|
||||||
RXA::bp1Set (rxa);
|
RXA::bp1Set (rxa);
|
||||||
ANR::flush_anr (a);
|
a->flush();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void RXA::SetANRPosition (RXA& rxa, int position)
|
||||||
|
{
|
||||||
|
rxa.anr->position = position;
|
||||||
|
rxa.bp1->position = position;
|
||||||
|
rxa.anr->flush();
|
||||||
|
}
|
||||||
|
|
||||||
void RXA::SetEMNRRun (RXA& rxa, int run)
|
void RXA::SetEMNRRun (RXA& rxa, int run)
|
||||||
{
|
{
|
||||||
EMNR *a = rxa.emnr;
|
EMNR *a = rxa.emnr;
|
||||||
@ -1323,6 +1337,12 @@ void RXA::SetEMNRRun (RXA& rxa, int run)
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void RXA::SetEMNRPosition (RXA& rxa, int position)
|
||||||
|
{
|
||||||
|
rxa.emnr->position = position;
|
||||||
|
rxa.bp1->position = position;
|
||||||
|
}
|
||||||
|
|
||||||
/********************************************************************************************************
|
/********************************************************************************************************
|
||||||
* *
|
* *
|
||||||
* Collectives *
|
* Collectives *
|
||||||
|
@ -173,11 +173,13 @@ public:
|
|||||||
static void SetSNBARun (RXA& rxa, int run);
|
static void SetSNBARun (RXA& rxa, int run);
|
||||||
// ANF
|
// ANF
|
||||||
static void SetANFRun (RXA& rxa, int run);
|
static void SetANFRun (RXA& rxa, int run);
|
||||||
|
static void SetANFPosition (RXA& rxa, int position);
|
||||||
// ANR
|
// ANR
|
||||||
static void SetANRRun (RXA& rxa, int run);
|
static void SetANRRun (RXA& rxa, int run);
|
||||||
|
static void SetANRPosition (RXA& rxa, int position);
|
||||||
// EMNR
|
// EMNR
|
||||||
static void SetEMNRRun (RXA& rxa, int run);
|
static void SetEMNRRun (RXA& rxa, int run);
|
||||||
|
static void SetEMNRPosition (RXA& rxa, int position);
|
||||||
// Collectives
|
// Collectives
|
||||||
static void SetPassband (RXA& rxa, float f_low, float f_high);
|
static void SetPassband (RXA& rxa, float f_low, float f_high);
|
||||||
static void SetNC (RXA& rxa, int nc);
|
static void SetNC (RXA& rxa, int nc);
|
||||||
|
@ -100,6 +100,7 @@ public:
|
|||||||
double tauI
|
double tauI
|
||||||
);
|
);
|
||||||
AMD(const AMD&) = delete;
|
AMD(const AMD&) = delete;
|
||||||
|
AMD& operator=(const AMD& other) = delete;
|
||||||
~AMD() = default;
|
~AMD() = default;
|
||||||
|
|
||||||
void init();
|
void init();
|
||||||
|
@ -81,6 +81,7 @@ public:
|
|||||||
double _muted_gain
|
double _muted_gain
|
||||||
);
|
);
|
||||||
AMSQ(const AMSQ&) = delete;
|
AMSQ(const AMSQ&) = delete;
|
||||||
|
AMSQ& operator=(const AMSQ& other) = delete;
|
||||||
~AMSQ() = default;
|
~AMSQ() = default;
|
||||||
|
|
||||||
void flush();
|
void flush();
|
||||||
|
@ -80,6 +80,7 @@ public:
|
|||||||
double threshold
|
double threshold
|
||||||
);
|
);
|
||||||
ANB(const ANB&) = delete;
|
ANB(const ANB&) = delete;
|
||||||
|
ANB& operator=(const ANB& other) = delete;
|
||||||
~ANB() = default;
|
~ANB() = default;
|
||||||
|
|
||||||
void flush();
|
void flush();
|
||||||
|
201
wdsp/anf.cpp
201
wdsp/anf.cpp
@ -36,144 +36,136 @@ warren@wpratt.com
|
|||||||
|
|
||||||
namespace WDSP {
|
namespace WDSP {
|
||||||
|
|
||||||
ANF* ANF::create_anf(
|
ANF::ANF(
|
||||||
int run,
|
int _run,
|
||||||
int position,
|
int _position,
|
||||||
int buff_size,
|
int _buff_size,
|
||||||
float *in_buff,
|
float *_in_buff,
|
||||||
float *out_buff,
|
float *_out_buff,
|
||||||
int dline_size,
|
int _dline_size,
|
||||||
int n_taps,
|
int _n_taps,
|
||||||
int delay,
|
int _delay,
|
||||||
double two_mu,
|
double _two_mu,
|
||||||
double gamma,
|
double _gamma,
|
||||||
double lidx,
|
double _lidx,
|
||||||
double lidx_min,
|
double _lidx_min,
|
||||||
double lidx_max,
|
double _lidx_max,
|
||||||
double ngamma,
|
double _ngamma,
|
||||||
double den_mult,
|
double _den_mult,
|
||||||
double lincr,
|
double _lincr,
|
||||||
double ldecr
|
double _ldecr
|
||||||
)
|
)
|
||||||
{
|
{
|
||||||
ANF *a = new ANF;
|
run = _run;
|
||||||
a->run = run;
|
position = _position;
|
||||||
a->position = position;
|
buff_size = _buff_size;
|
||||||
a->buff_size = buff_size;
|
in_buff = _in_buff;
|
||||||
a->in_buff = in_buff;
|
out_buff = _out_buff;
|
||||||
a->out_buff = out_buff;
|
dline_size = _dline_size;
|
||||||
a->dline_size = dline_size;
|
mask = _dline_size - 1;
|
||||||
a->mask = dline_size - 1;
|
n_taps = _n_taps;
|
||||||
a->n_taps = n_taps;
|
delay = _delay;
|
||||||
a->delay = delay;
|
two_mu = _two_mu;
|
||||||
a->two_mu = two_mu;
|
gamma = _gamma;
|
||||||
a->gamma = gamma;
|
in_idx = 0;
|
||||||
a->in_idx = 0;
|
lidx = _lidx;
|
||||||
a->lidx = lidx;
|
lidx_min = _lidx_min;
|
||||||
a->lidx_min = lidx_min;
|
lidx_max = _lidx_max;
|
||||||
a->lidx_max = lidx_max;
|
ngamma = _ngamma;
|
||||||
a->ngamma = ngamma;
|
den_mult = _den_mult;
|
||||||
a->den_mult = den_mult;
|
lincr = _lincr;
|
||||||
a->lincr = lincr;
|
ldecr = _ldecr;
|
||||||
a->ldecr = ldecr;
|
|
||||||
|
|
||||||
memset (a->d, 0, sizeof(double) * ANF_DLINE_SIZE);
|
std::fill(d.begin(), d.end(), 0);
|
||||||
memset (a->w, 0, sizeof(double) * ANF_DLINE_SIZE);
|
std::fill(w.begin(), w.end(), 0);
|
||||||
|
|
||||||
return a;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void ANF::destroy_anf (ANF *a)
|
void ANF::execute(int _position)
|
||||||
{
|
|
||||||
delete a;
|
|
||||||
}
|
|
||||||
|
|
||||||
void ANF::xanf(ANF *a, int position)
|
|
||||||
{
|
{
|
||||||
int i, j, idx;
|
int i, j, idx;
|
||||||
double c0, c1;
|
double c0, c1;
|
||||||
double y, error, sigma, inv_sigp;
|
double y, error, sigma, inv_sigp;
|
||||||
double nel, nev;
|
double nel, nev;
|
||||||
|
|
||||||
if (a->run && (a->position == position))
|
if (run && (position == _position))
|
||||||
{
|
{
|
||||||
for (i = 0; i < a->buff_size; i++)
|
for (i = 0; i < buff_size; i++)
|
||||||
{
|
{
|
||||||
a->d[a->in_idx] = a->in_buff[2 * i + 0];
|
d[in_idx] = in_buff[2 * i + 0];
|
||||||
|
|
||||||
y = 0;
|
y = 0;
|
||||||
sigma = 0;
|
sigma = 0;
|
||||||
|
|
||||||
for (j = 0; j < a->n_taps; j++)
|
for (j = 0; j < n_taps; j++)
|
||||||
{
|
{
|
||||||
idx = (a->in_idx + j + a->delay) & a->mask;
|
idx = (in_idx + j + delay) & mask;
|
||||||
y += a->w[j] * a->d[idx];
|
y += w[j] * d[idx];
|
||||||
sigma += a->d[idx] * a->d[idx];
|
sigma += d[idx] * d[idx];
|
||||||
}
|
}
|
||||||
|
|
||||||
inv_sigp = 1.0 / (sigma + 1e-10);
|
inv_sigp = 1.0 / (sigma + 1e-10);
|
||||||
error = a->d[a->in_idx] - y;
|
error = d[in_idx] - y;
|
||||||
|
|
||||||
a->out_buff[2 * i + 0] = error;
|
out_buff[2 * i + 0] = error;
|
||||||
a->out_buff[2 * i + 1] = 0.0;
|
out_buff[2 * i + 1] = 0.0;
|
||||||
|
|
||||||
if ((nel = error * (1.0 - a->two_mu * sigma * inv_sigp)) < 0.0)
|
if ((nel = error * (1.0 - two_mu * sigma * inv_sigp)) < 0.0)
|
||||||
nel = -nel;
|
nel = -nel;
|
||||||
|
|
||||||
if ((nev = a->d[a->in_idx] - (1.0 - a->two_mu * a->ngamma) * y - a->two_mu * error * sigma * inv_sigp) < 0.0)
|
if ((nev = d[in_idx] - (1.0 - two_mu * ngamma) * y - two_mu * error * sigma * inv_sigp) < 0.0)
|
||||||
nev = -nev;
|
nev = -nev;
|
||||||
|
|
||||||
if (nev < nel)
|
if (nev < nel)
|
||||||
{
|
{
|
||||||
if ((a->lidx += a->lincr) > a->lidx_max) a->lidx = a->lidx_max;
|
if ((lidx += lincr) > lidx_max) lidx = lidx_max;
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
if ((a->lidx -= a->ldecr) < a->lidx_min) a->lidx = a->lidx_min;
|
if ((lidx -= ldecr) < lidx_min) lidx = lidx_min;
|
||||||
}
|
}
|
||||||
|
|
||||||
a->ngamma = a->gamma * (a->lidx * a->lidx) * (a->lidx * a->lidx) * a->den_mult;
|
ngamma = gamma * (lidx * lidx) * (lidx * lidx) * den_mult;
|
||||||
|
|
||||||
c0 = 1.0 - a->two_mu * a->ngamma;
|
c0 = 1.0 - two_mu * ngamma;
|
||||||
c1 = a->two_mu * error * inv_sigp;
|
c1 = two_mu * error * inv_sigp;
|
||||||
|
|
||||||
for (j = 0; j < a->n_taps; j++)
|
for (j = 0; j < n_taps; j++)
|
||||||
{
|
{
|
||||||
idx = (a->in_idx + j + a->delay) & a->mask;
|
idx = (in_idx + j + delay) & mask;
|
||||||
a->w[j] = c0 * a->w[j] + c1 * a->d[idx];
|
w[j] = c0 * w[j] + c1 * d[idx];
|
||||||
}
|
}
|
||||||
|
|
||||||
a->in_idx = (a->in_idx + a->mask) & a->mask;
|
in_idx = (in_idx + mask) & mask;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
else if (a->in_buff != a->out_buff)
|
else if (in_buff != out_buff)
|
||||||
{
|
{
|
||||||
std::copy(a->in_buff, a->in_buff + a->buff_size * 2, a->out_buff);
|
std::copy(in_buff, in_buff + buff_size * 2, out_buff);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void ANF::flush_anf (ANF *a)
|
void ANF::flush()
|
||||||
{
|
{
|
||||||
memset (a->d, 0, sizeof(double) * ANF_DLINE_SIZE);
|
std::fill(d.begin(), d.end(), 0);
|
||||||
memset (a->w, 0, sizeof(double) * ANF_DLINE_SIZE);
|
std::fill(w.begin(), w.end(), 0);
|
||||||
a->in_idx = 0;
|
in_idx = 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
void ANF::setBuffers_anf (ANF *a, float* in, float* out)
|
void ANF::setBuffers(float* _in, float* _out)
|
||||||
{
|
{
|
||||||
a->in_buff = in;
|
in_buff = _in;
|
||||||
a->out_buff = out;
|
out_buff = _out;
|
||||||
}
|
}
|
||||||
|
|
||||||
void ANF::setSamplerate_anf (ANF *a, int)
|
void ANF::setSamplerate(int)
|
||||||
{
|
{
|
||||||
flush_anf (a);
|
flush();
|
||||||
}
|
}
|
||||||
|
|
||||||
void ANF::setSize_anf (ANF *a, int size)
|
void ANF::setSize(int _size)
|
||||||
{
|
{
|
||||||
a->buff_size = size;
|
buff_size = _size;
|
||||||
flush_anf (a);
|
flush();
|
||||||
}
|
}
|
||||||
|
|
||||||
/********************************************************************************************************
|
/********************************************************************************************************
|
||||||
@ -182,44 +174,37 @@ void ANF::setSize_anf (ANF *a, int size)
|
|||||||
* *
|
* *
|
||||||
********************************************************************************************************/
|
********************************************************************************************************/
|
||||||
|
|
||||||
void ANF::SetANFVals (RXA& rxa, int taps, int delay, double gain, double leakage)
|
void ANF::setVals(int _taps, int _delay, double _gain, double _leakage)
|
||||||
{
|
{
|
||||||
rxa.anf->n_taps = taps;
|
n_taps = _taps;
|
||||||
rxa.anf->delay = delay;
|
delay = _delay;
|
||||||
rxa.anf->two_mu = gain; //try two_mu = 1e-4
|
two_mu = _gain; //try two_mu = 1e-4
|
||||||
rxa.anf->gamma = leakage; //try gamma = 0.10
|
gamma = _leakage; //try gamma = 0.10
|
||||||
flush_anf (rxa.anf);
|
flush();
|
||||||
}
|
}
|
||||||
|
|
||||||
void ANF::SetANFTaps (RXA& rxa, int taps)
|
void ANF::setTaps(int _taps)
|
||||||
{
|
{
|
||||||
rxa.anf->n_taps = taps;
|
n_taps = _taps;
|
||||||
flush_anf (rxa.anf);
|
flush();
|
||||||
}
|
}
|
||||||
|
|
||||||
void ANF::SetANFDelay (RXA& rxa, int delay)
|
void ANF::setDelay(int _delay)
|
||||||
{
|
{
|
||||||
rxa.anf->delay = delay;
|
delay = _delay;
|
||||||
flush_anf (rxa.anf);
|
flush();
|
||||||
}
|
}
|
||||||
|
|
||||||
void ANF::SetANFGain (RXA& rxa, double gain)
|
void ANF::setGain(double _gain)
|
||||||
{
|
{
|
||||||
rxa.anf->two_mu = gain;
|
two_mu = _gain;
|
||||||
flush_anf (rxa.anf);
|
flush();
|
||||||
}
|
}
|
||||||
|
|
||||||
void ANF::SetANFLeakage (RXA& rxa, double leakage)
|
void ANF::setLeakage(double _leakage)
|
||||||
{
|
{
|
||||||
rxa.anf->gamma = leakage;
|
gamma = _leakage;
|
||||||
flush_anf (rxa.anf);
|
flush();
|
||||||
}
|
|
||||||
|
|
||||||
void ANF::SetANFPosition (RXA& rxa, int position)
|
|
||||||
{
|
|
||||||
rxa.anf->position = position;
|
|
||||||
rxa.bp1->position = position;
|
|
||||||
flush_anf (rxa.anf);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
} // namespace WDSP
|
} // namespace WDSP
|
||||||
|
36
wdsp/anf.hpp
36
wdsp/anf.hpp
@ -28,6 +28,8 @@ warren@wpratt.com
|
|||||||
#ifndef wdsp_anf_h
|
#ifndef wdsp_anf_h
|
||||||
#define wdsp_anf_h
|
#define wdsp_anf_h
|
||||||
|
|
||||||
|
#include <array>
|
||||||
|
|
||||||
#include "export.h"
|
#include "export.h"
|
||||||
|
|
||||||
#define ANF_DLINE_SIZE 2048
|
#define ANF_DLINE_SIZE 2048
|
||||||
@ -50,8 +52,8 @@ public:
|
|||||||
int delay;
|
int delay;
|
||||||
double two_mu;
|
double two_mu;
|
||||||
double gamma;
|
double gamma;
|
||||||
double d [ANF_DLINE_SIZE];
|
std::array<double, ANF_DLINE_SIZE> d;
|
||||||
double w [ANF_DLINE_SIZE];
|
std::array<double, ANF_DLINE_SIZE> w;
|
||||||
int in_idx;
|
int in_idx;
|
||||||
double lidx;
|
double lidx;
|
||||||
double lidx_min;
|
double lidx_min;
|
||||||
@ -61,7 +63,7 @@ public:
|
|||||||
double lincr;
|
double lincr;
|
||||||
double ldecr;
|
double ldecr;
|
||||||
|
|
||||||
static ANF* create_anf(
|
ANF(
|
||||||
int run,
|
int run,
|
||||||
int position,
|
int position,
|
||||||
int buff_size,
|
int buff_size,
|
||||||
@ -80,19 +82,21 @@ public:
|
|||||||
double lincr,
|
double lincr,
|
||||||
double ldecr
|
double ldecr
|
||||||
);
|
);
|
||||||
static void destroy_anf (ANF *a);
|
ANF(const ANF&) = delete;
|
||||||
static void flush_anf (ANF *a);
|
ANF& operator=(const ANF& other) = delete;
|
||||||
static void xanf (ANF *a, int position);
|
~ANF() = default;
|
||||||
static void setBuffers_anf (ANF *a, float* in, float* out);
|
|
||||||
static void setSamplerate_anf (ANF *a, int rate);
|
void flush();
|
||||||
static void setSize_anf (ANF *a, int size);
|
void execute(int position);
|
||||||
// RXA Properties
|
void setBuffers(float* in, float* out);
|
||||||
static void SetANFVals (RXA& rxa, int taps, int delay, double gain, double leakage);
|
void setSamplerate(int rate);
|
||||||
static void SetANFTaps (RXA& rxa, int taps);
|
void setSize(int size);
|
||||||
static void SetANFDelay (RXA& rxa, int delay);
|
// Public Properties
|
||||||
static void SetANFGain (RXA& rxa, double gain);
|
void setVals(int taps, int delay, double gain, double leakage);
|
||||||
static void SetANFLeakage (RXA& rxa, double leakage);
|
void setTaps(int taps);
|
||||||
static void SetANFPosition (RXA& rxa, int position);
|
void setDelay(int delay);
|
||||||
|
void setGain(double gain);
|
||||||
|
void setLeakage(double leakage);
|
||||||
};
|
};
|
||||||
|
|
||||||
} // namespace WDSP
|
} // namespace WDSP
|
||||||
|
210
wdsp/anr.cpp
210
wdsp/anr.cpp
@ -36,190 +36,174 @@ warren@wpratt.com
|
|||||||
|
|
||||||
namespace WDSP {
|
namespace WDSP {
|
||||||
|
|
||||||
ANR* ANR::create_anr (
|
ANR::ANR(
|
||||||
int run,
|
int _run,
|
||||||
int position,
|
int _position,
|
||||||
int buff_size,
|
int _buff_size,
|
||||||
float *in_buff,
|
float *_in_buff,
|
||||||
float *out_buff,
|
float *_out_buff,
|
||||||
int dline_size,
|
int _dline_size,
|
||||||
int n_taps,
|
int _n_taps,
|
||||||
int delay,
|
int _delay,
|
||||||
double two_mu,
|
double _two_mu,
|
||||||
double gamma,
|
double _gamma,
|
||||||
double lidx,
|
double _lidx,
|
||||||
double lidx_min,
|
double _lidx_min,
|
||||||
double lidx_max,
|
double _lidx_max,
|
||||||
double ngamma,
|
double _ngamma,
|
||||||
double den_mult,
|
double _den_mult,
|
||||||
double lincr,
|
double _lincr,
|
||||||
double ldecr
|
double _ldecr
|
||||||
)
|
) :
|
||||||
|
run(_run),
|
||||||
|
position(_position),
|
||||||
|
buff_size(_buff_size),
|
||||||
|
in_buff(_in_buff),
|
||||||
|
out_buff(_out_buff),
|
||||||
|
dline_size(_dline_size),
|
||||||
|
mask(_dline_size - 1),
|
||||||
|
n_taps(_n_taps),
|
||||||
|
delay(_delay),
|
||||||
|
two_mu(_two_mu),
|
||||||
|
gamma(_gamma),
|
||||||
|
in_idx(0),
|
||||||
|
lidx(_lidx),
|
||||||
|
lidx_min(_lidx_min),
|
||||||
|
lidx_max(_lidx_max),
|
||||||
|
ngamma(_ngamma),
|
||||||
|
den_mult(_den_mult),
|
||||||
|
lincr(_lincr),
|
||||||
|
ldecr(_ldecr)
|
||||||
{
|
{
|
||||||
ANR *a = new ANR;
|
std::fill(d.begin(), d.end(), 0);
|
||||||
a->run = run;
|
std::fill(w.begin(), w.end(), 0);
|
||||||
a->position = position;
|
|
||||||
a->buff_size = buff_size;
|
|
||||||
a->in_buff = in_buff;
|
|
||||||
a->out_buff = out_buff;
|
|
||||||
a->dline_size = dline_size;
|
|
||||||
a->mask = dline_size - 1;
|
|
||||||
a->n_taps = n_taps;
|
|
||||||
a->delay = delay;
|
|
||||||
a->two_mu = two_mu;
|
|
||||||
a->gamma = gamma;
|
|
||||||
a->in_idx = 0;
|
|
||||||
a->lidx = lidx;
|
|
||||||
a->lidx_min = lidx_min;
|
|
||||||
a->lidx_max = lidx_max;
|
|
||||||
a->ngamma = ngamma;
|
|
||||||
a->den_mult = den_mult;
|
|
||||||
a->lincr = lincr;
|
|
||||||
a->ldecr = ldecr;
|
|
||||||
|
|
||||||
memset (a->d, 0, sizeof(double) * ANR_DLINE_SIZE);
|
|
||||||
memset (a->w, 0, sizeof(double) * ANR_DLINE_SIZE);
|
|
||||||
|
|
||||||
return a;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void ANR::destroy_anr (ANR *a)
|
void ANR::execute(int _position)
|
||||||
{
|
|
||||||
delete a;
|
|
||||||
}
|
|
||||||
|
|
||||||
void ANR::xanr (ANR *a, int position)
|
|
||||||
{
|
{
|
||||||
int i, j, idx;
|
int i, j, idx;
|
||||||
double c0, c1;
|
double c0, c1;
|
||||||
double y, error, sigma, inv_sigp;
|
double y, error, sigma, inv_sigp;
|
||||||
double nel, nev;
|
double nel, nev;
|
||||||
|
|
||||||
if (a->run && (a->position == position))
|
if (run && (position == _position))
|
||||||
{
|
{
|
||||||
for (i = 0; i < a->buff_size; i++)
|
for (i = 0; i < buff_size; i++)
|
||||||
{
|
{
|
||||||
a->d[a->in_idx] = a->in_buff[2 * i + 0];
|
d[in_idx] = in_buff[2 * i + 0];
|
||||||
|
|
||||||
y = 0;
|
y = 0;
|
||||||
sigma = 0;
|
sigma = 0;
|
||||||
|
|
||||||
for (j = 0; j < a->n_taps; j++)
|
for (j = 0; j < n_taps; j++)
|
||||||
{
|
{
|
||||||
idx = (a->in_idx + j + a->delay) & a->mask;
|
idx = (in_idx + j + delay) & mask;
|
||||||
y += a->w[j] * a->d[idx];
|
y += w[j] * d[idx];
|
||||||
sigma += a->d[idx] * a->d[idx];
|
sigma += d[idx] * d[idx];
|
||||||
}
|
}
|
||||||
|
|
||||||
inv_sigp = 1.0 / (sigma + 1e-10);
|
inv_sigp = 1.0 / (sigma + 1e-10);
|
||||||
error = a->d[a->in_idx] - y;
|
error = d[in_idx] - y;
|
||||||
|
|
||||||
a->out_buff[2 * i + 0] = y;
|
out_buff[2 * i + 0] = y;
|
||||||
a->out_buff[2 * i + 1] = 0.0;
|
out_buff[2 * i + 1] = 0.0;
|
||||||
|
|
||||||
if ((nel = error * (1.0 - a->two_mu * sigma * inv_sigp)) < 0.0)
|
if ((nel = error * (1.0 - two_mu * sigma * inv_sigp)) < 0.0)
|
||||||
nel = -nel;
|
nel = -nel;
|
||||||
if ((nev = a->d[a->in_idx] - (1.0 - a->two_mu * a->ngamma) * y - a->two_mu * error * sigma * inv_sigp) < 0.0)
|
if ((nev = d[in_idx] - (1.0 - two_mu * ngamma) * y - two_mu * error * sigma * inv_sigp) < 0.0)
|
||||||
nev = -nev;
|
nev = -nev;
|
||||||
|
|
||||||
if (nev < nel)
|
if (nev < nel)
|
||||||
{
|
{
|
||||||
if ((a->lidx += a->lincr) > a->lidx_max)
|
if ((lidx += lincr) > lidx_max)
|
||||||
a->lidx = a->lidx_max;
|
lidx = lidx_max;
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
if ((a->lidx -= a->ldecr) < a->lidx_min)
|
if ((lidx -= ldecr) < lidx_min)
|
||||||
a->lidx = a->lidx_min;
|
lidx = lidx_min;
|
||||||
}
|
}
|
||||||
|
|
||||||
a->ngamma = a->gamma * (a->lidx * a->lidx) * (a->lidx * a->lidx) * a->den_mult;
|
ngamma = gamma * (lidx * lidx) * (lidx * lidx) * den_mult;
|
||||||
c0 = 1.0 - a->two_mu * a->ngamma;
|
c0 = 1.0 - two_mu * ngamma;
|
||||||
c1 = a->two_mu * error * inv_sigp;
|
c1 = two_mu * error * inv_sigp;
|
||||||
|
|
||||||
for (j = 0; j < a->n_taps; j++)
|
for (j = 0; j < n_taps; j++)
|
||||||
{
|
{
|
||||||
idx = (a->in_idx + j + a->delay) & a->mask;
|
idx = (in_idx + j + delay) & mask;
|
||||||
a->w[j] = c0 * a->w[j] + c1 * a->d[idx];
|
w[j] = c0 * w[j] + c1 * d[idx];
|
||||||
}
|
}
|
||||||
|
|
||||||
a->in_idx = (a->in_idx + a->mask) & a->mask;
|
in_idx = (in_idx + mask) & mask;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
else if (a->in_buff != a->out_buff)
|
else if (in_buff != out_buff)
|
||||||
{
|
{
|
||||||
std::copy(a->in_buff, a->in_buff + a->buff_size * 2, a->out_buff);
|
std::copy(in_buff, in_buff + buff_size * 2, out_buff);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void ANR::flush_anr (ANR *a)
|
void ANR::flush()
|
||||||
{
|
{
|
||||||
memset (a->d, 0, sizeof(double) * ANR_DLINE_SIZE);
|
std::fill(d.begin(), d.end(), 0);
|
||||||
memset (a->w, 0, sizeof(double) * ANR_DLINE_SIZE);
|
std::fill(w.begin(), w.end(), 0);
|
||||||
a->in_idx = 0;
|
in_idx = 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
void ANR::setBuffers_anr (ANR *a, float* in, float* out)
|
void ANR::setBuffers(float* _in, float* _out)
|
||||||
{
|
{
|
||||||
a->in_buff = in;
|
in_buff = _in;
|
||||||
a->out_buff = out;
|
out_buff = _out;
|
||||||
}
|
}
|
||||||
|
|
||||||
void ANR::setSamplerate_anr (ANR *a, int)
|
void ANR::setSamplerate(int)
|
||||||
{
|
{
|
||||||
flush_anr(a);
|
flush();
|
||||||
}
|
}
|
||||||
|
|
||||||
void ANR::setSize_anr (ANR *a, int size)
|
void ANR::setSize(int _size)
|
||||||
{
|
{
|
||||||
a->buff_size = size;
|
buff_size = _size;
|
||||||
flush_anr(a);
|
flush();
|
||||||
}
|
}
|
||||||
|
|
||||||
/********************************************************************************************************
|
/********************************************************************************************************
|
||||||
* *
|
* *
|
||||||
* RXA Properties *
|
* Public Properties *
|
||||||
* *
|
* *
|
||||||
********************************************************************************************************/
|
********************************************************************************************************/
|
||||||
|
|
||||||
void ANR::SetANRVals (RXA& rxa, int taps, int delay, double gain, double leakage)
|
void ANR::setVals(int _taps, int _delay, double _gain, double _leakage)
|
||||||
{
|
{
|
||||||
rxa.anr->n_taps = taps;
|
n_taps = _taps;
|
||||||
rxa.anr->delay = delay;
|
delay = _delay;
|
||||||
rxa.anr->two_mu = gain;
|
two_mu = _gain;
|
||||||
rxa.anr->gamma = leakage;
|
gamma = _leakage;
|
||||||
flush_anr (rxa.anr);
|
flush();
|
||||||
}
|
}
|
||||||
|
|
||||||
void ANR::SetANRTaps (RXA& rxa, int taps)
|
void ANR::setTaps(int _taps)
|
||||||
{
|
{
|
||||||
rxa.anr->n_taps = taps;
|
n_taps = _taps;
|
||||||
flush_anr (rxa.anr);
|
flush();
|
||||||
}
|
}
|
||||||
|
|
||||||
void ANR::SetANRDelay (RXA& rxa, int delay)
|
void ANR::setDelay(int _delay)
|
||||||
{
|
{
|
||||||
rxa.anr->delay = delay;
|
delay = _delay;
|
||||||
flush_anr (rxa.anr);
|
flush();
|
||||||
}
|
}
|
||||||
|
|
||||||
void ANR::SetANRGain (RXA& rxa, double gain)
|
void ANR::setGain(double _gain)
|
||||||
{
|
{
|
||||||
rxa.anr->two_mu = gain;
|
two_mu = _gain;
|
||||||
flush_anr (rxa.anr);
|
flush();
|
||||||
}
|
}
|
||||||
|
|
||||||
void ANR::SetANRLeakage (RXA& rxa, double leakage)
|
void ANR::setLeakage(double _leakage)
|
||||||
{
|
{
|
||||||
rxa.anr->gamma = leakage;
|
gamma = _leakage;
|
||||||
flush_anr (rxa.anr);
|
flush();
|
||||||
}
|
|
||||||
|
|
||||||
void ANR::SetANRPosition (RXA& rxa, int position)
|
|
||||||
{
|
|
||||||
rxa.anr->position = position;
|
|
||||||
rxa.bp1->position = position;
|
|
||||||
flush_anr (rxa.anr);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
} // namespace WDSP
|
} // namespace WDSP
|
||||||
|
33
wdsp/anr.hpp
33
wdsp/anr.hpp
@ -28,6 +28,8 @@ warren@wpratt.com
|
|||||||
#ifndef wdsp_anr_h
|
#ifndef wdsp_anr_h
|
||||||
#define wdsp_anr_h
|
#define wdsp_anr_h
|
||||||
|
|
||||||
|
#include <array>
|
||||||
|
|
||||||
#include "export.h"
|
#include "export.h"
|
||||||
|
|
||||||
#define ANR_DLINE_SIZE 2048
|
#define ANR_DLINE_SIZE 2048
|
||||||
@ -50,8 +52,8 @@ public:
|
|||||||
int delay;
|
int delay;
|
||||||
double two_mu;
|
double two_mu;
|
||||||
double gamma;
|
double gamma;
|
||||||
double d [ANR_DLINE_SIZE];
|
std::array<double, ANR_DLINE_SIZE> d;
|
||||||
double w [ANR_DLINE_SIZE];
|
std::array<double, ANR_DLINE_SIZE> w;
|
||||||
int in_idx;
|
int in_idx;
|
||||||
|
|
||||||
double lidx;
|
double lidx;
|
||||||
@ -62,7 +64,7 @@ public:
|
|||||||
double lincr;
|
double lincr;
|
||||||
double ldecr;
|
double ldecr;
|
||||||
|
|
||||||
static ANR* create_anr (
|
ANR(
|
||||||
int run,
|
int run,
|
||||||
int position,
|
int position,
|
||||||
int buff_size,
|
int buff_size,
|
||||||
@ -81,20 +83,21 @@ public:
|
|||||||
double lincr,
|
double lincr,
|
||||||
double ldecr
|
double ldecr
|
||||||
);
|
);
|
||||||
|
ANR(const ANR&) = delete;
|
||||||
|
ANR& operator=(const ANR& other) = delete;
|
||||||
|
~ANR() = default;
|
||||||
|
|
||||||
static void destroy_anr (ANR *a);
|
void flush();
|
||||||
static void flush_anr (ANR *a);
|
void execute(int position);
|
||||||
static void xanr (ANR *a, int position);
|
void setBuffers(float* in, float* out);
|
||||||
static void setBuffers_anr (ANR *a, float* in, float* out);
|
void setSamplerate(int rate);
|
||||||
static void setSamplerate_anr (ANR *a, int rate);
|
void setSize(int size);
|
||||||
static void setSize_anr (ANR *a, int size);
|
|
||||||
// RXA Properties
|
// RXA Properties
|
||||||
static void SetANRVals (RXA& rxa, int taps, int delay, double gain, double leakage);
|
void setVals(int taps, int delay, double gain, double leakage);
|
||||||
static void SetANRTaps (RXA& rxa, int taps);
|
void setTaps(int taps);
|
||||||
static void SetANRDelay (RXA& rxa, int delay);
|
void setDelay(int delay);
|
||||||
static void SetANRGain (RXA& rxa, double gain);
|
void setGain(double gain);
|
||||||
static void SetANRLeakage (RXA& rxa, double leakage);
|
void setLeakage(double leakage);
|
||||||
static void SetANRPosition (RXA& rxa, int position);
|
|
||||||
};
|
};
|
||||||
|
|
||||||
} // namespace WDSP
|
} // namespace WDSP
|
||||||
|
@ -80,6 +80,7 @@ public:
|
|||||||
NOTCHDB* notchdb
|
NOTCHDB* notchdb
|
||||||
);
|
);
|
||||||
BPSNBA(const BPSNBA&) = delete;
|
BPSNBA(const BPSNBA&) = delete;
|
||||||
|
BPSNBA& operator=(BPSNBA& other) = delete;
|
||||||
~BPSNBA();
|
~BPSNBA();
|
||||||
|
|
||||||
void flush();
|
void flush();
|
||||||
|
1348
wdsp/emnr.cpp
1348
wdsp/emnr.cpp
File diff suppressed because it is too large
Load Diff
167
wdsp/emnr.hpp
167
wdsp/emnr.hpp
@ -28,6 +28,9 @@ warren@wpratt.com
|
|||||||
#ifndef wdsp_emnr_h
|
#ifndef wdsp_emnr_h
|
||||||
#define wdsp_emnr_h
|
#define wdsp_emnr_h
|
||||||
|
|
||||||
|
#include <array>
|
||||||
|
#include <vector>
|
||||||
|
|
||||||
#include "fftw3.h"
|
#include "fftw3.h"
|
||||||
#include "export.h"
|
#include "export.h"
|
||||||
|
|
||||||
@ -46,18 +49,18 @@ public:
|
|||||||
int fsize;
|
int fsize;
|
||||||
int ovrlp;
|
int ovrlp;
|
||||||
int incr;
|
int incr;
|
||||||
float* window;
|
std::vector<float> window;
|
||||||
int iasize;
|
int iasize;
|
||||||
float* inaccum;
|
std::vector<float> inaccum;
|
||||||
float* forfftin;
|
std::vector<float> forfftin;
|
||||||
float* forfftout;
|
std::vector<float> forfftout;
|
||||||
int msize;
|
int msize;
|
||||||
double* mask;
|
std::vector<double> mask;
|
||||||
float* revfftin;
|
std::vector<float> revfftin;
|
||||||
float* revfftout;
|
std::vector<float> revfftout;
|
||||||
float** save;
|
std::vector<std::vector<float>> save;
|
||||||
int oasize;
|
int oasize;
|
||||||
float* outaccum;
|
std::vector<float> outaccum;
|
||||||
double rate;
|
double rate;
|
||||||
int wintype;
|
int wintype;
|
||||||
double ogain;
|
double ogain;
|
||||||
@ -71,14 +74,16 @@ public:
|
|||||||
int saveidx;
|
int saveidx;
|
||||||
fftwf_plan Rfor;
|
fftwf_plan Rfor;
|
||||||
fftwf_plan Rrev;
|
fftwf_plan Rrev;
|
||||||
struct _g
|
struct G
|
||||||
{
|
{
|
||||||
|
int incr;
|
||||||
|
double rate;
|
||||||
|
int msize;
|
||||||
|
double* mask;
|
||||||
|
float* y;
|
||||||
int gain_method;
|
int gain_method;
|
||||||
int npe_method;
|
int npe_method;
|
||||||
int ae_run;
|
int ae_run;
|
||||||
double msize;
|
|
||||||
double* mask;
|
|
||||||
float* y;
|
|
||||||
double* lambda_y;
|
double* lambda_y;
|
||||||
double* lambda_d;
|
double* lambda_d;
|
||||||
double* prev_mask;
|
double* prev_mask;
|
||||||
@ -93,36 +98,48 @@ public:
|
|||||||
double* GG;
|
double* GG;
|
||||||
double* GGS;
|
double* GGS;
|
||||||
FILE* fileb;
|
FILE* fileb;
|
||||||
} g;
|
G(
|
||||||
struct _npest
|
int incr,
|
||||||
|
double rate,
|
||||||
|
int msize,
|
||||||
|
double* mask,
|
||||||
|
float* y
|
||||||
|
);
|
||||||
|
G(const G&) = delete;
|
||||||
|
G& operator=(const G& other) = delete;
|
||||||
|
~G();
|
||||||
|
} *g;
|
||||||
|
struct NP
|
||||||
{
|
{
|
||||||
int incr;
|
int incr;
|
||||||
double rate;
|
double rate;
|
||||||
int msize;
|
int msize;
|
||||||
double* lambda_y;
|
double* lambda_y;
|
||||||
double* lambda_d;
|
double* lambda_d;
|
||||||
double* p;
|
|
||||||
double* alphaOptHat;
|
|
||||||
double alphaC;
|
|
||||||
double alphaCsmooth;
|
double alphaCsmooth;
|
||||||
double alphaCmin;
|
|
||||||
double* alphaHat;
|
|
||||||
double alphaMax;
|
double alphaMax;
|
||||||
double* sigma2N;
|
double alphaCmin;
|
||||||
double alphaMin_max_value;
|
double alphaMin_max_value;
|
||||||
double snrq;
|
double snrq;
|
||||||
double betamax;
|
double betamax;
|
||||||
double* pbar;
|
|
||||||
double* p2bar;
|
|
||||||
double invQeqMax;
|
double invQeqMax;
|
||||||
double av;
|
double av;
|
||||||
double* Qeq;
|
|
||||||
int U;
|
|
||||||
double Dtime;
|
double Dtime;
|
||||||
|
int U;
|
||||||
int V;
|
int V;
|
||||||
int D;
|
int D;
|
||||||
|
double* p;
|
||||||
|
double* alphaOptHat;
|
||||||
|
double alphaC;
|
||||||
|
double* alphaHat;
|
||||||
|
double* sigma2N;
|
||||||
|
double* pbar;
|
||||||
|
double* p2bar;
|
||||||
|
double* Qeq;
|
||||||
double MofD;
|
double MofD;
|
||||||
double MofV;
|
double MofV;
|
||||||
|
std::array<double, 4> invQbar_points;
|
||||||
|
std::array<double, 4> nsmax;
|
||||||
double* bmin;
|
double* bmin;
|
||||||
double* bmin_sub;
|
double* bmin_sub;
|
||||||
int* k_mod;
|
int* k_mod;
|
||||||
@ -131,12 +148,32 @@ public:
|
|||||||
int subwc;
|
int subwc;
|
||||||
int* lmin_flag;
|
int* lmin_flag;
|
||||||
double* pmin_u;
|
double* pmin_u;
|
||||||
double invQbar_points[4];
|
|
||||||
double nsmax[4];
|
|
||||||
double** actminbuff;
|
double** actminbuff;
|
||||||
int amb_idx;
|
int amb_idx;
|
||||||
} np;
|
NP(
|
||||||
struct _npests
|
int incr,
|
||||||
|
double rate,
|
||||||
|
int msize,
|
||||||
|
double* lambda_y,
|
||||||
|
double* lambda_d
|
||||||
|
);
|
||||||
|
NP(const NP&) = delete;
|
||||||
|
NP& operator=(const NP& other) = delete;
|
||||||
|
~NP();
|
||||||
|
void LambdaD();
|
||||||
|
|
||||||
|
private:
|
||||||
|
static const std::array<double, 18> DVals;
|
||||||
|
static const std::array<double, 18> MVals;
|
||||||
|
static void interpM (
|
||||||
|
double* res,
|
||||||
|
double x,
|
||||||
|
int nvals,
|
||||||
|
const std::array<double, 18>& xvals,
|
||||||
|
const std::array<double, 18>& yvals
|
||||||
|
);
|
||||||
|
} *np;
|
||||||
|
struct NPS
|
||||||
{
|
{
|
||||||
int incr;
|
int incr;
|
||||||
double rate;
|
double rate;
|
||||||
@ -153,17 +190,41 @@ public:
|
|||||||
double* PH1y;
|
double* PH1y;
|
||||||
double* Pbar;
|
double* Pbar;
|
||||||
double* EN2y;
|
double* EN2y;
|
||||||
} nps;
|
NPS(
|
||||||
struct _ae
|
int incr,
|
||||||
|
double rate,
|
||||||
|
int msize,
|
||||||
|
double* lambda_y,
|
||||||
|
double* lambda_d,
|
||||||
|
|
||||||
|
double alpha_pow,
|
||||||
|
double alpha_Pbar,
|
||||||
|
double epsH1
|
||||||
|
);
|
||||||
|
NPS(const NPS&) = delete;
|
||||||
|
NPS& operator=(const NPS& other) = delete;
|
||||||
|
~NPS();
|
||||||
|
void LambdaDs();
|
||||||
|
} *nps;
|
||||||
|
struct AE
|
||||||
{
|
{
|
||||||
int msize;
|
int msize;
|
||||||
double* lambda_y;
|
double* lambda_y;
|
||||||
double zetaThresh;
|
double zetaThresh;
|
||||||
double psi;
|
double psi;
|
||||||
double* nmask;
|
double* nmask;
|
||||||
} ae;
|
AE(
|
||||||
|
int msize,
|
||||||
|
double* lambda_y,
|
||||||
|
double zetaThresh,
|
||||||
|
double psi
|
||||||
|
);
|
||||||
|
AE(const AE&) = delete;
|
||||||
|
AE& operator=(const AE& other) = delete;
|
||||||
|
~AE();
|
||||||
|
} *ae;
|
||||||
|
|
||||||
static EMNR* create_emnr (
|
EMNR(
|
||||||
int run,
|
int run,
|
||||||
int position,
|
int position,
|
||||||
int size,
|
int size,
|
||||||
@ -178,33 +239,33 @@ public:
|
|||||||
int npe_method,
|
int npe_method,
|
||||||
int ae_run
|
int ae_run
|
||||||
);
|
);
|
||||||
static void destroy_emnr (EMNR *a);
|
EMNR(const EMNR&) = delete;
|
||||||
static void flush_emnr (EMNR *a);
|
EMNR& operator=(const EMNR& other) = delete;
|
||||||
static void xemnr (EMNR *a, int pos);
|
~EMNR();
|
||||||
static void setBuffers_emnr (EMNR *a, float* in, float* out);
|
|
||||||
static void setSamplerate_emnr (EMNR *a, int rate);
|
void flush();
|
||||||
static void setSize_emnr (EMNR *a, int size);
|
void execute(int pos);
|
||||||
// RXA Properties
|
void setBuffers(float* in, float* out);
|
||||||
static void SetEMNRgainMethod (RXA& rxa, int method);
|
void setSamplerate(int rate);
|
||||||
static void SetEMNRnpeMethod (RXA& rxa, int method);
|
void setSize(int size);
|
||||||
static void SetEMNRaeRun (RXA& rxa, int run);
|
// Public Properties
|
||||||
static void SetEMNRPosition (RXA& rxa, int position);
|
void setGainMethod(int method);
|
||||||
static void SetEMNRaeZetaThresh (RXA& rxa, double zetathresh);
|
void setNpeMethod(int method);
|
||||||
static void SetEMNRaePsi (RXA& rxa, double psi);
|
void setAeRun(int run);
|
||||||
|
void setAeZetaThresh(double zetathresh);
|
||||||
|
void setAePsi(double psi);
|
||||||
|
|
||||||
private:
|
private:
|
||||||
static double bessI0 (double x);
|
static double bessI0 (double x);
|
||||||
static double bessI1 (double x);
|
static double bessI1 (double x);
|
||||||
static double e1xb (double x);
|
static double e1xb (double x);
|
||||||
static void calc_window (EMNR *a);
|
|
||||||
static void interpM (double* res, double x, int nvals, double* xvals, double* yvals);
|
static void interpM (double* res, double x, int nvals, double* xvals, double* yvals);
|
||||||
static void calc_emnr(EMNR *a);
|
|
||||||
static void decalc_emnr(EMNR *a);
|
|
||||||
static void LambdaD(EMNR *a);
|
|
||||||
static void LambdaDs (EMNR *a);
|
|
||||||
static void aepf(EMNR *a);
|
|
||||||
static double getKey(double* type, double gamma, double xi);
|
static double getKey(double* type, double gamma, double xi);
|
||||||
static void calc_gain (EMNR *a);
|
void calc_window();
|
||||||
|
void calc();
|
||||||
|
void decalc();
|
||||||
|
void aepf();
|
||||||
|
void calc_gain();
|
||||||
};
|
};
|
||||||
|
|
||||||
} // namespace WDSP
|
} // namespace WDSP
|
||||||
|
@ -76,6 +76,7 @@ public:
|
|||||||
int samplerate
|
int samplerate
|
||||||
);
|
);
|
||||||
EQP(const EQP&) = delete;
|
EQP(const EQP&) = delete;
|
||||||
|
EQP& operator=(const EQP& other) = delete;
|
||||||
~EQP();
|
~EQP();
|
||||||
|
|
||||||
void flush();
|
void flush();
|
||||||
|
@ -111,6 +111,7 @@ public:
|
|||||||
int mp_aud
|
int mp_aud
|
||||||
);
|
);
|
||||||
FMD(const FMD&) = delete;
|
FMD(const FMD&) = delete;
|
||||||
|
FMD& operator=(const FMD& other) = delete;
|
||||||
~FMD();
|
~FMD();
|
||||||
|
|
||||||
void flush();
|
void flush();
|
||||||
|
@ -101,6 +101,7 @@ public:
|
|||||||
int _mp
|
int _mp
|
||||||
);
|
);
|
||||||
FMSQ(const FMSQ&) = delete;
|
FMSQ(const FMSQ&) = delete;
|
||||||
|
FMSQ& operator=(const FMSQ& other) = delete;
|
||||||
~FMSQ();
|
~FMSQ();
|
||||||
|
|
||||||
void flush();
|
void flush();
|
||||||
|
@ -52,6 +52,7 @@ public:
|
|||||||
|
|
||||||
NOTCHDB(int master_run, int maxnotches);
|
NOTCHDB(int master_run, int maxnotches);
|
||||||
NOTCHDB(const NOTCHDB&) = delete;
|
NOTCHDB(const NOTCHDB&) = delete;
|
||||||
|
NOTCHDB& operator=(const NOTCHDB& other) = delete;
|
||||||
~NOTCHDB() = default;
|
~NOTCHDB() = default;
|
||||||
|
|
||||||
int addNotch (int notch, double fcenter, double fwidth, int active);
|
int addNotch (int notch, double fcenter, double fwidth, int active);
|
||||||
@ -108,6 +109,7 @@ public:
|
|||||||
NOTCHDB* notchdb
|
NOTCHDB* notchdb
|
||||||
);
|
);
|
||||||
NBP(const NBP&) = delete;
|
NBP(const NBP&) = delete;
|
||||||
|
NBP& operator=(const NBP& other) = delete;
|
||||||
~NBP();
|
~NBP();
|
||||||
|
|
||||||
void flush();
|
void flush();
|
||||||
|
@ -99,6 +99,7 @@ public:
|
|||||||
double threshold
|
double threshold
|
||||||
);
|
);
|
||||||
NOB(const NOB&) = delete;
|
NOB(const NOB&) = delete;
|
||||||
|
NOB& operator=(const NOB& other) = delete;
|
||||||
~NOB() = default;
|
~NOB() = default;
|
||||||
//////////// legacy interface - remove
|
//////////// legacy interface - remove
|
||||||
void flush();
|
void flush();
|
||||||
|
@ -76,6 +76,7 @@ public:
|
|||||||
double gain
|
double gain
|
||||||
);
|
);
|
||||||
RESAMPLE(const RESAMPLE&) = delete;
|
RESAMPLE(const RESAMPLE&) = delete;
|
||||||
|
RESAMPLE& operator=(const RESAMPLE& other) = delete;
|
||||||
~RESAMPLE() = default;
|
~RESAMPLE() = default;
|
||||||
|
|
||||||
void flush();
|
void flush();
|
||||||
|
Loading…
x
Reference in New Issue
Block a user