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 "sigdef.h"
26 
27 // Repeat defines so we may notice mistakes.
28 #define CW_WORDSEP 255
29 #define CW_SPACE 254
30 #define CW_DOT 253
31 #define CW_DASH 252
32 
33 int cw_item_len[256-CW_DASH]={4,2,2,4};
34 char *cw_item_text[256-CW_DASH]={"WORDSEP","SPACE","DOT","DASH"};
35 
36 // Store character values.
37 // 243 means an error. The code is not used and no used code can
38 // be made by adding dots or dashes.
39 // 242 is an incomplete code. At least one dot or dash must be
40 // appended to get a valid code.
41 
42 unsigned char morsascii1[2]={
43  'E',//.
44 'T'};//_
45 unsigned char morsascii2[4]={
46  'I',//..
47  'A',//._
48  'N',//_.
49 'M'};//__
50 unsigned char morsascii3[8]={
51  'S',//...
52  'U',//.._
53  'R',//._.
54  'W',//.__
55  'D',//_..
56  'K',//_._
57  'G',//__.
58 'O'};//___
59 unsigned char morsascii4[16]={
60  'H',//....
61  'V',//..._
62  'F',//.._.
63  198,//..__
64  'L',//._..
65  196,//._._
66  'P',//.__.
67  'J',//.___
68  'B',//_...
69  'X',//_.._
70  'C',//_._.
71  'Y',//_.__
72  'Z',//__..
73  'Q',//__._
74  246,//___.
75 245};//____
76 unsigned char morsascii5[32]={
77  '5',//.....
78  '4',//...._
79  247,//..._.
80  '3',//...__
81  243,//.._..
82  243,//.._._
83  '!',//..__.
84  '2',//..___
85  243,//._...
86  242,//._.._
87  199,//._._.
88  243,//._.__
89  243,//.__..
90  197,//.__._
91  243,//.___.
92  '1',//.____
93  '6',//_....
94  '=',//_..._
95  '/',//_.._.
96  243,//_..__
97  243,//_._..
98  242,//_._._
99  '(',//_.__.
100  243,//_.___
101  '7',//__...
102  242,//__.._
103  243,//__._.
104  243,//__.__
105  '8',//___..
106  '9',//____.
107 '0'};//_____
108 unsigned char morsascii6[64]={
109  243,//......
110  243,//....._
111  243,//...._.
112  243,//....__
113  243,//..._..
114  200,//..._._
115  243,//...__.
116  243,//...___
117  243,//.._...
118  243,//.._.._
119  243,//.._._.
120  243,//.._.__
121  '?',//..__..
122  243,//..__._
123  243,//..___.
124  243,//..____
125  243,//._....
126  243,//._..._
127  '"',//._.._.
128  243,//._..__
129  243,//._._..
130  '.',//._._._
131  243,//._.__.
132  243,//._.___
133  243,//.__...
134  243,//.__.._
135  243,//.__._.
136  243,//.__.__
137  243,//.___..
138  243,//.____.
139  243,//._____
140  243,//_.....
141  '-',//_...._
142  243,//_..._.
143  243,//_...__
144  243,//_.._..
145  243,//_.._._
146  243,//_..__.
147  243,//_..___
148  243,//_._...
149  243,//_._.._
150  ';',//_._._.
151  243,//_._.__
152  243,//_.__..
153  ')',//_.__._
154  243,//_.___.
155  243,//_.____
156  243,//__....
157  243,//__..._
158  243,//__.._.
159  ',',//__..__
160  243,//__._..
161  243,//__._._
162  243,//__.__.
163  243,//__.___
164  ':',//___...
165  243,//___.._
166  243,//___._.
167  243,//___.__
168  243,//____..
169  243,//_____.
170 243};//______
171 
172 unsigned char *morsascii[6]={morsascii1, morsascii2, morsascii3,
173                morsascii4, morsascii5, morsascii6};
174 
175 float *squelch_info;
176 double squelch_turnon_time;
177 int squelch_on;
178 int bg_waterfall_blank_points;
179 
180 int baseb_min_block;
181 int baseb_output_block;
182 
183 int bg_filter_points;
184 float keying_spectrum_pos[KEYING_SPECTRUM_MAX];
185 float keying_spectrum_ampl[KEYING_SPECTRUM_MAX];
186 int keying_spectrum_ptr;
187 int keying_spectrum_max;
188 int keying_spectrum_cnt;
189 float keying_spectrum_f1;
190 int bg_no_of_notches;
191 int bg_current_notch;
192 int bg_notch_pos[MAX_BG_NOTCHES];
193 int bg_notch_width[MAX_BG_NOTCHES];
194 
195 int cg_oscw;
196 int cg_osc_points;
197 float rds_f1;
198 float rds_f2;
199 float rds_phase;
200 float rds_power;
201 
202 int min_daout_samps;
203 float fm0_ph1;
204 float fm0_ph2;
205 float fm1_ph1;
206 float fm1_ph2;
207 float fm2_ph1;
208 float fm2_ph2;
209 float *fm_lowpass;
210 int fmfil_rise;
211 int fmfil_len;
212 float fm_lowpass_ampsum;
213 float *fm_audiofil_fir;
214 int fm_audiofil_size;
215 int fm_audiofil_n;
216 int fm_audiofil_points;
217 float *fmfil70_fir;
218 int fmfil70_size;
219 int fmfil70_n;
220 int fmfil70_points;
221 int fm1_resample_ratio;
222 int fm1_pa;
223 int fm1_px;
224 float *fm1_all;
225 float fm1_sampling_speed;
226 int fm1_size;
227 int fm1_mask;
228 int bg_agc_hang_pts;
229 
230 
231 float *fmfil55_fir;
232 int fmfil55_size;
233 int fmfil55_n;
234 int fmfil55_points;
235 float *fmfil_rds_fir;
236 int fmfil_rds_size;
237 int fmfil_rds_n;
238 int fmfil_rds_points;
239 float *fmfil_fir;
240 int fmfil_size;
241 int fmfil_n;
242 int fmfil_points;
243 int fm_n;
244 int fm_size;
245 unsigned short int fm_permute[32];
246 COSIN_TABLE fm_tab[16];
247 float fm_win[32];
248 
249 MEMREF_T *baseband_handle;
250 float *baseb_out;
251 float *baseb;
252 float *baseb_raw;
253 
254 float *baseb_fm_phase;
255 float *baseb_fm_sumchan;
256 float *baseb_fm_diffchan;
257 float *baseb_fm_rdsraw;
258 float *baseb_fm_composite;
259 
260 float *baseb_fm_demod;
261 float *baseb_fm_demod_low;
262 float *baseb_fm_demod_high;
263 float *fm_pilot_tone;
264 float *baseb_fm_pil2;
265 float *baseb_fm_pil2det;
266 float *baseb_fm_pil3;
267 float *baseb_fm_pil3det;
268 int fm_pilot_size;
269 
270 float *baseb_wb_raw;
271 float *baseb_raw_orthog;
272 float *baseb_carrier;
273 float *baseb_carrier_ampl;
274 float *baseb_totpwr;
275 float *baseb_envelope;
276 float *baseb_upthreshold;
277 float *baseb_threshold;
278 float *baseb_fit;
279 float *baseb_tmp;
280 float *baseb_agc_level;
281 float *baseb_agc_det;
282 short int *baseb_ramp;
283 float *baseb_sho1;
284 float *baseb_sho2;
285 float carrfil_weight;
286 float bgfil_weight;
287 float *baseb_clock;
288 
289 float reg_dot_power[5];
290 float reg_dot_re[5];
291 float reg_dot_im[5];
292 float reg_dash_power;
293 float reg_dash_re;
294 float reg_dash_im;
295 int dot_siz, dot_sizhalf, dash_siz, dash_sizhalf;
296 int cg_old_y1;
297 int cg_old_y2;
298 int cg_old_x1;
299 int cg_old_x2;
300 
301 
302 
303 int keying_spectrum_size;
304 float *keying_spectrum;
305 char *mg_behind_meter;
306 short int *mg_rms_ypix;
307 short int *mg_peak_ypix;
308 float *mg_rms_meter;
309 float *mg_peak_meter;
310 short int mg_first_xpixel;
311 short int mg_last_xpixel;
312 short int mg_pa;
313 short int mg_px;
314 short int mg_size;
315 short int mg_mask;
316 short int mgw_p;
317 short int mg_ymin;
318 short int mg_ymax;
319 char mg_clear_flag;
320 int bg_update_filter;
321 double mg_dbscale_start;
322 double mg_scale_offset;
323 double mg_dbstep;
324 float mg_midscale;
325 int mg_valid;
326 int mg_bar;
327 char *mg_barbuf;
328 short int mg_bar_x1;
329 short int mg_bar_x2;
330 short int mg_y0;
331 short int mg_bar_y;
332 
333 int cg_wave_start;
334 float cg_wave_midpoint;
335 float cg_wave_fit;
336 float cg_wave_coh_re;
337 float cg_wave_coh_im;
338 float cg_wave_raw_re;
339 float cg_wave_raw_im;
340 float cg_wave_dat;
341 float cg_wave_err;
342 float *basblock_maxpower;
343 float *basblock_avgpower;
344 char *daout;
345 float *cg_map;
346 short int *cg_traces;
347 float *mix2_tmp;
348 float *mix2_pwr;
349 float *fftn_tmp;
350 MORSE_DECODE_DATA *cw;
351 float *cw_carrier_window;
352 char *bg_volbuf;
353 float *bg_binshape;
354 float *bg_ytmp;
355 float *dash_waveform;
356 
357 float *dash_wb_waveform;
358 float *dot_wb_waveform;
359 int dash_wb_ia;
360 int dash_wb_ib;
361 int dot_wb_ia;
362 int dot_wb_ib;
363 
364 
365 int cg_yzer[CG_MAXTRACE];
366 int cw_ptr;
367 int cw_detect_flag;
368 int max_cwdat;
369 int no_of_cwdat;
370 int correlate_no_of_cwdat;
371 int cw_decoded_chars;
372 float baseband_noise_level;
373 float carrier_noise_level;
374 
375 
376 
377 double da_block_counter;
378 int poleval_pointer;
379 float baseband_sampling_speed;
380 int timf1_to_baseband_speed_ratio;
381 int cg_no_of_traces;
382 int cg_lsep;
383 unsigned char cg_color[CG_MAXTRACE];
384 int cg_osc_ptr;
385 int cg_osc_offset;
386 int cg_osc_offset_inc;
387 int cg_osc_shift_flag;
388 int cg_max_trlevel;
389 float cg_code_unit;
390 float cg_decay_factor;
391 int cw_waveform_max;
392 unsigned int cw_avg_points;
393 int cg_update_interval;
394 int cg_update_count;
395 float cw_stoninv;
396 
397 int baseband_size;
398 int baseband_mask;
399 int baseband_neg;
400 int baseband_sizhalf;
401 int baseb_pa;
402 int baseb_pb;
403 int baseb_pc;
404 int baseb_pd;
405 int baseb_pe;
406 int baseb_pf;
407 int baseb_ps;
408 int baseb_pm;
409 int baseb_pn;
410 int baseb_px;
411 int baseb_py;
412 float baseb_fx;
413 int daout_size;
414 int new_baseb_flag;
415 float da_resample_ratio;
416 float new_da_resample_ratio;
417 int daout_upsamp;
418 int new_daout_upsamp;
419 int daout_upsamp_n;
420 int daout_pa;
421 int daout_px;
422 int tx_daout_block;
423 int daout_bufmask;
424 int flat_xpixel;
425 int curv_xpixel;
426 int bfo_xpixel;
427 int bfo10_xpixel;
428 int bfo100_xpixel;
429 double rx_daout_cos;
430 double rx_daout_sin;
431 double rx_daout_phstep_sin;
432 double rx_daout_phstep_cos;
433 
434 float daout_gain;
435 int daout_gain_y;
436 int bfo_flag;
437 int baseb_channels;
438 float baseb_wts;
439 float da_wttim;
440 float baseb_wttim;
441 float db_wttim;
442 float da_wait_time;
443 POLCOFF poleval_data[POLEVAL_SIZE];
444 int bg_filtershift_points;
445 int bg_expand;
446 int bg_coherent;
447 int bg_delay;
448 int bg_twopol;
449 float bg_expand_a;
450 float bg_expand_b;
451 float bg_amplimit;
452 float bg_agc_amplimit;
453 float bg_maxamp;
454 int bg_amp_indicator_x;
455 int bg_amp_indicator_y;
456 int da_ch2_sign;
457 int cg_size;
458 int dash_pts;
459 float dash_sumsq;
460 float cwbit_pts;
461 float refpwr;
462 int basblock_size;
463 int basblock_mask;
464 int basblock_hold_points;
465 int basblock_pa;
466 float s_meter_peak_hold;
467 float s_meter_fast_attack_slow_decay;
468 float s_meter_average_power;
469 float cg_maxavg;
470 float baseband_pwrfac;
471 float rx_agc_factor1;
472 float rx_agc_factor2;
473 float rx_agc_sumpow1;
474 float rx_agc_sumpow2;
475 float rx_agc_sumpow3;
476 float rx_agc_sumpow4;
477 float rx_agc_fastsum1;
478 float rx_agc_fastsum2;
479 float rx_agc_fast_factor1;
480 float rx_agc_fast_factor2;
481 float agc_attack_factor1;
482 float agc_attack_factor2;
483 float agc_release_factor;
484 float am_dclevel1;
485 float am_dclevel2;
486 float am_dclevel_factor1;
487 float am_dclevel_factor2;
488 int s_meter_avgnum;
489 float s_meter_avg;
490