1
0
mirror of https://github.com/f4exb/sdrangel.git synced 2024-11-24 17:08:36 -05:00

WDSP: FIRCORE rework

This commit is contained in:
f4exb 2024-08-06 06:26:53 +02:00
parent 34917a0b21
commit fe08cd4a78
16 changed files with 290 additions and 305 deletions

View File

@ -904,7 +904,7 @@ void RXA::bp1Set ()
a->run = 0;
if (!old && a->run)
a->flush();
FIRCORE::setUpdate_fircore(a->fircore);
a->fircore->setUpdate();
}
void RXA::bpsnbaCheck(int _mode, int _notch_run)
@ -989,7 +989,7 @@ void RXA::bpsnbaSet()
default:
break;
}
FIRCORE::setUpdate_fircore(a->bpsnba->fircore);
a->bpsnba->fircore->setUpdate();
}
void RXA::updateNBPFiltersLightWeight()
@ -1005,7 +1005,7 @@ void RXA::updateNBPFilters()
if (a->fnfrun)
{
a->calc_impulse();
FIRCORE::setImpulse_fircore(a->fircore, a->impulse, 1);
a->fircore->setImpulse(a->impulse, 1);
delete[] (a->impulse);
}
if (b->bpsnba->fnfrun)
@ -1097,10 +1097,10 @@ void RXA::nbpSetNotchesRun(int _run)
b->fnfrun = a->master_run;
bpsnbaCheck(mode, _run);
b->calc_impulse(); // recalc nbp impulse response
FIRCORE::setImpulse_fircore(b->fircore, b->impulse, 0); // calculate new filter masks
b->fircore->setImpulse(b->impulse, 0); // calculate new filter masks
delete[] (b->impulse);
bpsnbaSet();
FIRCORE::setUpdate_fircore(b->fircore); // apply new filter masks
b->fircore->setUpdate(); // apply new filter masks
}
}
@ -1115,7 +1115,7 @@ void RXA::nbpSetWindow(int _wintype)
{
a->wintype = _wintype;
a->calc_impulse();
FIRCORE::setImpulse_fircore(a->fircore, a->impulse, 1);
a->fircore->setImpulse(a->impulse, 1);
delete[] (a->impulse);
}
@ -1137,7 +1137,7 @@ void RXA::nbpSetAutoIncrease(int _autoincr)
{
a->autoincr = _autoincr;
a->calc_impulse();
FIRCORE::setImpulse_fircore(a->fircore, a->impulse, 1);
a->fircore->setImpulse(a->impulse, 1);
delete[] (a->impulse);
}

View File

@ -925,7 +925,7 @@ void TXA::setBandpassNC(int _nc)
1,
a->gain / (double)(2 * a->size)
);
FIRCORE::setNc_fircore(a->fircore, a->nc, impulse);
a->fircore->setNc(a->nc, impulse);
delete[] impulse;
}
@ -943,7 +943,7 @@ void TXA::setBandpassNC(int _nc)
1,
a->gain / (double)(2 * a->size)
);
FIRCORE::setNc_fircore(a->fircore, a->nc, impulse);
a->fircore->setNc(a->nc, impulse);
delete[] impulse;
}
@ -961,7 +961,7 @@ void TXA::setBandpassNC(int _nc)
1,
a->gain / (double)(2 * a->size)
);
FIRCORE::setNc_fircore(a->fircore, a->nc, impulse);
a->fircore->setNc(a->nc, impulse);
delete[] impulse;
}
}
@ -974,7 +974,7 @@ void TXA::setBandpassMP(int _mp)
if (_mp != a->mp)
{
a->mp = _mp;
FIRCORE::setMp_fircore(a->fircore, a->mp);
a->fircore->setMp(a->mp);
}
a = bp1;
@ -982,7 +982,7 @@ void TXA::setBandpassMP(int _mp)
if (_mp != a->mp)
{
a->mp = _mp;
FIRCORE::setMp_fircore(a->fircore, a->mp);
a->fircore->setMp(a->mp);
}
a = bp2;
@ -990,7 +990,7 @@ void TXA::setBandpassMP(int _mp)
if (_mp != a->mp)
{
a->mp = _mp;
FIRCORE::setMp_fircore(a->fircore, a->mp);
a->fircore->setMp(a->mp);
}
}

View File

@ -75,24 +75,24 @@ BANDPASS::BANDPASS(
1,
gain / (double)(2 * size)
);
fircore = FIRCORE::create_fircore (size, in, out, nc, mp, impulse);
fircore = new FIRCORE(size, in, out, nc, mp, impulse);
delete[] impulse;
}
BANDPASS::~BANDPASS()
{
FIRCORE::destroy_fircore (fircore);
delete (fircore);
}
void BANDPASS::flush()
{
FIRCORE::flush_fircore(fircore);
fircore->flush();
}
void BANDPASS::execute(int pos)
{
if (run && position == pos)
FIRCORE::xfircore(fircore);
fircore->execute();
else if (out != in)
std::copy(in, in + size * 2, out);
}
@ -101,7 +101,7 @@ void BANDPASS::setBuffers(float* _in, float* _out)
{
in = _in;
out = _out;
FIRCORE::setBuffers_fircore(fircore, in, out);
fircore->setBuffers(in, out);
}
void BANDPASS::setSamplerate(int _rate)
@ -116,7 +116,7 @@ void BANDPASS::setSamplerate(int _rate)
1,
gain / (double) (2 * size)
);
FIRCORE::setImpulse_fircore (fircore, impulse, 1);
fircore->setImpulse(impulse, 1);
delete[] impulse;
}
@ -124,7 +124,7 @@ void BANDPASS::setSize(int _size)
{
// NOTE: 'size' must be <= 'nc'
size = _size;
FIRCORE::setSize_fircore (fircore, size);
fircore->setSize(size);
// recalc impulse because scale factor is a function of size
float* impulse = FIR::fir_bandpass (
nc,
@ -135,7 +135,7 @@ void BANDPASS::setSize(int _size)
1,
gain / (double) (2 * size)
);
FIRCORE::setImpulse_fircore (fircore, impulse, 1);
fircore->setImpulse(impulse, 1);
delete[] impulse;
}
@ -151,7 +151,7 @@ void BANDPASS::setGain(double _gain, int _update)
1,
gain / (double) (2 * size)
);
FIRCORE::setImpulse_fircore (fircore, impulse, _update);
fircore->setImpulse(impulse, _update);
delete[] impulse;
}
@ -171,7 +171,7 @@ void BANDPASS::calcBandpassFilter(double _f_low, double _f_high, double _gain)
1,
gain / (double)(2 * size)
);
FIRCORE::setImpulse_fircore (fircore, impulse, 1);
fircore->setImpulse(impulse, 1);
delete[] impulse;
}
}
@ -196,11 +196,11 @@ void BANDPASS::setBandpassFreqs(double _f_low, double _f_high)
gain / (double)(2 * size)
);
FIRCORE::setImpulse_fircore (fircore, impulse, 0);
fircore->setImpulse(impulse, 0);
delete[] impulse;
f_low = _f_low;
f_high = _f_high;
FIRCORE::setUpdate_fircore (fircore);
fircore->setUpdate();
}
}
@ -219,7 +219,7 @@ void BANDPASS::SetBandpassNC(int _nc)
1,
gain / (double)( 2 * size)
);
FIRCORE::setNc_fircore (fircore, nc, impulse);
fircore->setNc(nc, impulse);
delete[] impulse;
}
}
@ -229,7 +229,7 @@ void BANDPASS::SetBandpassMP(int _mp)
if (_mp != mp)
{
mp = _mp;
FIRCORE::setMp_fircore (fircore, mp);
fircore->setMp(mp);
}
}

