1
0
mirror of https://github.com/f4exb/sdrangel.git synced 2024-11-21 23:55:13 -05:00

WDSP: Sonar lint fixes (2)

This commit is contained in:
f4exb 2024-08-03 11:05:12 +02:00
parent 8941835466
commit d6159067a8
37 changed files with 1091 additions and 1183 deletions

1
.gitignore vendored
View File

@ -28,6 +28,7 @@ obj-x86_64-linux-gnu/*
**/venv*/ **/venv*/
*.pyc *.pyc
.DS_Store .DS_Store
.sonarlint
### Go ### ### Go ###
# Binaries for programs and plugins # Binaries for programs and plugins

View File

@ -25,6 +25,8 @@ warren@wpratt.com
*/ */
#include <cstdio>
#include "comm.hpp" #include "comm.hpp"
#include "amsq.hpp" #include "amsq.hpp"
@ -174,7 +176,7 @@ void AMSQ::execute()
} }
else if (count-- == 0) else if (count-- == 0)
{ {
state = AMSQState::TAIL; state = AMSQState::DECREASE;
count = ntdown; count = ntdown;
} }

View File

@ -42,332 +42,124 @@ namespace WDSP {
********************************************************************************************************/ ********************************************************************************************************/
float* EQ::eq_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); float* impulse = EQP::eq_impulse (size + 1, nfreqs, F, G, samplerate, scale, ctfmode, wintype);
float* mults = FIR::fftcv_mults(2 * size, impulse); float* _mults = FIR::fftcv_mults(2 * size, impulse);
delete[] (impulse); mults.resize(2 * size * 2);
return mults; std::copy(_mults, _mults + 2*size*2, mults.begin());
delete[] _mults;
delete[] impulse;
} }
void EQ::calc_eq (EQ *a) void EQ::calc()
{ {
a->scale = 1.0 / (float)(2 * a->size); scale = (float) (1.0 / (float)(2 * size));
a->infilt = new float[2 * a->size * 2]; // (float *)malloc0(2 * a->size * sizeof(complex)); infilt.resize(2 * size * 2);
a->product = new float[2 * a->size * 2]; // (float *)malloc0(2 * a->size * sizeof(complex)); product.resize(2 * size * 2);
a->CFor = fftwf_plan_dft_1d(2 * a->size, (fftwf_complex *)a->infilt, (fftwf_complex *)a->product, FFTW_FORWARD, FFTW_PATIENT); CFor = fftwf_plan_dft_1d(
a->CRev = fftwf_plan_dft_1d(2 * a->size, (fftwf_complex *)a->product, (fftwf_complex *)a->out, FFTW_BACKWARD, FFTW_PATIENT); 2 * size,
a->mults = EQ::eq_mults(a->size, a->nfreqs, a->F, a->G, a->samplerate, a->scale, a->ctfmode, a->wintype); (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
);
EQ::eq_mults(mults, size, nfreqs, F.data(), G.data(), samplerate, scale, ctfmode, wintype);
} }
void EQ::decalc_eq (EQ *a) void EQ::decalc()
{ {
fftwf_destroy_plan(a->CRev); fftwf_destroy_plan(CRev);
fftwf_destroy_plan(a->CFor); fftwf_destroy_plan(CFor);
delete[] (a->mults);
delete[] (a->product);
delete[] (a->infilt);
} }
EQ* EQ::create_eq (int run, int size, float *in, float *out, int nfreqs, float* F, float* G, int ctfmode, int wintype, int samplerate) EQ::EQ(
int _run,
int _size,
float *_in,
float *_out,
int _nfreqs,
const float* _F,
const float* _G,
int _ctfmode,
int _wintype,
int _samplerate
) :
run(_run),
size(_size),
in(_in),
out(_out),
nfreqs(_nfreqs),
ctfmode(_ctfmode),
wintype(_wintype),
samplerate((float) _samplerate)
{ {
EQ *a = new EQ; F.resize(nfreqs + 1);
a->run = run; G.resize(nfreqs + 1);
a->size = size; std::copy(_F, _F + nfreqs + 1, F.begin());
a->in = in; std::copy(_G, _G + nfreqs + 1, G.begin());
a->out = out; calc();
a->nfreqs = nfreqs;
a->F = new float[a->nfreqs + 1]; // (float *) malloc0 ((a->nfreqs + 1) * sizeof (float));
a->G = new float[a->nfreqs + 1]; // (float *) malloc0 ((a->nfreqs + 1) * sizeof (float));
memcpy (a->F, F, (nfreqs + 1) * sizeof (float));
memcpy (a->G, G, (nfreqs + 1) * sizeof (float));
a->ctfmode = ctfmode;
a->wintype = wintype;
a->samplerate = (float)samplerate;
calc_eq (a);
return a;
} }
void EQ::destroy_eq (EQ *a) EQ::~EQ()
{ {
decalc_eq (a); decalc();
delete[] (a->G);
delete[] (a->F);
delete[] (a);
} }
void EQ::flush_eq (EQ *a) void EQ::flush()
{ {
std::fill(a->infilt, a->infilt + 2 * a->size * 2, 0); std::fill(infilt.begin(), infilt.end(), 0);
} }
void EQ::xeq (EQ *a) void EQ::execute()
{ {
int i; float I;
float I, Q; float Q;
if (a->run) if (run)
{ {
std::copy(a->in, a->in + a->size * 2, &(a->infilt[2 * a->size])); std::copy(in, in + size * 2, &(infilt[2 * size]));
fftwf_execute (a->CFor); fftwf_execute (CFor);
for (i = 0; i < 2 * a->size; i++) for (int i = 0; i < 2 * size; i++)
{ {
I = a->product[2 * i + 0]; I = product[2 * i + 0];
Q = a->product[2 * i + 1]; Q = product[2 * i + 1];
a->product[2 * i + 0] = I * a->mults[2 * i + 0] - Q * a->mults[2 * i + 1]; product[2 * i + 0] = I * mults[2 * i + 0] - Q * mults[2 * i + 1];
a->product[2 * i + 1] = I * a->mults[2 * i + 1] + Q * a->mults[2 * i + 0]; product[2 * i + 1] = I * mults[2 * i + 1] + Q * mults[2 * i + 0];
} }
fftwf_execute (a->CRev); fftwf_execute (CRev);
std::copy(&(a->infilt[2 * a->size]), &(a->infilt[2 * a->size]) + a->size * 2, a->infilt); std::copy(&(infilt[2 * size]), &(infilt[2 * size]) + size * 2, infilt);
} }
else if (a->in != a->out) else if (in != out)
std::copy( a->in, a->in + a->size * 2, a->out); std::copy( in, in + size * 2, out);
} }
void EQ::setBuffers_eq (EQ *a, float* in, float* out) void EQ::setBuffers(float* _in, float* _out)
{ {
decalc_eq (a); decalc();
a->in = in; in = _in;
a->out = out; out = _out;
calc_eq (a); calc();
} }
void EQ::setSamplerate_eq (EQ *a, int rate) void EQ::setSamplerate(int _rate)
{ {
decalc_eq (a); decalc();
a->samplerate = rate; samplerate = (float) _rate;
calc_eq (a); calc();
} }
void EQ::setSize_eq (EQ *a, int size) void EQ::setSize(int _size)
{ {
decalc_eq (a); decalc();
a->size = size; size = _size;
calc_eq (a); calc();
} }
/********************************************************************************************************
* *
* Overlap-Save Equalizer: RXA Properties *
* *
********************************************************************************************************/
/* // UNCOMMENT properties when a pointer is in place in rxa
PORT
void SetRXAEQRun (int channel, int run)
{
ch.csDSP.lock();
rxa.eq->run = run;
ch.csDSP.unlock();
}
PORT
void SetRXAEQProfile (int channel, int nfreqs, float* F, float* G)
{
EQ a;
ch.csDSP.lock();
a = rxa.eq;
delete[] (a->G);
delete[] (a->F);
a->nfreqs = nfreqs;
a->F = (float *) malloc0 ((a->nfreqs + 1) * sizeof (float));
a->G = (float *) malloc0 ((a->nfreqs + 1) * sizeof (float));
memcpy (a->F, F, (nfreqs + 1) * sizeof (float));
memcpy (a->G, G, (nfreqs + 1) * sizeof (float));
delete[] (a->mults);
a->mults = eq_mults (a->size, a->nfreqs, a->F, a->G, a->samplerate, a->scale, a->ctfmode, a->wintype);
ch.csDSP.unlock();
}
PORT
void SetRXAEQCtfmode (int channel, int mode)
{
EQ a;
ch.csDSP.lock();
a = rxa.eq;
a->ctfmode = mode;
delete[] (a->mults);
a->mults = eq_mults (a->size, a->nfreqs, a->F, a->G, a->samplerate, a->scale, a->ctfmode, a->wintype);
ch.csDSP.unlock();
}
PORT
void SetRXAEQWintype (int channel, int wintype)
{
EQ a;
ch.csDSP.lock();
a = rxa.eq;
a->wintype = wintype;
delete[] (a->mults);
a->mults = eq_mults (a->size, a->nfreqs, a->F, a->G, a->samplerate, a->scale, a->ctfmode, a->wintype);
ch.csDSP.unlock();
}
PORT
void SetRXAGrphEQ (int channel, int *rxeq)
{ // three band equalizer (legacy compatibility)
EQ a;
ch.csDSP.lock();
a = rxa.eq;
delete[] (a->G);
delete[] (a->F);
a->nfreqs = 4;
a->F = (float *) malloc0 ((a->nfreqs + 1) * sizeof (float));
a->G = (float *) malloc0 ((a->nfreqs + 1) * sizeof (float));
a->F[1] = 150.0;
a->F[2] = 400.0;
a->F[3] = 1500.0;
a->F[4] = 6000.0;
a->G[0] = (float)rxeq[0];
a->G[1] = (float)rxeq[1];
a->G[2] = (float)rxeq[1];
a->G[3] = (float)rxeq[2];
a->G[4] = (float)rxeq[3];
a->ctfmode = 0;
delete[] (a->mults);
a->mults = eq_mults (a->size, a->nfreqs, a->F, a->G, a->samplerate, a->scale, a->ctfmode, a->wintype);
ch.csDSP.unlock();
}
PORT
void SetRXAGrphEQ10 (int channel, int *rxeq)
{ // ten band equalizer (legacy compatibility)
EQ a;
int i;
ch.csDSP.lock();
a = rxa.eq;
delete[] (a->G);
delete[] (a->F);
a->nfreqs = 10;
a->F = (float *) malloc0 ((a->nfreqs + 1) * sizeof (float));
a->G = (float *) malloc0 ((a->nfreqs + 1) * sizeof (float));
a->F[1] = 32.0;
a->F[2] = 63.0;
a->F[3] = 125.0;
a->F[4] = 250.0;
a->F[5] = 500.0;
a->F[6] = 1000.0;
a->F[7] = 2000.0;
a->F[8] = 4000.0;
a->F[9] = 8000.0;
a->F[10] = 16000.0;
for (i = 0; i <= a->nfreqs; i++)
a->G[i] = (float)rxeq[i];
a->ctfmode = 0;
delete[] (a->mults);
a->mults = eq_mults (a->size, a->nfreqs, a->F, a->G, a->samplerate, a->scale, a->ctfmode, a->wintype);
ch.csDSP.unlock();
}
*/
/********************************************************************************************************
* *
* Overlap-Save Equalizer: TXA Properties *
* *
********************************************************************************************************/
/* // UNCOMMENT properties when a pointer is in place in rxa
PORT
void SetTXAEQRun (int channel, int run)
{
ch.csDSP.lock();
txa.eq->run = run;
ch.csDSP.unlock();
}
PORT
void SetTXAEQProfile (int channel, int nfreqs, float* F, float* G)
{
EQ a;
ch.csDSP.lock();
a = txa.eq;
delete[] (a->G);
delete[] (a->F);
a->nfreqs = nfreqs;
a->F = (float *) malloc0 ((a->nfreqs + 1) * sizeof (float));
a->G = (float *) malloc0 ((a->nfreqs + 1) * sizeof (float));
memcpy (a->F, F, (nfreqs + 1) * sizeof (float));
memcpy (a->G, G, (nfreqs + 1) * sizeof (float));
delete[] (a->mults);
a->mults = eq_mults (a->size, a->nfreqs, a->F, a->G, a->samplerate, a->scale, a->ctfmode, a->wintype);
ch.csDSP.unlock();
}
PORT
void SetTXAEQCtfmode (int channel, int mode)
{
EQ a;
ch.csDSP.lock();
a = txa.eq;
a->ctfmode = mode;
delete[] (a->mults);
a->mults = eq_mults (a->size, a->nfreqs, a->F, a->G, a->samplerate, a->scale, a->ctfmode, a->wintype);
ch.csDSP.unlock();
}
PORT
void SetTXAEQMethod (int channel, int wintype)
{
EQ a;
ch.csDSP.lock();
a = txa.eq;
a->wintype = wintype;
delete[] (a->mults);
a->mults = eq_mults (a->size, a->nfreqs, a->F, a->G, a->samplerate, a->scale, a->ctfmode, a->wintype);
ch.csDSP.unlock();
}
PORT
void SetTXAGrphEQ (int channel, int *txeq)
{ // three band equalizer (legacy compatibility)
EQ a;
ch.csDSP.lock();
a = txa.eq;
delete[] (a->G);
delete[] (a->F);
a->nfreqs = 4;
a->F = (float *) malloc0 ((a->nfreqs + 1) * sizeof (float));
a->G = (float *) malloc0 ((a->nfreqs + 1) * sizeof (float));
a->F[1] = 150.0;
a->F[2] = 400.0;
a->F[3] = 1500.0;
a->F[4] = 6000.0;
a->G[0] = (float)txeq[0];
a->G[1] = (float)txeq[1];
a->G[2] = (float)txeq[1];
a->G[3] = (float)txeq[2];
a->G[4] = (float)txeq[3];
a->ctfmode = 0;
delete[] (a->mults);
a->mults = eq_mults (a->size, a->nfreqs, a->F, a->G, a->samplerate, a->scale, a->ctfmode, a->wintype);
ch.csDSP.unlock();
}
PORT
void SetTXAGrphEQ10 (int channel, int *txeq)
{ // ten band equalizer (legacy compatibility)
EQ a;
int i;
ch.csDSP.lock();
a = txa.eq;
delete[] (a->G);
delete[] (a->F);
a->nfreqs = 10;
a->F = (float *) malloc0 ((a->nfreqs + 1) * sizeof (float));
a->G = (float *) malloc0 ((a->nfreqs + 1) * sizeof (float));
a->F[1] = 32.0;
a->F[2] = 63.0;
a->F[3] = 125.0;
a->F[4] = 250.0;
a->F[5] = 500.0;
a->F[6] = 1000.0;
a->F[7] = 2000.0;
a->F[8] = 4000.0;
a->F[9] = 8000.0;
a->F[10] = 16000.0;
for (i = 0; i <= a->nfreqs; i++)
a->G[i] = (float)txeq[i];
a->ctfmode = 0;
delete[] (a->mults);
a->mults = eq_mults (a->size, a->nfreqs, a->F, a->G, a->samplerate, a->scale, a->ctfmode, a->wintype);
ch.csDSP.unlock();
}
*/
} // namespace WDSP } // namespace WDSP

View File

@ -34,6 +34,8 @@ warren@wpratt.com
#ifndef wdsp_eq_h #ifndef wdsp_eq_h
#define wdsp_eq_h #define wdsp_eq_h
#include <vector>
#include "fftw3.h" #include "fftw3.h"
#include "export.h" #include "export.h"
@ -47,11 +49,11 @@ public:
float* in; float* in;
float* out; float* out;
int nfreqs; int nfreqs;
float* F; std::vector<float> F;
float* G; std::vector<float> G;
float* infilt; std::vector<float> infilt;
float* product; std::vector<float> product;
float* mults; std::vector<float> mults;
float scale; float scale;
int ctfmode; int ctfmode;
int wintype; int wintype;
@ -59,19 +61,32 @@ public:
fftwf_plan CFor; fftwf_plan CFor;
fftwf_plan CRev; fftwf_plan CRev;
static EQ* create_eq (int run, int size, float *in, float *out, int nfreqs, float* F, float* G, int ctfmode, int wintype, int samplerate); EQ(
// static float* eq_mults (int size, int nfreqs, float* F, float* G, float samplerate, float scale, int ctfmode, int wintype); int run,
static void destroy_eq (EQ *a); int size,
static void flush_eq (EQ *a); float *in,
static void xeq (EQ *a); float *out,
static void setBuffers_eq (EQ *a, float* in, float* out); int nfreqs,
static void setSamplerate_eq (EQ *a, int rate); const float* F,
static void setSize_eq (EQ *a, int size); const float* G,
int ctfmode,
int wintype,
int samplerate
);
EQ(const EQ&) = delete;
EQ& operator=(EQ& other) = delete;
~EQ() = default;
void flush();
void execute();
void setBuffers(float* in, float* out);
void setSamplerate(int rate);
void setSize(int size);
private: private:
static float* eq_mults (int size, int nfreqs, float* F, float* G, float samplerate, float scale, int ctfmode, int wintype); static void eq_mults (std::vector<float>& mults, int size, int nfreqs, float* F, float* G, float samplerate, float scale, int ctfmode, int wintype);
static void calc_eq (EQ *a); void calc();
static void decalc_eq (EQ *a); void decalc();
}; };
} // namespace WDSP } // namespace WDSP

View File

