comparison amrconv/cod-parse.c @ 211:78d1a6513393

amrconv: new program amr-cod-parse
author Mychaela Falconia <falcon@freecalypso.org>
date Thu, 20 Apr 2023 01:30:46 +0000
parents efrtest/cod-parse.c@bbe5669f0f29
children 0beafaa0623f
comparison
equal deleted inserted replaced
210:7e490a8efe8a 211:78d1a6513393
1 /*
2 * This program reads an ETSI/3GPP AMR *.cod file and parses it into
3 * 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 unsigned amr_bit_lengths[9];
15
16 static char *type_names[4] = {
17 "Speech",
18 "SID_FIRST",
19 "SID_UPDATE",
20 "NO_DATA"
21 };
22
23 main(argc, argv)
24 char **argv;
25 {
26 char *infname;
27 FILE *inf;
28 int big_endian;
29 unsigned frame_no, type, mode;
30 uint8_t input_bits[COD_FORMAT_NWORDS];
31 uint16_t params[MAX_PRM_SIZE];
32 int rc;
33
34 if (argc == 2 && argv[1][0] != '-') {
35 big_endian = 0;
36 infname = argv[1];
37 } else if (argc == 3 && !strcmp(argv[1], "-b")) {
38 big_endian = 1;
39 infname = argv[2];
40 } else {
41 fprintf(stderr, "usage: %s [-b] file.cod\n", argv[0]);
42 exit(1);
43 }
44 inf = fopen(infname, "r");
45 if (!inf) {
46 perror(infname);
47 exit(1);
48 }
49 for (frame_no = 0; ; frame_no++) {
50 rc = read_cod_bits(inf, big_endian, input_bits, infname);
51 if (!rc)
52 break;
53 type = input_bits[0];
54 mode = input_bits[245];
55 printf("#%u: Type=%u Mode=%u", frame_no, type, mode);
56 if (type > TX_NO_DATA || mode > MR122) {
57 printf(" (unsupported)\n");
58 continue;
59 }
60 printf(" (%s %s)\n", amr_mode_names[mode], type_names[type]);
61 switch (type) {
62 case TX_SPEECH_GOOD:
63 preen_frame_bits(input_bits+1, amr_bit_lengths[mode],
64 infname, frame_no);
65 reassemble_amr_params(input_bits+1, params, mode);
66 dump_amr_params(params, mode);
67 break;
68 case TX_SID_FIRST:
69 case TX_SID_UPDATE:
70 preen_frame_bits(input_bits+1, AMR_NBITS_SID, infname,
71 frame_no);
72 reassemble_amr_params(input_bits+1, params, MRDTX);
73 dump_amr_params(params, MRDTX);
74 break;
75 }
76 }
77 exit(0);
78 }