1
0
mirror of https://github.com/f4exb/sdrangel.git synced 2024-09-21 04:16:34 -04:00

WDSP: rework SSQL and PANEL classes

This commit is contained in:
f4exb 2024-08-01 02:01:09 +02:00
parent 71fe079ee3
commit cd38f356d0
8 changed files with 293 additions and 314 deletions

View File

@ -680,7 +680,7 @@ void WDSPRxSink::applySettings(const WDSPRxSettings& settings, bool force)
|| (m_settings.m_squelchThreshold != settings.m_squelchThreshold) || (m_settings.m_squelchThreshold != settings.m_squelchThreshold)
|| (m_settings.m_squelchMode != settings.m_squelchMode) || force) || (m_settings.m_squelchMode != settings.m_squelchMode) || force)
{ {
WDSP::SSQL::SetSSQLRun(*m_rxa, 0); m_rxa->ssql->setRun(0);
m_rxa->amsq->setRun(0); m_rxa->amsq->setRun(0);
m_rxa->fmsq->setRun(0); m_rxa->fmsq->setRun(0);
@ -690,9 +690,9 @@ void WDSPRxSink::applySettings(const WDSPRxSettings& settings, bool force)
{ {
case WDSPRxProfile::SquelchModeVoice: case WDSPRxProfile::SquelchModeVoice:
{ {
WDSP::SSQL::SetSSQLRun(*m_rxa, 1); m_rxa->ssql->setRun(1);
double threshold = 0.0075 * settings.m_squelchThreshold; double threshold = 0.0075 * settings.m_squelchThreshold;
WDSP::SSQL::SetSSQLThreshold(*m_rxa, threshold); m_rxa->ssql->setThreshold(threshold);
} }
break; break;
case WDSPRxProfile::SquelchModeAM: case WDSPRxProfile::SquelchModeAM:
@ -717,11 +717,11 @@ void WDSPRxSink::applySettings(const WDSPRxSettings& settings, bool force)
} }
if ((m_settings.m_ssqlTauMute != settings.m_ssqlTauMute) || force) { if ((m_settings.m_ssqlTauMute != settings.m_ssqlTauMute) || force) {
WDSP::SSQL::SetSSQLTauMute(*m_rxa, settings.m_ssqlTauMute); m_rxa->ssql->setTauMute(settings.m_ssqlTauMute);
} }
if ((m_settings.m_ssqlTauUnmute != settings.m_ssqlTauUnmute) || force) { if ((m_settings.m_ssqlTauUnmute != settings.m_ssqlTauUnmute) || force) {
WDSP::SSQL::SetSSQLTauUnMute(*m_rxa, settings.m_ssqlTauUnmute); m_rxa->ssql->setTauUnMute(settings.m_ssqlTauUnmute);
} }
if ((m_settings.m_amsqMaxTail != settings.m_amsqMaxTail) || force) { if ((m_settings.m_amsqMaxTail != settings.m_amsqMaxTail) || force) {
@ -743,7 +743,7 @@ void WDSPRxSink::applySettings(const WDSPRxSettings& settings, bool force)
// Audio panel // Audio panel
if ((m_settings.m_volume != settings.m_volume) || force) { if ((m_settings.m_volume != settings.m_volume) || force) {
WDSP::PANEL::SetPanelGain1(*m_rxa, settings.m_volume); m_rxa->panel->setGain1(settings.m_volume);
} }
if ((m_settings.m_audioBinaural != settings.m_audioBinaural) if ((m_settings.m_audioBinaural != settings.m_audioBinaural)
@ -752,13 +752,13 @@ void WDSPRxSink::applySettings(const WDSPRxSettings& settings, bool force)
{ {
if (settings.m_audioBinaural) if (settings.m_audioBinaural)
{ {
WDSP::PANEL::SetPanelCopy(*m_rxa, settings.m_audioFlipChannels ? 3 : 0); m_rxa->panel->setCopy(settings.m_audioFlipChannels ? 3 : 0);
WDSP::PANEL::SetPanelPan(*m_rxa, settings.m_audioPan); m_rxa->panel->setPan(settings.m_audioPan);
} }
else else
{ {
WDSP::PANEL::SetPanelCopy(*m_rxa, settings.m_audioFlipChannels ? 2 : 1); m_rxa->panel->setCopy(settings.m_audioFlipChannels ? 2 : 1);
WDSP::PANEL::SetPanelPan(*m_rxa, 0.5); m_rxa->panel->setPan(0.5);
} }
} }

View File

@ -515,7 +515,7 @@ RXA* RXA::create_rxa (
} }
// Syllabic squelch (Voice suelch) - Not in the block diagram // Syllabic squelch (Voice suelch) - Not in the block diagram
rxa->ssql = SSQL::create_ssql( rxa->ssql = new SSQL(
0, // run 0, // run
rxa->dsp_size, // size rxa->dsp_size, // size
rxa->midbuff, // pointer to input buffer rxa->midbuff, // pointer to input buffer
@ -532,7 +532,7 @@ RXA* RXA::create_rxa (
2000.0); // max freq for f_to_v converter 2000.0); // max freq for f_to_v converter
// PatchPanel // PatchPanel
rxa->panel = PANEL::create_panel ( rxa->panel = new PANEL(
1, // run 1, // run
rxa->dsp_size, // size rxa->dsp_size, // size
rxa->midbuff, // pointer to input buffer rxa->midbuff, // pointer to input buffer
@ -565,8 +565,8 @@ RXA* RXA::create_rxa (
void RXA::destroy_rxa (RXA *rxa) void RXA::destroy_rxa (RXA *rxa)
{ {
delete (rxa->rsmpout); delete (rxa->rsmpout);
PANEL::destroy_panel (rxa->panel); delete (rxa->panel);
SSQL::destroy_ssql (rxa->ssql); delete (rxa->ssql);
delete (rxa->mpeak); delete (rxa->mpeak);
delete (rxa->speak); delete (rxa->speak);
delete (rxa->cbl); delete (rxa->cbl);
@ -629,8 +629,8 @@ void RXA::flush_rxa (RXA *rxa)
rxa->cbl->flush(); rxa->cbl->flush();
rxa->speak->flush(); rxa->speak->flush();
rxa->mpeak->flush(); rxa->mpeak->flush();
SSQL::flush_ssql (rxa->ssql); rxa->ssql->flush();
PANEL::flush_panel (rxa->panel); rxa->panel->flush();
rxa->rsmpout->flush(); rxa->rsmpout->flush();
} }
@ -668,8 +668,8 @@ void RXA::xrxa (RXA *rxa)
rxa->cbl->execute(); rxa->cbl->execute();
rxa->speak->execute(); rxa->speak->execute();
rxa->mpeak->execute(); rxa->mpeak->execute();
SSQL::xssql (rxa->ssql); rxa->ssql->execute();
PANEL::xpanel (rxa->panel); rxa->panel->execute();
rxa->amsq->execute(); rxa->amsq->execute();
rxa->rsmpout->execute(); rxa->rsmpout->execute();
} }
@ -775,8 +775,8 @@ void RXA::setDSPSamplerate (RXA *rxa, int dsp_rate)
rxa->cbl->setSamplerate(rxa->dsp_rate); rxa->cbl->setSamplerate(rxa->dsp_rate);
rxa->speak->setSamplerate(rxa->dsp_rate); rxa->speak->setSamplerate(rxa->dsp_rate);
rxa->mpeak->setSamplerate(rxa->dsp_rate); rxa->mpeak->setSamplerate(rxa->dsp_rate);
SSQL::setSamplerate_ssql (rxa->ssql, rxa->dsp_rate); rxa->ssql->setSamplerate(rxa->dsp_rate);
PANEL::setSamplerate_panel (rxa->panel, rxa->dsp_rate); rxa->panel->setSamplerate(rxa->dsp_rate);
// output resampler // output resampler
rxa->rsmpout->setBuffers(rxa->midbuff, rxa->outbuff); rxa->rsmpout->setBuffers(rxa->midbuff, rxa->outbuff);
rxa->rsmpout->setInRate(rxa->dsp_rate); rxa->rsmpout->setInRate(rxa->dsp_rate);
@ -858,10 +858,10 @@ void RXA::setDSPBuffsize (RXA *rxa, int dsp_size)
rxa->speak->setSize(rxa->dsp_size); rxa->speak->setSize(rxa->dsp_size);
rxa->mpeak->setBuffers(rxa->midbuff, rxa->midbuff); rxa->mpeak->setBuffers(rxa->midbuff, rxa->midbuff);
rxa->mpeak->setSize(rxa->dsp_size); rxa->mpeak->setSize(rxa->dsp_size);
SSQL::setBuffers_ssql (rxa->ssql, rxa->midbuff, rxa->midbuff); rxa->ssql->setBuffers(rxa->midbuff, rxa->midbuff);
SSQL::setSize_ssql (rxa->ssql, rxa->dsp_size); rxa->ssql->setSize(rxa->dsp_size);
PANEL::setBuffers_panel (rxa->panel, rxa->midbuff, rxa->midbuff); rxa->panel->setBuffers(rxa->midbuff, rxa->midbuff);
PANEL::setSize_panel (rxa->panel, rxa->dsp_size); rxa->panel->setSize(rxa->dsp_size);
// output resampler // output resampler
rxa->rsmpout->setBuffers(rxa->midbuff, rxa->outbuff); rxa->rsmpout->setBuffers(rxa->midbuff, rxa->outbuff);
rxa->rsmpout->setSize(rxa->dsp_size); rxa->rsmpout->setSize(rxa->dsp_size);

View File

@ -103,7 +103,7 @@ TXA* TXA::create_txa (
txa->dsp_rate, // sample rate txa->dsp_rate, // sample rate
2); // mode 2); // mode
txa->panel = PANEL::create_panel ( txa->panel = new PANEL(
1, // run 1, // run
txa->dsp_size, // size txa->dsp_size, // size
txa->midbuff, // pointer to input buffer txa->midbuff, // pointer to input buffer
@ -549,7 +549,7 @@ void TXA::destroy_txa (TXA *txa)
delete (txa->amsq); delete (txa->amsq);
delete (txa->micmeter); delete (txa->micmeter);
delete (txa->phrot); delete (txa->phrot);
PANEL::destroy_panel (txa->panel); delete (txa->panel);
delete (txa->gen0); delete (txa->gen0);
delete (txa->rsmpin); delete (txa->rsmpin);
delete[] (txa->midbuff); delete[] (txa->midbuff);
@ -565,7 +565,7 @@ void TXA::flush_txa (TXA* txa)
std::fill(txa->midbuff, txa->midbuff + 2 * txa->dsp_size * 2, 0); std::fill(txa->midbuff, txa->midbuff + 2 * txa->dsp_size * 2, 0);
txa->rsmpin->flush(); txa->rsmpin->flush();
txa->gen0->flush(); txa->gen0->flush();
PANEL::flush_panel (txa->panel); txa->panel->flush ();
txa->phrot->flush(); txa->phrot->flush();
txa->micmeter->flush (); txa->micmeter->flush ();
txa->amsq->flush (); txa->amsq->flush ();
@ -599,7 +599,7 @@ void xtxa (TXA* txa)
{ {
txa->rsmpin->execute(); // input resampler txa->rsmpin->execute(); // input resampler
txa->gen0->execute(); // input signal generator txa->gen0->execute(); // input signal generator
PANEL::xpanel (txa->panel); // includes MIC gain txa->panel->execute(); // includes MIC gain
txa->phrot->execute(); // phase rotator txa->phrot->execute(); // phase rotator
txa->micmeter->execute (); // MIC meter txa->micmeter->execute (); // MIC meter
txa->amsq->xcap (); // downward expander capture txa->amsq->xcap (); // downward expander capture
@ -697,7 +697,7 @@ void TXA::setDSPSamplerate (TXA *txa, int dsp_rate)
txa->rsmpin->setOutRate(txa->dsp_rate); txa->rsmpin->setOutRate(txa->dsp_rate);
// dsp_rate blocks // dsp_rate blocks
txa->gen0->setSamplerate(txa->dsp_rate); txa->gen0->setSamplerate(txa->dsp_rate);
PANEL::setSamplerate_panel (txa->panel, txa->dsp_rate); txa->panel->setSamplerate(txa->dsp_rate);
txa->phrot->setSamplerate(txa->dsp_rate); txa->phrot->setSamplerate(txa->dsp_rate);
txa->micmeter->setSamplerate (txa->dsp_rate); txa->micmeter->setSamplerate (txa->dsp_rate);
txa->amsq->setSamplerate (txa->dsp_rate); txa->amsq->setSamplerate (txa->dsp_rate);
@ -758,8 +758,8 @@ void TXA::setDSPBuffsize (TXA *txa, int dsp_size)
// dsp_size blocks // dsp_size blocks
txa->gen0->setBuffers(txa->midbuff, txa->midbuff); txa->gen0->setBuffers(txa->midbuff, txa->midbuff);
txa->gen0->setSize(txa->dsp_size); txa->gen0->setSize(txa->dsp_size);
PANEL::setBuffers_panel (txa->panel, txa->midbuff, txa->midbuff); txa->panel->setBuffers(txa->midbuff, txa->midbuff);
PANEL::setSize_panel (txa->panel, txa->dsp_size); txa->panel->setSize(txa->dsp_size);
txa->phrot->setBuffers(txa->midbuff, txa->midbuff); txa->phrot->setBuffers(txa->midbuff, txa->midbuff);
txa->phrot->setSize(txa->dsp_size); txa->phrot->setSize(txa->dsp_size);
txa->micmeter->setBuffers (txa->midbuff); txa->micmeter->setBuffers (txa->midbuff);

View File

@ -66,6 +66,8 @@ public:
int enum_gain, int enum_gain,
double* pgain double* pgain
); );
METER(const METER&) = delete;
METER& operator=(const METER& other) = delete;
~METER() = default; ~METER() = default;
void flush(); void flush();

View File

@ -32,103 +32,94 @@ warren@wpratt.com
namespace WDSP { namespace WDSP {
PANEL* PANEL::create_panel ( PANEL::PANEL(
int run, int _run,
int size, int _size,
float* in, float* _in,
float* out, float* _out,
double gain1, double _gain1,
double gain2I, double _gain2I,
double gain2Q, double _gain2Q,
int inselect, int _inselect,
int copy int _copy
) ) :
run(_run),
size(_size),
in(_in),
out(_out),
gain1(_gain1),
gain2I(_gain2I),
gain2Q(_gain2Q),
inselect(_inselect),
copy(_copy)
{ {
PANEL* a = new PANEL;
a->run = run;
a->size = size;
a->in = in;
a->out = out;
a->gain1 = gain1;
a->gain2I = gain2I;
a->gain2Q = gain2Q;
a->inselect = inselect;
a->copy = copy;
return a;
} }
void PANEL::destroy_panel (PANEL *a) void PANEL::flush()
{ {
delete (a);
} }
void PANEL::flush_panel (PANEL *) void PANEL::execute()
{
}
void PANEL::xpanel (PANEL *a)
{ {
int i; int i;
double I, Q; double I, Q;
double gainI = a->gain1 * a->gain2I; double gainI = gain1 * gain2I;
double gainQ = a->gain1 * a->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 (a->copy) switch (copy)
{ {
case 0: // no copy case 0: // no copy
for (i = 0; i < a->size; i++) for (i = 0; i < size; i++)
{ {
I = a->in[2 * i + 0] * (a->inselect >> 1); I = in[2 * i + 0] * (inselect >> 1);
Q = a->in[2 * i + 1] * (a->inselect & 1); Q = in[2 * i + 1] * (inselect & 1);
a->out[2 * i + 0] = gainI * I; out[2 * i + 0] = gainI * I;
a->out[2 * i + 1] = gainQ * Q; out[2 * i + 1] = gainQ * Q;
} }
break; break;
case 1: // copy I to Q (then Q == I) case 1: // copy I to Q (then Q == I)
for (i = 0; i < a->size; i++) for (i = 0; i < size; i++)
{ {
I = a->in[2 * i + 0] * (a->inselect >> 1); I = in[2 * i + 0] * (inselect >> 1);
Q = I; Q = I;
a->out[2 * i + 0] = gainI * I; out[2 * i + 0] = gainI * I;
a->out[2 * i + 1] = gainQ * Q; out[2 * i + 1] = gainQ * Q;
} }
break; break;
case 2: // copy Q to I (then I == Q) case 2: // copy Q to I (then I == Q)
for (i = 0; i < a->size; i++) for (i = 0; i < size; i++)
{ {
Q = a->in[2 * i + 1] * (a->inselect & 1); Q = in[2 * i + 1] * (inselect & 1);
I = Q; I = Q;
a->out[2 * i + 0] = gainI * I; out[2 * i + 0] = gainI * I;
a->out[2 * i + 1] = gainQ * Q; out[2 * i + 1] = gainQ * Q;
} }
break; break;
case 3: // reverse (I=>Q and Q=>I) case 3: // reverse (I=>Q and Q=>I)
for (i = 0; i < a->size; i++) for (i = 0; i < size; i++)
{ {
Q = a->in[2 * i + 0] * (a->inselect >> 1); Q = in[2 * i + 0] * (inselect >> 1);
I = a->in[2 * i + 1] * (a->inselect & 1); I = in[2 * i + 1] * (inselect & 1);
a->out[2 * i + 0] = gainI * I; out[2 * i + 0] = gainI * I;
a->out[2 * i + 1] = gainQ * Q; out[2 * i + 1] = gainQ * Q;
} }
break; break;
} }
} }
void PANEL::setBuffers_panel (PANEL *a, float* in, float* out) void PANEL::setBuffers(float* _in, float* _out)
{ {
a->in = in; in = _in;
a->out = out; out = _out;
} }
void PANEL::setSamplerate_panel (PANEL *, int) void PANEL::setSamplerate(int)
{ {
} }
void PANEL::setSize_panel (PANEL *a, int size) void PANEL::setSize(int _size)
{ {
a->size = size; size = _size;
} }
/******************************************************************************************************** /********************************************************************************************************
@ -137,54 +128,54 @@ void PANEL::setSize_panel (PANEL *a, int size)
* * * *
********************************************************************************************************/ ********************************************************************************************************/
void PANEL::SetPanelRun (RXA& rxa, int run) void PANEL::setRun(int _run)
{ {
rxa.panel->run = run; run = _run;
} }
void PANEL::SetPanelSelect (RXA& rxa, int select) void PANEL::setSelect(int _select)
{ {
rxa.panel->inselect = select; inselect = _select;
} }
void PANEL::SetPanelGain1 (RXA& rxa, double gain) void PANEL::setGain1(double _gain)
{ {
rxa.panel->gain1 = gain; gain1 = _gain;
} }
void PANEL::SetPanelGain2 (RXA& rxa, double gainI, double gainQ) void PANEL::setGain2(double _gainI, double _gainQ)
{ {
rxa.panel->gain2I = gainI; gain2I = _gainI;
rxa.panel->gain2Q = gainQ; gain2Q = _gainQ;
} }
void PANEL::SetPanelPan (RXA& rxa, double pan) void PANEL::setPan(double _pan)
{ {
double gain1, gain2; double gain1, 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;
} }
rxa.panel->gain2I = gain1; gain2I = gain1;
rxa.panel->gain2Q = gain2; gain2Q = gain2;
} }
void PANEL::SetPanelCopy (RXA& rxa, int copy) void PANEL::setCopy(int _copy)
{ {
rxa.panel->copy = copy; copy = _copy;
} }
void PANEL::SetPanelBinaural (RXA& rxa, int bin) void PANEL::setBinaural(int _bin)
{ {
rxa.panel->copy = 1 - bin; copy = 1 - _bin;
} }
/******************************************************************************************************** /********************************************************************************************************
@ -193,25 +184,14 @@ void PANEL::SetPanelBinaural (RXA& rxa, int bin)
* * * *
********************************************************************************************************/ ********************************************************************************************************/
void PANEL::SetPanelRun (TXA& txa, int run) void PANEL::setSelectTx(int _select)
{ {
txa.panel->run = run; if (_select == 1)
} copy = 3;
void PANEL::SetPanelGain1 (TXA& txa, double gain)
{
txa.panel->gain1 = gain;
//print_message ("micgainset.txt", "Set MIC Gain to", (int)(100.0 * gain), 0, 0);
}
void PANEL::SetPanelSelect (TXA& txa, int select)
{
if (select == 1)
txa.panel->copy = 3;
else else
txa.panel->copy = 0; copy = 0;
txa.panel->inselect = select; inselect = _select;
} }
} // namespace WDSP } // namespace WDSP

View File

@ -48,7 +48,7 @@ public:
int inselect; int inselect;
int copy; int copy;
static PANEL* create_panel ( PANEL(
int run, int run,
int size, int size,
float* in, float* in,
@ -59,24 +59,25 @@ public:
int inselect, int inselect,
int copy int copy
); );
static void destroy_panel (PANEL *a); PANEL(const PANEL&) = delete;
static void flush_panel (PANEL *a); PANEL& operator=(const PANEL& other) = delete;
static void xpanel (PANEL *a); ~PANEL() = default;
static void setBuffers_panel (PANEL *a, float* in, float* out);
static void setSamplerate_panel (PANEL *a, int rate); void flush();
static void setSize_panel (PANEL *a, int size); void execute();
void setBuffers(float* in, float* out);
void setSamplerate(int rate);
void setSize(int size);
// RXA Properties // RXA Properties
static void SetPanelRun (RXA& rxa, int run); void setRun(int run);
static void SetPanelSelect (RXA& rxa, int select); void setSelect(int select);
static void SetPanelGain1 (RXA& rxa, double gain); void setGain1(double gain);
static void SetPanelGain2 (RXA& rxa, double gainI, double gainQ); void setGain2(double gainI, double gainQ);
static void SetPanelPan (RXA& rxa, double pan); void setPan(double pan);
static void SetPanelCopy (RXA& rxa, int copy); void setCopy(int copy);
static void SetPanelBinaural (RXA& rxa, int bin); void setBinaural(int bin);
// TXA Properties // TXA Properties
static void SetPanelRun (TXA& txa, int run); void setSelectTx(int select);
static void SetPanelGain1 (TXA& txa, double gain);
static void SetPanelSelect (TXA& txa, int select);
}; };
} // namespace WDSP } // namespace WDSP

View File

@ -117,127 +117,122 @@ void FTOV::execute()
void SSQL::compute_ssql_slews(SSQL *a) void SSQL::compute_slews()
{ {
int i;
double delta, theta; double delta, theta;
delta = PI / (double)a->ntup; delta = PI / (double) ntup;
theta = 0.0; theta = 0.0;
for (i = 0; i <= a->ntup; i++) for (int i = 0; i <= ntup; i++)
{ {
a->cup[i] = a->muted_gain + (1.0 - a->muted_gain) * 0.5 * (1.0 - cos(theta)); cup[i] = muted_gain + (1.0 - muted_gain) * 0.5 * (1.0 - cos(theta));
theta += delta; theta += delta;
} }
delta = PI / (double)a->ntdown; delta = PI / (double)ntdown;
theta = 0.0; theta = 0.0;
for (i = 0; i <= a->ntdown; i++) for (int i = 0; i <= ntdown; i++)
{ {
a->cdown[i] = a->muted_gain + (1.0 - a->muted_gain) * 0.5 * (1.0 + cos(theta)); cdown[i] = muted_gain + (1.0 - muted_gain) * 0.5 * (1.0 + cos(theta));
theta += delta; theta += delta;
} }
} }
void SSQL::calc_ssql (SSQL *a) void SSQL::calc()
{ {
a->b1 = new float[a->size * 2]; // (float*) malloc0 (a->size * sizeof (complex)); b1 = new float[size * 2]; // (float*) malloc0 (size * sizeof (complex));
a->dcbl = new CBL(1, a->size, a->in, a->b1, 0, a->rate, 0.02); dcbl = new CBL(1, size, in, b1, 0, rate, 0.02);
a->ibuff = new float[a->size]; // (float*) malloc0 (a->size * sizeof (float)); ibuff = new float[size]; // (float*) malloc0 (size * sizeof (float));
a->ftovbuff = new float[a->size]; // (float*) malloc0(a->size * sizeof (float)); ftovbuff = new float[size]; // (float*) malloc0(size * sizeof (float));
a->cvtr = new FTOV(1, a->size, a->rate, a->ftov_rsize, a->ftov_fmax, a->ibuff, a->ftovbuff); cvtr = new FTOV(1, size, rate, ftov_rsize, ftov_fmax, ibuff, ftovbuff);
a->lpbuff = new float[a->size]; // (float*) malloc0 (a->size * sizeof (float)); lpbuff = new float[size]; // (float*) malloc0 (size * sizeof (float));
a->filt = new DBQLP(1, a->size, a->ftovbuff, a->lpbuff, a->rate, 11.3, 1.0, 1.0, 1); filt = new DBQLP(1, size, ftovbuff, lpbuff, rate, 11.3, 1.0, 1.0, 1);
a->wdbuff = new int[a->size]; // (int*) malloc0 (a->size * sizeof (int)); wdbuff = new int[size]; // (int*) malloc0 (size * sizeof (int));
a->tr_signal = new int[a->size]; // (int*) malloc0 (a->size * sizeof (int)); tr_signal = new int[size]; // (int*) malloc0 (size * sizeof (int));
// window detector // window detector
a->wdmult = exp (-1.0 / (a->rate * a->wdtau)); wdmult = exp (-1.0 / (rate * wdtau));
a->wdaverage = 0.0; wdaverage = 0.0;
// trigger // trigger
a->tr_voltage = a->tr_thresh; tr_voltage = tr_thresh;
a->mute_mult = 1.0 - exp (-1.0 / (a->rate * a->tr_tau_mute)); mute_mult = 1.0 - exp (-1.0 / (rate * tr_tau_mute));
a->unmute_mult = 1.0 - exp (-1.0 / (a->rate * a->tr_tau_unmute)); unmute_mult = 1.0 - exp (-1.0 / (rate * tr_tau_unmute));
// level change // level change
a->ntup = (int)(a->tup * a->rate); ntup = (int)(tup * rate);
a->ntdown = (int)(a->tdown * a->rate); ntdown = (int)(tdown * rate);
a->cup = new float[a->ntup + 1]; // (float*) malloc0 ((a->ntup + 1) * sizeof (float)); cup = new float[ntup + 1]; // (float*) malloc0 ((ntup + 1) * sizeof (float));
a->cdown = new float[a->ntdown + 1]; // (float*) malloc0 ((a->ntdown + 1) * sizeof (float)); cdown = new float[ntdown + 1]; // (float*) malloc0 ((ntdown + 1) * sizeof (float));
compute_ssql_slews (a); compute_slews();
// control // control
a->state = 0; state = 0;
a->count = 0; count = 0;
} }
void SSQL::decalc_ssql (SSQL *a) void SSQL::decalc()
{ {
delete[] (a->tr_signal); delete[] (tr_signal);
delete[] (a->wdbuff); delete[] (wdbuff);
delete (a->filt); delete (filt);
delete[] (a->lpbuff); delete[] (lpbuff);
delete (a->cvtr); delete (cvtr);
delete[] (a->ftovbuff); delete[] (ftovbuff);
delete[] (a->ibuff); delete[] (ibuff);
delete (a->dcbl); delete (dcbl);
delete[] (a->b1); delete[] (b1);
delete[] (a->cdown); delete[] (cdown);
delete[] (a->cup); delete[] (cup);
} }
SSQL* SSQL::create_ssql ( SSQL::SSQL(
int run, int _run,
int size, int _size,
float* in, float* _in,
float* out, float* _out,
int rate, int _rate,
double tup, double _tup,
double tdown, double _tdown,
double muted_gain, double _muted_gain,
double tau_mute, double _tau_mute,
double tau_unmute, double _tau_unmute,
double wthresh, double _wthresh,
double tr_thresh, double _tr_thresh,
int rsize, int _rsize,
double fmax double _fmax
) )
{ {
SSQL *a = new SSQL; run = _run;
a->run = run; size = _size;
a->size = size; in = _in;
a->in = in; out = _out;
a->out = out; rate = _rate;
a->rate = rate; tup = _tup;
a->tup = tup; tdown = _tdown;
a->tdown = tdown; muted_gain = _muted_gain;
a->muted_gain = muted_gain; tr_tau_mute = _tau_mute;
a->tr_tau_mute = tau_mute; tr_tau_unmute = _tau_unmute;
a->tr_tau_unmute = tau_unmute; wthresh = _wthresh; // PRIMARY SQUELCH THRESHOLD CONTROL
a->wthresh = wthresh; // PRIMARY SQUELCH THRESHOLD CONTROL tr_thresh = _tr_thresh; // value between tr_ss_unmute and tr_ss_mute, default = 0.8197
a->tr_thresh = tr_thresh; // value between tr_ss_unmute and tr_ss_mute, default = 0.8197 tr_ss_mute = 1.0;
a->tr_ss_mute = 1.0; tr_ss_unmute = 0.3125;
a->tr_ss_unmute = 0.3125; wdtau = 0.5;
a->wdtau = 0.5; ftov_rsize = _rsize;
a->ftov_rsize = rsize; ftov_fmax = _fmax;
a->ftov_fmax = fmax; calc();
calc_ssql (a);
return a;
} }
void SSQL::destroy_ssql (SSQL *a) SSQL::~SSQL()
{ {
decalc_ssql (a); decalc();
delete (a);
} }
void SSQL::flush_ssql (SSQL *a) void SSQL::flush()
{ {
std::fill(b1, b1 + size * 2, 0);
std::fill(a->b1, a->b1 + a->size * 2, 0); dcbl->flush();
a->dcbl->flush(); memset (ibuff, 0, size * sizeof (float));
memset (a->ibuff, 0, a->size * sizeof (float)); memset (ftovbuff, 0, size * sizeof (float));
memset (a->ftovbuff, 0, a->size * sizeof (float)); cvtr->flush();
a->cvtr->flush(); memset (lpbuff, 0, size * sizeof (float));
memset (a->lpbuff, 0, a->size * sizeof (float)); filt->flush();
a->filt->flush(); memset (wdbuff, 0, size * sizeof (int));
memset (a->wdbuff, 0, a->size * sizeof (int)); memset (tr_signal, 0, size * sizeof (int));
memset (a->tr_signal, 0, a->size * sizeof (int));
} }
enum _ssqlstate enum _ssqlstate
@ -248,98 +243,98 @@ enum _ssqlstate
DECREASE DECREASE
}; };
void SSQL::xssql (SSQL *a) void SSQL::execute()
{ {
if (a->run) if (run)
{ {
a->dcbl->execute(); // dc block the input signal dcbl->execute(); // dc block the input signal
for (int i = 0; i < a->size; i++) // extract 'I' component for (int i = 0; i < size; i++) // extract 'I' component
a->ibuff[i] = a->b1[2 * i]; ibuff[i] = b1[2 * i];
a->cvtr->execute(); // convert frequency to voltage, ignoring amplitude cvtr->execute(); // convert frequency to voltage, ignoring amplitude
// WriteAudioWDSP(20.0, a->rate, a->size, a->ftovbuff, 4, 0.99); // WriteAudioWDSP(20.0, rate, size, ftovbuff, 4, 0.99);
a->filt->execute(); // low-pass filter filt->execute(); // low-pass filter
// WriteAudioWDSP(20.0, a->rate, a->size, a->lpbuff, 4, 0.99); // WriteAudioWDSP(20.0, rate, size, lpbuff, 4, 0.99);
// calculate the output of the window detector for each sample // calculate the output of the window detector for each sample
for (int i = 0; i < a->size; i++) for (int i = 0; i < size; i++)
{ {
a->wdaverage = a->wdmult * a->wdaverage + (1.0 - a->wdmult) * a->lpbuff[i]; wdaverage = wdmult * wdaverage + (1.0 - wdmult) * lpbuff[i];
if ((a->lpbuff[i] - a->wdaverage) > a->wthresh || (a->wdaverage - a->lpbuff[i]) > a->wthresh) if ((lpbuff[i] - wdaverage) > wthresh || (wdaverage - lpbuff[i]) > wthresh)
a->wdbuff[i] = 0; // signal unmute wdbuff[i] = 0; // signal unmute
else else
a->wdbuff[i] = 1; // signal mute wdbuff[i] = 1; // signal mute
} }
// calculate the trigger signal for each sample // calculate the trigger signal for each sample
for (int i = 0; i < a->size; i++) for (int i = 0; i < size; i++)
{ {
if (a->wdbuff[i] == 0) if (wdbuff[i] == 0)
a->tr_voltage += (a->tr_ss_unmute - a->tr_voltage) * a->unmute_mult; tr_voltage += (tr_ss_unmute - tr_voltage) * unmute_mult;
if (a->wdbuff[i] == 1) if (wdbuff[i] == 1)
a->tr_voltage += (a->tr_ss_mute - a->tr_voltage) * a->mute_mult; tr_voltage += (tr_ss_mute - tr_voltage) * mute_mult;
if (a->tr_voltage > a->tr_thresh) a->tr_signal[i] = 0; // muted if (tr_voltage > tr_thresh) tr_signal[i] = 0; // muted
else a->tr_signal[i] = 1; // unmuted else tr_signal[i] = 1; // unmuted
} }
// execute state machine; calculate audio output // execute state machine; calculate audio output
for (int i = 0; i < a->size; i++) for (int i = 0; i < size; i++)
{ {
switch (a->state) switch (state)
{ {
case MUTED: case MUTED:
if (a->tr_signal[i] == 1) if (tr_signal[i] == 1)
{ {
a->state = INCREASE; state = INCREASE;
a->count = a->ntup; count = ntup;
} }
a->out[2 * i + 0] = a->muted_gain * a->in[2 * i + 0]; out[2 * i + 0] = muted_gain * in[2 * i + 0];
a->out[2 * i + 1] = a->muted_gain * a->in[2 * i + 1]; out[2 * i + 1] = muted_gain * in[2 * i + 1];
break; break;
case INCREASE: case INCREASE:
a->out[2 * i + 0] = a->in[2 * i + 0] * a->cup[a->ntup - a->count]; out[2 * i + 0] = in[2 * i + 0] * cup[ntup - count];
a->out[2 * i + 1] = a->in[2 * i + 1] * a->cup[a->ntup - a->count]; out[2 * i + 1] = in[2 * i + 1] * cup[ntup - count];
if (a->count-- == 0) if (count-- == 0)
a->state = UNMUTED; state = UNMUTED;
break; break;
case UNMUTED: case UNMUTED:
if (a->tr_signal[i] == 0) if (tr_signal[i] == 0)
{ {
a->state = DECREASE; state = DECREASE;
a->count = a->ntdown; count = ntdown;
} }
a->out[2 * i + 0] = a->in[2 * i + 0]; out[2 * i + 0] = in[2 * i + 0];
a->out[2 * i + 1] = a->in[2 * i + 1]; out[2 * i + 1] = in[2 * i + 1];
break; break;
case DECREASE: case DECREASE:
a->out[2 * i + 0] = a->in[2 * i + 0] * a->cdown[a->ntdown - a->count]; out[2 * i + 0] = in[2 * i + 0] * cdown[ntdown - count];
a->out[2 * i + 1] = a->in[2 * i + 1] * a->cdown[a->ntdown - a->count]; out[2 * i + 1] = in[2 * i + 1] * cdown[ntdown - count];
if (a->count-- == 0) if (count-- == 0)
a->state = MUTED; state = MUTED;
break; break;
} }
} }
} }
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 SSQL::setBuffers_ssql (SSQL *a, float* in, float* out) void SSQL::setBuffers(float* _in, float* _out)
{ {
decalc_ssql (a); decalc();
a->in = in; in = _in;
a->out = out; out = _out;
calc_ssql (a); calc();
} }
void SSQL::setSamplerate_ssql (SSQL *a, int rate) void SSQL::setSamplerate(int _rate)
{ {
decalc_ssql (a); decalc();
a->rate = rate; rate = _rate;
calc_ssql (a); calc();
} }
void SSQL::setSize_ssql (SSQL *a, int size) void SSQL::setSize(int _size)
{ {
decalc_ssql (a); decalc();
a->size = size; size = _size;
calc_ssql (a); calc();
} }
/******************************************************************************************************** /********************************************************************************************************
@ -348,34 +343,32 @@ void SSQL::setSize_ssql (SSQL *a, int size)
* * * *
********************************************************************************************************/ ********************************************************************************************************/
void SSQL::SetSSQLRun (RXA& rxa, int run) void SSQL::setRun(int _run)
{ {
rxa.ssql->run = run; run = _run;
} }
void SSQL::SetSSQLThreshold (RXA& rxa, double threshold) void SSQL::setThreshold(double _threshold)
{ {
// 'threshold' should be between 0.0 and 1.0 // 'threshold' should be between 0.0 and 1.0
// WU2O testing: 0.16 is a good default for 'threshold'; => 0.08 for 'wthresh' // WU2O testing: 0.16 is a good default for 'threshold'; => 0.08 for 'wthresh'
rxa.ssql->wthresh = threshold / 2.0; wthresh = _threshold / 2.0;
} }
void SSQL::SetSSQLTauMute (RXA& rxa, double tau_mute) void SSQL::setTauMute(double _tau_mute)
{ {
// reasonable (wide) range is 0.1 to 2.0 // reasonable (wide) range is 0.1 to 2.0
// WU2O testing: 0.1 is good default value // WU2O testing: 0.1 is good default value
SSQL *a = rxa.ssql; tr_tau_mute = _tau_mute;
a->tr_tau_mute = tau_mute; mute_mult = 1.0 - exp (-1.0 / (rate * tr_tau_mute));
a->mute_mult = 1.0 - exp (-1.0 / (a->rate * a->tr_tau_mute));
} }
void SSQL::SetSSQLTauUnMute (RXA& rxa, double tau_unmute) void SSQL::setTauUnMute(double _tau_unmute)
{ {
// reasonable (wide) range is 0.1 to 1.0 // reasonable (wide) range is 0.1 to 1.0
// WU2O testing: 0.1 is good default value // WU2O testing: 0.1 is good default value
SSQL *a = rxa.ssql; tr_tau_unmute = _tau_unmute;
a->tr_tau_unmute = tau_unmute; unmute_mult = 1.0 - exp (-1.0 / (rate * tr_tau_unmute));
a->unmute_mult = 1.0 - exp (-1.0 / (a->rate * a->tr_tau_unmute));
} }
} // namespace WDSP } // namespace WDSP

View File

@ -117,7 +117,7 @@ public:
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 int* tr_signal; // trigger signal, 0 or 1
static SSQL* create_ssql ( SSQL(
int run, int run,
int size, int size,
float* in, float* in,
@ -133,22 +133,25 @@ public:
int rsize, int rsize,
double fmax double fmax
); );
static void destroy_ssql (SSQL *a); SSQL(const SSQL&) = delete;
static void flush_ssql (SSQL *a); SSQL& operator=(const SSQL& other) = delete;
static void xssql (SSQL *a); ~SSQL();
static void setBuffers_ssql (SSQL *a, float* in, float* out);
static void setSamplerate_ssql (SSQL *a, int rate); void flush();
static void setSize_ssql (SSQL *a, int size); void execute();
void setBuffers(float* in, float* out);
void setSamplerate(int rate);
void setSize(int size);
// RXA Properties // RXA Properties
static void SetSSQLRun (RXA& rxa, int run); void setRun(int run);
static void SetSSQLThreshold (RXA& rxa, double threshold); void setThreshold(double threshold);
static void SetSSQLTauMute (RXA& rxa, double tau_mute); void setTauMute(double tau_mute);
static void SetSSQLTauUnMute (RXA& rxa, double tau_unmute); void setTauUnMute(double tau_unmute);
private: private:
static void compute_ssql_slews(SSQL *a); void compute_slews();
static void calc_ssql (SSQL *a); void calc();
static void decalc_ssql (SSQL *a); void decalc();
}; };
} // namespace WDSP } // namespace WDSP