View File

@ -176,7 +176,7 @@ void BPSNBA::recalc_bpsnba_filter(int update)
b->gain = gain;
b->autoincr = autoincr;
b->calc_impulse();
FIRCORE::setImpulse_fircore (b->fircore, b->impulse, update);
b->fircore->setImpulse(b->impulse, update);
delete[] (b->impulse);
}

View File

@ -37,13 +37,13 @@ void CFIR::calc_cfir (CFIR *a)
float* impulse;
a->scale = 1.0 / (float)(2 * a->size);
impulse = cfir_impulse (a->nc, a->DD, a->R, a->Pairs, a->runrate, a->cicrate, a->cutoff, a->xtype, a->xbw, 1, a->scale, a->wintype);
a->p = FIRCORE::create_fircore (a->size, a->in, a->out, a->nc, a->mp, impulse);
a->p = new FIRCORE(a->size, a->in, a->out, a->nc, a->mp, impulse);
delete[] (impulse);
}
void CFIR::decalc_cfir (CFIR *a)
{
FIRCORE::destroy_fircore (a->p);
delete (a->p);
}
CFIR* CFIR::create_cfir (
@ -105,13 +105,13 @@ void CFIR::destroy_cfir (CFIR *a)
void CFIR::flush_cfir (CFIR *a)
{
FIRCORE::flush_fircore (a->p);
a->p->flush();
}
void CFIR::xcfir (CFIR *a)
{
if (a->run)
FIRCORE::xfircore (a->p);
a->p->execute();
else if (a->in != a->out)
std::copy( a->in, a->in + a->size * 2, a->out);
}

View File

@ -76,7 +76,7 @@ EMPHP::EMPHP(
1.0 / (2.0 * size),
0, 0
);
p = FIRCORE::create_fircore(size, in, out, nc, mp, impulse);
p = new FIRCORE(size, in, out, nc, mp, impulse);
delete[] (impulse);
}
@ -87,13 +87,13 @@ EMPHP::~EMPHP()
void EMPHP::flush()
{
FIRCORE::flush_fircore(p);
p->flush();
}
void EMPHP::execute(int _position)
{
if (run && position == _position)
FIRCORE::xfircore(p);
p->execute();
else if (in != out)
std::copy( in, in + size * 2, out);
}
@ -102,7 +102,7 @@ void EMPHP::setBuffers(float* _in, float* _out)
{
in = _in;
out = _out;
FIRCORE::setBuffers_fircore(p, in, out);
p->setBuffers(in, out);
}
void EMPHP::setSamplerate(int _rate)
@ -120,7 +120,7 @@ void EMPHP::setSamplerate(int _rate)
1.0 / (2.0 * size),
0, 0
);
FIRCORE::setImpulse_fircore(p, impulse, 1);
p->setImpulse(impulse, 1);
delete[] (impulse);
}
@ -128,7 +128,7 @@ void EMPHP::setSize(int _size)
{
float* impulse;
size = _size;
FIRCORE::setSize_fircore(p, size);
p->setSize(size);
impulse = FCurve::fc_impulse (
nc,
f_low,
@ -141,7 +141,7 @@ void EMPHP::setSize(int _size)
0,
0
);
FIRCORE::setImpulse_fircore(p, impulse, 1);
p->setImpulse(impulse, 1);
delete[] (impulse);
}
@ -161,7 +161,7 @@ void EMPHP::setMP(int _mp)
if (mp != _mp)
{
mp = _mp;
FIRCORE::setMp_fircore(p, mp);
p->setMp(mp);
}
}
@ -184,7 +184,7 @@ void EMPHP::setNC(int _nc)
0,
0
);
FIRCORE::setNc_fircore(p, nc, impulse);
p->setNc(nc, impulse);
delete[] (impulse);
}
}
@ -209,7 +209,7 @@ void EMPHP::setFreqs(double low, double high)
0,
0
);
FIRCORE::setImpulse_fircore(p, impulse, 1);
p->setImpulse(impulse, 1);
delete[] (impulse);
}
}

View File

