1 // Copyright (c) <2012> <Leif Asbrink>
2 //
3 // Permission is hereby granted, free of charge, to any person
4 // obtaining a copy of this software and associated documentation
5 // files (the "Software"), to deal in the Software without restriction,
6 // including without limitation the rights to use, copy, modify,
7 // merge, publish, distribute, sublicense, and/or sell copies of
8 // the Software, and to permit persons to whom the Software is
9 // furnished to do so, subject to the following conditions:
10 //
11 // The above copyright notice and this permission notice shall be
12 // included in all copies or substantial portions of the Software.
13 //
14 // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
15 // EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES
16 // OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
17 // NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT
18 // HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
19 // WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
20 // FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE
21 // OR OTHER DEALINGS IN THE SOFTWARE.
22 
23 
24 #include "globdef.h"
25 #include "fft1def.h"
26 
27 // Define setup info for each fft version.
28 //typedef struct {
29 //unsigned char window;
30 //unsigned char permute;
31 //unsigned char max_n;
32 //unsigned char mmx;
33 //unsigned char simd;
34 //unsigned char real2complex;
35 //unsigned char parall_fft;
36 //char *text;
37 //} FFT_SETUP_INFO;
38 
39 
40 FFT_SETUP_INFO fft_cntrl[MAX_FFT_VERSIONS]={
41 {4,0,15,0,1,0,2,"Twin Radix 4 DIT SIMD"},                   //0
42 {4,0,15,0,0,1,1,"Twin Radix 4 DIT C real"},                 //1
43 {2,2,14,0,0,0,1,"Split radix DIT C real"},                  //2
44 {4,0,15,0,0,1,2,"Quad Radix 4 DIT C real"},                 //3
45 {4,0,15,0,1,1,2,"Quad Radix 4 DIT SIMD real"},              //4
46 {4,0,15,0,0,0,2,"Twin Radix 4 DIT"},                        //5
47 {4,0,15,0,0,0,1,"Radix 4 DIT C"},                           //6
48 {1,1,15,0,0,0,1,"Radix 2 DIF C"},                           //7
49 {1,1,15,0,0,0,1,"Radix 2 DIF ASM"},                         //8
50 {1,1,15,0,0,0,1,"Twin radix 2 DIF ASM"},                    //9
51 {4,0,15,0,0,0,1,"Twin Radix 4 DIT C"},                      //10
52 {4,0,15,0,1,0,1,"Twin Radix 4 DIT SIMD"},                   //11
53 {4,0,15,1,0,0,1,"Twin Radix 4 DIT MMX"},                    //12
54 {4,0,15,0,0,0,1,"Quad Radix 4 DIT C"},                      //13
55 {4,0,15,1,0,0,1,"Quad Radix 4 DIT MMX"},                    //14
56 {4,0,15,0,0,0,1,"Radix 2 DIF C"},                           //15
57 {4,0,15,0,0,0,1,"Twin Radix 4 DIT C"},                      //16
58 {4,0,15,1,0,0,1,"Radix 4 DIT MMX"}};                        //17
59 
60 // For fft1 there are 4 input modes as defined by the
61 // value of ui.input_mode&(TWO_CHANNELS+IQ_DATA)/2
62 // Define the index to fft_cntrl for as many fft versions
63 // as are implemented in each case.
64 // *************
65 // permute = 1 => DIF, Permute complex data after transform
66 // permute = 2 => DIT, permute and rearrange before computing transform
67 
68 int fft1_version[4][MAX_FFT1_VERNR]={
69 //        0   1   2   3   4   5   6   7
70          {2,  1,  3,  4, -1, -1, -1, -1},     // 1 chan normal audio
71          {2, -1, -1, -1, -1, -1, -1, -1},     // 2 chan normal audio
72          {7,  8,  6,  5,  0, -1, -1, -1},     // 1 chan direct conversion (IQ)
73          {7,  8,  9,  6, 10, 11, -1, -1}};    // 2 chan direct conversion (IQ)
74 
75 int fft1_back_version[2][MAX_FFT1_BCKVERNR]={
76 //        0   1   2    3
77         {10, 12, -1,  -1},      // 1 chan
78         {13, 14, -1 , -1}};     // 2 chan
79 
80 int fft2_version[2][MAX_FFT2_VERNR]={
81 //        0   1   2   3
82         {15,  6, 17, -1 },     // 1 chan
83         {15, 16, 12, -1 }};    // 2 chan
84 
85 double fft1_show_time;
86 
87 
88 int fft1_correlation_flag;
89 short int *rxin_isho;
90 int *rxin_int;
91 char *rxin_char;
92 
93 COSIN_TABLE *fft1tab;
94 COSIN_TABLE *fft1_backtab;
95 unsigned short int *fft1_permute;
96 float *fft1_corrsum;
97 float *fft1_slowcorr;
98 float *fft1_window;
99 float *fft1_sumsq;
100 float *fft1_slowsum;
101 float *fft1_power;
102 float *fft1_powersum;
103 TWOCHAN_POWER *fft1_xypower;
104 TWOCHAN_POWER *fft1_xysum;
105 float *fftw_tmp;
106 float *timf2_tmp;
107 float *fftf_tmp;
108 float *fftt_tmp;
109 char *rawsave_tmp;
110 char *rawsave_tmp_net;
111 char *rawsave_tmp_disk;
112 float *fft1_foldcorr;
113 MEMREF_T *fft1_handle;
114 char  *fft1_char;
115 short int *fft1_short_int;
116 int   *fft1_int;
117 float *fft1_float;
118 short int *fft1_spectrum;
119 short int *fft1_corr_spectrum;
120 float *fft1_filtercorr;
121 float *fft1_desired;
122 float *liminfo;
123 char *fft1_netsend_buffer;
124 unsigned char *liminfo_wait;
125 float *liminfo_group_min;
126 short int *fft1_split_shi;
127 float *fft1_split_float;
128 MMX_COSIN_TABLE *fft1_mmxcosin;
129 float *fft1_inverted_window;
130 short int *fft1_inverted_mmxwin;
131 unsigned short int *fft1_back_scramble;
132 short int *fft1_backbuffer;
133 char *timf1_char;
134 float *timf1_float;
135 int *timf1_int;
136 short int *timf1_short_int;
137 unsigned int *timf2_pwr_int;
138 float *timf2_pwr_float;
139 short int *timf2pix;
140 int yieldflag_wdsp_fft1;
141 int yieldflag_timf2_fft1;
142 int ui_converter_direction;
143 double converter_offset_mhz;
144 
145 
146 
147 float *wg_waterf_yfac;
148 short int *wg_waterf;
149 int wg_waterf_size;
150 int wg_waterf_ptr;
151 int local_wg_waterf_ptr;
152 WATERF_TIMES *wg_waterf_times;
153 int max_wg_waterf_times;
154 int wg_waterf_ptr2;
155 int local_wg_yborder;
156 int fft1_waterfall_flag;
157 int change_fft1_flag;
158 
159 
160 int fft1_costab_size,fft1_permute_size,fft1_window_size;
161 int fft1_tmp_bytes;
162 int timf2pow_size;
163 int timf2pow_mask;
164 int fftn_tmp_bytes;
165 int timf3_totsiz;
166 float fft2_interleave_ratio, fftx_blocktime;
167 
168 double diskread_block_counter;
169 double file_start_block;
170 double file_stop_block;
171 
172 int timf1_indicator_block;
173 int fft1_indicator_block;
174 int timf2_indicator_block;
175 int fft2n_indicator_block;
176 int timf3_indicator_block;
177 int fft3_indicator_block;
178 int baseb_indicator_block;
179 int daout_indicator_block;
180 int dabuf_indicator_block;
181 int indicator_first_pixel;
182 int indicator_ypix;
183 
184 int fft1_n;
185 int fft1_size;
186 int fft1_block;
187 int fft1_mulblock;
188 int fft1_muln;
189 int fft1_blockbytes;
190 int fft1_interleave_points;
191 float fft1_interleave_ratio;
192 int fft1_new_points;
193 float fft1_blocktime;
194 int fft1_mask;
195 int fft1_bytes;
196 int fft1_bufmask;
197 int fft1net_pa;
198 int fft1net_px;
199 int fft1net_size;
200 int fft1net_mask;
201 int fft1_pa;
202 int fft1_pb;
203 int fft1_px;
204 int fft1_na;
205 int fft1_nb;
206 int fft1_nc;
207 int fft1_nm;
208 int fft1_nx;
209 int fft1afc_flag;
210 double wg_waterf_zero_time;
211 int no_of_fft1b;
212 
213 int ad_wts;
214 float fft1_wtb;
215 float ad_wttim;
216 float fft1_wttim;
217 float timf2_wtb;
218 float timf2_wttim;
219 int fft1_sumsq_mask;
220 int fft1_sumsq_bufsize;
221 int fft1_sumsq_counter;
222 int fft1_sumsq_pa;
223 int radar_fft1_sumsq_pa;
224 int fft1_sumsq_pwg;
225 int fft1mode;
226 int fft1_calibrate_flag;
227 int max_fft1_sumsq;
228 int input_counter;
229 int fft1_sumsq_recalc;
230 int fft1_first_point;
231 int fft1_first_sym_point;
232 int fft1_first_sumsq_point;
233 int fft1_last_point;
234 int fft1_last_inband;
235 int fft1_first_inband;
236 int fft1_last_sym_point;
237 int fft1_last_sumsq_point;
238 int fft1back_lowgain_n;
239 int max_fft1n;
240 int fft1n_mask;
241 int fft1_sumsq_tot;
242 int fft1_direction;
243 int fft1_filtercorr_direction;
244 float fft1_bandwidth;
245 float fft1_hz_per_point;
246 float fft1_filtercorr_start;
247 int liminfo_groups;
248 int liminfo_group_points;
249 int fft1_lowlevel_points;
250 float fft1_lowlevel_fraction;
251 float liminfo_amplitude_factor;
252 float fft1_desired_totsum;
253 float fft1_noise_floor;
254 int ad_bufmargin;
255 int wg_xpix1;
256 int wg_waterfall_blank_points;
257 
258 float txtest_decayfac2;
259 float txtest_decayfac1;
260 int txtest_last_xpix;
261 int txtest_peak_redraw;
262 float txtest_saturated;
263 
264 short int *txtest_ypeak;
265 short int *txtest_ypeak_decay;
266 short int *txtest_yavg;
267 float *txtest_power;
268 float *txtest_powersum;
269 short int *txtest_old_yavg;
270 short int *txtest_old_ypeak;
271 short int *fft1_old_spectrum;
272 short int *txtest_old_ypeak_decay;
273 float *txtest_peak_power;
274 float *txtest_peak_power_decay;
275 // Variables related to saving raw data on disk
276 int save_init_flag;
277 FILE *save_wr_file;
278 FILE *save_rd_file;
279 int diskwrite_flag;
280 int diskread_flag;
281 int save_rw_bytes;
282 
283 float timf1_sampling_speed;
284 int timf1_bytes;
285 int timf1_neg;
286 int timf1_bytemask;
287 int timf1_blockbytes;
288 int timf1_usebytes;
289 int timf1p_pa;
290 int timf1p_px;
291 int timf1p_pb;
292 int timf1p_pc_net;
293 int timf1p_pc_disk;
294 int timf1p_sdr;
295 
296 short int *timf2_shi;
297 float *timf2_float;
298 float *timf2_blockpower;
299 int timf2_blockpower_pa;
300 int timf2_blockpower_px;
301 int timf2_blockpower_size;
302 int timf2_blockpower_mask;
303 int timf2_pa;
304 int timf2_pb;
305 int timf2_pc;
306 int timf2_pn1;
307 int timf2_pn2;
308 int timf2_pt;
309 int timf2p_fit;
310 int timf2_px;
311 int timf2_mask;
312 int timf2_neg;
313 int timf2_size;
314 int timf2_blockpower_block;
315 int timf2_input_block;
316 int timf2_output_block;
317 int timf2_display_counter;
318 int timf2_display_interval;
319 int timf2_display_maxpoint;
320 int timf2_ovfl;
321 int timf2_fitted_pulses;
322 int timf2_cleared_points;
323 int timf2_blanker_points;
324 int ad_maxamp[MAX_AD_CHANNELS];
325 int timf2_maxamp[2*MAX_RX_CHANNELS];
326 int fft1_maxamp[2*MAX_RX_CHANNELS];
327 int timf2_y0[16];
328 int timf2_ymax[16];
329 int timf2_ymin[16];
330 int timf2_hg_x[2];
331 int timf2_hg_y[2];
332 float timf2_hg_xfac;
333 float timf2_hg_xlog;
334 int timf2_hg_xmin;
335 int timf2_hg_xmax;
336 int timf2_hg_yh;
337 int timf2_hg_stux;
338 int timf2_hg_clex;
339 int timf2_hg_qex;
340 int overrun_limit;
341 
342 float timf2_display_maxval_float;
343 float timf2_display_powermax_float;
344 unsigned int timf2_display_maxval_uint;
345 unsigned int timf2_display_powermax_uint;
346 
347 int txtest_no_of_segs;
348 float txtest_pixinc;
349 int txtest_pntinc;
350 int txtest_first_xpix;
351 int txtest_spek_no;
352 int txtest_spek_p0;
353 int txtest_first_point;
354 int txtest_show_p0;
355 float txtest_yfac;
356 
357 int wg_first_point;
358 int wg_last_point;
359 
360