1
0
mirror of https://github.com/f4exb/sdrangel.git synced 2024-11-13 20:01:46 -05:00
sdrangel/wdsp/ammod.cpp

119 lines
3.0 KiB
C++
Raw Normal View History

2024-06-16 05:31:13 -04:00
/* ammod.h
This file is part of a program that implements a Software-Defined Radio.
Copyright (C) 2013, 2017 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 <cmath>
#include "ammod.hpp"
#include "comm.hpp"
#include "TXA.hpp"
namespace WDSP {
2024-08-05 14:05:59 -04:00
AMMOD::AMMOD(
int _run,
int _mode,
int _size,
float* _in,
float* _out,
double _c_level
)
2024-06-16 05:31:13 -04:00
{
2024-08-05 14:05:59 -04:00
run = _run;
mode = _mode;
size = _size;
in = _in;
out = _out;
c_level = _c_level;
a_level = 1.0 - c_level;
mult = 1.0 / sqrt (2.0);
2024-06-16 05:31:13 -04:00
}
2024-08-05 14:05:59 -04:00
void AMMOD::flush()
2024-06-16 05:31:13 -04:00
{
2024-08-05 14:05:59 -04:00
// Nothing to flush
2024-06-16 05:31:13 -04:00
}
2024-08-05 14:05:59 -04:00
void AMMOD::execute()
2024-06-16 05:31:13 -04:00
{
2024-08-05 14:05:59 -04:00
if (run)
2024-06-16 05:31:13 -04:00
{
int i;
2024-08-05 14:05:59 -04:00
switch (mode)
2024-06-16 05:31:13 -04:00
{
case 0: // AM
2024-08-05 14:05:59 -04:00
for (i = 0; i < size; i++)
out[2 * i + 0] = out[2 * i + 1] = (float) (mult * (c_level + a_level * in[2 * i + 0]));
2024-06-16 05:31:13 -04:00
break;
case 1: // DSB
2024-08-05 14:05:59 -04:00
for (i = 0; i < size; i++)
out[2 * i + 0] = out[2 * i + 1] = (float) (mult * in[2 * i + 0]);
2024-06-16 05:31:13 -04:00
break;
case 2: // SSB w/Carrier
2024-08-05 14:05:59 -04:00
for (i = 0; i < size; i++)
2024-06-16 05:31:13 -04:00
{
2024-08-05 14:05:59 -04:00
out[2 * i + 0] = (float) (mult * c_level + a_level * in[2 * i + 0]);
out[2 * i + 1] = (float) (mult * c_level + a_level * in[2 * i + 1]);
2024-06-16 05:31:13 -04:00
}
break;
2024-08-05 14:05:59 -04:00
default:
break;
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 AMMOD::setBuffers(float* _in, float* _out)
2024-06-16 05:31:13 -04:00
{
2024-08-05 14:05:59 -04:00
in = _in;
out = _out;
2024-06-16 05:31:13 -04:00
}
2024-08-05 14:05:59 -04:00
void AMMOD::setSamplerate(int)
2024-06-16 05:31:13 -04:00
{
2024-08-05 14:05:59 -04:00
// Nothing to do
2024-06-16 05:31:13 -04:00
}
2024-08-05 14:05:59 -04:00
void AMMOD::setSize(int _size)
2024-06-16 05:31:13 -04:00
{
2024-08-05 14:05:59 -04:00
size = _size;
2024-06-16 05:31:13 -04:00
}
/********************************************************************************************************
* *
* TXA Properties *
* *
********************************************************************************************************/
2024-08-05 14:05:59 -04:00
void AMMOD::setAMCarrierLevel(double _c_level)
2024-06-16 05:31:13 -04:00
{
2024-08-05 14:05:59 -04:00
c_level = _c_level;
a_level = 1.0 - _c_level;
2024-06-16 05:31:13 -04:00
}
} // namespace WDSP