@ -234,24 +234,24 @@ EQP::EQP(
wintype = _wintype;
samplerate = (double) _samplerate;
impulse = eq_impulse (nc, nfreqs, F.data(), G.data(), samplerate, 1.0 / (2.0 * size), ctfmode, wintype);
fircore = FIRCORE::create_fircore (size, in, out, nc, mp, impulse);
fircore = new FIRCORE(size, in, out, nc, mp, impulse);
delete[] impulse;
}
EQP::~EQP()
{
FIRCORE::destroy_fircore (fircore);
delete (fircore);
}
void EQP::flush()
{
FIRCORE::flush_fircore (fircore);
fircore->flush();
}
void EQP::execute()
{
if (run)
FIRCORE::xfircore (fircore);
fircore->execute();
else
std::copy(in, in + size * 2, out);
}
@ -260,7 +260,7 @@ void EQP::setBuffers(float* _in, float* _out)
{
in = _in;
out = _out;
FIRCORE::setBuffers_fircore (fircore, in, out);
fircore->setBuffers(in, out);
}
void EQP::setSamplerate(int rate)
@ -268,7 +268,7 @@ void EQP::setSamplerate(int rate)
float* impulse;
samplerate = rate;
impulse = eq_impulse (nc, nfreqs, F.data(), G.data(), samplerate, 1.0 / (2.0 * size), ctfmode, wintype);
FIRCORE::setImpulse_fircore (fircore, impulse, 1);
fircore->setImpulse(impulse, 1);
delete[] impulse;
}
@ -276,9 +276,9 @@ void EQP::setSize(int _size)
{
float* impulse;
size = _size;
FIRCORE::setSize_fircore (fircore, size);
fircore->setSize(size);
impulse = eq_impulse (nc, nfreqs, F.data(), G.data(), samplerate, 1.0 / (2.0 * size), ctfmode, wintype);
FIRCORE::setImpulse_fircore (fircore, impulse, 1);
fircore->setImpulse(impulse, 1);
delete[] impulse;
}
@ -301,7 +301,7 @@ void EQP::setNC(int _nc)
{
nc = _nc;
impulse = eq_impulse (nc, nfreqs, F.data(), G.data(), samplerate, 1.0 / (2.0 * size), ctfmode, wintype);
FIRCORE::setNc_fircore (fircore, nc, impulse);
fircore->setNc(nc, impulse);
delete[] impulse;
}
}
@ -311,7 +311,7 @@ void EQP::setMP(int _mp)
if (mp != _mp)
{
mp = _mp;
FIRCORE::setMp_fircore (fircore, mp);
fircore->setMp(mp);
}
}
@ -324,7 +324,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());
impulse = eq_impulse (nc, nfreqs, F.data(), G.data(), samplerate, 1.0 / (2.0 * size), ctfmode, wintype);
FIRCORE::setImpulse_fircore (fircore, impulse, 1);
fircore->setImpulse(impulse, 1);
delete[] impulse;
}
@ -333,7 +333,7 @@ void EQP::setCtfmode(int _mode)
float* impulse;
ctfmode = _mode;
impulse = eq_impulse (nc, nfreqs, F.data(), G.data(), samplerate, 1.0 / (2.0 * size), ctfmode, wintype);
FIRCORE::setImpulse_fircore (fircore, impulse, 1);
fircore->setImpulse(impulse, 1);
delete[] impulse;
}
@ -342,7 +342,7 @@ void EQP::setWintype(int _wintype)
float* impulse;
wintype = _wintype;
impulse = eq_impulse (nc, nfreqs, F.data(), G.data(), samplerate, 1.0 / (2.0 * size), ctfmode, wintype);
FIRCORE::setImpulse_fircore (fircore, impulse, 1);
fircore->setImpulse(impulse, 1);
delete[] impulse;
}
@ -363,7 +363,7 @@ void EQP::setGrphEQ(const int *rxeq)
G[4] = (float)rxeq[3];
ctfmode = 0;
impulse = eq_impulse (nc, nfreqs, F.data(), G.data(), samplerate, 1.0 / (2.0 * size), ctfmode, wintype);
FIRCORE::setImpulse_fircore (fircore, impulse, 1);
fircore->setImpulse(impulse, 1);
delete[] impulse;
}
@ -387,7 +387,7 @@ void EQP::setGrphEQ10(const int *rxeq)
G[i] = (float)rxeq[i];
ctfmode = 0;
impulse = eq_impulse (nc, nfreqs, F.data(), G.data(), samplerate, 1.0 / (2.0 * size), ctfmode, wintype);
FIRCORE::setImpulse_fircore (fircore, impulse, 1);
fircore->setImpulse(impulse, 1);
delete[] impulse;
}

View File

