FreeCalypso > hg > gsm-codec-lib
changeset 434:ba5031723ab6
implement amrefr-tseq-enc test program
author | Mychaela Falconia <falcon@freecalypso.org> |
---|---|
date | Wed, 08 May 2024 02:17:08 +0000 |
parents | 51678b070c7a |
children | 9f354d2aea13 |
files | .hgignore Makefile amrefr/Makefile amrefr/tseq-enc.c |
diffstat | 4 files changed, 107 insertions(+), 1 deletions(-) [+] |
line wrap: on
line diff
--- a/.hgignore Wed May 08 01:13:50 2024 +0000 +++ b/.hgignore Wed May 08 02:17:08 2024 +0000 @@ -9,6 +9,8 @@ ^amrconv/gsm-amr2efr$ ^amrconv/gsm-efr2amr$ +^amrefr/amrefr-tseq-enc$ + ^amrtest/twamr-tseq-dec$ ^amrtest/twamr-tseq-enc$
--- a/Makefile Wed May 08 01:13:50 2024 +0000 +++ b/Makefile Wed May 08 02:17:08 2024 +0000 @@ -2,7 +2,7 @@ CFLAGS= -O2 SUBDIR_LIBPROD= libgsmefr libgsmfr2 -SUBDIR_UTILS= amrconv amrtest efrtest frtest miscutil +SUBDIR_UTILS= amrconv amrefr amrtest efrtest frtest miscutil SUBDIR_INT= dev libtest libtwamr SUBDIR= ${SUBDIR_LIBPROD} ${SUBDIR_UTILS} ${SUBDIR_INT} @@ -10,6 +10,7 @@ all: ${SUBDIR} amrconv: libtest +amrefr: libgsmefr libtwamr amrtest: libtwamr efrtest: libgsmefr libtest frtest: libgsmfr2 libtest
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/amrefr/Makefile Wed May 08 02:17:08 2024 +0000 @@ -0,0 +1,21 @@ +CC= gcc +CFLAGS= -O2 +PROGS= amrefr-tseq-enc +LIBEFR= ../libgsmefr/libgsmefr.a +LIBAMR= ../libtwamr/libtwamr.a +INSTBIN=/opt/freecalypso/bin + +all: ${PROGS} + +amrefr-tseq-enc: tseq-enc.o tseq-enc-common.o ${LIBEFR} ${LIBAMR} + ${CC} ${CFLAGS} -o $@ tseq-enc.o tseq-enc-common.o ${LIBEFR} ${LIBAMR} + +tseq-enc-common.o: ../efrtest/etsi-enc-common.c + ${CC} ${CFLAGS} -c -o $@ $< + +install: + mkdir -p ${INSTBIN} + install -c ${PROGS} ${INSTBIN} + +clean: + rm -f *.o *.out ${PROGS}
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/amrefr/tseq-enc.c Wed May 08 02:17:08 2024 +0000 @@ -0,0 +1,82 @@ +/* + * amrefr-tseq-enc is a test program for our libtwamr-based "alternative EFR" + * encoder: it functions just like gsmefr-etsi-enc, but uses libtwamr as + * the encoder engine instead of libgsmefr. Libgsmefr functions are still + * used for frame packing, but not for actual encoding. Note that there is + * no -d option in this version, and no DTX encoding support: a DTX-capable + * AMR-EFR hybrid is a beast that is currently outside our capabilities. + * + * The byte order is LE by default or BE with -b option. Practical testing + * will always require some manual byte-swap conversion: t??_efr.cod files + * in amr122_efr.zip are shipped in BE, but the corresponding t??.inp files + * in the 06.74 package are LE. + */ + +#include <stdio.h> +#include <stdint.h> +#include <stdlib.h> +#include <string.h> +#include <strings.h> +#include <unistd.h> +#include "../libgsmefr/gsm_efr.h" +#include "../libtwamr/tw_amr.h" + +main(argc, argv) + char **argv; +{ + char *infname, *outfname; + FILE *inf, *outf; + struct amr_encoder_state *state; + int16_t pcm[160]; + struct amr_param_frame amr_frame; + uint8_t efr_frame[EFR_RTP_FRAME_LEN], bits[250]; + int opt, rc, big_endian = 0; + extern int optind; + + while ((opt = getopt(argc, argv, "b")) != EOF) { + switch (opt) { + case 'b': + big_endian = 1; + continue; + default: + usage: + fprintf(stderr, "usage: %s [-b] input.inp output.cod\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_encoder_create(0, 0); + if (!state) { + perror("amr_encoder_create()"); + exit(1); + } + for (;;) { + rc = read_input(inf, pcm, infname, big_endian); + if (!rc) + break; + amr_encode_frame(state, MR122, pcm, &amr_frame); + amr_dhf_subst_efr(&amr_frame); + EFR_params2frame(amr_frame.param, efr_frame); + frame2bits(efr_frame, bits); + bits[248] = 1; + bits[249] = 1; + emit_output(outf, bits + 4, 246, big_endian); + } + fclose(outf); + exit(0); +}