1
0
mirror of https://github.com/f4exb/sdrangel.git synced 2024-09-21 12:26:34 -04:00
sdrangel/wdsp/emph.cpp

160 lines
3.8 KiB
C++
Raw Normal View History

2024-06-16 05:31:13 -04:00
/* emph.c
This file is part of a program that implements a Software-Defined Radio.
Copyright (C) 2014, 2016, 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 "emph.hpp"
#include "fcurve.hpp"
#include "fircore.hpp"
2024-06-16 05:31:13 -04:00
#include "TXA.hpp"
namespace WDSP {
/********************************************************************************************************
* *
* Overlap-Save FM Pre-Emphasis *
* *
********************************************************************************************************/
2024-08-05 14:05:59 -04:00
void EMPH::calc()
2024-06-16 05:31:13 -04:00
{
2024-08-10 17:46:47 -04:00
infilt.resize(2 * size * 2);
product.resize(2 * size * 2);
FCurve::fc_mults(
mults,
2024-08-05 14:05:59 -04:00
size,
2024-08-10 17:46:47 -04:00
(float) f_low,
(float) f_high,
(float) (-20.0 * log10(f_high / f_low)),
2024-08-05 14:05:59 -04:00
0.0,
ctype,
2024-08-10 17:46:47 -04:00
(float) rate,
(float) (1.0 / (2.0 * size)),
2024-08-05 14:05:59 -04:00
0,
0
);
2024-08-10 17:46:47 -04:00
CFor = fftwf_plan_dft_1d(
2 * size,
(fftwf_complex *)infilt.data(),
(fftwf_complex *)product.data(),
FFTW_FORWARD,
FFTW_PATIENT)
;
CRev = fftwf_plan_dft_1d(
2 * size,
(fftwf_complex *)product.data(),
(fftwf_complex *)out,
FFTW_BACKWARD,
FFTW_PATIENT
);
2024-06-16 05:31:13 -04:00
}
2024-08-05 14:05:59 -04:00
void EMPH::decalc()
2024-06-16 05:31:13 -04:00
{
2024-08-05 14:05:59 -04:00
fftwf_destroy_plan(CRev);
fftwf_destroy_plan(CFor);
2024-06-16 05:31:13 -04:00
}
2024-08-05 14:05:59 -04:00
EMPH::EMPH(
int _run,
int _position,
int _size,
float* _in,
float* _out,
int _rate,
int _ctype,
double _f_low,
double _f_high
) :
run(_run),
position(_position),
size(_size),
in(_in),
out(_out),
ctype(_ctype),
f_low(_f_low),
f_high(_f_high),
rate((double) _rate)
2024-06-16 05:31:13 -04:00
{
2024-08-05 14:05:59 -04:00
calc();
2024-06-16 05:31:13 -04:00
}
2024-08-05 14:05:59 -04:00
EMPH::~EMPH()
2024-06-16 05:31:13 -04:00
{
2024-08-05 14:05:59 -04:00
decalc();
2024-06-16 05:31:13 -04:00
}
2024-08-05 14:05:59 -04:00
void EMPH::flush()
2024-06-16 05:31:13 -04:00
{
2024-08-10 17:46:47 -04:00
std::fill(infilt.begin(), infilt.end(), 0);
2024-06-16 05:31:13 -04:00
}
2024-08-05 14:05:59 -04:00
void EMPH::execute(int _position)
2024-06-16 05:31:13 -04:00
{
2024-08-05 14:05:59 -04:00
double I;
double Q;
if (run && position == _position)
2024-06-16 05:31:13 -04:00
{
2024-08-05 14:05:59 -04:00
std::copy(in, in + size * 2, &(infilt[2 * size]));
fftwf_execute (CFor);
for (int i = 0; i < 2 * size; i++)
2024-06-16 05:31:13 -04:00
{
2024-08-05 14:05:59 -04:00
I = product[2 * i + 0];
Q = product[2 * i + 1];
product[2 * i + 0] = (float) (I * mults[2 * i + 0] - Q * mults[2 * i + 1]);
product[2 * i + 1] = (float) (I * mults[2 * i + 1] + Q * mults[2 * i + 0]);
2024-06-16 05:31:13 -04:00
}
2024-08-05 14:05:59 -04:00
fftwf_execute (CRev);
2024-08-10 17:46:47 -04:00
std::copy(&(infilt[2 * size]), &(infilt[2 * size]) + size * 2, infilt.begin());
2024-06-16 05:31:13 -04:00
}
2024-08-05 14:05:59 -04:00
else if (in != out)
std::copy( in, in + size * 2, out);
2024-06-16 05:31:13 -04:00
}
2024-08-05 14:05:59 -04:00
void EMPH::setBuffers(float* _in, float* _out)
2024-06-16 05:31:13 -04:00
{
2024-08-05 14:05:59 -04:00
decalc();
in = _in;
out = _out;
calc();
2024-06-16 05:31:13 -04:00
}
2024-08-05 14:05:59 -04:00
void EMPH::setSamplerate(int _rate)
2024-06-16 05:31:13 -04:00
{
2024-08-05 14:05:59 -04:00
decalc();
rate = _rate;
calc();
2024-06-16 05:31:13 -04:00
}
2024-08-05 14:05:59 -04:00
void EMPH::setSize(int _size)
2024-06-16 05:31:13 -04:00
{
2024-08-05 14:05:59 -04:00
decalc();
size = _size;
calc();
2024-06-16 05:31:13 -04:00
}
} // namespace WDSP