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

146 lines
3.6 KiB
C++
Raw Normal View History

2024-06-16 05:31:13 -04:00
/* delay.c
This file is part of a program that implements a Software-Defined Radio.
Copyright (C) 2013, 2019 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"
#include "delay.hpp"
#include "fir.hpp"
namespace WDSP {
DELAY::DELAY(
int _run,
int _size,
float* _in,
float* _out,
int _rate,
float _tdelta,
float _tdelay
)
2024-06-16 05:31:13 -04:00
{
run = _run;
size = _size;
in = _in;
out = _out;
rate = _rate;
tdelta = _tdelta;
tdelay = _tdelay;
L = (int)(0.5 + 1.0 / (tdelta * (float)rate));
adelta = 1.0f / (float) (rate * L);
ft = 0.45f / (float)L;
ncoef = (int)(60.0 / ft);
ncoef = (ncoef / L + 1) * L;
cpp = ncoef / L;
phnum = (int)(0.5 + tdelay / adelta);
snum = phnum / L;
phnum %= L;
idx_in = 0;
adelay = adelta * (float) (snum * L + phnum);
FIR::fir_bandpass (h, ncoef,-ft, +ft, 1.0, 1, 0, (float)L);
rsize = cpp + (WSDEL - 1);
ring.resize(rsize * 2);
2024-06-16 05:31:13 -04:00
}
void DELAY::flush()
2024-06-16 05:31:13 -04:00
{
std::fill(ring.begin(), ring.end(), 0);
idx_in = 0;
2024-06-16 05:31:13 -04:00
}
void DELAY::execute()
2024-06-16 05:31:13 -04:00
{
if (run)
2024-06-16 05:31:13 -04:00
{
int j;
int k;
int idx;
int n;
float Itmp;
float Qtmp;
for (int i = 0; i < size; i++)
2024-06-16 05:31:13 -04:00
{
ring[2 * idx_in + 0] = in[2 * i + 0];
ring[2 * idx_in + 1] = in[2 * i + 1];
2024-06-16 05:31:13 -04:00
Itmp = 0.0;
Qtmp = 0.0;
2024-07-13 17:59:46 -04:00
if ((n = idx_in + snum) >= rsize)
n -= rsize;
2024-07-13 17:59:46 -04:00
for (j = 0, k = L - 1 - phnum; j < cpp; j++, k+= L)
2024-06-16 05:31:13 -04:00
{
if ((idx = n + j) >= rsize)
idx -= rsize;
2024-07-13 17:59:46 -04:00
Itmp += ring[2 * idx + 0] * h[k];
Qtmp += ring[2 * idx + 1] * h[k];
2024-06-16 05:31:13 -04:00
}
2024-07-13 17:59:46 -04:00
out[2 * i + 0] = Itmp;
out[2 * i + 1] = Qtmp;
2024-07-13 17:59:46 -04:00
if (--idx_in < 0)
idx_in = rsize - 1;
2024-06-16 05:31:13 -04:00
}
}
else if (out != in)
std::copy( in, in + size * 2, out);
2024-06-16 05:31:13 -04:00
}
/********************************************************************************************************
* *
* Properties *
* *
********************************************************************************************************/
void DELAY::setRun(int _run)
2024-06-16 05:31:13 -04:00
{
run = _run;
2024-06-16 05:31:13 -04:00
}
float DELAY::setValue(float _tdelay)
2024-06-16 05:31:13 -04:00
{
float _adelay;
tdelay = _tdelay;
phnum = (int)(0.5 + tdelay / adelta);
snum = phnum / L;
phnum %= L;
_adelay = adelta * (float) (snum * L + phnum);
adelay = _adelay;
2024-06-16 05:31:13 -04:00
return adelay;
}
void DELAY::setBuffs(int _size, float* _in, float* _out)
2024-06-16 05:31:13 -04:00
{
size = _size;
in = _in;
out = _out;
2024-06-16 05:31:13 -04:00
}
} // namespace WDSP