# HG changeset patch # User Mychaela Falconia # Date 1715741450 0 # Node ID b5e73d5ebcd1ce1536b787d98144dbffd3c82494 # Parent 8b047c9bfe5f609efa98abc190556bc78c1c1a6b pcm-frag-extr program written diff -r 8b047c9bfe5f -r b5e73d5ebcd1 .hgignore --- a/.hgignore Wed May 15 02:31:01 2024 +0000 +++ b/.hgignore Wed May 15 02:50:50 2024 +0000 @@ -15,3 +15,4 @@ ^pcap-study/rtp-tfo-trace$ ^pcm-study/g711u-grep-gsmout$ +^pcm-study/pcm-frag-extr$ diff -r 8b047c9bfe5f -r b5e73d5ebcd1 pcm-study/Makefile --- a/pcm-study/Makefile Wed May 15 02:31:01 2024 +0000 +++ b/pcm-study/Makefile Wed May 15 02:50:50 2024 +0000 @@ -1,4 +1,4 @@ -PROGS= g711u-grep-gsmout +PROGS= g711u-grep-gsmout pcm-frag-extr include ../config.defs @@ -7,6 +7,9 @@ g711u-grep-gsmout: g711u-grep-gsmout.c ${CC} ${CFLAGS} -o $@ $@.c +pcm-frag-extr: pcm-frag-extr.c + ${CC} ${CFLAGS} -o $@ $@.c + install: mkdir -p ${DESTDIR}${bindir} install -c ${PROGS} ${DESTDIR}${bindir} diff -r 8b047c9bfe5f -r b5e73d5ebcd1 pcm-study/pcm-frag-extr.c --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/pcm-study/pcm-frag-extr.c Wed May 15 02:50:50 2024 +0000 @@ -0,0 +1,50 @@ +/* + * This program extracts a fragment of some N 160-sample frames from a G.711 + * recording file, starting at an arbitrary offset that may not be frame- + * aligned, and saves this fragment to a new binary file. + */ + +#include +#include +#include + +main(argc, argv) + char **argv; +{ + FILE *inf, *outf; + u_long start_offset; + unsigned n, nframes; + uint8_t buf[160]; + int cc; + + if (argc != 5) { + fprintf(stderr, + "usage: %s pcm-src-file start-offset N-frames pcm-out-file\n", + argv[0]); + exit(1); + } + inf = fopen(argv[1], "r"); + if (!inf) { + perror(argv[1]); + exit(1); + } + start_offset = strtoul(argv[2], 0, 0); + fseek(inf, start_offset, SEEK_SET); + nframes = strtoul(argv[3], 0, 0); + outf = fopen(argv[4], "w"); + if (!outf) { + perror(argv[4]); + exit(1); + } + for (n = 0; n < nframes; n++) { + cc = fread(buf, 1, 160, inf); + if (cc > 0) + fwrite(buf, 1, cc, outf); + if (cc < 160) { + fprintf(stderr, "warning: short read from %s\n", + argv[1]); + break; + } + } + exit(0); +}