# HG changeset patch # User Mychaela Falconia # Date 1739327541 0 # Node ID 2fcb6b27ee9b6f41f50553dafa3e6d15d8d2d349 # Parent 62fe499ffc153092dfa3d19f7d8105ecede11f27 hrutil: new program gsmhr-rpf2hex diff -r 62fe499ffc15 -r 2fcb6b27ee9b .hgignore --- a/.hgignore Wed Feb 12 01:48:01 2025 +0000 +++ b/.hgignore Wed Feb 12 02:32:21 2025 +0000 @@ -83,6 +83,7 @@ ^hrutil/gsmhr-dec-parse$ ^hrutil/gsmhr-hex2dec$ ^hrutil/gsmhr-hex2rpf$ +^hrutil/gsmhr-rpf2hex$ ^hrutil/tw5b-dump$ ^libgsmhr1/dhf_packed\.c$ diff -r 62fe499ffc15 -r 2fcb6b27ee9b hrutil/Makefile --- a/hrutil/Makefile Wed Feb 12 01:48:01 2025 +0000 +++ b/hrutil/Makefile Wed Feb 12 02:32:21 2025 +0000 @@ -1,5 +1,5 @@ PROGS= gsmhr-cod-parse gsmhr-cod2hex gsmhr-dec-craft gsmhr-dec-parse \ - gsmhr-hex2dec gsmhr-hex2rpf tw5b-dump + gsmhr-hex2dec gsmhr-hex2rpf gsmhr-rpf2hex tw5b-dump LIBHR1= ../libgsmhr1/libgsmhr1.a LIBTEST=../libtest/libtest.a LIBS= ${LIBHR1} ${LIBTEST} @@ -26,6 +26,9 @@ gsmhr-hex2rpf: hex2rpf.o ${LIBS} ${CC} ${CFLAGS} -o $@ $^ +gsmhr-rpf2hex: rpf2hex.o ${LIBHR1} + ${CC} ${CFLAGS} -o $@ $^ + tw5b-dump: print-frame.o tw5b-dump.o ${LIBS} ${CC} ${CFLAGS} -o $@ $^ diff -r 62fe499ffc15 -r 2fcb6b27ee9b hrutil/rpf2hex.c --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/hrutil/rpf2hex.c Wed Feb 12 02:32:21 2025 +0000 @@ -0,0 +1,80 @@ +/* + * This program converts HRv1 speech recordings from ETSI TS 101 318 raw + * packed format (14 bytes per frame, good frames only) into our preferred + * TW-TS-005 Annex B format. + */ + +#include +#include +#include +#include +#include +#include +#include "../libgsmhr1/tw_gsmhr.h" + +static void +emit_hr1_hex_frame(outf, frame, emit_5993) + FILE *outf; + uint8_t *frame; +{ + unsigned n; + + if (emit_5993) { + fprintf(outf, "%02X", + gsmhr_ts101318_is_perfect_sid(frame) << 4); + } + for (n = 0; n < GSMHR_FRAME_LEN_RPF; n++) + fprintf(outf, "%02X", frame[n]); + putc('\n', outf); +} + +main(argc, argv) + char **argv; +{ + char *infname, *outfname; + FILE *inf, *outf; + int opt, cc, emit_5993 = 0; + uint8_t frame[GSMHR_FRAME_LEN_RPF]; + extern int optind; + + while ((opt = getopt(argc, argv, "x")) != EOF) { + switch (opt) { + case 'x': + emit_5993 = 1; + continue; + default: + usage: + fprintf(stderr, + "usage: %s [-x] input.hrpf output.hex\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); + } + + for (;;) { + cc = fread(frame, 1, GSMHR_FRAME_LEN_RPF, inf); + if (cc == 0) + break; + if (cc != GSMHR_FRAME_LEN_RPF) { + fprintf(stderr, "error: short read from %s\n", infname); + exit(1); + } + emit_hr1_hex_frame(outf, frame, emit_5993); + } + exit(0); +}