@ -377,7 +377,7 @@ void FIR::analytic (int N, float* in, float* out)
fftwf_destroy_plan (pfor);
}
void FIR::mp_imp (int N, float* fir, float* mpfir, int pfactor, int polarity)
void FIR::mp_imp (int N, std::vector<float>& fir, std::vector<float>& mpfir, int pfactor, int polarity)
{
int i;
int size = N * pfactor;
@ -388,7 +388,7 @@ void FIR::mp_imp (int N, float* fir, float* mpfir, int pfactor, int polarity)
std::vector<float> ana(size * 2);
std::vector<float> impulse(size * 2);
std::vector<float> newfreq(size * 2);
std::copy(fir, fir + N * 2, firpad.begin());
std::copy(fir.begin(), fir.begin() + N * 2, firpad.begin());
fftwf_plan pfor = fftwf_plan_dft_1d (
size,
(fftwf_complex *) firpad.data(),
@ -425,9 +425,9 @@ void FIR::mp_imp (int N, float* fir, float* mpfir, int pfactor, int polarity)
}
fftwf_execute (prev);
if (polarity)
std::copy(&impulse[2 * (pfactor - 1) * N], &impulse[2 * (pfactor - 1) * N] + N * 2, mpfir);
std::copy(&impulse[2 * (pfactor - 1) * N], &impulse[2 * (pfactor - 1) * N] + N * 2, mpfir.begin());
else
std::copy(impulse.begin(), impulse.end(), mpfir);
std::copy(impulse.begin(), impulse.end(), mpfir.begin());
fftwf_destroy_plan (prev);
fftwf_destroy_plan (pfor);

View File

@ -27,6 +27,8 @@ warren@pratt.one
#ifndef wdsp_fir_h
#define wdsp_fir_h
#include <vector>
#include "export.h"
namespace WDSP {
@ -38,7 +40,7 @@ public:
static float* fir_fsamp_odd (int N, const float* A, int rtype, double scale, int wintype);
static float* fir_fsamp (int N, const float* A, int rtype, double scale, int wintype);
static float* fir_bandpass (int N, double f_low, double f_high, double samplerate, int wintype, int rtype, double scale);
static void mp_imp (int N, float* fir, float* mpfir, int pfactor, int polarity);
static void mp_imp (int N, std::vector<float>& fir, std::vector<float>& mpfir, int pfactor, int polarity);
private:
static void analytic (int N, float* in, float* out);

View File

@ -38,223 +38,202 @@ namespace WDSP {
********************************************************************************************************/
void FIRCORE::plan_fircore (FIRCORE *a)
void FIRCORE::plan()
{
// must call for change in 'nc', 'size', 'out'
int i;
a->nfor = a->nc / a->size;
a->cset = 0;
a->buffidx = 0;
a->idxmask = a->nfor - 1;
a->fftin = new float[2 * a->size * 2]; // (float *) malloc0 (2 * a->size * sizeof (complex));
a->fftout = new float*[a->nfor]; // (float **) malloc0 (a->nfor * sizeof (float *));
a->fmask = new float**[2]; // (float ***) malloc0 (2 * sizeof (float **));
a->fmask[0] = new float*[a->nfor]; // (float **) malloc0 (a->nfor * sizeof (float *));
a->fmask[1] = new float*[a->nfor]; // (float **) malloc0 (a->nfor * sizeof (float *));
a->maskgen = new float[2 * a->size * 2]; // (float *) malloc0 (2 * a->size * sizeof (complex));
a->pcfor = new fftwf_plan[a->nfor]; // (fftwf_plan *) malloc0 (a->nfor * sizeof (fftwf_plan));
a->maskplan = new fftwf_plan*[2]; // (fftwf_plan **) malloc0 (2 * sizeof (fftwf_plan *));
a->maskplan[0] = new fftwf_plan[a->nfor]; // (fftwf_plan *) malloc0 (a->nfor * sizeof (fftwf_plan));
a->maskplan[1] = new fftwf_plan[a->nfor]; // (fftwf_plan *) malloc0 (a->nfor * sizeof (fftwf_plan));
for (i = 0; i < a->nfor; i++)
nfor = nc / size;
cset = 0;
buffidx = 0;
idxmask = nfor - 1;
fftin.resize(2 * size * 2);
fftout.resize(nfor);
fmask[0].resize(nfor);
fmask[1].resize(nfor);
maskgen.resize(2 * size * 2);
pcfor.resize(nfor);
maskplan[0].resize(nfor);
maskplan[1].resize(nfor);
for (int i = 0; i < nfor; i++)
{
a->fftout[i] = new float[2 * a->size * 2]; // (float *) malloc0 (2 * a->size * sizeof (complex));
a->fmask[0][i] = new float[2 * a->size * 2]; // (float *) malloc0 (2 * a->size * sizeof (complex));
a->fmask[1][i] = new float[2 * a->size * 2]; // (float *) malloc0 (2 * a->size * sizeof (complex));
a->pcfor[i] = fftwf_plan_dft_1d(
2 * a->size,
(fftwf_complex *)a->fftin,
(fftwf_complex *)a->fftout[i],
fftout[i].resize(2 * size * 2);
fmask[0][i].resize(2 * size * 2);
fmask[1][i].resize(2 * size * 2);
pcfor[i] = fftwf_plan_dft_1d(
2 * size,
(fftwf_complex *)fftin.data(),
(fftwf_complex *)fftout[i].data(),
FFTW_FORWARD,
FFTW_PATIENT
);
a->maskplan[0][i] = fftwf_plan_dft_1d(
2 * a->size,
(fftwf_complex *)a->maskgen,
(fftwf_complex *)a->fmask[0][i],
maskplan[0][i] = fftwf_plan_dft_1d(
2 * size,
(fftwf_complex *)maskgen.data(),
(fftwf_complex *)fmask[0][i].data(),
FFTW_FORWARD,
FFTW_PATIENT
);
a->maskplan[1][i] = fftwf_plan_dft_1d(
2 * a->size,
(fftwf_complex *)a->maskgen,
(fftwf_complex *)a->fmask[1][i],
maskplan[1][i] = fftwf_plan_dft_1d(
2 * size,
(fftwf_complex *)maskgen.data(),
(fftwf_complex *)fmask[1][i].data(),
FFTW_FORWARD,
FFTW_PATIENT
);
}
a->accum = new float[2 * a->size * 2]; // (float *) malloc0 (2 * a->size * sizeof (complex));
a->crev = fftwf_plan_dft_1d(
2 * a->size,
(fftwf_complex *)a->accum,
(fftwf_complex *)a->out,
accum.resize(2 * size * 2);
crev = fftwf_plan_dft_1d(
2 * size,
(fftwf_complex *)accum.data(),
(fftwf_complex *)out,
FFTW_BACKWARD,
FFTW_PATIENT
);
a->masks_ready = 0;
masks_ready = 0;
}
void FIRCORE::calc_fircore (FIRCORE *a, int flip)
void FIRCORE::calc(int _flip)
{
// call for change in frequency, rate, wintype, gain
// must also call after a call to plan_firopt()
int i;
if (a->mp)
FIR::mp_imp (a->nc, a->impulse, a->imp, 16, 0);
if (mp)
FIR::mp_imp (nc, impulse, imp, 16, 0);
else
std::copy(a->impulse, a->impulse + a->nc * 2, a->imp);
std::copy(impulse.begin(), impulse.begin() + nc * 2, imp.begin());
for (i = 0; i < a->nfor; i++)
for (int i = 0; i < nfor; i++)
{
// I right-justified the impulse response => take output from left side of output buff, discard right side
// Be careful about flipping an asymmetrical impulse response.
std::copy(&(a->imp[2 * a->size * i]), &(a->imp[2 * a->size * i]) + a->size * 2, &(a->maskgen[2 * a->size]));
fftwf_execute (a->maskplan[1 - a->cset][i]);
std::copy(&(imp[2 * size * i]), &(imp[2 * size * i]) + size * 2, &(maskgen[2 * size]));
fftwf_execute (maskplan[1 - cset][i]);
}
a->masks_ready = 1;
masks_ready = 1;
if (flip)
if (_flip)
{
a->cset = 1 - a->cset;
a->masks_ready = 0;
cset = 1 - cset;
masks_ready = 0;
}
}
FIRCORE* FIRCORE::create_fircore (int size, float* in, float* out, int nc, int mp, float* impulse)
FIRCORE::FIRCORE(
int _size,
float* _in,
float* _out,
int _nc,
int _mp,
float* _impulse
)
{
FIRCORE *a = new FIRCORE;
a->size = size;
a->in = in;
a->out = out;
a->nc = nc;
a->mp = mp;
// InitializeCriticalSectionAndSpinCount (&a->update, 2500);
plan_fircore (a);
a->impulse = new float[a->nc * 2]; // (float *) malloc0 (a->nc * sizeof (complex));
a->imp = new float[a->nc * 2]; // (float *) malloc0 (a->nc * sizeof (complex));
std::copy(impulse, impulse + a->nc * 2, a->impulse);
calc_fircore (a, 1);
return a;
size = _size;
in = _in;
out = _out;
nc = _nc;
mp = _mp;
plan();
impulse.resize(nc * 2);
imp.resize(nc * 2);
std::copy(_impulse, _impulse + nc * 2, impulse.begin());
calc(1);
}
void FIRCORE::deplan_fircore (FIRCORE *a)
void FIRCORE::deplan()
{
int i;
fftwf_destroy_plan (a->crev);
delete[] (a->accum);
for (i = 0; i < a->nfor; i++)
fftwf_destroy_plan (crev);
for (int i = 0; i < nfor; i++)
{
delete[] (a->fftout[i]);
delete[] (a->fmask[0][i]);
delete[] (a->fmask[1][i]);
fftwf_destroy_plan (a->pcfor[i]);
fftwf_destroy_plan (a->maskplan[0][i]);
fftwf_destroy_plan (a->maskplan[1][i]);
fftwf_destroy_plan (pcfor[i]);
fftwf_destroy_plan (maskplan[0][i]);
fftwf_destroy_plan (maskplan[1][i]);
}
delete[] (a->maskplan[0]);
delete[] (a->maskplan[1]);
delete[] (a->maskplan);
delete[] (a->pcfor);
delete[] (a->maskgen);
delete[] (a->fmask[0]);
delete[] (a->fmask[1]);
delete[] (a->fmask);
delete[] (a->fftout);
delete[] (a->fftin);
}
void FIRCORE::destroy_fircore (FIRCORE *a)
FIRCORE::~FIRCORE()
{
deplan_fircore (a);
delete[] (a->imp);
delete[] (a->impulse);
delete (a);
deplan();
}
void FIRCORE::flush_fircore (FIRCORE *a)
void FIRCORE::flush()
{
int i;
std::fill(a->fftin, a->fftin + 2 * a->size * 2, 0);
for (i = 0; i < a->nfor; i++)
std::fill(a->fftout[i], a->fftout[i] + 2 * a->size * 2, 0);
a->buffidx = 0;
std::fill(fftin.begin(), fftin.end(), 0);
for (int i = 0; i < nfor; i++)
std::fill(fftout[i].begin(), fftout[i].end(), 0);
buffidx = 0;
}
void FIRCORE::xfircore (FIRCORE *a)
void FIRCORE::execute()
{
int i, j, k;
std::copy(a->in, a->in + a->size * 2, &(a->fftin[2 * a->size]));
fftwf_execute (a->pcfor[a->buffidx]);
k = a->buffidx;
std::fill(a->accum, a->accum + 2 * a->size * 2, 0);
int k;
std::copy(in, in + size * 2, &(fftin[2 * size]));
fftwf_execute (pcfor[buffidx]);
k = buffidx;
std::fill(accum.begin(), accum.end(), 0);
for (j = 0; j < a->nfor; j++)
for (int j = 0; j < nfor; j++)
{
for (i = 0; i < 2 * a->size; i++)
for (int i = 0; i < 2 * size; i++)
{
a->accum[2 * i + 0] += a->fftout[k][2 * i + 0] * a->fmask[a->cset][j][2 * i + 0] - a->fftout[k][2 * i + 1] * a->fmask[a->cset][j][2 * i + 1];
a->accum[2 * i + 1] += a->fftout[k][2 * i + 0] * a->fmask[a->cset][j][2 * i + 1] + a->fftout[k][2 * i + 1] * a->fmask[a->cset][j][2 * i + 0];
accum[2 * i + 0] += fftout[k][2 * i + 0] * fmask[cset][j][2 * i + 0] - fftout[k][2 * i + 1] * fmask[cset][j][2 * i + 1];
accum[2 * i + 1] += fftout[k][2 * i + 0] * fmask[cset][j][2 * i + 1] + fftout[k][2 * i + 1] * fmask[cset][j][2 * i + 0];
}
k = (k + a->idxmask) & a->idxmask;
k = (k + idxmask) & idxmask;
}
a->buffidx = (a->buffidx + 1) & a->idxmask;
fftwf_execute (a->crev);
std::copy(&(a->fftin[2 * a->size]), &(a->fftin[2 * a->size]) + a->size * 2, a->fftin);
buffidx = (buffidx + 1) & idxmask;
fftwf_execute (crev);
std::copy(&(fftin[2 * size]), &(fftin[2 * size]) + size * 2, fftin.begin());
}
void FIRCORE::setBuffers_fircore (FIRCORE *a, float* in, float* out)
void FIRCORE::setBuffers(float* _in, float* _out)
{
a->in = in;
a->out = out;
deplan_fircore (a);
plan_fircore (a);
calc_fircore (a, 1);
in = _in;
out = _out;
deplan();
plan();
calc(1);
}
void FIRCORE::setSize_fircore (FIRCORE *a, int size)
void FIRCORE::setSize(int _size)
{
a->size = size;
deplan_fircore (a);
plan_fircore (a);
calc_fircore (a, 1);
size = _size;
deplan();
plan();
calc(1);
}
void FIRCORE::setImpulse_fircore (FIRCORE *a, float* impulse, int update)
void FIRCORE::setImpulse(float* _impulse, int _update)
{
std::copy(impulse, impulse + a->nc * 2, a->impulse);
calc_fircore (a, update);
std::copy(_impulse, _impulse + nc * 2, impulse.begin());
calc(_update);
}
void FIRCORE::setNc_fircore (FIRCORE *a, int nc, float* impulse)
void FIRCORE::setNc(int _nc, float* _impulse)
{
// because of FFT planning, this will probably cause a glitch in audio if done during dataflow
deplan_fircore (a);
delete[] (a->impulse);
delete[] (a->imp);
a->nc = nc;
plan_fircore (a);
a->imp = new float[a->nc * 2]; // (float *) malloc0 (a->nc * sizeof (complex));
a->impulse = new float[a->nc * 2]; // (float *) malloc0 (a->nc * sizeof (complex));
std::copy(impulse, impulse + a->nc * 2, a->impulse);
calc_fircore (a, 1);
deplan();
nc = _nc;
plan();
imp.resize(nc * 2);
impulse.resize(nc * 2);
std::copy(_impulse, _impulse + nc * 2, impulse.begin());
calc(1);
}
void FIRCORE::setMp_fircore (FIRCORE *a, int mp)
void FIRCORE::setMp(int _mp)
{
a->mp = mp;
calc_fircore (a, 1);
mp = _mp;
calc(1);
}
void FIRCORE::setUpdate_fircore (FIRCORE *a)
void FIRCORE::setUpdate()
{
if (a->masks_ready)
if (masks_ready)
{
a->cset = 1 - a->cset;
a->masks_ready = 0;
cset = 1 - cset;
masks_ready = 0;
}
}

View File

@ -34,6 +34,9 @@ warren@wpratt.com
#ifndef wdsp_fircore_h
#define wdsp_fircore_h
#include <array>
#include <vector>
#include "fftw3.h"
#include "export.h"
@ -46,39 +49,49 @@ public:
float* in; // input buffer
float* out; // output buffer, can be same as input
int nc; // number of filter coefficients, power of two, >= size
float* impulse; // impulse response of filter
float* imp;
std::vector<float> impulse; // impulse response of filter
std::vector<float> imp;
int nfor; // number of buffers in delay line
float* fftin; // fft input buffer
float*** fmask; // frequency domain masks
float** fftout; // fftout delay line
float* accum; // frequency domain accumulator
std::vector<float> fftin; // fft input buffer
std::array<std::vector<std::vector<float>>, 2> fmask; // frequency domain masks
std::vector<std::vector<float>> fftout; // fftout delay line
std::vector<float> accum; // frequency domain accumulator
int buffidx; // fft out buffer index
int idxmask; // mask for index computations
float* maskgen; // input for mask generation FFT
fftwf_plan* pcfor; // array of forward FFT plans
std::vector<float> maskgen; // input for mask generation FFT
std::vector<fftwf_plan> pcfor; // array of forward FFT plans
fftwf_plan crev; // reverse fft plan
fftwf_plan** maskplan; // plans for frequency domain masks
std::array<std::vector<fftwf_plan>, 2> maskplan; // plans for frequency domain masks
int cset;
int mp;
int masks_ready;
static FIRCORE* create_fircore (int size, float* in, float* out,
int nc, int mp, float* impulse);
static void xfircore (FIRCORE *a);
static void destroy_fircore (FIRCORE *a);
static void flush_fircore (FIRCORE *a);
static void setBuffers_fircore (FIRCORE *a, float* in, float* out);
static void setSize_fircore (FIRCORE *a, int size);
static void setImpulse_fircore (FIRCORE *a, float* impulse, int update);
static void setNc_fircore (FIRCORE *a, int nc, float* impulse);
static void setMp_fircore (FIRCORE *a, int mp);
static void setUpdate_fircore (FIRCORE *a);
FIRCORE(
int size,
float* in,
float* out,
int nc,
int mp,
float*
impulse
);
FIRCORE(const FIRCORE&) = delete;
FIRCORE& operator=(const FIRCORE& other) = delete;
~FIRCORE();
void flush();
void execute();
void setBuffers(float* in, float* out);
void setSize(int size);
void setImpulse(float* impulse, int update);
void setNc(int nc, float* impulse);
void setMp(int mp);
void setUpdate();
private:
static void plan_fircore (FIRCORE *a);
static void calc_fircore (FIRCORE *a, int flip);
static void deplan_fircore (FIRCORE *a);
void plan();
void calc(int flip);
void deplan();
};
} // namespace WDSP

View File

@ -158,26 +158,26 @@ FMD::FMD(
0,
0
);
pde = FIRCORE::create_fircore (size, audio.data(), out, nc_de, mp_de, impulse);
pde = new FIRCORE(size, audio.data(), out, nc_de, mp_de, impulse);
delete[] impulse;
// audio filter
impulse = FIR::fir_bandpass(nc_aud, 0.8 * f_low, 1.1 * f_high, rate, 0, 1, afgain / (2.0 * size));
paud = FIRCORE::create_fircore (size, out, out, nc_aud, mp_aud, impulse);
paud = new FIRCORE(size, out, out, nc_aud, mp_aud, impulse);
delete[] impulse;
}
FMD::~FMD()
{
FIRCORE::destroy_fircore (paud);
FIRCORE::destroy_fircore (pde);
delete (paud);
delete (pde);
decalc();
}
void FMD::flush()
{
std::fill(audio.begin(), audio.end(), 0);
FIRCORE::flush_fircore (pde);
FIRCORE::flush_fircore (paud);
pde->flush();
paud->flush();
phs = 0.0;
fil_out = 0.0;
omega = 0.0;
@ -219,9 +219,9 @@ void FMD::execute()
audio[2 * i + 1] = audio[2 * i + 0];
}
// de-emphasis
FIRCORE::xfircore (pde);
pde->execute();
// audio filter
FIRCORE::xfircore (paud);
paud->execute();
// CTCSS Removal
sntch->execute();
if (lim_run)
@ -241,8 +241,8 @@ void FMD::setBuffers(float* _in, float* _out)
in = _in;
out = _out;
calc();
FIRCORE::setBuffers_fircore (pde, audio.data(), out);
FIRCORE::setBuffers_fircore (paud, out, out);
pde->setBuffers(audio.data(), out);
paud->setBuffers(out, out);
plim->setBuffers(out, out);
}
@ -265,11 +265,11 @@ void FMD::setSamplerate(int _rate)
0,
0
);
FIRCORE::setImpulse_fircore (pde, impulse, 1);
pde->setImpulse(impulse, 1);
delete[] impulse;
// audio filter
impulse = FIR::fir_bandpass(nc_aud, 0.8 * f_low, 1.1 * f_high, rate, 0, 1, afgain / (2.0 * size));
FIRCORE::setImpulse_fircore (paud, impulse, 1);
paud->setImpulse(impulse, 1);
delete[] impulse;
plim->setSamplerate((int) rate);
}
@ -282,7 +282,7 @@ void FMD::setSize(int _size)
calc();
audio.resize(size * 2);
// de-emphasis filter
FIRCORE::destroy_fircore (pde);
delete (pde);
impulse = FCurve::fc_impulse (
nc_de,
(float) f_low,
@ -295,12 +295,12 @@ void FMD::setSize(int _size)
0,
0
);
pde = FIRCORE::create_fircore (size, audio.data(), out, nc_de, mp_de, impulse);
pde = new FIRCORE(size, audio.data(), out, nc_de, mp_de, impulse);
delete[] impulse;
// audio filter
FIRCORE::destroy_fircore (paud);
delete (paud);
impulse = FIR::fir_bandpass(nc_aud, 0.8 * f_low, 1.1 * f_high, rate, 0, 1, afgain / (2.0 * size));
paud = FIRCORE::create_fircore (size, out, out, nc_aud, mp_aud, impulse);
paud = new FIRCORE(size, out, out, nc_aud, mp_aud, impulse);
delete[] impulse;
plim->setSize(size);
}
@ -348,7 +348,7 @@ void FMD::setNCde(int nc)
0,
0
);
FIRCORE::setNc_fircore (pde, nc_de, impulse);
pde->setNc(nc_de, impulse);
delete[] impulse;
}
}
@ -358,7 +358,7 @@ void FMD::setMPde(int mp)
if (mp_de != mp)
{
mp_de = mp;
FIRCORE::setMp_fircore (pde, mp_de);
pde->setMp(mp_de);
}
}
@ -370,7 +370,7 @@ void FMD::setNCaud(int nc)
{
nc_aud = nc;
impulse = FIR::fir_bandpass(nc_aud, 0.8 * f_low, 1.1 * f_high, rate, 0, 1, afgain / (2.0 * size));
FIRCORE::setNc_fircore (paud, nc_aud, impulse);
paud->setNc(nc_aud, impulse);
delete[] impulse;
}
}
@ -380,7 +380,7 @@ void FMD::setMPaud(int mp)
if (mp_aud != mp)
{
mp_aud = mp;
FIRCORE::setMp_fircore (paud, mp_aud);
paud->setMp(mp_aud);
}
}
@ -424,11 +424,11 @@ void FMD::setAFFilter(double low, double high)
0,
0
);
FIRCORE::setImpulse_fircore (pde, impulse, 1);
pde->setImpulse(impulse, 1);
delete[] impulse;
// audio filter
impulse = FIR::fir_bandpass (nc_aud, 0.8 * f_low, 1.1 * f_high, rate, 0, 1, afgain / (2.0 * size));
FIRCORE::setImpulse_fircore (paud, impulse, 1);
paud->setImpulse(impulse, 1);
delete[] impulse;
}
}

