1
0
mirror of https://github.com/f4exb/sdrangel.git synced 2024-12-22 01:20:56 -05:00

WDSP: ANF, ANR, EMNR: use vectors instead of C arrays and disable copy constructor

This commit is contained in:
f4exb 2024-07-29 08:57:02 +02:00
parent 3c2192603b
commit 6662357bcf
19 changed files with 1143 additions and 959 deletions

View File

@ -510,12 +510,12 @@ void WDSPRxSink::applySettings(const WDSPRxSettings& settings, bool force)
switch (settings.m_nrPosition)
{
case WDSPRxProfile::NRPositionPreAGC:
WDSP::ANR::SetANRPosition(*m_rxa, 0);
WDSP::EMNR::SetEMNRPosition(*m_rxa, 0);
WDSP::RXA::SetANRPosition(*m_rxa, 0);
WDSP::RXA::SetEMNRPosition(*m_rxa, 0);
break;
case WDSPRxProfile::NRPositionPostAGC:
WDSP::ANR::SetANRPosition(*m_rxa, 1);
WDSP::EMNR::SetEMNRPosition(*m_rxa, 1);
WDSP::RXA::SetANRPosition(*m_rxa, 1);
WDSP::RXA::SetEMNRPosition(*m_rxa, 1);
break;
default:
break;
@ -527,13 +527,13 @@ void WDSPRxSink::applySettings(const WDSPRxSettings& settings, bool force)
switch (settings.m_nr2Gain)
{
case WDSPRxProfile::NR2GainLinear:
WDSP::EMNR::SetEMNRgainMethod(*m_rxa, 0);
m_rxa->emnr->setGainMethod(0);
break;
case WDSPRxProfile::NR2GainLog:
WDSP::EMNR::SetEMNRgainMethod(*m_rxa, 1);
m_rxa->emnr->setGainMethod(1);
break;
case WDSPRxProfile::NR2GainGamma:
WDSP::EMNR::SetEMNRgainMethod(*m_rxa, 2);
m_rxa->emnr->setGainMethod(2);
break;
default:
break;
@ -545,10 +545,10 @@ void WDSPRxSink::applySettings(const WDSPRxSettings& settings, bool force)
switch (settings.m_nr2NPE)
{
case WDSPRxProfile::NR2NPEOSMS:
WDSP::EMNR::SetEMNRnpeMethod(*m_rxa, 0);
m_rxa->emnr->setNpeMethod(0);
break;
case WDSPRxProfile::NR2NPEMMSE:
WDSP::EMNR::SetEMNRnpeMethod(*m_rxa, 1);
m_rxa->emnr->setNpeMethod(1);
break;
default:
break;
@ -556,7 +556,7 @@ void WDSPRxSink::applySettings(const WDSPRxSettings& settings, bool 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) {

View File

@ -347,7 +347,7 @@ RXA* RXA::create_rxa (
}
// Auto notch filter
rxa->anf = ANF::create_anf (
rxa->anf = new ANF(
0, // run - OFF by default
0, // position
rxa->dsp_size, // buffer size
@ -367,7 +367,7 @@ RXA* RXA::create_rxa (
3.0); // ldecr
// LMS noise reduction (ANR or "NR")
rxa->anr = ANR::create_anr (
rxa->anr = new ANR(
0, // run - OFF by default
0, // position
rxa->dsp_size, // buffer size
@ -387,7 +387,7 @@ RXA* RXA::create_rxa (
3.0); // ldecr
// Spectral noise reduyction (EMNR or "NR2")
rxa->emnr = EMNR::create_emnr (
rxa->emnr = new EMNR(
0, // run
0, // position
rxa->dsp_size, // buffer size
@ -573,9 +573,9 @@ void RXA::destroy_rxa (RXA *rxa)
BANDPASS::destroy_bandpass (rxa->bp1);
delete (rxa->agcmeter);
WCPAGC::destroy_wcpagc (rxa->agc);
EMNR::destroy_emnr (rxa->emnr);
ANR::destroy_anr (rxa->anr);
ANF::destroy_anf (rxa->anf);
delete (rxa->emnr);
delete (rxa->anr);
delete (rxa->anf);
delete (rxa->eqp);
delete (rxa->snba);
delete (rxa->fmsq);
@ -618,9 +618,9 @@ void RXA::flush_rxa (RXA *rxa)
rxa->fmsq->flush();
rxa->snba->flush();
rxa->eqp->flush();
ANF::flush_anf (rxa->anf);
ANR::flush_anr (rxa->anr);
EMNR::flush_emnr (rxa->emnr);
rxa->anf->flush();
rxa->anr->flush();
rxa->emnr->flush();
WCPAGC::flush_wcpagc (rxa->agc);
rxa->agcmeter->flush();
BANDPASS::flush_bandpass (rxa->bp1);
@ -653,14 +653,14 @@ void RXA::xrxa (RXA *rxa)
rxa->bpsnba->exec_out(1);
rxa->snba->execute();
rxa->eqp->execute();
ANF::xanf (rxa->anf, 0);
ANR::xanr (rxa->anr, 0);
EMNR::xemnr (rxa->emnr, 0);
rxa->anf->execute(0);
rxa->anr->ANR::execute(0);
rxa->emnr->execute(0);
BANDPASS::xbandpass (rxa->bp1, 0);
WCPAGC::xwcpagc (rxa->agc);
ANF::xanf (rxa->anf, 1);
ANR::xanr (rxa->anr, 1);
EMNR::xemnr (rxa->emnr, 1);
rxa->anf->execute(1);
rxa->anr->execute(1);
rxa->emnr->execute(1);
BANDPASS::xbandpass (rxa->bp1, 1);
rxa->agcmeter->execute();
SIPHON::xsiphon (rxa->sip1, 0);
@ -764,9 +764,9 @@ void RXA::setDSPSamplerate (RXA *rxa, int dsp_rate)
rxa->fmsq->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);
EMNR::setSamplerate_emnr (rxa->emnr, rxa->dsp_rate);
rxa->anf->setSamplerate(rxa->dsp_rate);
rxa->anr->setSamplerate(rxa->dsp_rate);
rxa->emnr->setSamplerate(rxa->dsp_rate);
BANDPASS::setSamplerate_bandpass (rxa->bp1, rxa->dsp_rate);
WCPAGC::setSamplerate_wcpagc (rxa->agc, 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->eqp->setBuffers(rxa->midbuff, rxa->midbuff);
rxa->eqp->setSize(rxa->dsp_size);
ANF::setBuffers_anf (rxa->anf, rxa->midbuff, rxa->midbuff);
ANF::setSize_anf (rxa->anf, rxa->dsp_size);
ANR::setBuffers_anr (rxa->anr, rxa->midbuff, rxa->midbuff);
ANR::setSize_anr (rxa->anr, rxa->dsp_size);
EMNR::setBuffers_emnr (rxa->emnr, rxa->midbuff, rxa->midbuff);
EMNR::setSize_emnr (rxa->emnr, rxa->dsp_size);
rxa->anf->setBuffers(rxa->midbuff, rxa->midbuff);
rxa->anf->setSize(rxa->dsp_size);
rxa->anr->setBuffers(rxa->midbuff, rxa->midbuff);
rxa->anr->setSize(rxa->dsp_size);
rxa->emnr->setBuffers(rxa->midbuff, rxa->midbuff);
rxa->emnr->setSize(rxa->dsp_size);
BANDPASS::setBuffers_bandpass (rxa->bp1, rxa->midbuff, rxa->midbuff);
BANDPASS::setSize_bandpass (rxa->bp1, rxa->dsp_size);
WCPAGC::setBuffers_wcpagc (rxa->agc, rxa->midbuff, rxa->midbuff);
@ -1280,10 +1280,17 @@ void RXA::SetANFRun (RXA& rxa, int run)
);
a->run = run;
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)
{
ANR *a = rxa.anr;
@ -1300,10 +1307,17 @@ void RXA::SetANRRun (RXA& rxa, int run)
);
a->run = run;
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)
{
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 *

View File

@ -173,11 +173,13 @@ public:
static void SetSNBARun (RXA& rxa, int run);
// ANF
static void SetANFRun (RXA& rxa, int run);
static void SetANFPosition (RXA& rxa, int position);
// ANR
static void SetANRRun (RXA& rxa, int run);
static void SetANRPosition (RXA& rxa, int position);
// EMNR
static void SetEMNRRun (RXA& rxa, int run);
static void SetEMNRPosition (RXA& rxa, int position);
// Collectives
static void SetPassband (RXA& rxa, float f_low, float f_high);
static void SetNC (RXA& rxa, int nc);

View File

@ -100,6 +100,7 @@ public:
double tauI
);
AMD(const AMD&) = delete;
AMD& operator=(const AMD& other) = delete;
~AMD() = default;
void init();

View File

@ -81,6 +81,7 @@ public:
double _muted_gain
);
AMSQ(const AMSQ&) = delete;
AMSQ& operator=(const AMSQ& other) = delete;
~AMSQ() = default;
void flush();

View File

@ -80,6 +80,7 @@ public:
double threshold
);
ANB(const ANB&) = delete;
ANB& operator=(const ANB& other) = delete;
~ANB() = default;
void flush();

View File

@ -36,144 +36,136 @@ warren@wpratt.com
namespace WDSP {
ANF* ANF::create_anf(
int run,
int position,
int buff_size,
float *in_buff,
float *out_buff,
int dline_size,
int n_taps,
int delay,
double two_mu,
double gamma,
double lidx,
double lidx_min,
double lidx_max,
double ngamma,
double den_mult,
double lincr,
double ldecr
ANF::ANF(
int _run,
int _position,
int _buff_size,
float *_in_buff,
float *_out_buff,
int _dline_size,
int _n_taps,
int _delay,
double _two_mu,
double _gamma,
double _lidx,
double _lidx_min,
double _lidx_max,
double _ngamma,
double _den_mult,
double _lincr,
double _ldecr
)
{
ANF *a = new ANF;
a->run = run;
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;
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;
memset (a->d, 0, sizeof(double) * ANF_DLINE_SIZE);
memset (a->w, 0, sizeof(double) * ANF_DLINE_SIZE);
return a;
std::fill(d.begin(), d.end(), 0);
std::fill(w.begin(), w.end(), 0);
}
void ANF::destroy_anf (ANF *a)
{
delete a;
}
void ANF::xanf(ANF *a, int position)
void ANF::execute(int _position)
{
int i, j, idx;
double c0, c1;
double y, error, sigma, inv_sigp;
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;
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;
y += a->w[j] * a->d[idx];
sigma += a->d[idx] * a->d[idx];
idx = (in_idx + j + delay) & mask;
y += w[j] * d[idx];
sigma += d[idx] * d[idx];
}
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;
a->out_buff[2 * i + 1] = 0.0;
out_buff[2 * i + 0] = error;
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;
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;
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
{
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;
c1 = a->two_mu * error * inv_sigp;
c0 = 1.0 - two_mu * ngamma;
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;
a->w[j] = c0 * a->w[j] + c1 * a->d[idx];
idx = (in_idx + j + delay) & mask;
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);
memset (a->w, 0, sizeof(double) * ANF_DLINE_SIZE);
a->in_idx = 0;
std::fill(d.begin(), d.end(), 0);
std::fill(w.begin(), w.end(), 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;
a->out_buff = out;
in_buff = _in;
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;
flush_anf (a);
buff_size = _size;
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;
rxa.anf->delay = delay;
rxa.anf->two_mu = gain; //try two_mu = 1e-4
rxa.anf->gamma = leakage; //try gamma = 0.10
flush_anf (rxa.anf);
n_taps = _taps;
delay = _delay;
two_mu = _gain; //try two_mu = 1e-4
gamma = _leakage; //try gamma = 0.10
flush();
}
void ANF::SetANFTaps (RXA& rxa, int taps)
void ANF::setTaps(int _taps)
{
rxa.anf->n_taps = taps;
flush_anf (rxa.anf);
n_taps = _taps;
flush();
}
void ANF::SetANFDelay (RXA& rxa, int delay)
void ANF::setDelay(int _delay)
{
rxa.anf->delay = delay;
flush_anf (rxa.anf);
delay = _delay;
flush();
}
void ANF::SetANFGain (RXA& rxa, double gain)
void ANF::setGain(double _gain)
{
rxa.anf->two_mu = gain;
flush_anf (rxa.anf);
two_mu = _gain;
flush();
}
void ANF::SetANFLeakage (RXA& rxa, double leakage)
void ANF::setLeakage(double _leakage)
{
rxa.anf->gamma = leakage;
flush_anf (rxa.anf);
}
void ANF::SetANFPosition (RXA& rxa, int position)
{
rxa.anf->position = position;
rxa.bp1->position = position;
flush_anf (rxa.anf);
gamma = _leakage;
flush();
}
} // namespace WDSP

View File

@ -28,6 +28,8 @@ warren@wpratt.com
#ifndef wdsp_anf_h
#define wdsp_anf_h
#include <array>
#include "export.h"
#define ANF_DLINE_SIZE 2048
@ -50,8 +52,8 @@ public:
int delay;
double two_mu;
double gamma;
double d [ANF_DLINE_SIZE];
double w [ANF_DLINE_SIZE];
std::array<double, ANF_DLINE_SIZE> d;
std::array<double, ANF_DLINE_SIZE> w;
int in_idx;
double lidx;
double lidx_min;
@ -61,7 +63,7 @@ public:
double lincr;
double ldecr;
static ANF* create_anf(
ANF(
int run,
int position,
int buff_size,
@ -80,19 +82,21 @@ public:
double lincr,
double ldecr
);
static void destroy_anf (ANF *a);
static void flush_anf (ANF *a);
static void xanf (ANF *a, int position);
static void setBuffers_anf (ANF *a, float* in, float* out);
static void setSamplerate_anf (ANF *a, int rate);
static void setSize_anf (ANF *a, int size);
// RXA Properties
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);
static void SetANFGain (RXA& rxa, double gain);
static void SetANFLeakage (RXA& rxa, double leakage);
static void SetANFPosition (RXA& rxa, int position);
ANF(const ANF&) = delete;
ANF& operator=(const ANF& other) = delete;
~ANF() = default;
void flush();
void execute(int position);
void setBuffers(float* in, float* out);
void setSamplerate(int rate);
void setSize(int size);
// Public Properties
void setVals(int taps, int delay, double gain, double leakage);
void setTaps(int taps);
void setDelay(int delay);
void setGain(double gain);
void setLeakage(double leakage);
};
} // namespace WDSP

View File

@ -36,190 +36,174 @@ warren@wpratt.com
namespace WDSP {
ANR* ANR::create_anr (
int run,
int position,
int buff_size,
float *in_buff,
float *out_buff,
int dline_size,
int n_taps,
int delay,
double two_mu,
double gamma,
double lidx,
double lidx_min,
double lidx_max,
double ngamma,
double den_mult,
double lincr,
double ldecr
)
ANR::ANR(
int _run,
int _position,
int _buff_size,
float *_in_buff,
float *_out_buff,
int _dline_size,
int _n_taps,
int _delay,
double _two_mu,
double _gamma,
double _lidx,
double _lidx_min,
double _lidx_max,
double _ngamma,
double _den_mult,
double _lincr,
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;
a->run = run;
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;
std::fill(d.begin(), d.end(), 0);
std::fill(w.begin(), w.end(), 0);
}
void ANR::destroy_anr (ANR *a)
{
delete a;
}
void ANR::xanr (ANR *a, int position)
void ANR::execute(int _position)
{
int i, j, idx;
double c0, c1;
double y, error, sigma, inv_sigp;
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;
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;
y += a->w[j] * a->d[idx];
sigma += a->d[idx] * a->d[idx];
idx = (in_idx + j + delay) & mask;
y += w[j] * d[idx];
sigma += d[idx] * d[idx];
}
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;
a->out_buff[2 * i + 1] = 0.0;
out_buff[2 * i + 0] = y;
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;
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;
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
{
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;
c0 = 1.0 - a->two_mu * a->ngamma;
c1 = a->two_mu * error * inv_sigp;
ngamma = gamma * (lidx * lidx) * (lidx * lidx) * den_mult;
c0 = 1.0 - two_mu * ngamma;
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;
a->w[j] = c0 * a->w[j] + c1 * a->d[idx];
idx = (in_idx + j + delay) & mask;
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);
memset (a->w, 0, sizeof(double) * ANR_DLINE_SIZE);
a->in_idx = 0;
std::fill(d.begin(), d.end(), 0);
std::fill(w.begin(), w.end(), 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;
a->out_buff = out;
in_buff = _in;
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;
flush_anr(a);
buff_size = _size;
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;
rxa.anr->delay = delay;
rxa.anr->two_mu = gain;
rxa.anr->gamma = leakage;
flush_anr (rxa.anr);
n_taps = _taps;
delay = _delay;
two_mu = _gain;
gamma = _leakage;
flush();
}
void ANR::SetANRTaps (RXA& rxa, int taps)
void ANR::setTaps(int _taps)
{
rxa.anr->n_taps = taps;
flush_anr (rxa.anr);
n_taps = _taps;
flush();
}
void ANR::SetANRDelay (RXA& rxa, int delay)
void ANR::setDelay(int _delay)
{
rxa.anr->delay = delay;
flush_anr (rxa.anr);
delay = _delay;
flush();
}
void ANR::SetANRGain (RXA& rxa, double gain)
void ANR::setGain(double _gain)
{
rxa.anr->two_mu = gain;
flush_anr (rxa.anr);
two_mu = _gain;
flush();
}
void ANR::SetANRLeakage (RXA& rxa, double leakage)
void ANR::setLeakage(double _leakage)
{
rxa.anr->gamma = leakage;
flush_anr (rxa.anr);
}
void ANR::SetANRPosition (RXA& rxa, int position)
{
rxa.anr->position = position;
rxa.bp1->position = position;
flush_anr (rxa.anr);
gamma = _leakage;
flush();
}
} // namespace WDSP

View File

@ -28,6 +28,8 @@ warren@wpratt.com
#ifndef wdsp_anr_h
#define wdsp_anr_h
#include <array>
#include "export.h"
#define ANR_DLINE_SIZE 2048
@ -50,8 +52,8 @@ public:
int delay;
double two_mu;
double gamma;
double d [ANR_DLINE_SIZE];
double w [ANR_DLINE_SIZE];
std::array<double, ANR_DLINE_SIZE> d;
std::array<double, ANR_DLINE_SIZE> w;
int in_idx;
double lidx;
@ -62,7 +64,7 @@ public:
double lincr;
double ldecr;
static ANR* create_anr (
ANR(
int run,
int position,
int buff_size,
@ -81,20 +83,21 @@ public:
double lincr,
double ldecr
);
ANR(const ANR&) = delete;
ANR& operator=(const ANR& other) = delete;
~ANR() = default;
static void destroy_anr (ANR *a);
static void flush_anr (ANR *a);
static void xanr (ANR *a, int position);
static void setBuffers_anr (ANR *a, float* in, float* out);
static void setSamplerate_anr (ANR *a, int rate);
static void setSize_anr (ANR *a, int size);
void flush();
void execute(int position);
void setBuffers(float* in, float* out);
void setSamplerate(int rate);
void setSize(int size);
// RXA Properties
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);
static void SetANRGain (RXA& rxa, double gain);
static void SetANRLeakage (RXA& rxa, double leakage);
static void SetANRPosition (RXA& rxa, int position);
void setVals(int taps, int delay, double gain, double leakage);
void setTaps(int taps);
void setDelay(int delay);
void setGain(double gain);
void setLeakage(double leakage);
};
} // namespace WDSP

View File

@ -80,6 +80,7 @@ public:
NOTCHDB* notchdb
);
BPSNBA(const BPSNBA&) = delete;
BPSNBA& operator=(BPSNBA& other) = delete;
~BPSNBA();
void flush();

File diff suppressed because it is too large Load Diff

View File

@ -28,6 +28,9 @@ warren@wpratt.com
#ifndef wdsp_emnr_h
#define wdsp_emnr_h
#include <array>
#include <vector>
#include "fftw3.h"
#include "export.h"
@ -46,18 +49,18 @@ public:
int fsize;
int ovrlp;
int incr;
float* window;
std::vector<float> window;
int iasize;
float* inaccum;
float* forfftin;
float* forfftout;
std::vector<float> inaccum;
std::vector<float> forfftin;
std::vector<float> forfftout;
int msize;
double* mask;
float* revfftin;
float* revfftout;
float** save;
std::vector<double> mask;
std::vector<float> revfftin;
std::vector<float> revfftout;
std::vector<std::vector<float>> save;
int oasize;
float* outaccum;
std::vector<float> outaccum;
double rate;
int wintype;
double ogain;
@ -71,14 +74,16 @@ public:
int saveidx;
fftwf_plan Rfor;
fftwf_plan Rrev;
struct _g
struct G
{
int incr;
double rate;
int msize;
double* mask;
float* y;
int gain_method;
int npe_method;
int ae_run;
double msize;
double* mask;
float* y;
double* lambda_y;
double* lambda_d;
double* prev_mask;
@ -93,36 +98,48 @@ public:
double* GG;
double* GGS;
FILE* fileb;
} g;
struct _npest
G(
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;
double rate;
int msize;
double* lambda_y;
double* lambda_d;
double* p;
double* alphaOptHat;
double alphaC;
double alphaCsmooth;
double alphaCmin;
double* alphaHat;
double alphaMax;
double* sigma2N;
double alphaCmin;
double alphaMin_max_value;
double snrq;
double betamax;
double* pbar;
double* p2bar;
double invQeqMax;
double av;
double* Qeq;
int U;
double Dtime;
int U;
int V;
int D;
double* p;
double* alphaOptHat;
double alphaC;
double* alphaHat;
double* sigma2N;
double* pbar;
double* p2bar;
double* Qeq;
double MofD;
double MofV;
std::array<double, 4> invQbar_points;
std::array<double, 4> nsmax;
double* bmin;
double* bmin_sub;
int* k_mod;
@ -131,12 +148,32 @@ public:
int subwc;
int* lmin_flag;
double* pmin_u;
double invQbar_points[4];
double nsmax[4];
double** actminbuff;
int amb_idx;
} np;
struct _npests
NP(
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;
double rate;
@ -153,17 +190,41 @@ public:
double* PH1y;
double* Pbar;
double* EN2y;
} nps;
struct _ae
NPS(
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;
double* lambda_y;
double zetaThresh;
double psi;
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 position,
int size,
@ -178,33 +239,33 @@ public:
int npe_method,
int ae_run
);
static void destroy_emnr (EMNR *a);
static void flush_emnr (EMNR *a);
static void xemnr (EMNR *a, int pos);
static void setBuffers_emnr (EMNR *a, float* in, float* out);
static void setSamplerate_emnr (EMNR *a, int rate);
static void setSize_emnr (EMNR *a, int size);
// RXA Properties
static void SetEMNRgainMethod (RXA& rxa, int method);
static void SetEMNRnpeMethod (RXA& rxa, int method);
static void SetEMNRaeRun (RXA& rxa, int run);
static void SetEMNRPosition (RXA& rxa, int position);
static void SetEMNRaeZetaThresh (RXA& rxa, double zetathresh);
static void SetEMNRaePsi (RXA& rxa, double psi);
EMNR(const EMNR&) = delete;
EMNR& operator=(const EMNR& other) = delete;
~EMNR();
void flush();
void execute(int pos);
void setBuffers(float* in, float* out);
void setSamplerate(int rate);
void setSize(int size);
// Public Properties
void setGainMethod(int method);
void setNpeMethod(int method);
void setAeRun(int run);
void setAeZetaThresh(double zetathresh);
void setAePsi(double psi);
private:
static double bessI0 (double x);
static double bessI1 (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 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 void calc_gain (EMNR *a);
void calc_window();
void calc();
void decalc();
void aepf();
void calc_gain();
};
} // namespace WDSP

