3 common defs and code for parm update
5 This file is part of a program that implements a Software-Defined Radio.
7 Copyright (C) 2004 by Frank Brickle, AB2KT and Bob McGwier, N4HY
9 This program is free software; you can redistribute it and/or modify
10 it under the terms of the GNU General Public License as published by
11 the Free Software Foundation; either version 2 of the License, or
12 (at your option) any later version.
14 This program is distributed in the hope that it will be useful,
15 but WITHOUT ANY WARRANTY; without even the implied warranty of
16 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
17 GNU General Public License for more details.
19 You should have received a copy of the GNU General Public License
20 along with this program; if not, write to the Free Software
21 Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
23 The authors can be reached by email at
31 The DTTS Microwave Society
38 ////////////////////////////////////////////////////////////////////////////
41 dB2lin(REAL dB) { return pow(10.0, dB / 20.0); }
45 setRXFilter(int n, char **p) {
46 REAL low_frequency = atof(p[0]),
47 high_frequency = atof(p[1]);
48 int ncoef = uni.buflen + 1;
49 int i, fftlen = 2 * uni.buflen;
53 if (fabs(low_frequency) >= 0.5 * uni.samplerate) return -1;
54 if (fabs(high_frequency) >= 0.5 * uni.samplerate) return -2;
55 if ((low_frequency + 10) >= high_frequency) return -3;
56 delFIR_COMPLEX(rx.filt.coef);
58 rx.filt.coef = newFIR_Bandpass_COMPLEX(low_frequency,
63 zcvec = newvec_COMPLEX(fftlen, "filter z vec in setFilter");
64 ptmp = fftw_create_plan(fftlen, FFTW_FORWARD, FFTW_OUT_OF_PLACE);
66 for (i = 0; i < ncoef; i++) zcvec[i] = rx.filt.coef->coef[i];
68 for (i = 0; i < ncoef; i++) zcvec[fftlen - ncoef + i] = rx.filt.coef->coef[i];
70 fftw_one(ptmp, (fftw_complex *) zcvec, (fftw_complex *) rx.filt.ovsv->zfvec);
71 fftw_destroy_plan(ptmp);
72 delvec_COMPLEX(zcvec);
73 memcpy((char *) rx.filt.save,
74 (char *) rx.filt.ovsv->zfvec,
75 rx.filt.ovsv->fftlen * sizeof(COMPLEX));
82 setTXFilter(int n, char **p) {
83 REAL low_frequency = atof(p[0]),
84 high_frequency = atof(p[1]);
85 int ncoef = uni.buflen + 1;
86 int i, fftlen = 2 * uni.buflen;
90 if (fabs(low_frequency) >= 0.5 * uni.samplerate) return -1;
91 if (fabs(high_frequency) >= 0.5 * uni.samplerate) return -2;
92 if ((low_frequency + 10) >= high_frequency) return -3;
93 delFIR_COMPLEX(tx.filt.coef);
94 tx.filt.coef = newFIR_Bandpass_COMPLEX(low_frequency,
99 zcvec = newvec_COMPLEX(fftlen, "filter z vec in setFilter");
100 ptmp = fftw_create_plan(fftlen, FFTW_FORWARD, FFTW_OUT_OF_PLACE);
102 for (i = 0; i < ncoef; i++) zcvec[i] = tx.filt.coef->coef[i];
104 for (i = 0; i < ncoef; i++) zcvec[fftlen - ncoef + i] = tx.filt.coef->coef[i];
106 fftw_one(ptmp, (fftw_complex *) zcvec, (fftw_complex *) tx.filt.ovsv->zfvec);
107 fftw_destroy_plan(ptmp);
108 delvec_COMPLEX(zcvec);
109 memcpy((char *) tx.filt.save,
110 (char *) tx.filt.ovsv->zfvec,
111 tx.filt.ovsv->fftlen * sizeof(COMPLEX));
117 setFilter(int n, char **p) {
118 if (n == 2) return setRXFilter(n, p);
120 int trx = atoi(p[2]);
121 if (trx == RX) return setRXFilter(n, p);
122 else if (trx == TX) return setTXFilter(n, p);
127 // setMode <mode> [TRX]
130 setMode(int n, char **p) {
131 int mode = atoi(p[0]);
133 int trx = atoi(p[1]);
135 case TX: tx.mode = mode; break;
137 default: rx.mode = mode; break;
140 tx.mode = rx.mode = uni.mode.sdr = mode;
141 if (rx.mode == AM) rx.am.gen->mode = AMdet;
142 if (rx.mode == SAM) rx.am.gen->mode = SAMdet;
146 // setOsc <freq> [TRX]
148 setOsc(int n, char **p) {
149 REAL newfreq = atof(p[0]);
150 // fprintf(stderr,"freq =%lf, samplerate = %lf\n",newfreq,uni.samplerate);
151 if (fabs(newfreq) >= 0.5 * uni.samplerate) return -1;
152 newfreq *= 2.0 * M_PI / uni.samplerate;
154 int trx = atoi(p[1]);
156 case TX: tx.osc.gen->Frequency = newfreq; break;
158 default: rx.osc.gen->Frequency = newfreq; break;
161 tx.osc.gen->Frequency = rx.osc.gen->Frequency = newfreq;
166 setSampleRate(int n, char **p) {
167 REAL samplerate = atof(p[0]);
168 uni.samplerate = samplerate;
173 setNR(int n, char **p) {
174 rx.anr.flag = atoi(p[0]);
179 setANF(int n, char **p) {
180 rx.anf.flag = atoi(p[0]);
185 setNB(int n, char **p) {
186 rx.nb.flag = atoi(p[0]);
191 setNBvals(int n, char **p) {
192 REAL threshold = atof(p[0]);
193 rx.nb.gen->threshold = rx.nb.thresh = threshold;
198 setSDROM(int n, char **p) {
199 rx.nb_sdrom.flag = atoi(p[0]);
204 setSDROMvals(int n, char **p) {
205 REAL threshold = atof(p[0]);
206 rx.nb_sdrom.gen->threshold = rx.nb_sdrom.thresh = threshold;
211 setBIN(int n, char **p) {
212 rx.bin.flag = atoi(p[0]);
217 // setfixedAGC <gain> [TRX]
219 setfixedAGC(int n, char **p) {
220 REAL gain = atof(p[0]);
222 int trx = atoi(p[1]);
224 case TX: tx.agc.gen->AgcFixedGain = gain; break;
226 default: rx.agc.gen->AgcFixedGain = gain; break;
229 tx.agc.gen->AgcFixedGain = rx.agc.gen->AgcFixedGain = gain;
234 setTXAGC(int n, char **p) {
235 int setit = atoi(p[0]);
238 tx.agc.gen->AgcMode = agcOFF;
242 tx.agc.gen->AgcMode = agcSLOW;
243 tx.agc.gen->Hang = 10;
247 tx.agc.gen->AgcMode = agcMED;
248 tx.agc.gen->Hang = 6;
252 tx.agc.gen->AgcMode = agcFAST;
253 tx.agc.gen->Hang = 3;
257 tx.agc.gen->AgcMode = agcLONG;
258 tx.agc.gen->Hang = 23;
266 setTXAGCCompression(int n, char **p) {
267 REAL txcompression = atof(p[0]);
268 tx.agc.gen->MaxGain = pow(10.0 , txcompression * 0.05);
273 setTXAGCFF(int n, char **p) {
274 int setit = atoi(p[0]);
280 setTXAGCFFCompression(int n, char **p) {
281 REAL txcompression = atof(p[0]);
282 tx.spr.gen->MaxGain = pow(10.0 , txcompression * 0.05);
287 setTXAGCHang(int n, char **p) {
288 int hang = atoi(p[0]);
290 (int) max(1, min(23, ((REAL) hang) * uni.samplerate / (1000.0 * uni.buflen)));
295 setTXAGCLimit(int n, char **p) {
296 REAL limit = atof(p[0]);
297 tx.agc.gen->AgcLimit = 0.001 * limit;
302 setTXSpeechCompression(int n, char **p) {
303 tx.spr.flag = atoi(p[0]);
308 setTXSpeechCompressionGain(int n, char **p) {
309 tx.spr.gen->MaxGain = dB2lin(atof(p[0]));
313 //============================================================
317 REAL fix = tx.filt.ovsv->fftlen * f / uni.samplerate;
318 return (int) (fix + 0.5);
321 //------------------------------------------------------------
324 apply_txeq_band(REAL lof, REAL dB, REAL hif) {
328 l = tx.filt.ovsv->fftlen;
330 COMPLEX *src = tx.filt.save,
331 *trg = tx.filt.ovsv->zfvec;
332 for (i = lox; i < hix; i++) {
333 trg[i] = Cscl(src[i], g);
336 trg[j] = Cscl(src[j], g);
342 // 0 dB1 75 dB2 150 dB3 300 dB4 600 dB5 1200 dB6 2000 dB7 2800 dB8 3600
343 // approximates W2IHY bandcenters.
344 // no args, revert to no EQ.
346 setTXEQ(int n, char **p) {
349 memcpy((char *) tx.filt.ovsv->zfvec,
350 (char *) tx.filt.save,
351 tx.filt.ovsv->fftlen * sizeof(COMPLEX));
355 REAL lof = atof(p[0]);
356 for (i = 0; i < n - 2; i += 2) {
357 REAL dB = atof(p[i + 1]),
358 hif = atof(p[i + 2]);
359 if (lof < 0.0 || hif <= lof) return -1;
360 apply_txeq_band(lof, dB, hif);
367 //------------------------------------------------------------
370 apply_rxeq_band(REAL lof, REAL dB, REAL hif) {
374 l = rx.filt.ovsv->fftlen;
376 COMPLEX *src = rx.filt.save,
377 *trg = rx.filt.ovsv->zfvec;
378 for (i = lox; i < hix; i++) {
379 trg[i] = Cscl(src[i], g);
382 trg[j] = Cscl(src[j], g);
388 setRXEQ(int n, char **p) {
391 memcpy((char *) rx.filt.ovsv->zfvec,
392 (char *) rx.filt.save,
393 rx.filt.ovsv->fftlen * sizeof(COMPLEX));
397 REAL lof = atof(p[0]);
398 for (i = 0; i < n - 2; i += 2) {
399 REAL dB = atof(p[i + 1]),
400 hif = atof(p[i + 2]);
401 if (lof < 0.0 || hif <= lof) return -1;
402 apply_rxeq_band(lof, dB, hif);
409 //============================================================
411 setRXAGC(int n, char **p) {
412 int setit = atoi(p[0]);
415 rx.agc.gen->AgcMode = agcOFF;
419 rx.agc.gen->AgcMode = agcSLOW;
420 rx.agc.gen->Hang = 10;
424 rx.agc.gen->AgcMode = agcMED;
425 rx.agc.gen->Hang = 6;
429 rx.agc.gen->AgcMode = agcFAST;
430 rx.agc.gen->Hang = 3;
434 rx.agc.gen->AgcMode = agcLONG;
435 rx.agc.gen->Hang = 23;
443 setANFvals(int n, char **p) {
444 int taps = atoi(p[0]),
446 REAL gain = atof(p[2]),
448 rx.anf.gen->adaptive_filter_size = taps;
449 rx.anf.gen->delay = delay;
450 rx.anf.gen->adaptation_rate = gain;
451 rx.anf.gen->leakage = leak;
456 setNRvals(int n, char **p) {
457 int taps = atoi(p[0]),
459 REAL gain = atof(p[2]),
461 rx.anr.gen->adaptive_filter_size = taps;
462 rx.anr.gen->delay = delay;
463 rx.anr.gen->adaptation_rate = gain;
464 rx.anr.gen->leakage = leak;
469 setcorrectIQ(int n, char **p) {
470 int phaseadjustment = atoi(p[0]),
471 gainadjustment = atoi(p[1]);
472 rx.iqfix->phase = 0.001 * (REAL) phaseadjustment;
473 rx.iqfix->gain = 1.0+ 0.001 * (REAL) gainadjustment;
478 setcorrectIQphase(int n, char **p) {
479 int phaseadjustment = atoi(p[0]);
480 rx.iqfix->phase = 0.001 * (REAL) phaseadjustment;
485 setcorrectIQgain(int n, char **p) {
486 int gainadjustment = atoi(p[0]);
487 rx.iqfix->gain = 1.0 + 0.001 * (REAL) gainadjustment;
492 setSquelch(int n, char **p) {
493 rx.squelch.thresh = -atof(p[0]);
498 setMeterOffset(int n, char **p) {
499 rx.squelch.offset.meter = atof(p[0]);
504 setATTOffset(int n, char **p) {
505 rx.squelch.offset.att = atof(p[0]);
510 setGainOffset(int n, char **p) {
511 rx.squelch.offset.gain = atof(p[0]);
516 setSquelchSt(int n, char **p) {
517 rx.squelch.flag = atoi(p[0]);
522 setTRX(int n, char **p) {
523 uni.mode.trx = atoi(p[0]);
528 setRunState(int n, char **p) {
529 RUNMODE rs = (RUNMODE) atoi(p[0]);
535 setSpotToneVals(int n, char **p) {
536 REAL gain = atof(p[0]),
540 setSpotToneGenVals(rx.spot.gen, gain, freq, rise, fall);
545 setSpotTone(int n, char **p) {
547 SpotToneOn(rx.spot.gen);
550 SpotToneOff(rx.spot.gen);
555 setRXPreScl(int n, char **p) {
556 rx.scl.pre.flag = atoi(p[0]);
561 setRXPreSclVal(int n, char **p) {
562 rx.scl.pre.val = dB2lin(atof(p[0]));
567 setTXPreScl(int n, char **p) {
568 tx.scl.pre.flag = atoi(p[0]);
573 setTXPreSclVal(int n, char **p) {
574 tx.scl.pre.val = dB2lin(atof(p[0]));
579 setRXPostScl(int n, char **p) {
580 rx.scl.post.flag = atoi(p[0]);
585 setRXPostSclVal(int n, char **p) {
586 rx.scl.post.val = dB2lin(atof(p[0]));
591 setTXPostScl(int n, char **p) {
592 tx.scl.post.flag = atoi(p[0]);
597 setTXPostSclVal(int n, char **p) {
598 tx.scl.post.val = dB2lin(atof(p[0]));
603 setFinished(int n, char **p) {
609 setPWSmode(int n,char **p) {
610 int setit = atoi(p[0]);
611 uni.powerspectrum.pws->Mode = setit;
616 setPWSSubmode(int n,char **p) {
617 int setit = atoi(p[0]);
618 uni.powerspectrum.pws->SubMode = setit;
622 // next-trx-mode [nbufs-to-zap]
624 setSWCH(int n, char **p) {
625 top.swch.trx.next = atoi(p[0]);
626 if (n > 1) top.swch.bfct.want = atoi(p[1]);
627 else top.swch.bfct.want = 0;
628 top.swch.bfct.have = 0;
629 top.swch.run.last = top.state;
630 top.state = RUN_SWCH;
634 //========================================================================
638 CTE update_cmds[] = {
640 {"setANFvals", setANFvals},
641 {"setATTOffset", setATTOffset},
643 {"setcorrectIQ", setcorrectIQ},
644 {"setcorrectIQgain", setcorrectIQgain},
645 {"setcorrectIQphase", setcorrectIQphase},
646 {"setFilter", setFilter},
647 {"setfixedAGC", setfixedAGC},
648 {"setGainOffset", setGainOffset},
649 {"setMeterOffset", setMeterOffset},
650 {"setMode", setMode},
652 {"setNBvals", setNBvals},
654 {"setNRvals", setNRvals},
656 {"setRXAGC", setRXAGC},
657 {"setRunState", setRunState},
658 {"setSampleRate", setSampleRate},
659 {"setSquelch", setSquelch},
660 {"setSquelchSt", setSquelchSt},
661 {"setTXAGC", setTXAGC},
662 {"setTXAGCCompression", setTXAGCCompression},
663 {"setTXAGCFFCompression",setTXAGCFFCompression},
664 {"setTXAGCHang", setTXAGCHang},
665 {"setTXAGCLimit", setTXAGCLimit},
666 {"setTXSpeechCompression", setTXSpeechCompression},
667 {"setTXSpeechCompressionGain", setTXSpeechCompressionGain},
668 {"setRXEQ", setRXEQ},
669 {"setTXEQ", setTXEQ},
671 {"setRXPreScl", setRXPreScl},
672 {"setRXPreSclVal", setRXPreSclVal},
673 {"setTXPreScl", setTXPreScl},
674 {"setTXPreSclVal", setTXPreSclVal},
675 {"setRXPostScl", setRXPostScl},
676 {"setRXPostSclVal", setRXPostSclVal},
677 {"setTXPostScl", setTXPostScl},
678 {"setTXPostSclVal", setTXPostSclVal},
679 {"setFinished", setFinished},
680 {"setSWCH", setSWCH},
681 {"setSpotToneVals", setSpotToneVals},
682 {"setSpotTone", setSpotTone},
683 {"setPWSmode", setPWSmode},
684 {"setPWSSubmode",setPWSSubmode},
685 {"setSDROM", setSDROM},
686 {"setSDROMvals",setSDROMvals},
690 //........................................................................
692 int do_update(char *str) {
694 SPLIT splt = &uni.update.splt;
698 if (NF(splt) < 1) return -1;
700 Thunk thk = Thunk_lookup(update_cmds, F(splt, 0));
702 fprintf(stderr,"-1\n");
706 WaitForSingleObject(top.sync.upd.sem,INFINITE);
707 val = (*thk)(NF(splt) - 1, Fptr(splt, 1));
708 ReleaseSemaphore(top.sync.upd.sem,1L,NULL);
714 BOOLEAN newupdates() {
715 WaitForSingleObject(top.sync.upd2.sem,INFINITE);
720 sendcommand(char *str) {
721 putChan_nowait(uni.update.chan.c,str,strlen(str)+1);;
722 ReleaseSemaphore(top.sync.upd2.sem,1L,NULL);
728 changeMode(SDRMODE mode) {
732 sprintf(str,"setMode %d",LSB);
736 sprintf(str,"setMode %d",USB);
740 sprintf(str,"setMode %d",DSB);
744 sprintf(str,"setMode %d",CWL);
748 sprintf(str,"setMode %d",CWU);
752 sprintf(str,"setMode %d",AM);
756 sprintf(str,"setMode %d",PSK);
760 sprintf(str,"setMode %d",SPEC);
764 sprintf(str,"setMode %d",RTTY);
768 sprintf(str,"setMode %d",SAM);
772 sprintf(str,"setMode %d",DRM);
782 changeOsc(REAL newfreq){
784 if (fabs(newfreq) >= 0.5* uni.samplerate) return -1;
785 sprintf(str,"setOsc %lf RX",newfreq);
791 changeTXOsc(REAL newfreq){
793 if (fabs(newfreq) >= 0.5* uni.samplerate) return -1;
794 sprintf(str,"setOsc %lf TX",newfreq);
800 changeSampleRate(REAL newSampleRate) {
802 sprintf(str,"setSampleRate %9.0lf",newSampleRate);
807 DttSP_EXP void changeNR(int setit) {
809 sprintf(str,"setNR %d",setit);
813 DttSP_EXP void changeANF(int setit) {
815 sprintf(str,"setANF %d",setit);
819 DttSP_EXP void changeNB(int setit) {
821 sprintf(str,"setNB %d",setit);
825 DttSP_EXP void changeNBvals(REAL threshold) {
827 sprintf(str,"setNBvals %lf",threshold);
832 DttSP_EXP void changeBIN(int setit) {
834 sprintf(str,"setBIN %d",setit);
838 DttSP_EXP void changeAGC(AGCMODE setit) {
842 sprintf(str,"setRXAGC %d",agcOFF);
845 sprintf(str,"setRXAGC %d",agcLONG);
848 sprintf(str,"setRXAGC %d",agcSLOW);
851 sprintf(str,"setRXAGC %d",agcMED);
854 sprintf(str,"setRXAGC %d",agcFAST);
860 DttSP_EXP void changeANFvals(int taps, int delay, REAL gain, REAL leak) {
862 sprintf(str,"setANFvals %3d %3d %9.7lf %9.7lf",taps,delay,gain,leak);
866 DttSP_EXP void changeNRvals(int taps, int delay, REAL gain, REAL leak) {
868 sprintf(str,"setNRvals %3d %3d %9.7lf %9.7lf",taps,delay,gain,leak);
872 DttSP_EXP void setcorrectIQcmd(int phaseadjustment,int gainadjustment) {
874 sprintf(str,"setcorrectIQ %d %d",phaseadjustment,gainadjustment);
878 DttSP_EXP void changecorrectIQphase(int phaseadjustment){
880 sprintf(str,"setcorrectIQphase %d",phaseadjustment);
884 DttSP_EXP void changecorrectIQgain(int gainadjustment){
886 sprintf(str,"setcorrectIQgain %d",gainadjustment);
891 changeFilter(REAL low_frequency,REAL high_frequency,int ncoef, TRXMODE trx) {
893 if (trx == RX) sprintf(str,"setFilter %6.0lf %6.0lf RX",low_frequency,high_frequency);
894 else sprintf(str,"setFilter %6.0lf %6.0lf TX",low_frequency,high_frequency);
900 changePWSmode(PWSMODE setit) {
904 sprintf(str,"setPWSmode %d",PREFILTER);
907 sprintf(str,"setPWSmode %d",POSTFILTER);
910 sprintf(str,"setPWSmode %d",AUDIO);
919 changePWSsubmode(PWSSUBMODE setit) {
923 sprintf(str,"setPWSSubmode %d",SPECTRUM);
926 sprintf(str,"setPWSSubmode %d",PHASE);
929 sprintf(str,"setPWSSubmode %d",SCOPE);
932 sprintf(str,"setPWSSubmode %d",PHASE);
935 sprintf(str,"setPWSSubmode %d",WATERFALL);
938 sprintf(str,"setPWSSubmode %d",HISTOGRAM);
947 changeWindow(Windowtype Windowset){
951 oldsetTXEQ(int *txeq) {
954 "setTXEQ 0 %d 450 %d 800 %d 1150 %d 1450 %d 1800 %d 2150 %d 2450 %d 2800 %d 3600",
968 changeTXAGCCompression(double txc) {
970 sprintf(str,"setTXAGCCompression %lf",txc);
975 changeTXAGCFFCompression(double txc) {
977 sprintf(str,"setTXAGCFFCompression %lf",txc);
981 DttSP_EXP void oldsetGainOffset(float val) {
983 sprintf(str,"setGainOffset %f",val);
987 DttSP_EXP void setTXScale(REAL scale) {
989 sprintf(str,"setTXPreScl 1 ");
992 sprintf(str,"setTXPreSclVal %lf",20.0*log10(scale));
996 DttSP_EXP void oldsetATTOffset(float val){
998 sprintf(str,"setATTOffset %f",val);
1002 DttSP_EXP setRXScale(float val) {
1004 sprintf(str,"setRXPostScl 1");
1007 sprintf(str,"setRXPostSclVal %f",val);
1011 DttSP_EXP oldsetMeterOffset(float val){
1013 sprintf(str,"setMeterOffset %f",val);
1017 DttSP_EXP changeSquelch(float setit) {
1019 sprintf(str,"setSquelch %f",setit);
1023 DttSP_EXP changeSquelchSt(BOOLEAN setit) {
1025 sprintf(str,"setSquelch %d",setit);
1029 DttSP_EXP void changeSDROM(BOOLEAN setit) {
1031 sprintf(str,"setSDROM %d",setit);
1035 DttSP_EXP void changeSDROMvals(REAL threshold) {
1037 sprintf(str,"setSDROMvals %lf",threshold);
1042 #endif // END PROCESSVERS
1048 changeMode(SDRMODE mode) {
1062 WaitForSingleObject(top.sync.upd.sem,INFINITE);
1063 rx.mode = tx.mode = uni.mode.sdr = mode;
1064 if (mode == SAM) rx.am.gen->mode = SAMdet;
1065 if (mode == AM) rx.am.gen->mode = AMdet;
1066 ReleaseSemaphore(top.sync.upd.sem,1L,NULL);
1075 changeOsc(REAL newfreq){
1076 if (fabs(newfreq) >= 0.5* uni.samplerate) return -1;
1077 WaitForSingleObject(top.sync.upd.sem,INFINITE);
1078 rx.osc.gen->Frequency = rx.osc.freq = 2.0*M_PI*newfreq/uni.samplerate;
1079 ReleaseSemaphore(top.sync.upd.sem,1L,NULL);
1084 changeTXOsc(REAL newfreq){
1085 if (fabs(newfreq) >= 0.5* uni.samplerate) return -1;
1086 WaitForSingleObject(top.sync.upd.sem,INFINITE);
1087 tx.osc.gen->Frequency = tx.osc.freq = 2.0*M_PI*newfreq/uni.samplerate;
1088 ReleaseSemaphore(top.sync.upd.sem,1L,NULL);
1093 changeSampleRate(REAL newSampleRate) {
1094 WaitForSingleObject(top.sync.upd.sem,INFINITE);
1095 uni.samplerate = newSampleRate;
1096 ReleaseSemaphore(top.sync.upd.sem,1L,NULL);
1100 DttSP_EXP void changeNR(BOOLEAN setit) {
1101 WaitForSingleObject(top.sync.upd.sem,INFINITE);
1102 rx.anr.flag = setit;
1103 ReleaseSemaphore(top.sync.upd.sem,1L,NULL);
1106 DttSP_EXP void changeANF(BOOLEAN setit) {
1107 WaitForSingleObject(top.sync.upd.sem,INFINITE);
1108 rx.anf.flag = setit;
1109 ReleaseSemaphore(top.sync.upd.sem,1L,NULL);
1112 DttSP_EXP void changeNB(BOOLEAN setit) {
1113 WaitForSingleObject(top.sync.upd.sem,INFINITE);
1115 ReleaseSemaphore(top.sync.upd.sem,1L,NULL);
1118 DttSP_EXP void changeNBvals(REAL threshold) {
1119 WaitForSingleObject(top.sync.upd.sem,INFINITE);
1120 rx.nb.gen->threshold = rx.nb.thresh = threshold;
1121 ReleaseSemaphore(top.sync.upd.sem,1L,NULL);
1124 DttSP_EXP void changeSDROM(BOOLEAN setit) {
1125 WaitForSingleObject(top.sync.upd.sem,INFINITE);
1126 rx.nb_sdrom.flag = setit;
1127 ReleaseSemaphore(top.sync.upd.sem,1L,NULL);
1130 DttSP_EXP void changeSDROMvals(REAL threshold) {
1131 WaitForSingleObject(top.sync.upd.sem,INFINITE);
1132 rx.nb_sdrom.gen->threshold = rx.nb_sdrom.thresh = threshold;
1133 ReleaseSemaphore(top.sync.upd.sem,1L,NULL);
1137 DttSP_EXP void changeBIN(BOOLEAN setit) {
1138 WaitForSingleObject(top.sync.upd.sem,INFINITE);
1140 ReleaseSemaphore(top.sync.upd.sem,1L,NULL);
1143 DttSP_EXP void changeAGC(AGCMODE setit) {
1146 WaitForSingleObject(top.sync.upd.sem,INFINITE);
1147 rx.agc.gen->AgcMode = setit;
1148 ReleaseSemaphore(top.sync.upd.sem,1L,NULL);
1151 WaitForSingleObject(top.sync.upd.sem,INFINITE);
1152 rx.agc.gen->AgcMode = setit;
1153 rx.agc.gen->Hang = 23;
1154 ReleaseSemaphore(top.sync.upd.sem,1L,NULL);
1157 WaitForSingleObject(top.sync.upd.sem,INFINITE);
1158 rx.agc.gen->AgcMode = setit;
1159 rx.agc.gen->Hang = 7;
1160 ReleaseSemaphore(top.sync.upd.sem,1L,NULL);
1163 WaitForSingleObject(top.sync.upd.sem,INFINITE);
1164 rx.agc.gen->AgcMode = setit;
1165 rx.agc.gen->Hang = 4;
1166 ReleaseSemaphore(top.sync.upd.sem,1L,NULL);
1169 WaitForSingleObject(top.sync.upd.sem,INFINITE);
1170 rx.agc.gen->AgcMode = setit;
1171 rx.agc.gen->Hang = 2;
1172 ReleaseSemaphore(top.sync.upd.sem,1L,NULL);
1179 DttSP_EXP void changefixedAGC(REAL fixed_agc) {
1180 WaitForSingleObject(top.sync.upd.sem,INFINITE);
1181 rx.agc.gen->AgcFixedGain = dB2lin(fixed_agc);
1182 ReleaseSemaphore(top.sync.upd.sem,1L,NULL);
1185 DttSP_EXP void changemaxAGC(REAL max_agc) {
1186 WaitForSingleObject(top.sync.upd.sem,INFINITE);
1187 rx.agc.gen->MaxGain = dB2lin(max_agc);
1188 ReleaseSemaphore(top.sync.upd.sem,1L,NULL);
1191 DttSP_EXP void changeRXAGCAttackTimeScale(int limit) {
1192 WaitForSingleObject(top.sync.upd.sem,INFINITE);
1193 rx.agc.gen->AgcAttackTimeScale = limit;
1194 ReleaseSemaphore(top.sync.upd.sem,1L,NULL);
1198 DttSP_EXP void changeRXAGCHang(int limit) {
1199 WaitForSingleObject(top.sync.upd.sem,INFINITE);
1200 rx.agc.gen->Hang = limit;
1201 ReleaseSemaphore(top.sync.upd.sem,1L,NULL);
1205 DttSP_EXP void changeRXAGCLimit(int limit){
1206 WaitForSingleObject(top.sync.upd.sem,INFINITE);
1207 rx.agc.gen->AgcLimit = 0.001 * (double)limit;
1208 ReleaseSemaphore(top.sync.upd.sem,1L,NULL);
1211 DttSP_EXP void changeANFvals(int taps, int delay, REAL gain, REAL leak) {
1212 WaitForSingleObject(top.sync.upd.sem,INFINITE);
1213 rx.anf.gen->adaptation_rate = gain;
1214 rx.anf.gen->adaptive_filter_size = taps;
1215 rx.anf.gen->delay = delay;
1216 rx.anf.gen->leakage = leak;
1217 ReleaseSemaphore(top.sync.upd.sem,1L,NULL);
1220 DttSP_EXP void changeNRvals(int taps, int delay, REAL gain, REAL leak) {
1221 WaitForSingleObject(top.sync.upd.sem,INFINITE);
1222 rx.anr.gen->adaptation_rate = gain;
1223 rx.anr.gen->adaptive_filter_size = taps;
1224 rx.anr.gen->delay = delay;
1225 rx.anr.gen->leakage = leak;
1226 ReleaseSemaphore(top.sync.upd.sem,1L,NULL);
1230 setcorrectIQcmd(int phaseadjustment,int gainadjustment) {
1231 WaitForSingleObject(top.sync.upd.sem,INFINITE);
1232 rx.iqfix->phase = 0.001 * (REAL) phaseadjustment;
1233 rx.iqfix->gain = 1.0 + 0.001 * (REAL) gainadjustment;
1234 ReleaseSemaphore(top.sync.upd.sem,1L,NULL);
1238 changecorrectIQphase(int phaseadjustment) {
1239 WaitForSingleObject(top.sync.upd.sem,INFINITE);
1240 rx.iqfix->phase = 0.001 * (REAL) phaseadjustment;
1241 ReleaseSemaphore(top.sync.upd.sem,1L,NULL);
1245 changecorrectIQgain(int gainadjustment) {
1246 WaitForSingleObject(top.sync.upd.sem,INFINITE);
1247 rx.iqfix->gaina = 1.0 + 0.001 * (REAL) gainadjustment;
1248 ReleaseSemaphore(top.sync.upd.sem,1L,NULL);
1252 changeFilter(REAL low_frequency,REAL high_frequency,int ncoef, TRXMODE trx) {
1253 int i, fftlen = 2 * uni.buflen;
1256 ncoef = uni.buflen + 1;
1258 if (fabs(low_frequency) >= 0.5 * uni.samplerate) return -1;
1259 if (fabs(high_frequency) >= 0.5 * uni.samplerate) return -2;
1260 if ((low_frequency + 10) >= high_frequency) return -3;
1261 WaitForSingleObject(top.sync.upd.sem,INFINITE);
1263 delFIR_COMPLEX(rx.filt.coef);
1265 rx.filt.coef = newFIR_Bandpass_COMPLEX(low_frequency,
1270 zcvec = newvec_COMPLEX(fftlen, "filter z vec in setFilter");
1271 ptmp = fftw_create_plan(fftlen, FFTW_FORWARD, FFTW_OUT_OF_PLACE);
1273 for (i = 0; i < ncoef; i++) zcvec[i] = rx.filt.coef->coef[i];
1275 for (i = 0; i < ncoef; i++) zcvec[fftlen - ncoef + i] = rx.filt.coef->coef[i];
1277 fftw_one(ptmp, (fftw_complex *) zcvec, (fftw_complex *) rx.filt.ovsv->zfvec);
1278 fftw_destroy_plan(ptmp);
1279 delvec_COMPLEX(zcvec);
1280 memcpy((char *) rx.filt.save,
1281 (char *) rx.filt.ovsv->zfvec,
1282 rx.filt.ovsv->fftlen * sizeof(COMPLEX));
1284 delFIR_COMPLEX(tx.filt.coef);
1286 tx.filt.coef = newFIR_Bandpass_COMPLEX(low_frequency,
1291 zcvec = newvec_COMPLEX(fftlen, "filter z vec in setFilter");
1292 ptmp = fftw_create_plan(fftlen, FFTW_FORWARD, FFTW_OUT_OF_PLACE);
1294 for (i = 0; i < ncoef; i++) zcvec[i] = tx.filt.coef->coef[i];
1296 for (i = 0; i < ncoef; i++) zcvec[fftlen - ncoef + i] = tx.filt.coef->coef[i];
1298 fftw_one(ptmp, (fftw_complex *) zcvec, (fftw_complex *) tx.filt.ovsv->zfvec);
1299 fftw_destroy_plan(ptmp);
1300 delvec_COMPLEX(zcvec);
1301 memcpy((char *) tx.filt.save,
1302 (char *) tx.filt.ovsv->zfvec,
1303 tx.filt.ovsv->fftlen * sizeof(COMPLEX));
1306 ReleaseSemaphore(top.sync.upd.sem,1L,NULL);
1311 changePWSmode(PWSMODE setit) {
1312 WaitForSingleObject(top.sync.upd.sem,INFINITE);
1313 uni.powerspectrum.pws->Mode = setit;
1314 ReleaseSemaphore(top.sync.upd.sem,1L,NULL);
1319 changePWSsubmode(PWSSUBMODE setit) {
1320 WaitForSingleObject(top.sync.upd.sem,INFINITE);
1321 uni.powerspectrum.pws->SubMode = setit;
1322 ReleaseSemaphore(top.sync.upd.sem,1L,NULL);
1326 changeWindow(Windowtype Windowset){
1330 oldsetTXEQ(int *txeq) {
1331 WaitForSingleObject(top.sync.upd.sem,INFINITE);
1332 apply_txeq_band(0.0 ,txeq[ 0],120.0);
1333 apply_txeq_band(120.0 ,txeq[ 1],230.0);
1334 apply_txeq_band(230.0 ,txeq[ 2],450.0);
1335 apply_txeq_band(450.0 ,txeq[ 3],800.0);
1336 apply_txeq_band(800.0 ,txeq[ 4],1150.0);
1337 apply_txeq_band(1150.0,txeq[ 5],1450.0);
1338 apply_txeq_band(1450.0,txeq[ 6],1800.0);
1339 apply_txeq_band(1800.0,txeq[ 7],2150.0);
1340 apply_txeq_band(2150.0,txeq[ 8],2450.0);
1341 apply_txeq_band(2450.0,txeq[ 9],2800.0);
1342 apply_txeq_band(2800.0,txeq[10],3250.0);
1343 apply_txeq_band(3250.0,txeq[11],6000.0);
1344 ReleaseSemaphore(top.sync.upd.sem,1L,NULL);
1348 changeTXAGCCompression(double txc) {
1349 WaitForSingleObject(top.sync.upd.sem,INFINITE);
1350 tx.agc.gen->MaxGain = pow(10.0 , txc * 0.05);
1351 ReleaseSemaphore(top.sync.upd.sem,1L,NULL);
1355 changeTXAGCFF(BOOLEAN setit) {
1356 WaitForSingleObject(top.sync.upd.sem,INFINITE);
1357 tx.spr.flag = setit;
1358 ReleaseSemaphore(top.sync.upd.sem,1L,NULL);
1362 changeTXAGCLimit(int setit) {
1363 WaitForSingleObject(top.sync.upd.sem,INFINITE);
1364 tx.agc.gen->AgcLimit = 0.001*(REAL)setit;
1365 ReleaseSemaphore(top.sync.upd.sem,1L,NULL);
1369 changeTXAGCHang(int hang) {
1370 WaitForSingleObject(top.sync.upd.sem,INFINITE);
1371 tx.agc.gen->Hang = (int)max(1,min(23,((REAL)hang) * uni.samplerate /(1000.0*uni.buflen)));
1372 ReleaseSemaphore(top.sync.upd.sem,1L,NULL);
1376 changeTXAGCFFCompression(REAL txc) {
1377 WaitForSingleObject(top.sync.upd.sem,INFINITE);
1378 tx.spr.gen->MaxGain = pow(10.0 , txc * 0.05);
1379 ReleaseSemaphore(top.sync.upd.sem,1L,NULL);
1382 DttSP_EXP void setTXScale(REAL scale) {
1383 WaitForSingleObject(top.sync.upd.sem,INFINITE);
1384 tx.scl.post.flag = TRUE;
1385 tx.scl.post.val = scale;
1386 ReleaseSemaphore(top.sync.upd.sem,1L,NULL);
1389 DttSP_EXP void oldsetGainOffset(float val) {
1390 WaitForSingleObject(top.sync.upd.sem,INFINITE);
1391 rx.squelch.offset.gain = (REAL)val;
1392 ReleaseSemaphore(top.sync.upd.sem,1L,NULL);
1395 DttSP_EXP void oldsetATTOffset(float val){
1396 WaitForSingleObject(top.sync.upd.sem,INFINITE);
1397 rx.squelch.offset.att = (REAL)val;
1398 ReleaseSemaphore(top.sync.upd.sem,1L,NULL);
1401 DttSP_EXP oldsetMeterOffset(float val){
1402 WaitForSingleObject(top.sync.upd.sem,INFINITE);
1403 rx.squelch.offset.meter = (REAL)val;
1404 ReleaseSemaphore(top.sync.upd.sem,1L,NULL);
1408 DttSP_EXP setRXScale(REAL val) {
1409 WaitForSingleObject(top.sync.upd.sem,INFINITE);
1410 rx.scl.post.flag = TRUE;
1411 rx.scl.post.val = val;
1412 ReleaseSemaphore(top.sync.upd.sem,1L,NULL);
1415 DttSP_EXP changeSquelch(int setit) {
1416 WaitForSingleObject(top.sync.upd.sem,INFINITE);
1417 rx.squelch.thresh = -(REAL)setit;
1418 ReleaseSemaphore(top.sync.upd.sem,1L,NULL);
1421 DttSP_EXP changeSquelchSt(BOOLEAN setit) {
1422 WaitForSingleObject(top.sync.upd.sem,INFINITE);
1423 rx.squelch.flag = setit;
1424 ReleaseSemaphore(top.sync.upd.sem,1L,NULL);
1428 DttSP_EXP void oldsetTRX(TRXMODE setit) {
1429 WaitForSingleObject(top.sync.upd.sem,INFINITE);
1430 /* top.swch.trx.next = setit;
1431 top.swch.bfct.want = 2;
1432 top.swch.bfct.have = 0;
1433 top.swch.run.last = top.state;
1434 top.state = RUN_SWCH; */
1435 uni.mode.trx = setit;
1436 ReleaseSemaphore(top.sync.upd.sem,1L,NULL);
1438 #endif // END DLLVERS