forked from g0orx/wdsp
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy patheer.c
393 lines (350 loc) · 9.82 KB
/
eer.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
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
/* eer.c
This file is part of a program that implements a Software-Defined Radio.
Copyright (C) 2014 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"
PORT
EER create_eer (int run, int size, double* in, double* out, double* outM, int rate, double mgain, double pgain, int rundelays, double mdelay, double pdelay, int amiq)
{
EER a = (EER) malloc0 (sizeof (eer));
a->run = run;
a->size = size;
a->in = in;
a->out = out;
a->outM = outM;
a->rate = rate;
a->mgain = mgain;
a->pgain = pgain;
a->rundelays = rundelays;
a->mdelay = mdelay;
a->pdelay = pdelay;
a->amiq = amiq;
a->mdel = create_delay (
a->rundelays, // run
a->size, // size
a->outM, // input buffer
a->outM, // output buffer
a->rate, // sample rate
20.0e-09, // delta (delay stepsize)
a->mdelay); // delay
a->pdel = create_delay (
a->rundelays, // run
a->size, // size
a->out, // input buffer
a->out, // output buffer
a->rate, // sample rate
20.0e-09, // delta (delay stepsize)
a->pdelay); // delay
InitializeCriticalSectionAndSpinCount(&a->cs_update, 2500);
a->legacy = (double *) malloc0 (2048 * sizeof (complex)); /////////////// legacy interface - remove
a->legacyM = (double *) malloc0 (2048 * sizeof (complex)); /////////////// legacy interface - remove
return a;
}
PORT
void destroy_eer (EER a)
{
DeleteCriticalSection (&a->cs_update);
destroy_delay (a->pdel);
destroy_delay (a->mdel);
_aligned_free (a);
}
PORT
void flush_eer (EER a)
{
flush_delay (a->mdel);
flush_delay (a->pdel);
}
PORT
void xeer (EER a)
{
EnterCriticalSection (&a->cs_update);
if (a->run)
{
int i;
double I, Q, mag;
for (i = 0; i < a->size; i++)
{
I = a->in[2 * i + 0];
Q = a->in[2 * i + 1];
a->outM[2 * i + 0] = I * a->mgain;
a->outM[2 * i + 1] = Q * a->mgain;
switch (a->amiq)
{
case 0: // send phase info only, magnitude is constant
mag = sqrt (I * I + Q * Q);
a->out [2 * i + 0] = a->pgain * I / mag;
a->out [2 * i + 1] = a->pgain * Q / mag;
break;
case 1: // send magnitude and phase information, I and Q
a->out [2 * i + 0] = a->pgain * I;
a->out [2 * i + 1] = a->pgain * Q;
break;
case 2: // send envelope
mag = sqrt (I * I + Q * Q);
a->out [2 * i + 0] = a->out[2 * i + 1] = a->pgain * mag;
break;
}
}
xdelay (a->mdel); // delay for outM
xdelay (a->pdel); // delay for out
}
else if (a->out != a->in)
memcpy (a->out, a->in, a->size * sizeof (complex));
LeaveCriticalSection (&a->cs_update);
}
/********************************************************************************************************
* *
* CALLS FOR EXTERNAL USE *
* *
********************************************************************************************************/
#define MAX_EXT_EERS (2) // maximum number of EERs called from outside wdsp
__declspec (align (16)) EER peer[MAX_EXT_EERS]; // array of pointers for EERs used EXTERNAL to wdsp
PORT
void create_eerEXT (int id, int run, int size, int rate, double mgain, double pgain, int rundelays, double mdelay, double pdelay, int amiq)
{
peer[id] = create_eer (run, size, 0, 0, 0, rate, mgain, pgain, rundelays, mdelay, pdelay, amiq);
}
PORT
void destroy_eerEXT (int id)
{
destroy_eer (peer[id]);
}
PORT
void flush_eerEXT (int id)
{
flush_eer (peer[id]);
}
PORT
void SetEERRun (int id, int run)
{
EER a = peer[id];
EnterCriticalSection (&a->cs_update);
a->run = run;
LeaveCriticalSection (&a->cs_update);
}
PORT
void SetEERAMIQ (int id, int amiq)
{
EER a = peer[id];
EnterCriticalSection (&a->cs_update);
a->amiq = amiq;
LeaveCriticalSection (&a->cs_update);
}
PORT
void SetEERMgain (int id, double gain)
{
EER a = peer[id];
EnterCriticalSection (&a->cs_update);
a->mgain = gain;
LeaveCriticalSection (&a->cs_update);
}
PORT
void SetEERPgain (int id, double gain)
{
EER a = peer[id];
EnterCriticalSection (&a->cs_update);
a->pgain = gain;
LeaveCriticalSection (&a->cs_update);
}
PORT
void SetEERRunDelays (int id, int run)
{
EER a = peer[id];
EnterCriticalSection (&a->cs_update);
a->rundelays = run;
SetDelayRun (a->mdel, a->rundelays);
SetDelayRun (a->pdel, a->rundelays);
LeaveCriticalSection (&a->cs_update);
}
PORT
void SetEERMdelay (int id, double delay)
{
EER a = peer[id];
EnterCriticalSection (&a->cs_update);
a->mdelay = delay;
SetDelayValue (a->mdel, a->mdelay);
LeaveCriticalSection (&a->cs_update);
}
PORT
void SetEERPdelay (int id, double delay)
{
EER a = peer[id];
EnterCriticalSection (&a->cs_update);
a->pdelay = delay;
SetDelayValue (a->pdel, a->pdelay);
LeaveCriticalSection (&a->cs_update);
}
PORT
void SetEERSize (int id, int size)
{
EER a = peer[id];
EnterCriticalSection (&a->cs_update);
a->size = size;
SetDelayBuffs (a->mdel, a->size, a->outM, a->outM);
SetDelayBuffs (a->pdel, a->size, a->out, a->out);
LeaveCriticalSection (&a->cs_update);
}
PORT
void SetEERSamplerate (int id, int rate)
{
EER a = peer[id];
EnterCriticalSection (&a->cs_update);
a->rate = rate;
destroy_delay (a->mdel);
destroy_delay (a->pdel);
a->mdel = create_delay (
a->rundelays, // run
a->size, // size
a->outM, // input buffer
a->outM, // output buffer
a->rate, // sample rate
20.0e-09, // delta (delay stepsize)
a->mdelay); // delay
a->pdel = create_delay (
a->rundelays, // run
a->size, // size
a->out, // input buffer
a->out, // output buffer
a->rate, // sample rate
20.0e-09, // delta (delay stepsize)
a->pdelay); // delay
LeaveCriticalSection (&a->cs_update);
}
/********************************************************************************************************
* *
* POINTER-BASED PROPERTIES *
* *
********************************************************************************************************/
PORT
void pSetEERRun (EER a, int run)
{
EnterCriticalSection (&a->cs_update);
a->run = run;
LeaveCriticalSection (&a->cs_update);
}
PORT
void pSetEERAMIQ (EER a, int amiq)
{
EnterCriticalSection (&a->cs_update);
a->amiq = amiq;
LeaveCriticalSection (&a->cs_update);
}
PORT
void pSetEERMgain (EER a, double gain)
{
EnterCriticalSection (&a->cs_update);
a->mgain = gain;
LeaveCriticalSection (&a->cs_update);
}
PORT
void pSetEERPgain (EER a, double gain)
{
EnterCriticalSection (&a->cs_update);
a->pgain = gain;
LeaveCriticalSection (&a->cs_update);
}
PORT
void pSetEERRunDelays (EER a, int run)
{
EnterCriticalSection (&a->cs_update);
a->rundelays = run;
SetDelayRun (a->mdel, a->rundelays);
SetDelayRun (a->pdel, a->rundelays);
LeaveCriticalSection (&a->cs_update);
}
PORT
void pSetEERMdelay (EER a, double delay)
{
EnterCriticalSection (&a->cs_update);
a->mdelay = delay;
SetDelayValue (a->mdel, a->mdelay);
LeaveCriticalSection (&a->cs_update);
}
PORT
void pSetEERPdelay (EER a, double delay)
{
EnterCriticalSection (&a->cs_update);
a->pdelay = delay;
SetDelayValue (a->pdel, a->pdelay);
LeaveCriticalSection (&a->cs_update);
}
PORT
void pSetEERSize (EER a, int size)
{
EnterCriticalSection (&a->cs_update);
a->size = size;
SetDelayBuffs (a->mdel, a->size, a->outM, a->outM);
SetDelayBuffs (a->pdel, a->size, a->out, a->out);
LeaveCriticalSection (&a->cs_update);
}
PORT
void pSetEERSamplerate (EER a, int rate)
{
EnterCriticalSection (&a->cs_update);
a->rate = rate;
destroy_delay (a->mdel);
destroy_delay (a->pdel);
a->mdel = create_delay (
a->rundelays, // run
a->size, // size
a->outM, // input buffer
a->outM, // output buffer
a->rate, // sample rate
20.0e-09, // delta (delay stepsize)
a->mdelay); // delay
a->pdel = create_delay (
a->rundelays, // run
a->size, // size
a->out, // input buffer
a->out, // output buffer
a->rate, // sample rate
20.0e-09, // delta (delay stepsize)
a->pdelay); // delay
LeaveCriticalSection (&a->cs_update);
}
/********************************************************************************************************
* *
* Legacy Interface *
* *
********************************************************************************************************/
PORT
void xeerEXTF (int id, float* inI, float* inQ, float* outI, float* outQ, float* outMI, float* outMQ, int mox, int size)
{
EER a = peer[id];
if (mox && a->run)
{
int i;
a->in = a->legacy;
a->out = a->legacy;
a->outM = a->legacyM;
a->size = size;
SetDelayBuffs (a->mdel, a->size, a->outM, a->outM);
SetDelayBuffs (a->pdel, a->size, a->out, a->out);
for (i = 0; i < a->size; i++)
{
a->legacy[2 * i + 0] = (double)inI[i];
a->legacy[2 * i + 1] = (double)inQ[i];
}
xeer (a);
for (i = 0; i < a->size; i++)
{
outI[i] = (float)a->legacy [2 * i + 0];
outQ[i] = (float)a->legacy [2 * i + 1];
outMI[i] = (float)a->legacyM[2 * i + 0];
outMQ[i] = (float)a->legacyM[2 * i + 1];
}
}
}