1
0
mirror of https://github.com/f4exb/sdrangel.git synced 2024-11-10 18:43:28 -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; a->run = 0;
if (!old && a->run) if (!old && a->run)
a->flush(); a->flush();
FIRCORE::setUpdate_fircore(a->fircore); a->fircore->setUpdate();
} }
void RXA::bpsnbaCheck(int _mode, int _notch_run) void RXA::bpsnbaCheck(int _mode, int _notch_run)
@ -989,7 +989,7 @@ void RXA::bpsnbaSet()
default: default:
break; break;
} }
FIRCORE::setUpdate_fircore(a->bpsnba->fircore); a->bpsnba->fircore->setUpdate();
} }
void RXA::updateNBPFiltersLightWeight() void RXA::updateNBPFiltersLightWeight()
@ -1005,7 +1005,7 @@ void RXA::updateNBPFilters()
if (a->fnfrun) if (a->fnfrun)
{ {
a->calc_impulse(); a->calc_impulse();
FIRCORE::setImpulse_fircore(a->fircore, a->impulse, 1); a->fircore->setImpulse(a->impulse, 1);
delete[] (a->impulse); delete[] (a->impulse);
} }
if (b->bpsnba->fnfrun) if (b->bpsnba->fnfrun)
@ -1097,10 +1097,10 @@ void RXA::nbpSetNotchesRun(int _run)
b->fnfrun = a->master_run; b->fnfrun = a->master_run;
bpsnbaCheck(mode, _run); bpsnbaCheck(mode, _run);
b->calc_impulse(); // recalc nbp impulse response 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); delete[] (b->impulse);
bpsnbaSet(); 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->wintype = _wintype;
a->calc_impulse(); a->calc_impulse();
FIRCORE::setImpulse_fircore(a->fircore, a->impulse, 1); a->fircore->setImpulse(a->impulse, 1);
delete[] (a->impulse); delete[] (a->impulse);
} }
@ -1137,7 +1137,7 @@ void RXA::nbpSetAutoIncrease(int _autoincr)
{ {
a->autoincr = _autoincr; a->autoincr = _autoincr;
a->calc_impulse(); a->calc_impulse();
FIRCORE::setImpulse_fircore(a->fircore, a->impulse, 1); a->fircore->setImpulse(a->impulse, 1);
delete[] (a->impulse); delete[] (a->impulse);
} }

View File

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

View File

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

View File

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

View File

