mirror of
https://github.com/f4exb/sdrangel.git
synced 2024-11-22 08:04:49 -05:00
WDSP: impulse responses refactoring (1)
This commit is contained in:
parent
130d40c218
commit
62f05b3706
@ -34,11 +34,10 @@ namespace WDSP {
|
|||||||
|
|
||||||
void CFIR::calc()
|
void CFIR::calc()
|
||||||
{
|
{
|
||||||
float* impulse;
|
std::vector<float> impulse;
|
||||||
scale = 1.0 / (float)(2 * size);
|
scale = 1.0 / (float)(2 * size);
|
||||||
impulse = cfir_impulse (nc, DD, R, Pairs, runrate, cicrate, cutoff, xtype, xbw, 1, scale, wintype);
|
cfir_impulse (impulse, nc, DD, R, Pairs, runrate, cicrate, cutoff, xtype, xbw, 1, scale, wintype);
|
||||||
p = new FIRCORE(size, in, out, nc, mp, impulse);
|
p = new FIRCORE(size, in, out, nc, mp, impulse.data());
|
||||||
delete[] impulse;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void CFIR::decalc()
|
void CFIR::decalc()
|
||||||
@ -142,7 +141,8 @@ void CFIR::setOutRate(int rate)
|
|||||||
calc();
|
calc();
|
||||||
}
|
}
|
||||||
|
|
||||||
float* CFIR::cfir_impulse (
|
void CFIR::cfir_impulse (
|
||||||
|
std::vector<float>& impulse,
|
||||||
int _N,
|
int _N,
|
||||||
int _DD,
|
int _DD,
|
||||||
int _R,
|
int _R,
|
||||||
@ -175,7 +175,6 @@ float* CFIR::cfir_impulse (
|
|||||||
double ri;
|
double ri;
|
||||||
double mag = 0;
|
double mag = 0;
|
||||||
double fn;
|
double fn;
|
||||||
float* impulse;
|
|
||||||
std::vector<float> A(_N);
|
std::vector<float> A(_N);
|
||||||
double ft = _cutoff / _cicrate; // normalized cutoff frequency
|
double 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
|
||||||
@ -254,8 +253,8 @@ float* CFIR::cfir_impulse (
|
|||||||
else
|
else
|
||||||
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.data(), _rtype, 1.0, _wintype);
|
impulse.resize(2 * _N);
|
||||||
return impulse;
|
FIR::fir_fsamp (impulse, _N, A.data(), _rtype, 1.0, _wintype);
|
||||||
}
|
}
|
||||||
|
|
||||||
/********************************************************************************************************
|
/********************************************************************************************************
|
||||||
|
@ -28,6 +28,8 @@ warren@wpratt.com
|
|||||||
#ifndef wdsp_cfir_h
|
#ifndef wdsp_cfir_h
|
||||||
#define wdsp_cfir_h
|
#define wdsp_cfir_h
|
||||||
|
|
||||||
|
#include <vector>
|
||||||
|
|
||||||
#include "export.h"
|
#include "export.h"
|
||||||
|
|
||||||
namespace WDSP {
|
namespace WDSP {
|
||||||
@ -83,7 +85,8 @@ public:
|
|||||||
void setSamplerate(int rate);
|
void setSamplerate(int rate);
|
||||||
void setSize(int size);
|
void setSize(int size);
|
||||||
void setOutRate(int rate);
|
void setOutRate(int rate);
|
||||||
static float* cfir_impulse (
|
static void cfir_impulse (
|
||||||
|
std::vector<float>& impulse,
|
||||||
int N,
|
int N,
|
||||||
int DD,
|
int DD,
|
||||||
int R,
|
int R,
|
||||||
|
@ -53,7 +53,6 @@ EMPHP::EMPHP(
|
|||||||
double _f_high
|
double _f_high
|
||||||
)
|
)
|
||||||
{
|
{
|
||||||
float* impulse;
|
|
||||||
run = _run;
|
run = _run;
|
||||||
position = _position;
|
position = _position;
|
||||||
size = _size;
|
size = _size;
|
||||||
@ -65,7 +64,9 @@ EMPHP::EMPHP(
|
|||||||
ctype = _ctype;
|
ctype = _ctype;
|
||||||
f_low = _f_low;
|
f_low = _f_low;
|
||||||
f_high = _f_high;
|
f_high = _f_high;
|
||||||
impulse = FCurve::fc_impulse (
|
std::vector<float> impulse(2 * nc);
|
||||||
|
FCurve::fc_impulse (
|
||||||
|
impulse,
|
||||||
nc,
|
nc,
|
||||||
f_low,
|
f_low,
|
||||||
f_high,
|
f_high,
|
||||||
@ -76,8 +77,7 @@ EMPHP::EMPHP(
|
|||||||
1.0 / (2.0 * size),
|
1.0 / (2.0 * size),
|
||||||
0, 0
|
0, 0
|
||||||
);
|
);
|
||||||
p = new FIRCORE(size, in, out, nc, mp, impulse);
|
p = new FIRCORE(size, in, out, nc, mp, impulse.data());
|
||||||
delete[] (impulse);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
EMPHP::~EMPHP()
|
EMPHP::~EMPHP()
|
||||||
@ -107,9 +107,10 @@ void EMPHP::setBuffers(float* _in, float* _out)
|
|||||||
|
|
||||||
void EMPHP::setSamplerate(int _rate)
|
void EMPHP::setSamplerate(int _rate)
|
||||||
{
|
{
|
||||||
float* impulse;
|
|
||||||
rate = _rate;
|
rate = _rate;
|
||||||
impulse = FCurve::fc_impulse (
|
std::vector<float> impulse(2 * nc);
|
||||||
|
FCurve::fc_impulse (
|
||||||
|
impulse,
|
||||||
nc,
|
nc,
|
||||||
f_low,
|
f_low,
|
||||||
f_high,
|
f_high,
|
||||||
@ -120,16 +121,16 @@ void EMPHP::setSamplerate(int _rate)
|
|||||||
1.0 / (2.0 * size),
|
1.0 / (2.0 * size),
|
||||||
0, 0
|
0, 0
|
||||||
);
|
);
|
||||||
p->setImpulse(impulse, 1);
|
p->setImpulse(impulse.data(), 1);
|
||||||
delete[] (impulse);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void EMPHP::setSize(int _size)
|
void EMPHP::setSize(int _size)
|
||||||
{
|
{
|
||||||
float* impulse;
|
|
||||||
size = _size;
|
size = _size;
|
||||||
p->setSize(size);
|
p->setSize(size);
|
||||||
impulse = FCurve::fc_impulse (
|
std::vector<float> impulse(2 * nc);
|
||||||
|
FCurve::fc_impulse (
|
||||||
|
impulse,
|
||||||
nc,
|
nc,
|
||||||
f_low,
|
f_low,
|
||||||
f_high,
|
f_high,
|
||||||
@ -141,8 +142,7 @@ void EMPHP::setSize(int _size)
|
|||||||
0,
|
0,
|
||||||
0
|
0
|
||||||
);
|
);
|
||||||
p->setImpulse(impulse, 1);
|
p->setImpulse(impulse.data(), 1);
|
||||||
delete[] (impulse);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/********************************************************************************************************
|
/********************************************************************************************************
|
||||||
@ -167,12 +167,12 @@ void EMPHP::setMP(int _mp)
|
|||||||
|
|
||||||
void EMPHP::setNC(int _nc)
|
void EMPHP::setNC(int _nc)
|
||||||
{
|
{
|
||||||
float* impulse;
|
|
||||||
|
|
||||||
if (nc != _nc)
|
if (nc != _nc)
|
||||||
{
|
{
|
||||||
nc = _nc;
|
nc = _nc;
|
||||||
impulse = FCurve::fc_impulse (
|
std::vector<float> impulse(2 * nc);
|
||||||
|
FCurve::fc_impulse (
|
||||||
|
impulse,
|
||||||
nc,
|
nc,
|
||||||
f_low,
|
f_low,
|
||||||
f_high,
|
f_high,
|
||||||
@ -184,20 +184,19 @@ void EMPHP::setNC(int _nc)
|
|||||||
0,
|
0,
|
||||||
0
|
0
|
||||||
);
|
);
|
||||||
p->setNc(nc, impulse);
|
p->setNc(nc, impulse.data());
|
||||||
delete[] (impulse);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void EMPHP::setFreqs(double low, double high)
|
void EMPHP::setFreqs(double low, double high)
|
||||||
{
|
{
|
||||||
float* impulse;
|
|
||||||
|
|
||||||
if (f_low != low || f_high != high)
|
if (f_low != low || f_high != high)
|
||||||
{
|
{
|
||||||
f_low = low;
|
f_low = low;
|
||||||
f_high = high;
|
f_high = high;
|
||||||
impulse = FCurve::fc_impulse (
|
std::vector<float> impulse(2 * nc);
|
||||||
|
FCurve::fc_impulse (
|
||||||
|
impulse,
|
||||||
nc,
|
nc,
|
||||||
f_low,
|
f_low,
|
||||||
f_high,
|
f_high,
|
||||||
@ -209,8 +208,7 @@ void EMPHP::setFreqs(double low, double high)
|
|||||||
0,
|
0,
|
||||||
0
|
0
|
||||||
);
|
);
|
||||||
p->setImpulse(impulse, 1);
|
p->setImpulse(impulse.data(), 1);
|
||||||
delete[] (impulse);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -44,12 +44,12 @@ namespace WDSP {
|
|||||||
|
|
||||||
void EQ::eq_mults (std::vector<float>& mults, int size, int nfreqs, float* F, float* G, float samplerate, float scale, int ctfmode, int wintype)
|
void EQ::eq_mults (std::vector<float>& mults, int size, int nfreqs, float* F, float* G, float samplerate, float scale, int ctfmode, int wintype)
|
||||||
{
|
{
|
||||||
float* impulse = EQP::eq_impulse (size + 1, nfreqs, F, G, samplerate, scale, ctfmode, wintype);
|
std::vector<float> impulse;
|
||||||
float* _mults = FIR::fftcv_mults(2 * size, impulse);
|
EQP::eq_impulse (impulse, size + 1, nfreqs, F, G, samplerate, scale, ctfmode, wintype);
|
||||||
|
float* _mults = FIR::fftcv_mults(2 * size, impulse.data());
|
||||||
mults.resize(2 * size * 2);
|
mults.resize(2 * size * 2);
|
||||||
std::copy(_mults, _mults + 2*size*2, mults.begin());
|
std::copy(_mults, _mults + 2*size*2, mults.begin());
|
||||||
delete[] _mults;
|
delete[] _mults;
|
||||||
delete[] impulse;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void EQ::calc()
|
void EQ::calc()
|
||||||
|
109
wdsp/eqp.cpp
109
wdsp/eqp.cpp
@ -42,25 +42,34 @@ int EQP::fEQcompare (const void * a, const void * b)
|
|||||||
return 1;
|
return 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
float* EQP::eq_impulse (int N, int nfreqs, const float* F, const float* G, double samplerate, double scale, int ctfmode, int wintype)
|
void EQP::eq_impulse (
|
||||||
|
std::vector<float>& impulse,
|
||||||
|
int N,
|
||||||
|
int _nfreqs,
|
||||||
|
const float* F,
|
||||||
|
const float* G,
|
||||||
|
double samplerate,
|
||||||
|
double scale,
|
||||||
|
int ctfmode,
|
||||||
|
int wintype
|
||||||
|
)
|
||||||
{
|
{
|
||||||
std::vector<float> fp(nfreqs + 2);
|
std::vector<float> fp(_nfreqs + 2);
|
||||||
std::vector<float> gp(nfreqs + 2);
|
std::vector<float> gp(_nfreqs + 2);
|
||||||
std::vector<float> A(N / 2 + 1);
|
std::vector<float> A(N / 2 + 1);
|
||||||
float* sary = new float[2 * nfreqs];
|
float* sary = new float[2 * _nfreqs];
|
||||||
|
|
||||||
double gpreamp;
|
double gpreamp;
|
||||||
double f;
|
double f;
|
||||||
double frac;
|
double frac;
|
||||||
float* impulse;
|
|
||||||
int i;
|
int i;
|
||||||
int j;
|
int j;
|
||||||
int mid;
|
int mid;
|
||||||
fp[0] = 0.0;
|
fp[0] = 0.0;
|
||||||
fp[nfreqs + 1] = 1.0;
|
fp[_nfreqs + 1] = 1.0;
|
||||||
gpreamp = G[0];
|
gpreamp = G[0];
|
||||||
|
|
||||||
for (i = 1; i <= nfreqs; i++)
|
for (i = 1; i <= _nfreqs; i++)
|
||||||
{
|
{
|
||||||
fp[i] = (float) (2.0 * F[i] / samplerate);
|
fp[i] = (float) (2.0 * F[i] / samplerate);
|
||||||
|
|
||||||
@ -73,22 +82,22 @@ float* EQP::eq_impulse (int N, int nfreqs, const float* F, const float* G, doubl
|
|||||||
gp[i] = G[i];
|
gp[i] = G[i];
|
||||||
}
|
}
|
||||||
|
|
||||||
for (i = 1, j = 0; i <= nfreqs; i++, j+=2)
|
for (i = 1, j = 0; i <= _nfreqs; i++, j+=2)
|
||||||
{
|
{
|
||||||
sary[j + 0] = fp[i];
|
sary[j + 0] = fp[i];
|
||||||
sary[j + 1] = gp[i];
|
sary[j + 1] = gp[i];
|
||||||
}
|
}
|
||||||
|
|
||||||
qsort (sary, nfreqs, 2 * sizeof (float), fEQcompare);
|
qsort (sary, _nfreqs, 2 * sizeof (float), fEQcompare);
|
||||||
|
|
||||||
for (i = 1, j = 0; i <= nfreqs; i++, j+=2)
|
for (i = 1, j = 0; i <= _nfreqs; i++, j+=2)
|
||||||
{
|
{
|
||||||
fp[i] = sary[j + 0];
|
fp[i] = sary[j + 0];
|
||||||
gp[i] = sary[j + 1];
|
gp[i] = sary[j + 1];
|
||||||
}
|
}
|
||||||
|
|
||||||
gp[0] = gp[1];
|
gp[0] = gp[1];
|
||||||
gp[nfreqs + 1] = gp[nfreqs];
|
gp[_nfreqs + 1] = gp[_nfreqs];
|
||||||
mid = N / 2;
|
mid = N / 2;
|
||||||
j = 0;
|
j = 0;
|
||||||
|
|
||||||
@ -98,7 +107,7 @@ float* EQP::eq_impulse (int N, int nfreqs, const float* F, const float* G, doubl
|
|||||||
{
|
{
|
||||||
f = (double)i / (double)mid;
|
f = (double)i / (double)mid;
|
||||||
|
|
||||||
while ((f > fp[j + 1]) && (j < nfreqs))
|
while ((f > fp[j + 1]) && (j < _nfreqs))
|
||||||
j++;
|
j++;
|
||||||
|
|
||||||
frac = (f - fp[j]) / (fp[j + 1] - fp[j]);
|
frac = (f - fp[j]) / (fp[j + 1] - fp[j]);
|
||||||
@ -111,7 +120,7 @@ float* EQP::eq_impulse (int N, int nfreqs, const float* F, const float* G, doubl
|
|||||||
{
|
{
|
||||||
f = ((double)i + 0.5) / (double)mid;
|
f = ((double)i + 0.5) / (double)mid;
|
||||||
|
|
||||||
while ((f > fp[j + 1]) && (j < nfreqs))
|
while ((f > fp[j + 1]) && (j < _nfreqs))
|
||||||
j++;
|
j++;
|
||||||
|
|
||||||
frac = (f - fp[j]) / (fp[j + 1] - fp[j]);
|
frac = (f - fp[j]) / (fp[j + 1] - fp[j]);
|
||||||
@ -132,7 +141,7 @@ float* EQP::eq_impulse (int N, int nfreqs, const float* F, const float* G, doubl
|
|||||||
if (N & 1)
|
if (N & 1)
|
||||||
{
|
{
|
||||||
low = (int)(fp[1] * mid);
|
low = (int)(fp[1] * mid);
|
||||||
high = (int)(fp[nfreqs] * mid + 0.5);
|
high = (int)(fp[_nfreqs] * mid + 0.5);
|
||||||
lowmag = A[low];
|
lowmag = A[low];
|
||||||
highmag = A[high];
|
highmag = A[high];
|
||||||
flow4 = pow((double)low / (double)mid, 4.0);
|
flow4 = pow((double)low / (double)mid, 4.0);
|
||||||
@ -160,7 +169,7 @@ float* EQP::eq_impulse (int N, int nfreqs, const float* F, const float* G, doubl
|
|||||||
else
|
else
|
||||||
{
|
{
|
||||||
low = (int)(fp[1] * mid - 0.5);
|
low = (int)(fp[1] * mid - 0.5);
|
||||||
high = (int)(fp[nfreqs] * mid - 0.5);
|
high = (int)(fp[_nfreqs] * mid - 0.5);
|
||||||
lowmag = A[low];
|
lowmag = A[low];
|
||||||
highmag = A[high];
|
highmag = A[high];
|
||||||
flow4 = pow((double)low / (double)mid, 4.0);
|
flow4 = pow((double)low / (double)mid, 4.0);
|
||||||
@ -187,13 +196,14 @@ float* EQP::eq_impulse (int N, int nfreqs, const float* F, const float* G, doubl
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
impulse.resize(2 * N);
|
||||||
|
|
||||||
if (N & 1)
|
if (N & 1)
|
||||||
impulse = FIR::fir_fsamp_odd(N, A.data(), 1, 1.0, wintype);
|
FIR::fir_fsamp_odd(impulse, N, A.data(), 1, 1.0, wintype);
|
||||||
else
|
else
|
||||||
impulse = FIR::fir_fsamp(N, A.data(), 1, 1.0, wintype);
|
FIR::fir_fsamp(impulse, N, A.data(), 1, 1.0, wintype);
|
||||||
|
|
||||||
delete[] sary;
|
delete[] sary;
|
||||||
return impulse;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/********************************************************************************************************
|
/********************************************************************************************************
|
||||||
@ -218,7 +228,7 @@ EQP::EQP(
|
|||||||
)
|
)
|
||||||
{
|
{
|
||||||
// NOTE: 'nc' must be >= 'size'
|
// NOTE: 'nc' must be >= 'size'
|
||||||
float* impulse;
|
std::vector<float> impulse;
|
||||||
run = _run;
|
run = _run;
|
||||||
size = _size;
|
size = _size;
|
||||||
nc = _nc;
|
nc = _nc;
|
||||||
@ -233,9 +243,8 @@ EQP::EQP(
|
|||||||
ctfmode = _ctfmode;
|
ctfmode = _ctfmode;
|
||||||
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);
|
eq_impulse (impulse, nc, nfreqs, F.data(), G.data(), samplerate, 1.0 / (2.0 * size), ctfmode, wintype);
|
||||||
fircore = new FIRCORE(size, in, out, nc, mp, impulse);
|
fircore = new FIRCORE(size, in, out, nc, mp, impulse.data());
|
||||||
delete[] impulse;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
EQP::~EQP()
|
EQP::~EQP()
|
||||||
@ -265,21 +274,19 @@ void EQP::setBuffers(float* _in, float* _out)
|
|||||||
|
|
||||||
void EQP::setSamplerate(int rate)
|
void EQP::setSamplerate(int rate)
|
||||||
{
|
{
|
||||||
float* impulse;
|
std::vector<float> impulse;
|
||||||
samplerate = rate;
|
samplerate = rate;
|
||||||
impulse = eq_impulse (nc, nfreqs, F.data(), G.data(), samplerate, 1.0 / (2.0 * size), ctfmode, wintype);
|
eq_impulse (impulse, nc, nfreqs, F.data(), G.data(), samplerate, 1.0 / (2.0 * size), ctfmode, wintype);
|
||||||
fircore->setImpulse(impulse, 1);
|
fircore->setImpulse(impulse.data(), 1);
|
||||||
delete[] impulse;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void EQP::setSize(int _size)
|
void EQP::setSize(int _size)
|
||||||
{
|
{
|
||||||
float* impulse;
|
std::vector<float> impulse;
|
||||||
size = _size;
|
size = _size;
|
||||||
fircore->setSize(size);
|
fircore->setSize(size);
|
||||||
impulse = eq_impulse (nc, nfreqs, F.data(), G.data(), samplerate, 1.0 / (2.0 * size), ctfmode, wintype);
|
eq_impulse (impulse, nc, nfreqs, F.data(), G.data(), samplerate, 1.0 / (2.0 * size), ctfmode, wintype);
|
||||||
fircore->setImpulse(impulse, 1);
|
fircore->setImpulse(impulse.data(), 1);
|
||||||
delete[] impulse;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/********************************************************************************************************
|
/********************************************************************************************************
|
||||||
@ -295,14 +302,13 @@ void EQP::setRun(int _run)
|
|||||||
|
|
||||||
void EQP::setNC(int _nc)
|
void EQP::setNC(int _nc)
|
||||||
{
|
{
|
||||||
float* impulse;
|
std::vector<float> impulse;
|
||||||
|
|
||||||
if (nc != _nc)
|
if (nc != _nc)
|
||||||
{
|
{
|
||||||
nc = _nc;
|
nc = _nc;
|
||||||
impulse = eq_impulse (nc, nfreqs, F.data(), G.data(), samplerate, 1.0 / (2.0 * size), ctfmode, wintype);
|
eq_impulse (impulse, nc, nfreqs, F.data(), G.data(), samplerate, 1.0 / (2.0 * size), ctfmode, wintype);
|
||||||
fircore->setNc(nc, impulse);
|
fircore->setNc(nc, impulse.data());
|
||||||
delete[] impulse;
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -317,38 +323,35 @@ void EQP::setMP(int _mp)
|
|||||||
|
|
||||||
void EQP::setProfile(int _nfreqs, const float* _F, const float* _G)
|
void EQP::setProfile(int _nfreqs, const float* _F, const float* _G)
|
||||||
{
|
{
|
||||||
float* impulse;
|
std::vector<float> impulse;
|
||||||
nfreqs = _nfreqs;
|
nfreqs = _nfreqs;
|
||||||
F.resize(nfreqs + 1);
|
F.resize(nfreqs + 1);
|
||||||
G.resize(nfreqs + 1);
|
G.resize(nfreqs + 1);
|
||||||
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);
|
eq_impulse (impulse, nc, nfreqs, F.data(), G.data(), samplerate, 1.0 / (2.0 * size), ctfmode, wintype);
|
||||||
fircore->setImpulse(impulse, 1);
|
fircore->setImpulse(impulse.data(), 1);
|
||||||
delete[] impulse;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void EQP::setCtfmode(int _mode)
|
void EQP::setCtfmode(int _mode)
|
||||||
{
|
{
|
||||||
float* impulse;
|
std::vector<float> impulse;
|
||||||
ctfmode = _mode;
|
ctfmode = _mode;
|
||||||
impulse = eq_impulse (nc, nfreqs, F.data(), G.data(), samplerate, 1.0 / (2.0 * size), ctfmode, wintype);
|
eq_impulse (impulse, nc, nfreqs, F.data(), G.data(), samplerate, 1.0 / (2.0 * size), ctfmode, wintype);
|
||||||
fircore->setImpulse(impulse, 1);
|
fircore->setImpulse(impulse.data(), 1);
|
||||||
delete[] impulse;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void EQP::setWintype(int _wintype)
|
void EQP::setWintype(int _wintype)
|
||||||
{
|
{
|
||||||
float* impulse;
|
std::vector<float> impulse;
|
||||||
wintype = _wintype;
|
wintype = _wintype;
|
||||||
impulse = eq_impulse (nc, nfreqs, F.data(), G.data(), samplerate, 1.0 / (2.0 * size), ctfmode, wintype);
|
eq_impulse (impulse, nc, nfreqs, F.data(), G.data(), samplerate, 1.0 / (2.0 * size), ctfmode, wintype);
|
||||||
fircore->setImpulse(impulse, 1);
|
fircore->setImpulse(impulse.data(), 1);
|
||||||
delete[] impulse;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void EQP::setGrphEQ(const int *rxeq)
|
void EQP::setGrphEQ(const int *rxeq)
|
||||||
{ // three band equalizer (legacy compatibility)
|
{ // three band equalizer (legacy compatibility)
|
||||||
float* impulse;
|
std::vector<float> impulse;
|
||||||
nfreqs = 4;
|
nfreqs = 4;
|
||||||
F.resize(nfreqs + 1);
|
F.resize(nfreqs + 1);
|
||||||
G.resize(nfreqs + 1);
|
G.resize(nfreqs + 1);
|
||||||
@ -362,14 +365,13 @@ void EQP::setGrphEQ(const int *rxeq)
|
|||||||
G[3] = (float)rxeq[2];
|
G[3] = (float)rxeq[2];
|
||||||
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);
|
eq_impulse (impulse, nc, nfreqs, F.data(), G.data(), samplerate, 1.0 / (2.0 * size), ctfmode, wintype);
|
||||||
fircore->setImpulse(impulse, 1);
|
fircore->setImpulse(impulse.data(), 1);
|
||||||
delete[] impulse;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void EQP::setGrphEQ10(const int *rxeq)
|
void EQP::setGrphEQ10(const int *rxeq)
|
||||||
{ // ten band equalizer (legacy compatibility)
|
{ // ten band equalizer (legacy compatibility)
|
||||||
float* impulse;
|
std::vector<float> impulse;
|
||||||
nfreqs = 10;
|
nfreqs = 10;
|
||||||
F.resize(nfreqs + 1);
|
F.resize(nfreqs + 1);
|
||||||
G.resize(nfreqs + 1);
|
G.resize(nfreqs + 1);
|
||||||
@ -386,9 +388,8 @@ void EQP::setGrphEQ10(const int *rxeq)
|
|||||||
for (int i = 0; i <= nfreqs; i++)
|
for (int i = 0; i <= nfreqs; i++)
|
||||||
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);
|
eq_impulse (impulse, nc, nfreqs, F.data(), G.data(), samplerate, 1.0 / (2.0 * size), ctfmode, wintype);
|
||||||
fircore->setImpulse(impulse, 1);
|
fircore->setImpulse(impulse.data(), 1);
|
||||||
delete[] impulse;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
} // namespace WDSP
|
} // namespace WDSP
|
||||||
|
12
wdsp/eqp.hpp
12
wdsp/eqp.hpp
@ -92,7 +92,17 @@ public:
|
|||||||
void setGrphEQ(const int *rxeq);
|
void setGrphEQ(const int *rxeq);
|
||||||
void setGrphEQ10(const int *rxeq);
|
void setGrphEQ10(const int *rxeq);
|
||||||
|
|
||||||
static float* eq_impulse (int N, int nfreqs, const float* F, const float* G, double samplerate, double scale, int ctfmode, int wintype);
|
static void eq_impulse (
|
||||||
|
std::vector<float>& impulse,
|
||||||
|
int N,
|
||||||
|
int nfreqs,
|
||||||
|
const float* F,
|
||||||
|
const float* G,
|
||||||
|
double samplerate,
|
||||||
|
double scale,
|
||||||
|
int ctfmode,
|
||||||
|
int wintype
|
||||||
|
);
|
||||||
|
|
||||||
private:
|
private:
|
||||||
static int fEQcompare (const void * a, const void * b);
|
static int fEQcompare (const void * a, const void * b);
|
||||||
|
@ -31,12 +31,11 @@ warren@wpratt.com
|
|||||||
|
|
||||||
namespace WDSP {
|
namespace WDSP {
|
||||||
|
|
||||||
float* FCurve::fc_impulse (int nc, float f0, float f1, float g0, float, int curve, float samplerate, float scale, int ctfmode, int wintype)
|
void FCurve::fc_impulse (std::vector<float>& impulse, int nc, float f0, float f1, float g0, float, int curve, float samplerate, float scale, int ctfmode, int wintype)
|
||||||
{
|
{
|
||||||
float* A = new float[nc / 2 + 1]; // (float *) malloc0 ((nc / 2 + 1) * sizeof (float));
|
float* A = new float[nc / 2 + 1]; // (float *) malloc0 ((nc / 2 + 1) * sizeof (float));
|
||||||
int i;
|
int i;
|
||||||
float fn, f;
|
float fn, f;
|
||||||
float* impulse;
|
|
||||||
int mid = nc / 2;
|
int mid = nc / 2;
|
||||||
float g0_lin = pow(10.0, g0 / 20.0);
|
float g0_lin = pow(10.0, g0 / 20.0);
|
||||||
if (nc & 1)
|
if (nc & 1)
|
||||||
@ -140,21 +139,21 @@ float* FCurve::fc_impulse (int nc, float f0, float f1, float g0, float, int curv
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if (nc & 1)
|
if (nc & 1)
|
||||||
impulse = FIR::fir_fsamp_odd(nc, A, 1, 1.0, wintype);
|
FIR::fir_fsamp_odd(impulse, nc, A, 1, 1.0, wintype);
|
||||||
else
|
else
|
||||||
impulse = FIR::fir_fsamp(nc, A, 1, 1.0, wintype);
|
FIR::fir_fsamp(impulse, nc, A, 1, 1.0, wintype);
|
||||||
// print_impulse ("emph.txt", size + 1, impulse, 1, 0);
|
// print_impulse ("emph.txt", size + 1, impulse, 1, 0);
|
||||||
delete[] (A);
|
delete[] (A);
|
||||||
return impulse;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// generate mask for Overlap-Save Filter
|
// generate mask for Overlap-Save Filter
|
||||||
float* FCurve::fc_mults (int size, float f0, float f1, float g0, float g1, int curve, float samplerate, float scale, int ctfmode, int wintype)
|
float* FCurve::fc_mults (int size, float f0, float f1, float g0, float g1, int curve, float samplerate, float scale, int ctfmode, int wintype)
|
||||||
{
|
{
|
||||||
float* impulse = fc_impulse (size + 1, f0, f1, g0, g1, curve, samplerate, scale, ctfmode, wintype);
|
std::vector<float> impulse(2 * (size + 1));
|
||||||
float* mults = FIR::fftcv_mults(2 * size, impulse);
|
fc_impulse (impulse, size + 1, f0, f1, g0, g1, curve, samplerate, scale, ctfmode, wintype);
|
||||||
delete[] (impulse);
|
float* mults = FIR::fftcv_mults(2 * size, impulse.data());
|
||||||
return mults;
|
return mults;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -28,6 +28,8 @@ warren@wpratt.com
|
|||||||
#ifndef wdsp_fcurve_h
|
#ifndef wdsp_fcurve_h
|
||||||
#define wdsp_fcurve_h
|
#define wdsp_fcurve_h
|
||||||
|
|
||||||
|
#include <vector>
|
||||||
|
|
||||||
#include "export.h"
|
#include "export.h"
|
||||||
|
|
||||||
namespace WDSP {
|
namespace WDSP {
|
||||||
@ -35,7 +37,7 @@ namespace WDSP {
|
|||||||
class WDSP_API FCurve
|
class WDSP_API FCurve
|
||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
static float* fc_impulse (int nc, float f0, float f1, float g0, float g1, int curve, float samplerate, float scale, int ctfmode, int wintype);
|
static void fc_impulse (std::vector<float>& impulse, int nc, float f0, float f1, float g0, float g1, int curve, float samplerate, float scale, int ctfmode, int wintype);
|
||||||
static float* fc_mults (int size, float f0, float f1, float g0, float g1, int curve, float samplerate, float scale, int ctfmode, int wintype);
|
static float* fc_mults (int size, float f0, float f1, float g0, float g1, int curve, float samplerate, float scale, int ctfmode, int wintype);
|
||||||
};
|
};
|
||||||
|
|
||||||
|
10
wdsp/fir.cpp
10
wdsp/fir.cpp
@ -95,17 +95,16 @@ float* FIR::get_fsamp_window(int N, int wintype)
|
|||||||
return window;
|
return window;
|
||||||
}
|
}
|
||||||
|
|
||||||
float* FIR::fir_fsamp_odd (int N, const float* A, int rtype, double scale, int wintype)
|
void FIR::fir_fsamp_odd (std::vector<float>& c_impulse, int N, const float* A, int rtype, double scale, int wintype)
|
||||||
{
|
{
|
||||||
int mid = (N - 1) / 2;
|
int mid = (N - 1) / 2;
|
||||||
double mag;
|
double mag;
|
||||||
double phs;
|
double phs;
|
||||||
std::vector<float> fcoef(N * 2);
|
std::vector<float> fcoef(N * 2);
|
||||||
auto *c_impulse = new float[N * 2];
|
|
||||||
fftwf_plan ptmp = fftwf_plan_dft_1d(
|
fftwf_plan ptmp = fftwf_plan_dft_1d(
|
||||||
N,
|
N,
|
||||||
(fftwf_complex *)fcoef.data(),
|
(fftwf_complex *)fcoef.data(),
|
||||||
(fftwf_complex *)c_impulse,
|
(fftwf_complex *)c_impulse.data(),
|
||||||
FFTW_BACKWARD,
|
FFTW_BACKWARD,
|
||||||
FFTW_PATIENT
|
FFTW_PATIENT
|
||||||
);
|
);
|
||||||
@ -142,13 +141,11 @@ float* FIR::fir_fsamp_odd (int N, const float* A, int rtype, double scale, int w
|
|||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
delete[] window;
|
delete[] window;
|
||||||
return c_impulse;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
float* FIR::fir_fsamp (int N, const float* A, int rtype, double scale, int wintype)
|
void FIR::fir_fsamp (std::vector<float>& c_impulse, int N, const float* A, int rtype, double scale, int wintype)
|
||||||
{
|
{
|
||||||
double sum;
|
double sum;
|
||||||
auto c_impulse = new float[N * 2];
|
|
||||||
|
|
||||||
if (N & 1)
|
if (N & 1)
|
||||||
{
|
{
|
||||||
@ -202,7 +199,6 @@ float* FIR::fir_fsamp (int N, const float* A, int rtype, double scale, int winty
|
|||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
delete[] window;
|
delete[] window;
|
||||||
return c_impulse;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
float* FIR::fir_bandpass (int N, double f_low, double f_high, double samplerate, int wintype, int rtype, double scale)
|
float* FIR::fir_bandpass (int N, double f_low, double f_high, double samplerate, int wintype, int rtype, double scale)
|
||||||
|
@ -37,8 +37,8 @@ class WDSP_API FIR
|
|||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
static float* fftcv_mults (int NM, float* c_impulse);
|
static float* fftcv_mults (int NM, float* c_impulse);
|
||||||
static float* fir_fsamp_odd (int N, const float* A, int rtype, double scale, int wintype);
|
static void fir_fsamp_odd (std::vector<float>& c_impulse, 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 void fir_fsamp (std::vector<float>& c_impulse, 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, std::vector<float>& fir, std::vector<float>& mpfir, int pfactor, int polarity);
|
static void mp_imp (int N, std::vector<float>& fir, std::vector<float>& mpfir, int pfactor, int polarity);
|
||||||
|
|
||||||
|
65
wdsp/fmd.cpp
65
wdsp/fmd.cpp
@ -143,11 +143,12 @@ FMD::FMD(
|
|||||||
lim_gain(0.0001), // 2.5
|
lim_gain(0.0001), // 2.5
|
||||||
lim_pre_gain(0.01) // 0.4
|
lim_pre_gain(0.01) // 0.4
|
||||||
{
|
{
|
||||||
float* impulse;
|
|
||||||
calc();
|
calc();
|
||||||
// de-emphasis filter
|
// de-emphasis filter
|
||||||
audio.resize(size * 2);
|
audio.resize(size * 2);
|
||||||
impulse = FCurve::fc_impulse (
|
std::vector<float> impulse(2 * nc_de);
|
||||||
|
FCurve::fc_impulse (
|
||||||
|
impulse,
|
||||||
nc_de,
|
nc_de,
|
||||||
(float) f_low,
|
(float) f_low,
|
||||||
(float) f_high,
|
(float) f_high,
|
||||||
@ -158,12 +159,10 @@ FMD::FMD(
|
|||||||
0,
|
0,
|
||||||
0
|
0
|
||||||
);
|
);
|
||||||
pde = new FIRCORE(size, audio.data(), out, nc_de, mp_de, impulse);
|
pde = new FIRCORE(size, audio.data(), out, nc_de, mp_de, impulse.data());
|
||||||
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));
|
float *impulseb = FIR::fir_bandpass(nc_aud, 0.8 * f_low, 1.1 * f_high, rate, 0, 1, afgain / (2.0 * size));
|
||||||
paud = new FIRCORE(size, out, out, nc_aud, mp_aud, impulse);
|
paud = new FIRCORE(size, out, out, nc_aud, mp_aud, impulseb);
|
||||||
delete[] impulse;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
FMD::~FMD()
|
FMD::~FMD()
|
||||||
@ -248,12 +247,13 @@ void FMD::setBuffers(float* _in, float* _out)
|
|||||||
|
|
||||||
void FMD::setSamplerate(int _rate)
|
void FMD::setSamplerate(int _rate)
|
||||||
{
|
{
|
||||||
float* impulse;
|
|
||||||
decalc();
|
decalc();
|
||||||
rate = _rate;
|
rate = _rate;
|
||||||
calc();
|
calc();
|
||||||
// de-emphasis filter
|
// de-emphasis filter
|
||||||
impulse = FCurve::fc_impulse (
|
std::vector<float> impulse(2 * nc_de);
|
||||||
|
FCurve::fc_impulse (
|
||||||
|
impulse,
|
||||||
nc_de,
|
nc_de,
|
||||||
(float) f_low,
|
(float) f_low,
|
||||||
(float) f_high,
|
(float) f_high,
|
||||||
@ -265,25 +265,25 @@ void FMD::setSamplerate(int _rate)
|
|||||||
0,
|
0,
|
||||||
0
|
0
|
||||||
);
|
);
|
||||||
pde->setImpulse(impulse, 1);
|
pde->setImpulse(impulse.data(), 1);
|
||||||
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));
|
float* impulseb = FIR::fir_bandpass(nc_aud, 0.8 * f_low, 1.1 * f_high, rate, 0, 1, afgain / (2.0 * size));
|
||||||
paud->setImpulse(impulse, 1);
|
paud->setImpulse(impulseb, 1);
|
||||||
delete[] impulse;
|
delete[] impulseb;
|
||||||
plim->setSamplerate((int) rate);
|
plim->setSamplerate((int) rate);
|
||||||
}
|
}
|
||||||
|
|
||||||
void FMD::setSize(int _size)
|
void FMD::setSize(int _size)
|
||||||
{
|
{
|
||||||
float* impulse;
|
|
||||||
decalc();
|
decalc();
|
||||||
size = _size;
|
size = _size;
|
||||||
calc();
|
calc();
|
||||||
audio.resize(size * 2);
|
audio.resize(size * 2);
|
||||||
// de-emphasis filter
|
// de-emphasis filter
|
||||||
delete (pde);
|
delete (pde);
|
||||||
impulse = FCurve::fc_impulse (
|
std::vector<float> impulse(2 * nc_de);
|
||||||
|
FCurve::fc_impulse (
|
||||||
|
impulse,
|
||||||
nc_de,
|
nc_de,
|
||||||
(float) f_low,
|
(float) f_low,
|
||||||
(float) f_high,
|
(float) f_high,
|
||||||
@ -295,13 +295,12 @@ void FMD::setSize(int _size)
|
|||||||
0,
|
0,
|
||||||
0
|
0
|
||||||
);
|
);
|
||||||
pde = new FIRCORE(size, audio.data(), out, nc_de, mp_de, impulse);
|
pde = new FIRCORE(size, audio.data(), out, nc_de, mp_de, impulse.data());
|
||||||
delete[] impulse;
|
|
||||||
// audio filter
|
// audio filter
|
||||||
delete (paud);
|
delete (paud);
|
||||||
impulse = FIR::fir_bandpass(nc_aud, 0.8 * f_low, 1.1 * f_high, rate, 0, 1, afgain / (2.0 * size));
|
float* impulseb = FIR::fir_bandpass(nc_aud, 0.8 * f_low, 1.1 * f_high, rate, 0, 1, afgain / (2.0 * size));
|
||||||
paud = new FIRCORE(size, out, out, nc_aud, mp_aud, impulse);
|
paud = new FIRCORE(size, out, out, nc_aud, mp_aud, impulseb);
|
||||||
delete[] impulse;
|
delete[] impulseb;
|
||||||
plim->setSize(size);
|
plim->setSize(size);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -331,12 +330,12 @@ void FMD::setCTCSSRun(int _run)
|
|||||||
|
|
||||||
void FMD::setNCde(int nc)
|
void FMD::setNCde(int nc)
|
||||||
{
|
{
|
||||||
float* impulse;
|
|
||||||
|
|
||||||
if (nc_de != nc)
|
if (nc_de != nc)
|
||||||
{
|
{
|
||||||
nc_de = nc;
|
nc_de = nc;
|
||||||
impulse = FCurve::fc_impulse (
|
std::vector<float> impulse(2 * nc_de);
|
||||||
|
FCurve::fc_impulse (
|
||||||
|
impulse,
|
||||||
nc_de,
|
nc_de,
|
||||||
(float) f_low,
|
(float) f_low,
|
||||||
(float) f_high,
|
(float) f_high,
|
||||||
@ -348,8 +347,7 @@ void FMD::setNCde(int nc)
|
|||||||
0,
|
0,
|
||||||
0
|
0
|
||||||
);
|
);
|
||||||
pde->setNc(nc_de, impulse);
|
pde->setNc(nc_de, impulse.data());
|
||||||
delete[] impulse;
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -405,14 +403,14 @@ void FMD::setLimGain(double gaindB)
|
|||||||
|
|
||||||
void FMD::setAFFilter(double low, double high)
|
void FMD::setAFFilter(double low, double high)
|
||||||
{
|
{
|
||||||
float* impulse;
|
|
||||||
|
|
||||||
if (f_low != low || f_high != high)
|
if (f_low != low || f_high != high)
|
||||||
{
|
{
|
||||||
f_low = low;
|
f_low = low;
|
||||||
f_high = high;
|
f_high = high;
|
||||||
// de-emphasis filter
|
// de-emphasis filter
|
||||||
impulse = FCurve::fc_impulse (
|
std::vector<float> impulse(2 * nc_de);
|
||||||
|
FCurve::fc_impulse (
|
||||||
|
impulse,
|
||||||
nc_de,
|
nc_de,
|
||||||
(float) f_low,
|
(float) f_low,
|
||||||
(float) f_high,
|
(float) f_high,
|
||||||
@ -424,12 +422,11 @@ void FMD::setAFFilter(double low, double high)
|
|||||||
0,
|
0,
|
||||||
0
|
0
|
||||||
);
|
);
|
||||||
pde->setImpulse(impulse, 1);
|
pde->setImpulse(impulse.data(), 1);
|
||||||
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));
|
float* impulseb = FIR::fir_bandpass (nc_aud, 0.8 * f_low, 1.1 * f_high, rate, 0, 1, afgain / (2.0 * size));
|
||||||
paud->setImpulse(impulse, 1);
|
paud->setImpulse(impulseb, 1);
|
||||||
delete[] impulse;
|
delete[] impulseb;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -36,7 +36,7 @@ void FMSQ::calc()
|
|||||||
{
|
{
|
||||||
double delta;
|
double delta;
|
||||||
double theta;
|
double theta;
|
||||||
float* impulse;
|
std::vector<float> impulse;
|
||||||
int i;
|
int i;
|
||||||
// noise filter
|
// noise filter
|
||||||
noise.resize(2 * size * 2);
|
noise.resize(2 * size * 2);
|
||||||
@ -48,9 +48,8 @@ void FMSQ::calc()
|
|||||||
G[1] = 0.0;
|
G[1] = 0.0;
|
||||||
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);
|
EQP::eq_impulse (impulse, nc, 3, F.data(), G.data(), rate, 1.0 / (2.0 * size), 0, 0);
|
||||||
p = new FIRCORE(size, trigger, noise.data(), nc, mp, impulse);
|
p = new FIRCORE(size, trigger, noise.data(), nc, mp, impulse.data());
|
||||||
delete[] impulse;
|
|
||||||
// noise averaging
|
// noise averaging
|
||||||
avm = exp(-1.0 / (rate * avtau));
|
avm = exp(-1.0 / (rate * avtau));
|
||||||
onem_avm = 1.0 - avm;
|
onem_avm = 1.0 - avm;
|
||||||
@ -286,14 +285,13 @@ void FMSQ::setThreshold(double threshold)
|
|||||||
|
|
||||||
void FMSQ::setNC(int _nc)
|
void FMSQ::setNC(int _nc)
|
||||||
{
|
{
|
||||||
float* impulse;
|
std::vector<float> impulse;
|
||||||
|
|
||||||
if (nc != _nc)
|
if (nc != _nc)
|
||||||
{
|
{
|
||||||
nc = _nc;
|
nc = _nc;
|
||||||
impulse = EQP::eq_impulse (nc, 3, F.data(), G.data(), rate, 1.0 / (2.0 * size), 0, 0);
|
EQP::eq_impulse (impulse, nc, 3, F.data(), G.data(), rate, 1.0 / (2.0 * size), 0, 0);
|
||||||
p->setNc(nc, impulse);
|
p->setNc(nc, impulse.data());
|
||||||
delete[] impulse;
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -34,11 +34,10 @@ namespace WDSP {
|
|||||||
|
|
||||||
void ICFIR::calc_icfir (ICFIR *a)
|
void ICFIR::calc_icfir (ICFIR *a)
|
||||||
{
|
{
|
||||||
float* impulse;
|
std::vector<float> impulse;
|
||||||
a->scale = 1.0f / (float)(2 * a->size);
|
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);
|
icfir_impulse (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);
|
a->p = new FIRCORE(a->size, a->in, a->out, a->nc, a->mp, impulse.data());
|
||||||
delete[] (impulse);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void ICFIR::decalc_icfir (ICFIR *a)
|
void ICFIR::decalc_icfir (ICFIR *a)
|
||||||
@ -145,7 +144,8 @@ void ICFIR::setOutRate_icfir (ICFIR *a, int rate)
|
|||||||
calc_icfir (a);
|
calc_icfir (a);
|
||||||
}
|
}
|
||||||
|
|
||||||
float* ICFIR::icfir_impulse (
|
void ICFIR::icfir_impulse (
|
||||||
|
std::vector<float>& impulse,
|
||||||
int N,
|
int N,
|
||||||
int DD,
|
int DD,
|
||||||
int R,
|
int R,
|
||||||
@ -178,7 +178,6 @@ float* ICFIR::icfir_impulse (
|
|||||||
float ri;
|
float ri;
|
||||||
float mag;
|
float mag;
|
||||||
float fn;
|
float fn;
|
||||||
float* impulse;
|
|
||||||
auto* A = new float[N];
|
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
|
||||||
@ -239,10 +238,10 @@ float* ICFIR::icfir_impulse (
|
|||||||
else
|
else
|
||||||
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.resize(2 * N);
|
||||||
|
FIR::fir_fsamp (impulse, N, A, rtype, 1.0, wintype);
|
||||||
delete[] (A);
|
delete[] (A);
|
||||||
delete[] xistion;
|
delete[] xistion;
|
||||||
return impulse;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
@ -79,7 +79,8 @@ public:
|
|||||||
static void setSamplerate_icfir (ICFIR *a, int rate);
|
static void setSamplerate_icfir (ICFIR *a, int rate);
|
||||||
static void setSize_icfir (ICFIR *a, int size);
|
static void setSize_icfir (ICFIR *a, int size);
|
||||||
static void setOutRate_icfir (ICFIR *a, int rate);
|
static void setOutRate_icfir (ICFIR *a, int rate);
|
||||||
static float* icfir_impulse (
|
static void icfir_impulse (
|
||||||
|
std::vector<float>& impulse,
|
||||||
int N,
|
int N,
|
||||||
int DD,
|
int DD,
|
||||||
int R,
|
int R,
|
||||||
|
Loading…
Reference in New Issue
Block a user