FreeCalypso > hg > gsm-codec-lib
annotate amrconv/cod-parse.c @ 537:f9eefb61fb2f
frtest: new program gsmfr-decode-tw5
author | Mychaela Falconia <falcon@freecalypso.org> |
---|---|
date | Sat, 21 Sep 2024 23:31:25 +0000 |
parents | 0beafaa0623f |
children |
rev | line source |
---|---|
115
5a63294fa321
gsmefr-cod-parse test program written
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
1 /* |
211
78d1a6513393
amrconv: new program amr-cod-parse
Mychaela Falconia <falcon@freecalypso.org>
parents:
148
diff
changeset
|
2 * This program reads an ETSI/3GPP AMR *.cod file and parses it into |
78d1a6513393
amrconv: new program amr-cod-parse
Mychaela Falconia <falcon@freecalypso.org>
parents:
148
diff
changeset
|
3 * a human-readable form. |
115
5a63294fa321
gsmefr-cod-parse test program written
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
4 */ |
5a63294fa321
gsmefr-cod-parse test program written
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
5 |
5a63294fa321
gsmefr-cod-parse test program written
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
6 #include <stdio.h> |
5a63294fa321
gsmefr-cod-parse test program written
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
7 #include <stdint.h> |
5a63294fa321
gsmefr-cod-parse test program written
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
8 #include <stdlib.h> |
5a63294fa321
gsmefr-cod-parse test program written
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
9 #include <string.h> |
5a63294fa321
gsmefr-cod-parse test program written
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
10 #include <strings.h> |
211
78d1a6513393
amrconv: new program amr-cod-parse
Mychaela Falconia <falcon@freecalypso.org>
parents:
148
diff
changeset
|
11 #include "amr_defs.h" |
78d1a6513393
amrconv: new program amr-cod-parse
Mychaela Falconia <falcon@freecalypso.org>
parents:
148
diff
changeset
|
12 |
78d1a6513393
amrconv: new program amr-cod-parse
Mychaela Falconia <falcon@freecalypso.org>
parents:
148
diff
changeset
|
13 extern char *amr_mode_names[16]; |
78d1a6513393
amrconv: new program amr-cod-parse
Mychaela Falconia <falcon@freecalypso.org>
parents:
148
diff
changeset
|
14 extern unsigned amr_bit_lengths[9]; |
78d1a6513393
amrconv: new program amr-cod-parse
Mychaela Falconia <falcon@freecalypso.org>
parents:
148
diff
changeset
|
15 |
78d1a6513393
amrconv: new program amr-cod-parse
Mychaela Falconia <falcon@freecalypso.org>
parents:
148
diff
changeset
|
16 static char *type_names[4] = { |
78d1a6513393
amrconv: new program amr-cod-parse
Mychaela Falconia <falcon@freecalypso.org>
parents:
148
diff
changeset
|
17 "Speech", |
78d1a6513393
amrconv: new program amr-cod-parse
Mychaela Falconia <falcon@freecalypso.org>
parents:
148
diff
changeset
|
18 "SID_FIRST", |
78d1a6513393
amrconv: new program amr-cod-parse
Mychaela Falconia <falcon@freecalypso.org>
parents:
148
diff
changeset
|
19 "SID_UPDATE", |
78d1a6513393
amrconv: new program amr-cod-parse
Mychaela Falconia <falcon@freecalypso.org>
parents:
148
diff
changeset
|
20 "NO_DATA" |
78d1a6513393
amrconv: new program amr-cod-parse
Mychaela Falconia <falcon@freecalypso.org>
parents:
148
diff
changeset
|
21 }; |
115
5a63294fa321
gsmefr-cod-parse test program written
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
22 |
5a63294fa321
gsmefr-cod-parse test program written
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
23 main(argc, argv) |
5a63294fa321
gsmefr-cod-parse test program written
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
24 char **argv; |
5a63294fa321
gsmefr-cod-parse test program written
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
25 { |
148
bbe5669f0f29
gsmefr-cod-parse: add BE support
Mychaela Falconia <falcon@freecalypso.org>
parents:
147
diff
changeset
|
26 char *infname; |
115
5a63294fa321
gsmefr-cod-parse test program written
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
27 FILE *inf; |
148
bbe5669f0f29
gsmefr-cod-parse: add BE support
Mychaela Falconia <falcon@freecalypso.org>
parents:
147
diff
changeset
|
28 int big_endian; |
211
78d1a6513393
amrconv: new program amr-cod-parse
Mychaela Falconia <falcon@freecalypso.org>
parents:
148
diff
changeset
|
29 unsigned frame_no, type, mode; |
78d1a6513393
amrconv: new program amr-cod-parse
Mychaela Falconia <falcon@freecalypso.org>
parents:
148
diff
changeset
|
30 uint8_t input_bits[COD_FORMAT_NWORDS]; |
78d1a6513393
amrconv: new program amr-cod-parse
Mychaela Falconia <falcon@freecalypso.org>
parents:
148
diff
changeset
|
31 uint16_t params[MAX_PRM_SIZE]; |
78d1a6513393
amrconv: new program amr-cod-parse
Mychaela Falconia <falcon@freecalypso.org>
parents:
148
diff
changeset
|
32 int rc; |
115
5a63294fa321
gsmefr-cod-parse test program written
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
33 |
148
bbe5669f0f29
gsmefr-cod-parse: add BE support
Mychaela Falconia <falcon@freecalypso.org>
parents:
147
diff
changeset
|
34 if (argc == 2 && argv[1][0] != '-') { |
bbe5669f0f29
gsmefr-cod-parse: add BE support
Mychaela Falconia <falcon@freecalypso.org>
parents:
147
diff
changeset
|
35 big_endian = 0; |
bbe5669f0f29
gsmefr-cod-parse: add BE support
Mychaela Falconia <falcon@freecalypso.org>
parents:
147
diff
changeset
|
36 infname = argv[1]; |
bbe5669f0f29
gsmefr-cod-parse: add BE support
Mychaela Falconia <falcon@freecalypso.org>
parents:
147
diff
changeset
|
37 } else if (argc == 3 && !strcmp(argv[1], "-b")) { |
bbe5669f0f29
gsmefr-cod-parse: add BE support
Mychaela Falconia <falcon@freecalypso.org>
parents:
147
diff
changeset
|
38 big_endian = 1; |
bbe5669f0f29
gsmefr-cod-parse: add BE support
Mychaela Falconia <falcon@freecalypso.org>
parents:
147
diff
changeset
|
39 infname = argv[2]; |
bbe5669f0f29
gsmefr-cod-parse: add BE support
Mychaela Falconia <falcon@freecalypso.org>
parents:
147
diff
changeset
|
40 } else { |
bbe5669f0f29
gsmefr-cod-parse: add BE support
Mychaela Falconia <falcon@freecalypso.org>
parents:
147
diff
changeset
|
41 fprintf(stderr, "usage: %s [-b] file.cod\n", argv[0]); |
115
5a63294fa321
gsmefr-cod-parse test program written
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
42 exit(1); |
5a63294fa321
gsmefr-cod-parse test program written
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
43 } |
148
bbe5669f0f29
gsmefr-cod-parse: add BE support
Mychaela Falconia <falcon@freecalypso.org>
parents:
147
diff
changeset
|
44 inf = fopen(infname, "r"); |
115
5a63294fa321
gsmefr-cod-parse test program written
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
45 if (!inf) { |
148
bbe5669f0f29
gsmefr-cod-parse: add BE support
Mychaela Falconia <falcon@freecalypso.org>
parents:
147
diff
changeset
|
46 perror(infname); |
115
5a63294fa321
gsmefr-cod-parse test program written
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
47 exit(1); |
5a63294fa321
gsmefr-cod-parse test program written
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
48 } |
5a63294fa321
gsmefr-cod-parse test program written
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
49 for (frame_no = 0; ; frame_no++) { |
211
78d1a6513393
amrconv: new program amr-cod-parse
Mychaela Falconia <falcon@freecalypso.org>
parents:
148
diff
changeset
|
50 rc = read_cod_bits(inf, big_endian, input_bits, infname); |
115
5a63294fa321
gsmefr-cod-parse test program written
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
51 if (!rc) |
5a63294fa321
gsmefr-cod-parse test program written
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
52 break; |
211
78d1a6513393
amrconv: new program amr-cod-parse
Mychaela Falconia <falcon@freecalypso.org>
parents:
148
diff
changeset
|
53 type = input_bits[0]; |
78d1a6513393
amrconv: new program amr-cod-parse
Mychaela Falconia <falcon@freecalypso.org>
parents:
148
diff
changeset
|
54 mode = input_bits[245]; |
78d1a6513393
amrconv: new program amr-cod-parse
Mychaela Falconia <falcon@freecalypso.org>
parents:
148
diff
changeset
|
55 printf("#%u: Type=%u Mode=%u", frame_no, type, mode); |
212
0beafaa0623f
amr-cod-parse: handle Mode=-1 in NO_DATA frames
Mychaela Falconia <falcon@freecalypso.org>
parents:
211
diff
changeset
|
56 if (type == TX_NO_DATA) { |
0beafaa0623f
amr-cod-parse: handle Mode=-1 in NO_DATA frames
Mychaela Falconia <falcon@freecalypso.org>
parents:
211
diff
changeset
|
57 printf(" (NO_DATA)\n"); |
0beafaa0623f
amr-cod-parse: handle Mode=-1 in NO_DATA frames
Mychaela Falconia <falcon@freecalypso.org>
parents:
211
diff
changeset
|
58 continue; |
0beafaa0623f
amr-cod-parse: handle Mode=-1 in NO_DATA frames
Mychaela Falconia <falcon@freecalypso.org>
parents:
211
diff
changeset
|
59 } |
211
78d1a6513393
amrconv: new program amr-cod-parse
Mychaela Falconia <falcon@freecalypso.org>
parents:
148
diff
changeset
|
60 if (type > TX_NO_DATA || mode > MR122) { |
78d1a6513393
amrconv: new program amr-cod-parse
Mychaela Falconia <falcon@freecalypso.org>
parents:
148
diff
changeset
|
61 printf(" (unsupported)\n"); |
78d1a6513393
amrconv: new program amr-cod-parse
Mychaela Falconia <falcon@freecalypso.org>
parents:
148
diff
changeset
|
62 continue; |
78d1a6513393
amrconv: new program amr-cod-parse
Mychaela Falconia <falcon@freecalypso.org>
parents:
148
diff
changeset
|
63 } |
78d1a6513393
amrconv: new program amr-cod-parse
Mychaela Falconia <falcon@freecalypso.org>
parents:
148
diff
changeset
|
64 printf(" (%s %s)\n", amr_mode_names[mode], type_names[type]); |
78d1a6513393
amrconv: new program amr-cod-parse
Mychaela Falconia <falcon@freecalypso.org>
parents:
148
diff
changeset
|
65 switch (type) { |
78d1a6513393
amrconv: new program amr-cod-parse
Mychaela Falconia <falcon@freecalypso.org>
parents:
148
diff
changeset
|
66 case TX_SPEECH_GOOD: |
78d1a6513393
amrconv: new program amr-cod-parse
Mychaela Falconia <falcon@freecalypso.org>
parents:
148
diff
changeset
|
67 preen_frame_bits(input_bits+1, amr_bit_lengths[mode], |
78d1a6513393
amrconv: new program amr-cod-parse
Mychaela Falconia <falcon@freecalypso.org>
parents:
148
diff
changeset
|
68 infname, frame_no); |
78d1a6513393
amrconv: new program amr-cod-parse
Mychaela Falconia <falcon@freecalypso.org>
parents:
148
diff
changeset
|
69 reassemble_amr_params(input_bits+1, params, mode); |
78d1a6513393
amrconv: new program amr-cod-parse
Mychaela Falconia <falcon@freecalypso.org>
parents:
148
diff
changeset
|
70 dump_amr_params(params, mode); |
78d1a6513393
amrconv: new program amr-cod-parse
Mychaela Falconia <falcon@freecalypso.org>
parents:
148
diff
changeset
|
71 break; |
78d1a6513393
amrconv: new program amr-cod-parse
Mychaela Falconia <falcon@freecalypso.org>
parents:
148
diff
changeset
|
72 case TX_SID_FIRST: |
78d1a6513393
amrconv: new program amr-cod-parse
Mychaela Falconia <falcon@freecalypso.org>
parents:
148
diff
changeset
|
73 case TX_SID_UPDATE: |
78d1a6513393
amrconv: new program amr-cod-parse
Mychaela Falconia <falcon@freecalypso.org>
parents:
148
diff
changeset
|
74 preen_frame_bits(input_bits+1, AMR_NBITS_SID, infname, |
78d1a6513393
amrconv: new program amr-cod-parse
Mychaela Falconia <falcon@freecalypso.org>
parents:
148
diff
changeset
|
75 frame_no); |
78d1a6513393
amrconv: new program amr-cod-parse
Mychaela Falconia <falcon@freecalypso.org>
parents:
148
diff
changeset
|
76 reassemble_amr_params(input_bits+1, params, MRDTX); |
78d1a6513393
amrconv: new program amr-cod-parse
Mychaela Falconia <falcon@freecalypso.org>
parents:
148
diff
changeset
|
77 dump_amr_params(params, MRDTX); |
78d1a6513393
amrconv: new program amr-cod-parse
Mychaela Falconia <falcon@freecalypso.org>
parents:
148
diff
changeset
|
78 break; |
115
5a63294fa321
gsmefr-cod-parse test program written
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
79 } |
5a63294fa321
gsmefr-cod-parse test program written
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
80 } |
211
78d1a6513393
amrconv: new program amr-cod-parse
Mychaela Falconia <falcon@freecalypso.org>
parents:
148
diff
changeset
|
81 exit(0); |
115
5a63294fa321
gsmefr-cod-parse test program written
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
82 } |