comparison amrconv/ietf-parse.c @ 214:934cf92a1c45

amrconv: new program amr-ietf-parse
author Mychaela Falconia <falcon@freecalypso.org>
date Thu, 20 Apr 2023 22:48:22 +0000
parents
children
comparison
equal deleted inserted replaced
213:46a6e6b6841a 214:934cf92a1c45
1 /*
2 * This program reads an AMR recording in IETF RFC 4867 format and parses it
3 * into a human-readable form.
4 */
5
6 #include <stdio.h>
7 #include <stdint.h>
8 #include <stdlib.h>
9 #include <string.h>
10 #include <strings.h>
11 #include "amr_defs.h"
12
13 extern char *amr_mode_names[16];
14 extern const char amr_file_hdr[IETF_HDR_LEN];
15 extern const uint8_t extra_bytes_per_ft[9];
16
17 main(argc, argv)
18 char **argv;
19 {
20 char *infname;
21 FILE *inf;
22 uint8_t frm_in[MAX_IF1_BYTES];
23 unsigned frame_no, mode, qbit, sti, sid_mode;
24 uint8_t ser_bits[MAX_SERIAL_SIZE];
25 uint16_t params[MAX_PRM_SIZE];
26 int rc;
27
28 if (argc != 2) {
29 fprintf(stderr, "usage: %s amr_file\n", argv[0]);
30 exit(1);
31 }
32 infname = argv[1];
33 inf = fopen(infname, "r");
34 if (!inf) {
35 perror(infname);
36 exit(1);
37 }
38 if (fread(frm_in, 1, IETF_HDR_LEN, inf) != IETF_HDR_LEN ||
39 bcmp(frm_in, amr_file_hdr, IETF_HDR_LEN)) {
40 fprintf(stderr, "error: %s is not in IETF AMR format\n",
41 infname);
42 exit(1);
43 }
44 for (frame_no = 0; ; frame_no++) {
45 rc = getc(inf);
46 if (rc < 0)
47 break;
48 mode = (rc & 0x78) >> 3;
49 qbit = (rc & 4) >> 2;
50 printf("#%u: FT=%u (%s) Q=%u\n", frame_no, mode,
51 amr_mode_names[mode], qbit);
52 if (mode == MODE_NO_DATA)
53 continue;
54 if (mode > MRDTX) {
55 fprintf(stderr, "error in frame #%u: invalid FT=%u\n",
56 frame_no, mode);
57 exit(1);
58 }
59 rc = fread(frm_in, 1, extra_bytes_per_ft[mode], inf);
60 if (rc != extra_bytes_per_ft[mode]) {
61 fprintf(stderr,
62 "error: short read from %s on frame #%u\n",
63 infname, frame_no);
64 exit(1);
65 }
66 amr_if1_unpack(frm_in, ser_bits, mode);
67 reassemble_amr_params(ser_bits, params, mode);
68 dump_amr_params(params, mode);
69 if (mode == MRDTX) {
70 sti = (frm_in[4] & 0x10) >> 4;
71 sid_mode = 0;
72 if (frm_in[4] & 0x08)
73 sid_mode |= 1;
74 if (frm_in[4] & 0x04)
75 sid_mode |= 2;
76 if (frm_in[4] & 0x02)
77 sid_mode |= 4;
78 printf(" SID_%s Mode=%u\n", sti ? "UPDATE" : "FIRST",
79 sid_mode);
80 }
81 }
82 exit(0);
83 }