View File

@ -81,14 +81,14 @@ FMMOD* FMMOD::create_fmmod (
a->mp = mp;
calc_fmmod (a);
impulse = FIR::fir_bandpass(a->nc, -a->bp_fc, +a->bp_fc, a->samplerate, 0, 1, 1.0 / (2 * a->size));
a->p = FIRCORE::create_fircore (a->size, a->out, a->out, a->nc, a->mp, impulse);
a->p = new FIRCORE(a->size, a->out, a->out, a->nc, a->mp, impulse);
delete[] (impulse);
return a;
}
void FMMOD::destroy_fmmod (FMMOD *a)
{
FIRCORE::destroy_fircore (a->p);
delete (a->p);
delete (a);
}
@ -124,7 +124,7 @@ void FMMOD::xfmmod (FMMOD *a)
}
//print_deviation ("peakdev.txt", peak, a->samplerate);
if (a->bp_run)
FIRCORE::xfircore (a->p);
a->p->execute();
}
else if (a->in != a->out)
std::copy( a->in, a->in + a->size * 2, a->out);
@ -135,7 +135,7 @@ void FMMOD::setBuffers_fmmod (FMMOD *a, float* in, float* out)
a->in = in;
a->out = out;
calc_fmmod (a);
FIRCORE::setBuffers_fircore (a->p, a->out, a->out);
a->p->setBuffers(a->out, a->out);
}
void FMMOD::setSamplerate_fmmod (FMMOD *a, int rate)
@ -144,7 +144,7 @@ void FMMOD::setSamplerate_fmmod (FMMOD *a, int rate)
a->samplerate = rate;
calc_fmmod (a);
impulse = FIR::fir_bandpass(a->nc, -a->bp_fc, +a->bp_fc, a->samplerate, 0, 1, 1.0 / (2 * a->size));
FIRCORE::setImpulse_fircore (a->p, impulse, 1);
a->p->setImpulse(impulse, 1);
delete[] (impulse);
}
@ -153,9 +153,9 @@ void FMMOD::setSize_fmmod (FMMOD *a, int size)
float* impulse;
a->size = size;
calc_fmmod (a);
FIRCORE::setSize_fircore (a->p, a->size);
a->p->setSize(a->size);
impulse = FIR::fir_bandpass(a->nc, -a->bp_fc, +a->bp_fc, a->samplerate, 0, 1, 1.0 / (2 * a->size));
FIRCORE::setImpulse_fircore (a->p, impulse, 1);
a->p->setImpulse(impulse, 1);
delete[] (impulse);
}
@ -170,7 +170,7 @@ void FMMOD::SetFMDeviation (TXA& txa, float deviation)
FMMOD *a = txa.fmmod;
float bp_fc = a->f_high + deviation;
float* impulse = FIR::fir_bandpass (a->nc, -bp_fc, +bp_fc, a->samplerate, 0, 1, 1.0 / (2 * a->size));
FIRCORE::setImpulse_fircore (a->p, impulse, 0);
a->p->setImpulse(impulse, 0);
delete[] (impulse);
a->deviation = deviation;
// mod
@ -178,7 +178,7 @@ void FMMOD::SetFMDeviation (TXA& txa, float deviation)
a->sdelta = TWOPI * a->deviation / a->samplerate;
// bandpass
a->bp_fc = bp_fc;
FIRCORE::setUpdate_fircore (a->p);
a->p->setUpdate();
}
void FMMOD::SetCTCSSFreq (TXA& txa, float freq)
@ -205,7 +205,7 @@ void FMMOD::SetFMNC (TXA& txa, int nc)
{
a->nc = nc;
impulse = FIR::fir_bandpass (a->nc, -a->bp_fc, +a->bp_fc, a->samplerate, 0, 1, 1.0 / (2 * a->size));
FIRCORE::setNc_fircore (a->p, a->nc, impulse);
a->p->setNc(a->nc, impulse);
delete[] (impulse);
}
}
@ -217,7 +217,7 @@ void FMMOD::SetFMMP (TXA& txa, int mp)
if (a->mp != mp)
{
a->mp = mp;
FIRCORE::setMp_fircore (a->p, a->mp);
a->p->setMp(a->mp);
}
}
@ -233,7 +233,7 @@ void FMMOD::SetFMAFFreqs (TXA& txa, float low, float high)
a->f_high = high;
a->bp_fc = a->deviation + a->f_high;
impulse = FIR::fir_bandpass (a->nc, -a->bp_fc, +a->bp_fc, a->samplerate, 0, 1, 1.0 / (2 * a->size));
FIRCORE::setImpulse_fircore (a->p, impulse, 1);
a->p->setImpulse(impulse, 1);
delete[] (impulse);
}
}

