FreeCalypso > hg > gsm-codec-lib
changeset 114:ff0372186b59
gsmefr-etsi-enc test program written
author | Mychaela Falconia <falcon@freecalypso.org> |
---|---|
date | Tue, 29 Nov 2022 20:31:11 +0000 |
parents | 269d341db403 |
children | 5a63294fa321 |
files | .hgignore efrtest/Makefile efrtest/etsi-enc.c |
diffstat | 3 files changed, 131 insertions(+), 1 deletions(-) [+] |
line wrap: on
line diff
--- a/.hgignore Tue Nov 29 07:30:39 2022 +0000 +++ b/.hgignore Tue Nov 29 20:31:11 2022 +0000 @@ -11,6 +11,7 @@ ^efrtest/gsmefr-decode$ ^efrtest/gsmefr-etsi-dec$ +^efrtest/gsmefr-etsi-enc$ ^efrtest/gsmefr-rec2etsi$ ^frtest/gsmfr-cvt-dlcap$
--- a/efrtest/Makefile Tue Nov 29 07:30:39 2022 +0000 +++ b/efrtest/Makefile Tue Nov 29 20:31:11 2022 +0000 @@ -1,6 +1,6 @@ CC= gcc CFLAGS= -O2 -PROGS= gsmefr-decode gsmefr-etsi-dec gsmefr-rec2etsi +PROGS= gsmefr-decode gsmefr-etsi-dec gsmefr-etsi-enc gsmefr-rec2etsi LIBEFR= ../libgsmefr/libgsmefr.a LIBTEST=../libtest/libtest.a INSTBIN=/opt/freecalypso/bin @@ -13,6 +13,9 @@ gsmefr-etsi-dec: etsi-dec.o ${LIBEFR} ${CC} ${CFLAGS} -o $@ etsi-dec.o ${LIBEFR} +gsmefr-etsi-enc: etsi-enc.o ${LIBEFR} + ${CC} ${CFLAGS} -o $@ etsi-enc.o ${LIBEFR} + gsmefr-rec2etsi: rec2etsi.o ${LIBTEST} ${LIBEFR} ${CC} ${CFLAGS} -o $@ rec2etsi.o ${LIBTEST} ${LIBEFR}
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/efrtest/etsi-enc.c Tue Nov 29 20:31:11 2022 +0000 @@ -0,0 +1,126 @@ +/* + * gsmefr-etsi-enc is a test program for our EFR encoder: it reads raw + * 16-bit PCM (matching ETSI's *.inp) as input and writes ETSI's *.cod + * format as output, allowing our decoder to be tested with ETSI's + * official test sequences. + * + * ETSI input and output files are read and written in LE byte order, + * matching the official test sequences in ts_100725v050200p0.zip. + */ + +#include <stdio.h> +#include <stdint.h> +#include <stdlib.h> +#include <string.h> +#include <strings.h> +#include "../libgsmefr/gsm_efr.h" + +static int +read_input(inf, pcm, filename_for_errs) + FILE *inf; + int16_t *pcm; + char *filename_for_errs; +{ + uint8_t file_bytes[320], *sp; + int cc; + unsigned n; + + cc = fread(file_bytes, 2, 160, inf); + if (cc == 0) + return 0; + if (cc != 160) { + fprintf(stderr, "error: short read from %s\n", + filename_for_errs); + exit(1); + } + sp = file_bytes; + for (n = 0; n < 160; n++) { + pcm[n] = sp[0] | (sp[1] << 8); + sp += 2; + } + return 1; +} + +static void +frame2bits(frame, bits) + uint8_t *frame, *bits; +{ + unsigned nb, byte, mask, bit; + + for (nb = 0; nb < EFR_RTP_FRAME_LEN; nb++) { + byte = *frame++; + for (mask = 0x80; mask; mask >>= 1) { + if (byte & mask) + bit = 1; + else + bit = 0; + *bits++ = bit; + } + } +} + +static void +emit_output(outf, bits, nbits) + FILE *outf; + uint8_t *bits; + unsigned nbits; +{ + unsigned n; + + for (n = 0; n < nbits; n++) { + putc(bits[n], outf); + putc(0, outf); + } +} + +main(argc, argv) + char **argv; +{ + char *infname, *outfname; + FILE *inf, *outf; + struct EFR_encoder_state *state; + int16_t pcm[160]; + uint8_t frame[EFR_RTP_FRAME_LEN], bits[250]; + int dtx, rc, sp, vad; + + if (argc == 3 && argv[1][0] != '-') { + dtx = 0; + infname = argv[1]; + outfname = argv[2]; + } else if (argc == 4 && !strcmp(argv[1], "-d")) { + dtx = 1; + infname = argv[2]; + outfname = argv[3]; + } else { + fprintf(stderr, "usage: %s [-d] input.inp output.cod\n", + argv[0]); + exit(1); + } + inf = fopen(infname, "r"); + if (!inf) { + perror(infname); + exit(1); + } + outf = fopen(outfname, "w"); + if (!outf) { + perror(outfname); + exit(1); + } + state = EFR_encoder_create(dtx); + if (!state) { + perror("EFR_encoder_create()"); + exit(1); + } + for (;;) { + rc = read_input(inf, pcm, argv[1]); + if (!rc) + break; + EFR_encode_frame(state, pcm, frame, &sp, &vad); + frame2bits(frame, bits); + bits[248] = vad; + bits[249] = sp; + emit_output(outf, bits + 4, 246); + } + fclose(outf); + exit(0); +}