FreeCalypso > hg > gsm-codec-lib
diff hrutil/tfo-xfrm.c @ 584:fc7a59deb3c3 default tip
hrutil: new program gsmhr-tfo-xfrm
author | Mychaela Falconia <falcon@freecalypso.org> |
---|---|
date | Fri, 14 Feb 2025 01:34:48 +0000 |
parents | frtest/tfo-xfrm.c@b26df31124a4 |
children |
line wrap: on
line diff
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/hrutil/tfo-xfrm.c Fri Feb 14 01:34:48 2025 +0000 @@ -0,0 +1,87 @@ +/* + * This program exercises our ThemWi implementation of TFO transform for + * GSM-HR. It reads a stream of radio leg A Rx frames from a TW-TS-005 Annex B + * hex file and writes the "pristine" stream intended for radio leg B Tx + * into another TW-TS-005 Annex B hex file. DTXd can be enabled or disabled; + * the output can be in either TS 101 318 or RFC 5993 format. + */ + +#include <stdio.h> +#include <stdint.h> +#include <stdlib.h> +#include <unistd.h> +#include "../libgsmhr1/tw_gsmhr.h" +#include "../libtest/tw5reader.h" + +main(argc, argv) + char **argv; +{ + char *infname, *outfname; + FILE *inf, *outf; + unsigned lineno; + struct gsmhr_rxfe_state *state; + uint8_t frame_in[TWTS005_MAX_FRAME]; + unsigned frame_in_len; + int16_t prm_in[GSMHR_NUM_PARAMS_DEC], prm_out[GSMHR_NUM_PARAMS_ENC]; + int opt, rc, dtxd = 0, emit_5993 = 0; + extern int optind; + + while ((opt = getopt(argc, argv, "dx")) != EOF) { + switch (opt) { + case 'd': + dtxd = 1; + continue; + case 'x': + emit_5993 = 1; + continue; + default: + usage: + fprintf(stderr, + "usage: %s [-d] [-x] input.hex output.hex\n", + argv[0]); + exit(1); + } + } + if (argc != optind + 2) + goto usage; + infname = argv[optind]; + outfname = argv[optind+1]; + + inf = fopen(infname, "r"); + if (!inf) { + perror(infname); + exit(1); + } + lineno = 0; + outf = fopen(outfname, "w"); + if (!outf) { + perror(outfname); + exit(1); + } + state = gsmhr_rxfe_create(); + if (!state) { + fprintf(stderr, "gsmhr_rxfe_create() failed!\n"); + exit(1); + } + for (;;) { + rc = twts005_read_frame(inf, &lineno, frame_in, &frame_in_len); + if (rc < 0) { + fprintf(stderr, "%s line %u: not valid TW-TS-005\n", + argv[1], lineno); + exit(1); + } + if (!rc) + break; + rc = gsmhr_rtp_in_direct(frame_in, frame_in_len, prm_in); + if (rc < 0) { + fprintf(stderr, + "%s line %u: not a valid GSM-HR frame\n", + infname, lineno); + exit(1); + } + gsmhr_tfo_xfrm(state, dtxd, prm_in, prm_out); + emit_cod_to_tw5b(outf, prm_out, emit_5993); + } + fclose(outf); + exit(0); +}