View File

@ -49,7 +49,7 @@ void FMSQ::calc()
G[2] = 3.0;
G[3] = (float) (+20.0 * log10(20000.0 / *pllpole));
impulse = EQP::eq_impulse (nc, 3, F.data(), G.data(), rate, 1.0 / (2.0 * size), 0, 0);
p = FIRCORE::create_fircore (size, trigger, noise.data(), nc, mp, impulse);
p = new FIRCORE(size, trigger, noise.data(), nc, mp, impulse);
delete[] impulse;
// noise averaging
avm = exp(-1.0 / (rate * avtau));
@ -89,7 +89,7 @@ void FMSQ::calc()
void FMSQ::decalc()
{
FIRCORE::destroy_fircore (p);
delete (p);
}
FMSQ::FMSQ(
@ -143,7 +143,7 @@ FMSQ::~FMSQ()
void FMSQ::flush()
{
FIRCORE::flush_fircore (p);
p->flush();
avnoise = 100.0;
longnoise = 1.0;
state = FMSQState::MUTED;
@ -157,7 +157,7 @@ void FMSQ::execute()
{
double _noise;
double lnlimit;
FIRCORE::xfircore (p);
p->execute();
for (int i = 0; i < size; i++)
{
@ -250,7 +250,7 @@ void FMSQ::setBuffers(float* in, float* out, float* trig)
insig = in;
outsig = out;
trigger = trig;
FIRCORE::setBuffers_fircore (p, trigger, noise.data());
p->setBuffers(trigger, noise.data());
}
void FMSQ::setSamplerate(int _rate)
@ -292,7 +292,7 @@ void FMSQ::setNC(int _nc)
{
nc = _nc;
impulse = EQP::eq_impulse (nc, 3, F.data(), G.data(), rate, 1.0 / (2.0 * size), 0, 0);
FIRCORE::setNc_fircore (p, nc, impulse);
p->setNc(nc, impulse);
delete[] impulse;
}
}
@ -302,7 +302,7 @@ void FMSQ::setMP(int _mp)
if (mp != _mp)
{
mp = _mp;
FIRCORE::setMp_fircore (p, mp);
p->setMp(mp);
}
}

View File

@ -35,15 +35,15 @@ namespace WDSP {
void ICFIR::calc_icfir (ICFIR *a)
{
float* impulse;
a->scale = 1.0 / (float)(2 * a->size);
impulse = icfir_impulse (a->nc, a->DD, a->R, a->Pairs, a->runrate, a->cicrate, a->cutoff, a->xtype, a->xbw, 1, a->scale, a->wintype);
a->p = FIRCORE::create_fircore (a->size, a->in, a->out, a->nc, a->mp, impulse);
a->scale = 1.0f / (float)(2 * a->size);
impulse = icfir_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);
delete[] (impulse);
}
void ICFIR::decalc_icfir (ICFIR *a)
{
FIRCORE::destroy_fircore (a->p);
delete (a->p);
}
ICFIR* ICFIR::create_icfir (
@ -105,13 +105,13 @@ void ICFIR::destroy_icfir (ICFIR *a)
void ICFIR::flush_icfir (ICFIR *a)
{
FIRCORE::flush_fircore (a->p);
a->p->flush();
}
void ICFIR::xicfir (ICFIR *a)
{
if (a->run)
FIRCORE::xfircore (a->p);
a->p->execute();
else if (a->in != a->out)
std::copy( a->in, a->in + a->size * 2, a->out);
}
@ -171,16 +171,21 @@ float* ICFIR::icfir_impulse (
// xbw: transition bandwidth for raised cosine
// rtype: 0 for real output, 1 for complex output
// scale: scale factor to be applied to the output
int i, j;
float tmp, local_scale, ri, mag, fn;
int i;
int j;
float tmp;
float local_scale;
float ri;
float mag;
float fn;
float* impulse;
float* A = new float[N]; // (float *) malloc0 (N * sizeof (float));
auto* A = new float[N];
float ft = cutoff / cicrate; // normalized cutoff frequency
int u_samps = (N + 1) / 2; // number of unique samples, OK for odd or even N
int c_samps = (int)(cutoff / runrate * N) + (N + 1) / 2 - N / 2; // number of unique samples within bandpass, OK for odd or even N
int x_samps = (int)(xbw / runrate * N); // number of unique samples in transition region, OK for odd or even N
float offset = 0.5 - 0.5 * (float)((N + 1) / 2 - N / 2); // sample offset from center, OK for odd or even N
float* xistion = new float[x_samps + 1]; // (float *) malloc0 ((x_samps + 1) * sizeof (float));
auto x_samps = (int)(xbw / runrate * N); // number of unique samples in transition region, OK for odd or even N
float offset = 0.5f - 0.5f * (float)((N + 1) / 2 - N / 2); // sample offset from center, OK for odd or even N
auto* xistion = new float[x_samps + 1];
float delta = PI / (float)x_samps;
float L = cicrate / runrate;
float phs = 0.0;
@ -235,24 +240,10 @@ float* ICFIR::icfir_impulse (
for (i = u_samps, j = 1; i < N; i++, j++)
A[i] = A[u_samps - j];
impulse = FIR::fir_fsamp (N, A, rtype, 1.0, wintype);
// print_impulse ("icfirImpulse.txt", N, impulse, 1, 0);
delete[] (A);
delete[] xistion;
return impulse;
}
/********************************************************************************************************
* *
* TXA Properties *
* *
********************************************************************************************************/
//PORT void
//SetTXAICFIRRun (int channel, int run)
//{
// EnterCriticalSection(&ch[channel].csDSP);
// txa[channel].icfir.p->run = run;
// LeaveCriticalSection(&ch[channel].csDSP);
//}
} // namespace WDSP

View File

@ -333,7 +333,7 @@ void NBP::calc_lightweight()
gain / (float)(2 * size),
wintype
);
FIRCORE::setImpulse_fircore (fircore, impulse, 1);
fircore->setImpulse(impulse, 1);
// print_impulse ("nbp.txt", size + 1, impulse, 1, 0);
delete[] impulse;
}
@ -437,25 +437,25 @@ NBP::NBP(
bplow.resize(maxpb);
bphigh.resize(maxpb);
calc_impulse ();
fircore = FIRCORE::create_fircore (size, in, out, nc, mp, impulse);
fircore = new FIRCORE(size, in, out, nc, mp, impulse);
// print_impulse ("nbp.txt", size + 1, impulse, 1, 0);
delete[]impulse;
}
NBP::~NBP()
{
FIRCORE::destroy_fircore (fircore);
delete (fircore);
}
void NBP::flush()
{
FIRCORE::flush_fircore (fircore);
fircore->flush();
}
void NBP::execute (int pos)
{
if (run && pos == position)
FIRCORE::xfircore (fircore);
fircore->execute();
else if (in != out)
std::copy( in, in + size * 2, out);
}
@ -464,14 +464,14 @@ void NBP::setBuffers(float* _in, float* _out)
{
in = _in;
out = _out;
FIRCORE::setBuffers_fircore (fircore, in, out);
fircore->setBuffers(in, out);
}
void NBP::setSamplerate(int _rate)
{
rate = _rate;
calc_impulse ();
FIRCORE::setImpulse_fircore (fircore, impulse, 1);
fircore->setImpulse(impulse, 1);
delete[] impulse;
}
@ -479,22 +479,22 @@ void NBP::setSize(int _size)
{
// NOTE: 'size' must be <= 'nc'
size = _size;
FIRCORE::setSize_fircore (fircore, size);
fircore->setSize(size);
calc_impulse ();
FIRCORE::setImpulse_fircore (fircore, impulse, 1);
fircore->setImpulse(impulse, 1);
delete[] impulse;
}
void NBP::setNc()
{
calc_impulse();
FIRCORE::setNc_fircore (fircore, nc, impulse);
fircore->setNc(nc, impulse);
delete[] impulse;
}
void NBP::setMp()
{
FIRCORE::setMp_fircore (fircore, mp);
fircore->setMp(mp);
}
/********************************************************************************************************
@ -517,7 +517,7 @@ void NBP::SetFreqs(double _flow, double _fhigh)
flow = _flow;
fhigh = _fhigh;
calc_impulse();
FIRCORE::setImpulse_fircore (fircore, impulse, 1);
fircore->setImpulse(impulse, 1);
delete[] impulse;
}
}