WDSP: impulse responses refactoring (2)

pull/2222/head
f4exb 2024-08-09 06:33:00 +02:00
rodzic 62f05b3706
commit 7319e4cb88
10 zmienionych plików z 23 dodań i 30 usunięć

Wyświetl plik

@ -1040,9 +1040,8 @@ void TXA::SetBPSFreqs (TXA& txa, double _f_low, double _f_high)
{
a->f_low = _f_low;
a->f_high = _f_high;
delete[] (a->mults);
impulse = FIR::fir_bandpass(a->size + 1, _f_low, _f_high, a->samplerate, a->wintype, 1, 1.0 / (float)(2 * a->size));
a->mults = FIR::fftcv_mults (2 * a->size, impulse);
FIR::fftcv_mults (a->mults, 2 * a->size, impulse);
delete[] (impulse);
}
@ -1052,9 +1051,8 @@ void TXA::SetBPSFreqs (TXA& txa, double _f_low, double _f_high)
{
a->f_low = _f_low;
a->f_high = _f_high;
delete[] (a->mults);
impulse = FIR::fir_bandpass(a->size + 1, _f_low, _f_high, a->samplerate, a->wintype, 1, 1.0 / (float)(2 * a->size));
a->mults = FIR::fftcv_mults (2 * a->size, impulse);
FIR::fftcv_mults (a->mults, 2 * a->size, impulse);
delete[] (impulse);
}
@ -1064,9 +1062,8 @@ void TXA::SetBPSFreqs (TXA& txa, double _f_low, double _f_high)
{
a->f_low = _f_low;
a->f_high = _f_high;
delete[] (a->mults);
impulse = FIR::fir_bandpass(a->size + 1, _f_low, _f_high, a->samplerate, a->wintype, 1, 1.0 / (float)(2 * a->size));
a->mults = FIR::fftcv_mults (2 * a->size, impulse);
FIR::fftcv_mults (a->mults, 2 * a->size, impulse);
delete[] (impulse);
}
}
@ -1080,9 +1077,8 @@ void TXA::SetBPSWindow (TXA& txa, int _wintype)
if (a->wintype != _wintype)
{
a->wintype = _wintype;
delete[] (a->mults);
impulse = FIR::fir_bandpass(a->size + 1, a->f_low, a->f_high, a->samplerate, a->wintype, 1, 1.0 / (float)(2 * a->size));
a->mults = FIR::fftcv_mults (2 * a->size, impulse);
FIR::fftcv_mults (a->mults, 2 * a->size, impulse);
delete[] (impulse);
}
@ -1091,9 +1087,8 @@ void TXA::SetBPSWindow (TXA& txa, int _wintype)
if (a->wintype != _wintype)
{
a->wintype = _wintype;
delete[] (a->mults);
impulse = FIR::fir_bandpass(a->size + 1, a->f_low, a->f_high, a->samplerate, a->wintype, 1, 1.0 / (float)(2 * a->size));
a->mults = FIR::fftcv_mults (2 * a->size, impulse);
FIR::fftcv_mults (a->mults, 2 * a->size, impulse);
delete[] impulse;
}
@ -1102,9 +1097,8 @@ void TXA::SetBPSWindow (TXA& txa, int _wintype)
if (a->wintype != _wintype)
{
a->wintype = _wintype;
delete[] (a->mults);
impulse = FIR::fir_bandpass (a->size + 1, a->f_low, a->f_high, a->samplerate, a->wintype, 1, 1.0 / (float)(2 * a->size));
a->mults = FIR::fftcv_mults (2 * a->size, impulse);
FIR::fftcv_mults (a->mults, 2 * a->size, impulse);
delete[] impulse;
}
}

Wyświetl plik

