1
0
mirror of https://github.com/f4exb/sdrangel.git synced 2024-11-11 02:46:12 -05:00
sdrangel/wdsp/cblock.cpp

130 lines
3.1 KiB
C++
Raw Normal View History

2024-06-16 05:31:13 -04:00
/* cblock.c
This file is part of a program that implements a Software-Defined Radio.
Copyright (C) 2013, 2016 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 "cblock.hpp"
#include "RXA.hpp"
namespace WDSP {
2024-07-30 17:29:37 -04:00
void CBL::calc()
2024-06-16 05:31:13 -04:00
{
2024-07-30 17:29:37 -04:00
prevIin = 0.0;
prevQin = 0.0;
prevIout = 0.0;
prevQout = 0.0;
mtau = exp(-1.0 / (sample_rate * tau));
2024-06-16 05:31:13 -04:00
}
2024-07-30 17:29:37 -04:00
CBL::CBL(
int _run,
int _buff_size,
float *_in_buff,
float *_out_buff,
int _mode,
int _sample_rate,
double _tau
)
2024-06-16 05:31:13 -04:00
{
2024-07-30 17:29:37 -04:00
run = _run;
buff_size = _buff_size;
in_buff = _in_buff;
out_buff = _out_buff;
mode = _mode;
sample_rate = (double) _sample_rate;
tau = _tau;
calc();
2024-06-16 05:31:13 -04:00
}
2024-07-30 17:29:37 -04:00
void CBL::flush()
2024-06-16 05:31:13 -04:00
{
2024-07-30 17:29:37 -04:00
prevIin = 0.0;
prevQin = 0.0;
prevIout = 0.0;
prevQout = 0.0;
2024-06-16 05:31:13 -04:00
}
2024-07-30 17:29:37 -04:00
void CBL::execute()
2024-06-16 05:31:13 -04:00
{
2024-07-30 17:29:37 -04:00
if (run)
2024-06-16 05:31:13 -04:00
{
int i;
double tempI, tempQ;
2024-07-30 17:29:37 -04:00
for (i = 0; i < buff_size; i++)
2024-06-16 05:31:13 -04:00
{
2024-07-30 17:29:37 -04:00
tempI = in_buff[2 * i + 0];
tempQ = in_buff[2 * i + 1];
out_buff[2 * i + 0] = in_buff[2 * i + 0] - prevIin + mtau * prevIout;
out_buff[2 * i + 1] = in_buff[2 * i + 1] - prevQin + mtau * prevQout;
prevIin = tempI;
prevQin = tempQ;
if (fabs(prevIout = out_buff[2 * i + 0]) < 1.0e-20)
prevIout = 0.0;
if (fabs(prevQout = out_buff[2 * i + 1]) < 1.0e-20)
prevQout = 0.0;
2024-06-16 05:31:13 -04:00
}
}
2024-07-30 17:29:37 -04:00
else if (in_buff != out_buff)
{
2024-07-30 17:29:37 -04:00
std::copy(in_buff, in_buff + buff_size * 2, out_buff);
}
2024-06-16 05:31:13 -04:00
}
2024-07-30 17:29:37 -04:00
void CBL::setBuffers(float* _in, float* _out)
2024-06-16 05:31:13 -04:00
{
2024-07-30 17:29:37 -04:00
in_buff = _in;
out_buff = _out;
2024-06-16 05:31:13 -04:00
}
2024-07-30 17:29:37 -04:00
void CBL::setSamplerate(int _rate)
2024-06-16 05:31:13 -04:00
{
2024-07-30 17:29:37 -04:00
sample_rate = _rate;
calc();
2024-06-16 05:31:13 -04:00
}
2024-07-30 17:29:37 -04:00
void CBL::setSize(int _size)
2024-06-16 05:31:13 -04:00
{
2024-07-30 17:29:37 -04:00
buff_size = _size;
flush();
2024-06-16 05:31:13 -04:00
}
/********************************************************************************************************
* *
* RXA Properties *
* *
********************************************************************************************************/
2024-07-30 17:29:37 -04:00
void CBL::setRun(int setit)
2024-06-16 05:31:13 -04:00
{
2024-07-30 17:29:37 -04:00
run = setit;
2024-06-16 05:31:13 -04:00
}
} // namespace WDSP