@ -42,22 +42,27 @@ int EQP::fEQcompare (const void * a, const void * b)
return 1; return 1;
} }
float* EQP::eq_impulse (int N, int nfreqs, float* F, float* G, double samplerate, double scale, int ctfmode, int wintype) float* EQP::eq_impulse (int N, int nfreqs, const float* F, const float* G, double samplerate, double scale, int ctfmode, int wintype)
{ {
float* fp = new float[nfreqs + 2]; // (float *) malloc0 ((nfreqs + 2) * sizeof (float)); std::vector<float> fp(nfreqs + 2);
float* gp = new float[nfreqs + 2]; // (float *) malloc0 ((nfreqs + 2) * sizeof (float)); std::vector<float> gp(nfreqs + 2);
float* A = new float[N / 2 + 1]; // (float *) malloc0 ((N / 2 + 1) * sizeof (float)); std::vector<float> A(N / 2 + 1);
float* sary = new float[2 * nfreqs]; // (float *) malloc0 (2 * nfreqs * sizeof (float)); float* sary = new float[2 * nfreqs];
double gpreamp, f, frac;
double gpreamp;
double f;
double frac;
float* impulse; float* impulse;
int i, j, mid; int i;
int j;
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] = 2.0 * F[i] / samplerate; fp[i] = (float) (2.0 * F[i] / samplerate);
if (fp[i] < 0.0) if (fp[i] < 0.0)
fp[i] = 0.0; fp[i] = 0.0;
@ -97,7 +102,7 @@ float* EQP::eq_impulse (int N, int nfreqs, float* F, float* G, double samplerate
j++; j++;
frac = (f - fp[j]) / (fp[j + 1] - fp[j]); frac = (f - fp[j]) / (fp[j + 1] - fp[j]);
A[i] = pow (10.0, 0.05 * (frac * gp[j + 1] + (1.0 - frac) * gp[j] + gpreamp)) * scale; A[i] = (float) (pow (10.0, 0.05 * (frac * gp[j + 1] + (1.0 - frac) * gp[j] + gpreamp)) * scale);
} }
} }
else else
@ -110,14 +115,19 @@ float* EQP::eq_impulse (int N, int nfreqs, float* F, float* G, double samplerate
j++; j++;
frac = (f - fp[j]) / (fp[j + 1] - fp[j]); frac = (f - fp[j]) / (fp[j + 1] - fp[j]);
A[i] = pow (10.0, 0.05 * (frac * gp[j + 1] + (1.0 - frac) * gp[j] + gpreamp)) * scale; A[i] = (float) (pow (10.0, 0.05 * (frac * gp[j + 1] + (1.0 - frac) * gp[j] + gpreamp)) * scale);
} }
} }
if (ctfmode == 0) if (ctfmode == 0)
{ {
int k, low, high; int k;
double lowmag, highmag, flow4, fhigh4; int low;
int high;
double lowmag;
double highmag;
double flow4;
double fhigh4;
if (N & 1) if (N & 1)
{ {
@ -134,7 +144,7 @@ float* EQP::eq_impulse (int N, int nfreqs, float* F, float* G, double samplerate
f = (double)k / (double)mid; f = (double)k / (double)mid;
lowmag *= (f * f * f * f) / flow4; lowmag *= (f * f * f * f) / flow4;
if (lowmag < 1.0e-20) lowmag = 1.0e-20; if (lowmag < 1.0e-20) lowmag = 1.0e-20;
A[k] = lowmag; A[k] = (float) lowmag;
} }
k = high; k = high;
@ -144,7 +154,7 @@ float* EQP::eq_impulse (int N, int nfreqs, float* F, float* G, double samplerate
f = (double)k / (double)mid; f = (double)k / (double)mid;
highmag *= fhigh4 / (f * f * f * f); highmag *= fhigh4 / (f * f * f * f);
if (highmag < 1.0e-20) highmag = 1.0e-20; if (highmag < 1.0e-20) highmag = 1.0e-20;
A[k] = highmag; A[k] = (float) highmag;
} }
} }
else else
@ -162,7 +172,7 @@ float* EQP::eq_impulse (int N, int nfreqs, float* F, float* G, double samplerate
f = (double)k / (double)mid; f = (double)k / (double)mid;
lowmag *= (f * f * f * f) / flow4; lowmag *= (f * f * f * f) / flow4;
if (lowmag < 1.0e-20) lowmag = 1.0e-20; if (lowmag < 1.0e-20) lowmag = 1.0e-20;
A[k] = lowmag; A[k] = (float) lowmag;
} }
k = high; k = high;
@ -172,21 +182,17 @@ float* EQP::eq_impulse (int N, int nfreqs, float* F, float* G, double samplerate
f = (double)k / (double)mid; f = (double)k / (double)mid;
highmag *= fhigh4 / (f * f * f * f); highmag *= fhigh4 / (f * f * f * f);
if (highmag < 1.0e-20) highmag = 1.0e-20; if (highmag < 1.0e-20) highmag = 1.0e-20;
A[k] = highmag; A[k] = (float) highmag;
} }
} }
} }
if (N & 1) if (N & 1)
impulse = FIR::fir_fsamp_odd(N, A, 1, 1.0, wintype); impulse = FIR::fir_fsamp_odd(N, A.data(), 1, 1.0, wintype);
else else
impulse = FIR::fir_fsamp(N, A, 1, 1.0, wintype); impulse = FIR::fir_fsamp(N, A.data(), 1, 1.0, wintype);
// print_impulse("eq.txt", N, impulse, 1, 0); delete[] sary;
delete[] (sary);
delete[] (A);
delete[] (gp);
delete[] (fp);
return impulse; return impulse;
} }
@ -220,8 +226,8 @@ EQP::EQP(
in = _in; in = _in;
out = _out; out = _out;
nfreqs = _nfreqs; nfreqs = _nfreqs;
F.resize(nfreqs + 1); // (float *) malloc0 ((nfreqs + 1) * sizeof (float)); F.resize(nfreqs + 1);
G.resize(nfreqs + 1); // (float *) malloc0 ((nfreqs + 1) * sizeof (float)); 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());
ctfmode = _ctfmode; ctfmode = _ctfmode;
@ -229,7 +235,7 @@ EQP::EQP(
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 = FIRCORE::create_fircore (size, in, out, nc, mp, impulse);
delete[] (impulse); delete[] impulse;
} }
EQP::~EQP() EQP::~EQP()
@ -263,7 +269,7 @@ void EQP::setSamplerate(int rate)
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_fircore (fircore, impulse, 1);
delete[] (impulse); delete[] impulse;
} }
void EQP::setSize(int _size) void EQP::setSize(int _size)
@ -273,7 +279,7 @@ void EQP::setSize(int _size)
FIRCORE::setSize_fircore (fircore, size); FIRCORE::setSize_fircore (fircore, 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_fircore (fircore, impulse, 1);
delete[] (impulse); delete[] impulse;
} }
/******************************************************************************************************** /********************************************************************************************************
@ -296,7 +302,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_fircore (fircore, nc, impulse);
delete[] (impulse); delete[] impulse;
} }
} }
@ -313,13 +319,13 @@ void EQP::setProfile(int _nfreqs, const float* _F, const float* _G)
{ {
float* impulse; float* impulse;
nfreqs = _nfreqs; nfreqs = _nfreqs;
F.resize(nfreqs + 1); // (float *) malloc0 ((nfreqs + 1) * sizeof (float)); F.resize(nfreqs + 1);
G.resize(nfreqs + 1); // (float *) malloc0 ((nfreqs + 1) * sizeof (float)); 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); 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_fircore (fircore, impulse, 1);
delete[] (impulse); delete[] impulse;
} }
void EQP::setCtfmode(int _mode) void EQP::setCtfmode(int _mode)
@ -328,7 +334,7 @@ void EQP::setCtfmode(int _mode)
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_fircore (fircore, impulse, 1);
delete[] (impulse); delete[] impulse;
} }
void EQP::setWintype(int _wintype) void EQP::setWintype(int _wintype)
@ -337,15 +343,15 @@ void EQP::setWintype(int _wintype)
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_fircore (fircore, impulse, 1);
delete[] (impulse); delete[] impulse;
} }
void EQP::setGrphEQ(int *rxeq) void EQP::setGrphEQ(const int *rxeq)
{ // three band equalizer (legacy compatibility) { // three band equalizer (legacy compatibility)
float* impulse; float* impulse;
nfreqs = 4; nfreqs = 4;
F.resize(nfreqs + 1); // (float *) malloc0 ((nfreqs + 1) * sizeof (float)); F.resize(nfreqs + 1);
G.resize(nfreqs + 1); // (float *) malloc0 ((nfreqs + 1) * sizeof (float)); G.resize(nfreqs + 1);
F[1] = 150.0; F[1] = 150.0;
F[2] = 400.0; F[2] = 400.0;
F[3] = 1500.0; F[3] = 1500.0;
@ -358,16 +364,15 @@ void EQP::setGrphEQ(int *rxeq)
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_fircore (fircore, impulse, 1);
delete[] (impulse); delete[] impulse;
} }
void EQP::setGrphEQ10(int *rxeq) void EQP::setGrphEQ10(const int *rxeq)
{ // ten band equalizer (legacy compatibility) { // ten band equalizer (legacy compatibility)
float* impulse; float* impulse;
int i;
nfreqs = 10; nfreqs = 10;
F.resize(nfreqs + 1); // (float *) malloc0 ((nfreqs + 1) * sizeof (float)); F.resize(nfreqs + 1);
G.resize(nfreqs + 1); // (float *) malloc0 ((nfreqs + 1) * sizeof (float)); G.resize(nfreqs + 1);
F[1] = 32.0; F[1] = 32.0;
F[2] = 63.0; F[2] = 63.0;
F[3] = 125.0; F[3] = 125.0;
@ -378,13 +383,12 @@ void EQP::setGrphEQ10(int *rxeq)
F[8] = 4000.0; F[8] = 4000.0;
F[9] = 8000.0; F[9] = 8000.0;
F[10] = 16000.0; F[10] = 16000.0;
for (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); impulse = eq_impulse (nc, nfreqs, F.data(), G.data(), samplerate, 1.0 / (2.0 * size), ctfmode, wintype);
// print_impulse ("rxeq.txt", nc, impulse, 1, 0);
FIRCORE::setImpulse_fircore (fircore, impulse, 1); FIRCORE::setImpulse_fircore (fircore, impulse, 1);
delete[] (impulse); delete[] impulse;
} }
} // namespace WDSP } // namespace WDSP

View File

@ -89,10 +89,10 @@ public:
void setProfile(int nfreqs, const float* F, const float* G); void setProfile(int nfreqs, const float* F, const float* G);
void setCtfmode(int mode); void setCtfmode(int mode);
void setWintype(int wintype); void setWintype(int wintype);
void setGrphEQ(int *rxeq); void setGrphEQ(const int *rxeq);
void setGrphEQ10(int *rxeq); void setGrphEQ10(const int *rxeq);
static float* eq_impulse (int N, int nfreqs, float* F, float* G, double samplerate, double scale, int ctfmode, int wintype); static float* eq_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);

View File

@ -25,6 +25,8 @@ warren@wpratt.com
*/ */
#include <array>
#include "comm.hpp" #include "comm.hpp"
#include "fircore.hpp" #include "fircore.hpp"
#include "fcurve.hpp" #include "fcurve.hpp"
@ -91,8 +93,8 @@ void FMD::calc()
void FMD::decalc() void FMD::decalc()
{ {
delete (plim); delete plim;
delete (sntch); delete sntch;
} }
FMD::FMD( FMD::FMD(
@ -144,14 +146,24 @@ FMD::FMD(
float* impulse; float* impulse;
calc(); calc();
// de-emphasis filter // de-emphasis filter
audio.resize(size * 2); // (float *) malloc0 (size * sizeof (complex)); audio.resize(size * 2);
impulse = FCurve::fc_impulse (nc_de, f_low, f_high, +20.0 * log10(f_high / f_low), 0.0, 1, rate, 1.0 / (2.0 * size), 0, 0); impulse = FCurve::fc_impulse (
nc_de,
(float) f_low,
(float) f_high,
(float) (+20.0 * log10(f_high / f_low)),
0.0, 1,
(float) rate,
(float) (1.0 / (2.0 * size)),
0,
0
);
pde = FIRCORE::create_fircore (size, audio.data(), out, nc_de, mp_de, impulse); pde = FIRCORE::create_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 = FIRCORE::create_fircore (size, out, out, nc_aud, mp_aud, impulse);
delete[] (impulse); delete[] impulse;
} }
FMD::~FMD() FMD::~FMD()
@ -179,8 +191,11 @@ void FMD::execute()
if (run) if (run)
{ {
int i; int i;
double det, del_out; double det;
double vco[2], corr[2]; double del_out;
std::array<double, 2> vco;
std::array<double, 2> corr;
for (i = 0; i < size; i++) for (i = 0; i < size; i++)
{ {
// pll // pll
@ -200,7 +215,7 @@ void FMD::execute()
while (phs < 0.0) phs += TWOPI; while (phs < 0.0) phs += TWOPI;
// dc removal, gain, & demod output // dc removal, gain, & demod output
fmdc = mtau * fmdc + onem_mtau * fil_out; fmdc = mtau * fmdc + onem_mtau * fil_out;
audio[2 * i + 0] = again * (fil_out - fmdc); audio[2 * i + 0] = (float) (again * (fil_out - fmdc));
audio[2 * i + 1] = audio[2 * i + 0]; audio[2 * i + 1] = audio[2 * i + 0];
} }
// de-emphasis // de-emphasis
@ -212,7 +227,7 @@ void FMD::execute()
if (lim_run) if (lim_run)
{ {
for (i = 0; i < 2 * size; i++) for (i = 0; i < 2 * size; i++)
out[i] *= lim_pre_gain; out[i] *= (float) lim_pre_gain;
plim->execute(); plim->execute();
} }
} }
@ -238,13 +253,24 @@ void FMD::setSamplerate(int _rate)
rate = _rate; rate = _rate;
calc(); calc();
// de-emphasis filter // de-emphasis filter
impulse = FCurve::fc_impulse (nc_de, f_low, f_high, +20.0 * log10(f_high / f_low), 0.0, 1, rate, 1.0 / (2.0 * size), 0, 0); impulse = FCurve::fc_impulse (
nc_de,
(float) f_low,
(float) f_high,
(float) (+20.0 * log10(f_high / f_low)),
0.0,
1,
(float) rate,
(float) (1.0 / (2.0 * size)),
0,
0
);
FIRCORE::setImpulse_fircore (pde, impulse, 1); FIRCORE::setImpulse_fircore (pde, 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); FIRCORE::setImpulse_fircore (paud, impulse, 1);
delete[] (impulse); delete[] impulse;
plim->setSamplerate((int) rate); plim->setSamplerate((int) rate);
} }
@ -254,17 +280,28 @@ void FMD::setSize(int _size)
decalc(); decalc();
size = _size; size = _size;
calc(); calc();
audio.resize(size * 2); // (float *) malloc0 (size * sizeof (complex)); audio.resize(size * 2);
// de-emphasis filter // de-emphasis filter
FIRCORE::destroy_fircore (pde); FIRCORE::destroy_fircore (pde);
impulse = FCurve::fc_impulse (nc_de, f_low, f_high, +20.0 * log10(f_high / f_low), 0.0, 1, rate, 1.0 / (2.0 * size), 0, 0); impulse = FCurve::fc_impulse (
nc_de,
(float) f_low,
(float) f_high,
(float) (+20.0 * log10(f_high / f_low)),
0.0,
1,
(float) rate,
(float) (1.0 / (2.0 * size)),
0,
0
);
pde = FIRCORE::create_fircore (size, audio.data(), out, nc_de, mp_de, impulse); pde = FIRCORE::create_fircore (size, audio.data(), out, nc_de, mp_de, impulse);
delete[] (impulse); delete[] impulse;
// audio filter // audio filter
FIRCORE::destroy_fircore (paud); FIRCORE::destroy_fircore (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 = FIRCORE::create_fircore (size, out, out, nc_aud, mp_aud, impulse);
delete[] (impulse); delete[] impulse;
plim->setSize(size); plim->setSize(size);
} }
@ -286,9 +323,9 @@ void FMD::setCTCSSFreq(double freq)
sntch->setFreq(ctcss_freq); sntch->setFreq(ctcss_freq);
} }
void FMD::setCTCSSRun(int run) void FMD::setCTCSSRun(int _run)
{ {
sntch_run = run; sntch_run = _run;
sntch->setRun(sntch_run); sntch->setRun(sntch_run);
} }
@ -299,9 +336,20 @@ void FMD::setNCde(int nc)
if (nc_de != nc) if (nc_de != nc)
{ {
nc_de = nc; nc_de = nc;
impulse = FCurve::fc_impulse (nc_de, f_low, f_high, +20.0 * log10(f_high / f_low), 0.0, 1, rate, 1.0 / (2.0 * size), 0, 0); impulse = FCurve::fc_impulse (
nc_de,
(float) f_low,
(float) f_high,
(float) (+20.0 * log10(f_high / f_low)),
0.0,
1,
(float) rate,
(float) (1.0 / (2.0 * size)),
0,
0
);
FIRCORE::setNc_fircore (pde, nc_de, impulse); FIRCORE::setNc_fircore (pde, nc_de, impulse);
delete[] (impulse); delete[] impulse;
} }
} }
@ -323,7 +371,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); FIRCORE::setNc_fircore (paud, nc_aud, impulse);
delete[] (impulse); delete[] impulse;
} }
} }
@ -336,10 +384,10 @@ void FMD::setMPaud(int mp)
} }
} }
void FMD::setLimRun(int run) void FMD::setLimRun(int _run)
{ {
if (lim_run != run) { if (lim_run != _run) {
lim_run = run; lim_run = _run;
} }
} }
@ -364,13 +412,24 @@ void FMD::setAFFilter(double low, double high)
f_low = low; f_low = low;
f_high = high; f_high = high;
// de-emphasis filter // de-emphasis filter
impulse = FCurve::fc_impulse (nc_de, f_low, f_high, +20.0 * log10(f_high / f_low), 0.0, 1, rate, 1.0 / (2.0 * size), 0, 0); impulse = FCurve::fc_impulse (
nc_de,
(float) f_low,
(float) f_high,
(float) (+20.0 * log10(f_high / f_low)),
0.0,
1,
(float) rate,
(float) (1.0 / (2.0 * size)),
0,
0
);
FIRCORE::setImpulse_fircore (pde, impulse, 1); FIRCORE::setImpulse_fircore (pde, 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); FIRCORE::setImpulse_fircore (paud, impulse, 1);
delete[] (impulse); delete[] impulse;
} }
} }

View File

