FreeCalypso > hg > gsm-net-reveng
changeset 22:8957383370c5
trau-ul-prep: implement efrdec2tsrc
author | Mychaela Falconia <falcon@freecalypso.org> |
---|---|
date | Sun, 23 Jun 2024 22:24:39 +0000 |
parents | 453461ad9c15 |
children | bffbe80ffade |
files | .hgignore trau-ul-prep/Makefile trau-ul-prep/efrdec2tsrc.c trau-ul-prep/etsi-bit-rd.c trau-ul-prep/etsi.h |
diffstat | 5 files changed, 176 insertions(+), 1 deletions(-) [+] |
line wrap: on
line diff
--- a/.hgignore Sun Jun 23 22:05:17 2024 +0000 +++ b/.hgignore Sun Jun 23 22:24:39 2024 +0000 @@ -11,4 +11,5 @@ ^trau-files/.*\.gsmx$ ^trau-files/.*\.wav$ +^trau-ul-prep/efrdec2tsrc$ ^trau-ul-prep/gsmx2tsrc$
--- a/trau-ul-prep/Makefile Sun Jun 23 22:05:17 2024 +0000 +++ b/trau-ul-prep/Makefile Sun Jun 23 22:24:39 2024 +0000 @@ -1,9 +1,12 @@ CC= gcc CFLAGS= -O2 -PROGS= gsmx2tsrc +PROGS= efrdec2tsrc gsmx2tsrc all: ${PROGS} +efrdec2tsrc: efrdec2tsrc.o etsi-bit-rd.o + ${CC} ${CFLAGS} -o $@ $^ -lgsmefr + gsmx2tsrc: binreader.o gsmx2tsrc.o ${CC} ${CFLAGS} -o $@ $^ -lgsmfr2 -lgsmefr
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/trau-ul-prep/efrdec2tsrc.c Sun Jun 23 22:24:39 2024 +0000 @@ -0,0 +1,84 @@ +/* + * This program reads an EFR *.dec file in ETSI test sequence format + * and converts it into ASCII source for TRAU-UL construction. + */ + +#include <stdio.h> +#include <stdint.h> +#include <stdlib.h> +#include <string.h> +#include <strings.h> +#include <unistd.h> +#include <gsm_efr.h> +#include "etsi.h" + +main(argc, argv) + char **argv; +{ + char *infname, *outfname; + FILE *inf, *outf; + int big_endian = 0; + unsigned frame_no; + uint8_t input_bits[ETSI_DEC_NWORDS], frame[EFR_RTP_FRAME_LEN]; + int16_t params[EFR_NUM_PARAMS]; + int rc, i, j, n; + extern int optind; + + while ((rc = getopt(argc, argv, "b")) != EOF) { + switch (rc) { + case 'b': + big_endian = 1; + continue; + default: + usage: + fprintf(stderr, + "usage: %s [-b] input.dec [output.tsrc]\n", + argv[0]); + exit(1); + } + } + if (argc < optind + 1 || argc > optind + 2) + goto usage; + infname = argv[optind]; + outfname = argv[optind+1]; + + inf = fopen(infname, "r"); + if (!inf) { + perror(infname); + exit(1); + } + if (outfname) { + outf = fopen(outfname, "w"); + if (!outf) { + perror(outfname); + exit(1); + } + } else + outf = stdout; + for (frame_no = 0; ; frame_no++) { + rc = read_etsi_bits(inf, big_endian, input_bits, + ETSI_DEC_NWORDS, infname); + if (!rc) + break; + bits2frame(input_bits + 1, frame, infname, frame_no); + fprintf(outf, "# input frame %u\nFrame_EFR {\n", frame_no); + if (input_bits[246]) + fputs("\t# TAF position\n", outf); + fprintf(outf, "\tBFI %u\n", input_bits[0]); + EFR_frame2params(frame, params); + n = 0; + fputs("\tLPC", outf); + for (i = 0; i < 5; i++) + fprintf(outf, " %d", params[n++]); + putc('\n', outf); + for (i = 0; i < 4; i++) { + fputs("\tsf", outf); + for (j = 0; j < 13; j++) + fprintf(outf, " %d", params[n++]); + putc('\n', outf); + } + fprintf(outf, "\tSID %u\n", input_bits[245]); + fputs("}\n\n", outf); + } + exit(0); +}
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/trau-ul-prep/etsi-bit-rd.c Sun Jun 23 22:24:39 2024 +0000 @@ -0,0 +1,83 @@ +/* + * In this module we implement utility functions for reading ETSI *.cod + * and *.dec files in either LE or BE format. + */ + +#include <stdio.h> +#include <stdint.h> +#include <stdlib.h> +#include <string.h> +#include <strings.h> +#include <gsm_efr.h> +#include "etsi.h" + +read_etsi_bits(inf, big_endian, bitvec, nwords, filename_for_errs) + FILE *inf; + uint8_t *bitvec; + unsigned nwords; + char *filename_for_errs; +{ + uint8_t file_bytes[ETSI_DEC_NWORDS * 2], *sp; + int cc; + unsigned n, upper; + + cc = fread(file_bytes, 2, nwords, inf); + if (cc == 0) + return 0; + if (cc != nwords) { + fprintf(stderr, "error: short read from %s\n", + filename_for_errs); + exit(1); + } + sp = file_bytes; + for (n = 0; n < nwords; n++) { + if (big_endian) { + upper = sp[0]; + bitvec[n] = sp[1]; + } else { + bitvec[n] = sp[0]; + upper = sp[1]; + } + if (upper) { + fprintf(stderr, + "error in %s: non-zero in what should be %s upper byte\n", + filename_for_errs, big_endian ? "BE" : "LE"); + exit(1); + } + sp += 2; + } + return 1; +} + +void +bits2frame(input_bits, frame, filename_for_errs, frame_no) + uint8_t *input_bits, *frame; + char *filename_for_errs; + unsigned frame_no; +{ + uint8_t bits[248], *sp, *dp; + unsigned nb, byte, mask; + + bits[0] = 1; + bits[1] = 1; + bits[2] = 0; + bits[3] = 0; + bcopy(input_bits, bits + 4, 244); + sp = bits; + dp = frame; + for (nb = 0; nb < EFR_RTP_FRAME_LEN; nb++) { + byte = 0; + for (mask = 0x80; mask; mask >>= 1) { + if (*sp > 1) { + fprintf(stderr, + "error in %s frame #%u: data bit > 1\n", + filename_for_errs, frame_no); + exit(1); + } + if (*sp) + byte |= mask; + sp++; + } + *dp++ = byte; + } +}