1
0
mirror of https://github.com/f4exb/sdrangel.git synced 2024-11-22 08:04:49 -05:00
sdrangel/wdsp/patchpanel.cpp

218 lines
5.4 KiB
C++
Raw Normal View History

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"
#include "RXA.hpp"
#include "TXA.hpp"
namespace WDSP {
PANEL* PANEL::create_panel (
int run,
int size,
float* in,
float* out,
double gain1,
double gain2I,
double gain2Q,
int inselect,
int copy
)
2024-06-16 05:31:13 -04:00
{
PANEL* a = new PANEL;
a->run = run;
a->size = size;
a->in = in;
a->out = out;
a->gain1 = gain1;
a->gain2I = gain2I;
a->gain2Q = gain2Q;
a->inselect = inselect;
a->copy = copy;
return a;
}
void PANEL::destroy_panel (PANEL *a)
{
delete (a);
}
void PANEL::flush_panel (PANEL *)
{
}
void PANEL::xpanel (PANEL *a)
{
int i;
double I, Q;
double gainI = a->gain1 * a->gain2I;
double gainQ = a->gain1 * a->gain2Q;
2024-06-16 05:31:13 -04:00
// inselect is either 0(neither), 1(Q), 2(I), or 3(both)
switch (a->copy)
{
case 0: // no copy
for (i = 0; i < a->size; i++)
{
I = a->in[2 * i + 0] * (a->inselect >> 1);
Q = a->in[2 * i + 1] * (a->inselect & 1);
a->out[2 * i + 0] = gainI * I;
a->out[2 * i + 1] = gainQ * Q;
}
break;
case 1: // copy I to Q (then Q == I)
for (i = 0; i < a->size; i++)
{
I = a->in[2 * i + 0] * (a->inselect >> 1);
Q = I;
a->out[2 * i + 0] = gainI * I;
a->out[2 * i + 1] = gainQ * Q;
}
break;
case 2: // copy Q to I (then I == Q)
for (i = 0; i < a->size; i++)
{
Q = a->in[2 * i + 1] * (a->inselect & 1);
I = Q;
a->out[2 * i + 0] = gainI * I;
a->out[2 * i + 1] = gainQ * Q;
}
break;
case 3: // reverse (I=>Q and Q=>I)
for (i = 0; i < a->size; i++)
{
Q = a->in[2 * i + 0] * (a->inselect >> 1);
I = a->in[2 * i + 1] * (a->inselect & 1);
a->out[2 * i + 0] = gainI * I;
a->out[2 * i + 1] = gainQ * Q;
}
break;
}
}
2024-06-24 21:50:48 -04:00
void PANEL::setBuffers_panel (PANEL *a, float* in, float* out)
2024-06-16 05:31:13 -04:00
{
a->in = in;
a->out = out;
}
void PANEL::setSamplerate_panel (PANEL *, int)
{
}
void PANEL::setSize_panel (PANEL *a, int size)
{
a->size = size;
}
/********************************************************************************************************
* *
* RXA Properties *
* *
********************************************************************************************************/
void PANEL::SetPanelRun (RXA& rxa, int run)
{
2024-07-22 18:39:21 -04:00
rxa.panel->run = run;
2024-06-16 05:31:13 -04:00
}
void PANEL::SetPanelSelect (RXA& rxa, int select)
{
2024-07-22 18:39:21 -04:00
rxa.panel->inselect = select;
2024-06-16 05:31:13 -04:00
}
void PANEL::SetPanelGain1 (RXA& rxa, double gain)
2024-06-16 05:31:13 -04:00
{
2024-07-22 18:39:21 -04:00
rxa.panel->gain1 = gain;
2024-06-16 05:31:13 -04:00
}
void PANEL::SetPanelGain2 (RXA& rxa, double gainI, double gainQ)
2024-06-16 05:31:13 -04:00
{
2024-07-22 18:39:21 -04:00
rxa.panel->gain2I = gainI;
rxa.panel->gain2Q = gainQ;
2024-06-16 05:31:13 -04:00
}
void PANEL::SetPanelPan (RXA& rxa, double pan)
2024-06-16 05:31:13 -04:00
{
double gain1, gain2;
2024-07-13 17:59:46 -04:00
2024-06-16 05:31:13 -04:00
if (pan <= 0.5)
{
gain1 = 1.0;
gain2 = sin (pan * PI);
}
else
{
gain1 = sin (pan * PI);
gain2 = 1.0;
}
2024-07-13 17:59:46 -04:00
2024-07-22 18:39:21 -04:00
rxa.panel->gain2I = gain1;
rxa.panel->gain2Q = gain2;
2024-06-16 05:31:13 -04:00
}
void PANEL::SetPanelCopy (RXA& rxa, int copy)
{
2024-07-22 18:39:21 -04:00
rxa.panel->copy = copy;
2024-06-16 05:31:13 -04:00
}
void PANEL::SetPanelBinaural (RXA& rxa, int bin)
{
2024-07-22 18:39:21 -04:00
rxa.panel->copy = 1 - bin;
2024-06-16 05:31:13 -04:00
}
/********************************************************************************************************
* *
* TXA Properties *
* *
********************************************************************************************************/
void PANEL::SetPanelRun (TXA& txa, int run)
{
txa.panel.p->run = run;
}
void PANEL::SetPanelGain1 (TXA& txa, double gain)
2024-06-16 05:31:13 -04:00
{
txa.panel.p->gain1 = gain;
//print_message ("micgainset.txt", "Set MIC Gain to", (int)(100.0 * gain), 0, 0);
}
void PANEL::SetPanelSelect (TXA& txa, int select)
{
if (select == 1)
txa.panel.p->copy = 3;
else
txa.panel.p->copy = 0;
2024-07-13 17:59:46 -04:00
2024-06-16 05:31:13 -04:00
txa.panel.p->inselect = select;
}
} // namespace WDSP