📄 gentbl.c
字号:
static const float psk48_tx_coeff[80] = { -0.000379, -0.000640, -0.000000, 0.000772, 0.000543, -0.000629, -0.001187, -0.000000, 0.001634, 0.001183, -0.001382, -0.002603, -0.000000, 0.003481, 0.002472, -0.002828, -0.005215, -0.000000, 0.006705, 0.004678, -0.005269, -0.009584, -0.000000, 0.012065, 0.008360, -0.009375, -0.017028, -0.000000, 0.021603, 0.015123, -0.017229, -0.032012, -0.000000, 0.043774, 0.032544, -0.040365, -0.084963, -0.000000, 0.201161, 0.374060, 0.374060, 0.201161, -0.000000, -0.084963, -0.040365, 0.032544, 0.043774, -0.000000, -0.032012, -0.017229, 0.015123, 0.021603, -0.000000, -0.017028, -0.009375, 0.008360, 0.012065, -0.000000, -0.009584, -0.005269, 0.004678, 0.006705, -0.000000, -0.005215, -0.002828, 0.002472, 0.003481, -0.000000, -0.002603, -0.001382, 0.001183, 0.001634, -0.000000, -0.001187, -0.000629, 0.000543, 0.000772, -0.000000, -0.000640, -0.000379};static const float psk48_rx_coeff[PSK48_RXF_LEN] = { -0.000219, 0.000360, 0.000873, 0.001080, 0.000747, -0.000192, -0.001466, -0.002436, -0.002328, -0.000699, 0.002101, 0.004809, 0.005696, 0.003492, -0.001633, -0.007660, -0.011316, -0.009627, -0.001780, 0.009712, 0.019426, 0.021199, 0.011342, -0.008583, -0.030955, -0.044093, -0.036634, -0.002651, 0.054742, 0.123101, 0.184198, 0.220219, 0.220219, 0.184198, 0.123101, 0.054742, -0.002651, -0.036634, -0.044093, -0.030955, -0.008583, 0.011342, 0.021199, 0.019426, 0.009712, -0.001780, -0.009627, -0.011316, -0.007660, -0.001633, 0.003492, 0.005696, 0.004809, 0.002101, -0.000699, -0.002328, -0.002436, -0.001466, -0.000192, 0.000747, 0.001080, 0.000873, 0.000360, -0.000219};static void gentbl_psk4800(FILE *f){ int i, j, k; short x; fprintf(f, "\n/*\n * psk4800 specific tables\n */\n" "#define PSK48_TXF_OVERSAMPLING %d\n" "#define PSK48_TXF_NUMSAMPLES %d\n\n" "#define PSK48_SAMPLERATE 8000\n" "#define PSK48_CAR_FREQ 2000\n" "#define PSK48_PSK_LEN 5\n" "#define PSK48_RXF_LEN %u\n" "#define PSK48_PHASEINC (0x10000*PSK48_CAR_FREQ/PSK48_SAMPLERATE)\n" "#define PSK48_SPHASEINC (0x10000/(2*PSK48_PSK_LEN))\n\n" "static const short psk48_tx_table[PSK48_TXF_OVERSAMPLING*" "PSK48_TXF_NUMSAMPLES*8*2] = {", PSK48_TXF_OVERSAMPLING, PSK48_TXF_NUMSAMPLES, PSK48_RXF_LEN); for (i = 0; i < PSK48_TXF_OVERSAMPLING; i++) { for (j = 0; j < PSK48_TXF_NUMSAMPLES; j++) { fprintf(f, "\n\t"); for (k = 0; k < 8; k++) { x = 32767.0 * cos(k*M_PI/4.0) * psk48_tx_coeff[j * PSK48_TXF_OVERSAMPLING + i]; fprintf(f, "%6d, ", x); } fprintf(f, "\n\t"); for (k = 0; k < 8; k++) { x = 32767.0 * sin(k*M_PI/4.0) * psk48_tx_coeff[j * PSK48_TXF_OVERSAMPLING + i]; fprintf(f, "%6d", x); if (k != 7 || j != PSK48_TXF_NUMSAMPLES-1 || i != PSK48_TXF_OVERSAMPLING-1) fprintf(f, ", "); } } } fprintf(f, "\n};\n\n"); fprintf(f, "static const short psk48_rx_coeff[PSK48_RXF_LEN] = {\n\t"); for (i = 0; i < PSK48_RXF_LEN; i++) { fprintf(f, "%6d", (int)(psk48_rx_coeff[i]*32767.0)); if (i < PSK48_RXF_LEN-1) fprintf(f, ",%s", (i & 7) == 7 ? "\n\t" : ""); } fprintf(f, "\n};\n\n");}/* -------------------------------------------------------------------- */static void gentbl_hapn4800(FILE *f){ int i, j, k, l; float s; float c[44]; float min, max; fprintf(f, "\n/*\n * hapn4800 specific tables\n */\n\n"); /* * firstly generate tables for the FM transmitter modulator */ min = max = 0; memset(c, 0, sizeof(c)); for (i = 0; i < 24; i++) c[8+i] = sinc(1.5*((i-11.5)/8.0))*hamming(i/23.0)/2.4; for (i = 0; i < 24; i++) c[i] -= c[i+8]; fprintf(f, "static unsigned char hapn48_txfilt_8[] = {\n\t"); for (i = 0; i < 8; i++) { for (j = 0; j < 16; j++) { for (k = 1, s = 0, l = i; k < 16; k <<= 1, l += 8) { if (j & k) s += c[l]; else s -= c[l]; } if (s > max) max = s; if (s < min) min = s; fprintf(f, "%4d", (int)(128+127*s)); if (i < 7 || j < 15) fprintf(f, ",%s", (j & 7) == 7 ? "\n\t" : ""); } }#ifdef VERBOSE fprintf(stderr, "hapn4800: txfilt8: min = %f; max = %f\n", min, max);#endif fprintf(f, "\n};\n\n"); min = max = 0; memset(c, 0, sizeof(c)); for (i = 0; i < 30; i++) c[10+i] = sinc(1.5*((i-14.5)/10.0))*hamming(i/29.0)/2.4; for (i = 0; i < 30; i++) c[i] -= c[i+10]; fprintf(f, "static unsigned char hapn48_txfilt_10[] = {\n\t"); for (i = 0; i < 10; i++) { for (j = 0; j < 16; j++) { for (k = 1, s = 0, l = i; k < 16; k <<= 1, l += 10) { if (j & k) s += c[l]; else s -= c[l]; } if (s > max) max = s; if (s < min) min = s; fprintf(f, "%4d", (int)(128+127*s)); if (i < 9 || j < 15) fprintf(f, ",%s", (j & 7) == 7 ? "\n\t" : ""); } }#ifdef VERBOSE fprintf(stderr, "hapn4800: txfilt10: min = %f; max = %f\n", min, max);#endif fprintf(f, "\n};\n\n"); /* * secondly generate tables for the PM transmitter modulator */ min = max = 0; memset(c, 0, sizeof(c)); for (i = 0; i < 25; i++) c[i] = sinc(1.4*((i-12.0)/8.0))*hamming(i/24.0)/6.3; for (i = 0; i < 25; i++) for (j = 1; j < 8; j++) c[i] += c[i+j]; fprintf(f, "static unsigned char hapn48_txfilt_pm8[] = {\n\t"); for (i = 0; i < 8; i++) { for (j = 0; j < 16; j++) { for (k = 1, s = 0, l = i; k < 16; k <<= 1, l += 8) { if (j & k) s += c[l]; else s -= c[l]; } if (s > max) max = s; if (s < min) min = s; fprintf(f, "%4d", (int)(128+127*s)); if (i < 7 || j < 15) fprintf(f, ",%s", (j & 7) == 7 ? "\n\t" : ""); } }#ifdef VERBOSE fprintf(stderr, "hapn4800: txfiltpm8: min = %f; max = %f\n", min, max);#endif fprintf(f, "\n};\n\n"); min = max = 0; memset(c, 0, sizeof(c)); for (i = 0; i < 31; i++) c[10+i] = sinc(1.4*((i-15.0)/10.0))*hamming(i/30.0)/7.9; for (i = 0; i < 31; i++) for (j = 1; j < 10; j++) c[i] += c[i+j]; fprintf(f, "static unsigned char hapn48_txfilt_pm10[] = {\n\t"); for (i = 0; i < 10; i++) { for (j = 0; j < 16; j++) { for (k = 1, s = 0, l = i; k < 16; k <<= 1, l += 10) { if (j & k) s += c[l]; else s -= c[l]; } if (s > max) max = s; if (s < min) min = s; fprintf(f, "%4d", (int)(128+127*s)); if (i < 9 || j < 15) fprintf(f, ",%s", (j & 7) == 7 ? "\n\t" : ""); } }#ifdef VERBOSE fprintf(stderr, "hapn4800: txfiltpm10: min = %f; max = %f\n", min, max);#endif fprintf(f, "\n};\n\n"); }/* -------------------------------------------------------------------- */#define AFSK24_SAMPLERATE 16000#define AFSK24_CORRLEN 14static void gentbl_afsk2400(FILE *f, float tcm3105clk){ int i, sum, v; fprintf(f, "\n/*\n * afsk2400 specific tables (tcm3105 clk %7fHz)\n */\n" "#define AFSK24_TX_FREQ_LO %d\n" "#define AFSK24_TX_FREQ_HI %d\n" "#define AFSK24_BITPLL_INC %d\n" "#define AFSK24_SAMPLERATE %d\n\n", tcm3105clk, (int)(tcm3105clk/3694.0), (int)(tcm3105clk/2015.0), 0x10000*2400/AFSK24_SAMPLERATE, AFSK24_SAMPLERATE);#define ARGLO(x) 2.0*M_PI*(double)x*(tcm3105clk/3694.0)/(double)AFSK24_SAMPLERATE#define ARGHI(x) 2.0*M_PI*(double)x*(tcm3105clk/2015.0)/(double)AFSK24_SAMPLERATE#define WINDOW(x) hamming((float)(x)/(AFSK24_CORRLEN-1.0)) fprintf(f, "static const int afsk24_tx_lo_i[] = {\n\t"); for(sum = i = 0; i < AFSK24_CORRLEN; i++) { sum += (v = 127.0*cos(ARGLO(i))*WINDOW(i)); fprintf(f, " %4i%c", v, (i < AFSK24_CORRLEN-1) ? ',' : ' '); } fprintf(f, "\n};\n#define SUM_AFSK24_TX_LO_I %d\n\n" "static const int afsk24_tx_lo_q[] = {\n\t", sum); for(sum = i = 0; i < AFSK24_CORRLEN; i++) { sum += (v = 127.0*sin(ARGLO(i))*WINDOW(i)); fprintf(f, " %4i%c", v, (i < AFSK24_CORRLEN-1) ? ',' : ' '); } fprintf(f, "\n};\n#define SUM_AFSK24_TX_LO_Q %d\n\n" "static const int afsk24_tx_hi_i[] = {\n\t", sum); for(sum = i = 0; i < AFSK24_CORRLEN; i++) { sum += (v = 127.0*cos(ARGHI(i))*WINDOW(i)); fprintf(f, " %4i%c", v, (i < AFSK24_CORRLEN-1) ? ',' : ' '); } fprintf(f, "\n};\n#define SUM_AFSK24_TX_HI_I %d\n\n" "static const int afsk24_tx_hi_q[] = {\n\t", sum); for(sum = i = 0; i < AFSK24_CORRLEN; i++) { sum += (v = 127.0*sin(ARGHI(i))*WINDOW(i)); fprintf(f, " %4i%c", v, (i < AFSK24_CORRLEN-1) ? ',' : ' '); } fprintf(f, "\n};\n#define SUM_AFSK24_TX_HI_Q %d\n\n", sum);#undef ARGLO#undef ARGHI#undef WINDOW}/* -------------------------------------------------------------------- */static char *progname;static void gentbl_banner(FILE *f){ fprintf(f, "/*\n * THIS FILE IS GENERATED AUTOMATICALLY BY %s, " "DO NOT EDIT!\n */\n\n", progname);}/* -------------------------------------------------------------------- */int main(int argc, char *argv[]){ FILE *f; progname = argv[0]; if (!(f = fopen("sm_tbl_afsk1200.h", "w"))) exit(1); gentbl_banner(f); gentbl_offscostab(f, 6); gentbl_costab(f, 6); gentbl_afsk1200(f); fclose(f); if (!(f = fopen("sm_tbl_afsk2666.h", "w"))) exit(1); gentbl_banner(f); gentbl_offscostab(f, 6); gentbl_costab(f, 6); gentbl_afsk2666(f); fclose(f); if (!(f = fopen("sm_tbl_psk4800.h", "w"))) exit(1); gentbl_banner(f); gentbl_psk4800(f); gentbl_costab(f, 8); gentbl_atantab(f); fclose(f); if (!(f = fopen("sm_tbl_hapn4800.h", "w"))) exit(1); gentbl_banner(f); gentbl_hapn4800(f); fclose(f); if (!(f = fopen("sm_tbl_fsk9600.h", "w"))) exit(1); gentbl_banner(f); gentbl_fsk9600(f); fclose(f); if (!(f = fopen("sm_tbl_afsk2400_8.h", "w"))) exit(1); gentbl_banner(f); gentbl_offscostab(f, 6); gentbl_costab(f, 6); gentbl_afsk2400(f, 8000000); fclose(f); if (!(f = fopen("sm_tbl_afsk2400_7.h", "w"))) exit(1); gentbl_banner(f); gentbl_offscostab(f, 6); gentbl_costab(f, 6); gentbl_afsk2400(f, 7372800); fclose(f); exit(0);}/* -------------------------------------------------------------------- */
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -