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