# HG changeset patch # User Mychaela Falconia # Date 1773294563 0 # Node ID c53ce88d67a7d2e77070b684f6ba8e1708ebe5c8 # Parent 45e727b53da190b1045ddde848a306a4a61326d0 hrutil: new program gsmhr-encode diff -r 45e727b53da1 -r c53ce88d67a7 .hgignore --- a/.hgignore Thu Mar 12 04:46:03 2026 +0000 +++ b/.hgignore Thu Mar 12 05:49:23 2026 +0000 @@ -90,6 +90,7 @@ ^hrutil/gsmhr-dec2hex$ ^hrutil/gsmhr-decode$ ^hrutil/gsmhr-decode-r$ +^hrutil/gsmhr-encode$ ^hrutil/gsmhr-etsi-dec$ ^hrutil/gsmhr-etsi-enc$ ^hrutil/gsmhr-hex2dec$ diff -r 45e727b53da1 -r c53ce88d67a7 hrutil/Makefile --- a/hrutil/Makefile Thu Mar 12 04:46:03 2026 +0000 +++ b/hrutil/Makefile Thu Mar 12 05:49:23 2026 +0000 @@ -1,5 +1,5 @@ PROGS= gsmhr-cod-craft gsmhr-cod-parse gsmhr-cod2hex gsmhr-dec-craft \ - gsmhr-dec-parse gsmhr-dec2hex gsmhr-decode gsmhr-decode-r \ + gsmhr-dec-parse gsmhr-dec2hex gsmhr-decode gsmhr-decode-r gsmhr-encode \ gsmhr-etsi-dec gsmhr-etsi-enc gsmhr-hex2dec gsmhr-hex2rpf gsmhr-rpf2hex\ gsmhr-tfo-xfrm gsmhr-tfo-xfrm-dc tw5b-dump LIBHR1= ../libgsmhr1/libgsmhr1.a @@ -34,6 +34,9 @@ gsmhr-decode-r: decode-r.o ${LIBS} ${CC} ${CFLAGS} -o $@ $^ +gsmhr-encode: encode.o tw5b-out-cod.o ${LIBS} + ${CC} ${CFLAGS} -o $@ $^ + gsmhr-etsi-dec: etsi-dec.o etsi-pcm-out.o read-dec.o ${LIBS} ${CC} ${CFLAGS} -o $@ $^ diff -r 45e727b53da1 -r c53ce88d67a7 hrutil/encode.c --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/hrutil/encode.c Thu Mar 12 05:49:23 2026 +0000 @@ -0,0 +1,78 @@ +/* + * This file is the main module for gsmhr-encode utility. This utility + * is intended to serve as the "user-friendly" speech encoder for GSM-HR, + * reading speech input in WAV format and emitting GSM-HR output in + * TW-TS-005 Annex B hex format. + */ + +#include +#include +#include +#include +#include +#include +#include "../libgsmhr1/tw_gsmhr.h" +#include "../libtest/wavreader.h" +#include "../libtest/wavrdhelp.h" + +main(argc, argv) + char **argv; +{ + char *infname, *outfname; + void *wav; + FILE *outf; + struct gsmhr_encoder_state *state; + int16_t pcm[160]; + int16_t prm_out[GSMHR_NUM_PARAMS_ENC]; + int opt, rc, dtx = 0, emit_5993 = 0; + extern int optind; + + while ((opt = getopt(argc, argv, "dx")) != EOF) { + switch (opt) { + case 'd': + dtx = 1; + continue; + case 'x': + emit_5993 = 1; + continue; + default: + usage: + fprintf(stderr, + "usage: %s [-d] [-x] input.wav output.hex\n", + argv[0]); + exit(1); + } + } + if (argc != optind + 2) + goto usage; + infname = argv[optind]; + outfname = argv[optind+1]; + + wav = wav_read_open(infname); + if (!wav) { + perror(infname); + exit(1); + } + rc = wavrd_check_header(wav, infname); + if (rc < 0) + exit(1); /* error msg already printed */ + outf = fopen(outfname, "w"); + if (!outf) { + perror(outfname); + exit(1); + } + state = gsmhr_encoder_create(dtx); + if (!state) { + perror("gsmhr_encoder_create()"); + exit(1); + } + for (;;) { + rc = wavrd_get_pcm_block(wav, pcm); + if (!rc) + break; + gsmhr_encode_frame(state, pcm, prm_out); + emit_cod_to_tw5b(outf, prm_out, emit_5993); + } + fclose(outf); + exit(0); +}