annotate pcm-study/pcm-frag-extr.c @ 14:e7f43262efa1

rtp-stream-dump: add hex dump option
author Mychaela Falconia <falcon@freecalypso.org>
date Sun, 28 Jul 2024 01:53:41 +0000
parents b5e73d5ebcd1
children
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
12
b5e73d5ebcd1 pcm-frag-extr program written
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
1 /*
b5e73d5ebcd1 pcm-frag-extr program written
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
2 * This program extracts a fragment of some N 160-sample frames from a G.711
b5e73d5ebcd1 pcm-frag-extr program written
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
3 * recording file, starting at an arbitrary offset that may not be frame-
b5e73d5ebcd1 pcm-frag-extr program written
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
4 * aligned, and saves this fragment to a new binary file.
b5e73d5ebcd1 pcm-frag-extr program written
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
5 */
b5e73d5ebcd1 pcm-frag-extr program written
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
6
b5e73d5ebcd1 pcm-frag-extr program written
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
7 #include <stdio.h>
b5e73d5ebcd1 pcm-frag-extr program written
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
8 #include <stdint.h>
b5e73d5ebcd1 pcm-frag-extr program written
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
9 #include <stdlib.h>
b5e73d5ebcd1 pcm-frag-extr program written
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
10
b5e73d5ebcd1 pcm-frag-extr program written
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
11 main(argc, argv)
b5e73d5ebcd1 pcm-frag-extr program written
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
12 char **argv;
b5e73d5ebcd1 pcm-frag-extr program written
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
13 {
b5e73d5ebcd1 pcm-frag-extr program written
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
14 FILE *inf, *outf;
b5e73d5ebcd1 pcm-frag-extr program written
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
15 u_long start_offset;
b5e73d5ebcd1 pcm-frag-extr program written
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
16 unsigned n, nframes;
b5e73d5ebcd1 pcm-frag-extr program written
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
17 uint8_t buf[160];
b5e73d5ebcd1 pcm-frag-extr program written
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
18 int cc;
b5e73d5ebcd1 pcm-frag-extr program written
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
19
b5e73d5ebcd1 pcm-frag-extr program written
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
20 if (argc != 5) {
b5e73d5ebcd1 pcm-frag-extr program written
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
21 fprintf(stderr,
b5e73d5ebcd1 pcm-frag-extr program written
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
22 "usage: %s pcm-src-file start-offset N-frames pcm-out-file\n",
b5e73d5ebcd1 pcm-frag-extr program written
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
23 argv[0]);
b5e73d5ebcd1 pcm-frag-extr program written
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
24 exit(1);
b5e73d5ebcd1 pcm-frag-extr program written
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
25 }
b5e73d5ebcd1 pcm-frag-extr program written
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
26 inf = fopen(argv[1], "r");
b5e73d5ebcd1 pcm-frag-extr program written
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
27 if (!inf) {
b5e73d5ebcd1 pcm-frag-extr program written
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
28 perror(argv[1]);
b5e73d5ebcd1 pcm-frag-extr program written
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
29 exit(1);
b5e73d5ebcd1 pcm-frag-extr program written
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
30 }
b5e73d5ebcd1 pcm-frag-extr program written
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
31 start_offset = strtoul(argv[2], 0, 0);
b5e73d5ebcd1 pcm-frag-extr program written
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
32 fseek(inf, start_offset, SEEK_SET);
b5e73d5ebcd1 pcm-frag-extr program written
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
33 nframes = strtoul(argv[3], 0, 0);
b5e73d5ebcd1 pcm-frag-extr program written
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
34 outf = fopen(argv[4], "w");
b5e73d5ebcd1 pcm-frag-extr program written
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
35 if (!outf) {
b5e73d5ebcd1 pcm-frag-extr program written
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
36 perror(argv[4]);
b5e73d5ebcd1 pcm-frag-extr program written
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
37 exit(1);
b5e73d5ebcd1 pcm-frag-extr program written
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
38 }
b5e73d5ebcd1 pcm-frag-extr program written
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
39 for (n = 0; n < nframes; n++) {
b5e73d5ebcd1 pcm-frag-extr program written
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
40 cc = fread(buf, 1, 160, inf);
b5e73d5ebcd1 pcm-frag-extr program written
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
41 if (cc > 0)
b5e73d5ebcd1 pcm-frag-extr program written
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
42 fwrite(buf, 1, cc, outf);
b5e73d5ebcd1 pcm-frag-extr program written
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
43 if (cc < 160) {
b5e73d5ebcd1 pcm-frag-extr program written
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
44 fprintf(stderr, "warning: short read from %s\n",
b5e73d5ebcd1 pcm-frag-extr program written
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
45 argv[1]);
b5e73d5ebcd1 pcm-frag-extr program written
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
46 break;
b5e73d5ebcd1 pcm-frag-extr program written
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
47 }
b5e73d5ebcd1 pcm-frag-extr program written
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
48 }
b5e73d5ebcd1 pcm-frag-extr program written
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
49 exit(0);
b5e73d5ebcd1 pcm-frag-extr program written
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
50 }