mirror of
https://github.com/f4exb/sdrangel.git
synced 2024-11-24 17:08:36 -05:00
WDSP: rework former IIR classes
This commit is contained in:
parent
b9e3b10a6b
commit
71fe079ee3
@ -571,19 +571,19 @@ void WDSPRxSink::applySettings(const WDSPRxSettings& settings, bool force)
|
||||
// CW Peaking
|
||||
|
||||
if ((m_settings.m_cwPeaking != settings.m_cwPeaking) || force) {
|
||||
WDSP::SPEAK::SetSPCWRun(*m_rxa, settings.m_cwPeaking ? 1 : 0);
|
||||
m_rxa->speak->setRun(settings.m_cwPeaking ? 1 : 0);
|
||||
}
|
||||
|
||||
if ((m_settings.m_cwPeakFrequency != settings.m_cwPeakFrequency) || force) {
|
||||
WDSP::SPEAK::SetSPCWFreq(*m_rxa, settings.m_cwPeakFrequency);
|
||||
m_rxa->speak->setFreq(settings.m_cwPeakFrequency);
|
||||
}
|
||||
|
||||
if ((m_settings.m_cwBandwidth != settings.m_cwBandwidth) || force) {
|
||||
WDSP::SPEAK::SetSPCWBandwidth(*m_rxa, settings.m_cwBandwidth);
|
||||
m_rxa->speak->setBandwidth(settings.m_cwBandwidth);
|
||||
}
|
||||
|
||||
if ((m_settings.m_cwGain != settings.m_cwGain) || force) {
|
||||
WDSP::SPEAK::SetSPCWGain(*m_rxa, settings.m_cwGain);
|
||||
m_rxa->speak->setGain(settings.m_cwGain);
|
||||
}
|
||||
|
||||
// Noise Blanker
|
||||
|
28
wdsp/RXA.cpp
28
wdsp/RXA.cpp
@ -482,7 +482,7 @@ RXA* RXA::create_rxa (
|
||||
0.02); // tau
|
||||
|
||||
// CW peaking filter
|
||||
rxa->speak = SPEAK::create_speak (
|
||||
rxa->speak = new SPEAK(
|
||||
0, // run
|
||||
rxa->dsp_size, // buffer size,
|
||||
rxa->midbuff, // pointer to input buffer
|
||||
@ -500,7 +500,7 @@ RXA* RXA::create_rxa (
|
||||
double def_freq[2] = {2125.0, 2295.0};
|
||||
double def_bw[2] = {75.0, 75.0};
|
||||
double def_gain[2] = {1.0, 1.0};
|
||||
rxa->mpeak = MPEAK::create_mpeak (
|
||||
rxa->mpeak = new MPEAK(
|
||||
0, // run
|
||||
rxa->dsp_size, // size
|
||||
rxa->midbuff, // pointer to input buffer
|
||||
@ -567,8 +567,8 @@ void RXA::destroy_rxa (RXA *rxa)
|
||||
delete (rxa->rsmpout);
|
||||
PANEL::destroy_panel (rxa->panel);
|
||||
SSQL::destroy_ssql (rxa->ssql);
|
||||
MPEAK::destroy_mpeak (rxa->mpeak);
|
||||
SPEAK::destroy_speak (rxa->speak);
|
||||
delete (rxa->mpeak);
|
||||
delete (rxa->speak);
|
||||
delete (rxa->cbl);
|
||||
delete (rxa->sip1);
|
||||
delete (rxa->bp1);
|
||||
@ -627,8 +627,8 @@ void RXA::flush_rxa (RXA *rxa)
|
||||
rxa->bp1->flush();
|
||||
rxa->sip1->flush();
|
||||
rxa->cbl->flush();
|
||||
SPEAK::flush_speak (rxa->speak);
|
||||
MPEAK::flush_mpeak (rxa->mpeak);
|
||||
rxa->speak->flush();
|
||||
rxa->mpeak->flush();
|
||||
SSQL::flush_ssql (rxa->ssql);
|
||||
PANEL::flush_panel (rxa->panel);
|
||||
rxa->rsmpout->flush();
|
||||
@ -666,8 +666,8 @@ void RXA::xrxa (RXA *rxa)
|
||||
rxa->agcmeter->execute();
|
||||
rxa->sip1->execute(0);
|
||||
rxa->cbl->execute();
|
||||
SPEAK::xspeak (rxa->speak);
|
||||
MPEAK::xmpeak (rxa->mpeak);
|
||||
rxa->speak->execute();
|
||||
rxa->mpeak->execute();
|
||||
SSQL::xssql (rxa->ssql);
|
||||
PANEL::xpanel (rxa->panel);
|
||||
rxa->amsq->execute();
|
||||
@ -773,8 +773,8 @@ void RXA::setDSPSamplerate (RXA *rxa, int dsp_rate)
|
||||
rxa->agcmeter->setSamplerate(rxa->dsp_rate);
|
||||
rxa->sip1->setSamplerate(rxa->dsp_rate);
|
||||
rxa->cbl->setSamplerate(rxa->dsp_rate);
|
||||
SPEAK::setSamplerate_speak (rxa->speak, rxa->dsp_rate);
|
||||
MPEAK::setSamplerate_mpeak (rxa->mpeak, rxa->dsp_rate);
|
||||
rxa->speak->setSamplerate(rxa->dsp_rate);
|
||||
rxa->mpeak->setSamplerate(rxa->dsp_rate);
|
||||
SSQL::setSamplerate_ssql (rxa->ssql, rxa->dsp_rate);
|
||||
PANEL::setSamplerate_panel (rxa->panel, rxa->dsp_rate);
|
||||
// output resampler
|
||||
@ -854,10 +854,10 @@ void RXA::setDSPBuffsize (RXA *rxa, int dsp_size)
|
||||
rxa->sip1->setSize(rxa->dsp_size);
|
||||
rxa->cbl->setBuffers(rxa->midbuff, rxa->midbuff);
|
||||
rxa->cbl->setSize(rxa->dsp_size);
|
||||
SPEAK::setBuffers_speak (rxa->speak, rxa->midbuff, rxa->midbuff);
|
||||
SPEAK::setSize_speak (rxa->speak, rxa->dsp_size);
|
||||
MPEAK::setBuffers_mpeak (rxa->mpeak, rxa->midbuff, rxa->midbuff);
|
||||
MPEAK::setSize_mpeak (rxa->mpeak, rxa->dsp_size);
|
||||
rxa->speak->setBuffers(rxa->midbuff, rxa->midbuff);
|
||||
rxa->speak->setSize(rxa->dsp_size);
|
||||
rxa->mpeak->setBuffers(rxa->midbuff, rxa->midbuff);
|
||||
rxa->mpeak->setSize(rxa->dsp_size);
|
||||
SSQL::setBuffers_ssql (rxa->ssql, rxa->midbuff, rxa->midbuff);
|
||||
SSQL::setSize_ssql (rxa->ssql, rxa->dsp_size);
|
||||
PANEL::setBuffers_panel (rxa->panel, rxa->midbuff, rxa->midbuff);
|
||||
|
14
wdsp/TXA.cpp
14
wdsp/TXA.cpp
@ -114,7 +114,7 @@ TXA* TXA::create_txa (
|
||||
2, // 1 to use Q, 2 to use I for input
|
||||
0); // 0, no copy
|
||||
|
||||
txa->phrot = PHROT::create_phrot (
|
||||
txa->phrot = new PHROT(
|
||||
0, // run
|
||||
txa->dsp_size, // size
|
||||
txa->midbuff, // input buffer
|
||||
@ -548,7 +548,7 @@ void TXA::destroy_txa (TXA *txa)
|
||||
delete (txa->eqp);
|
||||
delete (txa->amsq);
|
||||
delete (txa->micmeter);
|
||||
PHROT::destroy_phrot (txa->phrot);
|
||||
delete (txa->phrot);
|
||||
PANEL::destroy_panel (txa->panel);
|
||||
delete (txa->gen0);
|
||||
delete (txa->rsmpin);
|
||||
@ -566,7 +566,7 @@ void TXA::flush_txa (TXA* txa)
|
||||
txa->rsmpin->flush();
|
||||
txa->gen0->flush();
|
||||
PANEL::flush_panel (txa->panel);
|
||||
PHROT::flush_phrot (txa->phrot);
|
||||
txa->phrot->flush();
|
||||
txa->micmeter->flush ();
|
||||
txa->amsq->flush ();
|
||||
txa->eqp->flush();
|
||||
@ -600,7 +600,7 @@ void xtxa (TXA* txa)
|
||||
txa->rsmpin->execute(); // input resampler
|
||||
txa->gen0->execute(); // input signal generator
|
||||
PANEL::xpanel (txa->panel); // includes MIC gain
|
||||
PHROT::xphrot (txa->phrot); // phase rotator
|
||||
txa->phrot->execute(); // phase rotator
|
||||
txa->micmeter->execute (); // MIC meter
|
||||
txa->amsq->xcap (); // downward expander capture
|
||||
txa->amsq->execute (); // downward expander action
|
||||
@ -698,7 +698,7 @@ void TXA::setDSPSamplerate (TXA *txa, int dsp_rate)
|
||||
// dsp_rate blocks
|
||||
txa->gen0->setSamplerate(txa->dsp_rate);
|
||||
PANEL::setSamplerate_panel (txa->panel, txa->dsp_rate);
|
||||
PHROT::setSamplerate_phrot (txa->phrot, txa->dsp_rate);
|
||||
txa->phrot->setSamplerate(txa->dsp_rate);
|
||||
txa->micmeter->setSamplerate (txa->dsp_rate);
|
||||
txa->amsq->setSamplerate (txa->dsp_rate);
|
||||
txa->eqp->setSamplerate (txa->dsp_rate);
|
||||
@ -760,8 +760,8 @@ void TXA::setDSPBuffsize (TXA *txa, int dsp_size)
|
||||
txa->gen0->setSize(txa->dsp_size);
|
||||
PANEL::setBuffers_panel (txa->panel, txa->midbuff, txa->midbuff);
|
||||
PANEL::setSize_panel (txa->panel, txa->dsp_size);
|
||||
PHROT::setBuffers_phrot (txa->phrot, txa->midbuff, txa->midbuff);
|
||||
PHROT::setSize_phrot (txa->phrot, txa->dsp_size);
|
||||
txa->phrot->setBuffers(txa->midbuff, txa->midbuff);
|
||||
txa->phrot->setSize(txa->dsp_size);
|
||||
txa->micmeter->setBuffers (txa->midbuff);
|
||||
txa->micmeter->setSize (txa->dsp_size);
|
||||
txa->amsq->setBuffers (txa->midbuff, txa->midbuff, txa->midbuff);
|
||||
|
143
wdsp/bqbp.cpp
143
wdsp/bqbp.cpp
@ -27,8 +27,6 @@ warren@wpratt.com
|
||||
|
||||
#include "comm.hpp"
|
||||
#include "bqbp.hpp"
|
||||
#include "RXA.hpp"
|
||||
#include "TXA.hpp"
|
||||
|
||||
namespace WDSP {
|
||||
|
||||
@ -38,122 +36,119 @@ namespace WDSP {
|
||||
* *
|
||||
********************************************************************************************************/
|
||||
|
||||
void BQBP::calc_bqbp(BQBP *a)
|
||||
void BQBP::calc()
|
||||
{
|
||||
double f0, w0, bw, q, sn, cs, c, den;
|
||||
bw = a->f_high - a->f_low;
|
||||
f0 = (a->f_high + a->f_low) / 2.0;
|
||||
|
||||
bw = f_high - f_low;
|
||||
f0 = (f_high + f_low) / 2.0;
|
||||
q = f0 / bw;
|
||||
w0 = TWOPI * f0 / a->rate;
|
||||
w0 = TWOPI * f0 / rate;
|
||||
sn = sin(w0);
|
||||
cs = cos(w0);
|
||||
c = sn / (2.0 * q);
|
||||
den = 1.0 + c;
|
||||
a->a0 = +c / den;
|
||||
a->a1 = 0.0;
|
||||
a->a2 = -c / den;
|
||||
a->b1 = 2.0 * cs / den;
|
||||
a->b2 = (c - 1.0) / den;
|
||||
flush_bqbp(a);
|
||||
a0 = +c / den;
|
||||
a1 = 0.0;
|
||||
a2 = -c / den;
|
||||
b1 = 2.0 * cs / den;
|
||||
b2 = (c - 1.0) / den;
|
||||
flush();
|
||||
}
|
||||
|
||||
BQBP* BQBP::create_bqbp(int run, int size, float* in, float* out, double rate, double f_low, double f_high, double gain, int nstages)
|
||||
BQBP::BQBP(
|
||||
int _run,
|
||||
int _size,
|
||||
float* _in,
|
||||
float* _out,
|
||||
double _rate,
|
||||
double _f_low,
|
||||
double _f_high,
|
||||
double _gain,
|
||||
int _nstages
|
||||
) :
|
||||
run(_run),
|
||||
size(_size),
|
||||
in(_in),
|
||||
out(_out),
|
||||
rate(_rate),
|
||||
f_low(_f_low),
|
||||
f_high(_f_high),
|
||||
gain(_gain),
|
||||
nstages(_nstages)
|
||||
{
|
||||
BQBP *a = new BQBP;
|
||||
a->run = run;
|
||||
a->size = size;
|
||||
a->in = in;
|
||||
a->out = out;
|
||||
a->rate = rate;
|
||||
a->f_low = f_low;
|
||||
a->f_high = f_high;
|
||||
a->gain = gain;
|
||||
a->nstages = nstages;
|
||||
a->x0 = new double[a->nstages * 2]; // (float*)malloc0(a->nstages * sizeof(complex));
|
||||
a->x1 = new double[a->nstages * 2]; // (float*)malloc0(a->nstages * sizeof(complex));
|
||||
a->x2 = new double[a->nstages * 2]; // (float*)malloc0(a->nstages * sizeof(complex));
|
||||
a->y0 = new double[a->nstages * 2]; // (float*)malloc0(a->nstages * sizeof(complex));
|
||||
a->y1 = new double[a->nstages * 2]; // (float*)malloc0(a->nstages * sizeof(complex));
|
||||
a->y2 = new double[a->nstages * 2]; // (float*)malloc0(a->nstages * sizeof(complex));
|
||||
calc_bqbp(a);
|
||||
return a;
|
||||
x0.resize(nstages * 2); // (float*)malloc0(nstages * sizeof(complex));
|
||||
x1.resize(nstages * 2); // (float*)malloc0(nstages * sizeof(complex));
|
||||
x2.resize(nstages * 2); // (float*)malloc0(nstages * sizeof(complex));
|
||||
y0.resize(nstages * 2); // (float*)malloc0(nstages * sizeof(complex));
|
||||
y1.resize(nstages * 2); // (float*)malloc0(nstages * sizeof(complex));
|
||||
y2.resize(nstages * 2); // (float*)malloc0(nstages * sizeof(complex));
|
||||
calc();
|
||||
}
|
||||
|
||||
void BQBP::destroy_bqbp(BQBP *a)
|
||||
void BQBP::flush()
|
||||
{
|
||||
delete[](a->y2);
|
||||
delete[](a->y1);
|
||||
delete[](a->y0);
|
||||
delete[](a->x2);
|
||||
delete[](a->x1);
|
||||
delete[](a->x0);
|
||||
delete(a);
|
||||
}
|
||||
|
||||
void BQBP::flush_bqbp(BQBP *a)
|
||||
{
|
||||
int i;
|
||||
for (i = 0; i < a->nstages; i++)
|
||||
for (int i = 0; i < nstages; i++)
|
||||
{
|
||||
a->x1[2 * i + 0] = a->x2[2 * i + 0] = a->y1[2 * i + 0] = a->y2[2 * i + 0] = 0.0;
|
||||
a->x1[2 * i + 1] = a->x2[2 * i + 1] = a->y1[2 * i + 1] = a->y2[2 * i + 1] = 0.0;
|
||||
x1[2 * i + 0] = x2[2 * i + 0] = y1[2 * i + 0] = y2[2 * i + 0] = 0.0;
|
||||
x1[2 * i + 1] = x2[2 * i + 1] = y1[2 * i + 1] = y2[2 * i + 1] = 0.0;
|
||||
}
|
||||
}
|
||||
|
||||
void BQBP::xbqbp(BQBP *a)
|
||||
void BQBP::execute()
|
||||
{
|
||||
if (a->run)
|
||||
if (run)
|
||||
{
|
||||
int i, j, n;
|
||||
|
||||
for (i = 0; i < a->size; i++)
|
||||
for (i = 0; i < size; i++)
|
||||
{
|
||||
for (j = 0; j < 2; j++)
|
||||
{
|
||||
a->x0[j] = a->gain * a->in[2 * i + j];
|
||||
x0[j] = gain * in[2 * i + j];
|
||||
|
||||
for (n = 0; n < a->nstages; n++)
|
||||
for (n = 0; n < nstages; n++)
|
||||
{
|
||||
if (n > 0)
|
||||
a->x0[2 * n + j] = a->y0[2 * (n - 1) + j];
|
||||
x0[2 * n + j] = y0[2 * (n - 1) + j];
|
||||
|
||||
a->y0[2 * n + j] = a->a0 * a->x0[2 * n + j]
|
||||
+ a->a1 * a->x1[2 * n + j]
|
||||
+ a->a2 * a->x2[2 * n + j]
|
||||
+ a->b1 * a->y1[2 * n + j]
|
||||
+ a->b2 * a->y2[2 * n + j];
|
||||
a->y2[2 * n + j] = a->y1[2 * n + j];
|
||||
a->y1[2 * n + j] = a->y0[2 * n + j];
|
||||
a->x2[2 * n + j] = a->x1[2 * n + j];
|
||||
a->x1[2 * n + j] = a->x0[2 * n + j];
|
||||
y0[2 * n + j] = a0 * x0[2 * n + j]
|
||||
+ a1 * x1[2 * n + j]
|
||||
+ a2 * x2[2 * n + j]
|
||||
+ b1 * y1[2 * n + j]
|
||||
+ b2 * y2[2 * n + j];
|
||||
y2[2 * n + j] = y1[2 * n + j];
|
||||
y1[2 * n + j] = y0[2 * n + j];
|
||||
x2[2 * n + j] = x1[2 * n + j];
|
||||
x1[2 * n + j] = x0[2 * n + j];
|
||||
}
|
||||
|
||||
a->out[2 * i + j] = a->y0[2 * (a->nstages - 1) + j];
|
||||
out[2 * i + j] = y0[2 * (nstages - 1) + j];
|
||||
}
|
||||
}
|
||||
}
|
||||
else if (a->out != a->in)
|
||||
else if (out != in)
|
||||
{
|
||||
std::copy(a->in, a->in + a->size * 2, a->out);
|
||||
std::copy(in, in + size * 2, out);
|
||||
}
|
||||
}
|
||||
|
||||
void BQBP::setBuffers_bqbp(BQBP *a, float* in, float* out)
|
||||
void BQBP::setBuffers(float* _in, float* _out)
|
||||
{
|
||||
a->in = in;
|
||||
a->out = out;
|
||||
in = _in;
|
||||
out = _out;
|
||||
}
|
||||
|
||||
void BQBP::setSamplerate_bqbp(BQBP *a, int rate)
|
||||
void BQBP::setSamplerate( int _rate)
|
||||
{
|
||||
a->rate = rate;
|
||||
calc_bqbp(a);
|
||||
rate = _rate;
|
||||
calc();
|
||||
}
|
||||
|
||||
void BQBP::setSize_bqbp(BQBP *a, int size)
|
||||
void BQBP::setSize(int _size)
|
||||
{
|
||||
a->size = size;
|
||||
flush_bqbp(a);
|
||||
size = _size;
|
||||
flush();
|
||||
}
|
||||
|
||||
} // namespace WDSP
|
||||
|
@ -34,6 +34,8 @@ warren@wpratt.com
|
||||
#ifndef wdsp_bqbp_h
|
||||
#define wdsp_bqbp_h
|
||||
|
||||
#include <vector>
|
||||
|
||||
#include "export.h"
|
||||
|
||||
namespace WDSP {
|
||||
@ -51,18 +53,31 @@ public:
|
||||
double gain;
|
||||
int nstages;
|
||||
double a0, a1, a2, b1, b2;
|
||||
double* x0, * x1, * x2, * y0, * y1, * y2;
|
||||
std::vector<double> x0, x1, x2, y0, y1, y2;
|
||||
|
||||
static BQBP* create_bqbp(int run, int size, float* in, float* out, double rate, double f_low, double f_high, double gain, int nstages);
|
||||
static void destroy_bqbp(BQBP *a);
|
||||
static void flush_bqbp(BQBP *a);
|
||||
static void xbqbp(BQBP *a);
|
||||
static void setBuffers_bqbp(BQBP *a, float* in, float* out);
|
||||
static void setSamplerate_bqbp(BQBP *a, int rate);
|
||||
static void setSize_bqbp(BQBP *a, int size);
|
||||
BQBP(
|
||||
int run,
|
||||
int size,
|
||||
float* in,
|
||||
float* out,
|
||||
double rate,
|
||||
double f_low,
|
||||
double f_high,
|
||||
double gain,
|
||||
int nstages
|
||||
);
|
||||
BQBP(const BQBP&) = delete;
|
||||
BQBP& operator=(BQBP& other) = delete;
|
||||
~BQBP() = default;
|
||||
|
||||
void flush();
|
||||
void execute();
|
||||
void setBuffers(float* in, float* out);
|
||||
void setSamplerate(int rate);
|
||||
void setSize(int size);
|
||||
|
||||
private:
|
||||
static void calc_bqbp(BQBP *a);
|
||||
void calc();
|
||||
};
|
||||
|
||||
} // namespace WDSP
|
||||
|
142
wdsp/bqlp.cpp
142
wdsp/bqlp.cpp
@ -27,8 +27,6 @@ warren@wpratt.com
|
||||
|
||||
#include "comm.hpp"
|
||||
#include "bqlp.hpp"
|
||||
#include "RXA.hpp"
|
||||
#include "TXA.hpp"
|
||||
|
||||
namespace WDSP {
|
||||
|
||||
@ -38,118 +36,114 @@ namespace WDSP {
|
||||
* *
|
||||
********************************************************************************************************/
|
||||
|
||||
void BQLP::calc_bqlp(BQLP *a)
|
||||
void BQLP::calc()
|
||||
{
|
||||
double w0, cs, c, den;
|
||||
w0 = TWOPI * a->fc / (double)a->rate;
|
||||
|
||||
w0 = TWOPI * fc / (double)rate;
|
||||
cs = cos(w0);
|
||||
c = sin(w0) / (2.0 * a->Q);
|
||||
c = sin(w0) / (2.0 * Q);
|
||||
den = 1.0 + c;
|
||||
a->a0 = 0.5 * (1.0 - cs) / den;
|
||||
a->a1 = (1.0 - cs) / den;
|
||||
a->a2 = 0.5 * (1.0 - cs) / den;
|
||||
a->b1 = 2.0 * cs / den;
|
||||
a->b2 = (c - 1.0) / den;
|
||||
flush_bqlp(a);
|
||||
a0 = 0.5 * (1.0 - cs) / den;
|
||||
a1 = (1.0 - cs) / den;
|
||||
a2 = 0.5 * (1.0 - cs) / den;
|
||||
b1 = 2.0 * cs / den;
|
||||
b2 = (c - 1.0) / den;
|
||||
flush();
|
||||
}
|
||||
|
||||
BQLP* BQLP::create_bqlp(int run, int size, float* in, float* out, double rate, double fc, double Q, double gain, int nstages)
|
||||
BQLP::BQLP(
|
||||
int _run,
|
||||
int _size,
|
||||
float* _in,
|
||||
float* _out,
|
||||
double _rate,
|
||||
double _fc,
|
||||
double _Q,
|
||||
double _gain,
|
||||
int _nstages
|
||||
) :
|
||||
run(_run),
|
||||
size(_size),
|
||||
in(_in),
|
||||
out(_out),
|
||||
rate(_rate),
|
||||
fc(_fc),
|
||||
Q(_Q),
|
||||
gain(_gain),
|
||||
nstages(_nstages)
|
||||
{
|
||||
BQLP *a = new BQLP;
|
||||
a->run = run;
|
||||
a->size = size;
|
||||
a->in = in;
|
||||
a->out = out;
|
||||
a->rate = rate;
|
||||
a->fc = fc;
|
||||
a->Q = Q;
|
||||
a->gain = gain;
|
||||
a->nstages = nstages;
|
||||
a->x0 = new double[a->nstages * 2]; // (float*)malloc0(a->nstages * sizeof(complex));
|
||||
a->x1 = new double[a->nstages * 2]; // (float*)malloc0(a->nstages * sizeof(complex));
|
||||
a->x2 = new double[a->nstages * 2]; // (float*)malloc0(a->nstages * sizeof(complex));
|
||||
a->y0 = new double[a->nstages * 2]; // (float*)malloc0(a->nstages * sizeof(complex));
|
||||
a->y1 = new double[a->nstages * 2]; // (float*)malloc0(a->nstages * sizeof(complex));
|
||||
a->y2 = new double[a->nstages * 2]; // (float*)malloc0(a->nstages * sizeof(complex));
|
||||
calc_bqlp(a);
|
||||
return a;
|
||||
x0.resize(nstages * 2); // (float*)malloc0(nstages * sizeof(complex));
|
||||
x1.resize(nstages * 2); // (float*)malloc0(nstages * sizeof(complex));
|
||||
x2.resize(nstages * 2); // (float*)malloc0(nstages * sizeof(complex));
|
||||
y0.resize(nstages * 2); // (float*)malloc0(nstages * sizeof(complex));
|
||||
y1.resize(nstages * 2); // (float*)malloc0(nstages * sizeof(complex));
|
||||
y2.resize(nstages * 2); // (float*)malloc0(nstages * sizeof(complex));
|
||||
calc();
|
||||
}
|
||||
|
||||
void BQLP::destroy_bqlp(BQLP *a)
|
||||
void BQLP::flush()
|
||||
{
|
||||
delete[](a->y2);
|
||||
delete[](a->y1);
|
||||
delete[](a->y0);
|
||||
delete[](a->x2);
|
||||
delete[](a->x1);
|
||||
delete[](a->x0);
|
||||
delete(a);
|
||||
}
|
||||
|
||||
void BQLP::flush_bqlp(BQLP *a)
|
||||
{
|
||||
int i;
|
||||
for (i = 0; i < a->nstages; i++)
|
||||
for (int i = 0; i < nstages; i++)
|
||||
{
|
||||
a->x1[2 * i + 0] = a->x2[2 * i + 0] = a->y1[2 * i + 0] = a->y2[2 * i + 0] = 0.0;
|
||||
a->x1[2 * i + 1] = a->x2[2 * i + 1] = a->y1[2 * i + 1] = a->y2[2 * i + 1] = 0.0;
|
||||
x1[2 * i + 0] = x2[2 * i + 0] = y1[2 * i + 0] = y2[2 * i + 0] = 0.0;
|
||||
x1[2 * i + 1] = x2[2 * i + 1] = y1[2 * i + 1] = y2[2 * i + 1] = 0.0;
|
||||
}
|
||||
}
|
||||
|
||||
void BQLP::xbqlp(BQLP *a)
|
||||
void BQLP::execute()
|
||||
{
|
||||
if (a->run)
|
||||
if (run)
|
||||
{
|
||||
int i, j, n;
|
||||
|
||||
for (i = 0; i < a->size; i++)
|
||||
for (i = 0; i < size; i++)
|
||||
{
|
||||
for (j = 0; j < 2; j++)
|
||||
{
|
||||
a->x0[j] = a->gain * a->in[2 * i + j];
|
||||
x0[j] = gain * in[2 * i + j];
|
||||
|
||||
for (n = 0; n < a->nstages; n++)
|
||||
for (n = 0; n < nstages; n++)
|
||||
{
|
||||
if (n > 0)
|
||||
a->x0[2 * n + j] = a->y0[2 * (n - 1) + j];
|
||||
a->y0[2 * n + j] = a->a0 * a->x0[2 * n + j]
|
||||
+ a->a1 * a->x1[2 * n + j]
|
||||
+ a->a2 * a->x2[2 * n + j]
|
||||
+ a->b1 * a->y1[2 * n + j]
|
||||
+ a->b2 * a->y2[2 * n + j];
|
||||
a->y2[2 * n + j] = a->y1[2 * n + j];
|
||||
a->y1[2 * n + j] = a->y0[2 * n + j];
|
||||
a->x2[2 * n + j] = a->x1[2 * n + j];
|
||||
a->x1[2 * n + j] = a->x0[2 * n + j];
|
||||
x0[2 * n + j] = y0[2 * (n - 1) + j];
|
||||
y0[2 * n + j] = a0 * x0[2 * n + j]
|
||||
+ a1 * x1[2 * n + j]
|
||||
+ a2 * x2[2 * n + j]
|
||||
+ b1 * y1[2 * n + j]
|
||||
+ b2 * y2[2 * n + j];
|
||||
y2[2 * n + j] = y1[2 * n + j];
|
||||
y1[2 * n + j] = y0[2 * n + j];
|
||||
x2[2 * n + j] = x1[2 * n + j];
|
||||
x1[2 * n + j] = x0[2 * n + j];
|
||||
}
|
||||
|
||||
a->out[2 * i + j] = a->y0[2 * (a->nstages - 1) + j];
|
||||
out[2 * i + j] = y0[2 * (nstages - 1) + j];
|
||||
}
|
||||
}
|
||||
}
|
||||
else if (a->out != a->in)
|
||||
else if (out != in)
|
||||
{
|
||||
std::copy(a->in, a->in + a->size * 2, a->out);
|
||||
std::copy(in, in + size * 2, out);
|
||||
}
|
||||
}
|
||||
|
||||
void BQLP::setBuffers_bqlp(BQLP *a, float* in, float* out)
|
||||
void BQLP::setBuffers(float* _in, float* _out)
|
||||
{
|
||||
a->in = in;
|
||||
a->out = out;
|
||||
in = _in;
|
||||
out = _out;
|
||||
}
|
||||
|
||||
void BQLP::setSamplerate_bqlp(BQLP *a, int rate)
|
||||
void BQLP::setSamplerate(int _rate)
|
||||
{
|
||||
a->rate = rate;
|
||||
calc_bqlp(a);
|
||||
rate = _rate;
|
||||
calc();
|
||||
}
|
||||
|
||||
void BQLP::setSize_bqlp(BQLP *a, int size)
|
||||
void BQLP::setSize(int _size)
|
||||
{
|
||||
a->size = size;
|
||||
flush_bqlp(a);
|
||||
size = _size;
|
||||
flush();
|
||||
}
|
||||
|
||||
|
||||
} // namespace WDSP
|
||||
|
@ -34,6 +34,8 @@ warren@wpratt.com
|
||||
#ifndef wdsp_bqlp_h
|
||||
#define wdsp_bqlp_h
|
||||
|
||||
#include <vector>
|
||||
|
||||
#include "export.h"
|
||||
|
||||
namespace WDSP {
|
||||
@ -51,18 +53,31 @@ public:
|
||||
double gain;
|
||||
int nstages;
|
||||
double a0, a1, a2, b1, b2;
|
||||
double* x0, * x1, * x2, * y0, * y1, * y2;
|
||||
std::vector<double> x0, x1, x2, y0, y1, y2;
|
||||
|
||||
static BQLP* create_bqlp(int run, int size, float* in, float* out, double rate, double fc, double Q, double gain, int nstages);
|
||||
static void destroy_bqlp(BQLP *a);
|
||||
static void flush_bqlp(BQLP *a);
|
||||
static void xbqlp(BQLP *a);
|
||||
static void setBuffers_bqlp(BQLP *a, float* in, float* out);
|
||||
static void setSamplerate_bqlp(BQLP *a, int rate);
|
||||
static void setSize_bqlp(BQLP *a, int size);
|
||||
BQLP(
|
||||
int run,
|
||||
int size,
|
||||
float* in,
|
||||
float* out,
|
||||
double rate,
|
||||
double fc,
|
||||
double Q,
|
||||
double gain,
|
||||
int nstages
|
||||
);
|
||||
BQLP(const BQLP&) = delete;
|
||||
BQLP& operator=(BQLP& other) = delete;
|
||||
~BQLP() = default;
|
||||
|
||||
void flush();
|
||||
void execute();
|
||||
void setBuffers(float* in, float* out);
|
||||
void setSamplerate(int rate);
|
||||
void setSize(int size);
|
||||
|
||||
private:
|
||||
static void calc_bqlp(BQLP *a);
|
||||
void calc();
|
||||
};
|
||||
|
||||
} // namespace WDSP
|
||||
|
141
wdsp/dbqbp.cpp
141
wdsp/dbqbp.cpp
@ -27,8 +27,6 @@ warren@wpratt.com
|
||||
|
||||
#include "comm.hpp"
|
||||
#include "dbqbp.hpp"
|
||||
#include "RXA.hpp"
|
||||
#include "TXA.hpp"
|
||||
|
||||
namespace WDSP {
|
||||
|
||||
@ -38,118 +36,115 @@ namespace WDSP {
|
||||
* *
|
||||
********************************************************************************************************/
|
||||
|
||||
void DBQBP::calc_dbqbp(DBQBP *a)
|
||||
void DBQBP::calc()
|
||||
{
|
||||
double f0, w0, bw, q, sn, cs, c, den;
|
||||
bw = a->f_high - a->f_low;
|
||||
f0 = (a->f_high + a->f_low) / 2.0;
|
||||
|
||||
bw = f_high - f_low;
|
||||
f0 = (f_high + f_low) / 2.0;
|
||||
q = f0 / bw;
|
||||
w0 = TWOPI * f0 / a->rate;
|
||||
w0 = TWOPI * f0 / rate;
|
||||
sn = sin(w0);
|
||||
cs = cos(w0);
|
||||
c = sn / (2.0 * q);
|
||||
den = 1.0 + c;
|
||||
a->a0 = +c / den;
|
||||
a->a1 = 0.0;
|
||||
a->a2 = -c / den;
|
||||
a->b1 = 2.0 * cs / den;
|
||||
a->b2 = (c - 1.0) / den;
|
||||
flush_dbqbp(a);
|
||||
a0 = +c / den;
|
||||
a1 = 0.0;
|
||||
a2 = -c / den;
|
||||
b1 = 2.0 * cs / den;
|
||||
b2 = (c - 1.0) / den;
|
||||
flush();
|
||||
}
|
||||
|
||||
DBQBP* DBQBP::create_dbqbp(int run, int size, float* in, float* out, double rate, double f_low, double f_high, double gain, int nstages)
|
||||
DBQBP::DBQBP(
|
||||
int _run,
|
||||
int _size,
|
||||
float* _in,
|
||||
float* _out,
|
||||
double _rate,
|
||||
double _f_low,
|
||||
double _f_high,
|
||||
double _gain,
|
||||
int _nstages
|
||||
) :
|
||||
run(_run),
|
||||
size(_size),
|
||||
in(_in),
|
||||
out(_out),
|
||||
rate(_rate),
|
||||
f_low(_f_low),
|
||||
f_high(_f_high),
|
||||
gain(_gain),
|
||||
nstages(_nstages)
|
||||
{
|
||||
DBQBP *a = new DBQBP;
|
||||
a->run = run;
|
||||
a->size = size;
|
||||
a->in = in;
|
||||
a->out = out;
|
||||
a->rate = rate;
|
||||
a->f_low = f_low;
|
||||
a->f_high = f_high;
|
||||
a->gain = gain;
|
||||
a->nstages = nstages;
|
||||
a->x0 = new double[a->nstages]; // (float*)malloc0(a->nstages * sizeof(float));
|
||||
a->x1 = new double[a->nstages]; // (float*)malloc0(a->nstages * sizeof(float));
|
||||
a->x2 = new double[a->nstages]; // (float*)malloc0(a->nstages * sizeof(float));
|
||||
a->y0 = new double[a->nstages]; // (float*)malloc0(a->nstages * sizeof(float));
|
||||
a->y1 = new double[a->nstages]; // (float*)malloc0(a->nstages * sizeof(float));
|
||||
a->y2 = new double[a->nstages]; // (float*)malloc0(a->nstages * sizeof(float));
|
||||
calc_dbqbp(a);
|
||||
return a;
|
||||
x0.resize(nstages); // (float*)malloc0(nstages * sizeof(float));
|
||||
x1.resize(nstages); // (float*)malloc0(nstages * sizeof(float));
|
||||
x2.resize(nstages); // (float*)malloc0(nstages * sizeof(float));
|
||||
y0.resize(nstages); // (float*)malloc0(nstages * sizeof(float));
|
||||
y1.resize(nstages); // (float*)malloc0(nstages * sizeof(float));
|
||||
y2.resize(nstages); // (float*)malloc0(nstages * sizeof(float));
|
||||
calc();
|
||||
}
|
||||
|
||||
void DBQBP::destroy_dbqbp(DBQBP *a)
|
||||
void DBQBP::flush()
|
||||
{
|
||||
delete[](a->y2);
|
||||
delete[](a->y1);
|
||||
delete[](a->y0);
|
||||
delete[](a->x2);
|
||||
delete[](a->x1);
|
||||
delete[](a->x0);
|
||||
delete(a);
|
||||
}
|
||||
|
||||
void DBQBP::flush_dbqbp(DBQBP *a)
|
||||
{
|
||||
int i;
|
||||
for (i = 0; i < a->nstages; i++)
|
||||
for (int i = 0; i < nstages; i++)
|
||||
{
|
||||
a->x1[i] = a->x2[i] = a->y1[i] = a->y2[i] = 0.0;
|
||||
x1[i] = x2[i] = y1[i] = y2[i] = 0.0;
|
||||
}
|
||||
}
|
||||
|
||||
void DBQBP::xdbqbp(DBQBP *a)
|
||||
void DBQBP::execute()
|
||||
{
|
||||
if (a->run)
|
||||
if (run)
|
||||
{
|
||||
int i, n;
|
||||
|
||||
for (i = 0; i < a->size; i++)
|
||||
for (i = 0; i < size; i++)
|
||||
{
|
||||
a->x0[0] = a->gain * a->in[i];
|
||||
x0[0] = gain * in[i];
|
||||
|
||||
for (n = 0; n < a->nstages; n++)
|
||||
for (n = 0; n < nstages; n++)
|
||||
{
|
||||
if (n > 0)
|
||||
a->x0[n] = a->y0[n - 1];
|
||||
x0[n] = y0[n - 1];
|
||||
|
||||
a->y0[n] = a->a0 * a->x0[n]
|
||||
+ a->a1 * a->x1[n]
|
||||
+ a->a2 * a->x2[n]
|
||||
+ a->b1 * a->y1[n]
|
||||
+ a->b2 * a->y2[n];
|
||||
a->y2[n] = a->y1[n];
|
||||
a->y1[n] = a->y0[n];
|
||||
a->x2[n] = a->x1[n];
|
||||
a->x1[n] = a->x0[n];
|
||||
y0[n] = a0 * x0[n]
|
||||
+ a1 * x1[n]
|
||||
+ a2 * x2[n]
|
||||
+ b1 * y1[n]
|
||||
+ b2 * y2[n];
|
||||
y2[n] = y1[n];
|
||||
y1[n] = y0[n];
|
||||
x2[n] = x1[n];
|
||||
x1[n] = x0[n];
|
||||
}
|
||||
|
||||
a->out[i] = a->y0[a->nstages - 1];
|
||||
out[i] = y0[nstages - 1];
|
||||
}
|
||||
}
|
||||
else if (a->out != a->in)
|
||||
else if (out != in)
|
||||
{
|
||||
memcpy(a->out, a->in, a->size * sizeof(float));
|
||||
std::copy(in, in + size, out);
|
||||
}
|
||||
}
|
||||
|
||||
void DBQBP::setBuffers_dbqbp(DBQBP *a, float* in, float* out)
|
||||
void DBQBP::setBuffers(float* _in, float* _out)
|
||||
{
|
||||
a->in = in;
|
||||
a->out = out;
|
||||
in = _in;
|
||||
out = _out;
|
||||
}
|
||||
|
||||
void DBQBP::setSamplerate_dbqbp(DBQBP *a, int rate)
|
||||
void DBQBP::setSamplerate(int _rate)
|
||||
{
|
||||
a->rate = rate;
|
||||
calc_dbqbp(a);
|
||||
rate = _rate;
|
||||
calc();
|
||||
}
|
||||
|
||||
void DBQBP::setSize_dbqbp(DBQBP *a, int size)
|
||||
void DBQBP::setSize(int _size)
|
||||
{
|
||||
a->size = size;
|
||||
flush_dbqbp(a);
|
||||
size = _size;
|
||||
flush();
|
||||
}
|
||||
|
||||
} // namespace WDSP
|
||||
|
@ -34,6 +34,8 @@ warren@wpratt.com
|
||||
#ifndef wdsp_dbqbp_h
|
||||
#define wdsp_dbqbp_h
|
||||
|
||||
#include <vector>
|
||||
|
||||
#include "export.h"
|
||||
|
||||
namespace WDSP {
|
||||
@ -51,19 +53,32 @@ public:
|
||||
double gain;
|
||||
int nstages;
|
||||
double a0, a1, a2, b1, b2;
|
||||
double* x0, * x1, * x2, * y0, * y1, * y2;
|
||||
std::vector<double> x0, x1, x2, y0, y1, y2;
|
||||
|
||||
// Double Bi-Quad Band-Pass
|
||||
static DBQBP* create_dbqbp(int run, int size, float* in, float* out, double rate, double f_low, double f_high, double gain, int nstages);
|
||||
static void destroy_dbqbp(DBQBP *a);
|
||||
static void flush_dbqbp(DBQBP *a);
|
||||
static void xdbqbp(DBQBP *a);
|
||||
static void setBuffers_dbqbp(DBQBP *a, float* in, float* out);
|
||||
static void setSamplerate_dbqbp(DBQBP *a, int rate);
|
||||
static void setSize_dbqbp(DBQBP *a, int size);
|
||||
DBQBP(
|
||||
int run,
|
||||
int size,
|
||||
float* in,
|
||||
float* out,
|
||||
double rate,
|
||||
double f_low,
|
||||
double f_high,
|
||||
double gain,
|
||||
int nstages
|
||||
);
|
||||
DBQBP(const DBQBP&) = delete;
|
||||
DBQBP& operator=(DBQBP& other) = delete;
|
||||
~DBQBP() = default;
|
||||
|
||||
void flush();
|
||||
void execute();
|
||||
void setBuffers(float* in, float* out);
|
||||
void setSamplerate(int rate);
|
||||
void setSize(int size);
|
||||
|
||||
private:
|
||||
static void calc_dbqbp(DBQBP *a);
|
||||
void calc();
|
||||
};
|
||||
|
||||
} // namespace WDSP
|
||||
|
139
wdsp/dbqlp.cpp
139
wdsp/dbqlp.cpp
@ -27,8 +27,6 @@ warren@wpratt.com
|
||||
|
||||
#include "comm.hpp"
|
||||
#include "dbqlp.hpp"
|
||||
#include "RXA.hpp"
|
||||
#include "TXA.hpp"
|
||||
|
||||
namespace WDSP {
|
||||
|
||||
@ -38,114 +36,111 @@ namespace WDSP {
|
||||
* *
|
||||
********************************************************************************************************/
|
||||
|
||||
void DBQLP::calc_dbqlp(DBQLP *a)
|
||||
void DBQLP::calc()
|
||||
{
|
||||
float w0, cs, c, den;
|
||||
w0 = TWOPI * a->fc / (float)a->rate;
|
||||
|
||||
w0 = TWOPI * fc / (float)rate;
|
||||
cs = cos(w0);
|
||||
c = sin(w0) / (2.0 * a->Q);
|
||||
c = sin(w0) / (2.0 * Q);
|
||||
den = 1.0 + c;
|
||||
a->a0 = 0.5 * (1.0 - cs) / den;
|
||||
a->a1 = (1.0 - cs) / den;
|
||||
a->a2 = 0.5 * (1.0 - cs) / den;
|
||||
a->b1 = 2.0 * cs / den;
|
||||
a->b2 = (c - 1.0) / den;
|
||||
flush_dbqlp(a);
|
||||
a0 = 0.5 * (1.0 - cs) / den;
|
||||
a1 = (1.0 - cs) / den;
|
||||
a2 = 0.5 * (1.0 - cs) / den;
|
||||
b1 = 2.0 * cs / den;
|
||||
b2 = (c - 1.0) / den;
|
||||
flush();
|
||||
}
|
||||
|
||||
DBQLP* DBQLP::create_dbqlp(int run, int size, float* in, float* out, double rate, double fc, double Q, double gain, int nstages)
|
||||
DBQLP::DBQLP(
|
||||
int _run,
|
||||
int _size,
|
||||
float* _in,
|
||||
float* _out,
|
||||
double _rate,
|
||||
double _fc,
|
||||
double _Q,
|
||||
double _gain,
|
||||
int _nstages
|
||||
) :
|
||||
run(_run),
|
||||
size(_size),
|
||||
in(_in),
|
||||
out(_out),
|
||||
rate(_rate),
|
||||
fc(_fc),
|
||||
Q(_Q),
|
||||
gain(_gain),
|
||||
nstages(_nstages)
|
||||
{
|
||||
DBQLP *a = new DBQLP;
|
||||
a->run = run;
|
||||
a->size = size;
|
||||
a->in = in;
|
||||
a->out = out;
|
||||
a->rate = rate;
|
||||
a->fc = fc;
|
||||
a->Q = Q;
|
||||
a->gain = gain;
|
||||
a->nstages = nstages;
|
||||
a->x0 = new double[a->nstages]; // (float*)malloc0(a->nstages * sizeof(float));
|
||||
a->x1 = new double[a->nstages]; // (float*)malloc0(a->nstages * sizeof(float));
|
||||
a->x2 = new double[a->nstages]; // (float*)malloc0(a->nstages * sizeof(float));
|
||||
a->y0 = new double[a->nstages]; // (float*)malloc0(a->nstages * sizeof(float));
|
||||
a->y1 = new double[a->nstages]; // (float*)malloc0(a->nstages * sizeof(float));
|
||||
a->y2 = new double[a->nstages]; // (float*)malloc0(a->nstages * sizeof(float));
|
||||
calc_dbqlp(a);
|
||||
return a;
|
||||
x0.resize(nstages); // (float*)malloc0(nstages * sizeof(float));
|
||||
x1.resize(nstages); // (float*)malloc0(nstages * sizeof(float));
|
||||
x2.resize(nstages); // (float*)malloc0(nstages * sizeof(float));
|
||||
y0.resize(nstages); // (float*)malloc0(nstages * sizeof(float));
|
||||
y1.resize(nstages); // (float*)malloc0(nstages * sizeof(float));
|
||||
y2.resize(nstages); // (float*)malloc0(nstages * sizeof(float));
|
||||
calc();
|
||||
}
|
||||
|
||||
void DBQLP::destroy_dbqlp(DBQLP *a)
|
||||
void DBQLP::flush()
|
||||
{
|
||||
delete[](a->y2);
|
||||
delete[](a->y1);
|
||||
delete[](a->y0);
|
||||
delete[](a->x2);
|
||||
delete[](a->x1);
|
||||
delete[](a->x0);
|
||||
delete(a);
|
||||
}
|
||||
|
||||
void DBQLP::flush_dbqlp(DBQLP *a)
|
||||
{
|
||||
int i;
|
||||
for (i = 0; i < a->nstages; i++)
|
||||
for (int i = 0; i < nstages; i++)
|
||||
{
|
||||
a->x1[i] = a->x2[i] = a->y1[i] = a->y2[i] = 0.0;
|
||||
x1[i] = x2[i] = y1[i] = y2[i] = 0.0;
|
||||
}
|
||||
}
|
||||
|
||||
void DBQLP::xdbqlp(DBQLP *a)
|
||||
void DBQLP::execute()
|
||||
{
|
||||
if (a->run)
|
||||
if (run)
|
||||
{
|
||||
int i, n;
|
||||
|
||||
for (i = 0; i < a->size; i++)
|
||||
for (i = 0; i < size; i++)
|
||||
{
|
||||
a->x0[0] = a->gain * a->in[i];
|
||||
x0[0] = gain * in[i];
|
||||
|
||||
for (n = 0; n < a->nstages; n++)
|
||||
for (n = 0; n < nstages; n++)
|
||||
{
|
||||
if (n > 0)
|
||||
a->x0[n] = a->y0[n - 1];
|
||||
x0[n] = y0[n - 1];
|
||||
|
||||
a->y0[n] = a->a0 * a->x0[n]
|
||||
+ a->a1 * a->x1[n]
|
||||
+ a->a2 * a->x2[n]
|
||||
+ a->b1 * a->y1[n]
|
||||
+ a->b2 * a->y2[n];
|
||||
a->y2[n] = a->y1[n];
|
||||
a->y1[n] = a->y0[n];
|
||||
a->x2[n] = a->x1[n];
|
||||
a->x1[n] = a->x0[n];
|
||||
y0[n] = a0 * x0[n]
|
||||
+ a1 * x1[n]
|
||||
+ a2 * x2[n]
|
||||
+ b1 * y1[n]
|
||||
+ b2 * y2[n];
|
||||
y2[n] = y1[n];
|
||||
y1[n] = y0[n];
|
||||
x2[n] = x1[n];
|
||||
x1[n] = x0[n];
|
||||
}
|
||||
|
||||
a->out[i] = a->y0[a->nstages - 1];
|
||||
out[i] = y0[nstages - 1];
|
||||
}
|
||||
}
|
||||
else if (a->out != a->in)
|
||||
else if (out != in)
|
||||
{
|
||||
memcpy(a->out, a->in, a->size * sizeof(float));
|
||||
std::copy(in, in + size, out);
|
||||
}
|
||||
}
|
||||
|
||||
void DBQLP::setBuffers_dbqlp(DBQLP *a, float* in, float* out)
|
||||
void DBQLP::setBuffers(float* _in, float* _out)
|
||||
{
|
||||
a->in = in;
|
||||
a->out = out;
|
||||
in = _in;
|
||||
out = _out;
|
||||
}
|
||||
|
||||
void DBQLP::setSamplerate_dbqlp(DBQLP *a, int rate)
|
||||
void DBQLP::setSamplerate(int _rate)
|
||||
{
|
||||
a->rate = rate;
|
||||
calc_dbqlp(a);
|
||||
rate = _rate;
|
||||
calc();
|
||||
}
|
||||
|
||||
void DBQLP::setSize_dbqlp(DBQLP *a, int size)
|
||||
void DBQLP::setSize(int _size)
|
||||
{
|
||||
a->size = size;
|
||||
flush_dbqlp(a);
|
||||
size = _size;
|
||||
flush();
|
||||
}
|
||||
|
||||
} // namespace WDSP
|
||||
|
@ -34,6 +34,8 @@ warren@wpratt.com
|
||||
#ifndef wdsp_dbqlp_h
|
||||
#define wdsp_dbqlp_h
|
||||
|
||||
#include <vector>
|
||||
|
||||
#include "export.h"
|
||||
|
||||
namespace WDSP {
|
||||
@ -51,18 +53,31 @@ public:
|
||||
double gain;
|
||||
int nstages;
|
||||
double a0, a1, a2, b1, b2;
|
||||
double* x0, * x1, * x2, * y0, * y1, * y2;
|
||||
std::vector<double> x0, x1, x2, y0, y1, y2;
|
||||
|
||||
static DBQLP* create_dbqlp(int run, int size, float* in, float* out, double rate, double fc, double Q, double gain, int nstages);
|
||||
static void destroy_dbqlp(DBQLP *a);
|
||||
static void flush_dbqlp(DBQLP *a);
|
||||
static void xdbqlp(DBQLP *a);
|
||||
static void setBuffers_dbqlp(DBQLP *a, float* in, float* out);
|
||||
static void setSamplerate_dbqlp(DBQLP *a, int rate);
|
||||
static void setSize_dbqlp(DBQLP *a, int size);
|
||||
DBQLP(
|
||||
int run,
|
||||
int size,
|
||||
float* in,
|
||||
float* out,
|
||||
double rate,
|
||||
double fc,
|
||||
double Q,
|
||||
double gain,
|
||||
int nstages
|
||||
);
|
||||
DBQLP(const DBQLP&) = delete;
|
||||
DBQLP& operator=(DBQLP& other) = delete;
|
||||
~DBQLP() = default;
|
||||
|
||||
void flush();
|
||||
void execute();
|
||||
void setBuffers(float* in, float* out);
|
||||
void setSamplerate(int rate);
|
||||
void setSize(int size);
|
||||
|
||||
private:
|
||||
static void calc_dbqlp(DBQLP *a);
|
||||
void calc();
|
||||
};
|
||||
|
||||
} // namespace WDSP
|
||||
|
118
wdsp/dsphp.cpp
118
wdsp/dsphp.cpp
@ -38,103 +38,91 @@ namespace WDSP {
|
||||
* *
|
||||
********************************************************************************************************/
|
||||
|
||||
void DSPHP::calc_dsphp(DSPHP *a)
|
||||
void DSPHP::calc()
|
||||
{
|
||||
double g;
|
||||
a->x0 = new double[a->nstages]; // (float*)malloc0(a->nstages * sizeof(float));
|
||||
a->x1 = new double[a->nstages]; // (float*)malloc0(a->nstages * sizeof(float));
|
||||
a->y0 = new double[a->nstages]; // (float*)malloc0(a->nstages * sizeof(float));
|
||||
a->y1 = new double[a->nstages]; // (float*)malloc0(a->nstages * sizeof(float));
|
||||
g = exp(-TWOPI * a->fc / a->rate);
|
||||
a->b0 = +0.5 * (1.0 + g);
|
||||
a->b1 = -0.5 * (1.0 + g);
|
||||
a->a1 = -g;
|
||||
x0.resize(nstages); // (float*)malloc0(nstages * sizeof(float));
|
||||
x1.resize(nstages); // (float*)malloc0(nstages * sizeof(float));
|
||||
y0.resize(nstages); // (float*)malloc0(nstages * sizeof(float));
|
||||
y1.resize(nstages); // (float*)malloc0(nstages * sizeof(float));
|
||||
g = exp(-TWOPI * fc / rate);
|
||||
b0 = +0.5 * (1.0 + g);
|
||||
b1 = -0.5 * (1.0 + g);
|
||||
a1 = -g;
|
||||
}
|
||||
|
||||
DSPHP* DSPHP::create_dsphp(int run, int size, float* in, float* out, double rate, double fc, int nstages)
|
||||
DSPHP::DSPHP(
|
||||
int _run,
|
||||
int _size,
|
||||
float* _in,
|
||||
float* _out,
|
||||
double _rate,
|
||||
double _fc,
|
||||
int _nstages
|
||||
)
|
||||
{
|
||||
DSPHP *a = new DSPHP;
|
||||
a->run = run;
|
||||
a->size = size;
|
||||
a->in = in;
|
||||
a->out = out;
|
||||
a->rate = rate;
|
||||
a->fc = fc;
|
||||
a->nstages = nstages;
|
||||
calc_dsphp(a);
|
||||
return a;
|
||||
run = _run;
|
||||
size = _size;
|
||||
in = _in;
|
||||
out = _out;
|
||||
rate = _rate;
|
||||
fc = _fc;
|
||||
nstages = _nstages;
|
||||
calc();
|
||||
}
|
||||
|
||||
void DSPHP::decalc_dsphp(DSPHP *a)
|
||||
void DSPHP::flush()
|
||||
{
|
||||
delete[](a->y1);
|
||||
delete[](a->y0);
|
||||
delete[](a->x1);
|
||||
delete[](a->x0);
|
||||
std::fill(x0.begin(), x0.end(), 0);
|
||||
std::fill(x1.begin(), x1.end(), 0);
|
||||
std::fill(y0.begin(), y0.end(), 0);
|
||||
std::fill(y1.begin(), y1.end(), 0);
|
||||
}
|
||||
|
||||
void DSPHP::destroy_dsphp(DSPHP *a)
|
||||
void DSPHP::execute()
|
||||
{
|
||||
decalc_dsphp(a);
|
||||
delete(a);
|
||||
}
|
||||
|
||||
void DSPHP::flush_dsphp(DSPHP *a)
|
||||
{
|
||||
memset(a->x0, 0, a->nstages * sizeof(float));
|
||||
memset(a->x1, 0, a->nstages * sizeof(float));
|
||||
memset(a->y0, 0, a->nstages * sizeof(float));
|
||||
memset(a->y1, 0, a->nstages * sizeof(float));
|
||||
}
|
||||
|
||||
void DSPHP::xdsphp(DSPHP *a)
|
||||
{
|
||||
if (a->run)
|
||||
if (run)
|
||||
{
|
||||
int i, n;
|
||||
|
||||
for (i = 0; i < a->size; i++)
|
||||
for (int i = 0; i < size; i++)
|
||||
{
|
||||
a->x0[0] = a->in[i];
|
||||
x0[0] = in[i];
|
||||
|
||||
for (n = 0; n < a->nstages; n++)
|
||||
for (int n = 0; n < nstages; n++)
|
||||
{
|
||||
if (n > 0)
|
||||
a->x0[n] = a->y0[n - 1];
|
||||
x0[n] = y0[n - 1];
|
||||
|
||||
a->y0[n] = a->b0 * a->x0[n]
|
||||
+ a->b1 * a->x1[n]
|
||||
- a->a1 * a->y1[n];
|
||||
a->y1[n] = a->y0[n];
|
||||
a->x1[n] = a->x0[n];
|
||||
y0[n] = b0 * x0[n]
|
||||
+ b1 * x1[n]
|
||||
- a1 * y1[n];
|
||||
y1[n] = y0[n];
|
||||
x1[n] = x0[n];
|
||||
}
|
||||
|
||||
a->out[i] = a->y0[a->nstages - 1];
|
||||
out[i] = y0[nstages - 1];
|
||||
}
|
||||
}
|
||||
else if (a->out != a->in)
|
||||
else if (out != in)
|
||||
{
|
||||
memcpy(a->out, a->in, a->size * sizeof(float));
|
||||
std::copy(in, in + size, out);
|
||||
}
|
||||
}
|
||||
|
||||
void DSPHP::setBuffers_dsphp(DSPHP *a, float* in, float* out)
|
||||
void DSPHP::setBuffers(float* _in, float* _out)
|
||||
{
|
||||
a->in = in;
|
||||
a->out = out;
|
||||
in = _in;
|
||||
out = _out;
|
||||
}
|
||||
|
||||
void DSPHP::setSamplerate_dsphp(DSPHP *a, int rate)
|
||||
void DSPHP::setSamplerate(int _rate)
|
||||
{
|
||||
decalc_dsphp(a);
|
||||
a->rate = rate;
|
||||
calc_dsphp(a);
|
||||
rate = _rate;
|
||||
calc();
|
||||
}
|
||||
|
||||
void DSPHP::setSize_dsphp(DSPHP *a, int size)
|
||||
void DSPHP::setSize(int _size)
|
||||
{
|
||||
a->size = size;
|
||||
flush_dsphp(a);
|
||||
size = _size;
|
||||
}
|
||||
|
||||
} // namespace WDSP
|
||||
|
@ -34,6 +34,8 @@ warren@wpratt.com
|
||||
#ifndef wdsp_dsphp_h
|
||||
#define wdsp_dsphp_h
|
||||
|
||||
#include <vector>
|
||||
|
||||
#include "export.h"
|
||||
|
||||
namespace WDSP {
|
||||
@ -49,19 +51,31 @@ public:
|
||||
double fc;
|
||||
int nstages;
|
||||
double a1, b0, b1;
|
||||
double* x0, * x1, * y0, * y1;
|
||||
std::vector<double> x0, x1, y0, y1;
|
||||
|
||||
static DSPHP* create_dsphp(int run, int size, float* in, float* out, double rate, double fc, int nstages);
|
||||
static void destroy_dsphp(DSPHP *a);
|
||||
static void flush_dsphp(DSPHP *a);
|
||||
static void xdsphp(DSPHP *a);
|
||||
static void setBuffers_dsphp(DSPHP *a, float* in, float* out);
|
||||
static void setSamplerate_dsphp(DSPHP *a, int rate);
|
||||
static void setSize_dsphp(DSPHP *a, int size);
|
||||
DSPHP(
|
||||
int run,
|
||||
int size,
|
||||
float* in,
|
||||
float* out,
|
||||
double rate,
|
||||
double fc,
|
||||
int nstages
|
||||
);
|
||||
DSPHP(const DSPHP&) = delete;
|
||||
DSPHP& operator=(DSPHP& other) = delete;
|
||||
~DSPHP() = default;
|
||||
|
||||
void destroy();
|
||||
void flush();
|
||||
void execute();
|
||||
void setBuffers(float* in, float* out);
|
||||
void setSamplerate(int rate);
|
||||
void setSize(int size);
|
||||
|
||||
private:
|
||||
static void calc_dsphp(DSPHP *a);
|
||||
static void decalc_dsphp(DSPHP *a);
|
||||
void calc();
|
||||
void decalc();
|
||||
};
|
||||
|
||||
} // namespace WDSP
|
||||
|
20
wdsp/fmd.cpp
20
wdsp/fmd.cpp
@ -53,7 +53,15 @@ void FMD::calc()
|
||||
// pll audio gain
|
||||
again = rate / (deviation * TWOPI);
|
||||
// CTCSS Removal
|
||||
sntch = SNOTCH::create_snotch(1, size, out, out, (int)rate, ctcss_freq, 0.0002);
|
||||
sntch = new SNOTCH(
|
||||
1,
|
||||
size,
|
||||
out,
|
||||
out,
|
||||
(int) rate,
|
||||
ctcss_freq,
|
||||
0.0002)
|
||||
;
|
||||
// detector limiter
|
||||
plim = new WCPAGC(
|
||||
1, // run - always ON
|
||||
@ -84,7 +92,7 @@ void FMD::calc()
|
||||
void FMD::decalc()
|
||||
{
|
||||
delete (plim);
|
||||
SNOTCH::destroy_snotch(sntch);
|
||||
delete (sntch);
|
||||
}
|
||||
|
||||
FMD::FMD(
|
||||
@ -162,7 +170,7 @@ void FMD::flush()
|
||||
fil_out = 0.0;
|
||||
omega = 0.0;
|
||||
fmdc = 0.0;
|
||||
SNOTCH::flush_snotch (sntch);
|
||||
sntch->flush();
|
||||
plim->flush();
|
||||
}
|
||||
|
||||
@ -200,7 +208,7 @@ void FMD::execute()
|
||||
// audio filter
|
||||
FIRCORE::xfircore (paud);
|
||||
// CTCSS Removal
|
||||
SNOTCH::xsnotch (sntch);
|
||||
sntch->execute();
|
||||
if (lim_run)
|
||||
{
|
||||
for (i = 0; i < 2 * size; i++)
|
||||
@ -275,13 +283,13 @@ void FMD::setDeviation(double _deviation)
|
||||
void FMD::setCTCSSFreq(double freq)
|
||||
{
|
||||
ctcss_freq = freq;
|
||||
SNOTCH::SetSNCTCSSFreq (sntch, ctcss_freq);
|
||||
sntch->setFreq(ctcss_freq);
|
||||
}
|
||||
|
||||
void FMD::setCTCSSRun(int run)
|
||||
{
|
||||
sntch_run = run;
|
||||
SNOTCH::SetSNCTCSSRun (sntch, sntch_run);
|
||||
sntch->setRun(sntch_run);
|
||||
}
|
||||
|
||||
void FMD::setNCde(int nc)
|
||||
|
204
wdsp/mpeak.cpp
204
wdsp/mpeak.cpp
@ -39,135 +39,121 @@ namespace WDSP {
|
||||
* *
|
||||
********************************************************************************************************/
|
||||
|
||||
void MPEAK::calc_mpeak (MPEAK *a)
|
||||
void MPEAK::calc()
|
||||
{
|
||||
int i;
|
||||
a->tmp = new float[a->size * 2]; // (float *) malloc0 (a->size * sizeof (complex));
|
||||
a->mix = new float[a->size * 2]; // (float *) malloc0 (a->size * sizeof (complex));
|
||||
for (i = 0; i < a->npeaks; i++)
|
||||
tmp.resize(size * 2); // (float *) malloc0 (size * sizeof (complex));
|
||||
mix.resize(size * 2); // (float *) malloc0 (size * sizeof (complex));
|
||||
for (int i = 0; i < npeaks; i++)
|
||||
{
|
||||
a->pfil[i] = SPEAK::create_speak (
|
||||
pfil[i] = new SPEAK(
|
||||
1,
|
||||
a->size,
|
||||
a->in,
|
||||
a->tmp,
|
||||
a->rate,
|
||||
a->f[i],
|
||||
a->bw[i],
|
||||
a->gain[i],
|
||||
a->nstages,
|
||||
size,
|
||||
in,
|
||||
tmp.data(),
|
||||
rate,
|
||||
f[i],
|
||||
bw[i],
|
||||
gain[i],
|
||||
nstages,
|
||||
1
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
void MPEAK::decalc_mpeak (MPEAK *a)
|
||||
void MPEAK::decalc()
|
||||
{
|
||||
int i;
|
||||
for (i = 0; i < a->npeaks; i++)
|
||||
SPEAK::destroy_speak (a->pfil[i]);
|
||||
delete[] (a->mix);
|
||||
delete[] (a->tmp);
|
||||
for (int i = 0; i < npeaks; i++)
|
||||
delete (pfil[i]);
|
||||
}
|
||||
|
||||
MPEAK* MPEAK::create_mpeak (
|
||||
int run,
|
||||
int size,
|
||||
float* in,
|
||||
float* out,
|
||||
int rate,
|
||||
int npeaks,
|
||||
int* enable,
|
||||
double* f,
|
||||
double* bw,
|
||||
double* gain,
|
||||
int nstages
|
||||
MPEAK::MPEAK(
|
||||
int _run,
|
||||
int _size,
|
||||
float* _in,
|
||||
float* _out,
|
||||
int _rate,
|
||||
int _npeaks,
|
||||
int* _enable,
|
||||
double* _f,
|
||||
double* _bw,
|
||||
double* _gain,
|
||||
int _nstages
|
||||
)
|
||||
{
|
||||
MPEAK *a = new MPEAK;
|
||||
a->run = run;
|
||||
a->size = size;
|
||||
a->in = in;
|
||||
a->out = out;
|
||||
a->rate = rate;
|
||||
a->npeaks = npeaks;
|
||||
a->nstages = nstages;
|
||||
a->enable = new int[a->npeaks]; // (int *) malloc0 (a->npeaks * sizeof (int));
|
||||
a->f = new double[a->npeaks]; // (float *) malloc0 (a->npeaks * sizeof (float));
|
||||
a->bw = new double[a->npeaks]; // (float *) malloc0 (a->npeaks * sizeof (float));
|
||||
a->gain = new double[a->npeaks]; // (float *) malloc0 (a->npeaks * sizeof (float));
|
||||
memcpy (a->enable, enable, a->npeaks * sizeof (int));
|
||||
memcpy (a->f, f, a->npeaks * sizeof (double));
|
||||
memcpy (a->bw, bw, a->npeaks * sizeof (double));
|
||||
memcpy (a->gain, gain, a->npeaks * sizeof (double));
|
||||
a->pfil = new SPEAK*[a->npeaks]; // (SPEAK *) malloc0 (a->npeaks * sizeof (SPEAK));
|
||||
calc_mpeak (a);
|
||||
return a;
|
||||
run = _run;
|
||||
size = _size;
|
||||
in = _in;
|
||||
out = _out;
|
||||
rate = _rate;
|
||||
npeaks = _npeaks;
|
||||
nstages = _nstages;
|
||||
enable.resize(npeaks); // (int *) malloc0 (npeaks * sizeof (int));
|
||||
f.resize(npeaks); // (float *) malloc0 (npeaks * sizeof (float));
|
||||
bw.resize(npeaks); // (float *) malloc0 (npeaks * sizeof (float));
|
||||
gain.resize(npeaks); // (float *) malloc0 (npeaks * sizeof (float));
|
||||
std::copy(_enable, _enable + npeaks, enable.begin());
|
||||
std::copy(_f, _f + npeaks, f.begin());
|
||||
std::copy(_bw, _bw + npeaks, bw.begin());
|
||||
std::copy(_gain, _gain + npeaks, gain.begin());
|
||||
pfil.resize(npeaks); // (SPEAK *) malloc0 (npeaks * sizeof (SPEAK));
|
||||
calc();
|
||||
}
|
||||
|
||||
void MPEAK::destroy_mpeak (MPEAK *a)
|
||||
MPEAK::~MPEAK()
|
||||
{
|
||||
decalc_mpeak (a);
|
||||
delete[] (a->pfil);
|
||||
delete[] (a->gain);
|
||||
delete[] (a->bw);
|
||||
delete[] (a->f);
|
||||
delete[] (a->enable);
|
||||
delete (a);
|
||||
decalc();
|
||||
}
|
||||
|
||||
void MPEAK::flush_mpeak (MPEAK *a)
|
||||
void MPEAK::flush()
|
||||
{
|
||||
int i;
|
||||
for (i = 0; i < a->npeaks; i++)
|
||||
SPEAK::flush_speak (a->pfil[i]);
|
||||
for (int i = 0; i < npeaks; i++)
|
||||
pfil[i]->flush();
|
||||
}
|
||||
|
||||
void MPEAK::xmpeak (MPEAK *a)
|
||||
void MPEAK::execute()
|
||||
{
|
||||
if (a->run)
|
||||
if (run)
|
||||
{
|
||||
int i, j;
|
||||
std::fill(a->mix, a->mix + a->size * 2, 0);
|
||||
std::fill(mix.begin(), mix.end(), 0);
|
||||
|
||||
for (i = 0; i < a->npeaks; i++)
|
||||
for (int i = 0; i < npeaks; i++)
|
||||
{
|
||||
if (a->enable[i])
|
||||
if (enable[i])
|
||||
{
|
||||
SPEAK::xspeak (a->pfil[i]);
|
||||
for (j = 0; j < 2 * a->size; j++)
|
||||
a->mix[j] += a->tmp[j];
|
||||
pfil[i]->execute();
|
||||
for (int j = 0; j < 2 * size; j++)
|
||||
mix[j] += tmp[j];
|
||||
}
|
||||
}
|
||||
|
||||
std::copy(a->mix, a->mix + a->size * 2, a->out);
|
||||
std::copy(mix.begin(), mix.end(), out);
|
||||
}
|
||||
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 MPEAK::setBuffers_mpeak (MPEAK *a, float* in, float* out)
|
||||
void MPEAK::setBuffers(float* _in, float* _out)
|
||||
{
|
||||
decalc_mpeak (a);
|
||||
a->in = in;
|
||||
a->out = out;
|
||||
calc_mpeak (a);
|
||||
decalc();
|
||||
in = _in;
|
||||
out = _out;
|
||||
calc();
|
||||
}
|
||||
|
||||
void MPEAK::setSamplerate_mpeak (MPEAK *a, int rate)
|
||||
void MPEAK::setSamplerate(int _rate)
|
||||
{
|
||||
decalc_mpeak (a);
|
||||
a->rate = rate;
|
||||
calc_mpeak (a);
|
||||
decalc();
|
||||
rate = _rate;
|
||||
calc();
|
||||
}
|
||||
|
||||
void MPEAK::setSize_mpeak (MPEAK *a, int size)
|
||||
void MPEAK::setSize(int _size)
|
||||
{
|
||||
decalc_mpeak (a);
|
||||
a->size = size;
|
||||
calc_mpeak (a);
|
||||
decalc();
|
||||
size = _size;
|
||||
calc();
|
||||
}
|
||||
|
||||
/********************************************************************************************************
|
||||
@ -176,46 +162,40 @@ void MPEAK::setSize_mpeak (MPEAK *a, int size)
|
||||
* *
|
||||
********************************************************************************************************/
|
||||
|
||||
void MPEAK::SetmpeakRun (RXA& rxa, int run)
|
||||
void MPEAK::setRun(int _run)
|
||||
{
|
||||
MPEAK *a = rxa.mpeak;
|
||||
a->run = run;
|
||||
run = _run;
|
||||
}
|
||||
|
||||
void MPEAK::SetmpeakNpeaks (RXA& rxa, int npeaks)
|
||||
void MPEAK::setNpeaks(int _npeaks)
|
||||
{
|
||||
MPEAK *a = rxa.mpeak;
|
||||
a->npeaks = npeaks;
|
||||
npeaks = _npeaks;
|
||||
}
|
||||
|
||||
void MPEAK::SetmpeakFilEnable (RXA& rxa, int fil, int enable)
|
||||
void MPEAK::setFilEnable(int _fil, int _enable)
|
||||
{
|
||||
MPEAK *a = rxa.mpeak;
|
||||
a->enable[fil] = enable;
|
||||
enable[_fil] = _enable;
|
||||
}
|
||||
|
||||
void MPEAK::SetmpeakFilFreq (RXA& rxa, int fil, double freq)
|
||||
void MPEAK::setFilFreq(int _fil, double _freq)
|
||||
{
|
||||
MPEAK *a = rxa.mpeak;
|
||||
a->f[fil] = freq;
|
||||
a->pfil[fil]->f = freq;
|
||||
SPEAK::calc_speak(a->pfil[fil]);
|
||||
f[_fil] = _freq;
|
||||
pfil[_fil]->f = _freq;
|
||||
pfil[_fil]->calc();
|
||||
}
|
||||
|
||||
void MPEAK::SetmpeakFilBw (RXA& rxa, int fil, double bw)
|
||||
void MPEAK::setFilBw(int _fil, double _bw)
|
||||
{
|
||||
MPEAK *a = rxa.mpeak;
|
||||
a->bw[fil] = bw;
|
||||
a->pfil[fil]->bw = bw;
|
||||
SPEAK::calc_speak(a->pfil[fil]);
|
||||
bw[_fil] = _bw;
|
||||
pfil[_fil]->bw = _bw;
|
||||
pfil[_fil]->calc();
|
||||
}
|
||||
|
||||
void MPEAK::SetmpeakFilGain (RXA& rxa, int fil, double gain)
|
||||
void MPEAK::setFilGain(int _fil, double _gain)
|
||||
{
|
||||
MPEAK *a = rxa.mpeak;
|
||||
a->gain[fil] = gain;
|
||||
a->pfil[fil]->gain = gain;
|
||||
SPEAK::calc_speak(a->pfil[fil]);
|
||||
gain[_fil] = _gain;
|
||||
pfil[_fil]->gain = _gain;
|
||||
pfil[_fil]->calc();
|
||||
}
|
||||
|
||||
} // namespace WDSP
|
||||
|
@ -34,11 +34,12 @@ warren@wpratt.com
|
||||
#ifndef _mpeak_h
|
||||
#define _mpeak_h
|
||||
|
||||
#include <vector>
|
||||
|
||||
#include "export.h"
|
||||
|
||||
namespace WDSP {
|
||||
|
||||
class RXA;
|
||||
class SPEAK;
|
||||
|
||||
class WDSP_API MPEAK
|
||||
@ -50,16 +51,16 @@ public:
|
||||
float* out;
|
||||
int rate;
|
||||
int npeaks;
|
||||
int* enable;
|
||||
double* f;
|
||||
double* bw;
|
||||
double* gain;
|
||||
std::vector<int> enable;
|
||||
std::vector<double> f;
|
||||
std::vector<double> bw;
|
||||
std::vector<double> gain;
|
||||
int nstages;
|
||||
SPEAK** pfil;
|
||||
float* tmp;
|
||||
float* mix;
|
||||
std::vector<SPEAK*> pfil;
|
||||
std::vector<float> tmp;
|
||||
std::vector<float> mix;
|
||||
|
||||
static MPEAK* create_mpeak (
|
||||
MPEAK(
|
||||
int run,
|
||||
int size,
|
||||
float* in,
|
||||
@ -72,23 +73,26 @@ public:
|
||||
double* gain,
|
||||
int nstages
|
||||
);
|
||||
static void destroy_mpeak (MPEAK *a);
|
||||
static void flush_mpeak (MPEAK *a);
|
||||
static void xmpeak (MPEAK *a);
|
||||
static void setBuffers_mpeak (MPEAK *a, float* in, float* out);
|
||||
static void setSamplerate_mpeak (MPEAK *a, int rate);
|
||||
static void setSize_mpeak (MPEAK *a, int size);
|
||||
MPEAK(const MPEAK&) = delete;
|
||||
MPEAK& operator=(const MPEAK& other) = delete;
|
||||
~MPEAK();
|
||||
|
||||
void flush();
|
||||
void execute();
|
||||
void setBuffers(float* in, float* out);
|
||||
void setSamplerate(int rate);
|
||||
void setSize(int size);
|
||||
// RXA
|
||||
static void SetmpeakRun (RXA& rxa, int run);
|
||||
static void SetmpeakNpeaks (RXA& rxa, int npeaks);
|
||||
static void SetmpeakFilEnable (RXA& rxa, int fil, int enable);
|
||||
static void SetmpeakFilFreq (RXA& rxa, int fil, double freq);
|
||||
static void SetmpeakFilBw (RXA& rxa, int fil, double bw);
|
||||
static void SetmpeakFilGain (RXA& rxa, int fil, double gain);
|
||||
void setRun(int run);
|
||||
void setNpeaks(int npeaks);
|
||||
void setFilEnable(int fil, int enable);
|
||||
void setFilFreq(int fil, double freq);
|
||||
void setFilBw(int fil, double bw);
|
||||
void setFilGain(int fil, double gain);
|
||||
|
||||
private:
|
||||
static void calc_mpeak (MPEAK *a);
|
||||
static void decalc_mpeak (MPEAK *a);
|
||||
void calc();
|
||||
void decalc();
|
||||
};
|
||||
|
||||
} // namespace WDSP
|
||||
|
157
wdsp/phrot.cpp
157
wdsp/phrot.cpp
@ -38,108 +38,97 @@ namespace WDSP {
|
||||
* *
|
||||
********************************************************************************************************/
|
||||
|
||||
void PHROT::calc_phrot (PHROT *a)
|
||||
void PHROT::calc()
|
||||
{
|
||||
double g;
|
||||
a->x0 = new double[a->nstages]; // (float *) malloc0 (a->nstages * sizeof (float));
|
||||
a->x1 = new double[a->nstages]; // (float *) malloc0 (a->nstages * sizeof (float));
|
||||
a->y0 = new double[a->nstages]; // (float *) malloc0 (a->nstages * sizeof (float));
|
||||
a->y1 = new double[a->nstages]; // (float *) malloc0 (a->nstages * sizeof (float));
|
||||
g = tan (PI * a->fc / (float)a->rate);
|
||||
a->b0 = (g - 1.0) / (g + 1.0);
|
||||
a->b1 = 1.0;
|
||||
a->a1 = a->b0;
|
||||
x0.resize(nstages); // (float *) malloc0 (nstages * sizeof (float));
|
||||
x1.resize(nstages); // (float *) malloc0 (nstages * sizeof (float));
|
||||
y0.resize(nstages); // (float *) malloc0 (nstages * sizeof (float));
|
||||
y1.resize(nstages); // (float *) malloc0 (nstages * sizeof (float));
|
||||
g = tan (PI * fc / (float)rate);
|
||||
b0 = (g - 1.0) / (g + 1.0);
|
||||
b1 = 1.0;
|
||||
a1 = b0;
|
||||
}
|
||||
|
||||
void PHROT::decalc_phrot (PHROT *a)
|
||||
PHROT::PHROT(
|
||||
int _run,
|
||||
int _size,
|
||||
float* _in,
|
||||
float* _out,
|
||||
int _rate,
|
||||
double _fc,
|
||||
int _nstages
|
||||
) :
|
||||
reverse(0),
|
||||
run(_run),
|
||||
size(_size),
|
||||
in(_in),
|
||||
out(_out),
|
||||
rate(_rate),
|
||||
fc(_fc),
|
||||
nstages(_nstages)
|
||||
{
|
||||
delete[] (a->y1);
|
||||
delete[] (a->y0);
|
||||
delete[] (a->x1);
|
||||
delete[] (a->x0);
|
||||
calc();
|
||||
}
|
||||
|
||||
PHROT* PHROT::create_phrot (int run, int size, float* in, float* out, int rate, double fc, int nstages)
|
||||
void PHROT::flush()
|
||||
{
|
||||
PHROT *a = new PHROT;
|
||||
a->reverse = 0;
|
||||
a->run = run;
|
||||
a->size = size;
|
||||
a->in = in;
|
||||
a->out = out;
|
||||
a->rate = rate;
|
||||
a->fc = fc;
|
||||
a->nstages = nstages;
|
||||
calc_phrot (a);
|
||||
return a;
|
||||
std::fill (x0.begin(), x0.end(), 0);
|
||||
std::fill (x1.begin(), x1.end(), 0);
|
||||
std::fill (y0.begin(), y0.end(), 0);
|
||||
std::fill (y1.begin(), y1.end(), 0);
|
||||
}
|
||||
|
||||
void PHROT::destroy_phrot (PHROT *a)
|
||||
void PHROT::execute()
|
||||
{
|
||||
decalc_phrot (a);
|
||||
delete (a);
|
||||
}
|
||||
|
||||
void PHROT::flush_phrot (PHROT *a)
|
||||
{
|
||||
memset (a->x0, 0, a->nstages * sizeof (double));
|
||||
memset (a->x1, 0, a->nstages * sizeof (double));
|
||||
memset (a->y0, 0, a->nstages * sizeof (double));
|
||||
memset (a->y1, 0, a->nstages * sizeof (double));
|
||||
}
|
||||
|
||||
void PHROT::xphrot (PHROT *a)
|
||||
{
|
||||
if (a->reverse)
|
||||
if (reverse)
|
||||
{
|
||||
for (int i = 0; i < a->size; i++)
|
||||
a->in[2 * i + 0] = -a->in[2 * i + 0];
|
||||
for (int i = 0; i < size; i++)
|
||||
in[2 * i + 0] = -in[2 * i + 0];
|
||||
}
|
||||
|
||||
if (a->run)
|
||||
if (run)
|
||||
{
|
||||
int i, n;
|
||||
|
||||
for (i = 0; i < a->size; i++)
|
||||
for (int i = 0; i < size; i++)
|
||||
{
|
||||
a->x0[0] = a->in[2 * i + 0];
|
||||
x0[0] = in[2 * i + 0];
|
||||
|
||||
for (n = 0; n < a->nstages; n++)
|
||||
for (int n = 0; n < nstages; n++)
|
||||
{
|
||||
if (n > 0) a->x0[n] = a->y0[n - 1];
|
||||
a->y0[n] = a->b0 * a->x0[n]
|
||||
+ a->b1 * a->x1[n]
|
||||
- a->a1 * a->y1[n];
|
||||
a->y1[n] = a->y0[n];
|
||||
a->x1[n] = a->x0[n];
|
||||
if (n > 0) x0[n] = y0[n - 1];
|
||||
y0[n] = b0 * x0[n]
|
||||
+ b1 * x1[n]
|
||||
- a1 * y1[n];
|
||||
y1[n] = y0[n];
|
||||
x1[n] = x0[n];
|
||||
}
|
||||
|
||||
a->out[2 * i + 0] = a->y0[a->nstages - 1];
|
||||
out[2 * i + 0] = y0[nstages - 1];
|
||||
}
|
||||
}
|
||||
else if (a->out != a->in)
|
||||
else if (out != in)
|
||||
{
|
||||
std::copy( a->in, a->in + a->size * 2, a->out);
|
||||
std::copy( in, in + size * 2, out);
|
||||
}
|
||||
}
|
||||
|
||||
void PHROT::setBuffers_phrot (PHROT *a, float* in, float* out)
|
||||
void PHROT::setBuffers(float* _in, float* _out)
|
||||
{
|
||||
a->in = in;
|
||||
a->out = out;
|
||||
in = _in;
|
||||
out = _out;
|
||||
}
|
||||
|
||||
void PHROT::setSamplerate_phrot (PHROT *a, int rate)
|
||||
void PHROT::setSamplerate(int _rate)
|
||||
{
|
||||
decalc_phrot (a);
|
||||
a->rate = rate;
|
||||
calc_phrot (a);
|
||||
rate = _rate;
|
||||
calc();
|
||||
}
|
||||
|
||||
void PHROT::setSize_phrot (PHROT *a, int size)
|
||||
void PHROT::setSize(int _size)
|
||||
{
|
||||
a->size = size;
|
||||
flush_phrot (a);
|
||||
size = _size;
|
||||
flush();
|
||||
}
|
||||
|
||||
/********************************************************************************************************
|
||||
@ -148,35 +137,29 @@ void PHROT::setSize_phrot (PHROT *a, int size)
|
||||
* *
|
||||
********************************************************************************************************/
|
||||
|
||||
void PHROT::SetPHROTRun (TXA& txa, int run)
|
||||
void PHROT::setRun(int run)
|
||||
{
|
||||
PHROT *a = txa.phrot;
|
||||
a->run = run;
|
||||
run = run;
|
||||
|
||||
if (a->run)
|
||||
flush_phrot (a);
|
||||
if (run)
|
||||
flush();
|
||||
}
|
||||
|
||||
void PHROT::SetPHROTCorner (TXA& txa, double corner)
|
||||
void PHROT::setCorner(double corner)
|
||||
{
|
||||
PHROT *a = txa.phrot;
|
||||
decalc_phrot (a);
|
||||
a->fc = corner;
|
||||
calc_phrot (a);
|
||||
fc = corner;
|
||||
calc();
|
||||
}
|
||||
|
||||
void PHROT::SetPHROTNstages (TXA& txa, int nstages)
|
||||
void PHROT::setNstages(int _nstages)
|
||||
{
|
||||
PHROT *a = txa.phrot;
|
||||
decalc_phrot (a);
|
||||
a->nstages = nstages;
|
||||
calc_phrot (a);
|
||||
nstages = _nstages;
|
||||
calc();
|
||||
}
|
||||
|
||||
void PHROT::SetPHROTReverse (TXA& txa, int reverse)
|
||||
void PHROT::setReverse(int _reverse)
|
||||
{
|
||||
PHROT *a = txa.phrot;
|
||||
a->reverse = reverse;
|
||||
reverse = _reverse;
|
||||
}
|
||||
|
||||
} // namespace WDSP
|
||||
|
@ -34,6 +34,8 @@ warren@wpratt.com
|
||||
#ifndef wdsp_phrot_h
|
||||
#define wdsp_phrot_h
|
||||
|
||||
#include <vector>
|
||||
|
||||
#include "export.h"
|
||||
|
||||
namespace WDSP {
|
||||
@ -53,24 +55,35 @@ public:
|
||||
int nstages;
|
||||
// normalized such that a0 = 1
|
||||
double a1, b0, b1;
|
||||
double *x0, *x1, *y0, *y1;
|
||||
std::vector<double> x0, x1, y0, y1;
|
||||
|
||||
static PHROT* create_phrot (int run, int size, float* in, float* out, int rate, double fc, int nstages);
|
||||
static void destroy_phrot (PHROT *a);
|
||||
static void flush_phrot (PHROT *a);
|
||||
static void xphrot (PHROT *a);
|
||||
static void setBuffers_phrot (PHROT *a, float* in, float* out);
|
||||
static void setSamplerate_phrot (PHROT *a, int rate);
|
||||
static void setSize_phrot (PHROT *a, int size);
|
||||
PHROT(
|
||||
int run,
|
||||
int size,
|
||||
float* in,
|
||||
float* out,
|
||||
int rate,
|
||||
double fc,
|
||||
int nstages
|
||||
);
|
||||
PHROT(const PHROT&) = delete;
|
||||
PHROT& operator=(const PHROT& other) = delete;
|
||||
~PHROT() = default;
|
||||
|
||||
void destroy();
|
||||
void flush();
|
||||
void execute();
|
||||
void setBuffers(float* in, float* out);
|
||||
void setSamplerate(int rate);
|
||||
void setSize(int size);
|
||||
// TXA Properties
|
||||
static void SetPHROTRun (TXA& txa, int run);
|
||||
static void SetPHROTCorner (TXA& txa, double corner);
|
||||
static void SetPHROTNstages (TXA& txa, int nstages);
|
||||
static void SetPHROTReverse (TXA& txa, int reverse);
|
||||
void setRun(int run);
|
||||
void setCorner(double corner);
|
||||
void setNstages(int nstages);
|
||||
void setReverse(int reverse);
|
||||
|
||||
private:
|
||||
static void calc_phrot (PHROT *a);
|
||||
static void decalc_phrot (PHROT *a);
|
||||
void calc();
|
||||
};
|
||||
|
||||
} // namespace WDSP
|
||||
|
105
wdsp/snotch.cpp
105
wdsp/snotch.cpp
@ -38,82 +38,83 @@ namespace WDSP {
|
||||
* *
|
||||
********************************************************************************************************/
|
||||
|
||||
void SNOTCH::calc_snotch (SNOTCH *a)
|
||||
void SNOTCH::calc()
|
||||
{
|
||||
double fn, qk, qr, csn;
|
||||
fn = a->f / (float)a->rate;
|
||||
fn = f / (double) rate;
|
||||
csn = cos (TWOPI * fn);
|
||||
qr = 1.0 - 3.0 * a->bw;
|
||||
qr = 1.0 - 3.0 * bw;
|
||||
qk = (1.0 - 2.0 * qr * csn + qr * qr) / (2.0 * (1.0 - csn));
|
||||
a->a0 = + qk;
|
||||
a->a1 = - 2.0 * qk * csn;
|
||||
a->a2 = + qk;
|
||||
a->b1 = + 2.0 * qr * csn;
|
||||
a->b2 = - qr * qr;
|
||||
flush_snotch (a);
|
||||
a0 = + qk;
|
||||
a1 = - 2.0 * qk * csn;
|
||||
a2 = + qk;
|
||||
b1 = + 2.0 * qr * csn;
|
||||
b2 = - qr * qr;
|
||||
flush();
|
||||
}
|
||||
|
||||
SNOTCH* SNOTCH::create_snotch (int run, int size, float* in, float* out, int rate, double f, double bw)
|
||||
SNOTCH::SNOTCH(
|
||||
int _run,
|
||||
int _size,
|
||||
float* _in,
|
||||
float* _out,
|
||||
int _rate,
|
||||
double _f,
|
||||
double _bw
|
||||
) :
|
||||
run(_run),
|
||||
size(_size),
|
||||
in(_in),
|
||||
out(_out),
|
||||
rate(_rate),
|
||||
f(_f),
|
||||
bw(_bw)
|
||||
{
|
||||
SNOTCH *a = new SNOTCH;
|
||||
a->run = run;
|
||||
a->size = size;
|
||||
a->in = in;
|
||||
a->out = out;
|
||||
a->rate = rate;
|
||||
a->f = f;
|
||||
a->bw = bw;
|
||||
calc_snotch (a);
|
||||
return a;
|
||||
calc();
|
||||
}
|
||||
|
||||
void SNOTCH::destroy_snotch (SNOTCH *a)
|
||||
void SNOTCH::flush()
|
||||
{
|
||||
delete (a);
|
||||
x1 = x2 = y1 = y2 = 0.0;
|
||||
}
|
||||
|
||||
void SNOTCH::flush_snotch (SNOTCH *a)
|
||||
void SNOTCH::execute()
|
||||
{
|
||||
a->x1 = a->x2 = a->y1 = a->y2 = 0.0;
|
||||
}
|
||||
|
||||
void SNOTCH::xsnotch (SNOTCH *a)
|
||||
{
|
||||
if (a->run)
|
||||
if (run)
|
||||
{
|
||||
int i;
|
||||
for (i = 0; i < a->size; i++)
|
||||
for (i = 0; i < size; i++)
|
||||
{
|
||||
a->x0 = a->in[2 * i + 0];
|
||||
a->out[2 * i + 0] = a->a0 * a->x0 + a->a1 * a->x1 + a->a2 * a->x2 + a->b1 * a->y1 + a->b2 * a->y2;
|
||||
a->y2 = a->y1;
|
||||
a->y1 = a->out[2 * i + 0];
|
||||
a->x2 = a->x1;
|
||||
a->x1 = a->x0;
|
||||
x0 = in[2 * i + 0];
|
||||
out[2 * i + 0] = a0 * x0 + a1 * x1 + a2 * x2 + b1 * y1 + b2 * y2;
|
||||
y2 = y1;
|
||||
y1 = out[2 * i + 0];
|
||||
x2 = x1;
|
||||
x1 = x0;
|
||||
}
|
||||
}
|
||||
else if (a->out != a->in)
|
||||
else if (out != in)
|
||||
{
|
||||
std::copy( a->in, a->in + a->size * 2, a->out);
|
||||
std::copy( in, in + size * 2, out);
|
||||
}
|
||||
}
|
||||
|
||||
void SNOTCH::setBuffers_snotch (SNOTCH *a, float* in, float* out)
|
||||
void SNOTCH::setBuffers(float* _in, float* _out)
|
||||
{
|
||||
a->in = in;
|
||||
a->out = out;
|
||||
in = _in;
|
||||
out = _out;
|
||||
}
|
||||
|
||||
void SNOTCH::setSamplerate_snotch (SNOTCH *a, int rate)
|
||||
void SNOTCH::setSamplerate(int _rate)
|
||||
{
|
||||
a->rate = rate;
|
||||
calc_snotch (a);
|
||||
rate = _rate;
|
||||
calc();
|
||||
}
|
||||
|
||||
void SNOTCH::setSize_snotch (SNOTCH *a, int size)
|
||||
void SNOTCH::setSize(int _size)
|
||||
{
|
||||
a->size = size;
|
||||
flush_snotch (a);
|
||||
size = _size;
|
||||
flush();
|
||||
}
|
||||
|
||||
/********************************************************************************************************
|
||||
@ -122,15 +123,15 @@ void SNOTCH::setSize_snotch (SNOTCH *a, int size)
|
||||
* *
|
||||
********************************************************************************************************/
|
||||
|
||||
void SNOTCH::SetSNCTCSSFreq (SNOTCH *a, double freq)
|
||||
void SNOTCH::setFreq(double _freq)
|
||||
{
|
||||
a->f = freq;
|
||||
calc_snotch (a);
|
||||
f = _freq;
|
||||
calc();
|
||||
}
|
||||
|
||||
void SNOTCH::SetSNCTCSSRun (SNOTCH *a, int run)
|
||||
void SNOTCH::setRun(int _run)
|
||||
{
|
||||
a->run = run;
|
||||
run = _run;
|
||||
}
|
||||
|
||||
} // namespace WDSP
|
||||
|
@ -51,18 +51,29 @@ public:
|
||||
double a0, a1, a2, b1, b2;
|
||||
double x0, x1, x2, y1, y2;
|
||||
|
||||
static SNOTCH* create_snotch (int run, int size, float* in, float* out, int rate, double f, double bw);
|
||||
static void destroy_snotch (SNOTCH *a);
|
||||
static void flush_snotch (SNOTCH *a);
|
||||
static void xsnotch (SNOTCH *a);
|
||||
static void setBuffers_snotch (SNOTCH *a, float* in, float* out);
|
||||
static void setSamplerate_snotch (SNOTCH *a, int rate);
|
||||
static void setSize_snotch (SNOTCH *a, int size);
|
||||
static void SetSNCTCSSFreq (SNOTCH *a, double freq);
|
||||
static void SetSNCTCSSRun (SNOTCH *a, int run);
|
||||
SNOTCH(
|
||||
int run,
|
||||
int size,
|
||||
float* in,
|
||||
float* out,
|
||||
int rate,
|
||||
double f,
|
||||
double bw
|
||||
);
|
||||
SNOTCH(const SNOTCH&) = delete;
|
||||
SNOTCH& operator=(SNOTCH& other) = delete;
|
||||
~SNOTCH() {}
|
||||
|
||||
void flush();
|
||||
void execute();
|
||||
void setBuffers(float* in, float* out);
|
||||
void setSamplerate(int rate);
|
||||
void setSize(int size);
|
||||
void setFreq(double freq);
|
||||
void setRun(int run);
|
||||
|
||||
private:
|
||||
static void calc_snotch (SNOTCH *a);
|
||||
void calc();
|
||||
};
|
||||
|
||||
} // namespace WDSP
|
||||
|
216
wdsp/speak.cpp
216
wdsp/speak.cpp
@ -38,16 +38,16 @@ namespace WDSP {
|
||||
* *
|
||||
********************************************************************************************************/
|
||||
|
||||
void SPEAK::calc_speak (SPEAK *a)
|
||||
void SPEAK::calc()
|
||||
{
|
||||
double ratio;
|
||||
double f_corr, g_corr, bw_corr, bw_parm, A, f_min;
|
||||
|
||||
switch (a->design)
|
||||
switch (design)
|
||||
{
|
||||
case 0:
|
||||
ratio = a->bw / a->f;
|
||||
switch (a->nstages)
|
||||
ratio = bw / f;
|
||||
switch (nstages)
|
||||
{
|
||||
case 4:
|
||||
bw_parm = 2.4;
|
||||
@ -62,23 +62,23 @@ void SPEAK::calc_speak (SPEAK *a)
|
||||
}
|
||||
{
|
||||
double fn, qk, qr, csn;
|
||||
a->fgain = a->gain / g_corr;
|
||||
fn = a->f / (double)a->rate / f_corr;
|
||||
fgain = gain / g_corr;
|
||||
fn = f / (double)rate / f_corr;
|
||||
csn = cos (TWOPI * fn);
|
||||
qr = 1.0 - 3.0 * a->bw / (double)a->rate * bw_parm;
|
||||
qr = 1.0 - 3.0 * bw / (double)rate * bw_parm;
|
||||
qk = (1.0 - 2.0 * qr * csn + qr * qr) / (2.0 * (1.0 - csn));
|
||||
a->a0 = 1.0 - qk;
|
||||
a->a1 = 2.0 * (qk - qr) * csn;
|
||||
a->a2 = qr * qr - qk;
|
||||
a->b1 = 2.0 * qr * csn;
|
||||
a->b2 = - qr * qr;
|
||||
a0 = 1.0 - qk;
|
||||
a1 = 2.0 * (qk - qr) * csn;
|
||||
a2 = qr * qr - qk;
|
||||
b1 = 2.0 * qr * csn;
|
||||
b2 = - qr * qr;
|
||||
}
|
||||
break;
|
||||
|
||||
case 1:
|
||||
if (a->f < 200.0) a->f = 200.0;
|
||||
ratio = a->bw / a->f;
|
||||
switch (a->nstages)
|
||||
if (f < 200.0) f = 200.0;
|
||||
ratio = bw / f;
|
||||
switch (nstages)
|
||||
{
|
||||
case 4:
|
||||
bw_parm = 5.0;
|
||||
@ -96,132 +96,116 @@ void SPEAK::calc_speak (SPEAK *a)
|
||||
}
|
||||
{
|
||||
double w0, sn, c, den;
|
||||
if (a->f < f_min) a->f = f_min;
|
||||
w0 = TWOPI * a->f / (double)a->rate;
|
||||
if (f < f_min) f = f_min;
|
||||
w0 = TWOPI * f / (double)rate;
|
||||
sn = sin (w0);
|
||||
a->cbw = bw_corr * a->f;
|
||||
c = sn * sinh(0.5 * log((a->f + 0.5 * a->cbw * bw_parm) / (a->f - 0.5 * a->cbw * bw_parm)) * w0 / sn);
|
||||
cbw = bw_corr * f;
|
||||
c = sn * sinh(0.5 * log((f + 0.5 * cbw * bw_parm) / (f - 0.5 * cbw * bw_parm)) * w0 / sn);
|
||||
den = 1.0 + c / A;
|
||||
a->a0 = (1.0 + c * A) / den;
|
||||
a->a1 = - 2.0 * cos (w0) / den;
|
||||
a->a2 = (1 - c * A) / den;
|
||||
a->b1 = - a->a1;
|
||||
a->b2 = - (1 - c / A ) / den;
|
||||
a->fgain = a->gain / pow (A * A, (double)a->nstages);
|
||||
a0 = (1.0 + c * A) / den;
|
||||
a1 = - 2.0 * cos (w0) / den;
|
||||
a2 = (1 - c * A) / den;
|
||||
b1 = - a1;
|
||||
b2 = - (1 - c / A ) / den;
|
||||
fgain = gain / pow (A * A, (double)nstages);
|
||||
}
|
||||
break;
|
||||
}
|
||||
flush_speak (a);
|
||||
flush();
|
||||
}
|
||||
|
||||
SPEAK* SPEAK::create_speak (
|
||||
int run,
|
||||
int size,
|
||||
float* in,
|
||||
float* out,
|
||||
int rate,
|
||||
double f,
|
||||
double bw,
|
||||
double gain,
|
||||
int nstages,
|
||||
int design
|
||||
)
|
||||
SPEAK::SPEAK(
|
||||
int _run,
|
||||
int _size,
|
||||
float* _in,
|
||||
float* _out,
|
||||
int _rate,
|
||||
double _f,
|
||||
double _bw,
|
||||
double _gain,
|
||||
int _nstages,
|
||||
int _design
|
||||
) :
|
||||
run(_run),
|
||||
size(_size),
|
||||
in(_in),
|
||||
out(_out),
|
||||
rate(_rate),
|
||||
f(_f),
|
||||
bw(_bw),
|
||||
gain(_gain),
|
||||
nstages(_nstages),
|
||||
design(_design)
|
||||
{
|
||||
SPEAK *a = new SPEAK;
|
||||
a->run = run;
|
||||
a->size = size;
|
||||
a->in = in;
|
||||
a->out = out;
|
||||
a->rate = rate;
|
||||
a->f = f;
|
||||
a->bw = bw;
|
||||
a->gain = gain;
|
||||
a->nstages = nstages;
|
||||
a->design = design;
|
||||
a->x0 = new double[a->nstages * 2]; // (float *) malloc0 (a->nstages * sizeof (complex));
|
||||
a->x1 = new double[a->nstages * 2]; // (float *) malloc0 (a->nstages * sizeof (complex));
|
||||
a->x2 = new double[a->nstages * 2]; //(float *) malloc0 (a->nstages * sizeof (complex));
|
||||
a->y0 = new double[a->nstages * 2]; // (float *) malloc0 (a->nstages * sizeof (complex));
|
||||
a->y1 = new double[a->nstages * 2]; // (float *) malloc0 (a->nstages * sizeof (complex));
|
||||
a->y2 = new double[a->nstages * 2]; // (float *) malloc0 (a->nstages * sizeof (complex));
|
||||
calc_speak (a);
|
||||
return a;
|
||||
x0.resize(nstages * 2); // (float *) malloc0 (nstages * sizeof (complex));
|
||||
x1.resize(nstages * 2); // (float *) malloc0 (nstages * sizeof (complex));
|
||||
x2.resize(nstages * 2); //(float *) malloc0 (nstages * sizeof (complex));
|
||||
y0.resize(nstages * 2); // (float *) malloc0 (nstages * sizeof (complex));
|
||||
y1.resize(nstages * 2); // (float *) malloc0 (nstages * sizeof (complex));
|
||||
y2.resize(nstages * 2); // (float *) malloc0 (nstages * sizeof (complex));
|
||||
calc();
|
||||
}
|
||||
|
||||
void SPEAK::destroy_speak (SPEAK *a)
|
||||
void SPEAK::flush()
|
||||
{
|
||||
delete[] (a->y2);
|
||||
delete[] (a->y1);
|
||||
delete[] (a->y0);
|
||||
delete[] (a->x2);
|
||||
delete[] (a->x1);
|
||||
delete[] (a->x0);
|
||||
delete (a);
|
||||
}
|
||||
|
||||
void SPEAK::flush_speak (SPEAK *a)
|
||||
{
|
||||
int i;
|
||||
for (i = 0; i < a->nstages; i++)
|
||||
for (int i = 0; i < nstages; i++)
|
||||
{
|
||||
a->x1[2 * i + 0] = a->x2[2 * i + 0] = a->y1[2 * i + 0] = a->y2[2 * i + 0] = 0.0;
|
||||
a->x1[2 * i + 1] = a->x2[2 * i + 1] = a->y1[2 * i + 1] = a->y2[2 * i + 1] = 0.0;
|
||||
x1[2 * i + 0] = x2[2 * i + 0] = y1[2 * i + 0] = y2[2 * i + 0] = 0.0;
|
||||
x1[2 * i + 1] = x2[2 * i + 1] = y1[2 * i + 1] = y2[2 * i + 1] = 0.0;
|
||||
}
|
||||
}
|
||||
|
||||
void SPEAK::xspeak (SPEAK *a)
|
||||
void SPEAK::execute()
|
||||
{
|
||||
if (a->run)
|
||||
if (run)
|
||||
{
|
||||
int i, j, n;
|
||||
|
||||
for (i = 0; i < a->size; i++)
|
||||
for (int i = 0; i < size; i++)
|
||||
{
|
||||
for (j = 0; j < 2; j++)
|
||||
for (int j = 0; j < 2; j++)
|
||||
{
|
||||
a->x0[j] = a->fgain * a->in[2 * i + j];
|
||||
x0[j] = fgain * in[2 * i + j];
|
||||
|
||||
for (n = 0; n < a->nstages; n++)
|
||||
for (int n = 0; n < nstages; n++)
|
||||
{
|
||||
if (n > 0)
|
||||
a->x0[2 * n + j] = a->y0[2 * (n - 1) + j];
|
||||
a->y0[2 * n + j] = a->a0 * a->x0[2 * n + j]
|
||||
+ a->a1 * a->x1[2 * n + j]
|
||||
+ a->a2 * a->x2[2 * n + j]
|
||||
+ a->b1 * a->y1[2 * n + j]
|
||||
+ a->b2 * a->y2[2 * n + j];
|
||||
a->y2[2 * n + j] = a->y1[2 * n + j];
|
||||
a->y1[2 * n + j] = a->y0[2 * n + j];
|
||||
a->x2[2 * n + j] = a->x1[2 * n + j];
|
||||
a->x1[2 * n + j] = a->x0[2 * n + j];
|
||||
x0[2 * n + j] = y0[2 * (n - 1) + j];
|
||||
y0[2 * n + j] = a0 * x0[2 * n + j]
|
||||
+ a1 * x1[2 * n + j]
|
||||
+ a2 * x2[2 * n + j]
|
||||
+ b1 * y1[2 * n + j]
|
||||
+ b2 * y2[2 * n + j];
|
||||
y2[2 * n + j] = y1[2 * n + j];
|
||||
y1[2 * n + j] = y0[2 * n + j];
|
||||
x2[2 * n + j] = x1[2 * n + j];
|
||||
x1[2 * n + j] = x0[2 * n + j];
|
||||
}
|
||||
|
||||
a->out[2 * i + j] = a->y0[2 * (a->nstages - 1) + j];
|
||||
out[2 * i + j] = y0[2 * (nstages - 1) + j];
|
||||
}
|
||||
}
|
||||
}
|
||||
else if (a->out != a->in)
|
||||
else if (out != in)
|
||||
{
|
||||
std::copy( a->in, a->in + a->size * 2, a->out);
|
||||
std::copy( in, in + size * 2, out);
|
||||
}
|
||||
}
|
||||
|
||||
void SPEAK::setBuffers_speak (SPEAK *a, float* in, float* out)
|
||||
void SPEAK::setBuffers(float* _in, float* _out)
|
||||
{
|
||||
a->in = in;
|
||||
a->out = out;
|
||||
in = _in;
|
||||
out = _out;
|
||||
}
|
||||
|
||||
void SPEAK::setSamplerate_speak (SPEAK *a, int rate)
|
||||
void SPEAK::setSamplerate(int _rate)
|
||||
{
|
||||
a->rate = rate;
|
||||
calc_speak (a);
|
||||
rate = _rate;
|
||||
calc();
|
||||
}
|
||||
|
||||
void SPEAK::setSize_speak (SPEAK *a, int size)
|
||||
void SPEAK::setSize(int _size)
|
||||
{
|
||||
a->size = size;
|
||||
flush_speak (a);
|
||||
size = _size;
|
||||
flush();
|
||||
}
|
||||
|
||||
/********************************************************************************************************
|
||||
@ -230,31 +214,27 @@ void SPEAK::setSize_speak (SPEAK *a, int size)
|
||||
* *
|
||||
********************************************************************************************************/
|
||||
|
||||
void SPEAK::SetSPCWRun (RXA& rxa, int run)
|
||||
void SPEAK::setRun(int _run)
|
||||
{
|
||||
SPEAK *a = rxa.speak;
|
||||
a->run = run;
|
||||
run = _run;
|
||||
}
|
||||
|
||||
void SPEAK::SetSPCWFreq (RXA& rxa, double freq)
|
||||
void SPEAK::setFreq(double _freq)
|
||||
{
|
||||
SPEAK *a = rxa.speak;
|
||||
a->f = freq;
|
||||
calc_speak (a);
|
||||
f = _freq;
|
||||
calc();
|
||||
}
|
||||
|
||||
void SPEAK::SetSPCWBandwidth (RXA& rxa, double bw)
|
||||
void SPEAK::setBandwidth(double _bw)
|
||||
{
|
||||
SPEAK *a = rxa.speak;
|
||||
a->bw = bw;
|
||||
calc_speak (a);
|
||||
bw = _bw;
|
||||
calc();
|
||||
}
|
||||
|
||||
void SPEAK::SetSPCWGain (RXA& rxa, double gain)
|
||||
void SPEAK::setGain(double _gain)
|
||||
{
|
||||
SPEAK *a = rxa.speak;
|
||||
a->gain = gain;
|
||||
calc_speak (a);
|
||||
gain = _gain;
|
||||
calc();
|
||||
}
|
||||
|
||||
} // namespace WDSP
|
||||
|
@ -34,6 +34,8 @@ warren@wpratt.com
|
||||
#ifndef wdsp_speak_h
|
||||
#define wdsp_speak_h
|
||||
|
||||
#include <vector>
|
||||
|
||||
#include "export.h"
|
||||
|
||||
namespace WDSP {
|
||||
@ -56,9 +58,9 @@ public:
|
||||
int nstages;
|
||||
int design;
|
||||
double a0, a1, a2, b1, b2;
|
||||
double *x0, *x1, *x2, *y0, *y1, *y2;
|
||||
std::vector<double> x0, x1, x2, y0, y1, y2;
|
||||
|
||||
static SPEAK* create_speak (
|
||||
SPEAK(
|
||||
int run,
|
||||
int size,
|
||||
float* in,
|
||||
@ -70,18 +72,21 @@ public:
|
||||
int nstages,
|
||||
int design
|
||||
);
|
||||
static void destroy_speak (SPEAK *a);
|
||||
static void flush_speak (SPEAK *a);
|
||||
static void xspeak (SPEAK *a);
|
||||
static void setBuffers_speak (SPEAK *a, float* in, float* out);
|
||||
static void setSamplerate_speak (SPEAK *a, int rate);
|
||||
static void setSize_speak (SPEAK *a, int size);
|
||||
SPEAK(const SPEAK&) = delete;
|
||||
SPEAK& operator=(const SPEAK& other) = delete;
|
||||
~SPEAK() {}
|
||||
|
||||
void flush();
|
||||
void execute();
|
||||
void setBuffers(float* in, float* out);
|
||||
void setSamplerate(int rate);
|
||||
void setSize(int size);
|
||||
// RXA
|
||||
static void SetSPCWRun (RXA& rxa, int run);
|
||||
static void SetSPCWFreq (RXA& rxa, double freq);
|
||||
static void SetSPCWBandwidth (RXA& rxa, double bw);
|
||||
static void SetSPCWGain (RXA& rxa, double gain);
|
||||
static void calc_speak (SPEAK *a);
|
||||
void setRun(int run);
|
||||
void setFreq(double freq);
|
||||
void setBandwidth(double bw);
|
||||
void setGain(double gain);
|
||||
void calc();
|
||||
};
|
||||
|
||||
} // namespace WDSP
|
||||
|
117
wdsp/sphp.cpp
117
wdsp/sphp.cpp
@ -37,105 +37,96 @@ namespace WDSP {
|
||||
* *
|
||||
********************************************************************************************************/
|
||||
|
||||
void SPHP::calc_sphp(SPHP *a)
|
||||
void SPHP::calc()
|
||||
{
|
||||
double g;
|
||||
a->x0 = new double[a->nstages * 2]; // (float*)malloc0(a->nstages * sizeof(complex));
|
||||
a->x1 = new double[a->nstages * 2]; // (float*)malloc0(a->nstages * sizeof(complex));
|
||||
a->y0 = new double[a->nstages * 2]; // (float*)malloc0(a->nstages * sizeof(complex));
|
||||
a->y1 = new double[a->nstages * 2]; // (float*)malloc0(a->nstages * sizeof(complex));
|
||||
g = exp(-TWOPI * a->fc / a->rate);
|
||||
a->b0 = +0.5 * (1.0 + g);
|
||||
a->b1 = -0.5 * (1.0 + g);
|
||||
a->a1 = -g;
|
||||
x0.resize(nstages * 2); // (float*)malloc0(nstages * sizeof(complex));
|
||||
x1.resize(nstages * 2); // (float*)malloc0(nstages * sizeof(complex));
|
||||
y0.resize(nstages * 2); // (float*)malloc0(nstages * sizeof(complex));
|
||||
y1.resize(nstages * 2); // (float*)malloc0(nstages * sizeof(complex));
|
||||
g = exp(-TWOPI * fc / rate);
|
||||
b0 = +0.5 * (1.0 + g);
|
||||
b1 = -0.5 * (1.0 + g);
|
||||
a1 = -g;
|
||||
}
|
||||
|
||||
SPHP* SPHP::create_sphp(int run, int size, float* in, float* out, double rate, double fc, int nstages)
|
||||
SPHP::SPHP(
|
||||
int _run,
|
||||
int _size,
|
||||
float* _in,
|
||||
float* _out,
|
||||
double _rate,
|
||||
double _fc,
|
||||
int _nstages
|
||||
) :
|
||||
run(_run),
|
||||
size(_size),
|
||||
in(_in),
|
||||
out(_out),
|
||||
rate(_rate),
|
||||
fc(_fc),
|
||||
nstages(_nstages)
|
||||
{
|
||||
SPHP *a = new SPHP;
|
||||
a->run = run;
|
||||
a->size = size;
|
||||
a->in = in;
|
||||
a->out = out;
|
||||
a->rate = rate;
|
||||
a->fc = fc;
|
||||
a->nstages = nstages;
|
||||
calc_sphp(a);
|
||||
return a;
|
||||
calc();
|
||||
}
|
||||
|
||||
void SPHP::decalc_sphp(SPHP *a)
|
||||
void SPHP::flush()
|
||||
{
|
||||
delete[](a->y1);
|
||||
delete[](a->y0);
|
||||
delete[](a->x1);
|
||||
delete[](a->x0);
|
||||
std::fill(x0.begin(), x0.end(), 0);
|
||||
std::fill(x1.begin(), x0.end(), 0);
|
||||
std::fill(y0.begin(), x0.end(), 0);
|
||||
std::fill(y1.begin(), x0.end(), 0);
|
||||
}
|
||||
|
||||
void SPHP::destroy_sphp(SPHP *a)
|
||||
void SPHP::execute()
|
||||
{
|
||||
decalc_sphp(a);
|
||||
delete(a);
|
||||
}
|
||||
|
||||
void SPHP::flush_sphp(SPHP *a)
|
||||
{
|
||||
std::fill(a->x0, a->x0 + a->nstages * 2, 0);
|
||||
std::fill(a->x1, a->x0 + a->nstages * 2, 0);
|
||||
std::fill(a->y0, a->x0 + a->nstages * 2, 0);
|
||||
std::fill(a->y1, a->x0 + a->nstages * 2, 0);
|
||||
}
|
||||
|
||||
void SPHP::xsphp(SPHP *a)
|
||||
{
|
||||
if (a->run)
|
||||
if (run)
|
||||
{
|
||||
int i, j, n;
|
||||
for (i = 0; i < a->size; i++)
|
||||
for (i = 0; i < size; i++)
|
||||
{
|
||||
for (j = 0; j < 2; j++)
|
||||
{
|
||||
a->x0[j] = a->in[2 * i + j];
|
||||
x0[j] = in[2 * i + j];
|
||||
|
||||
for (n = 0; n < a->nstages; n++)
|
||||
for (n = 0; n < nstages; n++)
|
||||
{
|
||||
if (n > 0)
|
||||
a->x0[2 * n + j] = a->y0[2 * (n - 1) + j];
|
||||
x0[2 * n + j] = y0[2 * (n - 1) + j];
|
||||
|
||||
a->y0[2 * n + j] = a->b0 * a->x0[2 * n + j]
|
||||
+ a->b1 * a->x1[2 * n + j]
|
||||
- a->a1 * a->y1[2 * n + j];
|
||||
a->y1[2 * n + j] = a->y0[2 * n + j];
|
||||
a->x1[2 * n + j] = a->x0[2 * n + j];
|
||||
y0[2 * n + j] = b0 * x0[2 * n + j]
|
||||
+ b1 * x1[2 * n + j]
|
||||
- a1 * y1[2 * n + j];
|
||||
y1[2 * n + j] = y0[2 * n + j];
|
||||
x1[2 * n + j] = x0[2 * n + j];
|
||||
}
|
||||
|
||||
a->out[2 * i + j] = a->y0[2 * (a->nstages - 1) + j];
|
||||
out[2 * i + j] = y0[2 * (nstages - 1) + j];
|
||||
}
|
||||
}
|
||||
}
|
||||
else if (a->out != a->in)
|
||||
else if (out != in)
|
||||
{
|
||||
std::copy(a->in, a->in + a->size * 2, a->out);
|
||||
std::copy(in, in + size * 2, out);
|
||||
}
|
||||
}
|
||||
|
||||
void SPHP::setBuffers_sphp(SPHP *a, float* in, float* out)
|
||||
void SPHP::setBuffers(float* _in, float* _out)
|
||||
{
|
||||
a->in = in;
|
||||
a->out = out;
|
||||
in = _in;
|
||||
out = _out;
|
||||
}
|
||||
|
||||
void SPHP::setSamplerate_sphp(SPHP *a, int rate)
|
||||
void SPHP::setSamplerate(int _rate)
|
||||
{
|
||||
decalc_sphp(a);
|
||||
a->rate = rate;
|
||||
calc_sphp(a);
|
||||
rate = _rate;
|
||||
calc();
|
||||
}
|
||||
|
||||
void SPHP::setSize_sphp(SPHP *a, int size)
|
||||
void SPHP::setSize(int _size)
|
||||
{
|
||||
a->size = size;
|
||||
flush_sphp(a);
|
||||
size = _size;
|
||||
flush();
|
||||
}
|
||||
|
||||
} // namespace WDSP
|
||||
|
@ -34,6 +34,8 @@ warren@wpratt.com
|
||||
#ifndef wdsp_sphp_h
|
||||
#define wdsp_sphp_h
|
||||
|
||||
#include <vector>
|
||||
|
||||
#include "export.h"
|
||||
|
||||
namespace WDSP {
|
||||
@ -49,20 +51,31 @@ public:
|
||||
double fc;
|
||||
int nstages;
|
||||
double a1, b0, b1;
|
||||
double* x0, * x1, * y0, * y1;
|
||||
std::vector<double> x0, x1, y0, y1;
|
||||
|
||||
// Complex Single-Pole High-Pass
|
||||
static SPHP* create_sphp(int run, int size, float* in, float* out, double rate, double fc, int nstages);
|
||||
static void destroy_sphp(SPHP *a);
|
||||
static void flush_sphp(SPHP *a);
|
||||
static void xsphp(SPHP *a);
|
||||
static void setBuffers_sphp(SPHP *a, float* in, float* out);
|
||||
static void setSamplerate_sphp(SPHP *a, int rate);
|
||||
static void setSize_sphp(SPHP *a, int size);
|
||||
SPHP(
|
||||
int run,
|
||||
int size,
|
||||
float* in,
|
||||
float* out,
|
||||
double rate,
|
||||
double fc,
|
||||
int nstages
|
||||
);
|
||||
SPHP(const SPHP&) = delete;
|
||||
SPHP& operator=(const SPHP& other) = delete;
|
||||
~SPHP() = default;
|
||||
|
||||
void destroy();
|
||||
void flush();
|
||||
void execute();
|
||||
void setBuffers(float* in, float* out);
|
||||
void setSamplerate(int rate);
|
||||
void setSize(int size);
|
||||
|
||||
private:
|
||||
static void calc_sphp(SPHP *a);
|
||||
static void decalc_sphp(SPHP *a);
|
||||
void calc();
|
||||
};
|
||||
|
||||
} // namespace WDSP
|
||||
|
114
wdsp/ssql.cpp
114
wdsp/ssql.cpp
@ -39,76 +39,76 @@ namespace WDSP {
|
||||
* *
|
||||
********************************************************************************************************/
|
||||
|
||||
FTOV* FTOV::create_ftov (int run, int size, int rate, int rsize, double fmax, float* in, float* out)
|
||||
FTOV::FTOV(
|
||||
int _run,
|
||||
int _size,
|
||||
int _rate,
|
||||
int _rsize,
|
||||
double _fmax,
|
||||
float* _in,
|
||||
float* _out
|
||||
)
|
||||
{
|
||||
FTOV *a = new FTOV;
|
||||
a->run = run;
|
||||
a->size = size;
|
||||
a->rate = rate;
|
||||
a->rsize = rsize;
|
||||
a->fmax = fmax;
|
||||
a->in = in;
|
||||
a->out = out;
|
||||
a->eps = 0.01;
|
||||
a->ring = new int[a->rsize]; // (int*) malloc0 (a->rsize * sizeof (int));
|
||||
a->rptr = 0;
|
||||
a->inlast = 0.0;
|
||||
a->rcount = 0;
|
||||
a->div = a->fmax * 2.0 * a->rsize / a->rate; // fmax * 2 = zero-crossings/sec
|
||||
run = _run;
|
||||
size = _size;
|
||||
rate = _rate;
|
||||
rsize = _rsize;
|
||||
fmax = _fmax;
|
||||
in = _in;
|
||||
out = _out;
|
||||
eps = 0.01;
|
||||
ring.resize(rsize); // (int*) malloc0 (rsize * sizeof (int));
|
||||
rptr = 0;
|
||||
inlast = 0.0;
|
||||
rcount = 0;
|
||||
div = fmax * 2.0 * rsize / rate; // fmax * 2 = zero-crossings/sec
|
||||
// rsize / rate = sec of data in ring
|
||||
// product is # zero-crossings in ring at fmax
|
||||
return a;
|
||||
}
|
||||
|
||||
void FTOV::destroy_ftov (FTOV *a)
|
||||
void FTOV::flush()
|
||||
{
|
||||
delete[] (a->ring);
|
||||
delete (a);
|
||||
std::fill(ring.begin(), ring.end(), 0);
|
||||
rptr = 0;
|
||||
rcount = 0;
|
||||
inlast = 0.0;
|
||||
}
|
||||
|
||||
void FTOV::flush_ftov (FTOV *a)
|
||||
{
|
||||
memset (a->ring, 0, a->rsize * sizeof (int));
|
||||
a->rptr = 0;
|
||||
a->rcount = 0;
|
||||
a->inlast = 0.0;
|
||||
}
|
||||
|
||||
void FTOV::xftov (FTOV *a)
|
||||
void FTOV::execute()
|
||||
{
|
||||
// 'ftov' does frequency to voltage conversion looking only at zero crossings of an
|
||||
// AC (DC blocked) signal, i.e., ignoring signal amplitude.
|
||||
if (a->run)
|
||||
if (run)
|
||||
{
|
||||
if (a->ring[a->rptr] == 1) // if current ring location is a '1' ...
|
||||
if (ring[rptr] == 1) // if current ring location is a '1' ...
|
||||
{
|
||||
a->rcount--; // decrement the count
|
||||
a->ring[a->rptr] = 0; // set the location to '0'
|
||||
rcount--; // decrement the count
|
||||
ring[rptr] = 0; // set the location to '0'
|
||||
}
|
||||
if ((a->inlast * a->in[0] < 0.0) && // different signs mean zero-crossing
|
||||
(fabs (a->inlast - a->in[0]) > a->eps))
|
||||
if ((inlast * in[0] < 0.0) && // different signs mean zero-crossing
|
||||
(fabs (inlast - in[0]) > eps))
|
||||
{
|
||||
a->ring[a->rptr] = 1; // set the ring location to '1'
|
||||
a->rcount++; // increment the count
|
||||
ring[rptr] = 1; // set the ring location to '1'
|
||||
rcount++; // increment the count
|
||||
}
|
||||
if (++a->rptr == a->rsize) a->rptr = 0; // increment and wrap the pointer as needed
|
||||
a->out[0] = std::min (1.0, (double)a->rcount / a->div); // calculate the output sample
|
||||
a->inlast = a->in[a->size - 1]; // save the last input sample for next buffer
|
||||
for (int i = 1; i < a->size; i++)
|
||||
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
|
||||
inlast = in[size - 1]; // save the last input sample for next buffer
|
||||
for (int i = 1; i < size; i++)
|
||||
{
|
||||
if (a->ring[a->rptr] == 1) // if current ring location is '1' ...
|
||||
if (ring[rptr] == 1) // if current ring location is '1' ...
|
||||
{
|
||||
a->rcount--; // decrement the count
|
||||
a->ring[a->rptr] = 0; // set the location to '0'
|
||||
rcount--; // decrement the count
|
||||
ring[rptr] = 0; // set the location to '0'
|
||||
}
|
||||
if ((a->in[i - 1] * a->in[i] < 0.0) && // different signs mean zero-crossing
|
||||
(fabs (a->in[i - 1] - a->in[i]) > a->eps))
|
||||
if ((in[i - 1] * in[i] < 0.0) && // different signs mean zero-crossing
|
||||
(fabs (in[i - 1] - in[i]) > eps))
|
||||
{
|
||||
a->ring[a->rptr] = 1; // set the ring location to '1'
|
||||
a->rcount++; // increment the count
|
||||
ring[rptr] = 1; // set the ring location to '1'
|
||||
rcount++; // increment the count
|
||||
}
|
||||
if (++a->rptr == a->rsize) a->rptr = 0; // increment and wrap the pointer as needed
|
||||
a->out[i] = std::min(1.0, (double)a->rcount / a->div); // calculate the output sample
|
||||
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
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -143,9 +143,9 @@ void SSQL::calc_ssql (SSQL *a)
|
||||
a->dcbl = new CBL(1, a->size, a->in, a->b1, 0, a->rate, 0.02);
|
||||
a->ibuff = new float[a->size]; // (float*) malloc0 (a->size * sizeof (float));
|
||||
a->ftovbuff = new float[a->size]; // (float*) malloc0(a->size * sizeof (float));
|
||||
a->cvtr = FTOV::create_ftov (1, a->size, a->rate, a->ftov_rsize, a->ftov_fmax, a->ibuff, a->ftovbuff);
|
||||
a->cvtr = new FTOV(1, a->size, a->rate, a->ftov_rsize, a->ftov_fmax, a->ibuff, a->ftovbuff);
|
||||
a->lpbuff = new float[a->size]; // (float*) malloc0 (a->size * sizeof (float));
|
||||
a->filt = DBQLP::create_dbqlp (1, a->size, a->ftovbuff, a->lpbuff, a->rate, 11.3, 1.0, 1.0, 1);
|
||||
a->filt = new DBQLP(1, a->size, a->ftovbuff, a->lpbuff, a->rate, 11.3, 1.0, 1.0, 1);
|
||||
a->wdbuff = new int[a->size]; // (int*) malloc0 (a->size * sizeof (int));
|
||||
a->tr_signal = new int[a->size]; // (int*) malloc0 (a->size * sizeof (int));
|
||||
// window detector
|
||||
@ -170,9 +170,9 @@ void SSQL::decalc_ssql (SSQL *a)
|
||||
{
|
||||
delete[] (a->tr_signal);
|
||||
delete[] (a->wdbuff);
|
||||
DBQLP::destroy_dbqlp (a->filt);
|
||||
delete (a->filt);
|
||||
delete[] (a->lpbuff);
|
||||
FTOV::destroy_ftov (a->cvtr);
|
||||
delete (a->cvtr);
|
||||
delete[] (a->ftovbuff);
|
||||
delete[] (a->ibuff);
|
||||
delete (a->dcbl);
|
||||
@ -233,9 +233,9 @@ void SSQL::flush_ssql (SSQL *a)
|
||||
a->dcbl->flush();
|
||||
memset (a->ibuff, 0, a->size * sizeof (float));
|
||||
memset (a->ftovbuff, 0, a->size * sizeof (float));
|
||||
FTOV::flush_ftov (a->cvtr);
|
||||
a->cvtr->flush();
|
||||
memset (a->lpbuff, 0, a->size * sizeof (float));
|
||||
DBQLP::flush_dbqlp (a->filt);
|
||||
a->filt->flush();
|
||||
memset (a->wdbuff, 0, a->size * sizeof (int));
|
||||
memset (a->tr_signal, 0, a->size * sizeof (int));
|
||||
}
|
||||
@ -255,9 +255,9 @@ void SSQL::xssql (SSQL *a)
|
||||
a->dcbl->execute(); // dc block the input signal
|
||||
for (int i = 0; i < a->size; i++) // extract 'I' component
|
||||
a->ibuff[i] = a->b1[2 * i];
|
||||
FTOV::xftov (a->cvtr); // convert frequency to voltage, ignoring amplitude
|
||||
a->cvtr->execute(); // convert frequency to voltage, ignoring amplitude
|
||||
// WriteAudioWDSP(20.0, a->rate, a->size, a->ftovbuff, 4, 0.99);
|
||||
DBQLP::xdbqlp (a->filt); // low-pass filter
|
||||
a->filt->execute(); // low-pass filter
|
||||
// WriteAudioWDSP(20.0, a->rate, a->size, a->lpbuff, 4, 0.99);
|
||||
// calculate the output of the window detector for each sample
|
||||
for (int i = 0; i < a->size; i++)
|
||||
|
@ -28,6 +28,8 @@ warren@pratt.one
|
||||
#ifndef wdsp_ssql_h
|
||||
#define wdsp_ssql_h
|
||||
|
||||
#include <vector>
|
||||
|
||||
#include "export.h"
|
||||
|
||||
namespace WDSP {
|
||||
@ -40,19 +42,30 @@ public:
|
||||
int rate; // sample-rate
|
||||
int rsize; // rate * time_to_fill_ring, e.g., 48K/s * 50ms = 2400
|
||||
double fmax; // frequency (Hz) for full output, e.g., 2000 (Hz)
|
||||
float* in; // pointer to the intput buffer for ftov
|
||||
float* out; // pointer to the output buffer for ftov
|
||||
int* ring; // pointer to the base of the ring
|
||||
float* in; // pointer to the intput buffer for ftov
|
||||
float* out; // pointer to the output buffer for ftov
|
||||
std::vector<int> ring; // the ring
|
||||
int rptr; // index into the ring
|
||||
double inlast; // holds last sample from previous buffer
|
||||
int rcount; // count of zero-crossings currently in the ring
|
||||
double div; // divisor for 'rcount' to produce output of 1.0 at 'fmax'
|
||||
double eps; // minimum input change to count as a signal edge transition
|
||||
|
||||
static FTOV* create_ftov (int run, int size, int rate, int rsize, double fmax, float* in, float* out);
|
||||
static void destroy_ftov (FTOV *a);
|
||||
static void flush_ftov (FTOV *a);
|
||||
static void xftov (FTOV *a);
|
||||
FTOV(
|
||||
int run,
|
||||
int size,
|
||||
int rate,
|
||||
int rsize,
|
||||
double fmax,
|
||||
float* in,
|
||||
float* out
|
||||
);
|
||||
FTOV(const FTOV&) = delete;
|
||||
FTOV& operator=(FTOV& other) = delete;
|
||||
~FTOV() = default;
|
||||
|
||||
void flush();
|
||||
void execute();
|
||||
};
|
||||
|
||||
class CBL;
|
||||
|
Loading…
Reference in New Issue
Block a user