View File

@ -76,6 +76,7 @@ public:
int samplerate
);
EQP(const EQP&) = delete;
EQP& operator=(const EQP& other) = delete;
~EQP();
void flush();

View File

@ -111,6 +111,7 @@ public:
int mp_aud
);
FMD(const FMD&) = delete;
FMD& operator=(const FMD& other) = delete;
~FMD();
void flush();

View File

@ -101,6 +101,7 @@ public:
int _mp
);
FMSQ(const FMSQ&) = delete;
FMSQ& operator=(const FMSQ& other) = delete;
~FMSQ();
void flush();

View File

@ -52,6 +52,7 @@ public:
NOTCHDB(int master_run, int maxnotches);
NOTCHDB(const NOTCHDB&) = delete;
NOTCHDB& operator=(const NOTCHDB& other) = delete;
~NOTCHDB() = default;
int addNotch (int notch, double fcenter, double fwidth, int active);
@ -108,6 +109,7 @@ public:
NOTCHDB* notchdb
);
NBP(const NBP&) = delete;
NBP& operator=(const NBP& other) = delete;
~NBP();
void flush();

View File

@ -99,6 +99,7 @@ public:
double threshold
);
NOB(const NOB&) = delete;
NOB& operator=(const NOB& other) = delete;
~NOB() = default;
//////////// legacy interface - remove
void flush();

View File

@ -76,6 +76,7 @@ public:
double gain
);
RESAMPLE(const RESAMPLE&) = delete;
RESAMPLE& operator=(const RESAMPLE& other) = delete;
~RESAMPLE() = default;
void flush();