forked from g0orx/wdsp
-
Notifications
You must be signed in to change notification settings - Fork 0
/
patchpanel.c
227 lines (197 loc) · 5.41 KB
/
patchpanel.c
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
/* patchpanel.c
This file is part of a program that implements a Software-Defined Radio.
Copyright (C) 2013 Warren Pratt, NR0V
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
*/
#include "comm.h"
PANEL create_panel (int channel, int run, int size, double* in, double* out, double gain1, double gain2I, double gain2Q, int inselect, int copy)
{
PANEL a = (PANEL) malloc0 (sizeof (panel));
a->channel = channel;
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 destroy_panel (PANEL a)
{
_aligned_free (a);
}
void flush_panel (PANEL a)
{
}
void xpanel (PANEL a)
{
int i;
double I, Q;
double gainI = a->gain1 * a->gain2I;
double gainQ = a->gain1 * a->gain2Q;
// 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;
}
}
void setBuffers_panel (PANEL a, double* in, double* out)
{
a->in = in;
a->out = out;
}
void setSamplerate_panel (PANEL a, int rate)
{
}
void setSize_panel (PANEL a, int size)
{
a->size = size;
}
/********************************************************************************************************
* *
* RXA Properties *
* *
********************************************************************************************************/
PORT
void SetRXAPanelRun (int channel, int run)
{
EnterCriticalSection (&ch[channel].csDSP);
rxa[channel].panel.p->run = run;
LeaveCriticalSection (&ch[channel].csDSP);
}
PORT
void SetRXAPanelSelect (int channel, int select)
{
EnterCriticalSection (&ch[channel].csDSP);
rxa[channel].panel.p->inselect = select;
LeaveCriticalSection (&ch[channel].csDSP);
}
PORT
void SetRXAPanelGain1 (int channel, double gain)
{
EnterCriticalSection (&ch[channel].csDSP);
rxa[channel].panel.p->gain1 = gain;
LeaveCriticalSection (&ch[channel].csDSP);
}
PORT
void SetRXAPanelGain2 (int channel, double gainI, double gainQ)
{
EnterCriticalSection (&ch[channel].csDSP);
rxa[channel].panel.p->gain2I = gainI;
rxa[channel].panel.p->gain2Q = gainQ;
LeaveCriticalSection (&ch[channel].csDSP);
}
PORT
void SetRXAPanelPan (int channel, double pan)
{
double gain1, gain2;
EnterCriticalSection (&ch[channel].csDSP);
if (pan <= 0.5)
{
gain1 = 1.0;
gain2 = sin (pan * PI);
}
else
{
gain1 = sin (pan * PI);
gain2 = 1.0;
}
rxa[channel].panel.p->gain2I = gain1;
rxa[channel].panel.p->gain2Q = gain2;
LeaveCriticalSection (&ch[channel].csDSP);
}
PORT
void SetRXAPanelCopy (int channel, int copy)
{
EnterCriticalSection (&ch[channel].csDSP);
rxa[channel].panel.p->copy = copy;
LeaveCriticalSection (&ch[channel].csDSP);
}
PORT
void SetRXAPanelBinaural (int channel, int bin)
{
EnterCriticalSection (&ch[channel].csDSP);
rxa[channel].panel.p->copy = 1 - bin;
LeaveCriticalSection (&ch[channel].csDSP);
}
/********************************************************************************************************
* *
* TXA Properties *
* *
********************************************************************************************************/
PORT
void SetTXAPanelRun (int channel, int run)
{
EnterCriticalSection (&ch[channel].csDSP);
txa[channel].panel.p->run = run;
LeaveCriticalSection (&ch[channel].csDSP);
}
PORT
void SetTXAPanelGain1 (int channel, double gain)
{
EnterCriticalSection (&ch[channel].csDSP);
txa[channel].panel.p->gain1 = gain;
//print_message ("micgainset.txt", "Set MIC Gain to", (int)(100.0 * gain), 0, 0);
LeaveCriticalSection (&ch[channel].csDSP);
}
PORT
void SetTXAPanelSelect (int channel, int select)
{
EnterCriticalSection (&ch[channel].csDSP);
if (select == 1)
txa[channel].panel.p->copy = 3;
else
txa[channel].panel.p->copy = 0;
txa[channel].panel.p->inselect = select;
LeaveCriticalSection (&ch[channel].csDSP);
}