1
0
mirror of https://github.com/f4exb/sdrangel.git synced 2024-11-25 01:18:38 -05:00
sdrangel/wdsp/mpeak.cpp

200 lines
4.5 KiB
C++
Raw Permalink Normal View History

2024-07-30 19:37:17 -04:00
/* mpeak.c
This file is part of a program that implements a Software-Defined Radio.
Copyright (C) 2014, 2022, 2023 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 "mpeak.hpp"
#include "speak.hpp"
namespace WDSP {
/********************************************************************************************************
* *
* Complex Multiple Peaking *
* *
********************************************************************************************************/
2024-07-31 18:31:28 -04:00
void MPEAK::calc()
2024-07-30 19:37:17 -04:00
{
2024-08-03 05:05:12 -04:00
tmp.resize(size * 2);
mix.resize(size * 2);
2024-07-31 18:31:28 -04:00
for (int i = 0; i < npeaks; i++)
2024-07-30 19:37:17 -04:00
{
2024-07-31 18:31:28 -04:00
pfil[i] = new SPEAK(
2024-07-30 19:37:17 -04:00
1,
2024-07-31 18:31:28 -04:00
size,
in,
tmp.data(),
rate,
f[i],
bw[i],
gain[i],
nstages,
2024-07-30 19:37:17 -04:00
1
);
}
}
2024-07-31 18:31:28 -04:00
void MPEAK::decalc()
2024-07-30 19:37:17 -04:00
{
2024-07-31 18:31:28 -04:00
for (int i = 0; i < npeaks; i++)
delete (pfil[i]);
2024-07-30 19:37:17 -04:00
}
2024-07-31 18:31:28 -04:00
MPEAK::MPEAK(
int _run,
int _size,
float* _in,
float* _out,
int _rate,
int _npeaks,
int* _enable,
double* _f,
double* _bw,
double* _gain,
int _nstages
2024-07-30 19:37:17 -04:00
)
{
2024-07-31 18:31:28 -04:00
run = _run;
size = _size;
in = _in;
out = _out;
rate = _rate;
npeaks = _npeaks;
nstages = _nstages;
2024-08-03 05:05:12 -04:00
enable.resize(npeaks);
f.resize(npeaks);
bw.resize(npeaks);
gain.resize(npeaks);
2024-07-31 18:31:28 -04:00
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());
2024-08-03 05:05:12 -04:00
pfil.resize(npeaks);
2024-07-31 18:31:28 -04:00
calc();
2024-07-30 19:37:17 -04:00
}
2024-07-31 18:31:28 -04:00
MPEAK::~MPEAK()
2024-07-30 19:37:17 -04:00
{
2024-07-31 18:31:28 -04:00
decalc();
2024-07-30 19:37:17 -04:00
}
2024-07-31 18:31:28 -04:00
void MPEAK::flush()
2024-07-30 19:37:17 -04:00
{
2024-07-31 18:31:28 -04:00
for (int i = 0; i < npeaks; i++)
pfil[i]->flush();
2024-07-30 19:37:17 -04:00
}
2024-07-31 18:31:28 -04:00
void MPEAK::execute()
2024-07-30 19:37:17 -04:00
{
2024-07-31 18:31:28 -04:00
if (run)
2024-07-30 19:37:17 -04:00
{
2024-07-31 18:31:28 -04:00
std::fill(mix.begin(), mix.end(), 0);
2024-07-30 19:37:17 -04:00
2024-07-31 18:31:28 -04:00
for (int i = 0; i < npeaks; i++)
2024-07-30 19:37:17 -04:00
{
2024-07-31 18:31:28 -04:00
if (enable[i])
2024-07-30 19:37:17 -04:00
{
2024-07-31 18:31:28 -04:00
pfil[i]->execute();
for (int j = 0; j < 2 * size; j++)
mix[j] += tmp[j];
2024-07-30 19:37:17 -04:00
}
}
2024-07-31 18:31:28 -04:00
std::copy(mix.begin(), mix.end(), out);
2024-07-30 19:37:17 -04:00
}
2024-07-31 18:31:28 -04:00
else if (in != out)
2024-07-30 19:37:17 -04:00
{
2024-07-31 18:31:28 -04:00
std::copy( in, in + size * 2, out);
2024-07-30 19:37:17 -04:00
}
}
2024-07-31 18:31:28 -04:00
void MPEAK::setBuffers(float* _in, float* _out)
2024-07-30 19:37:17 -04:00
{
2024-07-31 18:31:28 -04:00
decalc();
in = _in;
out = _out;
calc();
2024-07-30 19:37:17 -04:00
}
2024-07-31 18:31:28 -04:00
void MPEAK::setSamplerate(int _rate)
2024-07-30 19:37:17 -04:00
{
2024-07-31 18:31:28 -04:00
decalc();
rate = _rate;
calc();
2024-07-30 19:37:17 -04:00
}
2024-07-31 18:31:28 -04:00
void MPEAK::setSize(int _size)
2024-07-30 19:37:17 -04:00
{
2024-07-31 18:31:28 -04:00
decalc();
size = _size;
calc();
2024-07-30 19:37:17 -04:00
}
/********************************************************************************************************
* *
* RXA Properties *
* *
********************************************************************************************************/
2024-07-31 18:31:28 -04:00
void MPEAK::setRun(int _run)
2024-07-30 19:37:17 -04:00
{
2024-07-31 18:31:28 -04:00
run = _run;
2024-07-30 19:37:17 -04:00
}
2024-07-31 18:31:28 -04:00
void MPEAK::setNpeaks(int _npeaks)
2024-07-30 19:37:17 -04:00
{
2024-07-31 18:31:28 -04:00
npeaks = _npeaks;
2024-07-30 19:37:17 -04:00
}
2024-07-31 18:31:28 -04:00
void MPEAK::setFilEnable(int _fil, int _enable)
2024-07-30 19:37:17 -04:00
{
2024-07-31 18:31:28 -04:00
enable[_fil] = _enable;
2024-07-30 19:37:17 -04:00
}
2024-07-31 18:31:28 -04:00
void MPEAK::setFilFreq(int _fil, double _freq)
2024-07-30 19:37:17 -04:00
{
2024-07-31 18:31:28 -04:00
f[_fil] = _freq;
pfil[_fil]->f = _freq;
pfil[_fil]->calc();
2024-07-30 19:37:17 -04:00
}
2024-07-31 18:31:28 -04:00
void MPEAK::setFilBw(int _fil, double _bw)
2024-07-30 19:37:17 -04:00
{
2024-07-31 18:31:28 -04:00
bw[_fil] = _bw;
pfil[_fil]->bw = _bw;
pfil[_fil]->calc();
2024-07-30 19:37:17 -04:00
}
2024-07-31 18:31:28 -04:00
void MPEAK::setFilGain(int _fil, double _gain)
2024-07-30 19:37:17 -04:00
{
2024-07-31 18:31:28 -04:00
gain[_fil] = _gain;
pfil[_fil]->gain = _gain;
pfil[_fil]->calc();
2024-07-30 19:37:17 -04:00
}
} // namespace WDSP