FreeCalypso > hg > rtp-debug-utils
changeset 17:ab18adf989e3 default tip
pcm-study: new program pcm16-frag-extr
author | Mychaela Falconia <falcon@freecalypso.org> |
---|---|
date | Tue, 29 Oct 2024 00:32:33 +0000 |
parents | 1bc144545563 |
children | |
files | .hgignore pcm-study/Makefile pcm-study/pcm16-frag-extr.c |
diffstat | 3 files changed, 55 insertions(+), 1 deletions(-) [+] |
line wrap: on
line diff
--- a/.hgignore Thu Oct 10 17:40:16 2024 +0000 +++ b/.hgignore Tue Oct 29 00:32:33 2024 +0000 @@ -17,3 +17,4 @@ ^pcm-study/g711u-grep-gsmout$ ^pcm-study/pcm-frag-extr$ +^pcm-study/pcm16-frag-extr$
--- a/pcm-study/Makefile Thu Oct 10 17:40:16 2024 +0000 +++ b/pcm-study/Makefile Tue Oct 29 00:32:33 2024 +0000 @@ -1,4 +1,4 @@ -PROGS= g711u-grep-gsmout pcm-frag-extr +PROGS= g711u-grep-gsmout pcm-frag-extr pcm16-frag-extr include ../config.defs @@ -10,6 +10,9 @@ pcm-frag-extr: pcm-frag-extr.c ${CC} ${CFLAGS} -o $@ $@.c +pcm16-frag-extr: pcm16-frag-extr.c + ${CC} ${CFLAGS} -o $@ $@.c + install: mkdir -p ${DESTDIR}${bindir} install -c ${PROGS} ${DESTDIR}${bindir}
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/pcm-study/pcm16-frag-extr.c Tue Oct 29 00:32:33 2024 +0000 @@ -0,0 +1,50 @@ +/* + * This program extracts a fragment of some N 160-sample frames from a PCM16 + * recording file, starting at an arbitrary offset that may not be frame- + * aligned, and saves this fragment to a new binary file. + */ + +#include <stdio.h> +#include <stdint.h> +#include <stdlib.h> + +main(argc, argv) + char **argv; +{ + FILE *inf, *outf; + u_long start_offset; + unsigned n, nframes; + uint8_t buf[320]; + 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, 2, 160, inf); + if (cc > 0) + fwrite(buf, 2, cc, outf); + if (cc < 160) { + fprintf(stderr, "warning: short read from %s\n", + argv[1]); + break; + } + } + exit(0); +}