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