2024-06-29 14:03:13 -04:00
|
|
|
/* nobII.c
|
|
|
|
|
|
|
|
This file is part of a program that implements a Software-Defined Radio.
|
|
|
|
|
|
|
|
Copyright (C) 2014 Warren Pratt, NR0V
|
|
|
|
Copyright (C) 2024 Edouard Griffiths, F4EXB Adapted to SDRangel
|
|
|
|
|
|
|
|
This program is free software; you can redistribute it and/or
|
|
|
|
modify it under the terms of the GNU General Public License
|
|
|
|
as published by the Free Software Foundation; either version 2
|
|
|
|
of the License, or (at your option) any later version.
|
|
|
|
|
|
|
|
This program is distributed in the hope that it will be useful,
|
|
|
|
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
GNU General Public License for more details.
|
|
|
|
|
|
|
|
You should have received a copy of the GNU General Public License
|
|
|
|
along with this program; if not, write to the Free Software
|
|
|
|
Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
|
|
|
|
|
|
|
|
The author can be reached by email at
|
|
|
|
|
|
|
|
warren@wpratt.com
|
|
|
|
|
|
|
|
*/
|
|
|
|
|
|
|
|
#include "comm.hpp"
|
|
|
|
|
2024-07-21 05:24:54 -04:00
|
|
|
#define MAX_ADV_SLEW_TIME (0.01) // Slew time
|
|
|
|
#define MAX_ADV_TIME (0.01) // Lead time
|
|
|
|
#define MAX_HANG_SLEW_TIME (0.01) // Slew time
|
|
|
|
#define MAX_HANG_TIME (0.01) // Lag time
|
2024-06-29 14:03:13 -04:00
|
|
|
#define MAX_SEQ_TIME (0.025)
|
|
|
|
#define MAX_SAMPLERATE (1536000.0)
|
|
|
|
|
|
|
|
#include "nob.hpp"
|
|
|
|
#include "RXA.hpp"
|
|
|
|
|
|
|
|
namespace WDSP {
|
|
|
|
|
2024-07-23 02:06:13 -04:00
|
|
|
void NOB::init_nob()
|
2024-06-29 14:03:13 -04:00
|
|
|
{
|
|
|
|
int i;
|
|
|
|
double coef;
|
2024-07-17 15:19:57 -04:00
|
|
|
|
2024-07-23 02:06:13 -04:00
|
|
|
adv_slew_count = (int)(advslewtime * samplerate);
|
|
|
|
adv_count = (int)(advtime * samplerate);
|
|
|
|
hang_count = (int)(hangtime * samplerate);
|
|
|
|
hang_slew_count = (int)(hangslewtime * samplerate);
|
|
|
|
max_imp_seq = (int)(max_imp_seq_time * samplerate);
|
|
|
|
backmult = exp (-1.0 / (samplerate * backtau));
|
|
|
|
ombackmult = 1.0 - backmult;
|
2024-07-17 15:19:57 -04:00
|
|
|
|
2024-07-23 02:06:13 -04:00
|
|
|
if (adv_slew_count > 0)
|
2024-06-29 14:03:13 -04:00
|
|
|
{
|
2024-07-23 02:06:13 -04:00
|
|
|
coef = PI / (adv_slew_count + 1);
|
2024-07-17 15:19:57 -04:00
|
|
|
|
2024-07-23 02:06:13 -04:00
|
|
|
for (i = 0; i < adv_slew_count; i++)
|
|
|
|
awave[i] = 0.5 * cos ((i + 1) * coef);
|
2024-06-29 14:03:13 -04:00
|
|
|
}
|
2024-07-17 15:19:57 -04:00
|
|
|
|
2024-07-23 02:06:13 -04:00
|
|
|
if (hang_slew_count > 0)
|
2024-06-29 14:03:13 -04:00
|
|
|
{
|
2024-07-23 02:06:13 -04:00
|
|
|
coef = PI / hang_slew_count;
|
2024-07-17 15:19:57 -04:00
|
|
|
|
2024-07-23 02:06:13 -04:00
|
|
|
for (i = 0; i < hang_slew_count; i++)
|
|
|
|
hwave[i] = 0.5 * cos (i * coef);
|
2024-06-29 14:03:13 -04:00
|
|
|
}
|
|
|
|
|
2024-07-23 02:06:13 -04:00
|
|
|
flush();
|
2024-06-29 14:03:13 -04:00
|
|
|
}
|
|
|
|
|
2024-07-23 02:06:13 -04:00
|
|
|
NOB::NOB (
|
|
|
|
int _run,
|
|
|
|
int _buffsize,
|
|
|
|
float* _in,
|
|
|
|
float* _out,
|
|
|
|
double _samplerate,
|
|
|
|
int _mode,
|
|
|
|
double _advslewtime,
|
|
|
|
double _advtime,
|
|
|
|
double _hangslewtime,
|
|
|
|
double _hangtime,
|
|
|
|
double _max_imp_seq_time,
|
|
|
|
double _backtau,
|
|
|
|
double _threshold
|
|
|
|
)
|
2024-06-29 14:03:13 -04:00
|
|
|
{
|
2024-07-23 02:06:13 -04:00
|
|
|
run = _run;
|
|
|
|
buffsize = _buffsize;
|
|
|
|
in = _in;
|
|
|
|
out = _out;
|
|
|
|
samplerate = _samplerate;
|
|
|
|
mode = _mode;
|
|
|
|
advslewtime = _advslewtime;
|
|
|
|
advtime = _advtime;
|
|
|
|
hangslewtime = _hangslewtime;
|
|
|
|
hangtime = _hangtime;
|
|
|
|
max_imp_seq_time = _max_imp_seq_time;
|
|
|
|
backtau = _backtau;
|
|
|
|
threshold = _threshold;
|
|
|
|
dline_size = (int)(MAX_SAMPLERATE * (
|
|
|
|
MAX_ADV_SLEW_TIME +
|
|
|
|
MAX_ADV_TIME +
|
|
|
|
MAX_HANG_SLEW_TIME +
|
|
|
|
MAX_HANG_TIME +
|
|
|
|
MAX_SEQ_TIME ) + 2);
|
|
|
|
dline = new double[dline_size * 2];
|
|
|
|
imp = new int[dline_size];
|
|
|
|
awave = new double[(int)(MAX_ADV_SLEW_TIME * MAX_SAMPLERATE + 1)];
|
|
|
|
hwave = new double[(int)(MAX_HANG_SLEW_TIME * MAX_SAMPLERATE + 1)];
|
|
|
|
|
|
|
|
filterlen = 10;
|
|
|
|
bfbuff = new double[filterlen * 2];
|
|
|
|
ffbuff = new double[filterlen * 2];
|
|
|
|
fcoefs = new double[filterlen];
|
|
|
|
fcoefs[0] = 0.308720593;
|
|
|
|
fcoefs[1] = 0.216104415;
|
|
|
|
fcoefs[2] = 0.151273090;
|
|
|
|
fcoefs[3] = 0.105891163;
|
|
|
|
fcoefs[4] = 0.074123814;
|
|
|
|
fcoefs[5] = 0.051886670;
|
|
|
|
fcoefs[6] = 0.036320669;
|
|
|
|
fcoefs[7] = 0.025424468;
|
|
|
|
fcoefs[8] = 0.017797128;
|
|
|
|
fcoefs[9] = 0.012457989;
|
|
|
|
|
|
|
|
init_nob();
|
|
|
|
|
|
|
|
legacy = new double[2048 * 2]; /////////////// legacy interface - remove
|
2024-06-29 14:03:13 -04:00
|
|
|
}
|
|
|
|
|
2024-07-23 02:06:13 -04:00
|
|
|
NOB::~NOB()
|
2024-06-29 14:03:13 -04:00
|
|
|
{
|
2024-07-23 02:06:13 -04:00
|
|
|
delete[] (legacy); /////////////// remove
|
|
|
|
delete[] (fcoefs);
|
|
|
|
delete[] (ffbuff);
|
|
|
|
delete[] (bfbuff);
|
|
|
|
delete[] (hwave);
|
|
|
|
delete[] (awave);
|
|
|
|
delete[] (imp);
|
|
|
|
delete[] (dline);
|
2024-06-29 14:03:13 -04:00
|
|
|
}
|
|
|
|
|
2024-07-23 02:06:13 -04:00
|
|
|
void NOB::flush()
|
2024-06-29 14:03:13 -04:00
|
|
|
{
|
2024-07-23 02:06:13 -04:00
|
|
|
out_idx = 0;
|
|
|
|
scan_idx = out_idx + adv_slew_count + adv_count + 1;
|
|
|
|
in_idx = scan_idx + max_imp_seq + hang_count + hang_slew_count + filterlen;
|
|
|
|
state = 0;
|
|
|
|
overflow = 0;
|
|
|
|
avg = 1.0;
|
|
|
|
bfb_in_idx = filterlen - 1;
|
|
|
|
ffb_in_idx = filterlen - 1;
|
|
|
|
std::fill(dline, dline + dline_size * 2, 0);
|
|
|
|
std::fill(imp, imp + dline_size, 0);
|
|
|
|
std::fill(bfbuff, bfbuff + filterlen * 2, 0);
|
|
|
|
std::fill(ffbuff, ffbuff + filterlen * 2, 0);
|
2024-06-29 14:03:13 -04:00
|
|
|
}
|
|
|
|
|
2024-07-23 13:39:09 -04:00
|
|
|
void NOB::execute()
|
2024-06-29 14:03:13 -04:00
|
|
|
{
|
|
|
|
double scale;
|
|
|
|
double mag;
|
|
|
|
int bf_idx;
|
|
|
|
int ff_idx;
|
|
|
|
int lidx, tidx;
|
|
|
|
int i, j, k;
|
|
|
|
int bfboutidx;
|
|
|
|
int ffboutidx;
|
|
|
|
int hcount;
|
|
|
|
int len;
|
|
|
|
int ffcount;
|
|
|
|
int staydown;
|
2024-07-13 17:59:46 -04:00
|
|
|
|
2024-07-23 02:06:13 -04:00
|
|
|
if (run)
|
2024-06-29 14:03:13 -04:00
|
|
|
{
|
2024-07-23 02:06:13 -04:00
|
|
|
for (i = 0; i < buffsize; i++)
|
2024-06-29 14:03:13 -04:00
|
|
|
{
|
2024-07-23 02:06:13 -04:00
|
|
|
dline[2 * in_idx + 0] = in[2 * i + 0];
|
|
|
|
dline[2 * in_idx + 1] = in[2 * i + 1];
|
|
|
|
mag = sqrt(dline[2 * in_idx + 0] * dline[2 * in_idx + 0] + dline[2 * in_idx + 1] * dline[2 * in_idx + 1]);
|
|
|
|
avg = backmult * avg + ombackmult * mag;
|
2024-07-17 15:19:57 -04:00
|
|
|
|
2024-07-23 02:06:13 -04:00
|
|
|
if (mag > (avg * threshold))
|
|
|
|
imp[in_idx] = 1;
|
2024-06-29 14:03:13 -04:00
|
|
|
else
|
2024-07-23 02:06:13 -04:00
|
|
|
imp[in_idx] = 0;
|
2024-07-17 15:19:57 -04:00
|
|
|
|
2024-07-23 02:06:13 -04:00
|
|
|
if ((bf_idx = out_idx + adv_slew_count) >= dline_size)
|
|
|
|
bf_idx -= dline_size;
|
2024-07-17 15:19:57 -04:00
|
|
|
|
2024-07-23 02:06:13 -04:00
|
|
|
if (imp[bf_idx] == 0)
|
2024-06-29 14:03:13 -04:00
|
|
|
{
|
2024-07-23 02:06:13 -04:00
|
|
|
if (++bfb_in_idx == filterlen)
|
|
|
|
bfb_in_idx -= filterlen;
|
2024-07-17 15:19:57 -04:00
|
|
|
|
2024-07-23 02:06:13 -04:00
|
|
|
bfbuff[2 * bfb_in_idx + 0] = dline[2 * bf_idx + 0];
|
|
|
|
bfbuff[2 * bfb_in_idx + 1] = dline[2 * bf_idx + 1];
|
2024-06-29 14:03:13 -04:00
|
|
|
}
|
|
|
|
|
2024-07-23 02:06:13 -04:00
|
|
|
switch (state)
|
2024-06-29 14:03:13 -04:00
|
|
|
{
|
|
|
|
case 0: // normal output & impulse setup
|
|
|
|
{
|
2024-07-23 02:06:13 -04:00
|
|
|
out[2 * i + 0] = dline[2 * out_idx + 0];
|
|
|
|
out[2 * i + 1] = dline[2 * out_idx + 1];
|
|
|
|
Ilast = dline[2 * out_idx + 0];
|
|
|
|
Qlast = dline[2 * out_idx + 1];
|
2024-07-17 15:19:57 -04:00
|
|
|
|
2024-07-23 02:06:13 -04:00
|
|
|
if (imp[scan_idx] > 0)
|
2024-06-29 14:03:13 -04:00
|
|
|
{
|
2024-07-23 02:06:13 -04:00
|
|
|
time = 0;
|
2024-07-17 15:19:57 -04:00
|
|
|
|
2024-07-23 02:06:13 -04:00
|
|
|
if (adv_slew_count > 0)
|
|
|
|
state = 1;
|
|
|
|
else if (adv_count > 0)
|
|
|
|
state = 2;
|
2024-06-29 14:03:13 -04:00
|
|
|
else
|
2024-07-23 02:06:13 -04:00
|
|
|
state = 3;
|
2024-07-17 15:19:57 -04:00
|
|
|
|
2024-07-23 02:06:13 -04:00
|
|
|
tidx = scan_idx;
|
|
|
|
blank_count = 0;
|
2024-07-17 15:19:57 -04:00
|
|
|
|
2024-06-29 14:03:13 -04:00
|
|
|
do
|
|
|
|
{
|
|
|
|
len = 0;
|
|
|
|
hcount = 0;
|
2024-07-17 15:19:57 -04:00
|
|
|
|
2024-07-23 02:06:13 -04:00
|
|
|
while ((imp[tidx] > 0 || hcount > 0) && blank_count < max_imp_seq)
|
2024-06-29 14:03:13 -04:00
|
|
|
{
|
2024-07-23 02:06:13 -04:00
|
|
|
blank_count++;
|
2024-07-17 15:19:57 -04:00
|
|
|
if (hcount > 0)
|
|
|
|
hcount--;
|
2024-07-23 02:06:13 -04:00
|
|
|
if (imp[tidx] > 0)
|
|
|
|
hcount = hang_count + hang_slew_count;
|
|
|
|
if (++tidx >= dline_size)
|
|
|
|
tidx -= dline_size;
|
2024-06-29 14:03:13 -04:00
|
|
|
}
|
2024-07-17 15:19:57 -04:00
|
|
|
|
2024-06-29 14:03:13 -04:00
|
|
|
j = 1;
|
|
|
|
len = 0;
|
|
|
|
lidx = tidx;
|
2024-07-17 15:19:57 -04:00
|
|
|
|
2024-07-23 02:06:13 -04:00
|
|
|
while (j <= adv_slew_count + adv_count && len == 0)
|
2024-06-29 14:03:13 -04:00
|
|
|
{
|
2024-07-23 02:06:13 -04:00
|
|
|
if (imp[lidx] == 1)
|
2024-06-29 14:03:13 -04:00
|
|
|
{
|
|
|
|
len = j;
|
|
|
|
tidx = lidx;
|
|
|
|
}
|
2024-07-17 15:19:57 -04:00
|
|
|
|
2024-07-23 02:06:13 -04:00
|
|
|
if (++lidx >= dline_size)
|
|
|
|
lidx -= dline_size;
|
2024-07-17 15:19:57 -04:00
|
|
|
|
2024-06-29 14:03:13 -04:00
|
|
|
j++;
|
|
|
|
}
|
2024-07-17 15:19:57 -04:00
|
|
|
|
2024-07-23 02:06:13 -04:00
|
|
|
if((blank_count += len) > max_imp_seq)
|
2024-06-29 14:03:13 -04:00
|
|
|
{
|
2024-07-23 02:06:13 -04:00
|
|
|
blank_count = max_imp_seq;
|
|
|
|
overflow = 1;
|
2024-06-29 14:03:13 -04:00
|
|
|
break;
|
|
|
|
}
|
2024-07-17 15:19:57 -04:00
|
|
|
}
|
|
|
|
while (len != 0);
|
|
|
|
|
2024-07-23 02:06:13 -04:00
|
|
|
if (overflow == 0)
|
2024-06-29 14:03:13 -04:00
|
|
|
{
|
2024-07-23 02:06:13 -04:00
|
|
|
blank_count -= hang_slew_count;
|
|
|
|
Inext = dline[2 * tidx + 0];
|
|
|
|
Qnext = dline[2 * tidx + 1];
|
2024-06-29 14:03:13 -04:00
|
|
|
|
2024-07-23 02:06:13 -04:00
|
|
|
if (mode == 1 || mode == 2 || mode == 4)
|
2024-06-29 14:03:13 -04:00
|
|
|
{
|
2024-07-23 02:06:13 -04:00
|
|
|
bfboutidx = bfb_in_idx;
|
|
|
|
I1 = 0.0;
|
|
|
|
Q1 = 0.0;
|
2024-07-17 15:19:57 -04:00
|
|
|
|
2024-07-23 02:06:13 -04:00
|
|
|
for (k = 0; k < filterlen; k++)
|
2024-06-29 14:03:13 -04:00
|
|
|
{
|
2024-07-23 02:06:13 -04:00
|
|
|
I1 += fcoefs[k] * bfbuff[2 * bfboutidx + 0];
|
|
|
|
Q1 += fcoefs[k] * bfbuff[2 * bfboutidx + 1];
|
2024-07-17 15:19:57 -04:00
|
|
|
|
|
|
|
if (--bfboutidx < 0)
|
2024-07-23 02:06:13 -04:00
|
|
|
bfboutidx += filterlen;
|
2024-06-29 14:03:13 -04:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2024-07-23 02:06:13 -04:00
|
|
|
if (mode == 2 || mode == 3 || mode == 4)
|
2024-06-29 14:03:13 -04:00
|
|
|
{
|
2024-07-23 02:06:13 -04:00
|
|
|
if ((ff_idx = scan_idx + blank_count) >= dline_size)
|
|
|
|
ff_idx -= dline_size;
|
2024-07-17 15:19:57 -04:00
|
|
|
|
2024-06-29 14:03:13 -04:00
|
|
|
ffcount = 0;
|
2024-07-17 15:19:57 -04:00
|
|
|
|
2024-07-23 02:06:13 -04:00
|
|
|
while (ffcount < filterlen)
|
2024-06-29 14:03:13 -04:00
|
|
|
{
|
2024-07-23 02:06:13 -04:00
|
|
|
if (imp[ff_idx] == 0)
|
2024-06-29 14:03:13 -04:00
|
|
|
{
|
2024-07-23 02:06:13 -04:00
|
|
|
if (++ffb_in_idx == filterlen)
|
|
|
|
ffb_in_idx -= filterlen;
|
2024-07-17 15:19:57 -04:00
|
|
|
|
2024-07-23 02:06:13 -04:00
|
|
|
ffbuff[2 * ffb_in_idx + 0] = dline[2 * ff_idx + 0];
|
|
|
|
ffbuff[2 * ffb_in_idx + 1] = dline[2 * ff_idx + 1];
|
2024-06-29 14:03:13 -04:00
|
|
|
++ffcount;
|
|
|
|
}
|
2024-07-17 15:19:57 -04:00
|
|
|
|
2024-07-23 02:06:13 -04:00
|
|
|
if (++ff_idx >= dline_size)
|
|
|
|
ff_idx -= dline_size;
|
2024-06-29 14:03:13 -04:00
|
|
|
}
|
2024-07-17 15:19:57 -04:00
|
|
|
|
2024-07-23 02:06:13 -04:00
|
|
|
if ((ffboutidx = ffb_in_idx + 1) >= filterlen)
|
|
|
|
ffboutidx -= filterlen;
|
2024-07-17 15:19:57 -04:00
|
|
|
|
2024-07-23 02:06:13 -04:00
|
|
|
I2 = 0.0;
|
|
|
|
Q2 = 0.0;
|
2024-07-17 15:19:57 -04:00
|
|
|
|
2024-07-23 02:06:13 -04:00
|
|
|
for (k = 0; k < filterlen; k++)
|
2024-06-29 14:03:13 -04:00
|
|
|
{
|
2024-07-23 02:06:13 -04:00
|
|
|
I2 += fcoefs[k] * ffbuff[2 * ffboutidx + 0];
|
|
|
|
Q2 += fcoefs[k] * ffbuff[2 * ffboutidx + 1];
|
2024-07-17 15:19:57 -04:00
|
|
|
|
2024-07-23 02:06:13 -04:00
|
|
|
if (++ffboutidx >= filterlen)
|
|
|
|
ffboutidx -= filterlen;
|
2024-06-29 14:03:13 -04:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2024-07-23 02:06:13 -04:00
|
|
|
switch (mode)
|
2024-06-29 14:03:13 -04:00
|
|
|
{
|
|
|
|
case 0: // zero
|
2024-07-23 02:06:13 -04:00
|
|
|
deltaI = 0.0;
|
|
|
|
deltaQ = 0.0;
|
|
|
|
I = 0.0;
|
|
|
|
Q = 0.0;
|
2024-06-29 14:03:13 -04:00
|
|
|
break;
|
|
|
|
case 1: // sample-hold
|
2024-07-23 02:06:13 -04:00
|
|
|
deltaI = 0.0;
|
|
|
|
deltaQ = 0.0;
|
|
|
|
I = I1;
|
|
|
|
Q = Q1;
|
2024-06-29 14:03:13 -04:00
|
|
|
break;
|
|
|
|
case 2: // mean-hold
|
2024-07-23 02:06:13 -04:00
|
|
|
deltaI = 0.0;
|
|
|
|
deltaQ = 0.0;
|
|
|
|
I = 0.5 * (I1 + I2);
|
|
|
|
Q = 0.5 * (Q1 + Q2);
|
2024-06-29 14:03:13 -04:00
|
|
|
break;
|
|
|
|
case 3: // hold-sample
|
2024-07-23 02:06:13 -04:00
|
|
|
deltaI = 0.0;
|
|
|
|
deltaQ = 0.0;
|
|
|
|
I = I2;
|
|
|
|
Q = Q2;
|
2024-06-29 14:03:13 -04:00
|
|
|
break;
|
|
|
|
case 4: // linear interpolation
|
2024-07-23 02:06:13 -04:00
|
|
|
deltaI = (I2 - I1) / (adv_count + blank_count);
|
|
|
|
deltaQ = (Q2 - Q1) / (adv_count + blank_count);
|
|
|
|
I = I1;
|
|
|
|
Q = Q1;
|
2024-06-29 14:03:13 -04:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2024-07-23 02:06:13 -04:00
|
|
|
if (adv_slew_count > 0)
|
2024-07-17 15:19:57 -04:00
|
|
|
{
|
2024-07-23 02:06:13 -04:00
|
|
|
state = 5;
|
2024-07-17 15:19:57 -04:00
|
|
|
}
|
2024-06-29 14:03:13 -04:00
|
|
|
else
|
|
|
|
{
|
2024-07-23 02:06:13 -04:00
|
|
|
state = 6;
|
|
|
|
time = 0;
|
|
|
|
blank_count += adv_count + filterlen;
|
2024-06-29 14:03:13 -04:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2024-07-17 15:19:57 -04:00
|
|
|
|
2024-06-29 14:03:13 -04:00
|
|
|
break;
|
|
|
|
}
|
2024-07-17 15:19:57 -04:00
|
|
|
|
2024-06-29 14:03:13 -04:00
|
|
|
case 1: // slew output in advance of blanking period
|
|
|
|
{
|
2024-07-23 02:06:13 -04:00
|
|
|
scale = 0.5 + awave[time];
|
|
|
|
out[2 * i + 0] = Ilast * scale + (1.0 - scale) * I;
|
|
|
|
out[2 * i + 1] = Qlast * scale + (1.0 - scale) * Q;
|
2024-07-17 15:19:57 -04:00
|
|
|
|
2024-07-23 02:06:13 -04:00
|
|
|
if (++time == adv_slew_count)
|
2024-06-29 14:03:13 -04:00
|
|
|
{
|
2024-07-23 02:06:13 -04:00
|
|
|
time = 0;
|
2024-07-17 15:19:57 -04:00
|
|
|
|
2024-07-23 02:06:13 -04:00
|
|
|
if (adv_count > 0)
|
|
|
|
state = 2;
|
2024-06-29 14:03:13 -04:00
|
|
|
else
|
2024-07-23 02:06:13 -04:00
|
|
|
state = 3;
|
2024-06-29 14:03:13 -04:00
|
|
|
}
|
2024-07-17 15:19:57 -04:00
|
|
|
|
2024-06-29 14:03:13 -04:00
|
|
|
break;
|
|
|
|
}
|
2024-07-17 15:19:57 -04:00
|
|
|
|
2024-06-29 14:03:13 -04:00
|
|
|
case 2: // initial advance period
|
|
|
|
{
|
2024-07-23 02:06:13 -04:00
|
|
|
out[2 * i + 0] = I;
|
|
|
|
out[2 * i + 1] = Q;
|
|
|
|
I += deltaI;
|
|
|
|
Q += deltaQ;
|
2024-06-29 14:03:13 -04:00
|
|
|
|
2024-07-23 02:06:13 -04:00
|
|
|
if (++time == adv_count)
|
2024-06-29 14:03:13 -04:00
|
|
|
{
|
2024-07-23 02:06:13 -04:00
|
|
|
state = 3;
|
|
|
|
time = 0;
|
2024-06-29 14:03:13 -04:00
|
|
|
}
|
2024-07-17 15:19:57 -04:00
|
|
|
|
2024-06-29 14:03:13 -04:00
|
|
|
break;
|
|
|
|
}
|
2024-07-17 15:19:57 -04:00
|
|
|
|
2024-06-29 14:03:13 -04:00
|
|
|
case 3: // impulse & hang period
|
|
|
|
{
|
2024-07-23 02:06:13 -04:00
|
|
|
out[2 * i + 0] = I;
|
|
|
|
out[2 * i + 1] = Q;
|
|
|
|
I += deltaI;
|
|
|
|
Q += deltaQ;
|
2024-06-29 14:03:13 -04:00
|
|
|
|
2024-07-23 02:06:13 -04:00
|
|
|
if (++time == blank_count)
|
2024-06-29 14:03:13 -04:00
|
|
|
{
|
2024-07-23 02:06:13 -04:00
|
|
|
if (hang_slew_count > 0)
|
2024-06-29 14:03:13 -04:00
|
|
|
{
|
2024-07-23 02:06:13 -04:00
|
|
|
state = 4;
|
|
|
|
time = 0;
|
2024-06-29 14:03:13 -04:00
|
|
|
}
|
|
|
|
else
|
2024-07-17 15:19:57 -04:00
|
|
|
{
|
2024-07-23 02:06:13 -04:00
|
|
|
state = 0;
|
2024-07-17 15:19:57 -04:00
|
|
|
}
|
2024-06-29 14:03:13 -04:00
|
|
|
}
|
2024-07-17 15:19:57 -04:00
|
|
|
|
2024-06-29 14:03:13 -04:00
|
|
|
break;
|
|
|
|
}
|
2024-07-17 15:19:57 -04:00
|
|
|
|
2024-06-29 14:03:13 -04:00
|
|
|
case 4: // slew output after blanking period
|
|
|
|
{
|
2024-07-23 02:06:13 -04:00
|
|
|
scale = 0.5 - hwave[time];
|
|
|
|
out[2 * i + 0] = Inext * scale + (1.0 - scale) * I;
|
|
|
|
out[2 * i + 1] = Qnext * scale + (1.0 - scale) * Q;
|
2024-07-17 15:19:57 -04:00
|
|
|
|
2024-07-23 02:06:13 -04:00
|
|
|
if (++time == hang_slew_count)
|
|
|
|
state = 0;
|
2024-07-17 15:19:57 -04:00
|
|
|
|
2024-06-29 14:03:13 -04:00
|
|
|
break;
|
|
|
|
}
|
2024-07-17 15:19:57 -04:00
|
|
|
|
2024-06-29 14:03:13 -04:00
|
|
|
case 5:
|
|
|
|
{
|
2024-07-23 02:06:13 -04:00
|
|
|
scale = 0.5 + awave[time];
|
|
|
|
out[2 * i + 0] = Ilast * scale;
|
|
|
|
out[2 * i + 1] = Qlast * scale;
|
2024-07-17 15:19:57 -04:00
|
|
|
|
2024-07-23 02:06:13 -04:00
|
|
|
if (++time == adv_slew_count)
|
2024-06-29 14:03:13 -04:00
|
|
|
{
|
2024-07-23 02:06:13 -04:00
|
|
|
state = 6;
|
|
|
|
time = 0;
|
|
|
|
blank_count += adv_count + filterlen;
|
2024-06-29 14:03:13 -04:00
|
|
|
}
|
2024-07-17 15:19:57 -04:00
|
|
|
|
2024-06-29 14:03:13 -04:00
|
|
|
break;
|
|
|
|
}
|
2024-07-17 15:19:57 -04:00
|
|
|
|
2024-06-29 14:03:13 -04:00
|
|
|
case 6:
|
|
|
|
{
|
2024-07-23 02:06:13 -04:00
|
|
|
out[2 * i + 0] = 0.0;
|
|
|
|
out[2 * i + 1] = 0.0;
|
2024-07-17 15:19:57 -04:00
|
|
|
|
2024-07-23 02:06:13 -04:00
|
|
|
if (++time == blank_count)
|
|
|
|
state = 7;
|
2024-07-17 15:19:57 -04:00
|
|
|
|
2024-06-29 14:03:13 -04:00
|
|
|
break;
|
|
|
|
}
|
2024-07-17 15:19:57 -04:00
|
|
|
|
2024-06-29 14:03:13 -04:00
|
|
|
case 7:
|
|
|
|
{
|
2024-07-23 02:06:13 -04:00
|
|
|
out[2 * i + 0] = 0.0;
|
|
|
|
out[2 * i + 1] = 0.0;
|
2024-06-29 14:03:13 -04:00
|
|
|
staydown = 0;
|
2024-07-23 02:06:13 -04:00
|
|
|
time = 0;
|
2024-07-17 15:19:57 -04:00
|
|
|
|
2024-07-23 02:06:13 -04:00
|
|
|
if ((tidx = scan_idx + hang_slew_count + hang_count) >= dline_size)
|
|
|
|
tidx -= dline_size;
|
2024-07-17 15:19:57 -04:00
|
|
|
|
2024-07-23 02:06:13 -04:00
|
|
|
while (time++ <= adv_count + adv_slew_count + hang_slew_count + hang_count) // CHECK EXACT COUNTS!!!!!!!!!!!!!!!!!!!!!!!
|
2024-06-29 14:03:13 -04:00
|
|
|
{
|
2024-07-23 02:06:13 -04:00
|
|
|
if (imp[tidx] == 1) staydown = 1;
|
|
|
|
if (--tidx < 0) tidx += dline_size;
|
2024-06-29 14:03:13 -04:00
|
|
|
}
|
2024-07-17 15:19:57 -04:00
|
|
|
|
2024-06-29 14:03:13 -04:00
|
|
|
if (staydown == 0)
|
|
|
|
{
|
2024-07-23 02:06:13 -04:00
|
|
|
if (hang_count > 0)
|
2024-06-29 14:03:13 -04:00
|
|
|
{
|
2024-07-23 02:06:13 -04:00
|
|
|
state = 8;
|
|
|
|
time = 0;
|
2024-06-29 14:03:13 -04:00
|
|
|
}
|
2024-07-23 02:06:13 -04:00
|
|
|
else if (hang_slew_count > 0)
|
2024-06-29 14:03:13 -04:00
|
|
|
{
|
2024-07-23 02:06:13 -04:00
|
|
|
state = 9;
|
|
|
|
time = 0;
|
2024-07-17 15:19:57 -04:00
|
|
|
|
2024-07-23 02:06:13 -04:00
|
|
|
if ((tidx = scan_idx + hang_slew_count + hang_count - adv_count - adv_slew_count) >= dline_size)
|
|
|
|
tidx -= dline_size;
|
2024-07-17 15:19:57 -04:00
|
|
|
|
|
|
|
if (tidx < 0)
|
2024-07-23 02:06:13 -04:00
|
|
|
tidx += dline_size;
|
2024-07-17 15:19:57 -04:00
|
|
|
|
2024-07-23 02:06:13 -04:00
|
|
|
Inext = dline[2 * tidx + 0];
|
|
|
|
Qnext = dline[2 * tidx + 1];
|
2024-06-29 14:03:13 -04:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2024-07-23 02:06:13 -04:00
|
|
|
state = 0;
|
|
|
|
overflow = 0;
|
2024-06-29 14:03:13 -04:00
|
|
|
}
|
|
|
|
}
|
2024-07-17 15:19:57 -04:00
|
|
|
|
2024-06-29 14:03:13 -04:00
|
|
|
break;
|
|
|
|
}
|
2024-07-17 15:19:57 -04:00
|
|
|
|
2024-06-29 14:03:13 -04:00
|
|
|
case 8:
|
|
|
|
{
|
2024-07-23 02:06:13 -04:00
|
|
|
out[2 * i + 0] = 0.0;
|
|
|
|
out[2 * i + 1] = 0.0;
|
2024-07-17 15:19:57 -04:00
|
|
|
|
2024-07-23 02:06:13 -04:00
|
|
|
if (++time == hang_count)
|
2024-06-29 14:03:13 -04:00
|
|
|
{
|
2024-07-23 02:06:13 -04:00
|
|
|
if (hang_slew_count > 0)
|
2024-06-29 14:03:13 -04:00
|
|
|
{
|
2024-07-23 02:06:13 -04:00
|
|
|
state = 9;
|
|
|
|
time = 0;
|
2024-07-17 15:19:57 -04:00
|
|
|
|
2024-07-23 02:06:13 -04:00
|
|
|
if ((tidx = scan_idx + hang_slew_count - adv_count - adv_slew_count) >= dline_size)
|
|
|
|
tidx -= dline_size;
|
2024-07-17 15:19:57 -04:00
|
|
|
|
|
|
|
if (tidx < 0)
|
2024-07-23 02:06:13 -04:00
|
|
|
tidx += dline_size;
|
2024-07-17 15:19:57 -04:00
|
|
|
|
2024-07-23 02:06:13 -04:00
|
|
|
Inext = dline[2 * tidx + 0];
|
|
|
|
Qnext = dline[2 * tidx + 1];
|
2024-06-29 14:03:13 -04:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2024-07-23 02:06:13 -04:00
|
|
|
state = 0;
|
|
|
|
overflow = 0;
|
2024-06-29 14:03:13 -04:00
|
|
|
}
|
|
|
|
}
|
2024-07-17 15:19:57 -04:00
|
|
|
|
2024-06-29 14:03:13 -04:00
|
|
|
break;
|
|
|
|
}
|
2024-07-17 15:19:57 -04:00
|
|
|
|
2024-06-29 14:03:13 -04:00
|
|
|
case 9:
|
|
|
|
{
|
2024-07-23 02:06:13 -04:00
|
|
|
scale = 0.5 - hwave[time];
|
|
|
|
out[2 * i + 0] = Inext * scale;
|
|
|
|
out[2 * i + 1] = Qnext * scale;
|
2024-06-29 14:03:13 -04:00
|
|
|
|
2024-07-23 02:06:13 -04:00
|
|
|
if (++time >= hang_slew_count)
|
2024-06-29 14:03:13 -04:00
|
|
|
{
|
2024-07-23 02:06:13 -04:00
|
|
|
state = 0;
|
|
|
|
overflow = 0;
|
2024-06-29 14:03:13 -04:00
|
|
|
}
|
2024-07-17 15:19:57 -04:00
|
|
|
|
2024-06-29 14:03:13 -04:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
2024-07-17 15:19:57 -04:00
|
|
|
|
2024-07-23 02:06:13 -04:00
|
|
|
if (++in_idx == dline_size)
|
|
|
|
in_idx = 0;
|
2024-07-17 15:19:57 -04:00
|
|
|
|
2024-07-23 02:06:13 -04:00
|
|
|
if (++scan_idx == dline_size)
|
|
|
|
scan_idx = 0;
|
2024-07-17 15:19:57 -04:00
|
|
|
|
2024-07-23 02:06:13 -04:00
|
|
|
if (++out_idx == dline_size)
|
|
|
|
out_idx = 0;
|
2024-06-29 14:03:13 -04:00
|
|
|
}
|
|
|
|
}
|
2024-07-23 02:06:13 -04:00
|
|
|
else if (in != out)
|
2024-07-17 15:19:57 -04:00
|
|
|
{
|
2024-07-23 02:06:13 -04:00
|
|
|
std::copy(in, in + buffsize * 2, out);
|
2024-07-17 15:19:57 -04:00
|
|
|
}
|
2024-06-29 14:03:13 -04:00
|
|
|
}
|
|
|
|
|
2024-07-23 02:06:13 -04:00
|
|
|
void NOB::setBuffers(float* in, float* out)
|
2024-06-29 14:03:13 -04:00
|
|
|
{
|
2024-07-23 02:06:13 -04:00
|
|
|
in = in;
|
|
|
|
out = out;
|
2024-06-29 14:03:13 -04:00
|
|
|
}
|
|
|
|
|
2024-07-23 02:06:13 -04:00
|
|
|
void NOB::setSize(int size)
|
2024-06-29 14:03:13 -04:00
|
|
|
{
|
2024-07-23 02:06:13 -04:00
|
|
|
buffsize = size;
|
|
|
|
flush();
|
2024-06-29 14:03:13 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
/********************************************************************************************************
|
|
|
|
* *
|
2024-07-23 02:06:13 -04:00
|
|
|
* Common interface *
|
2024-06-29 14:03:13 -04:00
|
|
|
* *
|
|
|
|
********************************************************************************************************/
|
|
|
|
|
2024-07-23 02:06:13 -04:00
|
|
|
void NOB::setRun(int _run)
|
2024-06-29 14:03:13 -04:00
|
|
|
{
|
2024-07-23 02:06:13 -04:00
|
|
|
run = _run;
|
2024-06-29 14:03:13 -04:00
|
|
|
}
|
|
|
|
|
2024-07-23 02:06:13 -04:00
|
|
|
void NOB::setMode(int _mode)
|
2024-06-29 14:03:13 -04:00
|
|
|
{
|
2024-07-23 02:06:13 -04:00
|
|
|
mode = _mode;
|
2024-06-29 14:03:13 -04:00
|
|
|
}
|
|
|
|
|
2024-07-23 02:06:13 -04:00
|
|
|
void NOB::setBuffsize(int size)
|
2024-06-29 14:03:13 -04:00
|
|
|
{
|
2024-07-23 02:06:13 -04:00
|
|
|
buffsize = size;
|
2024-06-29 14:03:13 -04:00
|
|
|
}
|
|
|
|
|
2024-07-23 02:06:13 -04:00
|
|
|
void NOB::setSamplerate(int rate)
|
2024-06-29 14:03:13 -04:00
|
|
|
{
|
2024-07-23 02:06:13 -04:00
|
|
|
samplerate = (double) rate;
|
|
|
|
init_nob();
|
2024-06-29 14:03:13 -04:00
|
|
|
}
|
|
|
|
|
2024-07-23 02:06:13 -04:00
|
|
|
void NOB::setTau(double tau)
|
2024-06-29 14:03:13 -04:00
|
|
|
{
|
2024-07-23 02:06:13 -04:00
|
|
|
advslewtime = tau;
|
|
|
|
hangslewtime = tau;
|
|
|
|
init_nob();
|
2024-06-29 14:03:13 -04:00
|
|
|
}
|
|
|
|
|
2024-07-23 02:06:13 -04:00
|
|
|
void NOB::setHangtime(double time)
|
2024-06-29 14:03:13 -04:00
|
|
|
{
|
2024-07-23 02:06:13 -04:00
|
|
|
hangtime = time;
|
|
|
|
init_nob();
|
2024-06-29 14:03:13 -04:00
|
|
|
}
|
|
|
|
|
2024-07-23 02:06:13 -04:00
|
|
|
void NOB::setAdvtime(double time)
|
2024-06-29 14:03:13 -04:00
|
|
|
{
|
2024-07-23 02:06:13 -04:00
|
|
|
advtime = time;
|
|
|
|
init_nob();
|
2024-06-29 14:03:13 -04:00
|
|
|
}
|
|
|
|
|
2024-07-23 02:06:13 -04:00
|
|
|
void NOB::setBacktau(double tau)
|
2024-06-29 14:03:13 -04:00
|
|
|
{
|
2024-07-23 02:06:13 -04:00
|
|
|
backtau = tau;
|
|
|
|
init_nob();
|
2024-06-29 14:03:13 -04:00
|
|
|
}
|
|
|
|
|
2024-07-23 02:06:13 -04:00
|
|
|
void NOB::setThreshold(double thresh)
|
2024-06-29 14:03:13 -04:00
|
|
|
{
|
2024-07-23 02:06:13 -04:00
|
|
|
threshold = thresh;
|
2024-06-29 14:03:13 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
} // namespace
|