2024-06-16 05:31:13 -04:00
|
|
|
/* patchpanel.c
|
|
|
|
|
|
|
|
This file is part of a program that implements a Software-Defined Radio.
|
|
|
|
|
|
|
|
Copyright (C) 2013 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 "patchpanel.hpp"
|
|
|
|
|
|
|
|
namespace WDSP {
|
|
|
|
|
2024-07-31 20:01:09 -04:00
|
|
|
PANEL::PANEL(
|
|
|
|
int _run,
|
|
|
|
int _size,
|
|
|
|
float* _in,
|
|
|
|
float* _out,
|
|
|
|
double _gain1,
|
|
|
|
double _gain2I,
|
|
|
|
double _gain2Q,
|
|
|
|
int _inselect,
|
|
|
|
int _copy
|
|
|
|
) :
|
|
|
|
run(_run),
|
|
|
|
size(_size),
|
|
|
|
in(_in),
|
|
|
|
out(_out),
|
|
|
|
gain1(_gain1),
|
|
|
|
gain2I(_gain2I),
|
|
|
|
gain2Q(_gain2Q),
|
|
|
|
inselect(_inselect),
|
|
|
|
copy(_copy)
|
2024-06-16 05:31:13 -04:00
|
|
|
{
|
|
|
|
}
|
|
|
|
|
2024-07-31 20:01:09 -04:00
|
|
|
void PANEL::flush()
|
2024-06-16 05:31:13 -04:00
|
|
|
{
|
2024-08-03 05:05:12 -04:00
|
|
|
// There is no data to be reset internally
|
2024-06-16 05:31:13 -04:00
|
|
|
}
|
|
|
|
|
2024-07-31 20:01:09 -04:00
|
|
|
void PANEL::execute()
|
2024-06-16 05:31:13 -04:00
|
|
|
{
|
|
|
|
int i;
|
2024-08-03 05:05:12 -04:00
|
|
|
double I;
|
|
|
|
double Q;
|
2024-07-31 20:01:09 -04:00
|
|
|
double gainI = gain1 * gain2I;
|
|
|
|
double gainQ = gain1 * gain2Q;
|
2024-06-16 05:31:13 -04:00
|
|
|
// inselect is either 0(neither), 1(Q), 2(I), or 3(both)
|
2024-07-31 20:01:09 -04:00
|
|
|
switch (copy)
|
2024-06-16 05:31:13 -04:00
|
|
|
{
|
2024-08-03 05:05:12 -04:00
|
|
|
default: // 0 (default) no copy
|
2024-07-31 20:01:09 -04:00
|
|
|
for (i = 0; i < size; i++)
|
2024-06-16 05:31:13 -04:00
|
|
|
{
|
2024-07-31 20:01:09 -04:00
|
|
|
I = in[2 * i + 0] * (inselect >> 1);
|
|
|
|
Q = in[2 * i + 1] * (inselect & 1);
|
2024-08-03 05:05:12 -04:00
|
|
|
out[2 * i + 0] = (float) (gainI * I);
|
|
|
|
out[2 * i + 1] = (float) (gainQ * Q);
|
2024-06-16 05:31:13 -04:00
|
|
|
}
|
|
|
|
break;
|
|
|
|
case 1: // copy I to Q (then Q == I)
|
2024-07-31 20:01:09 -04:00
|
|
|
for (i = 0; i < size; i++)
|
2024-06-16 05:31:13 -04:00
|
|
|
{
|
2024-07-31 20:01:09 -04:00
|
|
|
I = in[2 * i + 0] * (inselect >> 1);
|
2024-06-16 05:31:13 -04:00
|
|
|
Q = I;
|
2024-08-03 05:05:12 -04:00
|
|
|
out[2 * i + 0] = (float) (gainI * I);
|
|
|
|
out[2 * i + 1] = (float) (gainQ * Q);
|
2024-06-16 05:31:13 -04:00
|
|
|
}
|
|
|
|
break;
|
|
|
|
case 2: // copy Q to I (then I == Q)
|
2024-07-31 20:01:09 -04:00
|
|
|
for (i = 0; i < size; i++)
|
2024-06-16 05:31:13 -04:00
|
|
|
{
|
2024-08-03 05:05:12 -04:00
|
|
|
Q = in[2 * i + 1] * (inselect & 1);
|
2024-06-16 05:31:13 -04:00
|
|
|
I = Q;
|
2024-08-03 05:05:12 -04:00
|
|
|
out[2 * i + 0] = (float) (gainI * I);
|
|
|
|
out[2 * i + 1] = (float) (gainQ * Q);
|
2024-06-16 05:31:13 -04:00
|
|
|
}
|
|
|
|
break;
|
|
|
|
case 3: // reverse (I=>Q and Q=>I)
|
2024-07-31 20:01:09 -04:00
|
|
|
for (i = 0; i < size; i++)
|
2024-06-16 05:31:13 -04:00
|
|
|
{
|
2024-07-31 20:01:09 -04:00
|
|
|
Q = in[2 * i + 0] * (inselect >> 1);
|
|
|
|
I = in[2 * i + 1] * (inselect & 1);
|
2024-08-03 05:05:12 -04:00
|
|
|
out[2 * i + 0] = (float) (gainI * I);
|
|
|
|
out[2 * i + 1] = (float) (gainQ * Q);
|
2024-06-16 05:31:13 -04:00
|
|
|
}
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2024-07-31 20:01:09 -04:00
|
|
|
void PANEL::setBuffers(float* _in, float* _out)
|
2024-06-16 05:31:13 -04:00
|
|
|
{
|
2024-07-31 20:01:09 -04:00
|
|
|
in = _in;
|
|
|
|
out = _out;
|
2024-06-16 05:31:13 -04:00
|
|
|
}
|
|
|
|
|
2024-07-31 20:01:09 -04:00
|
|
|
void PANEL::setSamplerate(int)
|
2024-06-16 05:31:13 -04:00
|
|
|
{
|
2024-08-03 05:05:12 -04:00
|
|
|
// There is no sample rate to be set for this component
|
2024-06-16 05:31:13 -04:00
|
|
|
}
|
|
|
|
|
2024-07-31 20:01:09 -04:00
|
|
|
void PANEL::setSize(int _size)
|
2024-06-16 05:31:13 -04:00
|
|
|
{
|
2024-07-31 20:01:09 -04:00
|
|
|
size = _size;
|
2024-06-16 05:31:13 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
/********************************************************************************************************
|
|
|
|
* *
|
|
|
|
* RXA Properties *
|
|
|
|
* *
|
|
|
|
********************************************************************************************************/
|
|
|
|
|
2024-07-31 20:01:09 -04:00
|
|
|
void PANEL::setRun(int _run)
|
2024-06-16 05:31:13 -04:00
|
|
|
{
|
2024-07-31 20:01:09 -04:00
|
|
|
run = _run;
|
2024-06-16 05:31:13 -04:00
|
|
|
}
|
|
|
|
|
2024-07-31 20:01:09 -04:00
|
|
|
void PANEL::setSelect(int _select)
|
2024-06-16 05:31:13 -04:00
|
|
|
{
|
2024-07-31 20:01:09 -04:00
|
|
|
inselect = _select;
|
2024-06-16 05:31:13 -04:00
|
|
|
}
|
|
|
|
|
2024-07-31 20:01:09 -04:00
|
|
|
void PANEL::setGain1(double _gain)
|
2024-06-16 05:31:13 -04:00
|
|
|
{
|
2024-07-31 20:01:09 -04:00
|
|
|
gain1 = _gain;
|
2024-06-16 05:31:13 -04:00
|
|
|
}
|
|
|
|
|
2024-07-31 20:01:09 -04:00
|
|
|
void PANEL::setGain2(double _gainI, double _gainQ)
|
2024-06-16 05:31:13 -04:00
|
|
|
{
|
2024-07-31 20:01:09 -04:00
|
|
|
gain2I = _gainI;
|
|
|
|
gain2Q = _gainQ;
|
2024-06-16 05:31:13 -04:00
|
|
|
}
|
|
|
|
|
2024-07-31 20:01:09 -04:00
|
|
|
void PANEL::setPan(double _pan)
|
2024-06-16 05:31:13 -04:00
|
|
|
{
|
2024-08-03 05:05:12 -04:00
|
|
|
double _gain1;
|
|
|
|
double _gain2;
|
2024-07-13 17:59:46 -04:00
|
|
|
|
2024-07-31 20:01:09 -04:00
|
|
|
if (_pan <= 0.5)
|
2024-06-16 05:31:13 -04:00
|
|
|
{
|
2024-08-03 05:05:12 -04:00
|
|
|
_gain1 = 1.0;
|
|
|
|
_gain2 = sin (_pan * PI);
|
2024-06-16 05:31:13 -04:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2024-08-03 05:05:12 -04:00
|
|
|
_gain1 = sin (_pan * PI);
|
|
|
|
_gain2 = 1.0;
|
2024-06-16 05:31:13 -04:00
|
|
|
}
|
2024-07-13 17:59:46 -04:00
|
|
|
|
2024-08-03 05:05:12 -04:00
|
|
|
gain2I = _gain1;
|
|
|
|
gain2Q = _gain2;
|
2024-06-16 05:31:13 -04:00
|
|
|
}
|
|
|
|
|
2024-07-31 20:01:09 -04:00
|
|
|
void PANEL::setCopy(int _copy)
|
2024-06-16 05:31:13 -04:00
|
|
|
{
|
2024-07-31 20:01:09 -04:00
|
|
|
copy = _copy;
|
2024-06-16 05:31:13 -04:00
|
|
|
}
|
|
|
|
|
2024-07-31 20:01:09 -04:00
|
|
|
void PANEL::setBinaural(int _bin)
|
2024-06-16 05:31:13 -04:00
|
|
|
{
|
2024-07-31 20:01:09 -04:00
|
|
|
copy = 1 - _bin;
|
2024-06-16 05:31:13 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
/********************************************************************************************************
|
|
|
|
* *
|
|
|
|
* TXA Properties *
|
|
|
|
* *
|
|
|
|
********************************************************************************************************/
|
|
|
|
|
2024-07-31 20:01:09 -04:00
|
|
|
void PANEL::setSelectTx(int _select)
|
2024-06-16 05:31:13 -04:00
|
|
|
{
|
2024-07-31 20:01:09 -04:00
|
|
|
if (_select == 1)
|
|
|
|
copy = 3;
|
2024-06-16 05:31:13 -04:00
|
|
|
else
|
2024-07-31 20:01:09 -04:00
|
|
|
copy = 0;
|
2024-07-13 17:59:46 -04:00
|
|
|
|
2024-07-31 20:01:09 -04:00
|
|
|
inselect = _select;
|
2024-06-16 05:31:13 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
} // namespace WDSP
|