1 /*****************************************************************************/
2 
3 /*
4  *      gentbl.c  -- soundcard radio modem driver table generator.
5  *
6  *      Copyright (C) 1996  Thomas Sailer (sailer@ife.ee.ethz.ch)
7  *
8  *      This program is free software; you can redistribute it and/or modify
9  *      it under the terms of the GNU General Public License as published by
10  *      the Free Software Foundation; either version 2 of the License, or
11  *      (at your option) any later version.
12  *
13  *      This program is distributed in the hope that it will be useful,
14  *      but WITHOUT ANY WARRANTY; without even the implied warranty of
15  *      MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
16  *      GNU General Public License for more details.
17  *
18  *      You should have received a copy of the GNU General Public License
19  *      along with this program; if not, write to the Free Software
20  *      Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
21  *
22  *  Please note that the GPL allows you to use the driver, NOT the radio.
23  *  In order to use the radio, you need a license from the communications
24  *  authority of your country.
25  *
26  */
27 
28 #include <stdio.h>
29 #include <stdlib.h>
30 #include <math.h>
31 #include <string.h>
32 
33 /* -------------------------------------------------------------------- */
34 
gentbl_offscostab(FILE * f,unsigned int nbits)35 static void gentbl_offscostab(FILE *f, unsigned int nbits)
36 {
37 	int i;
38 
39 	fprintf(f, "\n/*\n * small cosine table in U8 format\n */\n"
40 		"#define OFFSCOSTABBITS %u\n"
41 		"#define OFFSCOSTABSIZE (1<<OFFSCOSTABBITS)\n\n",
42 		nbits);
43 	fprintf(f, "static unsigned char offscostab[OFFSCOSTABSIZE] = {\n\t");
44 	for (i = 0; i < (1<<nbits); i++) {
45 		fprintf(f, "%4u", (int)
46 			(128+127.0*cos(i*2.0*M_PI/(1<<nbits))));
47 		if (i < (1<<nbits)-1)
48 			fprintf(f, "%s", (i & 7) == 7 ? ",\n\t" : ",");
49 	}
50 	fprintf(f, "\n};\n\n"
51 		"#define OFFSCOS(x) offscostab[((x)>>%d)&0x%x]\n\n",
52 		16-nbits, (1<<nbits)-1);
53 }
54 
55 /* -------------------------------------------------------------------- */
56 
gentbl_costab(FILE * f,unsigned int nbits)57 static void gentbl_costab(FILE *f, unsigned int nbits)
58 {
59         int i;
60 
61 	fprintf(f, "\n/*\n * more accurate cosine table\n */\n\n"
62 		"static const short costab[%d] = {", (1<<nbits));
63         for (i = 0; i < (1<<nbits); i++) {
64                 if (!(i & 7))
65                         fprintf(f, "\n\t");
66                 fprintf(f, "%6d", (int)(32767.0*cos(i*2.0*M_PI/(1<<nbits))));
67                 if (i != ((1<<nbits)-1))
68                         fprintf(f, ", ");
69         }
70         fprintf(f, "\n};\n\n#define COS(x) costab[((x)>>%d)&0x%x]\n"
71 		"#define SIN(x) COS((x)+0xc000)\n\n", 16-nbits,
72 		(1<<nbits)-1);
73 }
74 
75 /* -------------------------------------------------------------------- */
76 
77 #define AFSK12_SAMPLE_RATE 9600
78 #define AFSK12_TX_FREQ_LO 1200
79 #define AFSK12_TX_FREQ_HI 2200
80 #define AFSK12_CORRLEN 8
81 
gentbl_afsk1200(FILE * f)82 static void gentbl_afsk1200(FILE *f)
83 {
84         int i, v, sum;
85 
86 #define ARGLO(x) 2.0*M_PI*(double)x*(double)AFSK12_TX_FREQ_LO/(double)AFSK12_SAMPLE_RATE
87 #define ARGHI(x) 2.0*M_PI*(double)x*(double)AFSK12_TX_FREQ_HI/(double)AFSK12_SAMPLE_RATE
88 
89 	fprintf(f, "\n/*\n * afsk1200 specific tables\n */\n"
90 		"#define AFSK12_SAMPLE_RATE %u\n"
91 		"#define AFSK12_TX_FREQ_LO %u\n"
92 		"#define AFSK12_TX_FREQ_HI %u\n"
93 		"#define AFSK12_CORRLEN %u\n\n",
94 		AFSK12_SAMPLE_RATE, AFSK12_TX_FREQ_LO,
95 		AFSK12_TX_FREQ_HI, AFSK12_CORRLEN);
96 	fprintf(f, "static const int afsk12_tx_lo_i[] = {\n\t");
97         for(sum = i = 0; i < AFSK12_CORRLEN; i++) {
98 		sum += (v = 127.0*cos(ARGLO(i)));
99                 fprintf(f, " %4i%c", v, (i < AFSK12_CORRLEN-1) ? ',' : ' ');
100 	}
101         fprintf(f, "\n};\n#define SUM_AFSK12_TX_LO_I %d\n\n"
102 		"static const int afsk12_tx_lo_q[] = {\n\t", sum);
103         for(sum = i = 0; i < AFSK12_CORRLEN; i++) {
104 		sum += (v = 127.0*sin(ARGLO(i)));
105                 fprintf(f, " %4i%c", v, (i < AFSK12_CORRLEN-1) ? ',' : ' ');
106 	}
107         fprintf(f, "\n};\n#define SUM_AFSK12_TX_LO_Q %d\n\n"
108 		"static const int afsk12_tx_hi_i[] = {\n\t", sum);
109         for(sum = i = 0; i < AFSK12_CORRLEN; i++) {
110 		sum += (v = 127.0*cos(ARGHI(i)));
111                 fprintf(f, " %4i%c", v, (i < AFSK12_CORRLEN-1) ? ',' : ' ');
112 	}
113         fprintf(f, "\n};\n#define SUM_AFSK12_TX_HI_I %d\n\n"
114 		"static const int afsk12_tx_hi_q[] = {\n\t", sum);
115         for(sum = i = 0; i < AFSK12_CORRLEN; i++)  {
116 		sum += (v = 127.0*sin(ARGHI(i)));
117                 fprintf(f, " %4i%c", v, (i < AFSK12_CORRLEN-1) ? ',' : ' ');
118 	}
119 	fprintf(f, "\n};\n#define SUM_AFSK12_TX_HI_Q %d\n\n", sum);
120 #undef ARGLO
121 #undef ARGHI
122 }
123 
124 /* -------------------------------------------------------------------- */
125 
126 static const float fsk96_tx_coeff_4[32] = {
127               -0.001152,        0.000554,        0.002698,        0.002753,
128               -0.002033,       -0.008861,       -0.008002,        0.006607,
129                0.023727,        0.018905,       -0.018056,       -0.057957,
130               -0.044368,        0.055683,        0.207667,        0.322048,
131                0.322048,        0.207667,        0.055683,       -0.044368,
132               -0.057957,       -0.018056,        0.018905,        0.023727,
133                0.006607,       -0.008002,       -0.008861,       -0.002033,
134                0.002753,        0.002698,        0.000554,       -0.001152
135 };
136 
137 static const float fsk96_tx_coeff_5[40] = {
138               -0.001009,       -0.000048,        0.001376,        0.002547,
139                0.002061,       -0.001103,       -0.005795,       -0.008170,
140               -0.004017,        0.006924,        0.018225,        0.019238,
141                0.002925,       -0.025777,       -0.048064,       -0.039683,
142                0.013760,        0.104144,        0.200355,        0.262346,
143                0.262346,        0.200355,        0.104144,        0.013760,
144               -0.039683,       -0.048064,       -0.025777,        0.002925,
145                0.019238,        0.018225,        0.006924,       -0.004017,
146               -0.008170,       -0.005795,       -0.001103,        0.002061,
147                0.002547,        0.001376,       -0.000048,       -0.001009
148 };
149 
150 #define HAMMING(x) (0.54-0.46*cos(2*M_PI*(x)));
151 
hamming(float x)152 static inline float hamming(float x)
153 {
154 	return 0.54-0.46*cos(2*M_PI*x);
155 }
156 
sinc(float x)157 static inline float sinc(float x)
158 {
159 	if (x == 0)
160 		return 1;
161 	x *= M_PI;
162 	return sin(x)/x;
163 }
164 
gentbl_fsk9600(FILE * f)165 static void gentbl_fsk9600(FILE *f)
166 {
167         int i, j, k, l, m;
168 	float s;
169 	float c[44];
170 	float min, max;
171 
172 	fprintf(f, "\n/*\n * fsk9600 specific tables\n */\n");
173 	min = max = 0;
174 	memset(c, 0, sizeof(c));
175 #if 0
176 	memcpy(c+2, fsk96_tx_coeff_4, sizeof(fsk96_tx_coeff_4));
177 #else
178 	for (i = 0; i < 29; i++)
179 		c[3+i] = sinc(1.2*((i-14.0)/4.0))*hamming(i/28.0)/3.5;
180 #endif
181 	fprintf(f, "static unsigned char fsk96_txfilt_4[] = {\n\t");
182 	for (i = 0; i < 4; i++) {
183 		for (j = 0; j < 256; j++) {
184 			for (k = 1, s = 0, l = i; k < 256; k <<= 1) {
185 				if (j & k) {
186 					for (m = 0; m < 4; m++, l++)
187 						s += c[l];
188 				} else {
189 					for (m = 0; m < 4; m++, l++)
190 						s -= c[l];
191 				}
192 			}
193 			s *= 0.75;
194 			if (s > max)
195 				max = s;
196 			if (s < min)
197 				min = s;
198 			fprintf(f, "%4d", (int)(128+127*s));
199 			if (i < 3 || j < 255)
200 				fprintf(f, ",%s", (j & 7) == 7
201 					? "\n\t" : "");
202 		}
203 	}
204 #ifdef VERBOSE
205 	fprintf(stderr, "fsk9600: txfilt4: min = %f; max = %f\n", min, max);
206 #endif
207 	fprintf(f, "\n};\n\n");
208 	min = max = 0;
209 	memset(c, 0, sizeof(c));
210 #if 0
211 	memcpy(c+2, fsk96_tx_coeff_5, sizeof(fsk96_tx_coeff_5));
212 #else
213 	for (i = 0; i < 36; i++)
214 		c[4+i] = sinc(1.2*((i-17.5)/5.0))*hamming(i/35.0)/4.5;
215 #endif
216 	fprintf(f, "static unsigned char fsk96_txfilt_5[] = {\n\t");
217 	for (i = 0; i < 5; i++) {
218 		for (j = 0; j < 256; j++) {
219 			for (k = 1, s = 0, l = i; k < 256; k <<= 1) {
220 				if (j & k) {
221 					for (m = 0; m < 5; m++, l++)
222 						s += c[l];
223 				} else {
224 					for (m = 0; m < 5; m++, l++)
225 						s -= c[l];
226 				}
227 			}
228 			s *= 0.75;
229 			if (s > max)
230 				max = s;
231 			if (s < min)
232 				min = s;
233 			fprintf(f, "%4d", (int)(128+127*s));
234 			if (i < 4 || j < 255)
235 				fprintf(f, ",%s", (j & 7) == 7
236 					? "\n\t" : "");
237 		}
238 	}
239 #ifdef VERBOSE
240 	fprintf(stderr, "fsk9600: txfilt5: min = %f; max = %f\n", min, max);
241 #endif
242 	fprintf(f, "\n};\n\n");
243 }
244 
245 /* -------------------------------------------------------------------- */
246 
247 #define AFSK26_SAMPLERATE  16000
248 
249 #define AFSK26_NUMCAR      2
250 #define AFSK26_FIRSTCAR    2000
251 #define AFSK26_MSK_LEN     6
252 #define AFSK26_RXOVER      2
253 
254 #define AFSK26_DEMCORRLEN (2*AFSK26_MSK_LEN)
255 
256 #define AFSK26_WINDOW(x) ((1-cos(2.0*M_PI*(x)))/2.0)
257 
258 #define AFSK26_AMPL(x) (((x)?1.0:0.7))
259 
260 #undef AFSK26_AMPL
261 #define AFSK26_AMPL(x) 1
262 
gentbl_afsk2666(FILE * f)263 static void gentbl_afsk2666(FILE *f)
264 {
265         int i, j, k, l, o, v, sumi, sumq;
266         float window[AFSK26_DEMCORRLEN*AFSK26_RXOVER];
267 	int cfreq[AFSK26_NUMCAR];
268 
269 	fprintf(f, "\n/*\n * afsk2666 specific tables\n */\n"
270 		"#define AFSK26_DEMCORRLEN %d\n"
271 		"#define AFSK26_SAMPLERATE %d\n\n", AFSK26_DEMCORRLEN,
272 		AFSK26_SAMPLERATE);
273 	fprintf(f, "static const unsigned int afsk26_carfreq[%d] = { ",
274 		AFSK26_NUMCAR);
275 	for (i = 0; i < AFSK26_NUMCAR; i++) {
276 		cfreq[i] = 0x10000*AFSK26_FIRSTCAR/AFSK26_SAMPLERATE+
277 			0x10000*i/AFSK26_MSK_LEN/2;
278 		fprintf(f, "0x%x", cfreq[i]);
279 		if (i < AFSK26_NUMCAR-1)
280 			fprintf(f, ", ");
281 	}
282 	fprintf(f, " };\n\n");
283         for (i = 0; i < AFSK26_DEMCORRLEN*AFSK26_RXOVER; i++)
284                 window[i] = AFSK26_WINDOW(((float)i)/(AFSK26_DEMCORRLEN*
285 						      AFSK26_RXOVER)) * 127.0;
286         fprintf(f, "\nstatic const struct {\n\t"
287                "int i[%d];\n\tint q[%d];\n} afsk26_dem_tables[%d][%d] = {\n",
288                AFSK26_DEMCORRLEN, AFSK26_DEMCORRLEN, AFSK26_RXOVER, AFSK26_NUMCAR);
289         for (o = AFSK26_RXOVER-1; o >= 0; o--) {
290                 fprintf(f, "\t{\n");
291                 for (i = 0; i < AFSK26_NUMCAR; i++) {
292                         j = cfreq[i];
293                         fprintf(f, "\t\t{{ ");
294                         for (l = AFSK26_DEMCORRLEN-1, k = (j * o)/AFSK26_RXOVER, sumi = 0; l >= 0;
295                              l--, k = (k+j)&0xffffu) {
296 				sumi += (v = AFSK26_AMPL(i)*window[l*AFSK26_RXOVER+o]*
297 					 cos(M_PI*k/32768.0));
298                                 fprintf(f, "%6d%s", v, l ? ", " : " }, { ");
299 			}
300                         for (l = AFSK26_DEMCORRLEN-1, k = (j * o)/AFSK26_RXOVER, sumq = 0; l >= 0;
301                              l--, k = (k+j)&0xffffu) {
302 				sumq += (v = AFSK26_AMPL(i)*window[l*AFSK26_RXOVER+o]*
303 					 sin(M_PI*k/32768.0));
304                                 fprintf(f, "%6d%s", v, l ? ", " : " }}");
305 			}
306                         if (i < 1)
307                                 fprintf(f, ",");
308                         fprintf(f, "\n#define AFSK26_DEM_SUM_I_%d_%d %d\n"
309 				"#define AFSK26_DEM_SUM_Q_%d_%d %d\n",
310 				AFSK26_RXOVER-1-o, i, sumi, AFSK26_RXOVER-1-o, i, sumq);
311                 }
312                 fprintf(f, "\t}%s\n", o ? "," : "");
313         }
314         fprintf(f, "};\n\n");
315 }
316 
317 /* -------------------------------------------------------------------- */
318 
319 #define ATAN_TABLEN 1024
320 
gentbl_atantab(FILE * f)321 static void gentbl_atantab(FILE *f)
322 {
323         int i;
324         short x;
325 
326 	fprintf(f, "\n/*\n"
327 		" * arctan table (indexed by i/q; should really be indexed by i/(i+q)\n"
328 		" */\n""#define ATAN_TABLEN %d\n\n"
329 		"static const unsigned short atan_tab[ATAN_TABLEN+2] = {",
330                ATAN_TABLEN);
331         for (i = 0; i <= ATAN_TABLEN; i++) {
332                 if (!(i & 7))
333                         fprintf(f, "\n\t");
334                 x = atan(i / (float)ATAN_TABLEN) / M_PI * 0x8000;
335                 fprintf(f, "%6d, ", x);
336         }
337         fprintf(f, "%6d\n};\n\n", x);
338 
339 }
340 
341 /* -------------------------------------------------------------------- */
342 
343 #define PSK48_TXF_OVERSAMPLING 5
344 #define PSK48_TXF_NUMSAMPLES 16
345 #define PSK48_RXF_LEN     64
346 
347 static const float psk48_tx_coeff[80] = {
348               -0.000379,       -0.000640,       -0.000000,        0.000772,
349                0.000543,       -0.000629,       -0.001187,       -0.000000,
350                0.001634,        0.001183,       -0.001382,       -0.002603,
351               -0.000000,        0.003481,        0.002472,       -0.002828,
352               -0.005215,       -0.000000,        0.006705,        0.004678,
353               -0.005269,       -0.009584,       -0.000000,        0.012065,
354                0.008360,       -0.009375,       -0.017028,       -0.000000,
355                0.021603,        0.015123,       -0.017229,       -0.032012,
356               -0.000000,        0.043774,        0.032544,       -0.040365,
357               -0.084963,       -0.000000,        0.201161,        0.374060,
358                0.374060,        0.201161,       -0.000000,       -0.084963,
359               -0.040365,        0.032544,        0.043774,       -0.000000,
360               -0.032012,       -0.017229,        0.015123,        0.021603,
361               -0.000000,       -0.017028,       -0.009375,        0.008360,
362                0.012065,       -0.000000,       -0.009584,       -0.005269,
363                0.004678,        0.006705,       -0.000000,       -0.005215,
364               -0.002828,        0.002472,        0.003481,       -0.000000,
365               -0.002603,       -0.001382,        0.001183,        0.001634,
366               -0.000000,       -0.001187,       -0.000629,        0.000543,
367                0.000772,       -0.000000,       -0.000640,       -0.000379
368 };
369 
370 static const float psk48_rx_coeff[PSK48_RXF_LEN] = {
371               -0.000219,        0.000360,        0.000873,        0.001080,
372                0.000747,       -0.000192,       -0.001466,       -0.002436,
373               -0.002328,       -0.000699,        0.002101,        0.004809,
374                0.005696,        0.003492,       -0.001633,       -0.007660,
375               -0.011316,       -0.009627,       -0.001780,        0.009712,
376                0.019426,        0.021199,        0.011342,       -0.008583,
377               -0.030955,       -0.044093,       -0.036634,       -0.002651,
378                0.054742,        0.123101,        0.184198,        0.220219,
379                0.220219,        0.184198,        0.123101,        0.054742,
380               -0.002651,       -0.036634,       -0.044093,       -0.030955,
381               -0.008583,        0.011342,        0.021199,        0.019426,
382                0.009712,       -0.001780,       -0.009627,       -0.011316,
383               -0.007660,       -0.001633,        0.003492,        0.005696,
384                0.004809,        0.002101,       -0.000699,       -0.002328,
385               -0.002436,       -0.001466,       -0.000192,        0.000747,
386                0.001080,        0.000873,        0.000360,       -0.000219
387 };
388 
gentbl_psk4800(FILE * f)389 static void gentbl_psk4800(FILE *f)
390 {
391         int i, j, k;
392         short x;
393 
394 	fprintf(f, "\n/*\n * psk4800 specific tables\n */\n"
395 		"#define PSK48_TXF_OVERSAMPLING %d\n"
396 		"#define PSK48_TXF_NUMSAMPLES %d\n\n"
397 		"#define PSK48_SAMPLERATE  8000\n"
398 		"#define PSK48_CAR_FREQ    2000\n"
399 		"#define PSK48_PSK_LEN     5\n"
400 		"#define PSK48_RXF_LEN     %u\n"
401 		"#define PSK48_PHASEINC    (0x10000*PSK48_CAR_FREQ/PSK48_SAMPLERATE)\n"
402 		"#define PSK48_SPHASEINC   (0x10000/(2*PSK48_PSK_LEN))\n\n"
403 		"static const short psk48_tx_table[PSK48_TXF_OVERSAMPLING*"
404 		"PSK48_TXF_NUMSAMPLES*8*2] = {",
405 		PSK48_TXF_OVERSAMPLING, PSK48_TXF_NUMSAMPLES, PSK48_RXF_LEN);
406         for (i = 0; i < PSK48_TXF_OVERSAMPLING; i++) {
407                 for (j = 0; j < PSK48_TXF_NUMSAMPLES; j++) {
408                         fprintf(f, "\n\t");
409                         for (k = 0; k < 8; k++) {
410                                 x = 32767.0 * cos(k*M_PI/4.0) *
411                                         psk48_tx_coeff[j * PSK48_TXF_OVERSAMPLING + i];
412                                 fprintf(f, "%6d, ", x);
413                         }
414                         fprintf(f, "\n\t");
415                         for (k = 0; k < 8; k++) {
416                                 x = 32767.0 * sin(k*M_PI/4.0) *
417                                         psk48_tx_coeff[j * PSK48_TXF_OVERSAMPLING + i];
418                                 fprintf(f, "%6d", x);
419                                 if (k != 7 || j != PSK48_TXF_NUMSAMPLES-1 ||
420                                     i != PSK48_TXF_OVERSAMPLING-1)
421                                         fprintf(f, ", ");
422                         }
423                 }
424         }
425         fprintf(f, "\n};\n\n");
426 
427 	fprintf(f, "static const short psk48_rx_coeff[PSK48_RXF_LEN] = {\n\t");
428 	for (i = 0; i < PSK48_RXF_LEN; i++) {
429 		fprintf(f, "%6d", (int)(psk48_rx_coeff[i]*32767.0));
430 		if (i < PSK48_RXF_LEN-1)
431 			fprintf(f, ",%s", (i & 7) == 7 ? "\n\t" : "");
432 	}
433 	fprintf(f, "\n};\n\n");
434 }
435 
436 /* -------------------------------------------------------------------- */
437 
gentbl_hapn4800(FILE * f)438 static void gentbl_hapn4800(FILE *f)
439 {
440         int i, j, k, l;
441 	float s;
442 	float c[44];
443 	float min, max;
444 
445 	fprintf(f, "\n/*\n * hapn4800 specific tables\n */\n\n");
446 	/*
447 	 * firstly generate tables for the FM transmitter modulator
448 	 */
449 	min = max = 0;
450 	memset(c, 0, sizeof(c));
451 	for (i = 0; i < 24; i++)
452 		c[8+i] = sinc(1.5*((i-11.5)/8.0))*hamming(i/23.0)/2.4;
453 	for (i = 0; i < 24; i++)
454 		c[i] -= c[i+8];
455 	fprintf(f, "static unsigned char hapn48_txfilt_8[] = {\n\t");
456 	for (i = 0; i < 8; i++) {
457 		for (j = 0; j < 16; j++) {
458 			for (k = 1, s = 0, l = i; k < 16; k <<= 1, l += 8) {
459 				if (j & k)
460 					s += c[l];
461 				else
462 					s -= c[l];
463 			}
464 			if (s > max)
465 				max = s;
466 			if (s < min)
467 				min = s;
468 			fprintf(f, "%4d", (int)(128+127*s));
469 			if (i < 7 || j < 15)
470 				fprintf(f, ",%s", (j & 7) == 7
471 					? "\n\t" : "");
472 		}
473 	}
474 #ifdef VERBOSE
475 	fprintf(stderr, "hapn4800: txfilt8: min = %f; max = %f\n", min, max);
476 #endif
477 	fprintf(f, "\n};\n\n");
478 	min = max = 0;
479 	memset(c, 0, sizeof(c));
480 	for (i = 0; i < 30; i++)
481 		c[10+i] = sinc(1.5*((i-14.5)/10.0))*hamming(i/29.0)/2.4;
482 	for (i = 0; i < 30; i++)
483 		c[i] -= c[i+10];
484 	fprintf(f, "static unsigned char hapn48_txfilt_10[] = {\n\t");
485 	for (i = 0; i < 10; i++) {
486 		for (j = 0; j < 16; j++) {
487 			for (k = 1, s = 0, l = i; k < 16; k <<= 1, l += 10) {
488 				if (j & k)
489 					s += c[l];
490 				else
491 					s -= c[l];
492 			}
493 			if (s > max)
494 				max = s;
495 			if (s < min)
496 				min = s;
497 			fprintf(f, "%4d", (int)(128+127*s));
498 			if (i < 9 || j < 15)
499 				fprintf(f, ",%s", (j & 7) == 7
500 					? "\n\t" : "");
501 		}
502 	}
503 #ifdef VERBOSE
504 	fprintf(stderr, "hapn4800: txfilt10: min = %f; max = %f\n", min, max);
505 #endif
506 	fprintf(f, "\n};\n\n");
507 	/*
508 	 * secondly generate tables for the PM transmitter modulator
509 	 */
510 	min = max = 0;
511 	memset(c, 0, sizeof(c));
512 	for (i = 0; i < 25; i++)
513 		c[i] = sinc(1.4*((i-12.0)/8.0))*hamming(i/24.0)/6.3;
514 	for (i = 0; i < 25; i++)
515 		for (j = 1; j < 8; j++)
516 			c[i] += c[i+j];
517 	fprintf(f, "static unsigned char hapn48_txfilt_pm8[] = {\n\t");
518 	for (i = 0; i < 8; i++) {
519 		for (j = 0; j < 16; j++) {
520 			for (k = 1, s = 0, l = i; k < 16; k <<= 1, l += 8) {
521 				if (j & k)
522 					s += c[l];
523 				else
524 					s -= c[l];
525 			}
526 			if (s > max)
527 				max = s;
528 			if (s < min)
529 				min = s;
530 			fprintf(f, "%4d", (int)(128+127*s));
531 			if (i < 7 || j < 15)
532 				fprintf(f, ",%s", (j & 7) == 7
533 					? "\n\t" : "");
534 		}
535 	}
536 #ifdef VERBOSE
537 	fprintf(stderr, "hapn4800: txfiltpm8: min = %f; max = %f\n", min, max);
538 #endif
539 	fprintf(f, "\n};\n\n");
540 	min = max = 0;
541 	memset(c, 0, sizeof(c));
542 	for (i = 0; i < 31; i++)
543 		c[10+i] = sinc(1.4*((i-15.0)/10.0))*hamming(i/30.0)/7.9;
544 	for (i = 0; i < 31; i++)
545 		for (j = 1; j < 10; j++)
546 			c[i] += c[i+j];
547 	fprintf(f, "static unsigned char hapn48_txfilt_pm10[] = {\n\t");
548 	for (i = 0; i < 10; i++) {
549 		for (j = 0; j < 16; j++) {
550 			for (k = 1, s = 0, l = i; k < 16; k <<= 1, l += 10) {
551 				if (j & k)
552 					s += c[l];
553 				else
554 					s -= c[l];
555 			}
556 			if (s > max)
557 				max = s;
558 			if (s < min)
559 				min = s;
560 			fprintf(f, "%4d", (int)(128+127*s));
561 			if (i < 9 || j < 15)
562 				fprintf(f, ",%s", (j & 7) == 7
563 					? "\n\t" : "");
564 		}
565 	}
566 #ifdef VERBOSE
567 	fprintf(stderr, "hapn4800: txfiltpm10: min = %f; max = %f\n", min, max);
568 #endif
569 	fprintf(f, "\n};\n\n");
570 
571 }
572 
573 /* -------------------------------------------------------------------- */
574 
575 #define AFSK24_SAMPLERATE  16000
576 #define AFSK24_CORRLEN     14
577 
gentbl_afsk2400(FILE * f,float tcm3105clk)578 static void gentbl_afsk2400(FILE *f, float tcm3105clk)
579 {
580 	int i, sum, v;
581 
582 	fprintf(f, "\n/*\n * afsk2400 specific tables (tcm3105 clk %7fHz)\n */\n"
583 		"#define AFSK24_TX_FREQ_LO %d\n"
584 		"#define AFSK24_TX_FREQ_HI %d\n"
585 		"#define AFSK24_BITPLL_INC %d\n"
586 		"#define AFSK24_SAMPLERATE %d\n\n", tcm3105clk,
587 		(int)(tcm3105clk/3694.0), (int)(tcm3105clk/2015.0),
588 		0x10000*2400/AFSK24_SAMPLERATE, AFSK24_SAMPLERATE);
589 
590 #define ARGLO(x) 2.0*M_PI*(double)x*(tcm3105clk/3694.0)/(double)AFSK24_SAMPLERATE
591 #define ARGHI(x) 2.0*M_PI*(double)x*(tcm3105clk/2015.0)/(double)AFSK24_SAMPLERATE
592 #define WINDOW(x) hamming((float)(x)/(AFSK24_CORRLEN-1.0))
593 
594 	fprintf(f, "static const int afsk24_tx_lo_i[] = {\n\t");
595         for(sum = i = 0; i < AFSK24_CORRLEN; i++) {
596 		sum += (v = 127.0*cos(ARGLO(i))*WINDOW(i));
597                 fprintf(f, " %4i%c", v, (i < AFSK24_CORRLEN-1) ? ',' : ' ');
598 	}
599         fprintf(f, "\n};\n#define SUM_AFSK24_TX_LO_I %d\n\n"
600 		"static const int afsk24_tx_lo_q[] = {\n\t", sum);
601         for(sum = i = 0; i < AFSK24_CORRLEN; i++) {
602 		sum += (v = 127.0*sin(ARGLO(i))*WINDOW(i));
603                 fprintf(f, " %4i%c", v, (i < AFSK24_CORRLEN-1) ? ',' : ' ');
604 	}
605         fprintf(f, "\n};\n#define SUM_AFSK24_TX_LO_Q %d\n\n"
606 		"static const int afsk24_tx_hi_i[] = {\n\t", sum);
607         for(sum = i = 0; i < AFSK24_CORRLEN; i++) {
608 		sum += (v = 127.0*cos(ARGHI(i))*WINDOW(i));
609                 fprintf(f, " %4i%c", v, (i < AFSK24_CORRLEN-1) ? ',' : ' ');
610 	}
611         fprintf(f, "\n};\n#define SUM_AFSK24_TX_HI_I %d\n\n"
612 		"static const int afsk24_tx_hi_q[] = {\n\t", sum);
613         for(sum = i = 0; i < AFSK24_CORRLEN; i++)  {
614 		sum += (v = 127.0*sin(ARGHI(i))*WINDOW(i));
615                 fprintf(f, " %4i%c", v, (i < AFSK24_CORRLEN-1) ? ',' : ' ');
616 	}
617 	fprintf(f, "\n};\n#define SUM_AFSK24_TX_HI_Q %d\n\n", sum);
618 #undef ARGLO
619 #undef ARGHI
620 #undef WINDOW
621 }
622 
623 /* -------------------------------------------------------------------- */
624 
625 static char *progname;
626 
gentbl_banner(FILE * f)627 static void gentbl_banner(FILE *f)
628 {
629 	fprintf(f, "/*\n * THIS FILE IS GENERATED AUTOMATICALLY BY %s, "
630 		"DO NOT EDIT!\n */\n\n", progname);
631 }
632 
633 /* -------------------------------------------------------------------- */
634 
main(int argc,char * argv[])635 int main(int argc, char *argv[])
636 {
637 	FILE *f;
638 
639 	progname = argv[0];
640 	if (!(f = fopen("sm_tbl_afsk1200.h", "w")))
641 		exit(1);
642 	gentbl_banner(f);
643 	gentbl_offscostab(f, 6);
644 	gentbl_costab(f, 6);
645 	gentbl_afsk1200(f);
646 	fclose(f);
647 	if (!(f = fopen("sm_tbl_afsk2666.h", "w")))
648 		exit(1);
649 	gentbl_banner(f);
650 	gentbl_offscostab(f, 6);
651 	gentbl_costab(f, 6);
652 	gentbl_afsk2666(f);
653 	fclose(f);
654 	if (!(f = fopen("sm_tbl_psk4800.h", "w")))
655 		exit(1);
656 	gentbl_banner(f);
657 	gentbl_psk4800(f);
658 	gentbl_costab(f, 8);
659 	gentbl_atantab(f);
660 	fclose(f);
661 	if (!(f = fopen("sm_tbl_hapn4800.h", "w")))
662 		exit(1);
663 	gentbl_banner(f);
664 	gentbl_hapn4800(f);
665 	fclose(f);
666 	if (!(f = fopen("sm_tbl_fsk9600.h", "w")))
667 		exit(1);
668 	gentbl_banner(f);
669 	gentbl_fsk9600(f);
670 	fclose(f);
671 	if (!(f = fopen("sm_tbl_afsk2400_8.h", "w")))
672 		exit(1);
673 	gentbl_banner(f);
674 	gentbl_offscostab(f, 6);
675 	gentbl_costab(f, 6);
676 	gentbl_afsk2400(f, 8000000);
677 	fclose(f);
678 	if (!(f = fopen("sm_tbl_afsk2400_7.h", "w")))
679 		exit(1);
680 	gentbl_banner(f);
681 	gentbl_offscostab(f, 6);
682 	gentbl_costab(f, 6);
683 	gentbl_afsk2400(f, 7372800);
684 	fclose(f);
685 	exit(0);
686 }
687 
688 
689 /* -------------------------------------------------------------------- */
690