-
Notifications
You must be signed in to change notification settings - Fork 0
/
buf.c
1555 lines (1542 loc) · 60.1 KB
/
buf.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
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
// Copyright (c) <2012> <Leif Asbrink>
//
// Permission is hereby granted, free of charge, to any person
// obtaining a copy of this software and associated documentation
// files (the "Software"), to deal in the Software without restriction,
// including without limitation the rights to use, copy, modify,
// merge, publish, distribute, sublicense, and/or sell copies of
// the Software, and to permit persons to whom the Software is
// furnished to do so, subject to the following conditions:
//
// The above copyright notice and this permission notice shall be
// included in all copies or substantial portions of the Software.
//
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
// EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES
// OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
// NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT
// HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
// WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
// FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE
// OR OTHER DEALINGS IN THE SOFTWARE.
#include <string.h>
#include "globdef.h"
#include "uidef.h"
#include "fft1def.h"
#include "fft2def.h"
#include "fft3def.h"
#include "screendef.h"
#include "seldef.h"
#include "blnkdef.h"
#include "sigdef.h"
#include "hwaredef.h"
#define TIMF3_OSCILLOSCOPE_RATE 2
void fft1_block_timing(void)
{
fft1_interleave_ratio=(float)(fft1_interleave_points)/fft1_size;
fft1_new_points=fft1_size-fft1_interleave_points;
timf1_sampling_speed=ui.rx_ad_speed;
if( (ui.rx_input_mode&IQ_DATA) == 0) {
timf1_sampling_speed*=0.5;
}
fft1_blocktime=(float)(fft1_new_points)/timf1_sampling_speed;
}
void prepare_mixer(MIXER_VARIABLES *m, int nn)
{
unsigned int i, j, k;
float t1;
if( genparm[nn]!= 0 && (genparm[nn]!= 2 || rx_mode == MODE_TXTEST)) {
make_window(3,m[0].size, genparm[nn], m[0].window);
}
init_fft(0,m[0].n, m[0].size, m[0].table, m[0].permute);
// If we use a window for mix1 we need crossover functions, sin and cos
// squared. Will not be used in case the window itself is sin squared.
// Find out how long to make the crossover region.
// Stop it when the window has fallen by 20dB compared to the
// start of the crossover region.
m[0].crossover_points=0;
if( genparm[nn] != 0 && genparm[nn] != 2 ) {
if(genparm[nn] == 9) {
m[0].crossover_points=m[0].size/8;
} else {
if(genparm[nn] == 8) {
m[0].crossover_points=m[0].size/16;
} else {
i=m[0].interleave_points/2;
t1=m[0].window[i];
while(m[0].window[i]<30*t1 && i>0) {
i--;
m[0].crossover_points++;
}
if(m[0].crossover_points > 0.75*m[0].new_points)
m[0].crossover_points=0.75*m[0].new_points;
if(m[0].crossover_points > m[0].interleave_points/2)
m[0].crossover_points=m[0].interleave_points/2;
}
}
t1=0.25*PI_L/m[0].crossover_points;
j=(m[0].size-m[0].new_points)/2;
k=j;
k+=m[0].crossover_points/2;
j-=m[0].crossover_points/2;
for(i=0; i<m[0].crossover_points; i++) {
m[0].cos2win[i]=m[0].window[k]*pow(cos(t1),2.0);
m[0].sin2win[i]=m[0].window[j]*pow(sin(t1),2.0);
k--;
j++;
t1+=0.5*PI_L/m[0].crossover_points;
}
}
}
float make_interleave_ratio(int nn)
{
// Make interleave_ratio the distance between the points where the
// window function is 0.5.
if(genparm[nn] != 0) {
if(genparm[nn] == 9) {
return 0.625;
} else {
if(genparm[nn] == 8) {
return 0.8;
} else {
return 2*asin(pow(0.5,1.0/genparm[nn]))/PI_L;
}
}
}
return 0;
}
void get_wideband_sizes(void)
{
float t1;
int i, j, m, n, k, bwfac;
int reduced_max_dma;
if(fft1_handle != NULL) {
lirerr(1002);
return;
}
fft1mode=(ui.rx_input_mode&(TWO_CHANNELS+IQ_DATA))/2;
// Before doing anything else, set output format information
rx_daout_bytes=1+(genparm[OUTPUT_MODE]&1); //bit 0
rx_daout_channels=1+((genparm[OUTPUT_MODE]>>1)&1); //bit 1
if(rx_daout_channels < ui.rx_min_da_channels) {
rx_daout_channels = ui.rx_min_da_channels;
}
// Tell assembly routines how many channels we have (so we make no
// mistake when changing struct ui.
rx_channels=ui.rx_rf_channels;
twice_rxchan=2*ui.rx_rf_channels;
// *********************************************************************
// First find size of first fft.
// In case a window was selected we need more points for the
// same bandwidth. Get the interleave ratio.
fft1_interleave_ratio=make_interleave_ratio(FIRST_FFT_SINPOW);
{
if(genparm[FIRST_FFT_BANDWIDTH]==0) {
bwfac=65536;
} else {
bwfac=(0.3536*ui.rx_ad_speed)/
((1-fft1_interleave_ratio)*genparm[FIRST_FFT_BANDWIDTH]);
}
j=bwfac;
if( (ui.rx_input_mode&IQ_DATA) != 0)j*=2;
// j is the number of points we need for the whole transform to get the
// desired bandwidth multiplied by 1.414.
// Make j a power of two so the bandwidth will be in the range
// 0.707*desired < bw < 1.414*desired.
fft1_n=1;
i=j;
while(j != 0) {
j/=2;
fft1_n++;
}
// Never make the size below n=6 (=64)
// Note that i becomes small so we arrive at fft1_n=6
if(fft1_n < 7)fft1_n=7;
fft1_size=1<<fft1_n;
if( (float)(fft1_size)/i > 1.5) {
reduce_fft1_size:
;
fft1_size/=2;
fft1_n--;
}
}
if(fft1_n > 12) {
yieldflag_wdsp_fft1=TRUE;
} else {
yieldflag_wdsp_fft1=FALSE;
}
if(genparm[SECOND_FFT_ENABLE] == 0) {
if(ui.max_blocked_cpus > 0)yieldflag_wdsp_fft1=FALSE;
} else {
if(ui.max_blocked_cpus > 2)yieldflag_wdsp_fft1=FALSE;
}
// Each channel output is 2*float (re, im)
fft1_block=twice_rxchan*fft1_size;
fft1_muln=(fft_cntrl[FFT1_CURMODE].real2complex+1)
*fft_cntrl[FFT1_CURMODE].parall_fft;
fft1_mulblock=fft1_block*fft1_muln;
j=fft1_size*(fft_cntrl[FFT1_CURMODE].real2complex+1);
fft1_permute_size=j;
fft1_window_size=j;
{
fft1_costab_size=j/2;
if(fft_cntrl[FFT1_CURMODE].permute == 2) {
fft1_costab_size*=2;
fft1_permute_size*=2;
fft1_window_size+=16;
}
// To save cash we use short int for the unscramble table.
// Make sure the unscramble array is not too big.
if(fft1_permute_size > 0x10000)goto reduce_fft1_size;
if(genparm[FIRST_FFT_VERNR]==5 &&
fft1_permute_size > 0x8000)goto reduce_fft1_size;
if(genparm[FIRST_FFT_SINPOW] == 0)fft1_window_size=0;
}
fft1_blockbytes=fft1_block*sizeof(float);
// Each channel input is 16 bit or 32 bit.
snd[RXAD].framesize=2*ui.rx_ad_channels;
if( (ui.rx_input_mode&DWORD_INPUT) != 0) snd[RXAD].framesize*=2;
// Get number of points to overlap transforms so window function does
// not drop below 0.5.
// In this way all points contribute by approximately the same amount
// to the averaged power spectrum.
// We also need this to be able to use MMX for the back transform.
fft1_interleave_points=1+fft1_interleave_ratio*fft1_size;
fft1_interleave_points&=0xfffe;
fft1_bandwidth=0.5*ui.rx_ad_speed/((1-fft1_interleave_ratio)*fft1_size);
if( (ui.rx_input_mode&IQ_DATA) != 0)fft1_bandwidth*=2;
// *******************************************************
// Get the sizes for the second fft and the first mixer
// The first frequency mixer shifts the signal in timf1 or timf2 to
// the baseband.
// Rather tham multiplying with a sin/cos table of the selected frequency
// we use the corresponding fourier transforms from which a group of lines
// are selected, frequency shifted and back transformed.
new_mix1_n:
;
mix1.n=fft1_n-genparm[MIX1_BANDWIDTH_REDUCTION_N];
if(genparm[SECOND_FFT_ENABLE] == 0) {
fft2_size=0;
timf2pow_size=0;
// If we get signals from back transformation of fft1
// we use an interleave ratio that makes the interleave points
// go even up in mix1.size.
if(mix1.n < 3)mix1.n=3;
mix1.size=1<<mix1.n;
mix1.interleave_points=fft1_interleave_ratio*mix1.size;
mix1.interleave_points&=0xfffffffe;
fft1_interleave_points=mix1.interleave_points*(fft1_size/mix1.size);
fft1_block_timing();
fftx_blocktime=fft1_blocktime;
spur_freq_factor=(float)(fft1_new_points)/fft1_size;
timf3_sampling_speed=timf1_sampling_speed/fft1_size;
} else {
if(calibrate_flag == 0 && fft1_n > 15)goto reduce_fft1_size;
// Make the time constant for the blanker noise floor about 1 second.
// The first fft outputs data in blocks of fft1_new_points
fft1_block_timing();
j=(float)(ui.rx_ad_speed+fft1_new_points/2)/fft1_new_points;
if(j<1)j=1;
timf2_noise_floor_avgnum=j;
blanker_info_update_counter=0;
fft1_lowlevel_fraction=.75;
j/=8;
if(j<1)j=1;
blanker_info_update_interval=j;
timf2_oscilloscope_interval=timf2_noise_floor_avgnum/10;
if(timf2_oscilloscope_interval < 15)timf2_oscilloscope_interval=15;
timf2_oscilloscope_counter=0;
timf2_oscilloscope_maxpoint=0;
timf2_oscilloscope_maxval_uint=0;
timf2_oscilloscope_maxval_float=0;
fft2_interleave_ratio=make_interleave_ratio(SECOND_FFT_SINPOW);
j=1<<(genparm[SECOND_FFT_NINC]);
fft2_n=fft1_n;
fft2_sizeset:
;
fft2_size=1<<fft2_n;
if(fft2_n > 12 && ui.max_blocked_cpus == 0) {
yieldflag_fft2_fft2=TRUE;
} else {
yieldflag_fft2_fft2=FALSE;
}
fft2_bandwidth=0.5*ui.rx_ad_speed/((1-fft2_interleave_ratio)*fft2_size);
if( (ui.rx_input_mode&IQ_DATA) != 0)fft2_bandwidth*=2;
if(fft2_bandwidth*j < 1.5*fft1_bandwidth)goto fft2_size_x;
fft2_n++;
goto fft2_sizeset;
fft2_size_x:
;
fft2_interleave_points=1+fft2_interleave_ratio*fft2_size;
fft2_interleave_points&=0xfffe;
// Make timf2 hold 2 seconds of data
t1=2*timf1_sampling_speed;
// In case we are in the powtim function, fft2 is not
// in use although we use its arrays. Change accordingly:
if(lir_status==LIR_POWTIM) {
t1=timf1_sampling_speed*genparm[FFT1_STORAGE_TIME];
}
// or four fft2 transforms if that is more
if(t1 < 8.F*(float)fft2_size) t1 = 8.F*(float)fft2_size;
while(t1 < 2*screen_width*ui.rx_rf_channels)t1*=2;
if(t1*(float)(4*ui.rx_rf_channels*sizeof(float)) >= (float)0x8000000) {
timf2pow_size=0x2000000/(ui.rx_rf_channels*sizeof(float));
} else {
timf2pow_size=t1;
make_power_of_two(&timf2pow_size);
}
// There are 2 transforms (strong, weak) for each rx channel
timf2pow_mask=timf2pow_size-1;
timf2_size=4*ui.rx_rf_channels*timf2pow_size;
timf2_mask=timf2_size-1;
timf2_neg=timf2_mask-fft2_size;
timf2_input_block=(fft1_size-fft1_interleave_points)*4*ui.rx_rf_channels;
timf2_pa=0;
timf2_pb=0;
timf2_pc=0;
timf2_pn1=0;
timf2_pn2=0;
timf2_pt=0;
timf2p_fit=0;
timf2_px=0;
timf2_blockpower_size=2*genparm[BASEBAND_STORAGE_TIME]*
timf1_sampling_speed/(fft1_size-fft1_interleave_points);
make_power_of_two(&timf2_blockpower_size);
timf2_blockpower_mask=timf2_blockpower_size-1;
timf2_blockpower_pa=0;
timf2_blockpower_px=0;
// Set start noise floor 23dB above one bit amplitude
// and set channel noise = 1 so sum never becomes zero to avoid
// problems with log function.
timf2_noise_floor=200;
timf2_despiked_pwr[0]=timf2_noise_floor;
timf2_despiked_pwrinc[0]=1;
if(ui.rx_rf_channels == 2) {
timf2_despiked_pwr[1]=timf2_noise_floor;
timf2_despiked_pwrinc[1]=1;
timf2_noise_floor*=2;
}
timf2_fitted_pulses=0;
timf2_cleared_points=0;
timf2_blanker_points=0;
clever_blanker_rate=0;
stupid_blanker_rate=0;
mix1.n+=fft2_n-fft1_n;
if(mix1.n < 3)mix1.n=3;
mix1.size=1<<mix1.n;
if(mix1.n > 12) {
yieldflag_ndsp_mix1=TRUE;
} else {
yieldflag_ndsp_mix1=FALSE;
}
if(genparm[SECOND_FFT_ENABLE] == 0) {
if(ui.max_blocked_cpus > 1)yieldflag_ndsp_mix1=FALSE;
} else {
if(ui.max_blocked_cpus > 3)yieldflag_ndsp_mix1=FALSE;
}
mix1.interleave_points=fft2_interleave_ratio*mix1.size;
mix1.interleave_points&=0xfffffffe;
fft2_interleave_points=mix1.interleave_points*(fft2_size/mix1.size);
fft2_interleave_ratio=(float)(fft2_interleave_points)/fft2_size;
fft2_new_points=fft2_size-fft2_interleave_points;
fft2_blocktime=(float)(fft2_new_points)/timf1_sampling_speed;
fftx_blocktime=fft2_blocktime;
// Keep fft2 transforms for genparm[FFT2_STORAGE_TIME] seconds.
max_fft2n=genparm[FFT2_STORAGE_TIME]/fft2_blocktime;
make_power_of_two(&max_fft2n);
if(max_fft2n<4)max_fft2n=4;
t1=(float)(max_fft2n)*fft2_blockbytes;
if(t1 > 0x20000000) {
max_fft2n=0x20000000/fft2_blockbytes;
}
fft2n_mask=max_fft2n-1;
fft2_blockbytes=twice_rxchan*fft2_size;
fft2_totbytes=fft2_blockbytes*max_fft2n;
fft2_mask=fft2_totbytes-1;
fft2_pa=0;
fft2_pt=0;
fft2_na=0;
fft2_nc=0;
fft2_nb=fft2n_mask;
fft2_nx=0;
fft2_nm=0;
timf3_sampling_speed=timf1_sampling_speed/fft2_size;
timf2_output_block=fft2_new_points*4*ui.rx_rf_channels;
spur_freq_factor=(float)(fft2_new_points)/fft2_size;
}
timf3_sampling_speed*=mix1.size;
// ***********************************************************
// Transfer from the hardware device driver to our part of memory is
// done by read statements.
// If too few bytes are read each time we loose too much time because
// of the overhead of each read statement.
// If too many bytes are read each time we get an extra delay that
// is not acceptable in some receive modes.
// One output transform is fft1_blockbytes or fft1_size*twice_rxchan data words
// In I/Q mode (complex input format) the input contains the same
// number of data words as the output and the same number of fragments.
// In real mode (real input format) the fft routine contains a reduction
// of sampling speed (real to complex conversion).
// The number of input words is still the same as the number of output words
// but the fragment size is 2 times smaller at twice the sampling frequency.
// Make the maximum delay time 25% of the time for a full transform.
// This allows the user to force low delay times by selecting large
// fft1 bandwidths. (At questionable noise blanker performance)
if(genparm[SECOND_FFT_ENABLE] == 0) {
min_delay_time=fft1_size;
} else {
min_delay_time=fft2_size;
}
min_delay_time/=3*timf1_sampling_speed;
if(min_delay_time>0.1)min_delay_time=0.1;
snd[RXAD].block_frames=min_delay_time*ui.rx_ad_speed;
make_power_of_two((int*)&snd[RXAD].block_frames);
reduced_max_dma=ui.max_dma_rate;
if(snd[RXAD].block_frames<8)snd[RXAD].block_frames=8;
snd[RXAD].interrupt_rate=(float)(ui.rx_ad_speed)/(float)snd[RXAD].block_frames;
while(snd[RXAD].interrupt_rate < ui.min_dma_rate && snd[RXAD].block_frames>8) {
snd[RXAD].interrupt_rate*=2;
snd[RXAD].block_frames/=2;
}
while(snd[RXAD].interrupt_rate > reduced_max_dma) {
snd[RXAD].interrupt_rate/=2;
snd[RXAD].block_frames*=2;
}
{
{
snd[RXAD].block_bytes=snd[RXAD].block_frames*snd[RXAD].framesize;
// Set the interrupt rate high in case we write to the network.
// This will spread out the packages in time and make them easier
// to pick up on a slow computer.
k=10;
// Set interrupt rate high if the transmit side is enabled.
// This will reduce time jitter on the input from the morse hand key.
if(ui.tx_enable != 0)k=400;
if(k<ui.min_dma_rate)k=ui.min_dma_rate;
if(k>reduced_max_dma)k=reduced_max_dma;
// If we read from disk, allow big buffers.
// But not if we send to the network.
if( diskread_flag >=2) {
while(snd[RXAD].interrupt_rate > 200) {
snd[RXAD].block_frames*=2;
snd[RXAD].block_bytes*=2;
snd[RXAD].interrupt_rate/=2;
}
} else {
while( 2*snd[RXAD].interrupt_rate < k && snd[RXAD].block_frames>8) {
snd[RXAD].block_frames/=2;
snd[RXAD].block_bytes/=2;
snd[RXAD].interrupt_rate*=2;
}
}
}
}
// With the Delta44 we save 18 bit out of the 32 bits we read.
// Out of the 24 bits of data the last 6 contain only noise.
// Allocate snd[RXAD].block_bytes even if we use 16 bit format because
// the network write may use this scratch area.
save_rw_bytes=snd[RXAD].block_bytes;
rx_read_bytes=snd[RXAD].block_bytes;
if((ui.rx_input_mode&DWORD_INPUT) != 0)save_rw_bytes=18*snd[RXAD].block_bytes/32;
ad_bufmargin=2*(snd[RXAD].block_bytes+fft1_size*snd[RXAD].framesize);
timf1_blockbytes=fft1_new_points*snd[RXAD].framesize;
// In case fft1_size is small, the input thread might wake up the
// wideband routine very often causing needless overhead.
fft1_hz_per_point=(float)ui.rx_ad_speed/fft1_size;
if( (ui.rx_input_mode&IQ_DATA) == 0) {
fft1_hz_per_point/=2;
timf1_blockbytes*=2;
}
timf1_blockbytes*=fft_cntrl[FFT1_CURMODE].parall_fft;
timf1_blockbytes*=(fft_cntrl[FFT1_CURMODE].real2complex+1);
timf1_usebytes=timf1_blockbytes;
if(timf1_usebytes < (int)snd[RXAD].block_bytes)timf1_usebytes=snd[RXAD].block_bytes;
i=genparm[FIRST_FFT_NO_OF_THREADS];
// In case the oscilloscope for timf3 is enabled we want to
// update the screen at about TIMF3_OSCILLOSCOPE_RATE Hz.
timf3_osc_interval=twice_rxchan*(int)(timf3_sampling_speed/
TIMF3_OSCILLOSCOPE_RATE);
m=1+twice_rxchan;
t1=screen_height/(2*m);
for(i=0; i<8; i++)timf3_y0[i]=screen_height-(i+1)*t1;
// Allow for genparm[MIX1_NO_OF_CHANNELS] signals
// during the time for which we have transforms plus
// the duration of a transform (with a 5 s margin)
if( genparm[SECOND_FFT_ENABLE] == 0) {
t1=genparm[FFT1_STORAGE_TIME]+fft1_size/timf1_sampling_speed;
} else {
t1=genparm[FFT2_STORAGE_TIME]+fft2_size/timf1_sampling_speed;
}
t1+=5;
t1*=timf3_sampling_speed;
if(t1*genparm[MIX1_NO_OF_CHANNELS]*2*twice_rxchan*sizeof(float) > 0x7fffffff) {
t1=0x7fffffff/(genparm[MIX1_NO_OF_CHANNELS]*2*twice_rxchan*sizeof(float));
}
timf3_size=t1;
make_power_of_two(&timf3_size);
while(timf3_size < 2*screen_width)timf3_size *= 2;
timf3_size*=twice_rxchan;
timf3_totsiz=genparm[MIX1_NO_OF_CHANNELS]*timf3_size;
while( (float)(timf3_totsiz)*2*sizeof(float) > 0x7fffff00) {
timf3_size/=2;
timf3_totsiz/=2;
}
timf3_mask=timf3_size-1;
mix1.new_points=mix1.size-mix1.interleave_points;
timf3_block=twice_rxchan*mix1.new_points;
timf3_pa=0;
timf3_px=0;
timf3_py=0;
timf3_pn=0;
timf3_oscilloscope_limit=timf3_osc_interval+
twice_rxchan*(mix1.new_points+screen_width/2);
// ***********************************************************
// In case second fft is not enabled we need a buffer that can hold
// transforms during the time we average over in the AFC process
// in case it is enabled.
max_fft1n=8;
if(genparm[SECOND_FFT_ENABLE] == 0) {
// Keep fft1 transforms for genparm[FFT1_STORAGE_TIME] seconds.
max_fft1n=genparm[FFT1_STORAGE_TIME]/fft1_blocktime;
make_power_of_two(&max_fft1n);
}
// Always allocate at least 8 buffers.
// We may average over 5 buffers and use 2 for raw data processing.
if(max_fft1n < 8)max_fft1n=8;
t1=(float)(max_fft1n)*fft1_size;
t1*=twice_rxchan*sizeof(float);
if(t1 > 0x40000000) {
max_fft1n=0x40000000/(fft1_size*twice_rxchan*sizeof(float));
}
fft1_bytes=max_fft1n*fft1_size;
n=8;
if(8*(int)snd[RXAD].block_bytes > 4000000)n/=snd[RXAD].block_bytes/500000;
if(n < 1) n=1;
if(fft1_bytes < n*(int)snd[RXAD].block_bytes)
fft1_bytes=snd[RXAD].block_bytes*n;
max_fft1n=fft1_bytes/fft1_size;
fft1n_mask=max_fft1n-1;
fft1_bytes*=twice_rxchan;
fft1_mask=fft1_bytes-1;
fft1_bytes*=sizeof(float);
// ******************************************************
// We store fft1 power spectra in memory for fast calculation of averages.
// Check wide_graph.c for details.
max_fft1_sumsq=(1.+genparm[FFT1_STORAGE_TIME])/fft1_blocktime;
// We may group averages up to 5 to save time and space if avg time is long
{
max_fft1_sumsq/=5;
k=0;
while(max_fft1_sumsq != 0) {
max_fft1_sumsq/=2;
k++;
}
max_fft1_sumsq=1<<k;
if(max_fft1_sumsq<64)max_fft1_sumsq=max_fft1n;
}
if(genparm[SECOND_FFT_ENABLE] != 0 ||
(genparm[SECOND_FFT_ENABLE] == 0 && genparm[AFC_ENABLE] == 0)) {
fft1afc_flag=0;
} else {
fft1afc_flag=1;
}
t1=max_fft1_sumsq*fft1_size*sizeof(float);
if(t1 > 0x3ffffff) {
max_fft1_sumsq=0x3fffffff/(fft1_size*sizeof(float));
}
fft1_sumsq_bufsize=max_fft1_sumsq*fft1_size;
make_power_of_two(&fft1_sumsq_bufsize);
if(fft1_sumsq_bufsize > 0x3ffffff)fft1_sumsq_bufsize/=2;
max_fft1_sumsq--;
fft1_sumsq_mask=fft1_sumsq_bufsize-1;
// The raw data from the ad converter is read into timf1.
// This buffer is used as input to fft1. For this purpose only a
// small buffer is needed.
timf1_bytes=4*fft1_blockbytes;
no_of_fft1b=genparm[FIRST_FFT_NO_OF_THREADS];
if(no_of_fft1b > no_of_processors-1)no_of_fft1b=no_of_processors-1;
if(no_of_fft1b > 1)timf1_bytes*=no_of_fft1b;
// We read data into timf1 in blocks of snd[RXAD].block_bytes.
if(timf1_bytes < 2*(int)snd[RXAD].block_bytes+ad_bufmargin)
timf1_bytes=2*snd[RXAD].block_bytes+ad_bufmargin;
timf1_bytes+=snd[RXAD].framesize;
// When data is saved on the hard disk we send the contents of
// the buffer to the hard disk through a fwrite statement that will
// require the data to stay unchanged until the write is completed.
// Allow the data to reside in the buffer for 1 second because
// disk writes become pretty slow occasionally.
t1=ui.rx_ad_speed*snd[RXAD].framesize;
// In case we use Windows, allow 2 seconds.
if(screen_type == SCREEN_TYPE_WINDOWS )t1*=2;
// With very high sampling rates such as the 200 MHz of PCIe-9842
// the buffer becomes extremely large. Do not allow the timing
// requirement for disk save to increase the buffer above 32 megabytes
if(t1 > 32000000.0)t1=32000000.0;
if(timf1_bytes < t1)timf1_bytes=t1;
// Make sure timf1 is also a power of two
make_power_of_two(&timf1_bytes);
timf1_bytemask=timf1_bytes-1;
timf1_neg=timf1_bytes/2;
timf1p_pa=0;
timf1p_pb=0;
timf1p_px=0;
fft1_pa=0;
fft1_na=0;
fft1_pb=0;
fft1_px=0;
fft1_nm=0;
fft1_nb=0;
fft1_nc=0;
fft1_nx=0;
// In case we use approximate conversion from real to complex data
// we have to allocate memory and prepare for the assembly routines
// in getiq.s
// Set a value in case we run setup first
fft1_sumsq_recalc=fft1_size/2;
// To save time i.e. when oversampling we only compute spectrum between
// the points actually used.
// Set up values (full spectrum) for use in test modes.
wg.first_xpoint=0;
wg_last_point=fft1_size-1;
fft1_tmp_bytes=fft1_blockbytes*(fft_cntrl[FFT1_CURMODE].real2complex+1)*
fft_cntrl[FFT1_CURMODE].parall_fft;
if(genparm[SECOND_FFT_ENABLE] != 0)
fft1_tmp_bytes *= 2;
if(fft1_tmp_bytes < (int)snd[RXAD].block_bytes)
fft1_tmp_bytes=snd[RXAD].block_bytes;
// If second fft is enabled, we will calculate the noise floor
// in liminfo_groups segments of the entire spectrum.
// Start by assuming 500Hz is a reasonable bandwidth to get the
// noise floor in.
fftx_points_per_hz=1.0F/fft1_hz_per_point;
if(genparm[SECOND_FFT_ENABLE] != 0) {
fftx_size=fft2_size;
max_fftxn=max_fft2n;
liminfo_groups=500.F/fft1_hz_per_point;
if(liminfo_groups<16)liminfo_groups=16;
if(liminfo_groups>fft1_size/16)liminfo_groups=fft1_size/16;
make_power_of_two(&liminfo_groups);
liminfo_group_points=fft1_size/liminfo_groups;
if(liminfo_group_points == 0) {
liminfo_group_points=1;
liminfo_groups=fft1_size;
}
fft2_att_limit=fft2_n-1-genparm[SECOND_FFT_ATT_N];
fft2_to_fft1_ratio=fft2_size/fft1_size;
fftx_points_per_hz*=fft2_to_fft1_ratio;
} else {
fftx_size=fft1_size;
max_fftxn=max_fft1n;
liminfo_groups=0;
}
if(genparm[AFC_ENABLE]==0) genparm[MAX_NO_OF_SPURS] = 0;
fftn_tmp_bytes=fft1_tmp_bytes;
if(2*ui.rx_rf_channels*mix1.size*sizeof(float) > (unsigned)(fftn_tmp_bytes)) {
fftn_tmp_bytes=2*ui.rx_rf_channels*mix1.size*sizeof(float);
}
if(fft1_bytes < fft1_tmp_bytes)fft1_bytes=fft1_tmp_bytes;
if(rx_mode == MODE_TXTEST) {
if(mix1.size*fft1_hz_per_point > 5300) {
genparm[MIX1_BANDWIDTH_REDUCTION_N]++;
goto new_mix1_n;
}
if(mix1.size*fft1_hz_per_point < 2550) {
genparm[MIX1_BANDWIDTH_REDUCTION_N]--;
goto new_mix1_n;
}
}
if(mix1.size > 32768) {
genparm[MIX1_BANDWIDTH_REDUCTION_N]++;
goto new_mix1_n;
}
for(i=0; i<MAX_SC; i++) {
sd[i]=0;
sc[i]=0;
}
}
void get_buffers(int filldat)
{
int i,j,k;
int split_size, afcbuf_size;
float t1;
int *inttab;
afcbuf_size=0;
sw_onechan=(ui.rx_rf_channels==1);
// ***************************************************************
// The memory allocation is essential to program speed.
// Some time critical loops use several arrays. Place them next
// to each other in memory space so cash works well (?).
// (Was important for Pentium MMX, maybe not with modern computers)
init_memalloc(fft1mem, MAX_FFT1_ARRAYS);
mem( 2,&timf1_char,timf1_bytes,0);
mem( 3,&fft1_window,fft1_window_size*sizeof(float),0);
mem( 4,&fft1tab,fft1_costab_size*sizeof(COSIN_TABLE),16*sizeof(float));
// ***************************************************************
// fftw_tmp is used in THREAD_WIDEBAND_DSP in:
// fftw_tmp is also used in THREAD_POWTIM in:
k=fft1_tmp_bytes;
if(no_of_fft1b > 1) {
k=no_of_fft1b*(k+4*sizeof(float));
}
if(rx_mode == MODE_RX_ADTEST)k=4*screen_width*sizeof(int);
mem( 5,&fftw_tmp,2*k,4*sizeof(float));
mem( 551,&timf2_tmp,2*fft1_tmp_bytes,8*sizeof(float));
// ***************************************************************
mem( 552,&fftn_tmp,fftn_tmp_bytes,8*sizeof(float));
mem( 553,&rawsave_tmp,snd[RXAD].block_bytes,0);
mem( 555,&rawsave_tmp_disk,snd[RXAD].block_bytes,0);
mem( 6,&fft1_permute,fft1_permute_size*sizeof(short int),8*sizeof(int));
mem( 7,&fft1_filtercorr,fft1_blockbytes,8*sizeof(float));
mem( 8,&fft1_char, 2*fft1_bytes,0);
mem( 9,&wg_waterf_sum,fft1_size*sizeof(float),0);
mem(10,&fft1_sumsq,fft1_sumsq_bufsize*sizeof(float),0);
if(fft1afc_flag != 0) {
// AFC based on fft1 !!
if(sw_onechan) {
mem(1011,&fft1_power,fft1_size*max_fft1n*sizeof(float),0);
mem(1012,&fft1_powersum,fft1_size*sizeof(float),0);
} else {
mem(2011,&fft1_xypower,fft1_size*max_fft1n*sizeof(TWOCHAN_POWER),0);
mem(2012,&fft1_xysum,fft1_size*sizeof(TWOCHAN_POWER),0);
}
}
mem(13,&fft1_slowsum,fft1_size*sizeof(float),0);
if( (ui.rx_input_mode&IQ_DATA) != 0) {
mem(14,&fft1_foldcorr,twice_rxchan*fft1_size*sizeof(float),0);
}
mem(15,&fft1_spectrum,screen_width*sizeof(short int),0);
mem(16,&fft1_desired,fft1_size*sizeof(float),0);
mem(17,&wg_waterf_yfac,fft1_size*sizeof(float),0);
mem(18,&mix1.permute,mix1.size*sizeof(short int),0);
mem(19,&mix1.table,mix1.size*sizeof(COSIN_TABLE)/2,0);
mem(20,&timf3_float,2*timf3_totsiz*sizeof(float),0);
mem(21,&timf3_graph,ui.rx_rf_channels*screen_width*sizeof(short int),0);
mem(22,&liminfo_wait,fft1_size*sizeof(char),0);
mem(23,&liminfo,2*fft1_size*sizeof(float),0);
mem(24,&liminfo_group_min,liminfo_groups*sizeof(float),0);
if(genparm[SECOND_FFT_ENABLE] != 0) {
split_size=4*ui.rx_rf_channels*fft1_size;
mem(25,&fft1_split_float, split_size*sizeof(float),0);
// mem( 554,&fftf_tmp,(fft1_size+2*liminfo_groups)*sizeof(float),0);
mem( 554,&fftf_tmp,fft2_size*sizeof(float),0);
mem( 555,&fftt_tmp,fft2_size*sizeof(float),0);
mem( 640,&timf2_blockpower,ui.rx_rf_channels*
timf2_blockpower_size*sizeof(float),0);
}
mem(26,&mix1_fqwin,(mix1.size/2+16)*sizeof(float),0);
mem(27,&mix1.cos2win,mix1.new_points*sizeof(float),0);
mem(28,&mix1.sin2win,mix1.new_points*sizeof(float),0);
if(genparm[SECOND_FFT_ENABLE] == 0) {
if( genparm[FIRST_FFT_SINPOW]!=0 &&
(genparm[FIRST_FFT_SINPOW]!= 2 || rx_mode == MODE_TXTEST)) {
mem(1029,&mix1.window,(mix1.size/2+1)*sizeof(float),0);
}
} else {
if( genparm[FIRST_FFT_SINPOW]!= 2) {
if( genparm[FIRST_FFT_SINPOW]!=0 && genparm[FIRST_FFT_SINPOW]!= 2) {
mem(3029,&fft1_inverted_window,(16+fft1_size/2)*sizeof(float),0);
}
}
mem(30,&fft1_backbuffer,4*ui.rx_rf_channels*fft1_size*sizeof(short int),0);
mem(31,&fft1_back_scramble,fft1_size*sizeof(short int),0);
mem(3925,&hg_fft2_pwrsum,2*screen_width*sizeof(float),0);
if(!sw_onechan) {
mem(3926,&hg_fft2_pwr,max_fft2n*2*screen_width*sizeof(float),0);
}
mem(32,&timf2_float,4*ui.rx_rf_channels*timf2pow_size*sizeof(float),0);
if(lir_status != LIR_POWTIM) {
mem(33,&timf2_pwr_float,timf2pow_size*sizeof(float),0);
} else {
mem(33,&timf2_pwr_int,2*screen_width*sizeof(float),0);
}
if(fft_cntrl[FFT1_CURMODE].permute == 2 ||
fft_cntrl[FFT1_CURMODE].real2complex == 1) {
mem(34,&fft1_backtab,fft1_size*sizeof(COSIN_TABLE)/2,0);
}
if(sw_onechan) {
mem(1039,&fft2_power_float,fft2_size*max_fft2n*sizeof(float),0);
mem(1040,&fft2_powersum_float,fft2_size*sizeof(float),0);
} else {
mem(2039,&fft2_xypower,fft2_size*max_fft2n*sizeof(TWOCHAN_POWER),0);
mem(2040,&fft2_xysum,fft2_size*sizeof(TWOCHAN_POWER),0);
}
mem(3039,&fft2_bigpermute,fft2_size*sizeof(int),16*sizeof(int));
mem(1036,&fft2_float,max_fft2n*2*fft2_size*
ui.rx_rf_channels*sizeof(float),0);
mem(1037,&fft2_permute,fft2_size*sizeof(short int),0);
mem(1038,&fft2_tab,fft2_size*sizeof(COSIN_TABLE)/2,0);
if(genparm[SECOND_FFT_SINPOW] != 0) {
mem(1041,&fft2_window,fft2_size*sizeof(float),0);
}
if( lir_status==LIR_POWTIM ||
(genparm[SECOND_FFT_SINPOW]!= 0 && genparm[SECOND_FFT_SINPOW]!= 2)) {
mem(3042,&mix1.window,(mix1.size/2+1)*sizeof(float),0);
}
}
if(genparm[SECOND_FFT_ENABLE] == 0) {
afcbuf_size=max_fft1n*MAX_MIX1;
} else {
afcbuf_size=max_fft2n*MAX_MIX1;
}
if(genparm[AFC_ENABLE] != 0) {
mem(43,&mix1_fq_mid,afcbuf_size*sizeof(float),0);
mem(44,&mix1_fq_start,afcbuf_size*sizeof(float),0);
mem(45,&mix1_fq_curv,afcbuf_size*sizeof(float),0);
mem(46,&mix1_fq_slope,afcbuf_size*sizeof(float),0);
mem(47,&mix1_eval_avgn,afcbuf_size*sizeof(short int),0);
mem(48,&mix1_eval_fq,afcbuf_size*sizeof(float),0);
mem(49,&mix1_eval_sigpwr,afcbuf_size*sizeof(float),0);
mem(50,&mix1_eval_noise,afcbuf_size*sizeof(float),0);
mem(51,&mix1_fitted_fq,afcbuf_size*sizeof(float),0);
}
// Allocate memory for automatic spur cancellation
if(genparm[MAX_NO_OF_SPURS] != 0) {
if(genparm[MAX_NO_OF_SPURS] > fftx_size/SPUR_WIDTH) {
genparm[MAX_NO_OF_SPURS] = fftx_size/SPUR_WIDTH;
}
spur_block=SPUR_WIDTH*max_fftxn*twice_rxchan;
mem(2052,&spur_table,
genparm[MAX_NO_OF_SPURS]*spur_block*sizeof(float),0);
mem(53,&spur_location, genparm[MAX_NO_OF_SPURS]*sizeof(int),0);
mem(54,&spur_flag, genparm[MAX_NO_OF_SPURS]*sizeof(int),0);
mem(55,&spur_power, SPUR_WIDTH*sizeof(float),0);
mem(56,&spur_d0pha, genparm[MAX_NO_OF_SPURS]*sizeof(float),0);
mem(57,&spur_d1pha, genparm[MAX_NO_OF_SPURS]*sizeof(float),0);
mem(58,&spur_d2pha, genparm[MAX_NO_OF_SPURS]*sizeof(float),0);
mem(59,&spur_ampl, genparm[MAX_NO_OF_SPURS]*sizeof(float),0);
mem(60,&spur_noise, genparm[MAX_NO_OF_SPURS]*sizeof(float),0);
mem(61,&spur_avgd2, genparm[MAX_NO_OF_SPURS]*sizeof(float),0);
mem(62,&spur_pol,genparm[MAX_NO_OF_SPURS]*3*sizeof(float),0);
mem(63,&spur_spectra,NO_OF_SPUR_SPECTRA*SPUR_SIZE*sizeof(float),0);
mem(64,&spur_freq, genparm[MAX_NO_OF_SPURS]*sizeof(int),0);
mem(65,&spur_ind, genparm[MAX_NO_OF_SPURS]*max_fftxn*sizeof(int),0);
mem(66,&spur_signal, max_fftxn*twice_rxchan*
genparm[MAX_NO_OF_SPURS]*sizeof(float),0);
if(sw_onechan) {
mem(67,&spursearch_powersum,fftx_size*sizeof(float),0);
} else {
mem(68,&spursearch_xysum,fftx_size*sizeof(TWOCHAN_POWER),0);
}
mem(67,&spursearch_spectrum,fftx_size*sizeof(float),0);
spur_speknum=0.1*genparm[SPUR_TIMECONSTANT]/fftx_blocktime;
if(spur_speknum < 4)spur_speknum=4;
if(4*spur_speknum > max_fftxn && genparm[MAX_NO_OF_SPURS] != 0) {
lir_status=LIR_SPURERR;
return;
}
spursearch_sum_counter=0;
sp_numsub=spur_speknum-1;
sp_avgnum=spur_speknum/3;
if(sp_avgnum > 10)sp_avgnum=10;
spur_max_d2=PI_L*spur_freq_factor/spur_speknum;
// The spur signal is coherently averaged over spur_speknum transforms
// while noise is non-coherent rms value.
// Set the minimum S/N for at least 3dB in the narrower bandwidth for
// the noise we would get if the noise vas evaluated at the
// same bandwidth as the signal.
spur_minston=1/sqrt(0.5*(float)(spur_speknum));
// Make spur_weiold/new These parameters prevent the second
// derivative of the phase (frequency drift) to change rapidly.
t1=0.5*spur_speknum;
spur_weiold=t1/(1+t1);
spur_weinew=1/(1+t1);
// To fit a straight line to spur phase we need sum of squares.
t1=-0.5*sp_numsub;
spur_linefit=0;
for(i=0; i<spur_speknum; i++) {
spur_linefit+=t1*t1;
t1+=1;
}
}
no_of_spurs=0;
baseband_totmem=0;
afc_totmem=0;
hires_totmem=0;
fft3_totmem=0;
// *********************************************************
// Memory allocations for tx test mode.
if(rx_mode == MODE_TXTEST) {
mem(7201,&txtest_ypeak, screen_width*sizeof(short int),0);
mem(7211,&txtest_ypeak_decay, screen_width*sizeof(short int),0);
mem(7202,&txtest_yavg, screen_width*sizeof(short int),0);
i=(1+5*max_fft1_sumsq)*screen_width;
mem(7203,&txtest_power, i*sizeof(float),0);
mem(7204,&txtest_powersum, screen_width*sizeof(float),0);
mem(7205,&txtest_peak_power, screen_width*sizeof(float),0);
mem(7215,&txtest_peak_power_decay, screen_width*sizeof(float),0);
mem(7206,&txtest_old_yavg, screen_width*sizeof(short int),0);
mem(7207,&txtest_old_ypeak, screen_width*sizeof(short int),0);
mem(7217,&txtest_old_ypeak_decay, screen_width*sizeof(short int),0);
mem(7208,&fft1_old_spectrum, screen_width*sizeof(short int),0);
}
i=screen_width;
make_power_of_two(&i);
mg_size=i;
mg_mask=mg_size-1;
mem(7246,&mg_barbuf, 3*text_width*screen_height*sizeof(char),0);
mem(7247,&mg_rms_meter, mg_size*ui.rx_rf_channels*sizeof(float),0);
mem(7248,&mg_peak_ypix, 2*mg_size*ui.rx_rf_channels*sizeof(short int),0);
mem(7249,&mg_rms_ypix, 2*mg_size*ui.rx_rf_channels*sizeof(short int),0);
mem(7250,&mg_behind_meter, screen_height*sizeof(char),0);
mem(7254,&mg_peak_meter, mg_size*ui.rx_rf_channels*sizeof(float),0);
if(genparm[FFT1_CORRELATION_SPECTRUM]!=0 && ui.rx_rf_channels==2) {
// Allocate memory for an averaged correlation spectrum in the main
// spectrum window.
fft1_correlation_flag=TRUE;
mem(8101,&fft1_corrsum,2*fft1_sumsq_bufsize*sizeof(float),0);
mem(8102,&fft1_slowcorr,2*fft1_size*sizeof(double),0);
mem(8103,&fft1_corr_spectrum,screen_width*sizeof(short int),0);
mem(8104,&fft1_slowcorr_tot,2*fft1_size*sizeof(double),0);
mem(8105,&fft1_corr_spectrum_tot,screen_width*sizeof(short int),0);
} else {
fft1_correlation_flag=FALSE;
}
fftx_totmem=memalloc(&fft1_handle,"fft1,fft2");
if(fftx_totmem==0) {
lir_status=LIR_FFT1ERR;
return;
}
if(filldat==0)return;
fft1_calibrate_flag=0;
for(i=0; i<genparm[MAX_NO_OF_SPURS]*max_fftxn; i++)spur_ind[i]=-1;
if(genparm[AFC_ENABLE] != 0) {
for(i=0; i<afcbuf_size; i++)mix1_fq_mid[i]=-1;
for(i=0; i<afcbuf_size; i++)mix1_fq_start[i]=-1;
for(i=0; i<afcbuf_size; i++)mix1_fq_slope[i]=0;
for(i=0; i<afcbuf_size; i++)mix1_fq_curv[i]=0;
for(i=0; i<MAX_MIX1; i++)mix1_phase_step[i]=0;
for(i=0; i<MAX_MIX1; i++)mix1_phase[i]=0;
for(i=0; i<MAX_MIX1; i++)mix1_phase_rot[i]=0;
for(i=0; i<MAX_MIX1; i++)mix1_old_phase[i]=0;
for(i=0; i<MAX_MIX1; i++)mix1_old_point[i]=0;
}
if(genparm[SECOND_FFT_ENABLE] != 0) {
for(i=0; i<2*screen_width; i++)hg_fft2_pwrsum[i]=1;
}
timf1_float=(float*)(timf1_char);
timf1_int=(int*)(timf1_char);
timf1_short_int=(short int*)(timf1_char);
rxin_isho=(short int*)(timf1_char);
rxin_int=(int*)(timf1_char);
rxin_char=(char*)(timf1_char);
fft1_short_int=(short int*)(fft1_char);
fft1_int=(int*)(fft1_char);
fft1_float=(float*)(fft1_char);
timf3_int=(int*)(timf3_float);
if(genparm[MAX_NO_OF_SPURS] != 0) {
// Spur removal runs with fft1 or fft2. Place its scratch areas
// on the correct thread.
if(genparm[SECOND_FFT_ENABLE] == 0) {
sp_sig=(float*)(fftw_tmp);
} else {
sp_sig=(float*)(fftf_tmp);
}
sp_der=(float*)((char*)(sp_sig)+fftx_size*sizeof(float)/4);
sp_pha=(float*)((char*)(sp_der)+fftx_size*sizeof(float)/4);
sp_tmp=(float*)((char*)(sp_pha)+fftx_size*sizeof(float)/4);
for(i=0; i<fftx_size; i++)spursearch_spectrum[i]=1;
}
// *********************************************************************
make_window(5,mix1.size, 4, mix1_fqwin);
if(genparm[SECOND_FFT_ENABLE] == 0) {
if(lir_status != LIR_POWTIM) prepare_mixer(&mix1, FIRST_FFT_SINPOW);
} else {
prepare_mixer(&mix1, SECOND_FFT_SINPOW);
if( genparm[FIRST_FFT_SINPOW]!= 2) {
make_window(3,fft1_size, genparm[FIRST_FFT_SINPOW], fft1_inverted_window);
}
make_permute(fft_cntrl[FFT1_BCKCURMODE].permute, fft1_n,
fft1_size, fft1_back_scramble);
if(fft_cntrl[FFT1_CURMODE].permute == 2 ||
fft_cntrl[FFT1_CURMODE].real2complex == 1) {
make_sincos(0, fft1_size, fft1_backtab);
} else {
fft1_backtab=fft1tab;
}
make_bigpermute(fft_cntrl[FFT2_CURMODE].permute,
fft2_n, fft2_size, fft2_bigpermute);
make_sincos(1, fft2_size, fft2_tab);
// ****************************************************
if(genparm[SECOND_FFT_SINPOW] != 0) {
make_window(fft_cntrl[FFT2_CURMODE].window,fft2_size,
genparm[SECOND_FFT_SINPOW], fft2_window);
}
}
// Store bitmask for use by SIMD routine in scratch area before fft1tab
inttab=(int*)(fft1tab);
inttab[-1]=0x80000000;
inttab[-2]=0;
inttab[-3]=0x80000000;
inttab[-4]=0;
// Bitmask for use by simd routine in scratch area before fft1_filtercorr
inttab=(int*)(fft1_filtercorr);
inttab[-1]=0x80000000;
inttab[-2]=0;
inttab[-3]=0x80000000;
inttab[-4]=0;
if(kill_all_flag)return;
i=1;
if(fft_cntrl[FFT1_CURMODE].permute == 2)i=2;
if(fft_cntrl[FFT1_CURMODE].real2complex == 0) {
make_sincos(i, fft1_size, fft1tab);
make_permute(fft_cntrl[FFT1_CURMODE].permute, fft1_n, fft1_size, fft1_permute);
make_window(fft_cntrl[FFT1_CURMODE].window,fft1_size,
genparm[FIRST_FFT_SINPOW], fft1_window);
j=fft1_size;
} else {
make_sincos(i, 2*fft1_size, fft1tab);
make_permute(fft_cntrl[FFT1_CURMODE].permute, fft1_n+1,
2*fft1_size, fft1_permute);
make_window(fft_cntrl[FFT1_CURMODE].window,2*fft1_size,