1 // ----------------------------------------------------------------------------
2 // ifkp.h  --  BASIS FOR ALL MODEMS
3 //
4 // Copyright (C) 2006
5 //		Dave Freese, W1HKJ
6 //
7 // This file is part of fldigi.
8 //
9 // Fldigi 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 3 of the License, or
12 // (at your option) any later version.
13 //
14 // Fldigi 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.
18 //
19 // You should have received a copy of the GNU General Public License
20 // along with fldigi.  If not, see <http://www.gnu.org/licenses/>.
21 // ----------------------------------------------------------------------------
22 
23 #ifndef _IFKP_H
24 #define _IFKP_H
25 
26 #include <string>
27 
28 #include "trx.h"
29 #include "modem.h"
30 #include "complex.h"
31 #include "filters.h"
32 #include "picture.h"
33 #include <FL/Fl_Shared_Image.H>
34 
35 class ifkp : public modem {
36 
37 #define IFKP_FFTSIZE		4096
38 #define IFKP_SYMLEN			4096
39 
40 #define IFKP_BLOCK_SIZE		IFKP_FFTSIZE
41 #define IFKP_SHIFT_SIZE		(IFKP_SYMLEN / 16)
42 
43 //#define	IFKP_SR				8000 //16000
44 
45 #define IFKP_SPACING		3
46 #define IFKP_OFFSET			1
47 #define IFKP_NUMBINS		151 // 3 bin spacing
48 #define IMAGESPP			8 //16 , 12, 8
49 
50 enum IFKP_STATE {TEXT, IMAGE_START, IMAGE_SYNC, IMAGE};
51 
52 public:
53 	int			symlen;
54 
55 protected:
56 // Rx
57 	double			rx_stream[IFKP_BLOCK_SIZE + IFKP_SHIFT_SIZE];
58 	cmplx			fft_data[2*IFKP_FFTSIZE];
59 	double			a_blackman[IFKP_BLOCK_SIZE];
60 	C_FIR_filter	*rxfilter;
61 	double			tones[IFKP_NUMBINS];
62 	Cmovavg			*binfilt[IFKP_NUMBINS];
63 	int				movavg_size;
64 	int 			bkptr;
65 	g_fft<double>	*fft;
66 	Cmovavg			*snfilt;
67 	double			val;
68 	double			max;
69 	double			noise;
70 	double			noisepower;
71 	int				peak;
72 	int				prev_peak;
73 	int				last_peak;
74 	int				peak_counter;
75 	int				peak_hits;
76 	int				symbol;
77 	int				prev_symbol;
78 	int				curr_nibble;
79 	int				prev_nibble;
80 	int				nibbles[199];
81 	void			process_symbol(int);
82 	void			parse_pic(int);
83 	double			s2n;
84 	char			szestimate[40];
85 	std::string		station_calling;
86 	std::string		rx_text;
87 	std::string		toprint;
88 	std::string		pic_str;
89 
90 	IFKP_STATE		state;
91 
92 // Tx
93 //	C_FIR_filter	*xmtfilt;
94 	double			baud;
95 	int				tone;
96 	int				prevtone;
97 	double			txphase;
98 	bool			send_bot;
99 	void			transmit(double *buf, int len);
100 	void			send_char (int);
101 	void			send_idle ();
102 	void			send_symbol(int sym);
103 	void			send_tone(int tone);
104 	std::string		xmt_string;
105 	double			xmtdelay();
106 
107 // RxTx
108 	int				basetone;
109 	double			metric;
110 	bool			ch_sqlch_open;
111 	std::string		mycall;
112 
113 	void			show_mode();
114 	void			process_tones();
115 
116 	bool			valid_char(int);
117 
118 	std::string		heard_log_fname;
119 	std::string		audit_log_fname;
120 	std::ofstream	heard_log;
121 	std::ofstream	audit_log;
122 
123 	static std::string		imageheader;
124 	static std::string		avatarheader;
125 
126 public:
127 //----
128 // virtual in base class
129 	ifkp (trx_mode md);
130 	~ifkp ();
131 	void	init ();
132 	void	rx_init ();
133 	void	rx_reset ();
134 	void	restart ();
135 	void	tx_init ();
136 	int		rx_process (const double *buf, int len);
137 	int		tx_process ();
138 
139 	void	set_freq(double);
140 
141 	void	init_nibbles();
142 //----
143 
144 // support for ifkp image transfers
145 private:
146 	double pixel;
147 	double sync;
148 	bool    TX_IMAGE;
149 	bool    TX_AVATAR;
150 	unsigned char tx_pixel;
151 	int tx_pixelnbr;
152 	int image_mode;
153 	bool b_ava;
154 public:
155 	int		byte;
156 	double	picf;
157 	double picpeak;
158 	C_FIR_filter *picfilter;
159 	Cmovavg *pixfilter;
160 	Cmovavg *ampfilter;
161 	Cmovavg *syncfilter;
162 	double phidiff;
163 	double phase;
164 	cmplx	prevz;
165 	cmplx	currz;
166 	double image_freq[10];
167 	int		image_counter;
168 	int		picW;
169 	int		picH;
170 	int		row;
171 	int		col;
172 	int		rgb;
173 	int		pixelnbr;
174 	static int		IMAGEspp;
175 	int		TXspp;
176 	void	recvpic(double smpl);
177 	void	send_image();
178 	void	send_avatar();
179 	void	ifkp_send_avatar();
180 	void	m_ifkp_send_avatar();
181 	void	ifkp_send_image(std::string s = "", bool grey = false);
182 
183 	void	toggle_logs();
184 };
185 
186 #endif
187