@ -46,7 +46,7 @@ void BPS::calc()
infilt.resize(2 * size * 2);
product.resize(2 * size * 2);
impulse = FIR::fir_bandpass(size + 1, f_low, f_high, samplerate, wintype, 1, 1.0 / (float)(2 * size));
mults = FIR::fftcv_mults(2 * size, impulse);
FIR::fftcv_mults(mults, 2 * size, impulse);
CFor = fftwf_plan_dft_1d(2 * size, (fftwf_complex *) infilt.data(), (fftwf_complex *) product.data(), FFTW_FORWARD, FFTW_PATIENT);
CRev = fftwf_plan_dft_1d(2 * size, (fftwf_complex *) product.data(), (fftwf_complex *) out, FFTW_BACKWARD, FFTW_PATIENT);
delete[]impulse;
@ -56,7 +56,6 @@ void BPS::decalc()
{
fftwf_destroy_plan(CRev);
fftwf_destroy_plan(CFor);
delete[] mults;
}
BPS::BPS(

Wyświetl plik

@ -56,7 +56,7 @@ public:
double f_high;
std::vector<float> infilt;
std::vector<float> product;
float* mults;
std::vector<float> mults;
double samplerate;
int wintype;
double gain;

Wyświetl plik

@ -43,7 +43,8 @@ void EMPH::calc()
{
infilt = new float[2 * size * 2];
product = new float[2 * size * 2];
mults = FCurve::fc_mults(
FCurve::fc_mults(
mults,
size,
f_low,
f_high,
@ -63,7 +64,6 @@ void EMPH::decalc()
{
fftwf_destroy_plan(CRev);
fftwf_destroy_plan(CFor);
delete[] mults;
delete[] product;
delete[] infilt;
}

Wyświetl plik

@ -34,6 +34,8 @@ warren@wpratt.com
#ifndef _emph_h
#define _emph_h
#include <vector>
#include "fftw3.h"
#include "export.h"
@ -52,7 +54,7 @@ public:
double f_high;
float* infilt;
float* product;
float* mults;
std::vector<float> mults;
double rate;
fftwf_plan CFor;
fftwf_plan CRev;

Wyświetl plik

@ -46,10 +46,10 @@ void EQ::eq_mults (std::vector<float>& mults, int size, int nfreqs, float* F, fl
{
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());
std::vector<float> _mults;
FIR::fftcv_mults(_mults, 2 * size, impulse.data());
mults.resize(2 * size * 2);
std::copy(_mults, _mults + 2*size*2, mults.begin());
delete[] _mults;
std::copy(_mults.begin(), _mults.end(), mults.begin());
}
void EQ::calc()

Wyświetl plik

@ -149,12 +149,11 @@ void FCurve::fc_impulse (std::vector<float>& impulse, int nc, float f0, float f1
}
// 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 (std::vector<float>& mults, int size, float f0, float f1, float g0, float g1, int curve, float samplerate, float scale, int ctfmode, int wintype)
{
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;
FIR::fftcv_mults(mults, 2 * size, impulse.data());
}
} // namespace WDSP

Wyświetl plik

@ -38,7 +38,7 @@ class WDSP_API FCurve
{
public:
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 (std::vector<float>& mults, int size, float f0, float f1, float g0, float g1, int curve, float samplerate, float scale, int ctfmode, int wintype);
};
} // namespace WDSP

Wyświetl plik

@ -35,14 +35,14 @@ warren@pratt.one
namespace WDSP {
float* FIR::fftcv_mults (int NM, float* c_impulse)
void FIR::fftcv_mults (std::vector<float>& mults, int NM, float* c_impulse)
{
auto mults = new float[NM * 2];
mults.resize(NM * 2);
std::vector<float> cfft_impulse(NM * 2);
fftwf_plan ptmp = fftwf_plan_dft_1d(
NM,
(fftwf_complex *) cfft_impulse.data(),
(fftwf_complex *) mults,
(fftwf_complex *) mults.data(),
FFTW_FORWARD,
FFTW_PATIENT
);
@ -51,7 +51,6 @@ float* FIR::fftcv_mults (int NM, float* c_impulse)
std::copy(c_impulse, c_impulse + (NM / 2 + 1) * 2, &(cfft_impulse[NM - 2]));
fftwf_execute (ptmp);
fftwf_destroy_plan (ptmp);
return mults;
}
float* FIR::get_fsamp_window(int N, int wintype)

Wyświetl plik

@ -36,7 +36,7 @@ namespace WDSP {
class WDSP_API FIR
{
public:
static float* fftcv_mults (int NM, float* c_impulse);
static void fftcv_mults (std::vector<float>& mults, int NM, float* c_impulse);
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);