FreeCalypso > hg > gsm-codec-lib
changeset 430:edbbbf1c4ab1
implement twamr-tseq-dec test program
author | Mychaela Falconia <falcon@freecalypso.org> |
---|---|
date | Tue, 07 May 2024 23:35:41 +0000 |
parents | 3ce30a95769e |
children | f0496507d409 |
files | .hgignore amrtest/Makefile amrtest/tseq-dec.c |
diffstat | 3 files changed, 104 insertions(+), 1 deletions(-) [+] |
line wrap: on
line diff
--- a/.hgignore Tue May 07 22:34:11 2024 +0000 +++ b/.hgignore Tue May 07 23:35:41 2024 +0000 @@ -9,6 +9,7 @@ ^amrconv/gsm-amr2efr$ ^amrconv/gsm-efr2amr$ +^amrtest/twamr-tseq-dec$ ^amrtest/twamr-tseq-enc$ ^dev/a2s-regen$
--- a/amrtest/Makefile Tue May 07 22:34:11 2024 +0000 +++ b/amrtest/Makefile Tue May 07 23:35:41 2024 +0000 @@ -1,11 +1,14 @@ CC= gcc CFLAGS= -O2 -PROGS= twamr-tseq-enc +PROGS= twamr-tseq-dec twamr-tseq-enc LIBAMR= ../libtwamr/libtwamr.a INSTBIN=/opt/freecalypso/bin all: ${PROGS} +twamr-tseq-dec: tseq-dec.o ${LIBAMR} + ${CC} ${CFLAGS} -o $@ tseq-dec.o ${LIBAMR} + twamr-tseq-enc: mode_file.o mode_kw.o tseq-enc.o ${LIBAMR} ${CC} ${CFLAGS} -o $@ mode_file.o mode_kw.o tseq-enc.o ${LIBAMR}
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/amrtest/tseq-dec.c Tue May 07 23:35:41 2024 +0000 @@ -0,0 +1,99 @@ +/* + * twamr-tseq-dec is a test program for our AMR decoder: it reads + * 3GPP AMR *.cod files as input and writes 16-bit linear PCM (raw) + * files as output, allowing libtwamr decoder to be tested with the + * official test sequences. + * + * Both input and output are read/written in the host machine's + * native byte order. + */ + +#include <stdio.h> +#include <stdint.h> +#include <stdlib.h> +#include <string.h> +#include <strings.h> +#include <unistd.h> +#include "../libtwamr/tw_amr.h" + +static int +read_input(inf, cod, filename_for_errs) + FILE *inf; + uint16_t *cod; + char *filename_for_errs; +{ + int cc; + + cc = fread(cod, 2, AMR_COD_WORDS, inf); + if (cc == 0) + return 0; + if (cc != AMR_COD_WORDS) { + fprintf(stderr, "error: short read from %s\n", + filename_for_errs); + exit(1); + } + return 1; +} + +main(argc, argv) + char **argv; +{ + char *infname, *outfname; + FILE *inf, *outf; + struct amr_decoder_state *state; + uint16_t cod[AMR_COD_WORDS]; + struct amr_param_frame frame; + int16_t pcm[160]; + int opt, use_rxtype = 0, rc; + unsigned frame_no; + extern int optind; + + while ((opt = getopt(argc, argv, "r")) != EOF) { + switch (opt) { + case 'r': + use_rxtype = 1; + continue; + default: + usage: + fprintf(stderr, "usage: %s [-r] input.cod output.out\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); + } + outf = fopen(outfname, "w"); + if (!outf) { + perror(outfname); + exit(1); + } + state = amr_decoder_create(); + if (!state) { + perror("amr_decoder_create()"); + exit(1); + } + for (frame_no = 0; ; frame_no++) { + rc = read_input(inf, cod, infname); + if (!rc) + break; + rc = amr_frame_from_tseq(cod, use_rxtype, &frame); + if (rc < 0) { + fprintf(stderr, + "error in %s frame %u: amr_frame_from_tseq() returned %d\n", + infname, frame_no, rc); + exit(1); + } + amr_decode_frame(state, &frame, pcm); + fwrite(pcm, 2, 160, outf); + } + fclose(outf); + exit(0); +}