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
35static 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
57static 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
82static 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
126static 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
137static 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
152static inline float hamming(float x)
153{
154	return 0.54-0.46*cos(2*M_PI*x);
155}
156
157static inline float sinc(float x)
158{
159	if (x == 0)
160		return 1;
161	x *= M_PI;
162	return sin(x)/x;
163}
164
165static 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	for (i = 0; i < 29; i++)
176		c[3+i] = sinc(1.2*((i-14.0)/4.0))*hamming(i/28.0)/3.5;
177	fprintf(f, "static unsigned char fsk96_txfilt_4[] = {\n\t");
178	for (i = 0; i < 4; i++) {
179		for (j = 0; j < 256; j++) {
180			for (k = 1, s = 0, l = i; k < 256; k <<= 1) {
181				if (j & k) {
182					for (m = 0; m < 4; m++, l++)
183						s += c[l];
184				} else {
185					for (m = 0; m < 4; m++, l++)
186						s -= c[l];
187				}
188			}
189			s *= 0.75;
190			if (s > max)
191				max = s;
192			if (s < min)
193				min = s;
194			fprintf(f, "%4d", (int)(128+127*s));
195			if (i < 3 || j < 255)
196				fprintf(f, ",%s", (j & 7) == 7
197					? "\n\t" : "");
198		}
199	}
200#ifdef VERBOSE
201	fprintf(stderr, "fsk9600: txfilt4: min = %f; max = %f\n", min, max);
202#endif
203	fprintf(f, "\n};\n\n");
204	min = max = 0;
205	memset(c, 0, sizeof(c));
206	for (i = 0; i < 36; i++)
207		c[4+i] = sinc(1.2*((i-17.5)/5.0))*hamming(i/35.0)/4.5;
208	fprintf(f, "static unsigned char fsk96_txfilt_5[] = {\n\t");
209	for (i = 0; i < 5; i++) {
210		for (j = 0; j < 256; j++) {
211			for (k = 1, s = 0, l = i; k < 256; k <<= 1) {
212				if (j & k) {
213					for (m = 0; m < 5; m++, l++)
214						s += c[l];
215				} else {
216					for (m = 0; m < 5; m++, l++)
217						s -= c[l];
218				}
219			}
220			s *= 0.75;
221			if (s > max)
222				max = s;
223			if (s < min)
224				min = s;
225			fprintf(f, "%4d", (int)(128+127*s));
226			if (i < 4 || j < 255)
227				fprintf(f, ",%s", (j & 7) == 7
228					? "\n\t" : "");
229		}
230	}
231#ifdef VERBOSE
232	fprintf(stderr, "fsk9600: txfilt5: min = %f; max = %f\n", min, max);
233#endif
234	fprintf(f, "\n};\n\n");
235}
236
237/* -------------------------------------------------------------------- */
238
239#define AFSK26_SAMPLERATE  16000
240
241#define AFSK26_NUMCAR      2
242#define AFSK26_FIRSTCAR    2000
243#define AFSK26_MSK_LEN     6
244#define AFSK26_RXOVER      2
245
246#define AFSK26_DEMCORRLEN (2*AFSK26_MSK_LEN)
247
248#define AFSK26_WINDOW(x) ((1-cos(2.0*M_PI*(x)))/2.0)
249
250#define AFSK26_AMPL(x) (((x)?1.0:0.7))
251
252#undef AFSK26_AMPL
253#define AFSK26_AMPL(x) 1
254
255static void gentbl_afsk2666(FILE *f)
256{
257        int i, j, k, l, o, v, sumi, sumq;
258        float window[AFSK26_DEMCORRLEN*AFSK26_RXOVER];
259	int cfreq[AFSK26_NUMCAR];
260
261	fprintf(f, "\n/*\n * afsk2666 specific tables\n */\n"
262		"#define AFSK26_DEMCORRLEN %d\n"
263		"#define AFSK26_SAMPLERATE %d\n\n", AFSK26_DEMCORRLEN,
264		AFSK26_SAMPLERATE);
265	fprintf(f, "static const unsigned int afsk26_carfreq[%d] = { ",
266		AFSK26_NUMCAR);
267	for (i = 0; i < AFSK26_NUMCAR; i++) {
268		cfreq[i] = 0x10000*AFSK26_FIRSTCAR/AFSK26_SAMPLERATE+
269			0x10000*i/AFSK26_MSK_LEN/2;
270		fprintf(f, "0x%x", cfreq[i]);
271		if (i < AFSK26_NUMCAR-1)
272			fprintf(f, ", ");
273	}
274	fprintf(f, " };\n\n");
275        for (i = 0; i < AFSK26_DEMCORRLEN*AFSK26_RXOVER; i++)
276                window[i] = AFSK26_WINDOW(((float)i)/(AFSK26_DEMCORRLEN*
277						      AFSK26_RXOVER)) * 127.0;
278        fprintf(f, "\nstatic const struct {\n\t"
279               "int i[%d];\n\tint q[%d];\n} afsk26_dem_tables[%d][%d] = {\n",
280               AFSK26_DEMCORRLEN, AFSK26_DEMCORRLEN, AFSK26_RXOVER, AFSK26_NUMCAR);
281        for (o = AFSK26_RXOVER-1; o >= 0; o--) {
282                fprintf(f, "\t{\n");
283                for (i = 0; i < AFSK26_NUMCAR; i++) {
284                        j = cfreq[i];
285                        fprintf(f, "\t\t{{ ");
286                        for (l = AFSK26_DEMCORRLEN-1, k = (j * o)/AFSK26_RXOVER, sumi = 0; l >= 0;
287                             l--, k = (k+j)&0xffffu) {
288				sumi += (v = AFSK26_AMPL(i)*window[l*AFSK26_RXOVER+o]*
289					 cos(M_PI*k/32768.0));
290                                fprintf(f, "%6d%s", v, l ? ", " : " }, { ");
291			}
292                        for (l = AFSK26_DEMCORRLEN-1, k = (j * o)/AFSK26_RXOVER, sumq = 0; l >= 0;
293                             l--, k = (k+j)&0xffffu) {
294				sumq += (v = AFSK26_AMPL(i)*window[l*AFSK26_RXOVER+o]*
295					 sin(M_PI*k/32768.0));
296                                fprintf(f, "%6d%s", v, l ? ", " : " }}");
297			}
298                        if (i < 1)
299                                fprintf(f, ",");
300                        fprintf(f, "\n#define AFSK26_DEM_SUM_I_%d_%d %d\n"
301				"#define AFSK26_DEM_SUM_Q_%d_%d %d\n",
302				AFSK26_RXOVER-1-o, i, sumi, AFSK26_RXOVER-1-o, i, sumq);
303                }
304                fprintf(f, "\t}%s\n", o ? "," : "");
305        }
306        fprintf(f, "};\n\n");
307}
308
309/* -------------------------------------------------------------------- */
310
311#define ATAN_TABLEN 1024
312
313static void gentbl_atantab(FILE *f)
314{
315        int i;
316        short x;
317
318	fprintf(f, "\n/*\n"
319		" * arctan table (indexed by i/q; should really be indexed by i/(i+q)\n"
320		" */\n""#define ATAN_TABLEN %d\n\n"
321		"static const unsigned short atan_tab[ATAN_TABLEN+2] = {",
322               ATAN_TABLEN);
323        for (i = 0; i <= ATAN_TABLEN; i++) {
324                if (!(i & 7))
325                        fprintf(f, "\n\t");
326                x = atan(i / (float)ATAN_TABLEN) / M_PI * 0x8000;
327                fprintf(f, "%6d, ", x);
328        }
329        fprintf(f, "%6d\n};\n\n", x);
330
331}
332
333/* -------------------------------------------------------------------- */
334
335#define PSK48_TXF_OVERSAMPLING 5
336#define PSK48_TXF_NUMSAMPLES 16
337#define PSK48_RXF_LEN     64
338
339static const float psk48_tx_coeff[80] = {
340              -0.000379,       -0.000640,       -0.000000,        0.000772,
341               0.000543,       -0.000629,       -0.001187,       -0.000000,
342               0.001634,        0.001183,       -0.001382,       -0.002603,
343              -0.000000,        0.003481,        0.002472,       -0.002828,
344              -0.005215,       -0.000000,        0.006705,        0.004678,
345              -0.005269,       -0.009584,       -0.000000,        0.012065,
346               0.008360,       -0.009375,       -0.017028,       -0.000000,
347               0.021603,        0.015123,       -0.017229,       -0.032012,
348              -0.000000,        0.043774,        0.032544,       -0.040365,
349              -0.084963,       -0.000000,        0.201161,        0.374060,
350               0.374060,        0.201161,       -0.000000,       -0.084963,
351              -0.040365,        0.032544,        0.043774,       -0.000000,
352              -0.032012,       -0.017229,        0.015123,        0.021603,
353              -0.000000,       -0.017028,       -0.009375,        0.008360,
354               0.012065,       -0.000000,       -0.009584,       -0.005269,
355               0.004678,        0.006705,       -0.000000,       -0.005215,
356              -0.002828,        0.002472,        0.003481,       -0.000000,
357              -0.002603,       -0.001382,        0.001183,        0.001634,
358              -0.000000,       -0.001187,       -0.000629,        0.000543,
359               0.000772,       -0.000000,       -0.000640,       -0.000379
360};
361
362static const float psk48_rx_coeff[PSK48_RXF_LEN] = {
363              -0.000219,        0.000360,        0.000873,        0.001080,
364               0.000747,       -0.000192,       -0.001466,       -0.002436,
365              -0.002328,       -0.000699,        0.002101,        0.004809,
366               0.005696,        0.003492,       -0.001633,       -0.007660,
367              -0.011316,       -0.009627,       -0.001780,        0.009712,
368               0.019426,        0.021199,        0.011342,       -0.008583,
369              -0.030955,       -0.044093,       -0.036634,       -0.002651,
370               0.054742,        0.123101,        0.184198,        0.220219,
371               0.220219,        0.184198,        0.123101,        0.054742,
372              -0.002651,       -0.036634,       -0.044093,       -0.030955,
373              -0.008583,        0.011342,        0.021199,        0.019426,
374               0.009712,       -0.001780,       -0.009627,       -0.011316,
375              -0.007660,       -0.001633,        0.003492,        0.005696,
376               0.004809,        0.002101,       -0.000699,       -0.002328,
377              -0.002436,       -0.001466,       -0.000192,        0.000747,
378               0.001080,        0.000873,        0.000360,       -0.000219
379};
380
381static void gentbl_psk4800(FILE *f)
382{
383        int i, j, k;
384        short x;
385
386	fprintf(f, "\n/*\n * psk4800 specific tables\n */\n"
387		"#define PSK48_TXF_OVERSAMPLING %d\n"
388		"#define PSK48_TXF_NUMSAMPLES %d\n\n"
389		"#define PSK48_SAMPLERATE  8000\n"
390		"#define PSK48_CAR_FREQ    2000\n"
391		"#define PSK48_PSK_LEN     5\n"
392		"#define PSK48_RXF_LEN     %u\n"
393		"#define PSK48_PHASEINC    (0x10000*PSK48_CAR_FREQ/PSK48_SAMPLERATE)\n"
394		"#define PSK48_SPHASEINC   (0x10000/(2*PSK48_PSK_LEN))\n\n"
395		"static const short psk48_tx_table[PSK48_TXF_OVERSAMPLING*"
396		"PSK48_TXF_NUMSAMPLES*8*2] = {",
397		PSK48_TXF_OVERSAMPLING, PSK48_TXF_NUMSAMPLES, PSK48_RXF_LEN);
398        for (i = 0; i < PSK48_TXF_OVERSAMPLING; i++) {
399                for (j = 0; j < PSK48_TXF_NUMSAMPLES; j++) {
400                        fprintf(f, "\n\t");
401                        for (k = 0; k < 8; k++) {
402                                x = 32767.0 * cos(k*M_PI/4.0) *
403                                        psk48_tx_coeff[j * PSK48_TXF_OVERSAMPLING + i];
404                                fprintf(f, "%6d, ", x);
405                        }
406                        fprintf(f, "\n\t");
407                        for (k = 0; k < 8; k++) {
408                                x = 32767.0 * sin(k*M_PI/4.0) *
409                                        psk48_tx_coeff[j * PSK48_TXF_OVERSAMPLING + i];
410                                fprintf(f, "%6d", x);
411                                if (k != 7 || j != PSK48_TXF_NUMSAMPLES-1 ||
412                                    i != PSK48_TXF_OVERSAMPLING-1)
413                                        fprintf(f, ", ");
414                        }
415                }
416        }
417        fprintf(f, "\n};\n\n");
418
419	fprintf(f, "static const short psk48_rx_coeff[PSK48_RXF_LEN] = {\n\t");
420	for (i = 0; i < PSK48_RXF_LEN; i++) {
421		fprintf(f, "%6d", (int)(psk48_rx_coeff[i]*32767.0));
422		if (i < PSK48_RXF_LEN-1)
423			fprintf(f, ",%s", (i & 7) == 7 ? "\n\t" : "");
424	}
425	fprintf(f, "\n};\n\n");
426}
427
428/* -------------------------------------------------------------------- */
429
430static void gentbl_hapn4800(FILE *f)
431{
432        int i, j, k, l;
433	float s;
434	float c[44];
435	float min, max;
436
437	fprintf(f, "\n/*\n * hapn4800 specific tables\n */\n\n");
438	/*
439	 * firstly generate tables for the FM transmitter modulator
440	 */
441	min = max = 0;
442	memset(c, 0, sizeof(c));
443	for (i = 0; i < 24; i++)
444		c[8+i] = sinc(1.5*((i-11.5)/8.0))*hamming(i/23.0)/2.4;
445	for (i = 0; i < 24; i++)
446		c[i] -= c[i+8];
447	fprintf(f, "static unsigned char hapn48_txfilt_8[] = {\n\t");
448	for (i = 0; i < 8; i++) {
449		for (j = 0; j < 16; j++) {
450			for (k = 1, s = 0, l = i; k < 16; k <<= 1, l += 8) {
451				if (j & k)
452					s += c[l];
453				else
454					s -= c[l];
455			}
456			if (s > max)
457				max = s;
458			if (s < min)
459				min = s;
460			fprintf(f, "%4d", (int)(128+127*s));
461			if (i < 7 || j < 15)
462				fprintf(f, ",%s", (j & 7) == 7
463					? "\n\t" : "");
464		}
465	}
466#ifdef VERBOSE
467	fprintf(stderr, "hapn4800: txfilt8: min = %f; max = %f\n", min, max);
468#endif
469	fprintf(f, "\n};\n\n");
470	min = max = 0;
471	memset(c, 0, sizeof(c));
472	for (i = 0; i < 30; i++)
473		c[10+i] = sinc(1.5*((i-14.5)/10.0))*hamming(i/29.0)/2.4;
474	for (i = 0; i < 30; i++)
475		c[i] -= c[i+10];
476	fprintf(f, "static unsigned char hapn48_txfilt_10[] = {\n\t");
477	for (i = 0; i < 10; i++) {
478		for (j = 0; j < 16; j++) {
479			for (k = 1, s = 0, l = i; k < 16; k <<= 1, l += 10) {
480				if (j & k)
481					s += c[l];
482				else
483					s -= c[l];
484			}
485			if (s > max)
486				max = s;
487			if (s < min)
488				min = s;
489			fprintf(f, "%4d", (int)(128+127*s));
490			if (i < 9 || j < 15)
491				fprintf(f, ",%s", (j & 7) == 7
492					? "\n\t" : "");
493		}
494	}
495#ifdef VERBOSE
496	fprintf(stderr, "hapn4800: txfilt10: min = %f; max = %f\n", min, max);
497#endif
498	fprintf(f, "\n};\n\n");
499	/*
500	 * secondly generate tables for the PM transmitter modulator
501	 */
502	min = max = 0;
503	memset(c, 0, sizeof(c));
504	for (i = 0; i < 25; i++)
505		c[i] = sinc(1.4*((i-12.0)/8.0))*hamming(i/24.0)/6.3;
506	for (i = 0; i < 25; i++)
507		for (j = 1; j < 8; j++)
508			c[i] += c[i+j];
509	fprintf(f, "static unsigned char hapn48_txfilt_pm8[] = {\n\t");
510	for (i = 0; i < 8; i++) {
511		for (j = 0; j < 16; j++) {
512			for (k = 1, s = 0, l = i; k < 16; k <<= 1, l += 8) {
513				if (j & k)
514					s += c[l];
515				else
516					s -= c[l];
517			}
518			if (s > max)
519				max = s;
520			if (s < min)
521				min = s;
522			fprintf(f, "%4d", (int)(128+127*s));
523			if (i < 7 || j < 15)
524				fprintf(f, ",%s", (j & 7) == 7
525					? "\n\t" : "");
526		}
527	}
528#ifdef VERBOSE
529	fprintf(stderr, "hapn4800: txfiltpm8: min = %f; max = %f\n", min, max);
530#endif
531	fprintf(f, "\n};\n\n");
532	min = max = 0;
533	memset(c, 0, sizeof(c));
534	for (i = 0; i < 31; i++)
535		c[10+i] = sinc(1.4*((i-15.0)/10.0))*hamming(i/30.0)/7.9;
536	for (i = 0; i < 31; i++)
537		for (j = 1; j < 10; j++)
538			c[i] += c[i+j];
539	fprintf(f, "static unsigned char hapn48_txfilt_pm10[] = {\n\t");
540	for (i = 0; i < 10; i++) {
541		for (j = 0; j < 16; j++) {
542			for (k = 1, s = 0, l = i; k < 16; k <<= 1, l += 10) {
543				if (j & k)
544					s += c[l];
545				else
546					s -= c[l];
547			}
548			if (s > max)
549				max = s;
550			if (s < min)
551				min = s;
552			fprintf(f, "%4d", (int)(128+127*s));
553			if (i < 9 || j < 15)
554				fprintf(f, ",%s", (j & 7) == 7
555					? "\n\t" : "");
556		}
557	}
558#ifdef VERBOSE
559	fprintf(stderr, "hapn4800: txfiltpm10: min = %f; max = %f\n", min, max);
560#endif
561	fprintf(f, "\n};\n\n");
562
563}
564
565/* -------------------------------------------------------------------- */
566
567#define AFSK24_SAMPLERATE  16000
568#define AFSK24_CORRLEN     14
569
570static void gentbl_afsk2400(FILE *f, float tcm3105clk)
571{
572	int i, sum, v;
573
574	fprintf(f, "\n/*\n * afsk2400 specific tables (tcm3105 clk %7fHz)\n */\n"
575		"#define AFSK24_TX_FREQ_LO %d\n"
576		"#define AFSK24_TX_FREQ_HI %d\n"
577		"#define AFSK24_BITPLL_INC %d\n"
578		"#define AFSK24_SAMPLERATE %d\n\n", tcm3105clk,
579		(int)(tcm3105clk/3694.0), (int)(tcm3105clk/2015.0),
580		0x10000*2400/AFSK24_SAMPLERATE, AFSK24_SAMPLERATE);
581
582#define ARGLO(x) 2.0*M_PI*(double)x*(tcm3105clk/3694.0)/(double)AFSK24_SAMPLERATE
583#define ARGHI(x) 2.0*M_PI*(double)x*(tcm3105clk/2015.0)/(double)AFSK24_SAMPLERATE
584#define WINDOW(x) hamming((float)(x)/(AFSK24_CORRLEN-1.0))
585
586	fprintf(f, "static const int afsk24_tx_lo_i[] = {\n\t");
587        for(sum = i = 0; i < AFSK24_CORRLEN; i++) {
588		sum += (v = 127.0*cos(ARGLO(i))*WINDOW(i));
589                fprintf(f, " %4i%c", v, (i < AFSK24_CORRLEN-1) ? ',' : ' ');
590	}
591        fprintf(f, "\n};\n#define SUM_AFSK24_TX_LO_I %d\n\n"
592		"static const int afsk24_tx_lo_q[] = {\n\t", sum);
593        for(sum = i = 0; i < AFSK24_CORRLEN; i++) {
594		sum += (v = 127.0*sin(ARGLO(i))*WINDOW(i));
595                fprintf(f, " %4i%c", v, (i < AFSK24_CORRLEN-1) ? ',' : ' ');
596	}
597        fprintf(f, "\n};\n#define SUM_AFSK24_TX_LO_Q %d\n\n"
598		"static const int afsk24_tx_hi_i[] = {\n\t", sum);
599        for(sum = i = 0; i < AFSK24_CORRLEN; i++) {
600		sum += (v = 127.0*cos(ARGHI(i))*WINDOW(i));
601                fprintf(f, " %4i%c", v, (i < AFSK24_CORRLEN-1) ? ',' : ' ');
602	}
603        fprintf(f, "\n};\n#define SUM_AFSK24_TX_HI_I %d\n\n"
604		"static const int afsk24_tx_hi_q[] = {\n\t", sum);
605        for(sum = i = 0; i < AFSK24_CORRLEN; i++)  {
606		sum += (v = 127.0*sin(ARGHI(i))*WINDOW(i));
607                fprintf(f, " %4i%c", v, (i < AFSK24_CORRLEN-1) ? ',' : ' ');
608	}
609	fprintf(f, "\n};\n#define SUM_AFSK24_TX_HI_Q %d\n\n", sum);
610#undef ARGLO
611#undef ARGHI
612#undef WINDOW
613}
614
615/* -------------------------------------------------------------------- */
616
617static char *progname;
618
619static void gentbl_banner(FILE *f)
620{
621	fprintf(f, "/*\n * THIS FILE IS GENERATED AUTOMATICALLY BY %s, "
622		"DO NOT EDIT!\n */\n\n", progname);
623}
624
625/* -------------------------------------------------------------------- */
626
627int main(int argc, char *argv[])
628{
629	FILE *f;
630
631	progname = argv[0];
632	if (!(f = fopen("sm_tbl_afsk1200.h", "w")))
633		exit(1);
634	gentbl_banner(f);
635	gentbl_offscostab(f, 6);
636	gentbl_costab(f, 6);
637	gentbl_afsk1200(f);
638	fclose(f);
639	if (!(f = fopen("sm_tbl_afsk2666.h", "w")))
640		exit(1);
641	gentbl_banner(f);
642	gentbl_offscostab(f, 6);
643	gentbl_costab(f, 6);
644	gentbl_afsk2666(f);
645	fclose(f);
646	if (!(f = fopen("sm_tbl_psk4800.h", "w")))
647		exit(1);
648	gentbl_banner(f);
649	gentbl_psk4800(f);
650	gentbl_costab(f, 8);
651	gentbl_atantab(f);
652	fclose(f);
653	if (!(f = fopen("sm_tbl_hapn4800.h", "w")))
654		exit(1);
655	gentbl_banner(f);
656	gentbl_hapn4800(f);
657	fclose(f);
658	if (!(f = fopen("sm_tbl_fsk9600.h", "w")))
659		exit(1);
660	gentbl_banner(f);
661	gentbl_fsk9600(f);
662	fclose(f);
663	if (!(f = fopen("sm_tbl_afsk2400_8.h", "w")))
664		exit(1);
665	gentbl_banner(f);
666	gentbl_offscostab(f, 6);
667	gentbl_costab(f, 6);
668	gentbl_afsk2400(f, 8000000);
669	fclose(f);
670	if (!(f = fopen("sm_tbl_afsk2400_7.h", "w")))
671		exit(1);
672	gentbl_banner(f);
673	gentbl_offscostab(f, 6);
674	gentbl_costab(f, 6);
675	gentbl_afsk2400(f, 7372800);
676	fclose(f);
677	exit(0);
678}
679
680
681/* -------------------------------------------------------------------- */
682