]> git.rkrishnan.org Git - dttsp.git/blob - jDttSP/sdr.c
f04d641d52a9a0d3c472a1129db8b7dc6ce24627
[dttsp.git] / jDttSP / sdr.c
1 /* sdr.c
2
3 This file is part of a program that implements a Software-Defined Radio.
4
5 Copyright (C) 2004 by Frank Brickle, AB2KT and Bob McGwier, N4HY
6
7 This program is free software; you can redistribute it and/or modify
8 it under the terms of the GNU General Public License as published by
9 the Free Software Foundation; either version 2 of the License, or
10 (at your option) any later version.
11
12 This program is distributed in the hope that it will be useful,
13 but WITHOUT ANY WARRANTY; without even the implied warranty of
14 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
15 GNU General Public License for more details.
16
17 You should have received a copy of the GNU General Public License
18 along with this program; if not, write to the Free Software
19 Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
20
21 The authors can be reached by email at
22
23 ab2kt@arrl.net
24 or
25 rwmcgwier@comcast.net
26
27 or by paper mail at
28
29 The DTTS Microwave Society
30 6 Kathleen Place
31 Bridgewater, NJ 08807
32 */
33
34 #include <common.h>
35
36 //========================================================================
37 /* initialization and termination */
38
39 /* global and general info,
40    not specifically attached to
41    tx, rx, or scheduling */
42
43 PRIVATE void
44 setup_all(void) {
45
46   uni.samplerate = loc.def.rate;
47   uni.buflen = loc.def.size;
48   uni.mode.sdr = loc.def.mode;
49   uni.mode.trx = RX;
50
51   if (uni.meter.flag) {
52     uni.meter.chan.path = loc.path.meter;
53     uni.meter.chan.size = loc.mult.ring * sizeof(REAL);
54     uni.meter.val = -200.0;
55     uni.meter.chan.c = openChan(uni.meter.chan.path, uni.meter.chan.size);
56   }
57
58   uni.wisdom.path = loc.path.wisdom;
59   uni.wisdom.bits = FFTW_OUT_OF_PLACE | FFTW_ESTIMATE;
60   {
61     FILE *f = fopen(uni.wisdom.path, "r");
62     if (f) {
63 #define WBUFLEN 2048
64 #define WSTRLEN 64      
65       char *line = alloca(WBUFLEN);
66       fgets(line, WBUFLEN, f);
67       if ((strlen(line) > WSTRLEN) &&
68           (fftw_import_wisdom_from_string(line) != FFTW_FAILURE))
69         uni.wisdom.bits = FFTW_OUT_OF_PLACE | FFTW_MEASURE | FFTW_USE_WISDOM;
70 #undef WSTRLEN
71 #undef WBUFLEN      
72       fclose(f);
73     }
74   }
75
76   uni.tick = 0;
77 }
78
79 /* purely rx */
80
81 PRIVATE void
82 setup_rx(void) {
83
84   /* conditioning */
85   rx.iqfix = newCorrectIQ(0.0, 1.0);
86   rx.filt.coef = newFIR_Bandpass_COMPLEX(-4800.0,
87                                          4800.0,
88                                          uni.samplerate,
89                                          uni.buflen + 1);
90   rx.filt.ovsv = newFiltOvSv(FIRcoef(rx.filt.coef),
91                              FIRsize(rx.filt.coef),
92                              uni.wisdom.bits);
93   normalize_vec_COMPLEX(rx.filt.ovsv->zfvec,
94                         rx.filt.ovsv->fftlen);
95
96   // hack for EQ
97   rx.filt.save = newvec_COMPLEX(rx.filt.ovsv->fftlen, "RX filter cache");
98   memcpy((char *) rx.filt.save,
99          (char *) rx.filt.ovsv->zfvec,
100          rx.filt.ovsv->fftlen * sizeof(COMPLEX));
101
102   /* buffers */
103   /* note we overload the internal filter buffers
104      we just created */
105   rx.buf.i = newCXB(FiltOvSv_fetchsize(rx.filt.ovsv),
106                     FiltOvSv_fetchpoint(rx.filt.ovsv),
107                     "init rx.buf.i");
108   rx.buf.o = newCXB(FiltOvSv_storesize(rx.filt.ovsv),
109                     FiltOvSv_storepoint(rx.filt.ovsv),
110                     "init rx.buf.o");
111   
112   /* conversion */
113   rx.osc.freq = -11025.0;
114   rx.osc.phase = 0.0;
115   rx.osc.gen = newOSC(uni.buflen,
116                       ComplexTone,
117                       rx.osc.freq,
118                       rx.osc.phase,
119                       uni.samplerate,
120                       "SDR RX Oscillator");
121
122   rx.agc.gen = newDigitalAgc(agcMED,    // Mode
123                              7,         // Hang
124                              7,         // Size
125                              48,        // Ramp
126                              3,         // Over
127                              3,         // Rcov
128                              CXBsize(rx.buf.o), // BufSize
129                              100.0,     // MaxGain
130                              0.707,     // Limit
131                              1.0,       // CurGain
132                              CXBbase(rx.buf.o));
133   rx.agc.flag = TRUE;
134
135   /* demods */
136   rx.am.gen = newAMD(48000.0,   // REAL samprate
137                      0.0,       // REAL f_initial
138                      -500.0,    // REAL f_lobound,
139                      500.0,     // REAL f_hibound,
140                      400.0,     // REAL f_bandwid,
141                      CXBsize(rx.buf.o), // int size,
142                      CXBbase(rx.buf.o), // COMPLEX *ivec,
143                      CXBbase(rx.buf.o), // COMPLEX *ovec,
144                      AMdet,     // AM Mode AMdet == rectifier,
145                                 //         SAMdet == synchronous detector
146                              "AM detector blew");       // char *tag
147   rx.fm.gen = newFMD(48000,     // REAL samprate
148                      0.0,       // REAL f_initial
149                      -6000.0,   // REAL f_lobound
150                      6000.0,    // REAL f_hibound
151                      10000.0,   // REAL f_bandwid
152                      CXBsize(rx.buf.o), // int size
153                      CXBbase(rx.buf.o), // COMPLEX *ivec
154                      CXBbase(rx.buf.o), // COMPLEX *ovec
155                      "New FM Demod structure"); // char *error message;
156
157   /* noise reduction */
158   rx.anf.gen = new_lmsr(rx.buf.o,       // CXB signal,
159                         64,             // int delay,
160                         0.01,           // REAL adaptation_rate,
161                         0.00001,        // REAL leakage,
162                         45,             // int adaptive_filter_size,
163                         LMADF_INTERFERENCE);
164   rx.anf.flag = FALSE;
165   rx.anr.gen = new_lmsr(rx.buf.o,       // CXB signal,
166                         64,             // int delay,
167                         0.01,           // REAL adaptation_rate,
168                         0.00001,        // REAL leakage,
169                         45,             // int adaptive_filter_size,
170                         LMADF_NOISE);
171   rx.anr.flag = FALSE;
172
173   rx.nb.thresh = 3.3;
174   rx.nb.gen = new_noiseblanker(rx.buf.i, rx.nb.thresh);
175   rx.nb.flag = FALSE;
176
177   rx.nb_sdrom.thresh = 2.5;
178   rx.nb_sdrom.gen = new_noiseblanker(rx.buf.i, rx.nb_sdrom.thresh);
179   rx.nb_sdrom.flag = FALSE;
180
181   rx.spot.gen = newSpotToneGen(-12.0,   // gain
182                                700.0,   // freq
183                                5.0,     // ms rise
184                                5.0,     // ms fall
185                                uni.buflen,
186                                uni.samplerate);
187
188   rx.scl.pre.val = 1.0;
189   rx.scl.pre.flag = FALSE;
190   rx.scl.post.val = 1.0;
191   rx.scl.post.flag = FALSE;
192
193   memset((char *) &rx.squelch, 0, sizeof(rx.squelch));
194   rx.squelch.thresh = -30.0;
195   rx.squelch.power = 0.0;
196   rx.squelch.flag = rx.squelch.running = rx.squelch.set = FALSE;
197   rx.squelch.num = (int) (0.0395 * uni.samplerate + 0.5);
198
199   rx.mode = uni.mode.sdr;
200   rx.bin.flag = FALSE;
201
202   rx.tick = 0;
203 }
204
205 /* purely tx */
206
207 PRIVATE void
208 setup_tx(void) {
209
210   /* conditioning */
211   tx.iqfix = newCorrectIQ(0.0, 1.0);
212   tx.filt.coef = newFIR_Bandpass_COMPLEX(300.0,
213                                          3000.0,
214                                          uni.samplerate,
215                                          uni.buflen + 1);
216   tx.filt.ovsv = newFiltOvSv(FIRcoef(tx.filt.coef),
217                              FIRsize(tx.filt.coef),
218                              uni.wisdom.bits);
219   normalize_vec_COMPLEX(tx.filt.ovsv->zfvec,
220                         tx.filt.ovsv->fftlen);
221
222   // hack for EQ
223   tx.filt.save = newvec_COMPLEX(tx.filt.ovsv->fftlen, "TX filter cache");
224   memcpy((char *) tx.filt.save,
225          (char *) tx.filt.ovsv->zfvec,
226          tx.filt.ovsv->fftlen * sizeof(COMPLEX));
227
228   /* buffers */
229   tx.buf.i = newCXB(FiltOvSv_fetchsize(tx.filt.ovsv),
230                     FiltOvSv_fetchpoint(tx.filt.ovsv),
231                     "init tx.buf.i");
232   tx.buf.o = newCXB(FiltOvSv_storesize(tx.filt.ovsv),
233                     FiltOvSv_storepoint(tx.filt.ovsv),
234                     "init tx.buf.o");
235   
236   /* conversion */
237   tx.osc.freq = 0.0;
238   tx.osc.phase = 0.0;
239   tx.osc.gen = newOSC(uni.buflen,
240                       ComplexTone,
241                       tx.osc.freq,
242                       tx.osc.phase,
243                       uni.samplerate,
244                       "SDR TX Oscillator");
245
246   tx.agc.gen = newDigitalAgc(agcFAST,   // Mode
247                              3,         // Hang
248                              3,         // Size
249                              3,         // Over
250                              3,         // Rcov
251                              48,        // Ramp
252                              CXBsize(tx.buf.o), // BufSize
253                              1.0,       // MaxGain
254                              0.900,     // Limit
255                              1.0,       // CurGain
256                              CXBbase(tx.buf.o));
257   tx.agc.flag = TRUE;
258
259   tx.spr.gen = newSpeechProc(0.4, 10.0, CXBbase(tx.buf.i), CXBsize(tx.buf.i));
260   tx.spr.flag = FALSE;
261
262   tx.scl.dc = cxzero;
263   tx.scl.pre.val = 1.0;
264   tx.scl.pre.flag = FALSE;
265   tx.scl.post.val = 1.0;
266   tx.scl.post.flag = FALSE;
267
268   tx.mode = uni.mode.sdr;
269
270   tx.tick = 0;
271   /* not much else to do for TX */
272 }
273
274 /* how the outside world sees it */
275
276 void
277 setup_workspace(void) {
278   setup_all(), setup_rx(), setup_tx();
279 }
280
281 void
282 destroy_workspace(void) {
283
284   /* TX */
285   delSpeechProc(tx.spr.gen);
286   delDigitalAgc(tx.agc.gen);
287   delOSC(tx.osc.gen);
288   delvec_COMPLEX(tx.filt.save);
289   delFiltOvSv(tx.filt.ovsv);
290   delFIR_Bandpass_COMPLEX(tx.filt.coef);
291   delCorrectIQ(tx.iqfix);
292   delCXB(tx.buf.o);
293   delCXB(tx.buf.i);
294
295   /* RX */
296   delSpotToneGen(rx.spot.gen);
297   delDigitalAgc(rx.agc.gen);
298   del_nb(rx.nb_sdrom.gen);
299   del_nb(rx.nb.gen);
300   del_lmsr(rx.anf.gen);
301   del_lmsr(rx.anr.gen);
302   delAMD(rx.am.gen);
303   delFMD(rx.fm.gen);
304   delOSC(rx.osc.gen);
305   delvec_COMPLEX(rx.filt.save);
306   delFiltOvSv(rx.filt.ovsv);
307   delFIR_Bandpass_COMPLEX(rx.filt.coef);
308   delCorrectIQ(rx.iqfix);
309   delCXB(rx.buf.o);
310   delCXB(rx.buf.i);
311
312   /* all */
313   if (uni.meter.flag)
314     closeChan(uni.meter.chan.c);
315 }
316
317 //////////////////////////////////////////////////////////////////////////
318 // execution
319 //////////////////////////////////////////////////////////////////////////
320
321 //========================================================================
322 /* all */
323
324 /* tap off S-meter from some buf */
325
326 PRIVATE void
327 do_meter(COMPLEX *vec, int len) {
328   int i;
329   
330   uni.meter.val = 0;
331
332   switch (uni.meter.type) {
333   case AVG_SIGNAL_STRENGTH:
334     for (i = 0; i < len; i++)
335       uni.meter.val += Csqrmag(vec[i]);
336     uni.meter.val =
337       uni.meter.avgval = 0.9 * uni.meter.avgval + log10(uni.meter.val + 1e-20);
338     break;
339   case SIGNAL_STRENGTH:
340     for (i = 0; i < len; i++)
341       uni.meter.val += Csqrmag(vec[i]);
342     uni.meter.avgval = uni.meter.val = 10.0 * log10(uni.meter.val + 1e-20);
343     break;
344   case ADC_REAL:
345     for(i = 0; i < len; i++)
346       uni.meter.val = max(fabs(vec[i].re), uni.meter.val);
347     uni.meter.val = 20.0 * log10(uni.meter.val + 1e-10);
348     break;
349   case ADC_IMAG:
350     for(i = 0; i < len; i++)
351       uni.meter.val = max(fabs(vec[i].im), uni.meter.val);
352     uni.meter.val = 20.0 * log10(uni.meter.val + 1e-10);
353     break;
354   default:
355     break;
356   }
357
358   putChan_nowait(uni.meter.chan.c,
359                  (char *) &uni.meter.val,
360                  sizeof(uni.meter.val));
361 }
362
363 //========================================================================
364 /* RX processing */ 
365
366 PRIVATE BOOLEAN
367 should_do_rx_squelch(void) {
368   if (rx.squelch.flag) {
369     int i, n = CXBhave(rx.buf.o);
370     REAL tst;
371     rx.squelch.power = 0.0;
372     for (i = 0; i < n; i++)
373       rx.squelch.power += Csqrmag(CXBdata(rx.buf.o, i));
374     tst = (10.0 * log10(rx.squelch.power)
375             + rx.squelch.offset.meter
376             + rx.squelch.offset.att
377             + rx.squelch.offset.gain);
378     return rx.squelch.thresh > tst;
379   } else
380     return rx.squelch.set = FALSE;
381 }
382
383 // apply squelch
384 // slew into silence first time
385
386 PRIVATE void
387 do_squelch(void) {
388   rx.squelch.set = TRUE;
389   if (!rx.squelch.running) {
390     int i, m = rx.squelch.num, n = CXBhave(rx.buf.o) - m;
391     for (i = 0; i < m; i++)
392       CXBdata(rx.buf.o, i) = Cscl(CXBdata(rx.buf.o, i), 1.0 - (REAL) i / m);
393     memset((void *) (CXBbase(rx.buf.o) + m), 0, n * sizeof(COMPLEX));
394     rx.squelch.running = TRUE;
395   } else
396     memset((void *) CXBbase(rx.buf.o), 0, CXBhave(rx.buf.o) * sizeof(COMPLEX));
397 }
398
399 // lift squelch
400 // slew out from silence to full scale
401
402 PRIVATE void
403 no_squelch(void) {
404   if (rx.squelch.running) {
405     int i, m = rx.squelch.num;
406     for (i = 0; i < m; i++)
407       CXBdata(rx.buf.o, i) = Cscl(CXBdata(rx.buf.o, i), (REAL) i / m);
408     rx.squelch.running = FALSE;
409   }
410 }
411
412 /* pre-condition for (nearly) all RX modes */
413
414 PRIVATE void
415 do_rx_pre(void) {
416   int i, n = min(CXBhave(rx.buf.i), uni.buflen);
417
418   //
419   // do shrinkage here
420   //
421
422   if (rx.scl.pre.flag)
423     for (i = 0; i < n; i++)
424       CXBdata(rx.buf.i, i) = Cscl(CXBdata(rx.buf.i, i),
425                                   rx.scl.pre.val); 
426
427   if (rx.nb.flag) noiseblanker(rx.nb.gen);
428   if (rx.nb_sdrom.flag) SDROMnoiseblanker(rx.nb_sdrom.gen);
429
430   correctIQ(rx.buf.i, rx.iqfix);
431
432   /* 2nd if conversion happens here */
433   if (rx.osc.gen->Frequency != 0.0) {
434     ComplexOSC(rx.osc.gen);
435     for (i = 0; i < n; i++)
436       CXBdata(rx.buf.i, i) = Cmul(CXBdata(rx.buf.i, i),
437                                   OSCCdata(rx.osc.gen, i));
438   } 
439
440   /* filtering, metering, & AGC */
441   if (rx.mode != SPEC) {
442     filter_OvSv(rx.filt.ovsv);
443     CXBhave(rx.buf.o) = CXBhave(rx.buf.i);
444     if (uni.meter.flag) do_meter(CXBbase(rx.buf.o), uni.buflen);
445     if (rx.agc.flag) DigitalAgc(rx.agc.gen, rx.tick);
446   } else if (uni.meter.flag)
447     do_meter(CXBbase(rx.buf.o), uni.buflen);
448 }
449
450 PRIVATE void
451 do_rx_post(void) {
452   int i, n = CXBhave(rx.buf.o);;
453
454   if (!rx.squelch.set)  {
455     no_squelch();
456     // spotting tone
457     if (rx.spot.flag) {
458       // remember whether it's turned itself off during this pass
459       rx.spot.flag = SpotTone(rx.spot.gen);
460       for (i = 0; i < n; i++)
461         CXBdata(rx.buf.o, i) = Cadd(CXBdata(rx.buf.o, i),
462                                     CXBdata(rx.spot.gen->buf, i));
463     }
464   }
465
466   //
467   // mix in sidetone here
468   //
469
470   if (rx.scl.post.flag)
471     for (i = 0; i < n; i++)
472       CXBdata(rx.buf.o, i) = Cscl(CXBdata(rx.buf.o, i),
473                                   rx.scl.post.val);
474
475   // not binaural? collapse
476   if (!rx.bin.flag)
477     for (i = 0; i < n; i++)
478       CXBimag(rx.buf.o, i) = CXBreal(rx.buf.o, i);
479 }
480
481 /* demod processing */
482
483 PRIVATE void
484 do_rx_SBCW(void) {
485   if (rx.anr.flag) lmsr_adapt(rx.anr.gen);
486   if (rx.anf.flag) lmsr_adapt(rx.anf.gen);
487 }
488
489 PRIVATE void
490 do_rx_AM(void) { AMDemod(rx.am.gen); }
491
492 PRIVATE void
493 do_rx_FM(void) { FMDemod(rx.fm.gen); }
494
495 PRIVATE void
496 do_rx_DRM(void) {}
497
498 PRIVATE void
499 do_rx_SPEC(void) {
500   memcpy(CXBbase(rx.buf.o),
501          CXBbase(rx.buf.i),
502          sizeof(COMPLEX) * CXBhave(rx.buf.i));
503   if (rx.agc.flag) DigitalAgc(rx.agc.gen, rx.tick);
504 }
505
506 PRIVATE void
507 do_rx_NIL(void) {
508   int i, n = min(CXBhave(rx.buf.i), uni.buflen);
509   for (i = 0; i < n; i++) CXBdata(rx.buf.o, i) = cxzero;
510 }
511
512 /* overall dispatch for RX processing */
513
514 PRIVATE void
515 do_rx(void) {
516   do_rx_pre();
517   switch (rx.mode) {
518   case USB:
519   case LSB:
520   case CWU:
521   case CWL:
522   case DSB:  do_rx_SBCW(); break;
523   case AM:
524   case SAM:  do_rx_AM(); break;
525   case FMN:  do_rx_FM();   break;
526   case DRM:  do_rx_DRM();  break;
527   case SPEC:
528     default: do_rx_SPEC(); break;
529   }
530   do_rx_post();
531 }  
532
533 //==============================================================
534 /* TX processing */
535
536 /* pre-condition for (nearly) all TX modes */
537
538 PRIVATE void
539 do_tx_pre(void) {
540   if (tx.scl.pre.flag) {
541     int i, n = CXBhave(tx.buf.i);
542     for (i = 0; i < n; i++)
543       CXBdata(tx.buf.i, i) = Cmplx(CXBreal(tx.buf.i, i) * tx.scl.pre.val, 0.0);
544   }
545
546   //
547   // mix in CW tone here
548   //
549
550   correctIQ(tx.buf.i, tx.iqfix);
551
552   if (tx.spr.flag) SpeechProcessor(tx.spr.gen);
553   filter_OvSv(tx.filt.ovsv);
554 }
555
556 PRIVATE void
557 do_tx_post(void) {
558   CXBhave(tx.buf.o) = CXBhave(tx.buf.i);
559
560   if (tx.agc.flag) DigitalAgc(tx.agc.gen, tx.tick);
561   if (tx.scl.post.flag) {
562     int i, n = CXBhave(tx.buf.o);
563     for (i = 0; i < n; i++)
564       CXBdata(tx.buf.o, i) = Cscl(CXBdata(tx.buf.o, i), tx.scl.post.val);
565   }
566   if (uni.meter.flag) do_meter(CXBbase(tx.buf.o), uni.buflen);
567   if (tx.osc.gen->Frequency != 0.0) {
568     int i;
569     ComplexOSC(tx.osc.gen);
570     for (i = 0; i < CXBhave(tx.buf.o); i++)
571       CXBdata(tx.buf.o, i) = Cmul(CXBdata(tx.buf.o, i), OSCCdata(tx.osc.gen, i));
572   }
573 }
574
575 /* modulator processing */
576
577 PRIVATE void
578 do_tx_SBCW(void) {
579   int i, n = min(CXBhave(tx.buf.i), uni.buflen); 
580   for (i = 0; i < n; i++) {
581     tx.scl.dc = Cadd(Cscl(tx.scl.dc, 0.99),
582                      Cscl(CXBdata(tx.buf.o,i), -0.01));
583     CXBdata(tx.buf.o, i) = Cadd(CXBdata(tx.buf.o,i), tx.scl.dc);
584   }
585 }
586
587 PRIVATE void
588 do_tx_AM(void) {
589   int i, n = min(CXBhave(tx.buf.i), uni.buflen); 
590   for (i = 0; i < n; i++) { 
591     tx.scl.dc = Cadd(Cscl(tx.scl.dc, 0.999),
592                      Cscl(CXBdata(tx.buf.o,i), -0.001));
593     CXBreal(tx.buf.o, i) =
594       0.49995 + 0.49995 * (CXBreal(tx.buf.o,i) - tx.scl.dc.re);
595     CXBimag(tx.buf.o, i) = 0.0;
596   }
597 }
598
599 PRIVATE void
600 do_tx_FM(void) {
601   int i, n = min(CXBhave(tx.buf.i), uni.buflen);
602   for (i = 0; i < n; i++) {
603     tx.scl.dc = Cadd(Cscl(tx.scl.dc,0.999),
604                      Cscl(CXBdata(tx.buf.o,i), 0.001));
605     tx.osc.phase += (CXBreal(tx.buf.o, i)- tx.scl.dc.re) * CvtMod2Freq;
606     if (tx.osc.phase >= TWOPI) tx.osc.phase -= TWOPI;
607     if (tx.osc.phase < 0.0) tx.osc.phase += TWOPI;
608     CXBdata(tx.buf.o, i) =
609       Cscl(Cmplx(cos(tx.osc.phase), sin(tx.osc.phase)), 0.99999);
610   }
611 }
612
613 PRIVATE void
614 do_tx_NIL(void) {
615   int i, n = min(CXBhave(tx.buf.i), uni.buflen);
616   for (i = 0; i < n; i++) CXBdata(tx.buf.o, i) = cxzero;
617 }
618
619 /* general TX processing dispatch */
620
621 PRIVATE void
622 do_tx(void) {
623   do_tx_pre();
624   switch (tx.mode) {
625   case USB:
626   case LSB:
627   case CWU:
628   case CWL:
629   case DSB:  do_tx_SBCW(); break;
630   case AM:
631   case SAM:  do_tx_AM();   break;
632   case FMN:  do_tx_FM();   break;
633   case DRM:
634   case SPEC:
635     default: do_tx_NIL(); break;
636   }
637   do_tx_post();
638 }
639
640 //========================================================================
641 /* overall buffer processing;
642    come here when there are buffers to work on */
643
644 void
645 process_samples(float *bufl, float *bufr, int n) {
646   int i;
647
648   switch (uni.mode.trx) {
649
650   case RX:
651     for (i = 0; i < n; i++)
652       CXBimag(rx.buf.i, i) = bufl[i], CXBreal(rx.buf.i, i) = bufr[i];
653     CXBhave(rx.buf.i) = n;
654
655     do_rx(), rx.tick++;
656
657     for (i = 0; i < n; i++)
658       bufl[i] = (float)CXBimag(rx.buf.o, i), bufr[i] = (float)CXBreal(rx.buf.o, i);
659     CXBhave(rx.buf.o) = n;
660     break;
661
662   case TX:
663     for (i = 0; i < n; i++)
664       CXBimag(tx.buf.i, i) = bufl[i], CXBreal(tx.buf.i, i) = bufr[i];
665     CXBhave(tx.buf.i) = n;
666
667     do_tx(), tx.tick++;
668
669     for (i = 0; i < n; i++)
670       bufl[i] = (float)CXBimag(tx.buf.o, i), bufr[i] = (float)CXBreal(tx.buf.o, i);
671     CXBhave(rx.buf.o) = n;
672     break;
673   }
674
675   uni.tick++;
676 }