@ -34,22 +34,23 @@ namespace WDSP {
void FMSQ::calc() void FMSQ::calc()
{ {
double delta, theta; double delta;
double theta;
float* impulse; float* impulse;
int i; int i;
// noise filter // noise filter
noise.resize(2 * size * 2); // (float *)malloc0(2 * size * sizeof(complex)); noise.resize(2 * size * 2);
F[0] = 0.0; F[0] = 0.0;
F[1] = fc; F[1] = (float) fc;
F[2] = *pllpole; F[2] = (float) *pllpole;
F[3] = 20000.0; F[3] = 20000.0;
G[0] = 0.0; G[0] = 0.0;
G[1] = 0.0; G[1] = 0.0;
G[2] = 3.0; G[2] = 3.0;
G[3] = +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 = FIRCORE::create_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));
onem_avm = 1.0 - avm; onem_avm = 1.0 - avm;
@ -60,8 +61,8 @@ void FMSQ::calc()
// level change // level change
ntup = (int)(tup * rate); ntup = (int)(tup * rate);
ntdown = (int)(tdown * rate); ntdown = (int)(tdown * rate);
cup.resize(ntup + 1); // (float *)malloc0 ((ntup + 1) * sizeof(float)); cup.resize(ntup + 1);
cdown.resize(ntdown + 1); //(float *)malloc0 ((ntdown + 1) * sizeof(float)); cdown.resize(ntdown + 1);
delta = PI / (double) ntup; delta = PI / (double) ntup;
theta = 0.0; theta = 0.0;
@ -80,7 +81,7 @@ void FMSQ::calc()
theta += delta; theta += delta;
} }
// control // control
state = 0; state = FMSQState::MUTED;
ready = 0; ready = 0;
ramp = 0.0; ramp = 0.0;
rstep = 1.0 / rate; rstep = 1.0 / rate;
@ -145,29 +146,20 @@ void FMSQ::flush()
FIRCORE::flush_fircore (p); FIRCORE::flush_fircore (p);
avnoise = 100.0; avnoise = 100.0;
longnoise = 1.0; longnoise = 1.0;
state = 0; state = FMSQState::MUTED;
ready = 0; ready = 0;
ramp = 0.0; ramp = 0.0;
} }
enum _fmsqstate
{
MUTED,
INCREASE,
UNMUTED,
TAIL,
DECREASE
};
void FMSQ::execute() void FMSQ::execute()
{ {
if (run) if (run)
{ {
int i; double _noise;
double _noise, lnlimit; double lnlimit;
FIRCORE::xfircore (p); FIRCORE::xfircore (p);
for (i = 0; i < size; i++) for (int i = 0; i < size; i++)
{ {
double noise0 = noise[2 * i + 0]; double noise0 = noise[2 * i + 0];
double noise1 = noise[2 * i + 1]; double noise1 = noise[2 * i + 1];
@ -183,10 +175,10 @@ void FMSQ::execute()
switch (state) switch (state)
{ {
case MUTED: case FMSQState::MUTED:
if (avnoise < unmute_thresh && ready) if (avnoise < unmute_thresh && ready)
{ {
state = INCREASE; state = FMSQState::INCREASE;
count = ntup; count = ntup;
} }
@ -195,19 +187,19 @@ void FMSQ::execute()
break; break;
case INCREASE: case FMSQState::INCREASE:
outsig[2 * i + 0] = insig[2 * i + 0] * cup[ntup - count]; outsig[2 * i + 0] = (float) (insig[2 * i + 0] * cup[ntup - count]);
outsig[2 * i + 1] = insig[2 * i + 1] * cup[ntup - count]; outsig[2 * i + 1] = (float) (insig[2 * i + 1] * cup[ntup - count]);
if (count-- == 0) if (count-- == 0)
state = UNMUTED; state = FMSQState::UNMUTED;
break; break;
case UNMUTED: case FMSQState::UNMUTED:
if (avnoise > tail_thresh) if (avnoise > tail_thresh)
{ {
state = TAIL; state = FMSQState::TAIL;
if ((lnlimit = longnoise) > 1.0) if ((lnlimit = longnoise) > 1.0)
lnlimit = 1.0; lnlimit = 1.0;
@ -220,28 +212,28 @@ void FMSQ::execute()
break; break;
case TAIL: case FMSQState::TAIL:
outsig[2 * i + 0] = insig[2 * i + 0]; outsig[2 * i + 0] = insig[2 * i + 0];
outsig[2 * i + 1] = insig[2 * i + 1]; outsig[2 * i + 1] = insig[2 * i + 1];
if (avnoise < unmute_thresh) if (avnoise < unmute_thresh)
{ {
state = UNMUTED; state = FMSQState::UNMUTED;
} }
else if (count-- == 0) else if (count-- == 0)
{ {
state = DECREASE; state = FMSQState::DECREASE;
count = ntdown; count = ntdown;
} }
break; break;
case DECREASE: case FMSQState::DECREASE:
outsig[2 * i + 0] = insig[2 * i + 0] * cdown[ntdown - count]; outsig[2 * i + 0] = (float) (insig[2 * i + 0] * cdown[ntdown - count]);
outsig[2 * i + 1] = insig[2 * i + 1] * cdown[ntdown - count]; outsig[2 * i + 1] = (float) (insig[2 * i + 1] * cdown[ntdown - count]);
if (count-- == 0) if (count-- == 0)
state = MUTED; state = FMSQState::MUTED;
break; break;
} }
@ -301,7 +293,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); FIRCORE::setNc_fircore (p, nc, impulse);
delete[] (impulse); delete[] impulse;
} }
} }

View File

@ -40,6 +40,15 @@ class FIRCORE;
class WDSP_API FMSQ class WDSP_API FMSQ
{ {
public: public:
enum class FMSQState
{
MUTED,
INCREASE,
UNMUTED,
TAIL,
DECREASE
};
int run; // 0 if squelch system is OFF; 1 if it's ON int run; // 0 if squelch system is OFF; 1 if it's ON
int size; // size of input/output buffers int size; // size of input/output buffers
float* insig; // squelch input signal buffer float* insig; // squelch input signal buffer
@ -59,7 +68,7 @@ public:
double longavm; double longavm;
double onem_longavm; double onem_longavm;
double longnoise; double longnoise;
int state; // state machine control FMSQState state; // state machine control
int count; int count;
double tup; double tup;
double tdown; double tdown;

View File

@ -78,8 +78,8 @@ void GEN::calc_triangle()
void GEN::calc_pulse () void GEN::calc_pulse ()
{ {
int i; double delta;
float delta, theta; double theta;
pulse.pperiod = 1.0 / pulse.pf; pulse.pperiod = 1.0 / pulse.pf;
pulse.tphs = 0.0; pulse.tphs = 0.0;
pulse.tdelta = TWOPI * pulse.tf / rate; pulse.tdelta = TWOPI * pulse.tf / rate;
@ -93,11 +93,11 @@ void GEN::calc_pulse ()
pulse.pnoff = 0; pulse.pnoff = 0;
pulse.pcount = pulse.pnoff; pulse.pcount = pulse.pnoff;
pulse.state = 0; pulse.state = PState::OFF;
pulse.ctrans = new float[pulse.pntrans + 1]; // (float *) malloc0 ((pulse.pntrans + 1) * sizeof (float)); pulse.ctrans = new double[pulse.pntrans + 1];
delta = PI / (float)pulse.pntrans; delta = PI / (float)pulse.pntrans;
theta = 0.0; theta = 0.0;
for (i = 0; i <= pulse.pntrans; i++) for (int i = 0; i <= pulse.pntrans; i++)
{ {
pulse.ctrans[i] = 0.5 * (1.0 - cos (theta)); pulse.ctrans[i] = 0.5 * (1.0 - cos (theta));
theta += delta; theta += delta;
@ -143,7 +143,7 @@ GEN::GEN(
tt.f1 = + 900.0; tt.f1 = + 900.0;
tt.f2 = + 1700.0; tt.f2 = + 1700.0;
// noise // noise
srand ((unsigned int) time (0)); srand ((unsigned int) time (nullptr));
noise.mag = 1.0; noise.mag = 1.0;
// sweep // sweep
sweep.mag = 1.0; sweep.mag = 1.0;
@ -172,17 +172,9 @@ GEN::~GEN()
void GEN::flush() void GEN::flush()
{ {
pulse.state = 0; pulse.state = PState::OFF;
} }
enum pstate
{
OFF,
UP,
ON,
DOWN
};
void GEN::execute() void GEN::execute()
{ {
if (run) if (run)
@ -191,14 +183,14 @@ void GEN::execute()
{ {
case 0: // tone case 0: // tone
{ {
int i; double t1;
float t1, t2; double t2;
float cosphase = cos (tone.phs); double cosphase = cos (tone.phs);
float sinphase = sin (tone.phs); double sinphase = sin (tone.phs);
for (i = 0; i < size; i++) for (int i = 0; i < size; i++)
{ {
out[2 * i + 0] = + tone.mag * cosphase; out[2 * i + 0] = (float) (+ tone.mag * cosphase);
out[2 * i + 1] = - tone.mag * sinphase; out[2 * i + 1] = (float) (- tone.mag * sinphase);
t1 = cosphase; t1 = cosphase;
t2 = sinphase; t2 = sinphase;
cosphase = t1 * tone.cosdelta - t2 * tone.sindelta; cosphase = t1 * tone.cosdelta - t2 * tone.sindelta;
@ -211,16 +203,16 @@ void GEN::execute()
} }
case 1: // two-tone case 1: // two-tone
{ {
int i; double tcos;
float tcos, tsin; double tsin;
float cosphs1 = cos (tt.phs1); double cosphs1 = cos (tt.phs1);
float sinphs1 = sin (tt.phs1); double sinphs1 = sin (tt.phs1);
float cosphs2 = cos (tt.phs2); double cosphs2 = cos (tt.phs2);
float sinphs2 = sin (tt.phs2); double sinphs2 = sin (tt.phs2);
for (i = 0; i < size; i++) for (int i = 0; i < size; i++)
{ {
out[2 * i + 0] = + tt.mag1 * cosphs1 + tt.mag2 * cosphs2; out[2 * i + 0] = (float) (+ tt.mag1 * cosphs1 + tt.mag2 * cosphs2);
out[2 * i + 1] = - tt.mag1 * sinphs1 - tt.mag2 * sinphs2; out[2 * i + 1] = (float) (- tt.mag1 * sinphs1 - tt.mag2 * sinphs2);
tcos = cosphs1; tcos = cosphs1;
tsin = sinphs1; tsin = sinphs1;
cosphs1 = tcos * tt.cosdelta1 - tsin * tt.sindelta1; cosphs1 = tcos * tt.cosdelta1 - tsin * tt.sindelta1;
@ -240,29 +232,30 @@ void GEN::execute()
} }
case 2: // noise case 2: // noise
{ {
int i; double r1;
float r1, r2, c, rad; double r2;
for (i = 0; i < size; i++) double c;
double rad;
for (int i = 0; i < size; i++)
{ {
do do
{ {
r1 = 2.0 * (float)rand() / (float)RAND_MAX - 1.0; r1 = 2.0 * (double)rand() / (double)RAND_MAX - 1.0;
r2 = 2.0 * (float)rand() / (float)RAND_MAX - 1.0; r2 = 2.0 * (double)rand() / (double)RAND_MAX - 1.0;
c = r1 * r1 + r2 * r2; c = r1 * r1 + r2 * r2;
} while (c >= 1.0); } while (c >= 1.0);
rad = sqrt (-2.0 * log (c) / c); rad = sqrt (-2.0 * log (c) / c);
out[2 * i + 0] = noise.mag * rad * r1; out[2 * i + 0] = (float) (noise.mag * rad * r1);
out[2 * i + 1] = noise.mag * rad * r2; out[2 * i + 1] = (float) (noise.mag * rad * r2);
} }
break; break;
} }
case 3: // sweep case 3: // sweep
{ {
int i; for (int i = 0; i < size; i++)
for (i = 0; i < size; i++)
{ {
out[2 * i + 0] = + sweep.mag * cos(sweep.phs); out[2 * i + 0] = (float) (+ sweep.mag * cos(sweep.phs));
out[2 * i + 1] = - sweep.mag * sin(sweep.phs); out[2 * i + 1] = (float) (- sweep.mag * sin(sweep.phs));
sweep.phs += sweep.dphs; sweep.phs += sweep.dphs;
sweep.dphs += sweep.d2phs; sweep.dphs += sweep.d2phs;
if (sweep.phs >= TWOPI) sweep.phs -= TWOPI; if (sweep.phs >= TWOPI) sweep.phs -= TWOPI;
@ -274,11 +267,10 @@ void GEN::execute()
} }
case 4: // sawtooth (audio only) case 4: // sawtooth (audio only)
{ {
int i; for (int i = 0; i < size; i++)
for (i = 0; i < size; i++)
{ {
if (saw.t > saw.period) saw.t -= saw.period; if (saw.t > saw.period) saw.t -= saw.period;
out[2 * i + 0] = saw.mag * (saw.t * saw.f - 1.0); out[2 * i + 0] = (float) (saw.mag * (saw.t * saw.f - 1.0));
out[2 * i + 1] = 0.0; out[2 * i + 1] = 0.0;
saw.t += saw.delta; saw.t += saw.delta;
} }
@ -286,13 +278,12 @@ void GEN::execute()
break; break;
case 5: // triangle (audio only) case 5: // triangle (audio only)
{ {
int i; for (int i = 0; i < size; i++)
for (i = 0; i < size; i++)
{ {
if (tri.t > tri.period) tri.t1 = tri.t -= tri.period; if (tri.t > tri.period) tri.t1 = tri.t -= tri.period;
if (tri.t > tri.half) tri.t1 -= tri.delta; if (tri.t > tri.half) tri.t1 -= tri.delta;
else tri.t1 += tri.delta; else tri.t1 += tri.delta;
out[2 * i + 0] = tri.mag * (4.0 * tri.t1 * tri.f - 1.0); out[2 * i + 0] = (float) (tri.mag * (4.0 * tri.t1 * tri.f - 1.0));
out[2 * i + 1] = 0.0; out[2 * i + 1] = 0.0;
tri.t += tri.delta; tri.t += tri.delta;
} }
@ -300,44 +291,44 @@ void GEN::execute()
break; break;
case 6: // pulse (audio only) case 6: // pulse (audio only)
{ {
int i; double t1;
float t1, t2; double t2;
float cosphase = cos (pulse.tphs); double cosphase = cos (pulse.tphs);
float sinphase = sin (pulse.tphs); double sinphase = sin (pulse.tphs);
for (i = 0; i < size; i++) for (int i = 0; i < size; i++)
{ {
if (pulse.pnoff != 0) if (pulse.pnoff != 0)
switch (pulse.state) switch (pulse.state)
{ {
case OFF: case PState::OFF:
out[2 * i + 0] = 0.0; out[2 * i + 0] = 0.0;
if (--pulse.pcount == 0) if (--pulse.pcount == 0)
{ {
pulse.state = UP; pulse.state = PState::UP;
pulse.pcount = pulse.pntrans; pulse.pcount = pulse.pntrans;
} }
break; break;
case UP: case PState::UP:
out[2 * i + 0] = pulse.mag * cosphase * pulse.ctrans[pulse.pntrans - pulse.pcount]; out[2 * i + 0] = (float) (pulse.mag * cosphase * pulse.ctrans[pulse.pntrans - pulse.pcount]);
if (--pulse.pcount == 0) if (--pulse.pcount == 0)
{ {
pulse.state = ON; pulse.state = PState::ON;
pulse.pcount = pulse.pnon; pulse.pcount = pulse.pnon;
} }
break; break;
case ON: case PState::ON:
out[2 * i + 0] = pulse.mag * cosphase; out[2 * i + 0] = (float) (pulse.mag * cosphase);
if (--pulse.pcount == 0) if (--pulse.pcount == 0)
{ {
pulse.state = DOWN; pulse.state = PState::DOWN;
pulse.pcount = pulse.pntrans; pulse.pcount = pulse.pntrans;
} }
break; break;
case DOWN: case PState::DOWN:
out[2 * i + 0] = pulse.mag * cosphase * pulse.ctrans[pulse.pcount]; out[2 * i + 0] = (float) (pulse.mag * cosphase * pulse.ctrans[pulse.pcount]);
if (--pulse.pcount == 0) if (--pulse.pcount == 0)
{ {
pulse.state = OFF; pulse.state = PState::OFF;
pulse.pcount = pulse.pnoff; pulse.pcount = pulse.pnoff;
} }
break; break;
@ -432,9 +423,9 @@ void GEN::SetPreSweepFreq(float freq1, float freq2)
calc_sweep(); calc_sweep();
} }
void GEN::SetPreSweepRate(float rate) void GEN::SetPreSweepRate(float _rate)
{ {
sweep.sweeprate = rate; sweep.sweeprate = _rate;
calc_sweep(); calc_sweep();
} }

View File

@ -37,88 +37,103 @@ class TXA;
class WDSP_API GEN class WDSP_API GEN
{ {
public: public:
enum class PState
{
OFF,
UP,
ON,
DOWN
};
int run; // run int run; // run
int size; // number of samples per buffer int size; // number of samples per buffer
float* in; // input buffer (retained in case I want to mix in a generated signal) float* in; // input buffer (retained in case I want to mix in a generated signal)
float* out; // output buffer float* out; // output buffer
float rate; // sample rate double rate; // sample rate
int mode; int mode;
struct _tone struct _tone
{ {
float mag; double mag;
float freq; double freq;
float phs; double phs;
float delta; double delta;
float cosdelta; double cosdelta;
float sindelta; double sindelta;
} tone; };
_tone tone;
struct _tt struct _tt
{ {
float mag1; double mag1;
float mag2; double mag2;
float f1; double f1;
float f2; double f2;
float phs1; double phs1;
float phs2; double phs2;
float delta1; double delta1;
float delta2; double delta2;
float cosdelta1; double cosdelta1;
float cosdelta2; double cosdelta2;
float sindelta1; double sindelta1;
float sindelta2; double sindelta2;
} tt; };
_tt tt;
struct _noise struct _noise
{ {
float mag; double mag;
} noise; };
_noise noise;
struct _sweep struct _sweep
{ {
float mag; double mag;
float f1; double f1;
float f2; double f2;
float sweeprate; double sweeprate;
float phs; double phs;
float dphs; double dphs;
float d2phs; double d2phs;
float dphsmax; double dphsmax;
} sweep; };
_sweep sweep;
struct _saw struct _saw
{ {
float mag; double mag;
float f; double f;
float period; double period;
float delta; double delta;
float t; double t;
} saw; };
_saw saw;
struct _tri struct _tri
{ {
float mag; double mag;
float f; double f;
float period; double period;
float half; double half;
float delta; double delta;
float t; double t;
float t1; double t1;
} tri; };
_tri tri;
struct _pulse struct _pulse
{ {
float mag; double mag;
float pf; double pf;
float pdutycycle; double pdutycycle;
float ptranstime; double ptranstime;
float* ctrans; double* ctrans;
int pcount; int pcount;
int pnon; int pnon;
int pntrans; int pntrans;
int pnoff; int pnoff;
float pperiod; double pperiod;
float tf; double tf;
float tphs; double tphs;
float tdelta; double tdelta;
float tcosdelta; double tcosdelta;
float tsindelta; double tsindelta;
int state; PState state;
} pulse; };
_pulse pulse;
GEN( GEN(
int run, int run,

View File

@ -51,20 +51,20 @@ METER::METER(
int _enum_pk, int _enum_pk,
int _enum_gain, int _enum_gain,
double* _pgain double* _pgain
) ) :
run(_run),
prun(_prun),
size(_size),
buff(_buff),
rate((double) _rate),
tau_average(_tau_av),
tau_peak_decay(_tau_decay),
result(_result),
enum_av(_enum_av),
enum_pk(_enum_pk),
enum_gain(_enum_gain),
pgain(_pgain)
{ {
run = _run;
prun = _prun;
size = _size;
buff = _buff;
rate = (double) _rate;
tau_average = _tau_av;
tau_peak_decay = _tau_decay;
result = _result;
enum_av = _enum_av;
enum_pk = _enum_pk;
enum_gain = _enum_gain;
pgain = _pgain;
calc(); calc();
} }
@ -75,7 +75,7 @@ void METER::flush()
result[enum_av] = -100.0; result[enum_av] = -100.0;
result[enum_pk] = -100.0; result[enum_pk] = -100.0;
if ((pgain != 0) && (enum_gain >= 0)) if ((pgain != nullptr) && (enum_gain >= 0))
result[enum_gain] = 0.0; result[enum_gain] = 0.0;
} }
@ -83,18 +83,17 @@ void METER::execute()
{ {
int srun; int srun;
if (prun != 0) if (prun != nullptr)
srun = *(prun); srun = *prun;
else else
srun = 1; srun = 1;
if (run && srun) if (run && srun)
{ {
int i;
double smag; double smag;
double np = 0.0; double np = 0.0;
for (i = 0; i < size; i++) for (int i = 0; i < size; i++)
{ {
double xr = buff[2 * i + 0]; double xr = buff[2 * i + 0];
double xi = buff[2 * i + 1]; double xi = buff[2 * i + 1];
@ -112,7 +111,7 @@ void METER::execute()
result[enum_av] = 10.0 * MemLog::mlog10 (avg <= 0 ? 1.0e-20 : avg); result[enum_av] = 10.0 * MemLog::mlog10 (avg <= 0 ? 1.0e-20 : avg);
result[enum_pk] = 10.0 * MemLog::mlog10 (peak <= 0 ? 1.0e-20 : peak); result[enum_pk] = 10.0 * MemLog::mlog10 (peak <= 0 ? 1.0e-20 : peak);
if ((pgain != 0) && (enum_gain >= 0)) if ((pgain != nullptr) && (enum_gain >= 0))
result[enum_gain] = 20.0 * MemLog::mlog10 (*pgain <= 0 ? 1.0e-20 : *pgain); result[enum_gain] = 20.0 * MemLog::mlog10 (*pgain <= 0 ? 1.0e-20 : *pgain);
} }
else else
@ -150,7 +149,7 @@ void METER::setSize(int _size)
* * * *
********************************************************************************************************/ ********************************************************************************************************/
double METER::getMeter(int mt) double METER::getMeter(int mt) const
{ {
return result[mt]; return result[mt];
} }

View File

@ -75,7 +75,7 @@ public:
void setBuffers(float* in); void setBuffers(float* in);
void setSamplerate(int rate); void setSamplerate(int rate);
void setSize(int size); void setSize(int size);
double getMeter(int mt); double getMeter(int mt) const;
private: private:
void calc(); void calc();

View File

@ -39,8 +39,8 @@ namespace WDSP {
void MPEAK::calc() void MPEAK::calc()
{ {
tmp.resize(size * 2); // (float *) malloc0 (size * sizeof (complex)); tmp.resize(size * 2);
mix.resize(size * 2); // (float *) malloc0 (size * sizeof (complex)); mix.resize(size * 2);
for (int i = 0; i < npeaks; i++) for (int i = 0; i < npeaks; i++)
{ {
pfil[i] = new SPEAK( pfil[i] = new SPEAK(
@ -85,15 +85,15 @@ MPEAK::MPEAK(
rate = _rate; rate = _rate;
npeaks = _npeaks; npeaks = _npeaks;
nstages = _nstages; nstages = _nstages;
enable.resize(npeaks); // (int *) malloc0 (npeaks * sizeof (int)); enable.resize(npeaks);
f.resize(npeaks); // (float *) malloc0 (npeaks * sizeof (float)); f.resize(npeaks);
bw.resize(npeaks); // (float *) malloc0 (npeaks * sizeof (float)); bw.resize(npeaks);
gain.resize(npeaks); // (float *) malloc0 (npeaks * sizeof (float)); gain.resize(npeaks);
std::copy(_enable, _enable + npeaks, enable.begin()); std::copy(_enable, _enable + npeaks, enable.begin());
std::copy(_f, _f + npeaks, f.begin()); std::copy(_f, _f + npeaks, f.begin());
std::copy(_bw, _bw + npeaks, bw.begin()); std::copy(_bw, _bw + npeaks, bw.begin());
std::copy(_gain, _gain + npeaks, gain.begin()); std::copy(_gain, _gain + npeaks, gain.begin());
pfil.resize(npeaks); // (SPEAK *) malloc0 (npeaks * sizeof (SPEAK)); pfil.resize(npeaks);
calc(); calc();
} }

View File

@ -25,6 +25,8 @@ warren@wpratt.com
*/ */
#include <array>
#include "comm.hpp" #include "comm.hpp"
#include "fir.hpp" #include "fir.hpp"
#include "fircore.hpp" #include "fircore.hpp"
@ -44,16 +46,17 @@ NOTCHDB::NOTCHDB(int _master_run, int _maxnotches)
master_run = _master_run; master_run = _master_run;
maxnotches = _maxnotches; maxnotches = _maxnotches;
nn = 0; nn = 0;
fcenter.resize(maxnotches); // (float *) malloc0 (maxnotches * sizeof (float)); fcenter.resize(maxnotches);
fwidth.resize(maxnotches); // (float *) malloc0 (maxnotches * sizeof (float)); fwidth.resize(maxnotches);
nlow.resize(maxnotches); // (float *) malloc0 (maxnotches * sizeof (float)); nlow.resize(maxnotches);
nhigh.resize(maxnotches); // (float *) malloc0 (maxnotches * sizeof (float)); nhigh.resize(maxnotches);
active.resize(maxnotches); // (int *) malloc0 (maxnotches * sizeof (int )); active.resize(maxnotches);
} }
int NOTCHDB::addNotch(int notch, double _fcenter, double _fwidth, int _active) int NOTCHDB::addNotch(int notch, double _fcenter, double _fwidth, int _active)
{ {
int i, j; int i;
int j;
int rval; int rval;
if (notch <= nn && nn < maxnotches) if (notch <= nn && nn < maxnotches)
@ -104,7 +107,8 @@ int NOTCHDB::getNotch(int _notch, double* _fcenter, double* _fwidth, int* _activ
int NOTCHDB::deleteNotch(int _notch) int NOTCHDB::deleteNotch(int _notch)
{ {
int i, j; int i;
int j;
int rval; int rval;
if (_notch < nn) if (_notch < nn)
@ -143,7 +147,7 @@ int NOTCHDB::editNotch(int _notch, double _fcenter, double _fwidth, int _active)
return rval; return rval;
} }
void NOTCHDB::getNumNotches(int* _nnotches) void NOTCHDB::getNumNotches(int* _nnotches) const
{ {
*_nnotches = nn; *_nnotches = nn;
} }
@ -154,25 +158,24 @@ void NOTCHDB::getNumNotches(int* _nnotches)
* * * *
********************************************************************************************************/ ********************************************************************************************************/
float* NBP::fir_mbandpass (int N, int nbp, double* flow, double* fhigh, double rate, double scale, int wintype) float* NBP::fir_mbandpass (int N, int nbp, const double* flow, const double* fhigh, double rate, double scale, int wintype)
{ {
int i, k; auto* impulse = new float[N * 2];
float* impulse = new float[N * 2]; // (float *) malloc0 (N * sizeof (complex)); std::fill(impulse, impulse + N*2, 0);
float* imp; for (int k = 0; k < nbp; k++)
for (k = 0; k < nbp; k++)
{ {
imp = FIR::fir_bandpass (N, flow[k], fhigh[k], rate, wintype, 1, scale); float* imp = FIR::fir_bandpass (N, flow[k], fhigh[k], rate, wintype, 1, scale);
for (i = 0; i < N; i++) for (int i = 0; i < N; i++)
{ {
impulse[2 * i + 0] += imp[2 * i + 0]; impulse[2 * i + 0] += imp[2 * i + 0];
impulse[2 * i + 1] += imp[2 * i + 1]; impulse[2 * i + 1] += imp[2 * i + 1];
} }
delete[] (imp); delete[] imp;
} }
return impulse; return impulse;
} }
double NBP::min_notch_width() double NBP::min_notch_width() const
{ {
double min_width; double min_width;
switch (wintype) switch (wintype)
@ -183,6 +186,8 @@ double NBP::min_notch_width()
case 1: case 1:
min_width = 2200.0 / (nc / 256) * (rate / 48000); min_width = 2200.0 / (nc / 256) * (rate / 48000);
break; break;
default:
min_width = 0;
} }
return min_width; return min_width;
} }
@ -204,10 +209,12 @@ int NBP::make_nbp (
) )
{ {
int nbp; int nbp;
int nnbp, adds; int nnbp;
int i, j, k; int adds;
double nl, nh; int i;
int* del = new int[1024]; // (int *) malloc0 (1024 * sizeof (int)); double nl;
double nh;
std::array<int, 1024> del;
if (fhigh > flow) if (fhigh > flow)
{ {
bplow[0] = flow; bplow[0] = flow;
@ -217,11 +224,10 @@ int NBP::make_nbp (
else else
{ {
nbp = 0; nbp = 0;
delete[] del;
return nbp; return nbp;
} }
*havnotch = 0; *havnotch = 0;
for (k = 0; k < nn; k++) for (int k = 0; k < nn; k++)
{ {
if (autoincr && width[k] < minwidth) if (autoincr && width[k] < minwidth)
{ {
@ -270,7 +276,7 @@ int NBP::make_nbp (
if (del[i] == 1) if (del[i] == 1)
{ {
nnbp--; nnbp--;
for (j = i; j < nnbp; j++) for (int j = i; j < nnbp; j++)
{ {
bplow[j] = bplow[j + 1]; bplow[j] = bplow[j + 1];
bphigh[j] = bphigh[j + 1]; bphigh[j] = bphigh[j + 1];
@ -281,14 +287,13 @@ int NBP::make_nbp (
nbp = nnbp; nbp = nnbp;
} }
} }
delete[] (del);
return nbp; return nbp;
} }
void NBP::calc_lightweight() void NBP::calc_lightweight()
{ // calculate and set new impulse response; used when changing tune freq or shift freq { // calculate and set new impulse response; used when changing tune freq or shift freq
int i; double fl;
double fl, fh; double fh;
double offset; double offset;
NOTCHDB *b = notchdb; NOTCHDB *b = notchdb;
if (fnfrun) if (fnfrun)
@ -314,7 +319,7 @@ void NBP::calc_lightweight()
// when tuning, no need to recalc filter if there were not and are not any notches in passband // when tuning, no need to recalc filter if there were not and are not any notches in passband
if (hadnotch || havnotch) if (hadnotch || havnotch)
{ {
for (i = 0; i < numpb; i++) for (int i = 0; i < numpb; i++)
{ {
bplow[i] -= offset; bplow[i] -= offset;
bphigh[i] -= offset; bphigh[i] -= offset;
@ -330,7 +335,7 @@ void NBP::calc_lightweight()
); );
FIRCORE::setImpulse_fircore (fircore, impulse, 1); FIRCORE::setImpulse_fircore (fircore, impulse, 1);
// print_impulse ("nbp.txt", size + 1, impulse, 1, 0); // print_impulse ("nbp.txt", size + 1, impulse, 1, 0);
delete[](impulse); delete[] impulse;
} }
hadnotch = havnotch; hadnotch = havnotch;
} }
@ -340,8 +345,8 @@ void NBP::calc_lightweight()
void NBP::calc_impulse () void NBP::calc_impulse ()
{ // calculates impulse response; for create_fircore() and parameter changes { // calculates impulse response; for create_fircore() and parameter changes
int i; double fl;
float fl, fh; double fh;
double offset; double offset;
NOTCHDB *b = notchdb; NOTCHDB *b = notchdb;
@ -365,7 +370,7 @@ void NBP::calc_impulse ()
bphigh, bphigh,
&havnotch &havnotch
); );
for (i = 0; i < numpb; i++) for (int i = 0; i < numpb; i++)
{ {
bplow[i] -= offset; bplow[i] -= offset;
bphigh[i] -= offset; bphigh[i] -= offset;
@ -429,12 +434,12 @@ NBP::NBP(
maxpb(_maxpb), maxpb(_maxpb),
notchdb(_notchdb) notchdb(_notchdb)
{ {
bplow.resize(maxpb); // (float *) malloc0 (maxpb * sizeof (float)); bplow.resize(maxpb);
bphigh.resize(maxpb); // (float *) malloc0 (maxpb * sizeof (float)); bphigh.resize(maxpb);
calc_impulse (); calc_impulse ();
fircore = FIRCORE::create_fircore (size, in, out, nc, mp, impulse); fircore = FIRCORE::create_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()
@ -467,7 +472,7 @@ void NBP::setSamplerate(int _rate)
rate = _rate; rate = _rate;
calc_impulse (); calc_impulse ();
FIRCORE::setImpulse_fircore (fircore, impulse, 1); FIRCORE::setImpulse_fircore (fircore, impulse, 1);
delete[] (impulse); delete[] impulse;
} }
void NBP::setSize(int _size) void NBP::setSize(int _size)
@ -477,14 +482,14 @@ void NBP::setSize(int _size)
FIRCORE::setSize_fircore (fircore, size); FIRCORE::setSize_fircore (fircore, size);
calc_impulse (); calc_impulse ();
FIRCORE::setImpulse_fircore (fircore, impulse, 1); FIRCORE::setImpulse_fircore (fircore, impulse, 1);
delete[] (impulse); delete[] impulse;
} }
void NBP::setNc() void NBP::setNc()
{ {
calc_impulse(); calc_impulse();
FIRCORE::setNc_fircore (fircore, nc, impulse); FIRCORE::setNc_fircore (fircore, nc, impulse);
delete[] (impulse); delete[] impulse;
} }
void NBP::setMp() void NBP::setMp()
@ -513,7 +518,7 @@ void NBP::SetFreqs(double _flow, double _fhigh)
fhigh = _fhigh; fhigh = _fhigh;
calc_impulse(); calc_impulse();
FIRCORE::setImpulse_fircore (fircore, impulse, 1); FIRCORE::setImpulse_fircore (fircore, impulse, 1);
delete[] (impulse); delete[] impulse;
} }
} }
@ -536,7 +541,7 @@ void NBP::SetMP(int _mp)
} }
} }
void NBP::GetMinNotchWidth(double* minwidth) void NBP::GetMinNotchWidth(double* minwidth) const
{ {
*minwidth = min_notch_width(); *minwidth = min_notch_width();
} }

View File

@ -59,7 +59,7 @@ public:
int getNotch (int notch, double* fcenter, double* fwidth, int* active); int getNotch (int notch, double* fcenter, double* fwidth, int* active);
int deleteNotch (int notch); int deleteNotch (int notch);
int editNotch (int notch, double fcenter, double fwidth, int active); int editNotch (int notch, double fcenter, double fwidth, int active);
void getNumNotches (int* nnotches); void getNumNotches (int* nnotches) const;
}; };
@ -125,12 +125,12 @@ public:
void SetFreqs(double flow, double fhigh); void SetFreqs(double flow, double fhigh);
void SetNC(int nc); void SetNC(int nc);
void SetMP(int mp); void SetMP(int mp);
void GetMinNotchWidth(double* minwidth); void GetMinNotchWidth(double* minwidth) const;
void calc_lightweight(); void calc_lightweight();
private: private:
static float* fir_mbandpass (int N, int nbp, double* flow, double* fhigh, double rate, double scale, int wintype); static float* fir_mbandpass (int N, int nbp, const double* flow, const double* fhigh, double rate, double scale, int wintype);
double min_notch_width (); double min_notch_width () const;
static int make_nbp ( static int make_nbp (
int nn, int nn,
std::vector<int>& active, std::vector<int>& active,

View File

@ -150,8 +150,10 @@ void NOB::execute()
double mag; double mag;
int bf_idx; int bf_idx;
int ff_idx; int ff_idx;
int lidx, tidx; int lidx;
int i, j, k; int tidx;
int j;
int k;
int bfboutidx; int bfboutidx;
int ffboutidx; int ffboutidx;
int hcount; int hcount;
@ -161,7 +163,7 @@ void NOB::execute()
if (run) if (run)
{ {
for (i = 0; i < buffsize; i++) for (int i = 0; i < buffsize; i++)
{ {
dline[2 * in_idx + 0] = in[2 * i + 0]; dline[2 * in_idx + 0] = in[2 * i + 0];
dline[2 * in_idx + 1] = in[2 * i + 1]; dline[2 * in_idx + 1] = in[2 * i + 1];
@ -189,8 +191,8 @@ void NOB::execute()
{ {
case 0: // normal output & impulse setup case 0: // normal output & impulse setup
{ {
out[2 * i + 0] = dline[2 * out_idx + 0]; out[2 * i + 0] = (float) (dline[2 * out_idx + 0]);
out[2 * i + 1] = dline[2 * out_idx + 1]; out[2 * i + 1] = (float) (dline[2 * out_idx + 1]);
Ilast = dline[2 * out_idx + 0]; Ilast = dline[2 * out_idx + 0];
Qlast = dline[2 * out_idx + 1]; Qlast = dline[2 * out_idx + 1];
@ -210,7 +212,6 @@ void NOB::execute()
do do
{ {
len = 0;
hcount = 0; hcount = 0;
while ((imp[tidx] > 0 || hcount > 0) && blank_count < max_imp_seq) while ((imp[tidx] > 0 || hcount > 0) && blank_count < max_imp_seq)
@ -314,7 +315,7 @@ void NOB::execute()
switch (mode) switch (mode)
{ {
case 0: // zero default: // zero
deltaI = 0.0; deltaI = 0.0;
deltaQ = 0.0; deltaQ = 0.0;
I = 0.0; I = 0.0;
@ -367,8 +368,8 @@ void NOB::execute()
case 1: // slew output in advance of blanking period case 1: // slew output in advance of blanking period
{ {
scale = 0.5 + awave[time]; scale = 0.5 + awave[time];
out[2 * i + 0] = Ilast * scale + (1.0 - scale) * I; out[2 * i + 0] = (float) (Ilast * scale + (1.0 - scale) * I);
out[2 * i + 1] = Qlast * scale + (1.0 - scale) * Q; out[2 * i + 1] = (float) (Qlast * scale + (1.0 - scale) * Q);
if (++time == adv_slew_count) if (++time == adv_slew_count)
{ {
@ -385,8 +386,8 @@ void NOB::execute()
case 2: // initial advance period case 2: // initial advance period
{ {
out[2 * i + 0] = I; out[2 * i + 0] = (float) I;
out[2 * i + 1] = Q; out[2 * i + 1] = (float) Q;
I += deltaI; I += deltaI;
Q += deltaQ; Q += deltaQ;
@ -401,8 +402,8 @@ void NOB::execute()
case 3: // impulse & hang period case 3: // impulse & hang period
{ {
out[2 * i + 0] = I; out[2 * i + 0] = (float) I;
out[2 * i + 1] = Q; out[2 * i + 1] = (float) Q;
I += deltaI; I += deltaI;
Q += deltaQ; Q += deltaQ;
@ -425,8 +426,8 @@ void NOB::execute()
case 4: // slew output after blanking period case 4: // slew output after blanking period
{ {
scale = 0.5 - hwave[time]; scale = 0.5 - hwave[time];
out[2 * i + 0] = Inext * scale + (1.0 - scale) * I; out[2 * i + 0] = (float) (Inext * scale + (1.0 - scale) * I);
out[2 * i + 1] = Qnext * scale + (1.0 - scale) * Q; out[2 * i + 1] = (float) (Qnext * scale + (1.0 - scale) * Q);
if (++time == hang_slew_count) if (++time == hang_slew_count)
state = 0; state = 0;
@ -437,8 +438,8 @@ void NOB::execute()
case 5: case 5:
{ {
scale = 0.5 + awave[time]; scale = 0.5 + awave[time];
out[2 * i + 0] = Ilast * scale; out[2 * i + 0] = (float) (Ilast * scale);
out[2 * i + 1] = Qlast * scale; out[2 * i + 1] = (float) (Qlast * scale);
if (++time == adv_slew_count) if (++time == adv_slew_count)
{ {
@ -542,8 +543,8 @@ void NOB::execute()
case 9: case 9:
{ {
scale = 0.5 - hwave[time]; scale = 0.5 - hwave[time];
out[2 * i + 0] = Inext * scale; out[2 * i + 0] = (float) (Inext * scale);
out[2 * i + 1] = Qnext * scale; out[2 * i + 1] = (float) (Qnext * scale);
if (++time >= hang_slew_count) if (++time >= hang_slew_count)
{ {

View File

@ -55,24 +55,26 @@ PANEL::PANEL(
void PANEL::flush() void PANEL::flush()
{ {
// There is no data to be reset internally
} }
void PANEL::execute() void PANEL::execute()
{ {
int i; int i;
double I, Q; double I;
double Q;
double gainI = gain1 * gain2I; double gainI = gain1 * gain2I;
double gainQ = gain1 * gain2Q; double gainQ = gain1 * gain2Q;
// inselect is either 0(neither), 1(Q), 2(I), or 3(both) // inselect is either 0(neither), 1(Q), 2(I), or 3(both)
switch (copy) switch (copy)
{ {
case 0: // no copy default: // 0 (default) no copy
for (i = 0; i < size; i++) for (i = 0; i < size; i++)
{ {
I = in[2 * i + 0] * (inselect >> 1); I = in[2 * i + 0] * (inselect >> 1);
Q = in[2 * i + 1] * (inselect & 1); Q = in[2 * i + 1] * (inselect & 1);
out[2 * i + 0] = gainI * I; out[2 * i + 0] = (float) (gainI * I);
out[2 * i + 1] = gainQ * Q; out[2 * i + 1] = (float) (gainQ * Q);
} }
break; break;
case 1: // copy I to Q (then Q == I) case 1: // copy I to Q (then Q == I)
@ -80,8 +82,8 @@ void PANEL::execute()
{ {
I = in[2 * i + 0] * (inselect >> 1); I = in[2 * i + 0] * (inselect >> 1);
Q = I; Q = I;
out[2 * i + 0] = gainI * I; out[2 * i + 0] = (float) (gainI * I);
out[2 * i + 1] = gainQ * Q; out[2 * i + 1] = (float) (gainQ * Q);
} }
break; break;
case 2: // copy Q to I (then I == Q) case 2: // copy Q to I (then I == Q)
@ -89,8 +91,8 @@ void PANEL::execute()
{ {
Q = in[2 * i + 1] * (inselect & 1); Q = in[2 * i + 1] * (inselect & 1);
I = Q; I = Q;
out[2 * i + 0] = gainI * I; out[2 * i + 0] = (float) (gainI * I);
out[2 * i + 1] = gainQ * Q; out[2 * i + 1] = (float) (gainQ * Q);
} }
break; break;
case 3: // reverse (I=>Q and Q=>I) case 3: // reverse (I=>Q and Q=>I)
@ -98,8 +100,8 @@ void PANEL::execute()
{ {
Q = in[2 * i + 0] * (inselect >> 1); Q = in[2 * i + 0] * (inselect >> 1);
I = in[2 * i + 1] * (inselect & 1); I = in[2 * i + 1] * (inselect & 1);
out[2 * i + 0] = gainI * I; out[2 * i + 0] = (float) (gainI * I);
out[2 * i + 1] = gainQ * Q; out[2 * i + 1] = (float) (gainQ * Q);
} }
break; break;
} }
@ -113,6 +115,7 @@ void PANEL::setBuffers(float* _in, float* _out)
void PANEL::setSamplerate(int) void PANEL::setSamplerate(int)
{ {
// There is no sample rate to be set for this component
} }
void PANEL::setSize(int _size) void PANEL::setSize(int _size)
@ -149,21 +152,22 @@ void PANEL::setGain2(double _gainI, double _gainQ)
void PANEL::setPan(double _pan) void PANEL::setPan(double _pan)
{ {
double gain1, gain2; double _gain1;
double _gain2;
if (_pan <= 0.5) if (_pan <= 0.5)
{ {
gain1 = 1.0; _gain1 = 1.0;
gain2 = sin (_pan * PI); _gain2 = sin (_pan * PI);
} }
else else
{ {
gain1 = sin (_pan * PI); _gain1 = sin (_pan * PI);
gain2 = 1.0; _gain2 = 1.0;
} }
gain2I = gain1; gain2I = _gain1;
gain2Q = gain2; gain2Q = _gain2;
} }
void PANEL::setCopy(int _copy) void PANEL::setCopy(int _copy)

View File

@ -39,10 +39,10 @@ namespace WDSP {
void PHROT::calc() void PHROT::calc()
{ {
double g; double g;
x0.resize(nstages); // (float *) malloc0 (nstages * sizeof (float)); x0.resize(nstages);
x1.resize(nstages); // (float *) malloc0 (nstages * sizeof (float)); x1.resize(nstages);
y0.resize(nstages); // (float *) malloc0 (nstages * sizeof (float)); y0.resize(nstages);
y1.resize(nstages); // (float *) malloc0 (nstages * sizeof (float)); y1.resize(nstages);
g = tan (PI * fc / (float)rate); g = tan (PI * fc / (float)rate);
b0 = (g - 1.0) / (g + 1.0); b0 = (g - 1.0) / (g + 1.0);
b1 = 1.0; b1 = 1.0;
@ -58,7 +58,6 @@ PHROT::PHROT(
double _fc, double _fc,
int _nstages int _nstages
) : ) :
reverse(0),
run(_run), run(_run),
size(_size), size(_size),
in(_in), in(_in),
@ -67,6 +66,7 @@ PHROT::PHROT(
fc(_fc), fc(_fc),
nstages(_nstages) nstages(_nstages)
{ {
reverse = 0;
calc(); calc();
} }
@ -102,7 +102,7 @@ void PHROT::execute()
x1[n] = x0[n]; x1[n] = x0[n];
} }
out[2 * i + 0] = y0[nstages - 1]; out[2 * i + 0] = (float) y0[nstages - 1];
} }
} }
else if (out != in) else if (out != in)
@ -135,9 +135,9 @@ void PHROT::setSize(int _size)
* * * *
********************************************************************************************************/ ********************************************************************************************************/
void PHROT::setRun(int run) void PHROT::setRun(int _run)
{ {
run = run; run = _run;
if (run) if (run)
flush(); flush();

View File

@ -54,8 +54,13 @@ public:
double fc; double fc;
int nstages; int nstages;
// normalized such that a0 = 1 // normalized such that a0 = 1
double a1, b0, b1; double a1;
std::vector<double> x0, x1, y0, y1; double b0;
double b1;
std::vector<double> x0;
std::vector<double> x1;
std::vector<double> y0;
std::vector<double> y1;
PHROT( PHROT(
int run, int run,

View File

@ -39,11 +39,14 @@ namespace WDSP {
void RESAMPLE::calc() void RESAMPLE::calc()
{ {
int x, y, z; int x;
int i, j, k; int y;
int z;
int i;
int min_rate; int min_rate;
double full_rate; double full_rate;
double fc_norm_high, fc_norm_low; double fc_norm_high;
double fc_norm_low;
float* impulse; float* impulse;
fc = fcin; fc = fcin;
ncoef = ncoefin; ncoef = ncoefin;
@ -84,22 +87,22 @@ void RESAMPLE::calc()
ncoef = (ncoef / L + 1) * L; ncoef = (ncoef / L + 1) * L;
cpp = ncoef / L; cpp = ncoef / L;
h.resize(ncoef); // (float *)malloc0(ncoef * sizeof(float)); h.resize(ncoef);
impulse = FIR::fir_bandpass(ncoef, fc_norm_low, fc_norm_high, 1.0, 1, 0, gain * (double)L); impulse = FIR::fir_bandpass(ncoef, fc_norm_low, fc_norm_high, 1.0, 1, 0, gain * (double)L);
i = 0; i = 0;
for (j = 0; j < L; j++) for (int j = 0; j < L; j++)
{ {
for (k = 0; k < ncoef; k += L) for (int k = 0; k < ncoef; k += L)
h[i++] = impulse[j + k]; h[i++] = impulse[j + k];
} }
ringsize = cpp; ringsize = cpp;
ring.resize(ringsize); // (float *)malloc0(ringsize * sizeof(complex)); ring.resize(ringsize);
idx_in = ringsize - 1; idx_in = ringsize - 1;
phnum = 0; phnum = 0;
delete[] (impulse); delete[] impulse;
} }
RESAMPLE::RESAMPLE ( RESAMPLE::RESAMPLE (
@ -141,11 +144,12 @@ int RESAMPLE::execute()
if (run) if (run)
{ {
int i, j, n; int n;
int idx_out; int idx_out;
double I, Q; double I;
double Q;
for (i = 0; i < size; i++) for (int i = 0; i < size; i++)
{ {
ring[2 * idx_in + 0] = in[2 * i + 0]; ring[2 * idx_in + 0] = in[2 * i + 0];
ring[2 * idx_in + 1] = in[2 * i + 1]; ring[2 * idx_in + 1] = in[2 * i + 1];
@ -156,7 +160,7 @@ int RESAMPLE::execute()
Q = 0.0; Q = 0.0;
n = cpp * phnum; n = cpp * phnum;
for (j = 0; j < cpp; j++) for (int j = 0; j < cpp; j++)
{ {
if ((idx_out = idx_in + j) >= ringsize) if ((idx_out = idx_in + j) >= ringsize)
idx_out -= ringsize; idx_out -= ringsize;
@ -165,8 +169,8 @@ int RESAMPLE::execute()
Q += h[n + j] * ring[2 * idx_out + 1]; Q += h[n + j] * ring[2 * idx_out + 1];
} }
out[2 * outsamps + 0] = I; out[2 * outsamps + 0] = (float) I;
out[2 * outsamps + 1] = Q; out[2 * outsamps + 1] = (float) Q;
outsamps++; outsamps++;
phnum += M; phnum += M;
} }
@ -231,25 +235,24 @@ void RESAMPLE::setBandwidth(double _fc_low, double _fc_high)
// exported calls // exported calls
void* RESAMPLE::createV (int in_rate, int out_rate) RESAMPLE* RESAMPLE::Create(int in_rate, int out_rate)
{ {
return (void *) new RESAMPLE(1, 0, 0, 0, in_rate, out_rate, 0.0, 0, 1.0); return new RESAMPLE(1, 0, nullptr, nullptr, in_rate, out_rate, 0.0, 0, 1.0);
} }
void RESAMPLE::executeV (float* input, float* output, int numsamps, int* outsamps, void* ptr) void RESAMPLE::Execute(float* input, float* output, int numsamps, int* outsamps, RESAMPLE* ptr)
{ {
RESAMPLE *a = (RESAMPLE*) ptr; ptr->in = input;
a->in = input; ptr->out = output;
a->out = output; ptr->size = numsamps;
a->size = numsamps; *outsamps = ptr->execute();
*outsamps = a->execute();
} }
void RESAMPLE::destroyV (void* ptr) void RESAMPLE::Destroy(RESAMPLE* ptr)
{ {
delete ( (RESAMPLE*) ptr ); delete ptr;
} }
} // namespace WDSP } // namespace WDSP

View File

@ -87,10 +87,10 @@ public:
void setOutRate(int rate); void setOutRate(int rate);
void setFCLow(double fc_low); void setFCLow(double fc_low);
void setBandwidth(double fc_low, double fc_high); void setBandwidth(double fc_low, double fc_high);
// Exported calls // Static methods
static void* createV (int in_rate, int out_rate); static RESAMPLE* Create (int in_rate, int out_rate);
static void executeV (float* input, float* output, int numsamps, int* outsamps, void* ptr); static void Execute (float* input, float* output, int numsamps, int* outsamps, RESAMPLE* ptr);
static void destroyV (void* ptr); static void Destroy (RESAMPLE* ptr);
private: private:
void calc(); void calc();

View File

@ -36,30 +36,21 @@ SENDER::SENDER(int _run, int _flag, int _mode, int _size, float* _in) :
flag(_flag), flag(_flag),
mode(_mode), mode(_mode),
size(_size), size(_size),
in(_in) in(_in),
spectrumProbe(nullptr)
{ {
spectrumProbe = nullptr;
} }
void SENDER::flush() void SENDER::flush()
{ {
// There is no internal data to be reset
} }
void SENDER::execute() void SENDER::execute()
{ {
if (run && flag) if (run && flag && (mode == 0) && spectrumProbe) {
{
switch (mode)
{
case 0:
{
if (spectrumProbe) {
spectrumProbe->proceed(in, size); spectrumProbe->proceed(in, size);
} }
break;
}
}
}
} }
void SENDER::setBuffers(float* _in) void SENDER::setBuffers(float* _in)

View File

@ -50,9 +50,9 @@ SHIFT::SHIFT (
in(_in), in(_in),
out(_out), out(_out),
rate((double) _rate), rate((double) _rate),
shift(_fshift) shift(_fshift),
phase(0.0)
{ {
phase = 0.0;
calc(); calc();
} }
@ -65,17 +65,19 @@ void SHIFT::execute()
{ {
if (run) if (run)
{ {
int i; double I1;
double I1, Q1, t1, t2; double Q1;
double t1;
double t2;
double cos_phase = cos (phase); double cos_phase = cos (phase);
double sin_phase = sin (phase); double sin_phase = sin (phase);
for (i = 0; i < size; i++) for (int i = 0; i < size; i++)
{ {
I1 = in[2 * i + 0]; I1 = in[2 * i + 0];
Q1 = in[2 * i + 1]; Q1 = in[2 * i + 1];
out[2 * i + 0] = I1 * cos_phase - Q1 * sin_phase; out[2 * i + 0] = (float) (I1 * cos_phase - Q1 * sin_phase);
out[2 * i + 1] = I1 * sin_phase + Q1 * cos_phase; out[2 * i + 1] = (float) (I1 * sin_phase + Q1 * cos_phase);
t1 = cos_phase; t1 = cos_phase;
t2 = sin_phase; t2 = sin_phase;
cos_phase = t1 * cos_delta - t2 * sin_delta; cos_phase = t1 * cos_delta - t2 * sin_delta;

View File

@ -34,23 +34,25 @@ namespace WDSP {
void SIPHON::build_window() void SIPHON::build_window()
{ {
int i; int i;
double arg0, cosphi; double arg0;
double sum, scale; double cosphi;
double sum;
float scale;
arg0 = 2.0 * PI / ((double) fftsize - 1.0); arg0 = 2.0 * PI / ((double) fftsize - 1.0);
sum = 0.0; sum = 0.0;
for (i = 0; i < fftsize; i++) for (i = 0; i < fftsize; i++)
{ {
cosphi = cos (arg0 * (float)i); cosphi = cos (arg0 * (float)i);
window[i] = + 6.3964424114390378e-02 window[i] = (float) (+ 6.3964424114390378e-02
+ cosphi * ( - 2.3993864599352804e-01 + cosphi * ( - 2.3993864599352804e-01
+ cosphi * ( + 3.5015956323820469e-01 + cosphi * ( + 3.5015956323820469e-01
+ cosphi * ( - 2.4774111897080783e-01 + cosphi * ( - 2.4774111897080783e-01
+ cosphi * ( + 8.5438256055858031e-02 + cosphi * ( + 8.5438256055858031e-02
+ cosphi * ( - 1.2320203369293225e-02 + cosphi * ( - 1.2320203369293225e-02
+ cosphi * ( + 4.3778825791773474e-04 )))))); + cosphi * ( + 4.3778825791773474e-04 )))))));
sum += window[i]; sum += window[i];
} }
scale = 1.0 / sum; scale = 1.0f / (float) sum;
for (i = 0; i < fftsize; i++) for (i = 0; i < fftsize; i++)
window[i] *= scale; window[i] *= scale;
} }
@ -65,23 +67,23 @@ SIPHON::SIPHON(
int _sipsize, int _sipsize,
int _fftsize, int _fftsize,
int _specmode int _specmode
) ) :
run(_run),
position(_position),
mode(_mode),
disp(_disp),
insize(_insize),
in(_in),
sipsize(_sipsize), // NOTE: sipsize MUST BE A POWER OF TWO!!
fftsize(_fftsize),
specmode(_specmode)
{ {
run = _run; sipbuff.resize(sipsize * 2);
position = _position;
mode = _mode;
disp = _disp;
insize = _insize;
in = _in;
sipsize = _sipsize; // NOTE: sipsize MUST BE A POWER OF TWO!!
fftsize = _fftsize;
specmode = _specmode;
sipbuff.resize(sipsize * 2); // (float *) malloc0 (sipsize * sizeof (complex));
idx = 0; idx = 0;
sipout.resize(sipsize * 2); // (float *) malloc0 (sipsize * sizeof (complex)); sipout.resize(sipsize * 2);
specout.resize(fftsize * 2); // (float *) malloc0 (fftsize * sizeof (complex)); specout.resize(fftsize * 2);
sipplan = fftwf_plan_dft_1d (fftsize, (fftwf_complex *) sipout.data(), (fftwf_complex *) specout.data(), FFTW_FORWARD, FFTW_PATIENT); sipplan = fftwf_plan_dft_1d (fftsize, (fftwf_complex *) sipout.data(), (fftwf_complex *) specout.data(), FFTW_FORWARD, FFTW_PATIENT);
window.resize(fftsize * 2); // (float *) malloc0 (fftsize * sizeof (complex)); window.resize(fftsize * 2);
build_window(); build_window();
} }
@ -100,13 +102,11 @@ void SIPHON::flush()
void SIPHON::execute(int pos) void SIPHON::execute(int pos)
{ {
int first, second; int first;
int second;
if (run && position == pos) if (run && (position == pos) && (mode == 0))
{ {
switch (mode)
{
case 0:
if (insize >= sipsize) if (insize >= sipsize)
std::copy(&(in[2 * (insize - sipsize)]), &(in[2 * (insize - sipsize)]) + sipsize * 2, sipbuff.begin()); std::copy(&(in[2 * (insize - sipsize)]), &(in[2 * (insize - sipsize)]) + sipsize * 2, sipbuff.begin());
else else
@ -125,11 +125,6 @@ void SIPHON::execute(int pos)
std::copy(in + 2 * first, in + 2 * first + second * 2, sipbuff.begin()); std::copy(in + 2 * first, in + 2 * first + second * 2, sipbuff.begin());
if ((idx += insize) >= sipsize) idx -= sipsize; if ((idx += insize) >= sipsize) idx -= sipsize;
} }
break;
case 1:
// Spectrum0 (1, disp, 0, 0, in);
break;
}
} }
} }
@ -168,8 +163,7 @@ void SIPHON::suck()
void SIPHON::sip_spectrum() void SIPHON::sip_spectrum()
{ {
int i; for (int i = 0; i < fftsize; i++)
for (i = 0; i < fftsize; i++)
{ {
sipout[2 * i + 0] *= window[i]; sipout[2 * i + 0] *= window[i];
sipout[2 * i + 1] *= window[i]; sipout[2 * i + 1] *= window[i];
@ -189,7 +183,7 @@ void SIPHON::getaSipF(float* _out, int _size)
suck (); suck ();
for (int i = 0; i < _size; i++) { for (int i = 0; i < _size; i++) {
_out[i] = (float) sipout[2 * i + 0]; _out[i] = sipout[2 * i + 0];
} }
} }
@ -200,8 +194,8 @@ void SIPHON::getaSipF1(float* _out, int _size)
for (int i = 0; i < _size; i++) for (int i = 0; i < _size; i++)
{ {
_out[2 * i + 0] = (float) sipout[2 * i + 0]; _out[2 * i + 0] = sipout[2 * i + 0];
_out[2 * i + 1] = (float) sipout[2 * i + 1]; _out[2 * i + 1] = sipout[2 * i + 1];
} }
} }
@ -236,7 +230,11 @@ void SIPHON::setSipSpecmode(int _mode)
void SIPHON::getSpecF1(float* _out) void SIPHON::getSpecF1(float* _out)
{ // return spectrum magnitudes in dB { // return spectrum magnitudes in dB
int i, j, mid, m, n; int i;
int j;
int mid;
int m;
int n;
outsize = fftsize; outsize = fftsize;
suck(); suck();
sip_spectrum(); sip_spectrum();
@ -262,68 +260,5 @@ void SIPHON::getSpecF1(float* _out)
} }
} }
/********************************************************************************************************
* *
* CALLS FOR EXTERNAL USE *
* *
********************************************************************************************************/
/*
#define MAX_EXT_SIPHONS (2) // maximum number of Siphons called from outside wdsp
__declspec (align (16)) SIPHON psiphon[MAX_EXT_SIPHONS]; // array of pointers for Siphons used EXTERNAL to wdsp
PORT
void create_siphonEXT (int id, int run, int insize, int sipsize, int fftsize, int specmode)
{
psiphon[id] = create_siphon (run, 0, 0, 0, insize, 0, sipsize, fftsize, specmode);
}
PORT
void destroy_siphonEXT (int id)
{
destroy_siphon (psiphon[id]);
}
PORT
void flush_siphonEXT (int id)
{
flush_siphon (psiphon[id]);
}
PORT
void xsiphonEXT (int id, float* buff)
{
SIPHON a = psiphon[id];
a->in = buff;
xsiphon (a, 0);
}
PORT
void GetaSipF1EXT (int id, float* out, int size)
{ // return raw samples as floats
SIPHON a = psiphon[id];
int i;
a->update.lock();
a->outsize = size;
suck (a);
a->update.unlock();
for (i = 0; i < size; i++)
{
out[2 * i + 0] = (float)a->sipout[2 * i + 0];
out[2 * i + 1] = (float)a->sipout[2 * i + 1];
}
}
PORT
void SetSiphonInsize (int id, int size)
{
SIPHON a = psiphon[id];
a->update.lock();
a->insize = size;
a->update.unlock();
}
*/
} // namespace WDSP } // namespace WDSP

View File

@ -87,11 +87,6 @@ public:
void setSipDisplay(int disp); void setSipDisplay(int disp);
void getSpecF1(float* out); void getSpecF1(float* out);
void setSipSpecmode(int mode); void setSipSpecmode(int mode);
// Calls for External Use
// static void create_siphonEXT (int id, int run, int insize, int sipsize, int fftsize, int specmode);
// static void destroy_siphonEXT (int id);
// static void xsiphonEXT (int id, float* buff);
// static void SetSiphonInsize (int id, int size);
private: private:
void build_window(); void build_window();

View File

@ -25,6 +25,8 @@ warren@wpratt.com
*/ */
#include <array>
#include "comm.hpp" #include "comm.hpp"
#include "resample.hpp" #include "resample.hpp"
#include "lmath.hpp" #include "lmath.hpp"
@ -36,10 +38,75 @@ warren@wpratt.com
#include "emnr.hpp" #include "emnr.hpp"
#include "snba.hpp" #include "snba.hpp"
#define MAXIMP 256
namespace WDSP { namespace WDSP {
SNBA::Exec::Exec(int xsize, int _asize, int _npasses) :
asize(_asize),
npasses(_npasses)
{
a.resize(xsize);
v.resize(xsize);
detout.resize(xsize);
savex.resize(xsize);
xHout.resize(xsize);
unfixed.resize(xsize);
}
void SNBA::Exec::fluxh()
{
std::fill (a.begin(), a.end(), 0);
std::fill (v.begin(), v.end(), 0);
std::fill (detout.begin(), detout.end(), 0);
std::fill (savex.begin(), savex.end(), 0);
std::fill (xHout.begin(), xHout.end(), 0);
std::fill (unfixed.begin(), unfixed.end(), 0);
}
SNBA::Det::Det(
int _xsize,
double _k1,
double _k2,
int _b,
int _pre,
int _post
) :
k1(_k1),
k2(_k2),
b(_b),
pre(_pre),
post(_post)
{
vp.resize(_xsize);
vpwr.resize(_xsize);
}
void SNBA::Det::flush()
{
std::fill(vp.begin(), vp.end(), 0);
std::fill(vpwr.begin(), vpwr.end(), 0);
}
SNBA::Wrk::Wrk(
int xsize,
int asize
) :
xHat_a1rows_max(xsize + asize),
xHat_a2cols_max(xsize + 2 * asize)
{
xHat_r.resize(xsize);
xHat_ATAI.resize(xsize * xsize);
xHat_A1.resize(xHat_a1rows_max * xsize);
xHat_A2.resize(xHat_a1rows_max * xHat_a2cols_max);
xHat_P1.resize(xsize * xHat_a2cols_max);
xHat_P2.resize(xsize);
trI_y.resize(xsize - 1);
trI_v.resize(xsize - 1);
dR_z.resize(xsize - 2);
asolve_r.resize(asize + 1);
asolve_z.resize(asize + 1);
}
void SNBA::calc() void SNBA::calc()
{ {
if (inrate >= internalrate) if (inrate >= internalrate)
@ -47,8 +114,8 @@ void SNBA::calc()
else else
isize = bsize * (internalrate / inrate); isize = bsize * (internalrate / inrate);
inbuff = new float[isize * 2]; // (double *) malloc0 (isize * sizeof (complex)); inbuff = new float[isize * 2];
outbuff = new float[isize * 2]; // (double *) malloc0 (isize * sizeof (complex)); outbuff = new float[isize * 2];
if (inrate != internalrate) if (inrate != internalrate)
resamprun = 1; resamprun = 1;
@ -88,7 +155,7 @@ void SNBA::calc()
iainidx = 0; iainidx = 0;
iaoutidx = 0; iaoutidx = 0;
inaccum = new double[iasize * 2]; // (double *) malloc0 (iasize * sizeof (double)); inaccum.resize(iasize * 2);
nsamps = 0; nsamps = 0;
if (incr > isize) if (incr > isize)
@ -105,7 +172,7 @@ void SNBA::calc()
} }
init_oaoutidx = oaoutidx; init_oaoutidx = oaoutidx;
outaccum = new double[oasize * 2]; // (double *) malloc0 (oasize * sizeof (double)); outaccum.resize(oasize * 2);
} }
SNBA::SNBA( SNBA::SNBA(
@ -140,15 +207,12 @@ SNBA::SNBA(
iasize(0), iasize(0),
iainidx(0), iainidx(0),
iaoutidx(0), iaoutidx(0),
inaccum(nullptr),
xbase(nullptr),
xaux(nullptr), xaux(nullptr),
nsamps(0), nsamps(0),
oasize(0), oasize(0),
oainidx(0), oainidx(0),
oaoutidx(0), oaoutidx(0),
init_oaoutidx(0), init_oaoutidx(0),
outaccum(nullptr),
resamprun(0), resamprun(0),
isize(0), isize(0),
inresamp(nullptr), inresamp(nullptr),
@ -156,80 +220,29 @@ SNBA::SNBA(
inbuff(nullptr), inbuff(nullptr),
outbuff(nullptr), outbuff(nullptr),
out_low_cut(_out_low_cut), out_low_cut(_out_low_cut),
out_high_cut(_out_high_cut) out_high_cut(_out_high_cut),
exec(_xsize, _asize, _npasses),
sdet(_xsize, _k1, _k2, _b, _pre, _post),
wrk(_xsize, _asize)
{ {
exec.asize = _asize;
exec.npasses = _npasses;
sdet.k1 = _k1;
sdet.k2 = _k2;
sdet.b = _b;
sdet.pre = _pre;
sdet.post = _post;
scan.pmultmin = _pmultmin; scan.pmultmin = _pmultmin;
calc(); calc();
xbase = new double[2 * xsize]; // (double *) malloc0 (2 * xsize * sizeof (double)); xbase.resize(2 * xsize);
xaux = xbase + xsize; xaux = &xbase[xsize];
exec.a = new double[xsize]; //(double *) malloc0 (xsize * sizeof (double));
exec.v = new double[xsize]; //(double *) malloc0 (xsize * sizeof (double));
exec.detout = new int[xsize]; //(int *) malloc0 (xsize * sizeof (int));
exec.savex = new double[xsize]; //(double *) malloc0 (xsize * sizeof (double));
exec.xHout = new double[xsize]; //(double *) malloc0 (xsize * sizeof (double));
exec.unfixed = new int[xsize]; //(int *) malloc0 (xsize * sizeof (int));
sdet.vp = new double[xsize]; //(double *) malloc0 (xsize * sizeof (double));
sdet.vpwr = new double[xsize]; //(double *) malloc0 (xsize * sizeof (double));
wrk.xHat_a1rows_max = xsize + exec.asize;
wrk.xHat_a2cols_max = xsize + 2 * exec.asize;
wrk.xHat_r = new double[xsize]; // (double *) malloc0 (xsize * sizeof(double));
wrk.xHat_ATAI = new double[xsize * xsize]; // (double *) malloc0 (xsize * xsize * sizeof(double));
wrk.xHat_A1 = new double[wrk.xHat_a1rows_max * xsize]; // (double *) malloc0 (wrk.xHat_a1rows_max * xsize * sizeof(double));
wrk.xHat_A2 = new double[wrk.xHat_a1rows_max * wrk.xHat_a2cols_max]; // (double *) malloc0 (wrk.xHat_a1rows_max * wrk.xHat_a2cols_max * sizeof(double));
wrk.xHat_P1 = new double[xsize * wrk.xHat_a2cols_max]; // (double *) malloc0 (xsize * wrk.xHat_a2cols_max * sizeof(double));
wrk.xHat_P2 = new double[xsize]; // (double *) malloc0 (xsize * sizeof(double));
wrk.trI_y = new double[xsize - 1]; // (double *) malloc0 ((xsize - 1) * sizeof(double));
wrk.trI_v = new double[xsize - 1]; // (double *) malloc0 ((xsize - 1) * sizeof(double));
wrk.dR_z = new double[xsize - 2]; // (double *) malloc0 ((xsize - 2) * sizeof(double));
wrk.asolve_r = new double[exec.asize + 1]; // (double *) malloc0 ((exec.asize + 1) * sizeof(double));
wrk.asolve_z = new double[exec.asize + 1]; // (double *) malloc0 ((exec.asize + 1) * sizeof(double));
} }
void SNBA::decalc() void SNBA::decalc()
{ {
delete (outresamp); delete outresamp;
delete (inresamp); delete inresamp;
delete[] (outbuff); delete[] outbuff;
delete[] (inbuff); delete[] inbuff;
delete[] (outaccum);
delete[] (inaccum);
} }
SNBA::~SNBA() SNBA::~SNBA()
{ {
delete[] (wrk.xHat_r);
delete[] (wrk.xHat_ATAI);
delete[] (wrk.xHat_A1);
delete[] (wrk.xHat_A2);
delete[] (wrk.xHat_P1);
delete[] (wrk.xHat_P2);
delete[] (wrk.trI_y);
delete[] (wrk.trI_v);
delete[] (wrk.dR_z);
delete[] (wrk.asolve_r);
delete[] (wrk.asolve_z);
delete[] (sdet.vpwr);
delete[] (sdet.vp);
delete[] (exec.unfixed);
delete[] (exec.xHout);
delete[] (exec.savex);
delete[] (exec.detout);
delete[] (exec.v);
delete[] (exec.a);
delete[] (xbase);
decalc(); decalc();
} }
@ -241,18 +254,11 @@ void SNBA::flush()
oainidx = 0; oainidx = 0;
oaoutidx = init_oaoutidx; oaoutidx = init_oaoutidx;
memset (inaccum, 0, iasize * sizeof (double)); exec.fluxh();
memset (outaccum, 0, oasize * sizeof (double)); sdet.flush();
memset (xaux, 0, xsize * sizeof (double)); std::fill(inaccum.begin(), inaccum.end(), 0);
memset (exec.a, 0, xsize * sizeof (double)); std::fill(outaccum.begin(), outaccum.end(), 0);
memset (exec.v, 0, xsize * sizeof (double)); std::fill(xaux, xaux + xsize, 0);
memset (exec.detout, 0, xsize * sizeof (int));
memset (exec.savex, 0, xsize * sizeof (double));
memset (exec.xHout, 0, xsize * sizeof (double));
memset (exec.unfixed, 0, xsize * sizeof (int));
memset (sdet.vp, 0, xsize * sizeof (double));
memset (sdet.vpwr, 0, xsize * sizeof (double));
std::fill(inbuff, inbuff + isize * 2, 0); std::fill(inbuff, inbuff + isize * 2, 0);
std::fill(outbuff, outbuff + isize * 2, 0); std::fill(outbuff, outbuff + isize * 2, 0);
@ -282,27 +288,26 @@ void SNBA::setSize(int size)
calc(); calc();
} }
void SNBA::ATAc0 (int n, int nr, double* A, double* r) void SNBA::ATAc0 (int n, int nr, std::vector<double>& A, std::vector<double>& r)
{ {
int i, j; std::fill(r.begin(), r.begin() + n, 0);
memset(r, 0, n * sizeof (double));
for (i = 0; i < n; i++) for (int i = 0; i < n; i++)
{ {
for (j = 0; j < nr; j++) for (int j = 0; j < nr; j++)
r[i] += A[j * n + i] * A[j * n + 0]; r[i] += A[j * n + i] * A[j * n + 0];
} }
} }
void SNBA::multA1TA2(double* a1, double* a2, int m, int n, int q, double* c) void SNBA::multA1TA2(std::vector<double>& a1, std::vector<double>& a2, int m, int n, int q, std::vector<double>& c)
{ {
int i, j, k; int k;
int p = q - m; int p = q - m;
memset (c, 0, m * n * sizeof (double)); std::fill(c.begin(), c.begin() + m*n, 0);
for (i = 0; i < m; i++) for (int i = 0; i < m; i++)
{ {
for (j = 0; j < n; j++) for (int j = 0; j < n; j++)
{ {
if (j < p) if (j < p)
{ {
@ -318,12 +323,12 @@ void SNBA::multA1TA2(double* a1, double* a2, int m, int n, int q, double* c)
} }
} }
void SNBA::multXKE(double* a, double* xk, int m, int q, int p, double* vout) void SNBA::multXKE(std::vector<double>& a, const double* xk, int m, int q, int p, std::vector<double>& vout)
{ {
int i, k; int k;
memset (vout, 0, m * sizeof (double)); std::fill(vout.begin(), vout.begin() + m, 0);
for (i = 0; i < m; i++) for (int i = 0; i < m; i++)
{ {
for (k = i; k < p; k++) for (k = i; k < p; k++)
vout[i] += a[i * q + k] * xk[k]; vout[i] += a[i * q + k] * xk[k];
@ -332,14 +337,13 @@ void SNBA::multXKE(double* a, double* xk, int m, int q, int p, double* vout)
} }
} }
void SNBA::multAv(double* a, double* v, int m, int q, double* vout) void SNBA::multAv(std::vector<double>& a, std::vector<double>& v, int m, int q, std::vector<double>& vout)
{ {
int i, k; std::fill(vout.begin(), vout.begin() + m, 0);
memset (vout, 0, m * sizeof (double));
for (i = 0; i < m; i++) for (int i = 0; i < m; i++)
{ {
for (k = 0; k < q; k++) for (int k = 0; k < q; k++)
vout[i] += a[i * q + k] * v[k]; vout[i] += a[i * q + k] * v[k];
} }
} }
@ -347,29 +351,31 @@ void SNBA::multAv(double* a, double* v, int m, int q, double* vout)
void SNBA::xHat( void SNBA::xHat(
int xusize, int xusize,
int asize, int asize,
double* xk, const double* xk,
double* a, std::vector<double>& a,
double* xout, std::vector<double>& xout,
double* r, std::vector<double>& r,
double* ATAI, std::vector<double>& ATAI,
double* A1, std::vector<double>& A1,
double* A2, std::vector<double>& A2,
double* P1, std::vector<double>& P1,
double* P2, std::vector<double>& P2,
double* trI_y, std::vector<double>& trI_y,
double* trI_v, std::vector<double>& trI_v,
double* dR_z std::vector<double>& dR_z
) )
{ {
int i, j, k; int i;
int j;
int k;
int a1rows = xusize + asize; int a1rows = xusize + asize;
int a2cols = xusize + 2 * asize; int a2cols = xusize + 2 * asize;
memset (r, 0, xusize * sizeof(double)); // work space std::fill (r.begin(), r.begin() + xusize, 0); // work space
memset (ATAI, 0, xusize * xusize * sizeof(double)); // work space std::fill (ATAI.begin(), ATAI.begin() + xusize * xusize, 0); // work space
memset (A1, 0, a1rows * xusize * sizeof(double)); // work space std::fill (A1.begin(), A1.begin() + a1rows * xusize, 0); // work space
memset (A2, 0, a1rows * a2cols * sizeof(double)); // work space std::fill (A2.begin(), A2.begin() + a1rows * a2cols, 0); // work space
memset (P1, 0, xusize * a2cols * sizeof(double)); // work space std::fill (P1.begin(), P1.begin() + xusize * a2cols, 0); // work space
memset (P2, 0, xusize * sizeof(double)); // work space std::fill (P2.begin(), P2.begin() + xusize, 0); // work space
for (i = 0; i < xusize; i++) for (i = 0; i < xusize; i++)
{ {
@ -392,16 +398,17 @@ void SNBA::xHat(
} }
ATAc0(xusize, xusize + asize, A1, r); ATAc0(xusize, xusize + asize, A1, r);
LMathd::trI(xusize, r, ATAI, trI_y, trI_v, dR_z); LMathd::trI(xusize, r.data(), ATAI.data(), trI_y.data(), trI_v.data(), dR_z.data());
multA1TA2(A1, A2, xusize, 2 * asize + xusize, xusize + asize, P1); multA1TA2(A1, A2, xusize, 2 * asize + xusize, xusize + asize, P1);
multXKE(P1, xk, xusize, xusize + 2 * asize, asize, P2); multXKE(P1, xk, xusize, xusize + 2 * asize, asize, P2);
multAv(ATAI, P2, xusize, xusize, xout); multAv(ATAI, P2, xusize, xusize, xout);
} }
void SNBA::invf(int xsize, int asize, double* a, double* x, double* v) void SNBA::invf(int xsize, int asize, std::vector<double>& a, const double* x, std::vector<double>& v)
{ {
int i, j; int i;
memset (v, 0, xsize * sizeof (double)); int j;
std::fill(v.begin(), v.begin() + xsize, 0);
for (i = asize; i < xsize - asize; i++) for (i = asize; i < xsize - asize; i++)
{ {
@ -417,12 +424,16 @@ void SNBA::invf(int xsize, int asize, double* a, double* x, double* v)
} }
} }
void SNBA::det(int asize, double* v, int* detout) void SNBA::det(int asize, std::vector<double>& v, std::vector<int>& detout)
{ {
int i, j; int i;
int j;
double medpwr; double medpwr;
double t1, t2; double t1;
int bstate, bcount, bsamp; double t2;
int bstate;
int bcount;
int bsamp;
for (i = asize, j = 0; i < xsize; i++, j++) for (i = asize, j = 0; i < xsize; i++, j++)
{ {
@ -430,7 +441,7 @@ void SNBA::det(int asize, double* v, int* detout)
sdet.vp[j] = sdet.vpwr[i]; sdet.vp[j] = sdet.vpwr[i];
} }
LMathd::median(xsize - asize, sdet.vp, &medpwr); LMathd::median(xsize - asize, sdet.vp.data(), &medpwr);
t1 = sdet.k1 * medpwr; t1 = sdet.k1 * medpwr;
t2 = 0.0; t2 = 0.0;
@ -492,6 +503,8 @@ void SNBA::det(int asize, double* v, int* detout)
bstate = 1; bstate = 1;
} }
break;
default:
break; break;
} }
} }
@ -525,24 +538,26 @@ int SNBA::scanFrame(
int xsize, int xsize,
int pval, int pval,
double pmultmin, double pmultmin,
int* det, std::vector<int>& det,
int* bimp, std::array<int, MAXIMP>& bimp,
int* limp, std::array<int, MAXIMP>& limp,
int* befimp, std::array<int, MAXIMP>& befimp,
int* aftimp, std::array<int, MAXIMP>& aftimp,
int* p_opt, std::array<int, MAXIMP>& p_opt,
int* next int* next
) )
{ {
int inflag = 0; int inflag = 0;
int i = 0, j = 0, k = 0; int i = 0;
int j = 0;
int k = 0;
int nimp = 0; int nimp = 0;
double td; double td;
int ti; int ti;
double merit[MAXIMP] = { 0 }; std::array<double, MAXIMP> merit = { 0 };
int nextlist[MAXIMP]; std::array<int, MAXIMP> nextlist;
memset (befimp, 0, MAXIMP * sizeof (int)); std::fill(befimp.begin(), befimp.end(), 0);
memset (aftimp, 0, MAXIMP * sizeof (int)); std::fill(aftimp.begin(), aftimp.end(), 0);
while (i < xsize && nimp < MAXIMP) while (i < xsize && nimp < MAXIMP)
{ {
@ -555,6 +570,7 @@ int SNBA::scanFrame(
} }
else if (det[i] == 1) else if (det[i] == 1)
{ {
if (nimp > 0)
limp[nimp - 1]++; limp[nimp - 1]++;
} }
else else
@ -634,22 +650,20 @@ int SNBA::scanFrame(
void SNBA::execFrame(double* x) void SNBA::execFrame(double* x)
{ {
int i, k;
int pass;
int nimp; int nimp;
int bimp[MAXIMP]; std::array<int, MAXIMP> bimp;
int limp[MAXIMP]; std::array<int, MAXIMP> limp;
int befimp[MAXIMP]; std::array<int, MAXIMP> befimp;
int aftimp[MAXIMP]; std::array<int, MAXIMP> aftimp;
int p_opt[MAXIMP]; std::array<int, MAXIMP> p_opt;
int next = 0; int next = 0;
int p; int p;
memcpy (exec.savex, x, xsize * sizeof (double)); std::copy(x, x + xsize, exec.savex.begin());
LMathd::asolve(xsize, exec.asize, x, exec.a, wrk.asolve_r, wrk.asolve_z); LMathd::asolve(xsize, exec.asize, x, exec.a.data(), wrk.asolve_r.data(), wrk.asolve_z.data());
invf(xsize, exec.asize, exec.a, x, exec.v); invf(xsize, exec.asize, exec.a, x, exec.v);
det(exec.asize, exec.v, exec.detout); det(exec.asize, exec.v, exec.detout);
for (i = 0; i < xsize; i++) for (int i = 0; i < xsize; i++)
{ {
if (exec.detout[i] != 0) if (exec.detout[i] != 0)
x[i] = 0.0; x[i] = 0.0;
@ -657,18 +671,18 @@ void SNBA::execFrame(double* x)
nimp = scanFrame(xsize, exec.asize, scan.pmultmin, exec.detout, bimp, limp, befimp, aftimp, p_opt, &next); nimp = scanFrame(xsize, exec.asize, scan.pmultmin, exec.detout, bimp, limp, befimp, aftimp, p_opt, &next);
for (pass = 0; pass < exec.npasses; pass++) for (int pass = 0; pass < exec.npasses; pass++)
{ {
memcpy (exec.unfixed, exec.detout, xsize * sizeof (int)); std::copy(exec.detout.begin(), exec.detout.end(), exec.unfixed.begin());
for (k = 0; k < nimp; k++) for (int k = 0; k < nimp; k++)
{ {
if (k > 0) if (k > 0)
scanFrame(xsize, exec.asize, scan.pmultmin, exec.unfixed, bimp, limp, befimp, aftimp, p_opt, &next); scanFrame(xsize, exec.asize, scan.pmultmin, exec.unfixed, bimp, limp, befimp, aftimp, p_opt, &next);
if ((p = p_opt[next]) > 0) if ((p = p_opt[next]) > 0)
{ {
LMathd::asolve(xsize, p, x, exec.a, wrk.asolve_r, wrk.asolve_z); LMathd::asolve(xsize, p, x, exec.a.data(), wrk.asolve_r.data(), wrk.asolve_z.data());
xHat( xHat(
limp[next], limp[next],
p, p,
@ -685,7 +699,7 @@ void SNBA::execFrame(double* x)
wrk.trI_v, wrk.trI_v,
wrk.dR_z wrk.dR_z
); );
memcpy (&x[bimp[next]], exec.xHout, limp[next] * sizeof (double)); std::copy(exec.xHout.begin(), exec.xHout.begin() + limp[next], &x[bimp[next]]);
memset (&exec.unfixed[bimp[next]], 0, limp[next] * sizeof (int)); memset (&exec.unfixed[bimp[next]], 0, limp[next] * sizeof (int));
} }
else else
@ -719,12 +733,12 @@ void SNBA::execute()
nsamps -= incr; nsamps -= incr;
memcpy (&outaccum[oainidx], xaux, incr * sizeof (double)); memcpy (&outaccum[oainidx], xaux, incr * sizeof (double));
oainidx = (oainidx + incr) % oasize; oainidx = (oainidx + incr) % oasize;
memmove (xbase, &xbase[incr], (2 * xsize - incr) * sizeof (double)); std::copy(&xbase[incr], &xbase[incr] + (2 * xsize - incr), xbase.begin());
} }
for (i = 0; i < isize; i++) for (i = 0; i < isize; i++)
{ {
outbuff[2 * i + 0] = outaccum[oaoutidx]; outbuff[2 * i + 0] = (float) outaccum[oaoutidx];
outbuff[2 * i + 1] = 0.0; outbuff[2 * i + 1] = 0.0;
oaoutidx = (oaoutidx + 1) % oasize; oaoutidx = (oaoutidx + 1) % oasize;
} }
@ -792,7 +806,8 @@ void SNBA::setPmultmin(double pmultmin)
void SNBA::setOutputBandwidth(double flow, double fhigh) void SNBA::setOutputBandwidth(double flow, double fhigh)
{ {
double f_low, f_high; double f_low = 0;
double f_high = 0;
if (flow >= 0 && fhigh >= 0) if (flow >= 0 && fhigh >= 0)
{ {
@ -802,7 +817,7 @@ void SNBA::setOutputBandwidth(double flow, double fhigh)
if (flow > out_high_cut) if (flow > out_high_cut)
flow = out_high_cut; flow = out_high_cut;
f_low = std::max ( out_low_cut, flow); f_low = std::max (out_low_cut, flow);
f_high = std::min (out_high_cut, fhigh); f_high = std::min (out_high_cut, fhigh);
} }
else if (flow <= 0 && fhigh <= 0) else if (flow <= 0 && fhigh <= 0)
@ -813,7 +828,7 @@ void SNBA::setOutputBandwidth(double flow, double fhigh)
if (fhigh < -out_high_cut) if (fhigh < -out_high_cut)
fhigh = -out_high_cut; fhigh = -out_high_cut;
f_low = std::max ( out_low_cut, -fhigh); f_low = std::max (out_low_cut, -fhigh);
f_high = std::min (out_high_cut, -flow); f_high = std::min (out_high_cut, -flow);
} }
else if (flow < 0 && fhigh > 0) else if (flow < 0 && fhigh > 0)

View File

@ -28,11 +28,15 @@ warren@wpratt.com
#ifndef wdsp_snba_h #ifndef wdsp_snba_h
#define wdsp_snba_h #define wdsp_snba_h
#include <vector>
#include "export.h"
namespace WDSP{ namespace WDSP{
class RESAMPLE; class RESAMPLE;
class SNBA class WDSP_API SNBA
{ {
public: public:
int run; int run;
@ -47,15 +51,15 @@ public:
int iasize; int iasize;
int iainidx; int iainidx;
int iaoutidx; int iaoutidx;
double* inaccum; std::vector<double> inaccum;
double* xbase; std::vector<double> xbase;
double* xaux; double* xaux;
int nsamps; int nsamps;
int oasize; int oasize;
int oainidx; int oainidx;
int oaoutidx; int oaoutidx;
int init_oaoutidx; int init_oaoutidx;
double* outaccum; std::vector<double> outaccum;
int resamprun; int resamprun;
int isize; int isize;
RESAMPLE *inresamp; RESAMPLE *inresamp;
@ -64,48 +68,72 @@ public:
float* outbuff; float* outbuff;
double out_low_cut; double out_low_cut;
double out_high_cut; double out_high_cut;
static const int MAXIMP = 256;
struct _exec struct Exec
{ {
int asize; int asize;
double* a; std::vector<double> a;
double* v; std::vector<double> v;
int* detout; std::vector<int> detout;
double* savex; std::vector<double> savex;
double* xHout; std::vector<double> xHout;
int* unfixed; std::vector<int> unfixed;
int npasses; int npasses;
} exec;
struct _det Exec(int xsize, int _asize, int _npasses);
void fluxh();
};
Exec exec;
struct Det
{ {
double k1; double k1;
double k2; double k2;
int b; int b;
int pre; int pre;
int post; int post;
double* vp; std::vector<double> vp;
double* vpwr; std::vector<double> vpwr;
} sdet;
struct _scan Det(
int xsize,
double k1,
double k2,
int b,
int pre,
int post
);
void flush();
};
Det sdet;
struct Scan
{ {
double pmultmin; double pmultmin;
} scan; };
struct _wrk Scan scan;
struct Wrk
{ {
int xHat_a1rows_max; int xHat_a1rows_max;
int xHat_a2cols_max; int xHat_a2cols_max;
double* xHat_r; std::vector<double> xHat_r;
double* xHat_ATAI; std::vector<double> xHat_ATAI;
double* xHat_A1; std::vector<double> xHat_A1;
double* xHat_A2; std::vector<double> xHat_A2;
double* xHat_P1; std::vector<double> xHat_P1;
double* xHat_P2; std::vector<double> xHat_P2;
double* trI_y; std::vector<double> trI_y;
double* trI_v; std::vector<double> trI_v;
double* dR_z; std::vector<double> dR_z;
double* asolve_r; std::vector<double> asolve_r;
double* asolve_z; std::vector<double> asolve_z;
} wrk;
Wrk(
int xsize,
int asize
);
void flush();
};
Wrk wrk;
SNBA( SNBA(
int run, int run,
@ -149,40 +177,40 @@ public:
private: private:
void calc(); void calc();
void decalc(); void decalc();
static void ATAc0 (int n, int nr, double* A, double* r); static void ATAc0 (int n, int nr, std::vector<double>& A, std::vector<double>& r);
static void multA1TA2(double* a1, double* a2, int m, int n, int q, double* c); static void multA1TA2(std::vector<double>& a1, std::vector<double>& a2, int m, int n, int q, std::vector<double>& c);
static void multXKE(double* a, double* xk, int m, int q, int p, double* vout); static void multXKE(std::vector<double>& a, const double* xk, int m, int q, int p, std::vector<double>& vout);
static void multAv(double* a, double* v, int m, int q, double* vout); static void multAv(std::vector<double>& a, std::vector<double>& v, int m, int q, std::vector<double>& vout);
static void xHat( static void xHat(
int xusize, int xusize,
int asize, int asize,
double* xk, const double* xk,
double* a, std::vector<double>& a,
double* xout, std::vector<double>& xout,
double* r, std::vector<double>& r,
double* ATAI, std::vector<double>& ATAI,
double* A1, std::vector<double>& A1,
double* A2, std::vector<double>& A2,
double* P1, std::vector<double>& P1,
double* P2, std::vector<double>& P2,
double* trI_y, std::vector<double>& trI_y,
double* trI_v, std::vector<double>& trI_v,
double* dR_z std::vector<double>& dR_z
); );
static void invf(int xsize, int asize, double* a, double* x, double* v); static void invf(int xsize, int asize, std::vector<double>& a, const double* x, std::vector<double>& v);
static int scanFrame( static int scanFrame(
int xsize, int xsize,
int pval, int pval,
double pmultmin, double pmultmin,
int* det, std::vector<int>& det,
int* bimp, std::array<int, MAXIMP>& bimp,
int* limp, std::array<int, MAXIMP>& limp,
int* befimp, std::array<int, MAXIMP>& befimp,
int* aftimp, std::array<int, MAXIMP>& aftimp,
int* p_opt, std::array<int, MAXIMP>& p_opt,
int* next int* next
); );
void det(int asize, double* v, int* detout); void det(int asize, std::vector<double>& v, std::vector<int>& detout);
void execFrame(double* x); void execFrame(double* x);
}; };

View File

@ -38,8 +38,11 @@ namespace WDSP {
void SNOTCH::calc() void SNOTCH::calc()
{ {
double fn, qk, qr, csn; double fn;
fn = f / (double) rate; double qk;
double qr;
double csn;
fn = f / rate;
csn = cos (TWOPI * fn); csn = cos (TWOPI * fn);
qr = 1.0 - 3.0 * bw; qr = 1.0 - 3.0 * bw;
qk = (1.0 - 2.0 * qr * csn + qr * qr) / (2.0 * (1.0 - csn)); qk = (1.0 - 2.0 * qr * csn + qr * qr) / (2.0 * (1.0 - csn));
@ -80,11 +83,10 @@ void SNOTCH::execute()
{ {
if (run) if (run)
{ {
int i; for (int i = 0; i < size; i++)
for (i = 0; i < size; i++)
{ {
x0 = in[2 * i + 0]; x0 = in[2 * i + 0];
out[2 * i + 0] = a0 * x0 + a1 * x1 + a2 * x2 + b1 * y1 + b2 * y2; out[2 * i + 0] = (float) (a0 * x0 + a1 * x1 + a2 * x2 + b1 * y1 + b2 * y2);
y2 = y1; y2 = y1;
y1 = out[2 * i + 0]; y1 = out[2 * i + 0];
x2 = x1; x2 = x1;

View File

@ -48,8 +48,16 @@ public:
double rate; double rate;
double f; double f;
double bw; double bw;
double a0, a1, a2, b1, b2; double a0;
double x0, x1, x2, y1, y2; double a1;
double a2;
double b1;
double b2;
double x0;
double x1;
double x2;
double y1;
double y2;
SNOTCH( SNOTCH(
int run, int run,
@ -62,7 +70,7 @@ public:
); );
SNOTCH(const SNOTCH&) = delete; SNOTCH(const SNOTCH&) = delete;
SNOTCH& operator=(SNOTCH& other) = delete; SNOTCH& operator=(SNOTCH& other) = delete;
~SNOTCH() {} ~SNOTCH() = default;
void flush(); void flush();
void execute(); void execute();

View File

@ -39,31 +39,38 @@ namespace WDSP {
void SPEAK::calc() void SPEAK::calc()
{ {
double ratio; double ratio;
double f_corr, g_corr, bw_corr, bw_parm, A, f_min; double f_corr;
double g_corr;
double bw_corr;
double bw_parm;
double A;
double f_min;
switch (design) switch (design)
{ {
case 0: case 0:
ratio = bw / f; ratio = bw / f;
switch (nstages) if (nstages == 4)
{ {
case 4:
bw_parm = 2.4; bw_parm = 2.4;
f_corr = 1.0 - 0.160 * ratio + 1.440 * ratio * ratio; f_corr = 1.0 - 0.160 * ratio + 1.440 * ratio * ratio;
g_corr = 1.0 - 1.003 * ratio + 3.990 * ratio * ratio; g_corr = 1.0 - 1.003 * ratio + 3.990 * ratio * ratio;
break; }
default: else
{
bw_parm = 1.0; bw_parm = 1.0;
f_corr = 1.0; f_corr = 1.0;
g_corr = 1.0; g_corr = 1.0;
break;
} }
{ {
double fn, qk, qr, csn; double fn;
double qk;
double qr;
double csn;
fgain = gain / g_corr; fgain = gain / g_corr;
fn = f / (double)rate / f_corr; fn = f / rate / f_corr;
csn = cos (TWOPI * fn); csn = cos (TWOPI * fn);
qr = 1.0 - 3.0 * bw / (double)rate * bw_parm; qr = 1.0 - 3.0 * bw / rate * bw_parm;
qk = (1.0 - 2.0 * qr * csn + qr * qr) / (2.0 * (1.0 - csn)); qk = (1.0 - 2.0 * qr * csn + qr * qr) / (2.0 * (1.0 - csn));
a0 = 1.0 - qk; a0 = 1.0 - qk;
a1 = 2.0 * (qk - qr) * csn; a1 = 2.0 * (qk - qr) * csn;
@ -76,26 +83,27 @@ void SPEAK::calc()
case 1: case 1:
if (f < 200.0) f = 200.0; if (f < 200.0) f = 200.0;
ratio = bw / f; ratio = bw / f;
switch (nstages) if (nstages == 4)
{ {
case 4:
bw_parm = 5.0; bw_parm = 5.0;
bw_corr = 1.13 * ratio - 0.956 * ratio * ratio; bw_corr = 1.13 * ratio - 0.956 * ratio * ratio;
A = 2.5; A = 2.5;
f_min = 50.0; f_min = 50.0;
break; }
default: else
{
bw_parm = 1.0; bw_parm = 1.0;
bw_corr = 1.0; bw_corr = 1.0;
g_corr = 1.0;
A = 2.5; A = 2.5;
f_min = 50.0; f_min = 50.0;
break;
} }
{ {
double w0, sn, c, den; double w0;
double sn;
double c;
double den;
if (f < f_min) f = f_min; if (f < f_min) f = f_min;
w0 = TWOPI * f / (double)rate; w0 = TWOPI * f / rate;
sn = sin (w0); sn = sin (w0);
cbw = bw_corr * f; cbw = bw_corr * f;
c = sn * sinh(0.5 * log((f + 0.5 * cbw * bw_parm) / (f - 0.5 * cbw * bw_parm)) * w0 / sn); c = sn * sinh(0.5 * log((f + 0.5 * cbw * bw_parm) / (f - 0.5 * cbw * bw_parm)) * w0 / sn);
@ -108,6 +116,8 @@ void SPEAK::calc()
fgain = gain / pow (A * A, (double)nstages); fgain = gain / pow (A * A, (double)nstages);
} }
break; break;
default:
break;
} }
flush(); flush();
} }
@ -135,12 +145,12 @@ SPEAK::SPEAK(
nstages(_nstages), nstages(_nstages),
design(_design) design(_design)
{ {
x0.resize(nstages * 2); // (float *) malloc0 (nstages * sizeof (complex)); x0.resize(nstages * 2);
x1.resize(nstages * 2); // (float *) malloc0 (nstages * sizeof (complex)); x1.resize(nstages * 2);
x2.resize(nstages * 2); //(float *) malloc0 (nstages * sizeof (complex)); x2.resize(nstages * 2);
y0.resize(nstages * 2); // (float *) malloc0 (nstages * sizeof (complex)); y0.resize(nstages * 2);
y1.resize(nstages * 2); // (float *) malloc0 (nstages * sizeof (complex)); y1.resize(nstages * 2);
y2.resize(nstages * 2); // (float *) malloc0 (nstages * sizeof (complex)); y2.resize(nstages * 2);
calc(); calc();
} }
@ -178,7 +188,7 @@ void SPEAK::execute()
x1[2 * n + j] = x0[2 * n + j]; x1[2 * n + j] = x0[2 * n + j];
} }
out[2 * i + j] = y0[2 * (nstages - 1) + j]; out[2 * i + j] = (float) y0[2 * (nstages - 1) + j];
} }
} }
} }

View File

@ -55,8 +55,17 @@ public:
double fgain; double fgain;
int nstages; int nstages;
int design; int design;
double a0, a1, a2, b1, b2; double a0;
std::vector<double> x0, x1, x2, y0, y1, y2; double a1;
double a2;
double b1;
double b2;
std::vector<double> x0;
std::vector<double> x1;
std::vector<double> x2;
std::vector<double> y0;
std::vector<double> y1;
std::vector<double> y2;
SPEAK( SPEAK(
int run, int run,
@ -72,7 +81,7 @@ public:
); );
SPEAK(const SPEAK&) = delete; SPEAK(const SPEAK&) = delete;
SPEAK& operator=(const SPEAK& other) = delete; SPEAK& operator=(const SPEAK& other) = delete;
~SPEAK() {} ~SPEAK() = default;
void flush(); void flush();
void execute(); void execute();

View File

@ -81,14 +81,13 @@ void SPHP::execute()
{ {
if (run) if (run)
{ {
int i, j, n; for (int i = 0; i < size; i++)
for (i = 0; i < size; i++)
{ {
for (j = 0; j < 2; j++) for (int j = 0; j < 2; j++)
{ {
x0[j] = in[2 * i + j]; x0[j] = in[2 * i + j];
for (n = 0; n < nstages; n++) for (int n = 0; n < nstages; n++)
{ {
if (n > 0) if (n > 0)
x0[2 * n + j] = y0[2 * (n - 1) + j]; x0[2 * n + j] = y0[2 * (n - 1) + j];
@ -100,7 +99,7 @@ void SPHP::execute()
x1[2 * n + j] = x0[2 * n + j]; x1[2 * n + j] = x0[2 * n + j];
} }
out[2 * i + j] = y0[2 * (nstages - 1) + j]; out[2 * i + j] = (float) y0[2 * (nstages - 1) + j];
} }
} }
} }

View File

@ -56,7 +56,7 @@ FTOV::FTOV(
in = _in; in = _in;
out = _out; out = _out;
eps = 0.01; eps = 0.01;
ring.resize(rsize); // (int*) malloc0 (rsize * sizeof (int)); ring.resize(rsize);
rptr = 0; rptr = 0;
inlast = 0.0; inlast = 0.0;
rcount = 0; rcount = 0;
@ -91,7 +91,7 @@ void FTOV::execute()
rcount++; // increment the count rcount++; // increment the count
} }
if (++rptr == rsize) rptr = 0; // increment and wrap the pointer as needed if (++rptr == rsize) rptr = 0; // increment and wrap the pointer as needed
out[0] = std::min (1.0, (double)rcount / div); // calculate the output sample out[0] = (float) std::min (1.0, (double)rcount / div); // calculate the output sample
inlast = in[size - 1]; // save the last input sample for next buffer inlast = in[size - 1]; // save the last input sample for next buffer
for (int i = 1; i < size; i++) for (int i = 1; i < size; i++)
{ {
@ -107,7 +107,7 @@ void FTOV::execute()
rcount++; // increment the count rcount++; // increment the count
} }
if (++rptr == rsize) rptr = 0; // increment and wrap the pointer as needed if (++rptr == rsize) rptr = 0; // increment and wrap the pointer as needed
out[i] = std::min(1.0, (double)rcount / div); // calculate the output sample out[i] = (float) std::min(1.0, (double)rcount / div); // calculate the output sample
} }
} }
} }
@ -118,7 +118,8 @@ void FTOV::execute()
void SSQL::compute_slews() void SSQL::compute_slews()
{ {
double delta, theta; double delta;
double theta;
delta = PI / (double) ntup; delta = PI / (double) ntup;
theta = 0.0; theta = 0.0;
for (int i = 0; i <= ntup; i++) for (int i = 0; i <= ntup; i++)
@ -137,15 +138,33 @@ void SSQL::compute_slews()
void SSQL::calc() void SSQL::calc()
{ {
b1 = new float[size * 2]; // (float*) malloc0 (size * sizeof (complex)); b1.resize(size * 2);
dcbl = new CBL(1, size, in, b1, 0, rate, 0.02); dcbl = new CBL(1, size, in, b1.data(), 0, rate, 0.02);
ibuff = new float[size]; // (float*) malloc0 (size * sizeof (float)); ibuff.resize(size);
ftovbuff = new float[size]; // (float*) malloc0(size * sizeof (float)); ftovbuff.resize(size);
cvtr = new FTOV(1, size, rate, ftov_rsize, ftov_fmax, ibuff, ftovbuff); cvtr = new FTOV(
lpbuff = new float[size]; // (float*) malloc0 (size * sizeof (float)); 1,
filt = new DBQLP(1, size, ftovbuff, lpbuff, rate, 11.3, 1.0, 1.0, 1); size,
wdbuff = new int[size]; // (int*) malloc0 (size * sizeof (int)); rate,
tr_signal = new int[size]; // (int*) malloc0 (size * sizeof (int)); ftov_rsize,
ftov_fmax,
ibuff.data(),
ftovbuff.data()
);
lpbuff.resize(size);
filt = new DBQLP(
1,
size,
ftovbuff.data(),
lpbuff.data(),
rate,
11.3,
1.0,
1.0,
1
);
wdbuff.resize(size);
tr_signal.resize(size);
// window detector // window detector
wdmult = exp (-1.0 / (rate * wdtau)); wdmult = exp (-1.0 / (rate * wdtau));
wdaverage = 0.0; wdaverage = 0.0;
@ -156,27 +175,19 @@ void SSQL::calc()
// level change // level change
ntup = (int)(tup * rate); ntup = (int)(tup * rate);
ntdown = (int)(tdown * rate); ntdown = (int)(tdown * rate);
cup = new float[ntup + 1]; // (float*) malloc0 ((ntup + 1) * sizeof (float)); cup.resize(ntup + 1);
cdown = new float[ntdown + 1]; // (float*) malloc0 ((ntdown + 1) * sizeof (float)); cdown.resize(ntdown + 1);
compute_slews(); compute_slews();
// control // control
state = 0; state = SSQLState::MUTED;
count = 0; count = 0;
} }
void SSQL::decalc() void SSQL::decalc()
{ {
delete[] (tr_signal); delete filt;
delete[] (wdbuff); delete cvtr;
delete (filt); delete dcbl;
delete[] (lpbuff);
delete (cvtr);
delete[] (ftovbuff);
delete[] (ibuff);
delete (dcbl);
delete[] (b1);
delete[] (cdown);
delete[] (cup);
} }
SSQL::SSQL( SSQL::SSQL(
@ -223,24 +234,17 @@ SSQL::~SSQL()
void SSQL::flush() void SSQL::flush()
{ {
std::fill(b1, b1 + size * 2, 0); std::fill(b1.begin(), b1.end(), 0);
dcbl->flush(); dcbl->flush();
memset (ibuff, 0, size * sizeof (float)); std::fill(ibuff.begin(), ibuff.end(), 0);
memset (ftovbuff, 0, size * sizeof (float)); std::fill(ftovbuff.begin(), ftovbuff.end(), 0);
cvtr->flush(); cvtr->flush();
memset (lpbuff, 0, size * sizeof (float)); std::fill(lpbuff.begin(), lpbuff.end(), 0);
filt->flush(); filt->flush();
memset (wdbuff, 0, size * sizeof (int)); std::fill(wdbuff.begin(), wdbuff.end(), 0);
memset (tr_signal, 0, size * sizeof (int)); std::fill(tr_signal.begin(), tr_signal.end(), 0);
} }
enum _ssqlstate
{
MUTED,
INCREASE,
UNMUTED,
DECREASE
};
void SSQL::execute() void SSQL::execute()
{ {
@ -277,35 +281,35 @@ void SSQL::execute()
{ {
switch (state) switch (state)
{ {
case MUTED: case SSQLState::MUTED:
if (tr_signal[i] == 1) if (tr_signal[i] == 1)
{ {
state = INCREASE; state = SSQLState::INCREASE;
count = ntup; count = ntup;
} }
out[2 * i + 0] = muted_gain * in[2 * i + 0]; out[2 * i + 0] = (float) (muted_gain * in[2 * i + 0]);
out[2 * i + 1] = muted_gain * in[2 * i + 1]; out[2 * i + 1] = (float) (muted_gain * in[2 * i + 1]);
break; break;
case INCREASE: case SSQLState::INCREASE:
out[2 * i + 0] = in[2 * i + 0] * cup[ntup - count]; out[2 * i + 0] = (float) (in[2 * i + 0] * cup[ntup - count]);
out[2 * i + 1] = in[2 * i + 1] * cup[ntup - count]; out[2 * i + 1] = (float) (in[2 * i + 1] * cup[ntup - count]);
if (count-- == 0) if (count-- == 0)
state = UNMUTED; state = SSQLState::UNMUTED;
break; break;
case UNMUTED: case SSQLState::UNMUTED:
if (tr_signal[i] == 0) if (tr_signal[i] == 0)
{ {
state = DECREASE; state = SSQLState::DECREASE;
count = ntdown; count = ntdown;
} }
out[2 * i + 0] = in[2 * i + 0]; out[2 * i + 0] = in[2 * i + 0];
out[2 * i + 1] = in[2 * i + 1]; out[2 * i + 1] = in[2 * i + 1];
break; break;
case DECREASE: case SSQLState::DECREASE:
out[2 * i + 0] = in[2 * i + 0] * cdown[ntdown - count]; out[2 * i + 0] = (float) (in[2 * i + 0] * cdown[ntdown - count]);
out[2 * i + 1] = in[2 * i + 1] * cdown[ntdown - count]; out[2 * i + 1] = (float) (in[2 * i + 1] * cdown[ntdown - count]);
if (count-- == 0) if (count-- == 0)
state = MUTED; state = SSQLState::MUTED;
break; break;
} }
} }

View File

@ -75,26 +75,33 @@ class DBQLP;
class WDSP_API SSQL // Syllabic Squelch class WDSP_API SSQL // Syllabic Squelch
{ {
public: public:
enum class SSQLState
{
MUTED,
INCREASE,
UNMUTED,
DECREASE
};
int run; // 0 if squelch system is OFF; 1 if it's ON int run; // 0 if squelch system is OFF; 1 if it's ON
int size; // size of input/output buffers int size; // size of input/output buffers
float* in; // squelch input signal buffer float* in; // squelch input signal buffer
float* out; // squelch output signal buffer float* out; // squelch output signal buffer
int rate; // sample rate int rate; // sample rate
int state; // state machine control SSQLState state; // state machine control
int count; // count variable for raised cosine transitions int count; // count variable for raised cosine transitions
double tup; // time for turn-on transition double tup; // time for turn-on transition
double tdown; // time for turn-off transition double tdown; // time for turn-off transition
int ntup; // number of samples for turn-on transition int ntup; // number of samples for turn-on transition
int ntdown; // number of samples for turn-off transition int ntdown; // number of samples for turn-off transition
float* cup; // coefficients for up-slew std::vector<double> cup; // coefficients for up-slew
float* cdown; // coefficients for down-slew std::vector<double> cdown; // coefficients for down-slew
double muted_gain; // audio gain while muted; 0.0 for complete silence double muted_gain; // audio gain while muted; 0.0 for complete silence
float* b1; // buffer to hold output of dc-block function std::vector<float> b1; // buffer to hold output of dc-block function
float* ibuff; // buffer containing only 'I' component std::vector<float> ibuff; // buffer containing only 'I' component
float* ftovbuff; // buffer containing output of f to v converter std::vector<float> ftovbuff; // buffer containing output of f to v converter
float* lpbuff; // buffer containing output of low-pass filter std::vector<float> lpbuff; // buffer containing output of low-pass filter
int* wdbuff; // buffer containing output of window detector std::vector<int> wdbuff; // buffer containing output of window detector
CBL *dcbl; // pointer to DC Blocker data structure CBL *dcbl; // pointer to DC Blocker data structure
FTOV *cvtr; // pointer to F to V Converter data structure FTOV *cvtr; // pointer to F to V Converter data structure
DBQLP *filt; // pointer to Bi-Quad Low-Pass Filter data structure DBQLP *filt; // pointer to Bi-Quad Low-Pass Filter data structure
@ -114,7 +121,7 @@ public:
double tr_voltage; // trigger voltage double tr_voltage; // trigger voltage
double mute_mult; // multiplier for successive voltage calcs when muted double mute_mult; // multiplier for successive voltage calcs when muted
double unmute_mult; // multiplier for successive voltage calcs when unmuted double unmute_mult; // multiplier for successive voltage calcs when unmuted
int* tr_signal; // trigger signal, 0 or 1 std::vector<int> tr_signal; // trigger signal, 0 or 1
SSQL( SSQL(
int run, int run,

View File

@ -146,7 +146,8 @@ void WCPAGC::flush()
void WCPAGC::execute() void WCPAGC::execute()
{ {
int i, j, k; int i;
int k;
double mult; double mult;
if (run) if (run)
@ -155,8 +156,8 @@ void WCPAGC::execute()
{ {
for (i = 0; i < io_buffsize; i++) for (i = 0; i < io_buffsize; i++)
{ {
out[2 * i + 0] = fixed_gain * in[2 * i + 0]; out[2 * i + 0] = (float) (fixed_gain * in[2 * i + 0]);
out[2 * i + 1] = fixed_gain * in[2 * i + 1]; out[2 * i + 1] = (float) (fixed_gain * in[2 * i + 1]);
} }
return; return;
@ -173,8 +174,10 @@ void WCPAGC::execute()
out_sample[0] = ring[2 * out_index + 0]; out_sample[0] = ring[2 * out_index + 0];
out_sample[1] = ring[2 * out_index + 1]; out_sample[1] = ring[2 * out_index + 1];
abs_out_sample = abs_ring[out_index]; abs_out_sample = abs_ring[out_index];
double xr = ring[2 * in_index + 0] = in[2 * i + 0]; ring[2 * in_index + 0] = in[2 * i + 0];
double xi = ring[2 * in_index + 1] = in[2 * i + 1]; ring[2 * in_index + 1] = in[2 * i + 1];
double xr = ring[2 * in_index + 0];
double xi = ring[2 * in_index + 1];
if (pmode == 0) if (pmode == 0)
abs_ring[in_index] = std::max(fabs(xr), fabs(xi)); abs_ring[in_index] = std::max(fabs(xr), fabs(xi));
@ -189,7 +192,7 @@ void WCPAGC::execute()
ring_max = 0.0; ring_max = 0.0;
k = out_index; k = out_index;
for (j = 0; j < attack_buffsize; j++) for (int j = 0; j < attack_buffsize; j++)
{ {
if (++k == ring_buffsize) if (++k == ring_buffsize)
k = 0; k = 0;
@ -323,6 +326,8 @@ void WCPAGC::execute()
} }
break; break;
} }
default:
break;
} }
if (volts < min_volts) if (volts < min_volts)
@ -330,8 +335,8 @@ void WCPAGC::execute()
gain = volts * inv_out_target; gain = volts * inv_out_target;
mult = (out_target - slope_constant * std::min (0.0, log10(inv_max_input * volts))) / volts; mult = (out_target - slope_constant * std::min (0.0, log10(inv_max_input * volts))) / volts;
out[2 * i + 0] = out_sample[0] * mult; out[2 * i + 0] = (float) (out_sample[0] * mult);
out[2 * i + 1] = out_sample[1] * mult; out[2 * i + 1] = (float) (out_sample[1] * mult);
} }
} }
else if (out != in) else if (out != in)
@ -406,7 +411,7 @@ void WCPAGC::setMode(int _mode)
void WCPAGC::setFixed(double _fixed_agc) void WCPAGC::setFixed(double _fixed_agc)
{ {
fixed_gain = pow (10.0, (double) _fixed_agc / 20.0); fixed_gain = pow (10.0, _fixed_agc / 20.0);
loadWcpAGC(); loadWcpAGC();
} }
@ -428,7 +433,7 @@ void WCPAGC::setHang(int _hang)
loadWcpAGC(); loadWcpAGC();
} }
void WCPAGC::getHangLevel(double *hangLevel) void WCPAGC::getHangLevel(double *hangLevel) const
//for line on bandscope //for line on bandscope
{ {
*hangLevel = 20.0 * log10(hang_level / 0.637); *hangLevel = 20.0 * log10(hang_level / 0.637);
@ -437,7 +442,8 @@ void WCPAGC::getHangLevel(double *hangLevel)
void WCPAGC::setHangLevel(double _hangLevel) void WCPAGC::setHangLevel(double _hangLevel)
//for line on bandscope //for line on bandscope
{ {
double convert, tmp; double convert;
double tmp;
if (max_input > min_volts) if (max_input > min_volts)
{ {
@ -451,7 +457,7 @@ void WCPAGC::setHangLevel(double _hangLevel)
loadWcpAGC(); loadWcpAGC();
} }
void WCPAGC::getHangThreshold(int *hangthreshold) void WCPAGC::getHangThreshold(int *hangthreshold) const
//for slider in setup //for slider in setup
{ {
*hangthreshold = (int) (100.0 * hang_thresh); *hangthreshold = (int) (100.0 * hang_thresh);
@ -464,7 +470,7 @@ void WCPAGC::setHangThreshold(int _hangthreshold)
loadWcpAGC(); loadWcpAGC();
} }
void WCPAGC::getTop(double *max_agc) void WCPAGC::getTop(double *max_agc) const
//for AGC Max Gain in setup //for AGC Max Gain in setup
{ {
*max_agc = 20 * log10 (max_gain); *max_agc = 20 * log10 (max_gain);
@ -473,7 +479,7 @@ void WCPAGC::getTop(double *max_agc)
void WCPAGC::setTop(double _max_agc) void WCPAGC::setTop(double _max_agc)
//for AGC Max Gain in setup //for AGC Max Gain in setup
{ {
max_gain = pow (10.0, (double) _max_agc / 20.0); max_gain = pow (10.0, _max_agc / 20.0);
loadWcpAGC(); loadWcpAGC();
} }
@ -489,9 +495,9 @@ void WCPAGC::setMaxInputLevel(double _level)
loadWcpAGC(); loadWcpAGC();
} }
void WCPAGC::setRun(int state) void WCPAGC::setRun(int _state)
{ {
run = state; run = _state;
} }
} // namespace WDSP } // namespace WDSP

View File

@ -145,11 +145,11 @@ public:
void setAttack(int attack); void setAttack(int attack);
void setDecay(int decay); void setDecay(int decay);
void setHang(int hang); void setHang(int hang);
void getHangLevel(double *hangLevel); void getHangLevel(double *hangLevel) const;
void setHangLevel(double hangLevel); void setHangLevel(double hangLevel);
void getHangThreshold(int *hangthreshold); void getHangThreshold(int *hangthreshold) const;
void setHangThreshold(int hangthreshold); void setHangThreshold(int hangthreshold);
void getTop(double *max_agc); void getTop(double *max_agc) const;
void setTop(double max_agc); void setTop(double max_agc);
void setSlope(int slope); void setSlope(int slope);
void setMaxInputLevel(double level); void setMaxInputLevel(double level);