@ -377,7 +377,7 @@ void FIR::analytic (int N, float* in, float* out)
fftwf_destroy_plan (pfor); 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 i;
int size = N * pfactor; 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> ana(size * 2);
std::vector<float> impulse(size * 2); std::vector<float> impulse(size * 2);
std::vector<float> newfreq(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 ( fftwf_plan pfor = fftwf_plan_dft_1d (
size, size,
(fftwf_complex *) firpad.data(), (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); fftwf_execute (prev);
if (polarity) 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 else
std::copy(impulse.begin(), impulse.end(), mpfir); std::copy(impulse.begin(), impulse.end(), mpfir.begin());
fftwf_destroy_plan (prev); fftwf_destroy_plan (prev);
fftwf_destroy_plan (pfor); fftwf_destroy_plan (pfor);

View File

@ -27,6 +27,8 @@ warren@pratt.one
#ifndef wdsp_fir_h #ifndef wdsp_fir_h
#define wdsp_fir_h #define wdsp_fir_h
#include <vector>
#include "export.h" #include "export.h"
namespace WDSP { 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_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_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 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: private:
static void analytic (int N, float* in, float* out); 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' // must call for change in 'nc', 'size', 'out'
int i; nfor = nc / size;
a->nfor = a->nc / a->size; cset = 0;
a->cset = 0; buffidx = 0;
a->buffidx = 0; idxmask = nfor - 1;
a->idxmask = a->nfor - 1; fftin.resize(2 * size * 2);
a->fftin = new float[2 * a->size * 2]; // (float *) malloc0 (2 * a->size * sizeof (complex)); fftout.resize(nfor);
a->fftout = new float*[a->nfor]; // (float **) malloc0 (a->nfor * sizeof (float *)); fmask[0].resize(nfor);
a->fmask = new float**[2]; // (float ***) malloc0 (2 * sizeof (float **)); fmask[1].resize(nfor);
a->fmask[0] = new float*[a->nfor]; // (float **) malloc0 (a->nfor * sizeof (float *)); maskgen.resize(2 * size * 2);
a->fmask[1] = new float*[a->nfor]; // (float **) malloc0 (a->nfor * sizeof (float *)); pcfor.resize(nfor);
a->maskgen = new float[2 * a->size * 2]; // (float *) malloc0 (2 * a->size * sizeof (complex)); maskplan[0].resize(nfor);
a->pcfor = new fftwf_plan[a->nfor]; // (fftwf_plan *) malloc0 (a->nfor * sizeof (fftwf_plan)); maskplan[1].resize(nfor);
a->maskplan = new fftwf_plan*[2]; // (fftwf_plan **) malloc0 (2 * sizeof (fftwf_plan *)); for (int i = 0; i < nfor; i++)
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++)
{ {
a->fftout[i] = new float[2 * a->size * 2]; // (float *) malloc0 (2 * a->size * sizeof (complex)); fftout[i].resize(2 * size * 2);
a->fmask[0][i] = new float[2 * a->size * 2]; // (float *) malloc0 (2 * a->size * sizeof (complex)); fmask[0][i].resize(2 * size * 2);
a->fmask[1][i] = new float[2 * a->size * 2]; // (float *) malloc0 (2 * a->size * sizeof (complex)); fmask[1][i].resize(2 * size * 2);
a->pcfor[i] = fftwf_plan_dft_1d( pcfor[i] = fftwf_plan_dft_1d(
2 * a->size, 2 * size,
(fftwf_complex *)a->fftin, (fftwf_complex *)fftin.data(),
(fftwf_complex *)a->fftout[i], (fftwf_complex *)fftout[i].data(),
FFTW_FORWARD, FFTW_FORWARD,
FFTW_PATIENT FFTW_PATIENT
); );
a->maskplan[0][i] = fftwf_plan_dft_1d( maskplan[0][i] = fftwf_plan_dft_1d(
2 * a->size, 2 * size,
(fftwf_complex *)a->maskgen, (fftwf_complex *)maskgen.data(),
(fftwf_complex *)a->fmask[0][i], (fftwf_complex *)fmask[0][i].data(),
FFTW_FORWARD, FFTW_FORWARD,
FFTW_PATIENT FFTW_PATIENT
); );
a->maskplan[1][i] = fftwf_plan_dft_1d( maskplan[1][i] = fftwf_plan_dft_1d(
2 * a->size, 2 * size,
(fftwf_complex *)a->maskgen, (fftwf_complex *)maskgen.data(),
(fftwf_complex *)a->fmask[1][i], (fftwf_complex *)fmask[1][i].data(),
FFTW_FORWARD, FFTW_FORWARD,
FFTW_PATIENT FFTW_PATIENT
); );
} }
a->accum = new float[2 * a->size * 2]; // (float *) malloc0 (2 * a->size * sizeof (complex)); accum.resize(2 * size * 2);
a->crev = fftwf_plan_dft_1d( crev = fftwf_plan_dft_1d(
2 * a->size, 2 * size,
(fftwf_complex *)a->accum, (fftwf_complex *)accum.data(),
(fftwf_complex *)a->out, (fftwf_complex *)out,
FFTW_BACKWARD, FFTW_BACKWARD,
FFTW_PATIENT 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 // call for change in frequency, rate, wintype, gain
// must also call after a call to plan_firopt() // must also call after a call to plan_firopt()
int i;
if (a->mp) if (mp)
FIR::mp_imp (a->nc, a->impulse, a->imp, 16, 0); FIR::mp_imp (nc, impulse, imp, 16, 0);
else 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 // 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. // 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])); std::copy(&(imp[2 * size * i]), &(imp[2 * size * i]) + size * 2, &(maskgen[2 * size]));
fftwf_execute (a->maskplan[1 - a->cset][i]); fftwf_execute (maskplan[1 - cset][i]);
} }
a->masks_ready = 1; masks_ready = 1;
if (flip) if (_flip)
{ {
a->cset = 1 - a->cset; cset = 1 - cset;
a->masks_ready = 0; 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; size = _size;
a->size = size; in = _in;
a->in = in; out = _out;
a->out = out; nc = _nc;
a->nc = nc; mp = _mp;
a->mp = mp; plan();
// InitializeCriticalSectionAndSpinCount (&a->update, 2500); impulse.resize(nc * 2);
plan_fircore (a); imp.resize(nc * 2);
a->impulse = new float[a->nc * 2]; // (float *) malloc0 (a->nc * sizeof (complex)); std::copy(_impulse, _impulse + nc * 2, impulse.begin());
a->imp = new float[a->nc * 2]; // (float *) malloc0 (a->nc * sizeof (complex)); calc(1);
std::copy(impulse, impulse + a->nc * 2, a->impulse);
calc_fircore (a, 1);
return a;
} }
void FIRCORE::deplan_fircore (FIRCORE *a) void FIRCORE::deplan()
{ {
int i; fftwf_destroy_plan (crev);
fftwf_destroy_plan (a->crev); for (int i = 0; i < nfor; i++)
delete[] (a->accum);
for (i = 0; i < a->nfor; i++)
{ {
delete[] (a->fftout[i]); fftwf_destroy_plan (pcfor[i]);
delete[] (a->fmask[0][i]); fftwf_destroy_plan (maskplan[0][i]);
delete[] (a->fmask[1][i]); fftwf_destroy_plan (maskplan[1][i]);
fftwf_destroy_plan (a->pcfor[i]);
fftwf_destroy_plan (a->maskplan[0][i]);
fftwf_destroy_plan (a->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); deplan();
delete[] (a->imp);
delete[] (a->impulse);
delete (a);
} }
void FIRCORE::flush_fircore (FIRCORE *a) void FIRCORE::flush()
{ {
int i; std::fill(fftin.begin(), fftin.end(), 0);
std::fill(a->fftin, a->fftin + 2 * a->size * 2, 0); for (int i = 0; i < nfor; i++)
for (i = 0; i < a->nfor; i++) std::fill(fftout[i].begin(), fftout[i].end(), 0);
std::fill(a->fftout[i], a->fftout[i] + 2 * a->size * 2, 0); buffidx = 0;
a->buffidx = 0;
} }
void FIRCORE::xfircore (FIRCORE *a) void FIRCORE::execute()
{ {
int i, j, k; int k;
std::copy(a->in, a->in + a->size * 2, &(a->fftin[2 * a->size])); std::copy(in, in + size * 2, &(fftin[2 * size]));
fftwf_execute (a->pcfor[a->buffidx]); fftwf_execute (pcfor[buffidx]);
k = a->buffidx; k = buffidx;
std::fill(a->accum, a->accum + 2 * a->size * 2, 0); 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]; 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];
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 + 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; buffidx = (buffidx + 1) & idxmask;
fftwf_execute (a->crev); fftwf_execute (crev);
std::copy(&(a->fftin[2 * a->size]), &(a->fftin[2 * a->size]) + a->size * 2, a->fftin); 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; in = _in;
a->out = out; out = _out;
deplan_fircore (a); deplan();
plan_fircore (a); plan();
calc_fircore (a, 1); calc(1);
} }
void FIRCORE::setSize_fircore (FIRCORE *a, int size) void FIRCORE::setSize(int _size)
{ {
a->size = size; size = _size;
deplan_fircore (a); deplan();
plan_fircore (a); plan();
calc_fircore (a, 1); 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); std::copy(_impulse, _impulse + nc * 2, impulse.begin());
calc_fircore (a, update); 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 // because of FFT planning, this will probably cause a glitch in audio if done during dataflow
deplan_fircore (a); deplan();
delete[] (a->impulse); nc = _nc;
delete[] (a->imp); plan();
a->nc = nc; imp.resize(nc * 2);
plan_fircore (a); impulse.resize(nc * 2);
a->imp = new float[a->nc * 2]; // (float *) malloc0 (a->nc * sizeof (complex)); std::copy(_impulse, _impulse + nc * 2, impulse.begin());
a->impulse = new float[a->nc * 2]; // (float *) malloc0 (a->nc * sizeof (complex)); calc(1);
std::copy(impulse, impulse + a->nc * 2, a->impulse);
calc_fircore (a, 1);
} }
void FIRCORE::setMp_fircore (FIRCORE *a, int mp) void FIRCORE::setMp(int _mp)
{ {
a->mp = mp; mp = _mp;
calc_fircore (a, 1); calc(1);
} }
void FIRCORE::setUpdate_fircore (FIRCORE *a) void FIRCORE::setUpdate()
{ {
if (a->masks_ready) if (masks_ready)
{ {
a->cset = 1 - a->cset; cset = 1 - cset;
a->masks_ready = 0; masks_ready = 0;
} }
} }

View File

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

View File

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

View File

@ -81,14 +81,14 @@ FMMOD* FMMOD::create_fmmod (
a->mp = mp; a->mp = mp;
calc_fmmod (a); calc_fmmod (a);
impulse = FIR::fir_bandpass(a->nc, -a->bp_fc, +a->bp_fc, a->samplerate, 0, 1, 1.0 / (2 * a->size)); 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); delete[] (impulse);
return a; return a;
} }
void FMMOD::destroy_fmmod (FMMOD *a) void FMMOD::destroy_fmmod (FMMOD *a)
{ {
FIRCORE::destroy_fircore (a->p); delete (a->p);
delete (a); delete (a);
} }
@ -124,7 +124,7 @@ void FMMOD::xfmmod (FMMOD *a)
} }
//print_deviation ("peakdev.txt", peak, a->samplerate); //print_deviation ("peakdev.txt", peak, a->samplerate);
if (a->bp_run) if (a->bp_run)
FIRCORE::xfircore (a->p); a->p->execute();
} }
else if (a->in != a->out) else if (a->in != a->out)
std::copy( a->in, a->in + a->size * 2, 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->in = in;
a->out = out; a->out = out;
calc_fmmod (a); 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) void FMMOD::setSamplerate_fmmod (FMMOD *a, int rate)
@ -144,7 +144,7 @@ void FMMOD::setSamplerate_fmmod (FMMOD *a, int rate)
a->samplerate = rate; a->samplerate = rate;
calc_fmmod (a); calc_fmmod (a);
impulse = FIR::fir_bandpass(a->nc, -a->bp_fc, +a->bp_fc, a->samplerate, 0, 1, 1.0 / (2 * 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); delete[] (impulse);
} }
@ -153,9 +153,9 @@ void FMMOD::setSize_fmmod (FMMOD *a, int size)
float* impulse; float* impulse;
a->size = size; a->size = size;
calc_fmmod (a); 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)); 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); delete[] (impulse);
} }
@ -170,7 +170,7 @@ void FMMOD::SetFMDeviation (TXA& txa, float deviation)
FMMOD *a = txa.fmmod; FMMOD *a = txa.fmmod;
float bp_fc = a->f_high + deviation; 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)); 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); delete[] (impulse);
a->deviation = deviation; a->deviation = deviation;
// mod // mod
@ -178,7 +178,7 @@ void FMMOD::SetFMDeviation (TXA& txa, float deviation)
a->sdelta = TWOPI * a->deviation / a->samplerate; a->sdelta = TWOPI * a->deviation / a->samplerate;
// bandpass // bandpass
a->bp_fc = bp_fc; a->bp_fc = bp_fc;
FIRCORE::setUpdate_fircore (a->p); a->p->setUpdate();
} }
void FMMOD::SetCTCSSFreq (TXA& txa, float freq) void FMMOD::SetCTCSSFreq (TXA& txa, float freq)
@ -205,7 +205,7 @@ void FMMOD::SetFMNC (TXA& txa, int nc)
{ {
a->nc = 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)); 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); delete[] (impulse);
} }
} }
@ -217,7 +217,7 @@ void FMMOD::SetFMMP (TXA& txa, int mp)
if (a->mp != mp) if (a->mp != mp)
{ {
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->f_high = high;
a->bp_fc = a->deviation + a->f_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)); 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); delete[] (impulse);
} }
} }

View File

@ -49,7 +49,7 @@ void FMSQ::calc()
G[2] = 3.0; G[2] = 3.0;
G[3] = (float) (+20.0 * log10(20000.0 / *pllpole)); 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); 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; delete[] impulse;
// noise averaging // noise averaging
avm = exp(-1.0 / (rate * avtau)); avm = exp(-1.0 / (rate * avtau));
@ -89,7 +89,7 @@ void FMSQ::calc()
void FMSQ::decalc() void FMSQ::decalc()
{ {
FIRCORE::destroy_fircore (p); delete (p);
} }
FMSQ::FMSQ( FMSQ::FMSQ(
@ -143,7 +143,7 @@ FMSQ::~FMSQ()
void FMSQ::flush() void FMSQ::flush()
{ {
FIRCORE::flush_fircore (p); p->flush();
avnoise = 100.0; avnoise = 100.0;
longnoise = 1.0; longnoise = 1.0;
state = FMSQState::MUTED; state = FMSQState::MUTED;
@ -157,7 +157,7 @@ void FMSQ::execute()
{ {
double _noise; double _noise;
double lnlimit; double lnlimit;
FIRCORE::xfircore (p); p->execute();
for (int i = 0; i < size; i++) for (int i = 0; i < size; i++)
{ {
@ -250,7 +250,7 @@ void FMSQ::setBuffers(float* in, float* out, float* trig)
insig = in; insig = in;
outsig = out; outsig = out;
trigger = trig; trigger = trig;
FIRCORE::setBuffers_fircore (p, trigger, noise.data()); p->setBuffers(trigger, noise.data());
} }
void FMSQ::setSamplerate(int _rate) void FMSQ::setSamplerate(int _rate)
@ -292,7 +292,7 @@ void FMSQ::setNC(int _nc)
{ {
nc = _nc; nc = _nc;
impulse = EQP::eq_impulse (nc, 3, F.data(), G.data(), rate, 1.0 / (2.0 * size), 0, 0); 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; delete[] impulse;
} }
} }
@ -302,7 +302,7 @@ void FMSQ::setMP(int _mp)
if (mp != _mp) if (mp != _mp)
{ {
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) void ICFIR::calc_icfir (ICFIR *a)
{ {
float* impulse; float* impulse;
a->scale = 1.0 / (float)(2 * a->size); a->scale = 1.0f / (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); 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 = 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); delete[] (impulse);
} }
void ICFIR::decalc_icfir (ICFIR *a) void ICFIR::decalc_icfir (ICFIR *a)
{ {
FIRCORE::destroy_fircore (a->p); delete (a->p);
} }
ICFIR* ICFIR::create_icfir ( ICFIR* ICFIR::create_icfir (
@ -105,13 +105,13 @@ void ICFIR::destroy_icfir (ICFIR *a)
void ICFIR::flush_icfir (ICFIR *a) void ICFIR::flush_icfir (ICFIR *a)
{ {
FIRCORE::flush_fircore (a->p); a->p->flush();
} }
void ICFIR::xicfir (ICFIR *a) void ICFIR::xicfir (ICFIR *a)
{ {
if (a->run) if (a->run)
FIRCORE::xfircore (a->p); a->p->execute();
else if (a->in != a->out) else if (a->in != a->out)
std::copy( a->in, a->in + a->size * 2, 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 // xbw: transition bandwidth for raised cosine
// rtype: 0 for real output, 1 for complex output // rtype: 0 for real output, 1 for complex output
// scale: scale factor to be applied to the output // scale: scale factor to be applied to the output
int i, j; int i;
float tmp, local_scale, ri, mag, fn; int j;
float tmp;
float local_scale;
float ri;
float mag;
float fn;
float* impulse; float* impulse;
float* A = new float[N]; // (float *) malloc0 (N * sizeof (float)); auto* A = new float[N];
float ft = cutoff / cicrate; // normalized cutoff frequency float ft = cutoff / cicrate; // normalized cutoff frequency
int u_samps = (N + 1) / 2; // number of unique samples, OK for odd or even N 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 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 auto 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 offset = 0.5f - 0.5f * (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* xistion = new float[x_samps + 1];
float delta = PI / (float)x_samps; float delta = PI / (float)x_samps;
float L = cicrate / runrate; float L = cicrate / runrate;
float phs = 0.0; float phs = 0.0;
@ -235,24 +240,10 @@ float* ICFIR::icfir_impulse (
for (i = u_samps, j = 1; i < N; i++, j++) for (i = u_samps, j = 1; i < N; i++, j++)
A[i] = A[u_samps - j]; A[i] = A[u_samps - j];
impulse = FIR::fir_fsamp (N, A, rtype, 1.0, wintype); impulse = FIR::fir_fsamp (N, A, rtype, 1.0, wintype);
// print_impulse ("icfirImpulse.txt", N, impulse, 1, 0);
delete[] (A); delete[] (A);
delete[] xistion; delete[] xistion;
return impulse; 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 } // namespace WDSP

View File

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